panfrost: Record architecture major version

This tends to be easier to work with than the raw GPU ID and needs some
special casing for Midgard vs Bifrost/Valhall.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7206>
diff --git a/src/panfrost/lib/pan_device.h b/src/panfrost/lib/pan_device.h
index 9a7b31d..664204e 100644
--- a/src/panfrost/lib/pan_device.h
+++ b/src/panfrost/lib/pan_device.h
@@ -96,6 +96,7 @@
         int fd;
 
         /* Properties of the GPU in use */
+        unsigned arch;
         unsigned gpu_id;
         unsigned core_count;
         unsigned thread_tls_alloc;
diff --git a/src/panfrost/lib/pan_props.c b/src/panfrost/lib/pan_props.c
index 831b203..627828c 100644
--- a/src/panfrost/lib/pan_props.c
+++ b/src/panfrost/lib/pan_props.c
@@ -132,6 +132,29 @@
         return dev->compressed_formats & (1 << idx);
 }
 
+/* Returns the architecture version given a GPU ID, either from a table for
+ * old-style Midgard versions or directly for new-style Bifrost/Valhall
+ * versions */
+
+static unsigned
+panfrost_major_version(unsigned gpu_id)
+{
+        switch (gpu_id) {
+        case 0x600:
+        case 0x620:
+        case 0x720:
+                return 4;
+        case 0x750:
+        case 0x820:
+        case 0x830:
+        case 0x860:
+        case 0x880:
+                return 5;
+        default:
+                return gpu_id >> 12;
+        }
+}
+
 /* Given a GPU ID like 0x860, return a prettified model name */
 
 const char *
@@ -160,6 +183,7 @@
         dev->fd = fd;
         dev->memctx = memctx;
         dev->gpu_id = panfrost_query_gpu_version(fd);
+        dev->arch = panfrost_major_version(dev->gpu_id);
         dev->core_count = panfrost_query_core_count(fd);
         dev->thread_tls_alloc = panfrost_query_thread_tls_alloc(fd);
         dev->kernel_version = drmGetVersion(fd);