[RFC PATCH] config/udev: determine bus id from pci name

Maarten Lankhorst maarten.lankhorst at canonical.com
Wed Mar 20 06:03:14 PDT 2013


It seems ODEV_ATTRIB_BUSID is only used in xf86platformProbe for pci devices,
and there's no need to open the drm device to find out the pci id. It
can be determined from the sysfs path.

/sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/drm/card0 will become pci:0000:01:00.0 here.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst at canonical.com>

---
diff --git a/config/udev.c b/config/udev.c
index 454838f..af133d2 100644
--- a/config/udev.c
+++ b/config/udev.c
@@ -98,7 +98,7 @@ device_added(struct udev_device *udev_device)
         if (strncmp(sysname, "card", 4) != 0)
             return;
 
-        LogMessage(X_INFO, "config/udev: Adding drm device (%s)\n", path);
+        LogMessage(X_INFO, "config/udev: Adding drm device (%s) %s %s\n", path, sysname, syspath);
 
         config_udev_odev_setup_attribs(path, syspath, NewGPUDeviceRequest);
         return;
@@ -267,7 +267,7 @@ device_removed(struct udev_device *device)
 
         if (strncmp(sysname,"card", 4) != 0)
             return;
-        ErrorF("removing GPU device %s %d\n", syspath, path);
+        ErrorF("removing GPU device %s %s\n", syspath, path);
         if (!path)
             return;
 
@@ -437,6 +437,16 @@ config_udev_odev_setup_attribs(const char *path, const char *syspath,
     if (ret == FALSE)
         goto fail;
 
+    if (strstr(syspath, "/devices/pci")) {
+        const char *end = strstr(syspath, "/drm/card");
+        if (end && end - 12 > syspath) {
+            char pci_str[17] = "pci:";
+
+            strncpy(pci_str + 4, end - 12, 12);
+            ret = config_odev_add_attribute(attribs, ODEV_ATTRIB_BUSID, pci_str);
+        }
+    }
+
     /* ownership of attribs is passed to probe layer */
     probe_callback(attribs);
     return TRUE;
diff --git a/hw/xfree86/os-support/linux/lnx_platform.c b/hw/xfree86/os-support/linux/lnx_platform.c
index 76f5583..11bb9fc 100644
--- a/hw/xfree86/os-support/linux/lnx_platform.c
+++ b/hw/xfree86/os-support/linux/lnx_platform.c
@@ -17,36 +17,6 @@
 
 #include "hotplug.h"
 
-static Bool
-get_drm_info(struct OdevAttributes *attribs, char *path)
-{
-    drmSetVersion sv;
-    char *buf;
-    int fd;
-
-    fd = open(path, O_RDWR, O_CLOEXEC);
-    if (fd == -1)
-        return FALSE;
-
-    sv.drm_di_major = 1;
-    sv.drm_di_minor = 4;
-    sv.drm_dd_major = -1;       /* Don't care */
-    sv.drm_dd_minor = -1;       /* Don't care */
-    if (drmSetInterfaceVersion(fd, &sv)) {
-        ErrorF("setversion 1.4 failed\n");
-        return FALSE;
-    }
-
-    xf86_add_platform_device(attribs);
-
-    buf = drmGetBusid(fd);
-    xf86_add_platform_device_attrib(xf86_num_platform_devices - 1,
-                                    ODEV_ATTRIB_BUSID, buf);
-    drmFreeBusid(buf);
-    close(fd);
-    return TRUE;
-}
-
 Bool
 xf86PlatformDeviceCheckBusID(struct xf86_platform_device *device, const char *busid)
 {
@@ -119,10 +89,6 @@ xf86PlatformDeviceProbe(struct OdevAttributes *attribs)
     LogMessage(X_INFO, "config/udev: Adding drm device (%s)\n",
                path);
 
-    ret = get_drm_info(attribs, path);
-    if (ret == FALSE)
-        goto out_free;
-
     return;
 
 out_free:



More information about the xorg-devel mailing list