#define ETIME ETIMEDOUT
#endif
#include "libdrm_macros.h"
-#include "libdrm_lists.h"
+#include "util/list.h"
#include "brw_bufmgr.h"
#include "intel_bufmgr_priv.h"
#include "intel_chipset.h"
typedef struct _drm_bacon_bo_gem drm_bacon_bo_gem;
struct drm_bacon_gem_bo_bucket {
- drmMMListHead head;
+ struct list_head head;
unsigned long size;
};
int num_buckets;
time_t time;
- drmMMListHead managers;
+ struct list_head managers;
drm_bacon_bo_gem *name_table;
drm_bacon_bo_gem *handle_table;
- drmMMListHead vma_cache;
+ struct list_head vma_cache;
int vma_count, vma_open, vma_max;
uint64_t gtt_size;
*/
void *user_virtual;
int map_count;
- drmMMListHead vma_list;
+ struct list_head vma_list;
/** BO cache list */
- drmMMListHead head;
+ struct list_head head;
/**
* Boolean of whether this BO and its children have been included in
drm_bacon_gem_bo_cache_purge_bucket(drm_bacon_bufmgr_gem *bufmgr_gem,
struct drm_bacon_gem_bo_bucket *bucket)
{
- while (!DRMLISTEMPTY(&bucket->head)) {
+ while (!list_empty(&bucket->head)) {
drm_bacon_bo_gem *bo_gem;
- bo_gem = DRMLISTENTRY(drm_bacon_bo_gem,
- bucket->head.next, head);
+ bo_gem = LIST_ENTRY(drm_bacon_bo_gem,
+ bucket->head.next, head);
if (drm_bacon_gem_bo_madvise_internal
(bufmgr_gem, bo_gem, I915_MADV_DONTNEED))
break;
- DRMLISTDEL(&bo_gem->head);
+ list_del(&bo_gem->head);
drm_bacon_gem_bo_free(&bo_gem->bo);
}
}
/* Get a buffer out of the cache if available */
retry:
alloc_from_cache = false;
- if (bucket != NULL && !DRMLISTEMPTY(&bucket->head)) {
+ if (bucket != NULL && !list_empty(&bucket->head)) {
if (for_render) {
/* Allocate new render-target BOs from the tail (MRU)
* of the list, as it will likely be hot in the GPU
* cache and in the aperture for us.
*/
- bo_gem = DRMLISTENTRY(drm_bacon_bo_gem,
- bucket->head.prev, head);
- DRMLISTDEL(&bo_gem->head);
+ bo_gem = LIST_ENTRY(drm_bacon_bo_gem,
+ bucket->head.prev, head);
+ list_del(&bo_gem->head);
alloc_from_cache = true;
bo_gem->bo.align = alignment;
} else {
* allocating a new buffer is probably faster than
* waiting for the GPU to finish.
*/
- bo_gem = DRMLISTENTRY(drm_bacon_bo_gem,
- bucket->head.next, head);
+ bo_gem = LIST_ENTRY(drm_bacon_bo_gem,
+ bucket->head.next, head);
if (!drm_bacon_gem_bo_busy(&bo_gem->bo)) {
alloc_from_cache = true;
- DRMLISTDEL(&bo_gem->head);
+ list_del(&bo_gem->head);
}
}
if (!bo_gem)
goto err;
- /* drm_bacon_gem_bo_free calls DRMLISTDEL() for an uninitialized
+ /* drm_bacon_gem_bo_free calls list_del() for an uninitialized
list (vma_list), so better set the list head here */
- DRMINITLISTHEAD(&bo_gem->vma_list);
+ list_inithead(&bo_gem->vma_list);
bo_gem->bo.size = bo_size;
return NULL;
p_atomic_set(&bo_gem->refcount, 1);
- DRMINITLISTHEAD(&bo_gem->vma_list);
+ list_inithead(&bo_gem->vma_list);
bo_gem->bo.size = size;
goto out;
p_atomic_set(&bo_gem->refcount, 1);
- DRMINITLISTHEAD(&bo_gem->vma_list);
+ list_inithead(&bo_gem->vma_list);
bo_gem->bo.size = open_arg.size;
bo_gem->bo.offset = 0;
struct drm_gem_close close;
int ret;
- DRMLISTDEL(&bo_gem->vma_list);
+ list_del(&bo_gem->vma_list);
if (bo_gem->mem_virtual) {
VG(VALGRIND_FREELIKE_BLOCK(bo_gem->mem_virtual, 0));
drm_munmap(bo_gem->mem_virtual, bo_gem->bo.size);
struct drm_bacon_gem_bo_bucket *bucket =
&bufmgr_gem->cache_bucket[i];
- while (!DRMLISTEMPTY(&bucket->head)) {
+ while (!list_empty(&bucket->head)) {
drm_bacon_bo_gem *bo_gem;
- bo_gem = DRMLISTENTRY(drm_bacon_bo_gem,
- bucket->head.next, head);
+ bo_gem = LIST_ENTRY(drm_bacon_bo_gem,
+ bucket->head.next, head);
if (time - bo_gem->free_time <= 1)
break;
- DRMLISTDEL(&bo_gem->head);
+ list_del(&bo_gem->head);
drm_bacon_gem_bo_free(&bo_gem->bo);
}
while (bufmgr_gem->vma_count > limit) {
drm_bacon_bo_gem *bo_gem;
- bo_gem = DRMLISTENTRY(drm_bacon_bo_gem,
- bufmgr_gem->vma_cache.next,
- vma_list);
+ bo_gem = LIST_ENTRY(drm_bacon_bo_gem,
+ bufmgr_gem->vma_cache.next,
+ vma_list);
assert(bo_gem->map_count == 0);
- DRMLISTDELINIT(&bo_gem->vma_list);
+ list_delinit(&bo_gem->vma_list);
if (bo_gem->mem_virtual) {
drm_munmap(bo_gem->mem_virtual, bo_gem->bo.size);
drm_bacon_bo_gem *bo_gem)
{
bufmgr_gem->vma_open--;
- DRMLISTADDTAIL(&bo_gem->vma_list, &bufmgr_gem->vma_cache);
+ list_addtail(&bo_gem->vma_list, &bufmgr_gem->vma_cache);
if (bo_gem->mem_virtual)
bufmgr_gem->vma_count++;
if (bo_gem->wc_virtual)
drm_bacon_bo_gem *bo_gem)
{
bufmgr_gem->vma_open++;
- DRMLISTDEL(&bo_gem->vma_list);
+ list_del(&bo_gem->vma_list);
if (bo_gem->mem_virtual)
bufmgr_gem->vma_count--;
if (bo_gem->wc_virtual)
bo_gem->name = NULL;
bo_gem->validate_index = -1;
- DRMLISTADDTAIL(&bo_gem->head, &bucket->head);
+ list_addtail(&bo_gem->head, &bucket->head);
} else {
drm_bacon_gem_bo_free(bo);
}
&bufmgr_gem->cache_bucket[i];
drm_bacon_bo_gem *bo_gem;
- while (!DRMLISTEMPTY(&bucket->head)) {
- bo_gem = DRMLISTENTRY(drm_bacon_bo_gem,
- bucket->head.next, head);
- DRMLISTDEL(&bo_gem->head);
+ while (!list_empty(&bucket->head)) {
+ bo_gem = LIST_ENTRY(drm_bacon_bo_gem,
+ bucket->head.next, head);
+ list_del(&bo_gem->head);
drm_bacon_gem_bo_free(&bo_gem->bo);
}
goto out;
p_atomic_set(&bo_gem->refcount, 1);
- DRMINITLISTHEAD(&bo_gem->vma_list);
+ list_inithead(&bo_gem->vma_list);
/* Determine size of bo. The fd-to-handle ioctl really should
* return the size, but it doesn't. If we have kernel 3.12 or
assert(i < ARRAY_SIZE(bufmgr_gem->cache_bucket));
- DRMINITLISTHEAD(&bufmgr_gem->cache_bucket[i].head);
+ list_inithead(&bufmgr_gem->cache_bucket[i].head);
bufmgr_gem->cache_bucket[i].size = size;
bufmgr_gem->num_buckets++;
}
}
static pthread_mutex_t bufmgr_list_mutex = PTHREAD_MUTEX_INITIALIZER;
-static drmMMListHead bufmgr_list = { &bufmgr_list, &bufmgr_list };
+static struct list_head bufmgr_list = { &bufmgr_list, &bufmgr_list };
static drm_bacon_bufmgr_gem *
drm_bacon_bufmgr_gem_find(int fd)
{
- drm_bacon_bufmgr_gem *bufmgr_gem;
-
- DRMLISTFOREACHENTRY(bufmgr_gem, &bufmgr_list, managers) {
+ list_for_each_entry(drm_bacon_bufmgr_gem,
+ bufmgr_gem, &bufmgr_list, managers) {
if (bufmgr_gem->fd == fd) {
p_atomic_inc(&bufmgr_gem->refcount);
return bufmgr_gem;
pthread_mutex_lock(&bufmgr_list_mutex);
if (p_atomic_dec_zero(&bufmgr_gem->refcount)) {
- DRMLISTDEL(&bufmgr_gem->managers);
+ list_del(&bufmgr_gem->managers);
drm_bacon_bufmgr_gem_destroy(bufmgr);
}
init_cache_buckets(bufmgr_gem);
- DRMINITLISTHEAD(&bufmgr_gem->vma_cache);
+ list_inithead(&bufmgr_gem->vma_cache);
bufmgr_gem->vma_max = -1; /* unlimited by default */
- DRMLISTADD(&bufmgr_gem->managers, &bufmgr_list);
+ list_add(&bufmgr_gem->managers, &bufmgr_list);
exit:
pthread_mutex_unlock(&bufmgr_list_mutex);
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND. USA.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- */
-
-/*
- * List macros heavily inspired by the Linux kernel
- * list handling. No list looping yet.
- */
-
-#include <stddef.h>
-
-#ifndef typeof
-#define typeof __typeof__
-#endif
-
-typedef struct _drmMMListHead
-{
- struct _drmMMListHead *prev;
- struct _drmMMListHead *next;
-} drmMMListHead;
-
-#define DRMINITLISTHEAD(__item) \
- do{ \
- (__item)->prev = (__item); \
- (__item)->next = (__item); \
- } while (0)
-
-#define DRMLISTADD(__item, __list) \
- do { \
- (__item)->prev = (__list); \
- (__item)->next = (__list)->next; \
- (__list)->next->prev = (__item); \
- (__list)->next = (__item); \
- } while (0)
-
-#define DRMLISTADDTAIL(__item, __list) \
- do { \
- (__item)->next = (__list); \
- (__item)->prev = (__list)->prev; \
- (__list)->prev->next = (__item); \
- (__list)->prev = (__item); \
- } while(0)
-
-#define DRMLISTDEL(__item) \
- do { \
- (__item)->prev->next = (__item)->next; \
- (__item)->next->prev = (__item)->prev; \
- } while(0)
-
-#define DRMLISTDELINIT(__item) \
- do { \
- (__item)->prev->next = (__item)->next; \
- (__item)->next->prev = (__item)->prev; \
- (__item)->next = (__item); \
- (__item)->prev = (__item); \
- } while(0)
-
-#define DRMLISTENTRY(__type, __item, __field) \
- ((__type *)(((char *) (__item)) - offsetof(__type, __field)))
-
-#define DRMLISTEMPTY(__item) ((__item)->next == (__item))
-
-#define DRMLISTSINGLE(__list) \
- (!DRMLISTEMPTY(__list) && ((__list)->next == (__list)->prev))
-
-#define DRMLISTFOREACH(__item, __list) \
- for ((__item) = (__list)->next; \
- (__item) != (__list); (__item) = (__item)->next)
-
-#define DRMLISTFOREACHSAFE(__item, __temp, __list) \
- for ((__item) = (__list)->next, (__temp) = (__item)->next; \
- (__item) != (__list); \
- (__item) = (__temp), (__temp) = (__item)->next)
-
-#define DRMLISTFOREACHSAFEREVERSE(__item, __temp, __list) \
- for ((__item) = (__list)->prev, (__temp) = (__item)->prev; \
- (__item) != (__list); \
- (__item) = (__temp), (__temp) = (__item)->prev)
-
-#define DRMLISTFOREACHENTRY(__item, __list, __head) \
- for ((__item) = DRMLISTENTRY(typeof(*__item), (__list)->next, __head); \
- &(__item)->__head != (__list); \
- (__item) = DRMLISTENTRY(typeof(*__item), \
- (__item)->__head.next, __head))
-
-#define DRMLISTFOREACHENTRYSAFE(__item, __temp, __list, __head) \
- for ((__item) = DRMLISTENTRY(typeof(*__item), (__list)->next, __head), \
- (__temp) = DRMLISTENTRY(typeof(*__item), \
- (__item)->__head.next, __head); \
- &(__item)->__head != (__list); \
- (__item) = (__temp), \
- (__temp) = DRMLISTENTRY(typeof(*__item), \
- (__temp)->__head.next, __head))
-
-#define DRMLISTJOIN(__list, __join) if (!DRMLISTEMPTY(__list)) { \
- (__list)->next->prev = (__join); \
- (__list)->prev->next = (__join)->next; \
- (__join)->next->prev = (__list)->prev; \
- (__join)->next = (__list)->next; \
-}