/* SPDX-License-Identifier: GPL-2.0-only */ #include #include uint16_t pci_config_read_word(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset) { uint32_t addr; uint32_t lbus = bus; uint32_t lslot = slot; uint32_t lfunc = func; uint16_t tmp = 0; addr = (lbus << 16) | (lslot << 11) | (lfunc << 8) | (offset & 0xfc) | 0x80000000; outl(PCIPM_CONFIG_ADDRESS, addr); tmp = (uint16_t)((inl(PCIPM_CONFIG_DATA) >> ((offset & 2) << 3)) & 0xFFFF); return tmp; } static void pci_print_bus(uint8_t bus) { for (uint8_t slot = 0; slot < 32; slot++) { uint16_t vendor_id = pci_config_read_word(bus, slot, 0, 0); if (vendor_id == 0xFFFF) continue; uint8_t class = pci_config_read_word(bus, slot, 0, 0xA); if(class == 0xFF) continue; uint8_t subclass = (pci_config_read_word(bus, slot, 0, 0xA) >> 8); printf(LOG_INFO "PCI device [bus:%xh slot:%xh]: class=%xh sub=%xh\n", bus, slot, class, subclass); } } void pci_init() { for (int bus = 0; bus < 256; bus++) pci_print_bus(bus); }