]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
stub: Do a single PCI read to get the vendor and device ID
authorDaan De Meyer <daan@amutable.com>
Wed, 1 Apr 2026 15:11:44 +0000 (17:11 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 2 Apr 2026 12:58:42 +0000 (14:58 +0200)
src/boot/stub.c

index 6b5ae0a68786c650f5f58b5a6348d8125eb9ac18..02621b68bb928fcd457e7ae689074d7f33180dae 100644 (file)
@@ -1276,15 +1276,14 @@ static bool has_virtio_console_pci_device(void) {
                 if (BS->HandleProtocol(handles[i], MAKE_GUID_PTR(EFI_PCI_IO_PROTOCOL), (void **) &pci_io) != EFI_SUCCESS)
                         continue;
 
-                uint16_t vendor_id = 0, device_id = 0;
-                if (pci_io->Pci.Read(pci_io, EfiPciIoWidthUint16, 0x00, 1, &vendor_id) != EFI_SUCCESS)
-                        continue;
-                if (pci_io->Pci.Read(pci_io, EfiPciIoWidthUint16, 0x02, 1, &device_id) != EFI_SUCCESS)
+                /* Read PCI vendor ID and device ID (at offsets 0x00 and 0x02 in PCI config space) */
+                uint16_t pci_id[2] = {};
+                if (pci_io->Pci.Read(pci_io, EfiPciIoWidthUint16, /* offset= */ 0x00, /* count= */ 2, pci_id) != EFI_SUCCESS)
                         continue;
 
-                log_debug("PCI device %zu: vendor=%04x device=%04x", i, vendor_id, device_id);
+                log_debug("PCI device %zu: vendor=%04x device=%04x", i, pci_id[0], pci_id[1]);
 
-                if (vendor_id == PCI_VENDOR_ID_REDHAT && device_id == PCI_DEVICE_ID_VIRTIO_CONSOLE)
+                if (pci_id[0] == PCI_VENDOR_ID_REDHAT && pci_id[1] == PCI_DEVICE_ID_VIRTIO_CONSOLE)
                         n_virtio_console++;
 
                 if (n_virtio_console > 1) {