libdrm: fix drmGetDeviceFromDevId for Redox (P4)

Add #ifdef __redox__ path to drmGetDeviceFromDevId() that mirrors the
working drmGetDevice2() Redox implementation. On Redox there is no
/dev/dri/ directory — DRM devices are accessed via /scheme/drm/card0.
The patch constructs a drmDevice with both PRIMARY and RENDER nodes
pointing to /scheme/drm/card0, since the redox-drm scheme serves both
roles through a single endpoint.

Also fixes drmParseSubsystemType() to return DRM_BUS_PCI on Redox.

Fix P3 patch paths (strip local/recipes/libs/libdrm/source/ prefix
from diff headers so patches apply correctly during repo fetch).
This commit is contained in:
2026-05-28 16:35:16 +03:00
parent cb50169517
commit 2b11b20a2f
3 changed files with 75 additions and 7 deletions
@@ -1,7 +1,7 @@
diff --git a/local/recipes/libs/libdrm/source/xf86drm.c b/local/recipes/libs/libdrm/source/xf86drm.c
diff --git a/xf86drm.c b/xf86drm.c
index 1b206ccd4..c3904caa3 100644
--- a/local/recipes/libs/libdrm/source/xf86drm.c
+++ b/local/recipes/libs/libdrm/source/xf86drm.c
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -1774,0 +1775,23 @@ drm_public drmVersionPtr drmGetVersion(int fd)
+
+ /* The scheme returns a NUL-terminated driver name in version.name.
@@ -26,9 +26,9 @@ index 1b206ccd4..c3904caa3 100644
+ }
+ }
+
diff --git a/local/recipes/libs/libdrm/source/xf86drm_redox.h b/local/recipes/libs/libdrm/source/xf86drm_redox.h
diff --git a/xf86drm_redox.h b/xf86drm_redox.h
index c1abe8256..7f9d252fa 100644
--- a/local/recipes/libs/libdrm/source/xf86drm_redox.h
+++ b/local/recipes/libs/libdrm/source/xf86drm_redox.h
--- a/xf86drm_redox.h
+++ b/xf86drm_redox.h
@@ -140,0 +141 @@ struct redox_drm_version_wire {
+ char name[64];
@@ -0,0 +1,68 @@
diff --git a/xf86drm.c b/xf86drm.c
index c3904caa3..306026e8b 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -4096 +4096 @@ static int drmParseSubsystemType(int maj, int min)
-#elif defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD__)
+#elif defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__redox__)
@@ -5122,0 +5123,60 @@ drm_public int drmGetDeviceFromDevId(dev_t find_rdev, uint32_t flags, drmDeviceP
+ return 0;
+#elif defined(__redox__)
+ /* On Redox there is no /dev/dri/ directory to enumerate.
+ * Instead, open /scheme/drm/card0 and query PCI info to
+ * construct a single drmDevice that serves as both primary
+ * and render node. */
+ drmDevicePtr devp;
+ char *pptr;
+ int max_node_length = 64, i;
+ size_t extra, psize;
+ uint8_t pbuf[22];
+ size_t prsize = 0;
+ int pret, fd;
+
+ if (device == NULL)
+ return -EINVAL;
+ if (drm_device_validate_flags(flags))
+ return -EINVAL;
+
+ fd = open("/scheme/drm/card0", O_RDWR | O_CLOEXEC);
+ if (fd < 0)
+ return -errno;
+
+ pret = redox_drm_exchange(fd, REDOX_DRM_IOCTL_GET_PCI_INFO, NULL, 0,
+ pbuf, sizeof(pbuf), &prsize);
+ close(fd);
+ if (pret != 0 || prsize < 17)
+ return -EIO;
+
+ extra = DRM_NODE_MAX * (sizeof(void *) + max_node_length);
+ psize = sizeof(drmDevice) + extra + sizeof(drmPciBusInfo) + sizeof(drmPciDeviceInfo);
+ devp = calloc(1, psize);
+ if (!devp)
+ return -ENOMEM;
+
+ devp->bustype = DRM_BUS_PCI;
+ /* Advertise both PRIMARY and RENDER — same path on Redox */
+ devp->available_nodes = (1 << DRM_NODE_PRIMARY) | (1 << DRM_NODE_RENDER);
+ pptr = (char *)devp + sizeof(drmDevice);
+ devp->nodes = (char **)pptr;
+ pptr += DRM_NODE_MAX * sizeof(void *);
+ for (i = 0; i < DRM_NODE_MAX; i++) { devp->nodes[i] = pptr; pptr += max_node_length; }
+ snprintf(devp->nodes[DRM_NODE_PRIMARY], max_node_length, "/scheme/drm/card0");
+ snprintf(devp->nodes[DRM_NODE_RENDER], max_node_length, "/scheme/drm/card0");
+
+ devp->businfo.pci = (drmPciBusInfoPtr)pptr;
+ pptr += sizeof(drmPciBusInfo);
+ devp->businfo.pci->domain = pbuf[10] | (pbuf[11] << 8) | (pbuf[12] << 16) | (pbuf[13] << 24);
+ devp->businfo.pci->bus = pbuf[14];
+ devp->businfo.pci->dev = pbuf[15];
+ devp->businfo.pci->func = pbuf[16];
+
+ devp->deviceinfo.pci = (drmPciDeviceInfoPtr)pptr;
+ devp->deviceinfo.pci->vendor_id = pbuf[0] | (pbuf[1] << 8);
+ devp->deviceinfo.pci->device_id = pbuf[2] | (pbuf[3] << 8);
+ devp->deviceinfo.pci->subvendor_id = pbuf[4] | (pbuf[5] << 8);
+ devp->deviceinfo.pci->subdevice_id = pbuf[6] | (pbuf[7] << 8);
+ devp->deviceinfo.pci->revision_id = pbuf[8];
+
+ *device = devp;
+1 -1
View File
@@ -1,7 +1,7 @@
[source]
tar = "https://gitlab.freedesktop.org/mesa/libdrm/-/archive/libdrm-2.4.125/libdrm-libdrm-2.4.125.tar.gz"
blake3 = "33e6448252639f4ff8a8cd30129b335c5d85356c1c93f8d77a79221003b14f66"
patches = ["redox.patch", "../../../patches/libdrm/P1-drm-ioctl-bridge.patch", "../../../patches/libdrm/P2-drm-get-pci-info.patch", "../../../patches/libdrm/P3-drm-get-version-driver-name.patch"]
patches = ["redox.patch", "../../../patches/libdrm/P1-drm-ioctl-bridge.patch", "../../../patches/libdrm/P2-drm-get-pci-info.patch", "../../../patches/libdrm/P3-drm-get-version-driver-name.patch", "../../../patches/libdrm/P4-drmGetDeviceFromDevId-redox.patch"]
[build]
template = "meson"