virgl/drm: handle flink name better.
authorDave Airlie <airlied@redhat.com>
Tue, 9 Apr 2019 04:54:27 +0000 (14:54 +1000)
committerDave Airlie <airlied@redhat.com>
Wed, 24 Apr 2019 20:05:43 +0000 (06:05 +1000)
This realigns this code with code from radeon.

Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
src/gallium/winsys/virgl/drm/virgl_drm_winsys.h

index 08509224b4ffc18c601616fbf177da1c4ddd0598..4c8947bf679c730677da9e069982821153e34bd2 100644 (file)
@@ -60,20 +60,13 @@ static void virgl_hw_res_destroy(struct virgl_drm_winsys *qdws,
 {
       struct drm_gem_close args;
 
-      if (res->flinked) {
-         mtx_lock(&qdws->bo_handles_mutex);
+      mtx_lock(&qdws->bo_handles_mutex);
+      util_hash_table_remove(qdws->bo_handles,
+                             (void *)(uintptr_t)res->bo_handle);
+      if (res->flink_name)
          util_hash_table_remove(qdws->bo_names,
-                                (void *)(uintptr_t)res->flink);
-         mtx_unlock(&qdws->bo_handles_mutex);
-      }
-
-      if (res->bo_handle) {
-         mtx_lock(&qdws->bo_handles_mutex);
-         util_hash_table_remove(qdws->bo_handles,
-                                (void *)(uintptr_t)res->bo_handle);
-         mtx_unlock(&qdws->bo_handles_mutex);
-      }
-
+                                (void *)(uintptr_t)res->flink_name);
+      mtx_unlock(&qdws->bo_handles_mutex);
       if (res->ptr)
          os_munmap(res->ptr, res->size);
 
@@ -483,21 +476,20 @@ static boolean virgl_drm_winsys_resource_get_handle(struct virgl_winsys *qws,
        return FALSE;
 
    if (whandle->type == WINSYS_HANDLE_TYPE_SHARED) {
-      if (!res->flinked) {
+      if (!res->flink_name) {
          memset(&flink, 0, sizeof(flink));
          flink.handle = res->bo_handle;
 
          if (drmIoctl(qdws->fd, DRM_IOCTL_GEM_FLINK, &flink)) {
             return FALSE;
          }
-         res->flinked = TRUE;
-         res->flink = flink.name;
+         res->flink_name = flink.name;
 
          mtx_lock(&qdws->bo_handles_mutex);
-         util_hash_table_set(qdws->bo_names, (void *)(uintptr_t)res->flink, res);
+         util_hash_table_set(qdws->bo_names, (void *)(uintptr_t)res->flink_name, res);
          mtx_unlock(&qdws->bo_handles_mutex);
       }
-      whandle->handle = res->flink;
+      whandle->handle = res->flink_name;
    } else if (whandle->type == WINSYS_HANDLE_TYPE_KMS) {
       whandle->handle = res->bo_handle;
    } else if (whandle->type == WINSYS_HANDLE_TYPE_FD) {
index d30fe2a0dccea179c8fe6b813410b62ac0b1a2ed..c0d1ae568a705508850151b756233e4883267714 100644 (file)
@@ -47,8 +47,7 @@ struct virgl_hw_res {
    uint32_t bind;
    boolean cacheable;
    int64_t start, end;
-   boolean flinked;
-   uint32_t flink;
+   uint32_t flink_name;
 };
 
 struct virgl_drm_winsys