Files
RedBear-OS/local/patches/libdrm/P4-drmGetDeviceFromDevId-redox.patch
T
vasilito 2b11b20a2f 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).
2026-05-28 16:35:16 +03:00

69 lines
2.8 KiB
Diff

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;