Use the common pipe_screen ref counting and fd hashing functions. The mutex can be dropped as the pipe loader serializes the create_screen() and destroy() calls.
This changes the reference counting from the winsys to the pipe screen. Previously, it was possible to have 1 winsys with multiple pipe screens. Now there will only be a single winsys and pipe screen. Signed-off-by: Rob Herring <r...@kernel.org> Cc: Brian Paul <bri...@vmware.com> --- src/gallium/auxiliary/target-helpers/drm_helper.h | 21 ++++++--- src/gallium/targets/pipe-loader/pipe_vmwgfx.c | 24 +++++----- src/gallium/winsys/svga/drm/vmw_screen.c | 55 ++++------------------- src/gallium/winsys/svga/drm/vmw_screen.h | 6 --- 4 files changed, 37 insertions(+), 69 deletions(-) diff --git a/src/gallium/auxiliary/target-helpers/drm_helper.h b/src/gallium/auxiliary/target-helpers/drm_helper.h index 95b4a27111cb..dd5ca613ba1f 100644 --- a/src/gallium/auxiliary/target-helpers/drm_helper.h +++ b/src/gallium/auxiliary/target-helpers/drm_helper.h @@ -214,19 +214,28 @@ pipe_radeonsi_configuration_query(enum drm_conf conf) #ifdef GALLIUM_VMWGFX #include "svga/drm/svga_drm_public.h" #include "svga/svga_public.h" +#include "util/u_screen.h" + +#include <fcntl.h> struct pipe_screen * pipe_vmwgfx_create_screen(int fd, const struct pipe_screen_config *config) { struct svga_winsys_screen *sws; - struct pipe_screen *screen; + struct pipe_screen *screen = pipe_screen_reference(fd); - sws = svga_drm_winsys_screen_create(fd); - if (!sws) - return NULL; + if (!screen) { + sws = svga_drm_winsys_screen_create(fd); + if (!sws) + return NULL; - screen = svga_screen_create(sws); - return screen ? debug_screen_wrap(screen) : NULL; + screen = svga_screen_create(sws); + if (!screen) + return NULL; + + pipe_screen_reference_init(screen, fcntl(fd, F_DUPFD_CLOEXEC, 3)); + } + return debug_screen_wrap(screen); } #else diff --git a/src/gallium/targets/pipe-loader/pipe_vmwgfx.c b/src/gallium/targets/pipe-loader/pipe_vmwgfx.c index 68bf92ce82e5..0e7baf3f1552 100644 --- a/src/gallium/targets/pipe-loader/pipe_vmwgfx.c +++ b/src/gallium/targets/pipe-loader/pipe_vmwgfx.c @@ -3,24 +3,28 @@ #include "state_tracker/drm_driver.h" #include "svga/drm/svga_drm_public.h" #include "svga/svga_public.h" +#include "util/u_screen.h" + +#include <fcntl.h> static struct pipe_screen * create_screen(int fd, const struct pipe_screen_config *config) { struct svga_winsys_screen *sws; - struct pipe_screen *screen; - - sws = svga_drm_winsys_screen_create(fd); - if (!sws) - return NULL; + struct pipe_screen *screen = pipe_screen_reference(fd); - screen = svga_screen_create(sws); - if (!screen) - return NULL; + if (!screen) { + sws = svga_drm_winsys_screen_create(fd); + if (!sws) + return NULL; - screen = debug_screen_wrap(screen); + screen = svga_screen_create(sws); + if (!screen) + return NULL; - return screen; + pipe_screen_reference_init(screen, fcntl(fd, F_DUPFD_CLOEXEC, 3)); + } + return debug_screen_wrap(screen); } static const struct drm_conf_ret throttle_ret = { diff --git a/src/gallium/winsys/svga/drm/vmw_screen.c b/src/gallium/winsys/svga/drm/vmw_screen.c index e122e0c9902c..90fb8149c204 100644 --- a/src/gallium/winsys/svga/drm/vmw_screen.c +++ b/src/gallium/winsys/svga/drm/vmw_screen.c @@ -29,31 +29,17 @@ #include "vmw_context.h" #include "util/u_memory.h" +#include "util/u_screen.h" #include "pipe/p_compiler.h" -#include "util/u_hash_table.h" #ifdef MAJOR_IN_MKDEV #include <sys/mkdev.h> #endif #ifdef MAJOR_IN_SYSMACROS #include <sys/sysmacros.h> #endif -#include <sys/stat.h> #include <unistd.h> #include <fcntl.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. @@ -66,29 +52,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 = fcntl(fd, F_DUPFD_CLOEXEC, 3); vws->base.have_gb_dma = TRUE; vws->base.need_to_rebind_resources = FALSE; @@ -106,14 +74,10 @@ 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; - cnd_init(&vws->cs_cond); mtx_init(&vws->cs_mutex, mtx_plain); return vws; -out_no_hash_insert: out_no_svga: vmw_pools_cleanup(vws); out_no_pools: @@ -130,14 +94,11 @@ 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); - mtx_destroy(&vws->cs_mutex); - cnd_destroy(&vws->cs_cond); - FREE(vws); - } + vmw_pools_cleanup(vws); + vws->fence_ops->destroy(vws->fence_ops); + vmw_ioctl_cleanup(vws); + close(vws->ioctl.drm_fd); + mtx_destroy(&vws->cs_mutex); + cnd_destroy(&vws->cs_cond); + FREE(vws); } diff --git a/src/gallium/winsys/svga/drm/vmw_screen.h b/src/gallium/winsys/svga/drm/vmw_screen.h index f21cabb51f93..e5faf36e73dc 100644 --- a/src/gallium/winsys/svga/drm/vmw_screen.h +++ b/src/gallium/winsys/svga/drm/vmw_screen.h @@ -94,12 +94,6 @@ struct vmw_winsys_screen struct pb_fence_ops *fence_ops; - /* - * Screen instances - */ - dev_t device; - int open_count; - cnd_t cs_cond; mtx_t cs_mutex; }; -- 2.11.0 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev