etnaviv: drm: Use _mesa_hash_table instead of drmHash
[mesa.git] / src / etnaviv / drm / etnaviv_bo.c
index 43ce6b4e3c9fd6a8aad68a85081d5b4f6cce3c95..096415afae3e0fdafe67d2564296066e5389454d 100644 (file)
  *    Christian Gmeiner <christian.gmeiner@gmail.com>
  */
 
  *    Christian Gmeiner <christian.gmeiner@gmail.com>
  */
 
+#include "os/os_mman.h"
+#include "util/hash_table.h"
+
 #include "etnaviv_priv.h"
 #include "etnaviv_drmif.h"
 
 #include "etnaviv_priv.h"
 #include "etnaviv_drmif.h"
 
-drm_private pthread_mutex_t table_lock = PTHREAD_MUTEX_INITIALIZER;
-drm_private void bo_del(struct etna_bo *bo);
+pthread_mutex_t table_lock = PTHREAD_MUTEX_INITIALIZER;
+void bo_del(struct etna_bo *bo);
 
 /* set buffer name, and add to table, call w/ table_lock held: */
 static void set_name(struct etna_bo *bo, uint32_t name)
 {
        bo->name = name;
        /* add ourself into the name table: */
 
 /* set buffer name, and add to table, call w/ table_lock held: */
 static void set_name(struct etna_bo *bo, uint32_t name)
 {
        bo->name = name;
        /* add ourself into the name table: */
-       drmHashInsert(bo->dev->name_table, name, bo);
+       _mesa_hash_table_insert(bo->dev->name_table, &bo->name, bo);
 }
 
 /* Called under table_lock */
 }
 
 /* Called under table_lock */
