From 3c9b60ecf72d7f0bbf439b13ce5a6847d3b04ae0 Mon Sep 17 00:00:00 2001
From: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Date: Fri, 7 Mar 2025 09:28:42 -0500
Subject: [PATCH] DO NOT UPSTREAM: Probe unstable UAPI

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
---
 src/asahi/lib/agx_device.c            | 34 ++++-----------------------
 src/asahi/lib/unstable_asahi_drm.h    |  7 +-----
 src/asahi/vulkan/hk_physical_device.c |  3 ---
 src/gallium/drivers/asahi/agx_pipe.c  |  7 ------
 4 files changed, 6 insertions(+), 45 deletions(-)

diff --git a/src/asahi/lib/agx_device.c b/src/asahi/lib/agx_device.c
index 525f41a854595..0a8c54250ffb5 100644
--- a/src/asahi/lib/agx_device.c
+++ b/src/asahi/lib/agx_device.c
@@ -530,36 +530,12 @@ agx_open_device(void *memctx, struct agx_device *dev)
    }
    assert(params_size >= sizeof(dev->params));
 
-   /* Refuse to probe. */
    if (dev->params.unstable_uabi_version != DRM_ASAHI_UNSTABLE_UABI_VERSION) {
-      fprintf(
-         stderr,
-         "You are attempting to use upstream Mesa with a downstream kernel!\n"
-         "This WILL NOT work.\n"
-         "The Asahi UABI is unstable and NOT SUPPORTED in upstream Mesa.\n"
-         "UABI related code in upstream Mesa is not for use!\n"
-         "\n"
-         "Do NOT attempt to patch out checks, you WILL break your system.\n"
-         "Do NOT report bugs.\n"
-         "Do NOT ask Mesa developers for support.\n"
-         "Do NOT write guides about how to patch out these checks.\n"
-         "Do NOT package patches to Mesa to bypass this.\n"
-         "\n"
-         "~~~\n"
-         "This is not a place of honor.\n"
-         "No highly esteemed deed is commemorated here.\n"
-         "Nothing valued is here.\n"
-         "\n"
-         "What is here was dangerous and repulsive to us.\n"
-         "This message is a warning about danger.\n"
-         "\n"
-         "The danger is still present, in your time, as it was in ours.\n"
-         "The danger is unleashed only if you substantially disturb this place physically.\n"
-         "This place is best shunned and left uninhabited.\n"
-         "~~~\n"
-         "\n"
-         "THIS IS NOT A BUG. THIS IS YOU DOING SOMETHING BROKEN!\n");
-      abort();
+      fprintf(stderr, "UABI mismatch: Kernel %d, Mesa %d\n",
+              dev->params.unstable_uabi_version,
+              DRM_ASAHI_UNSTABLE_UABI_VERSION);
+      assert(0);
+      return false;
    }
 
    uint64_t incompat =
diff --git a/src/asahi/lib/unstable_asahi_drm.h b/src/asahi/lib/unstable_asahi_drm.h
index 06c96412a21b2..e5b55012fce1b 100644
--- a/src/asahi/lib/unstable_asahi_drm.h
+++ b/src/asahi/lib/unstable_asahi_drm.h
@@ -17,12 +17,7 @@
 extern "C" {
 #endif
 
-/*
- * The UAPI defined in this file MUST NOT BE USED. End users, DO NOT attempt to
- * use upstream Mesa with asahi kernels, it will blow up. Distro packagers, DO
- * NOT patch upstream Mesa to do the same.
- */
-#define DRM_ASAHI_UNSTABLE_UABI_VERSION (0xDEADBEEF)
+#define DRM_ASAHI_UNSTABLE_UABI_VERSION		10011
 
 #define DRM_ASAHI_GET_PARAMS			0x00
 #define DRM_ASAHI_VM_CREATE			0x01
diff --git a/src/asahi/vulkan/hk_physical_device.c b/src/asahi/vulkan/hk_physical_device.c
index c5334a0d67659..0429dc022a73d 100644
--- a/src/asahi/vulkan/hk_physical_device.c
+++ b/src/asahi/vulkan/hk_physical_device.c
@@ -1118,9 +1118,6 @@ hk_create_drm_physical_device(struct vk_instance *_instance,
    struct hk_instance *instance = (struct hk_instance *)_instance;
    VkResult result;
 
-   /* Blanket refusal to probe due to unstable UAPI. */
-   return VK_ERROR_INCOMPATIBLE_DRIVER;
-
    if (!(drm_device->available_nodes & (1 << DRM_NODE_RENDER)) ||
        drm_device->bustype != DRM_BUS_PLATFORM)
       return VK_ERROR_INCOMPATIBLE_DRIVER;
diff --git a/src/gallium/drivers/asahi/agx_pipe.c b/src/gallium/drivers/asahi/agx_pipe.c
index 8d5b647f0f84f..9ef236ee9c5d0 100644
--- a/src/gallium/drivers/asahi/agx_pipe.c
+++ b/src/gallium/drivers/asahi/agx_pipe.c
@@ -2488,13 +2488,6 @@ agx_screen_create(int fd, struct renderonly *ro,
    struct agx_screen *agx_screen;
    struct pipe_screen *screen;
 
-   /* Refuse to probe. There is no stable UAPI yet. Upstream Mesa cannot be used
-    * yet with Asahi. Do not try. Do not patch out this check. Do not teach
-    * others about patching this check. Do not distribute upstream Mesa with
-    * this check patched out.
-    */
-   return NULL;
-
    agx_screen = rzalloc(NULL, struct agx_screen);
    if (!agx_screen)
       return NULL;
-- 
GitLab