Commit 5eed0d51 authored by Arjen Hiemstra's avatar Arjen Hiemstra
Browse files

GPU: Query for DRM devices and use DRM number as card number

The order in which PCI devices are enumerated can apparently change with
some driver changes. This means that GPU 1 suddenly becomes GPU 2 and
the other way around. The DRM subsystem does seem to have a consistent
numbering for these devices, so query the DRM subsystem for devices and
use its numbering for GPU indexing so that it remains stable.

BUG: 453283
parent 18a85e54
Pipeline #190892 passed with stage
in 3 minutes and 4 seconds
......@@ -33,39 +33,43 @@ void LinuxBackend::start()
auto enumerate = udev_enumerate_new(m_udev);
udev_enumerate_add_match_property(enumerate, "ID_PCI_CLASS_FROM_DATABASE", "Display controller");
udev_enumerate_add_match_subsystem(enumerate, "pci");
udev_enumerate_add_match_property(enumerate, "DEVTYPE", "drm_minor");
udev_enumerate_add_match_subsystem(enumerate, "drm");
int gpuCounter = 0;
auto devices = udev_enumerate_get_list_entry(enumerate);
for (auto entry = devices; entry; entry = udev_list_entry_get_next(entry)) {
auto path = udev_list_entry_get_name(entry);
auto device = udev_device_new_from_syspath(m_udev, path);
auto drmDevice = udev_device_new_from_syspath(m_udev, path);
auto pciDevice = udev_device_get_parent(drmDevice);
if (strstr(udev_device_get_sysname(drmDevice), "render") != NULL) {
auto vendor = QByteArray(udev_device_get_sysattr_value(device, "vendor"));
auto vendor = QByteArray(udev_device_get_sysattr_value(pciDevice, "vendor"));
auto drmNumber = std::atoi(udev_device_get_sysnum(drmDevice));
auto gpuId = QStringLiteral("gpu%1").arg(gpuCounter);
auto gpuName = i18nc("@title %1 is GPU number", "GPU %1", gpuCounter + 1);
auto gpuId = QStringLiteral("gpu%1").arg(drmNumber);
auto gpuName = i18nc("@title %1 is GPU number", "GPU %1", drmNumber + 1);
GpuDevice *gpu = nullptr;
if (vendor == amdVendor) {
gpu = new LinuxAmdGpu{gpuId, gpuName, device};
gpu = new LinuxAmdGpu{gpuId, gpuName, pciDevice};
} else if (vendor == nvidiaVendor) {
gpu = new LinuxNvidiaGpu{gpuCounter, gpuId, gpuName};
gpu = new LinuxNvidiaGpu{drmNumber, gpuId, gpuName};
} else {
qDebug() << "Found unsupported GPU:" << path;
Q_EMIT deviceAdded(gpu);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment