The PCIe bus is now queried for devices and the device IDs are printed
2 files changed, 19 insertions(+), 0 deletions(-)

M kernel/src/acpi.c
M kernel/src/pcie.c
M kernel/src/acpi.c +2 -0
@@ 23,6 23,7 @@ 
 
 #include <mem.h>
 #include <apic.h>
+#include <pcie.h>
 #include <panic.h>
 #include <printf.h>
 

          
@@ 249,6 250,7 @@ void acpi_init(EFI_SYSTEM_TABLE* system_
 		} else if(cmpsig(sdt->signature, "MCFG", 4)) {
 			mcfg = (struct mcfg*) sdt;
 			verify(mcfg, "MCFG");
+			pcie_init(mcfg);
 		}
 	}
 

          
M kernel/src/pcie.c +17 -0
@@ 17,6 17,9 @@ 
 
 #include <pcie.h>
 
+#include <mem.h>
+#include <printf.h>
+
 struct pcie_cmd {
 	uint8_t padding1:2;
 	bool bus_master_enable:1;

          
@@ 102,5 105,19 @@ struct pcie_port {
 } __attribute__((packed));
 
 void pcie_init(struct mcfg* mcfg) {
+	uint64_t entry_count = (mcfg->header.length - sizeof(struct mcfg)) / sizeof(struct mcfg_entry);
 
+	for(uint64_t count = 0; count < entry_count; ++count) {
+		struct mcfg_entry* entry = (struct mcfg_entry*) LOW_TO_HIGH((uint64_t) (mcfg->entries + count));
+
+		for(uint64_t count = entry->start_bus; count < entry->end_bus; ++count) {
+			for(uint64_t dev = 0; dev < 8; ++dev) {
+				struct pcie_header* hdr = (struct pcie_header*) LOW_TO_HIGH((entry->base_addr + (0x100000 * (count - entry->start_bus)) + (0x8000 * dev)));
+				if(hdr->vendor_id == 0xFFFF) {
+					continue;
+				}
+				kprintf("PCIe device: %X:%X\n", hdr->vendor_id, hdr->device_id);
+			}
+		}
+	}
 }