summaryrefslogtreecommitdiffstats
path: root/src/panfrost
diff options
context:
space:
mode:
authorAlyssa Rosenzweig <[email protected]>2020-03-24 13:40:12 -0400
committerMarge Bot <[email protected]>2020-03-31 01:12:26 +0000
commit39378eec578c4855dbcad19605242ca038e575ee (patch)
tree0569fb33de609cdd68ab6c9b55d488cb04af0589 /src/panfrost
parentfd18695a2697bf54cf11894959780c2c761a1808 (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>
Diffstat (limited to 'src/panfrost')
-rw-r--r--src/panfrost/encoder/pan_device.h6
-rw-r--r--src/panfrost/encoder/pan_props.c53
2 files changed, 59 insertions, 0 deletions
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);
+
+}