diff options
author | Alyssa Rosenzweig <[email protected]> | 2020-03-24 13:40:12 -0400 |
---|---|---|
committer | Marge Bot <[email protected]> | 2020-03-31 01:12:26 +0000 |
commit | 39378eec578c4855dbcad19605242ca038e575ee (patch) | |
tree | 0569fb33de609cdd68ab6c9b55d488cb04af0589 | |
parent | fd18695a2697bf54cf11894959780c2c761a1808 (diff) |
panfrost: Move device open/close to root panfrost
We need it for standalone testing too.
Signed-off-by: Alyssa Rosenzweig <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4382>
-rw-r--r-- | src/gallium/drivers/panfrost/pan_screen.c | 42 | ||||
-rw-r--r-- | src/panfrost/encoder/pan_device.h | 6 | ||||
-rw-r--r-- | src/panfrost/encoder/pan_props.c | 53 |
3 files changed, 62 insertions, 39 deletions
diff --git a/src/gallium/drivers/panfrost/pan_screen.c b/src/gallium/drivers/panfrost/pan_screen.c index e2e8d4847a5..46f33d584a0 100644 --- a/src/gallium/drivers/panfrost/pan_screen.c +++ b/src/gallium/drivers/panfrost/pan_screen.c @@ -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)); diff --git a/src/panfrost/encoder/pan_device.h b/src/panfrost/encoder/pan_device.h index 19aa2df35bd..75bf82e4434 100644 --- a/src/panfrost/encoder/pan_device.h +++ b/src/panfrost/encoder/pan_device.h @@ -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 diff --git a/src/panfrost/encoder/pan_props.c b/src/panfrost/encoder/pan_props.c index fe9e5ab3e0a..3f751be949f 100644 --- a/src/panfrost/encoder/pan_props.c +++ b/src/panfrost/encoder/pan_props.c @@ -28,8 +28,13 @@ #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); + +} |