Skip to contentSkip to conversation

xf86drm: generalize the device subsystem type parsing code

PATCH RESEND In review Mikhail Golubev 2 participants 4 messages Jan 30, 2020 – Jan 31, 2020

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/2 xf86drm: generalize the device subsystem type parsing code

From: Vasyl Vavrychuk <[email protected]>

Move the code, which used to get the device subsystem type from a device path in sysfs, to a separate function to be reusable.

---
 xf86drm.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
xf86drm.c +16 -5
index 7ae41c37..b1479128 100644
@@ -2964,10 +2964,10 @@ sysfs_uevent_get(const char *path, const char *fmt, ...)
 /* Little white lie to avoid major rework of the existing code */
 #define DRM_BUS_VIRTIO 0x10
 
-static int drmParseSubsystemType(int maj, int min)
-{
 #ifdef __linux__
-    char path[PATH_MAX + 1];
+static int get_subsystem_type(const char *device_path)
+{
+    char path[PATH_MAX + 1] = "";
     char link[PATH_MAX + 1] = "";
     char *name;
     struct {
@@ -2982,8 +2982,8 @@ static int drmParseSubsystemType(int maj, int min)
         { "/virtio", DRM_BUS_VIRTIO },
     };
 
-    snprintf(path, PATH_MAX, "/sys/dev/char/%d:%d/device/subsystem",
-             maj, min);
+    strncpy(path, device_path, PATH_MAX);
+    strncat(path, "/subsystem", PATH_MAX);
 
     if (readlink(path, link, PATH_MAX) < 0)
         return -errno;
@@ -2998,6 +2998,17 @@ static int drmParseSubsystemType(int maj, int min)
     }
 
     return -EINVAL;
+}
+#endif
+
+static int drmParseSubsystemType(int maj, int min)
+{
+#ifdef __linux__
+    char path[PATH_MAX + 1] = "";
+
+    snprintf(path, PATH_MAX, "/sys/dev/char/%d:%d/device", maj, min);
+
+    return get_subsystem_type(path);
 #elif defined(__OpenBSD__) || defined(__DragonFly__)
     return DRM_BUS_PCI;
 #else
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH RESEND 2/2 xf86drm: fix subsystem type lookup for virtio mmio-based devices

From: Vasyl Vavrychuk <[email protected]>

Currently the code assumes that a virtio based device is always located on the PCI bus.

Modify the parser to make it check the device's parent directory to determine on which bus it is located.

Output for virtio-pci is the PCI bus.
Output for virtio-mmio is the Platform bus.

---
 xf86drm.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
xf86drm.c +11 -2
index b1479128..1b22efe4 100644
@@ -3005,10 +3005,20 @@ static int drmParseSubsystemType(int maj, int min)
 {
 #ifdef __linux__
     char path[PATH_MAX + 1] = "";
+    char real_path[PATH_MAX + 1] = "";
+    int subsystem_type;
 
     snprintf(path, PATH_MAX, "/sys/dev/char/%d:%d/device", maj, min);
+    if (!realpath(path, real_path))
+        return -errno;
+    strncpy(path, real_path, PATH_MAX);
 
-    return get_subsystem_type(path);
+    subsystem_type = get_subsystem_type(path);
+    if (subsystem_type == DRM_BUS_VIRTIO) {
+        strncat(path, "/..", PATH_MAX);
+        subsystem_type = get_subsystem_type(path);
+    }
+    return subsystem_type;
 #elif defined(__OpenBSD__) || defined(__DragonFly__)
     return DRM_BUS_PCI;
 #else
@@ -3710,7 +3720,6 @@ process_device(drmDevicePtr *device, const char *d_name,
 
     switch (subsystem_type) {
     case DRM_BUS_PCI:
-    case DRM_BUS_VIRTIO:
         return drmProcessPciDevice(device, node, node_type, maj, min,
                                    fetch_deviceinfo, flags);
     case DRM_BUS_USB:
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw
In reply to Mikhail Golubev

Hi Mikhail,

thanks for the patches.

Please create a merge request by clicking the "Fork" button on
https://gitlab.freedesktop.org/mesa/drm, pushing the two commits to a new branch in the newly created repository, and opening the URL in the "git push" output.

Thanks,

Signature · 6 lines
Earthling Michel Dänzer               |               https://redhat.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw

Hi Michel!

Thanks for reply.
Did create the merge request here:
https://gitlab.freedesktop.org/mesa/drm/merge_requests/43

BR,
Mikhail.

Quoted 14 lines · Michel Dänzer

Hi Mikhail,

thanks for the patches.

Please create a merge request by clicking the "Fork" button on
https://gitlab.freedesktop.org/mesa/drm, pushing the two commits to a new branch in the newly created repository, and opening the URL in the "git push" output.

Thanks,

Signature · 17 lines
Mikhail Golubev
Senior Software Engineer

OpenSynergy GmbH
Rotherstr. 20, 10245 Berlin

Telefon: +49 (30) 60 98 54 0 - 903
EMail:   [email protected]

www.opensynergy.com

Handelsregister/Commercial Registry: Amtsgericht Charlottenburg, HRB 108616B
Geschäftsführer/Managing Director: Regis Adjamah
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel