From c586a2551e25ac10e2492c37d39440b03ec3f6b4 Mon Sep 17 00:00:00 2001 From: Bhushan Shah Date: Mon, 12 Oct 2020 23:34:11 +0530 Subject: [PATCH] Drop check for if parent subsystem is PCI This check is completely wrong for mobile GPUs where GPU are internal and are not attached through PCI subsystem, P: /devices/platform/display-engine/drm/card1 N: dri/card1 L: 0 S: dri/by-path/platform-display-engine-card E: DEVPATH=/devices/platform/display-engine/drm/card1 E: DEVNAME=/dev/dri/card1 E: DEVTYPE=drm_minor E: MAJOR=226 E: MINOR=1 E: SUBSYSTEM=drm E: USEC_INITIALIZED=4239383 E: ID_PATH=platform-display-engine E: ID_PATH_TAG=platform-display-engine E: ID_FOR_SEAT=drm-platform-display-engine E: DEVLINKS=/dev/dri/by-path/platform-display-engine-card E: TAGS=:master-of-seat:seat:uaccess: For example, on A64 platform, the KMS capable card is card1 which is not attached with PCI. --- udev.cpp | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/udev.cpp b/udev.cpp index f6a9e63aca..2c90c99a4e 100644 --- a/udev.cpp +++ b/udev.cpp @@ -114,8 +114,7 @@ std::vector UdevEnumerate::find() if (deviceSeat != LogindIntegration::self()->seat()) { continue; } - if (device->getParentWithSubsystemDevType("pci")) - vect.push_back(std::move(device)); + vect.push_back(std::move(device)); } return vect; } @@ -140,17 +139,22 @@ std::vector Udev::listGPUs() std::sort(vect.begin(), vect.end(), [](const UdevDevice::Ptr &device1, const UdevDevice::Ptr &device2) { auto pci1 = device1->getParentWithSubsystemDevType("pci"); auto pci2 = device2->getParentWithSubsystemDevType("pci"); + const char *systAttrValue; // if set as boot GPU, prefer 1 - const char *systAttrValue = udev_device_get_sysattr_value(pci1, "boot_vga"); - if (systAttrValue && qstrcmp(systAttrValue, "1") == 0) { - return true; + if (pci1) { + systAttrValue = udev_device_get_sysattr_value(pci1, "boot_vga"); + if (systAttrValue && qstrcmp(systAttrValue, "1") == 0) { + return true; + } } // if set as boot GPU, prefer 2 - systAttrValue = udev_device_get_sysattr_value(pci2, "boot_vga"); - if (systAttrValue && qstrcmp(systAttrValue, "1") == 0) { - return false; + if (pci2) { + systAttrValue = udev_device_get_sysattr_value(pci2, "boot_vga"); + if (systAttrValue && qstrcmp(systAttrValue, "1") == 0) { + return false; + } } - return udev_device_get_sysnum(pci1) > udev_device_get_sysnum(pci2); + return true; }); return vect; #endif @@ -171,17 +175,22 @@ std::vector Udev::listFramebuffers() std::sort(vect.begin(), vect.end(), [](const UdevDevice::Ptr &device1, const UdevDevice::Ptr &device2) { auto pci1 = device1->getParentWithSubsystemDevType("pci"); auto pci2 = device2->getParentWithSubsystemDevType("pci"); + const char *systAttrValue; // if set as boot GPU, prefer 1 - const char *systAttrValue = udev_device_get_sysattr_value(pci1, "boot_vga"); - if (systAttrValue && qstrcmp(systAttrValue, "1") == 0) { - return true; + if (pci1) { + systAttrValue = udev_device_get_sysattr_value(pci1, "boot_vga"); + if (systAttrValue && qstrcmp(systAttrValue, "1") == 0) { + return true; + } } // if set as boot GPU, prefer 2 - systAttrValue = udev_device_get_sysattr_value(pci2, "boot_vga"); - if (systAttrValue && qstrcmp(systAttrValue, "1") == 0) { - return false; + if (pci2) { + systAttrValue = udev_device_get_sysattr_value(pci2, "boot_vga"); + if (systAttrValue && qstrcmp(systAttrValue, "1") == 0) { + return false; + } } - return udev_device_get_sysnum(pci1) > udev_device_get_sysnum(pci2); + return true; }); return vect; }