panfrost: Move device open/close to root panfrost
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Tue, 24 Mar 2020 17:40:12 +0000 (13:40 -0400)
committerMarge Bot <eric+marge@anholt.net>
Tue, 31 Mar 2020 01:12:26 +0000 (01:12 +0000)
We need it for standalone testing too.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4382>

src/gallium/drivers/panfrost/pan_screen.c
src/panfrost/encoder/pan_device.h
src/panfrost/encoder/pan_props.c

index e2e8d4847a56e3851cf59df40ddd76bb9fcd959b..46f33d584a0d4e6e88b624513d1c6602d0ac21bd 100644 (file)
@@ -591,11 +591,7 @@ panfrost_get_compute_param(struct pipe_screen *pscreen, enum pipe_shader_ir ir_t
 static void
 panfrost_destroy_screen(struct pipe_screen *pscreen)
 {
-        struct panfrost_device *dev = pan_device(pscreen);
-        panfrost_bo_cache_evict_all(dev);
-        pthread_mutex_destroy(&dev->bo_cache.lock);
-        pthread_mutex_destroy(&dev->active_bos_lock);
-        drmFreeVersion(dev->kernel_version);
+        panfrost_close_device(pan_device(pscreen));
         ralloc_free(pscreen);
 }
 
@@ -705,22 +701,6 @@ panfrost_screen_get_compiler_options(struct pipe_screen *pscreen,
         return &midgard_nir_options;
 }
 
-static uint32_t
-panfrost_active_bos_hash(const void *key)
-{
-        const struct panfrost_bo *bo = key;
-
-        return _mesa_hash_data(&bo->gem_handle, sizeof(bo->gem_handle));
-}
-
-static bool
-panfrost_active_bos_cmp(const void *keya, const void *keyb)
-{
-        const struct panfrost_bo *a = keya, *b = keyb;
-
-        return a->gem_handle == b->gem_handle;
-}
-
 struct pipe_screen *
 panfrost_create_screen(int fd, struct renderonly *ro)
 {
@@ -745,6 +725,7 @@ panfrost_create_screen(int fd, struct renderonly *ro)
                 return NULL;
 
         struct panfrost_device *dev = pan_device(&screen->base);
+        panfrost_open_device(screen, fd, dev);
 
         if (ro) {
                 dev->ro = renderonly_dup(ro);
@@ -755,15 +736,6 @@ panfrost_create_screen(int fd, struct renderonly *ro)
                 }
         }
 
-        dev->fd = fd;
-        dev->memctx = screen;
-
-        dev->gpu_id = panfrost_query_gpu_version(dev->fd);
-        dev->core_count = panfrost_query_core_count(dev->fd);
-        dev->thread_tls_alloc = panfrost_query_thread_tls_alloc(dev->fd);
-        dev->quirks = panfrost_get_quirks(dev->gpu_id);
-        dev->kernel_version = drmGetVersion(fd);
-
         /* Check if we're loading against a supported GPU model. */
 
         switch (dev->gpu_id) {
@@ -775,18 +747,10 @@ panfrost_create_screen(int fd, struct renderonly *ro)
         default:
                 /* Fail to load against untested models */
                 debug_printf("panfrost: Unsupported model %X", dev->gpu_id);
+                panfrost_destroy_screen(&(screen->base));
                 return NULL;
         }
 
-        pthread_mutex_init(&dev->active_bos_lock, NULL);
-        dev->active_bos = _mesa_set_create(screen, panfrost_active_bos_hash,
-                                              panfrost_active_bos_cmp);
-
-        pthread_mutex_init(&dev->bo_cache.lock, NULL);
-        list_inithead(&dev->bo_cache.lru);
-        for (unsigned i = 0; i < ARRAY_SIZE(dev->bo_cache.buckets); ++i)
-                list_inithead(&dev->bo_cache.buckets[i]);
-
         if (pan_debug & (PAN_DBG_TRACE | PAN_DBG_SYNC))
                 pandecode_initialize(!(pan_debug & PAN_DBG_TRACE));
 
index 19aa2df35bdfc5eaa9494be315793d286d49bc0c..75bf82e4434e4957983065a8432d8782dbf4f0fc 100644 (file)
@@ -104,4 +104,10 @@ struct panfrost_device {
         } bo_cache;
 };
 
+void
+panfrost_open_device(void *memctx, int fd, struct panfrost_device *dev);
+
+void
+panfrost_close_device(struct panfrost_device *dev);
+
 #endif
index fe9e5ab3e0abae0eeffd1657cdb6dd29c1a03e0f..3f751be949f93583854c05499672af09b8da2012 100644 (file)
 
 #include "util/u_math.h"
 #include "util/macros.h"
+#include "util/hash_table.h"
+#include "util/u_thread.h"
 #include "drm-uapi/panfrost_drm.h"
 #include "pan_encoder.h"
+#include "pan_device.h"
+#include "panfrost-quirks.h"
+#include "pan_bo.h"
 
 /* Abstraction over the raw drm_panfrost_get_param ioctl for fetching
  * information about devices */
@@ -106,3 +111,51 @@ panfrost_model_name(unsigned gpu_id)
                     unreachable("Invalid GPU ID");
         }
 }
+
+static uint32_t
+panfrost_active_bos_hash(const void *key)
+{
+        const struct panfrost_bo *bo = key;
+
+        return _mesa_hash_data(&bo->gem_handle, sizeof(bo->gem_handle));
+}
+
+static bool
+panfrost_active_bos_cmp(const void *keya, const void *keyb)
+{
+        const struct panfrost_bo *a = keya, *b = keyb;
+
+        return a->gem_handle == b->gem_handle;
+}
+
+void
+panfrost_open_device(void *memctx, int fd, struct panfrost_device *dev)
+{
+        dev->fd = fd;
+        dev->memctx = memctx;
+        dev->gpu_id = panfrost_query_gpu_version(fd);
+        dev->core_count = panfrost_query_core_count(fd);
+        dev->thread_tls_alloc = panfrost_query_thread_tls_alloc(fd);
+        dev->kernel_version = drmGetVersion(fd);
+        dev->quirks = panfrost_get_quirks(dev->gpu_id);
+
+        pthread_mutex_init(&dev->active_bos_lock, NULL);
+        dev->active_bos = _mesa_set_create(memctx,
+                        panfrost_active_bos_hash, panfrost_active_bos_cmp);
+
+        pthread_mutex_init(&dev->bo_cache.lock, NULL);
+        list_inithead(&dev->bo_cache.lru);
+
+        for (unsigned i = 0; i < ARRAY_SIZE(dev->bo_cache.buckets); ++i)
+                list_inithead(&dev->bo_cache.buckets[i]);
+}
+
+void
+panfrost_close_device(struct panfrost_device *dev)
+{
+        panfrost_bo_cache_evict_all(dev);
+        pthread_mutex_destroy(&dev->bo_cache.lock);
+        pthread_mutex_destroy(&dev->active_bos_lock);
+        drmFreeVersion(dev->kernel_version);
+
+}