Blame SOURCES/0001-linux-Make-platform-device-probe-less-fragile.patch

0bac9e
From b96e7972e90144a697401f393ae8e1e12b3e767c Mon Sep 17 00:00:00 2001
0bac9e
From: Adam Jackson <ajax@redhat.com>
0bac9e
Date: Tue, 18 Sep 2018 14:37:51 -0400
0bac9e
Subject: [PATCH] linux: Make platform device probe less fragile
0bac9e
0bac9e
If we have platform devices - and we usually do - we would really want
0bac9e
them to bind through the platform bus code not PCI. At the point where
0bac9e
get_drm_info runs, however, we haven't yet taken our own VT, which means
0bac9e
we can't perform drm "master" operations on the device. This is tragic,
0bac9e
because the operation we need to perform here is fishing the bus id out
0bac9e
of the kernel, which we can only do after drmSetInterfaceVersion, which
0bac9e
for some reason stores that knowledge on the device not the file handle
0bac9e
and thus needs master access. Since we fail, the probe logic gets very
0bac9e
confused.
0bac9e
0bac9e
Fortunately we know the format of the busid string (it's our own, drm
0bac9e
copied it from xfree86), so we can scrape that out of the sysfs path. We
0bac9e
do still potentially do the whole SetInterfaceVersion dance later on,
0bac9e
but it's harmless at that point because we've taken the VT by then.
0bac9e
0bac9e
This should all be vastly simplified, but that is not the cat we're
0bac9e
skinning today.
0bac9e
---
0bac9e
 hw/xfree86/os-support/linux/lnx_platform.c | 22 ++++++++++++----------
0bac9e
 1 file changed, 12 insertions(+), 10 deletions(-)
0bac9e
0bac9e
diff --git a/hw/xfree86/os-support/linux/lnx_platform.c b/hw/xfree86/os-support/linux/lnx_platform.c
0bac9e
index 70374ac..cbf7dd2 100644
0bac9e
--- a/hw/xfree86/os-support/linux/lnx_platform.c
0bac9e
+++ b/hw/xfree86/os-support/linux/lnx_platform.c
0bac9e
@@ -29,6 +29,9 @@ get_drm_info(struct OdevAttributes *attribs, char *path, int delayed_index)
0bac9e
     int fd;
0bac9e
     int err = 0;
0bac9e
     Bool paused, server_fd = FALSE;
0bac9e
+    const char pci_prefix[] = "/sys/devices/pci";
0bac9e
+
0bac9e
+    LogMessage(X_INFO, "Platform probe for %s\n", attribs->syspath);
0bac9e
 
0bac9e
     fd = systemd_logind_take_fd(attribs->major, attribs->minor, path, &paused);
0bac9e
     if (fd != -1) {
0bac9e
@@ -53,13 +56,6 @@ get_drm_info(struct OdevAttributes *attribs, char *path, int delayed_index)
0bac9e
     sv.drm_dd_major = -1;       /* Don't care */
0bac9e
     sv.drm_dd_minor = -1;       /* Don't care */
0bac9e
 
0bac9e
-    err = drmSetInterfaceVersion(fd, &sv;;
0bac9e
-    if (err) {
0bac9e
-        xf86Msg(X_ERROR, "%s: failed to set DRM interface version 1.4: %s\n",
0bac9e
-                path, strerror(-err));
0bac9e
-        goto out;
0bac9e
-    }
0bac9e
-
0bac9e
     /* for a delayed probe we've already added the device */
0bac9e
     if (delayed_index == -1) {
0bac9e
             xf86_add_platform_device(attribs, FALSE);
0bac9e
@@ -69,9 +65,15 @@ get_drm_info(struct OdevAttributes *attribs, char *path, int delayed_index)
0bac9e
     if (server_fd)
0bac9e
         xf86_platform_devices[delayed_index].flags |= XF86_PDEV_SERVER_FD;
0bac9e
 
0bac9e
-    buf = drmGetBusid(fd);
0bac9e
-    xf86_platform_odev_attributes(delayed_index)->busid = XNFstrdup(buf);
0bac9e
-    drmFreeBusid(buf);
0bac9e
+    /* parse out a bus id */
0bac9e
+    if (!strncmp(attribs->syspath, pci_prefix, strlen(pci_prefix))) {
0bac9e
+        char *dbdf = attribs->syspath + strlen(pci_prefix) + strlen("XXXX:XX") + 1;
0bac9e
+        asprintf(&xf86_platform_odev_attributes(delayed_index)->busid,
0bac9e
+                 "pci:%.12s", dbdf);
0bac9e
+        LogMessage(X_INFO, "Platform PCI device at %s\n",
0bac9e
+                   xf86_platform_odev_attributes(delayed_index)->busid);
0bac9e
+    }
0bac9e
+
0bac9e
 
0bac9e
     v = drmGetVersion(fd);
0bac9e
     if (!v) {
0bac9e
-- 
0bac9e
2.17.1
0bac9e