amdgpu: use handle table for KMS handles
Instead of the hash use the handle table.
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Reviewed-and-Tested-by: Junwei Zhang <Jerry.Zhang@amd.com>
diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c
index d29be24..66edb8d 100644
--- a/amdgpu/amdgpu_bo.c
+++ b/amdgpu/amdgpu_bo.c
@@ -90,8 +90,12 @@
pthread_mutex_init(&bo->cpu_access_mutex, NULL);
- *buf_handle = bo;
- return 0;
+ if (r)
+ amdgpu_bo_free(bo);
+ else
+ *buf_handle = bo;
+
+ return r;
}
int amdgpu_bo_set_metadata(amdgpu_bo_handle bo,
@@ -171,8 +175,7 @@
static void amdgpu_add_handle_to_table(amdgpu_bo_handle bo)
{
pthread_mutex_lock(&bo->dev->bo_table_mutex);
- util_hash_table_set(bo->dev->bo_handles,
- (void*)(uintptr_t)bo->handle, bo);
+ handle_table_insert(&bo->dev->bo_handles, bo->handle, bo);
pthread_mutex_unlock(&bo->dev->bo_table_mutex);
}
@@ -303,8 +306,7 @@
break;
case amdgpu_bo_handle_type_dma_buf_fd:
- bo = util_hash_table_get(dev->bo_handles,
- (void*)(uintptr_t)shared_handle);
+ bo = handle_table_lookup(&dev->bo_handles, shared_handle);
break;
case amdgpu_bo_handle_type_kms:
@@ -387,7 +389,7 @@
bo->dev = dev;
pthread_mutex_init(&bo->cpu_access_mutex, NULL);
- util_hash_table_set(dev->bo_handles, (void*)(uintptr_t)bo->handle, bo);
+ handle_table_insert(&dev->bo_handles, bo->handle, bo);
pthread_mutex_unlock(&dev->bo_table_mutex);
output->buf_handle = bo;
@@ -406,8 +408,7 @@
if (update_references(&bo->refcount, NULL)) {
/* Remove the buffer from the hash tables. */
- util_hash_table_remove(dev->bo_handles,
- (void*)(uintptr_t)bo->handle);
+ handle_table_remove(&dev->bo_handles, bo->handle);
if (bo->flink_name) {
util_hash_table_remove(dev->bo_flink_names,
diff --git a/amdgpu/amdgpu_device.c b/amdgpu/amdgpu_device.c
index 38fd186..824c1da 100644
--- a/amdgpu/amdgpu_device.c
+++ b/amdgpu/amdgpu_device.c
@@ -122,8 +122,8 @@
amdgpu_vamgr_deinit(&dev->vamgr);
amdgpu_vamgr_deinit(&dev->vamgr_high_32);
amdgpu_vamgr_deinit(&dev->vamgr_high);
+ handle_table_fini(&dev->bo_handles);
util_hash_table_destroy(dev->bo_flink_names);
- util_hash_table_destroy(dev->bo_handles);
pthread_mutex_destroy(&dev->bo_table_mutex);
free(dev->marketing_name);
free(dev);
@@ -230,7 +230,6 @@
dev->bo_flink_names = util_hash_table_create(handle_hash,
handle_compare);
- dev->bo_handles = util_hash_table_create(handle_hash, handle_compare);
pthread_mutex_init(&dev->bo_table_mutex, NULL);
/* Check if acceleration is working. */
diff --git a/amdgpu/amdgpu_internal.h b/amdgpu/amdgpu_internal.h
index 83012ca..36ebc73 100644
--- a/amdgpu/amdgpu_internal.h
+++ b/amdgpu/amdgpu_internal.h
@@ -32,6 +32,7 @@
#include "xf86atomic.h"
#include "amdgpu.h"
#include "util_double_list.h"
+#include "handle_table.h"
#define AMDGPU_CS_MAX_RINGS 8
/* do not use below macro if b is not power of 2 aligned value */
@@ -73,7 +74,7 @@
char *marketing_name;
/** List of buffer handles. Protected by bo_table_mutex. */
- struct util_hash_table *bo_handles;
+ struct handle_table bo_handles;
/** List of buffer GEM flink names. Protected by bo_table_mutex. */
struct util_hash_table *bo_flink_names;
/** This protects all hash tables. */