tech-x11 archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

libdrm interface



I have been doing some tracing of how libdrm gets back the 'unique'
string from the DRM drivers kernel and am not finding it to be very
reliable.

Sometimes I get back a valid string.

Other times, get back a length of zero for the string, the drmGetBusid()
function doesn't check for this and returns an empty one byte string.

Third case, the ioctl calls to set the version fail when the file
descriptor used is not the one picked to be the "master" device.

This is used by drmParseSubsystemType() in libdrm and gets called
multiple times during startup of anything using MesaLib.

I'm testing it with wip/kmscube so it is the only drm application
talking to the kernel at that time, have tried it against amdgpu
and panfrost.

With amdgpu, one of the times that drmGetBusid() fails is at the
point that mesa should detect that it is a PCI device then use the
vendor and device IDs to decide which driver to use, so it falls back
to software rendering.

Newer versions of mesa have changed how they start up to look more like
what kmscube is doing. I recently created a wip/mesa package and had
started trying to debug it.


I have a couple of local changes to kernel and userland to make libdrm
work with non-pci devices.

The kernel change is below which makes the default unique string be the
name of the drm_driver not the NetBSD driver instance, so you get back
e.g. "panfrost" and "rockchip" from the GPU and display devices instead
of "panfrost0" and "rkdrm0", these strings need to match the mesa
symlinks to gallium_dri.so for the loader code to work.

A PCI device will still override this with a "pci:XXX" value for the
string.

Index: drm_drv.c
===================================================================
RCS file: /cvsroot/src/sys/external/bsd/drm2/dist/drm/drm_drv.c,v
retrieving revision 1.24
diff -u -r1.24 drm_drv.c
--- drm_drv.c   15 Oct 2022 15:19:28 -0000      1.24
+++ drm_drv.c   22 Jun 2025 16:20:04 -0000
@@ -739,7 +739,11 @@
                }
        }
 
+#ifdef __NetBSD__
+       ret = drm_dev_set_unique(dev, driver->name);
+#else
        ret = drm_dev_set_unique(dev, dev_name(parent));
+#endif
        if (ret)
                goto err_setunique;
 

The userland change is to xf86drm.c in libdrm to just return
DRM_BUS_PLATFORM from drmPartSubsystemType() if the unique string
doesn't start with "pci:".

     ret = -EINVAL;
     if (strncmp(buf, "pci:", 4) == 0)
        ret = DRM_BUS_PCI;
+    else
+        ret = DRM_BUS_PLATFORM;
 
     /* We're done with the bus id.  */
     free(buf);


Original PRs for this area were 51786 and 51795, some alternative ways
of doing things were discussed but I think that having a reliable way of
getting the unique string from the kernel results in fewest changes in
mesa & libdrm.


Home | Main Index | Thread Index | Old Index