-drm_private void bo_del(struct etna_bo *bo)
+void bo_del(struct etna_bo *bo)
 {
        if (bo->map)
 {
        if (bo->map)
-               drm_munmap(bo->map, bo->size);
+               os_munmap(bo->map, bo->size);
 
        if (bo->name)
 
        if (bo->name)
-               drmHashDelete(bo->dev->name_table, bo->name);
+               _mesa_hash_table_remove_key(bo->dev->name_table, &bo->name);
 
        if (bo->handle) {
                struct drm_gem_close req = {
                        .handle = bo->handle,
                };
 
 
        if (bo->handle) {
                struct drm_gem_close req = {
                        .handle = bo->handle,
                };
 
-               drmHashDelete(bo->dev->handle_table, bo->handle);
+               _mesa_hash_table_remove_key(bo->dev->handle_table, &bo->handle);
                drmIoctl(bo->dev->fd, DRM_IOCTL_GEM_CLOSE, &req);
        }
 
                drmIoctl(bo->dev->fd, DRM_IOCTL_GEM_CLOSE, &req);
        }
 
@@ -63,10 +66,11 @@ drm_private void bo_del(struct etna_bo *bo)
 static struct etna_bo *lookup_bo(void *tbl, uint32_t handle)
 {
        struct etna_bo *bo = NULL;
 static struct etna_bo *lookup_bo(void *tbl, uint32_t handle)
 {
        struct etna_bo *bo = NULL;
+       struct hash_entry *entry = _mesa_hash_table_search(tbl, &handle);
 
 
-       if (!drmHashLookup(tbl, handle, (void **)&bo)) {
+       if (entry) {
                /* found, incr refcnt and return: */
                /* found, incr refcnt and return: */
-               bo = etna_bo_ref(bo);
+               bo = etna_bo_ref(entry->data);
 
                /* don't break the bucket if this bo was found in one */
                list_delinit(&bo->list);
 
                /* don't break the bucket if this bo was found in one */
                list_delinit(&bo->list);
@@ -95,16 +99,16 @@ static struct etna_bo *bo_from_handle(struct etna_device *dev,
        bo->size = size;
        bo->handle = handle;
        bo->flags = flags;
        bo->size = size;
        bo->handle = handle;
        bo->flags = flags;
-       atomic_set(&bo->refcnt, 1);
+       p_atomic_set(&bo->refcnt, 1);
        list_inithead(&bo->list);
        /* add ourselves to the handle table: */
        list_inithead(&bo->list);
        /* add ourselves to the handle table: */
-       drmHashInsert(dev->handle_table, handle, bo);
+       _mesa_hash_table_insert(dev->handle_table, &bo->handle, bo);
 
        return bo;
 }
 
 /* allocate a new (un-tiled) buffer object */
 
        return bo;
 }
 
 /* allocate a new (un-tiled) buffer object */
-drm_public struct etna_bo *etna_bo_new(struct etna_device *dev, uint32_t size,
+struct etna_bo *etna_bo_new(struct etna_device *dev, uint32_t size,
                uint32_t flags)
 {
        struct etna_bo *bo;
                uint32_t flags)
 {
        struct etna_bo *bo;
@@ -131,9 +135,9 @@ drm_public struct etna_bo *etna_bo_new(struct etna_device *dev, uint32_t size,
        return bo;
 }
 
        return bo;
 }
 
-drm_public struct etna_bo *etna_bo_ref(struct etna_bo *bo)
+struct etna_bo *etna_bo_ref(struct etna_bo *bo)
 {
 {
-       atomic_inc(&bo->refcnt);
+       p_atomic_inc(&bo->refcnt);
 
        return bo;
 }
 
        return bo;
 }
@@ -159,7 +163,7 @@ static int get_buffer_info(struct etna_bo *bo)
 }
 
 /* import a buffer object from DRI2 name */
 }
 
 /* import a buffer object from DRI2 name */
-drm_public struct etna_bo *etna_bo_from_name(struct etna_device *dev,
+struct etna_bo *etna_bo_from_name(struct etna_device *dev,
                uint32_t name)
 {
        struct etna_bo *bo;
                uint32_t name)
 {
        struct etna_bo *bo;
@@ -197,7 +201,7 @@ out_unlock:
  * fd so caller should close() the fd when it is otherwise done
  * with it (even if it is still using the 'struct etna_bo *')
  */
  * fd so caller should close() the fd when it is otherwise done
  * with it (even if it is still using the 'struct etna_bo *')
  */
-drm_public struct etna_bo *etna_bo_from_dmabuf(struct etna_device *dev, int fd)
+struct etna_bo *etna_bo_from_dmabuf(struct etna_device *dev, int fd)
 {
        struct etna_bo *bo;
        int ret, size;
 {
        struct etna_bo *bo;
        int ret, size;
@@ -232,14 +236,14 @@ out_unlock:
 }
 
 /* destroy a buffer object */
 }
 
 /* destroy a buffer object */
-drm_public void etna_bo_del(struct etna_bo *bo)
+void etna_bo_del(struct etna_bo *bo)
 {
        struct etna_device *dev = bo->dev;
 
        if (!bo)
                return;
 
 {
        struct etna_device *dev = bo->dev;
 
        if (!bo)
                return;
 
-       if (!atomic_dec_and_test(&bo->refcnt))
+       if (!p_atomic_dec_zero(&bo->refcnt))
                return;
 
        pthread_mutex_lock(&table_lock);
                return;
 
        pthread_mutex_lock(&table_lock);
@@ -254,7 +258,7 @@ out:
 }
 
 /* get the global flink/DRI2 buffer name */
 }
 
 /* get the global flink/DRI2 buffer name */
-drm_public int etna_bo_get_name(struct etna_bo *bo, uint32_t *name)
+int etna_bo_get_name(struct etna_bo *bo, uint32_t *name)
 {
        if (!bo->name) {
                struct drm_gem_flink req = {
 {
        if (!bo->name) {
                struct drm_gem_flink req = {
@@ -278,7 +282,7 @@ drm_public int etna_bo_get_name(struct etna_bo *bo, uint32_t *name)
        return 0;
 }
 
        return 0;
 }
 
-drm_public uint32_t etna_bo_handle(struct etna_bo *bo)
+uint32_t etna_bo_handle(struct etna_bo *bo)
 {
        return bo->handle;
 }
 {
        return bo->handle;
 }
@@ -286,7 +290,7 @@ drm_public uint32_t etna_bo_handle(struct etna_bo *bo)
 /* caller owns the dmabuf fd that is returned and is responsible
  * to close() it when done
  */
 /* caller owns the dmabuf fd that is returned and is responsible
  * to close() it when done
  */
-drm_public int etna_bo_dmabuf(struct etna_bo *bo)
+int etna_bo_dmabuf(struct etna_bo *bo)
 {
        int ret, prime_fd;
 
 {
        int ret, prime_fd;
 
@@ -302,20 +306,20 @@ drm_public int etna_bo_dmabuf(struct etna_bo *bo)
        return prime_fd;
 }
 
        return prime_fd;
 }
 
-drm_public uint32_t etna_bo_size(struct etna_bo *bo)
+uint32_t etna_bo_size(struct etna_bo *bo)
 {
        return bo->size;
 }
 
 {
        return bo->size;
 }
 
-drm_public void *etna_bo_map(struct etna_bo *bo)
+void *etna_bo_map(struct etna_bo *bo)
 {
        if (!bo->map) {
                if (!bo->offset) {
                        get_buffer_info(bo);
                }
 
 {
        if (!bo->map) {
                if (!bo->offset) {
                        get_buffer_info(bo);
                }
 
-               bo->map = drm_mmap(0, bo->size, PROT_READ | PROT_WRITE,
-                               MAP_SHARED, bo->dev->fd, bo->offset);
+               bo->map = os_mmap(0, bo->size, PROT_READ | PROT_WRITE,
+                                 MAP_SHARED, bo->dev->fd, bo->offset);
                if (bo->map == MAP_FAILED) {
                        ERROR_MSG("mmap failed: %s", strerror(errno));
                        bo->map = NULL;
                if (bo->map == MAP_FAILED) {
                        ERROR_MSG("mmap failed: %s", strerror(errno));
                        bo->map = NULL;
@@ -325,7 +329,7 @@ drm_public void *etna_bo_map(struct etna_bo *bo)
        return bo->map;
 }
 
        return bo->map;
 }
 
-drm_public int etna_bo_cpu_prep(struct etna_bo *bo, uint32_t op)
+int etna_bo_cpu_prep(struct etna_bo *bo, uint32_t op)
 {
        struct drm_etnaviv_gem_cpu_prep req = {
                .handle = bo->handle,
 {
        struct drm_etnaviv_gem_cpu_prep req = {
                .handle = bo->handle,
@@ -338,7 +342,7 @@ drm_public int etna_bo_cpu_prep(struct etna_bo *bo, uint32_t op)
                        &req, sizeof(req));
 }
 
                        &req, sizeof(req));
 }
 
-drm_public void etna_bo_cpu_fini(struct etna_bo *bo)
+void etna_bo_cpu_fini(struct etna_bo *bo)
 {
        struct drm_etnaviv_gem_cpu_fini req = {
                .handle = bo->handle,
 {
        struct drm_etnaviv_gem_cpu_fini req = {
                .handle = bo->handle,