@@ -29,6 +29,8 @@ bool pcie_memprotect(pcie_controller_t *ctl) {
29
29
// Initialise the PCIe controller.
30
30
// Init successful or not, takes ownership of the memory in `ctl`.
31
31
static bool pcie_controller_init () {
32
+ logkf (LOG_DEBUG , "PCIe config paddr: 0x%{size;x}" , ctl .config_paddr );
33
+
32
34
// Allocate ranges of virtual memory to map the controller into.
33
35
size_t bus_count = ctl .bus_end - ctl .bus_start + 1 ;
34
36
size_t config_size = bus_count * PCIE_ECAM_SIZE_PER_BUS ;
@@ -79,7 +81,7 @@ static void pcie_ecam_func_detect(uint8_t bus, uint8_t dev, uint8_t func) {
79
81
hdr -> classcode .subclass ,
80
82
hdr -> classcode .progif
81
83
);
82
- find_pci_driver (hdr -> classcode , (pci_addr_t ){bus , dev , func });
84
+ // find_pci_driver(hdr->classcode, (pci_addr_t){bus, dev, func});
83
85
}
84
86
85
87
// Enumerate device via ECAM.
@@ -380,12 +382,34 @@ static void
380
382
return ;
381
383
}
382
384
ctl .type = PCIE_CTYPE_SIFIVE_FU740 ;
385
+
386
+ // Read FU740 PCIe configuration space physical address.
387
+ ctl .config_paddr = dtb_read_cells (handle , node , "reg" , 4 , addr_cells );
388
+
389
+ // Read bus range.
390
+ dtb_prop_t * bus_range = dtb_get_prop (handle , node , "bus-range" );
391
+ if (bus_range -> content_len != 8 ) {
392
+ logk (LOG_ERROR , "Incorrect bus-range for PCI" );
393
+ goto malformed_dtb ;
394
+ }
395
+ ctl .bus_start = dtb_prop_read_cell (handle , bus_range , 0 );
396
+ ctl .bus_end = dtb_prop_read_cell (handle , bus_range , 1 );
397
+
398
+ // Read PCIe interrupt mappings.
399
+ if (!pci_dtb_irqmap (handle , node )) {
400
+ goto malformed_dtb ;
401
+ }
402
+
403
+ // Read PCIe range mappings.
383
404
if (!pci_dtb_ranges (handle , node )) {
384
- logk (LOG_WARN , "Malformed DTB; ignoring this PCIe controller!" );
385
- return ;
405
+ goto malformed_dtb ;
386
406
}
387
- // TODO: Find FU740 PCIe configuration space.
407
+
388
408
pcie_controller_init ();
409
+ return ;
410
+
411
+ malformed_dtb :
412
+ logk (LOG_WARN , "Initialization failed; ignoring this PCIe controller!" );
389
413
}
390
414
#endif
391
415
#endif
0 commit comments