[Mesa-dev] [PATCH v3 09/11] vmwgfx: use common screen ref counting

Rob Herring robh at kernel.org
Wed Jul 20 22:25:10 UTC 2016


Use the common pipe_screen ref counting and fd hashing functions. The
mutex can be dropped as the pipe loader protects the create_screen()
calls.

Signed-off-by: Rob Herring <robh at kernel.org>
---
 src/gallium/winsys/svga/drm/vmw_screen.c | 51 ++++----------------------------
 src/gallium/winsys/svga/drm/vmw_screen.h |  6 ----
 2 files changed, 6 insertions(+), 51 deletions(-)

diff --git a/src/gallium/winsys/svga/drm/vmw_screen.c b/src/gallium/winsys/svga/drm/vmw_screen.c
index 7fcb6d2..2b05012 100644
--- a/src/gallium/winsys/svga/drm/vmw_screen.c
+++ b/src/gallium/winsys/svga/drm/vmw_screen.c
@@ -30,24 +30,9 @@
 
 #include "util/u_memory.h"
 #include "pipe/p_compiler.h"
-#include "util/u_hash_table.h"
 #include <sys/types.h>
-#include <sys/stat.h>
 #include <unistd.h>
 
-static struct util_hash_table *dev_hash = NULL;
-
-static int vmw_dev_compare(void *key1, void *key2)
-{
-   return (major(*(dev_t *)key1) == major(*(dev_t *)key2) &&
-           minor(*(dev_t *)key1) == minor(*(dev_t *)key2)) ? 0 : 1;
-}
-
-static unsigned vmw_dev_hash(void *key)
-{
-   return (major(*(dev_t *) key) << 16) | minor(*(dev_t *) key);
-}
-
 /* Called from vmw_drm_create_screen(), creates and initializes the
  * vmw_winsys_screen structure, which is the main entity in this
  * module.
@@ -60,29 +45,11 @@ struct vmw_winsys_screen *
 vmw_winsys_create( int fd )
 {
    struct vmw_winsys_screen *vws;
-   struct stat stat_buf;
-
-   if (dev_hash == NULL) {
-      dev_hash = util_hash_table_create(vmw_dev_hash, vmw_dev_compare);
-      if (dev_hash == NULL)
-         return NULL;
-   }
-
-   if (fstat(fd, &stat_buf))
-      return NULL;
-
-   vws = util_hash_table_get(dev_hash, &stat_buf.st_rdev);
-   if (vws) {
-      vws->open_count++;
-      return vws;
-   }
 
    vws = CALLOC_STRUCT(vmw_winsys_screen);
    if (!vws)
       goto out_no_vws;
 
-   vws->device = stat_buf.st_rdev;
-   vws->open_count = 1;
    vws->ioctl.drm_fd = dup(fd);
    vws->base.have_gb_dma = TRUE;
    vws->base.need_to_rebind_resources = FALSE;
@@ -100,11 +67,8 @@ vmw_winsys_create( int fd )
    if (!vmw_winsys_screen_init_svga(vws))
       goto out_no_svga;
 
-   if (util_hash_table_set(dev_hash, &vws->device, vws) != PIPE_OK)
-      goto out_no_hash_insert;
-
    return vws;
-out_no_hash_insert:
+
 out_no_svga:
    vmw_pools_cleanup(vws);
 out_no_pools:
@@ -121,12 +85,9 @@ out_no_vws:
 void
 vmw_winsys_destroy(struct vmw_winsys_screen *vws)
 {
-   if (--vws->open_count == 0) {
-      util_hash_table_remove(dev_hash, &vws->device);
-      vmw_pools_cleanup(vws);
-      vws->fence_ops->destroy(vws->fence_ops);
-      vmw_ioctl_cleanup(vws);
-      close(vws->ioctl.drm_fd);
-      FREE(vws);
-   }
+   vmw_pools_cleanup(vws);
+   vws->fence_ops->destroy(vws->fence_ops);
+   vmw_ioctl_cleanup(vws);
+   close(vws->ioctl.drm_fd);
+   FREE(vws);
 }
diff --git a/src/gallium/winsys/svga/drm/vmw_screen.h b/src/gallium/winsys/svga/drm/vmw_screen.h
index 79d0949..cfde6bb 100644
--- a/src/gallium/winsys/svga/drm/vmw_screen.h
+++ b/src/gallium/winsys/svga/drm/vmw_screen.h
@@ -93,12 +93,6 @@ struct vmw_winsys_screen
    } pools;
 
    struct pb_fence_ops *fence_ops;
-
-   /*
-    * Screen instances
-    */
-   dev_t device;
-   int open_count;
 };
 
 
-- 
2.9.2



More information about the mesa-dev mailing list