panfrost: Query core count and thread tls alloc
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Mon, 9 Dec 2019 14:06:51 +0000 (09:06 -0500)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Fri, 13 Dec 2019 00:47:23 +0000 (00:47 +0000)
This is supported only on newer kernels.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
src/gallium/drivers/panfrost/pan_screen.c
src/gallium/drivers/panfrost/pan_screen.h

index ff9e93e5c00ed7308c1da97ef575b670e441add8..aecfe6960445cdfa6bc8f416ede398723aeb84eb 100644 (file)
@@ -674,7 +674,8 @@ static __u64
 panfrost_query_raw(
                 struct panfrost_screen *screen,
                 enum drm_panfrost_param param,
-                bool required)
+                bool required,
+                unsigned default_value)
 {
         struct drm_panfrost_get_param get_param = {0,};
         ASSERTED int ret;
@@ -682,7 +683,10 @@ panfrost_query_raw(
         get_param.param = DRM_PANFROST_PARAM_GPU_PROD_ID;
         ret = drmIoctl(screen->fd, DRM_IOCTL_PANFROST_GET_PARAM, &get_param);
 
-        assert(!(ret && required));
+        if (ret) {
+                assert(!required);
+                return default_value;
+        }
 
         return get_param.value;
 }
@@ -690,7 +694,28 @@ panfrost_query_raw(
 static unsigned
 panfrost_query_gpu_version(struct panfrost_screen *screen)
 {
-        return panfrost_query_raw(screen, DRM_PANFROST_PARAM_GPU_PROD_ID, true);
+        return panfrost_query_raw(screen, DRM_PANFROST_PARAM_GPU_PROD_ID, true, 0);
+}
+
+static unsigned
+panfrost_query_core_count(struct panfrost_screen *screen)
+{
+        /* On older kernels, worst-case to 16 cores */
+
+        unsigned mask = panfrost_query_raw(screen,
+                        DRM_PANFROST_PARAM_SHADER_PRESENT, false, 0xffff);
+
+        return util_bitcount(mask);
+}
+
+static unsigned
+panfrost_query_thread_tls_alloc(struct panfrost_screen *screen)
+{
+        /* On older kernels, we worst-case to 1024 threads, the architectural
+         * maximum for Midgard */
+
+        return panfrost_query_raw(screen,
+                        DRM_PANFROST_PARAM_THREAD_TLS_ALLOC, false, 1024);
 }
 
 static uint32_t
@@ -744,6 +769,8 @@ panfrost_create_screen(int fd, struct renderonly *ro)
         screen->fd = fd;
 
         screen->gpu_id = panfrost_query_gpu_version(screen);
+        screen->core_count = panfrost_query_core_count(screen);
+        screen->thread_tls_alloc = panfrost_query_thread_tls_alloc(screen);
         screen->quirks = panfrost_get_quirks(screen->gpu_id);
         screen->kernel_version = drmGetVersion(fd);
 
index 974010ae9946f84ea80981a57d074cb5f7e40042..348b8e759c62b74701c49cac309f7d30ab38caa4 100644 (file)
@@ -80,6 +80,8 @@ struct panfrost_screen {
 
         /* Properties of the GPU in use */
         unsigned gpu_id;
+        unsigned core_count;
+        unsigned thread_tls_alloc;
         unsigned quirks;
 
         drmVersionPtr kernel_version;