#include "amdgpu_cs.h"
+#include "util/hash_table.h"
#include "util/os_time.h"
#include "util/u_hash_table.h"
#include "state_tracker/drm_driver.h"
void amdgpu_bo_destroy(struct pb_buffer *_buf)
{
struct amdgpu_winsys_bo *bo = amdgpu_winsys_bo(_buf);
+ struct amdgpu_screen_winsys *sws_iter;
struct amdgpu_winsys *ws = bo->ws;
assert(bo->bo && "must not be called for slab entries");
simple_mtx_unlock(&ws->global_bo_list_lock);
}
+ simple_mtx_lock(&ws->sws_list_lock);
+ for (sws_iter = ws->sws_list; sws_iter; sws_iter = sws_iter->next)
+ _mesa_hash_table_remove_key(sws_iter->kms_handles, bo);
+ simple_mtx_unlock(&ws->sws_list_lock);
+
simple_mtx_lock(&ws->bo_export_table_lock);
util_hash_table_remove(ws->bo_export_table, bo->bo);
simple_mtx_unlock(&ws->bo_export_table_lock);
struct amdgpu_winsys_bo *bo = amdgpu_winsys_bo(buffer);
struct amdgpu_winsys *ws = bo->ws;
enum amdgpu_bo_handle_type type;
+ struct hash_entry *entry;
int r;
/* Don't allow exports of slab entries and sparse buffers. */
type = amdgpu_bo_handle_type_gem_flink_name;
break;
case WINSYS_HANDLE_TYPE_KMS:
+ simple_mtx_lock(&ws->sws_list_lock);
+ entry = _mesa_hash_table_search(sws->kms_handles, bo);
+ simple_mtx_unlock(&ws->sws_list_lock);
+ if (entry) {
+ whandle->handle = (uintptr_t)entry->data;
+ return true;
+ }
+ /* Fall through */
case WINSYS_HANDLE_TYPE_FD:
type = amdgpu_bo_handle_type_dma_buf_fd;
break;
if (r)
return false;
+
+ simple_mtx_lock(&ws->sws_list_lock);
+ _mesa_hash_table_insert_pre_hashed(sws->kms_handles,
+ bo->u.real.kms_handle, bo,
+ (void*)(uintptr_t)whandle->handle);
+ simple_mtx_unlock(&ws->sws_list_lock);
}
simple_mtx_lock(&ws->bo_export_table_lock);
simple_mtx_unlock(&ws->sws_list_lock);
}
+ _mesa_hash_table_destroy(sws->kms_handles, NULL);
close(sws->fd);
FREE(rws);
}
util_cpu_caps.cores_per_L3);
}
+static uint32_t kms_handle_hash(const void *key)
+{
+ const struct amdgpu_winsys_bo *bo = key;
+
+ return bo->u.real.kms_handle;
+}
+
+static bool kms_handle_equals(const void *a, const void *b)
+{
+ return a == b;
+}
+
PUBLIC struct radeon_winsys *
amdgpu_winsys_create(int fd, const struct pipe_screen_config *config,
radeon_screen_create_t screen_create)
ws->fd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
+ ws->kms_handles = _mesa_hash_table_create(NULL, kms_handle_hash,
+ kms_handle_equals);
+ if (!ws->kms_handles)
+ goto fail;
+
/* Look up the winsys from the dev table. */
simple_mtx_lock(&dev_tab_mutex);
if (!dev_tab)
fail_alloc:
FREE(aws);
fail:
+ if (ws->kms_handles)
+ _mesa_hash_table_destroy(ws->kms_handles, NULL);
close(ws->fd);
FREE(ws);
simple_mtx_unlock(&dev_tab_mutex);