ECAM access formula in PCI Express page is wrong
Posted: Tue Apr 30, 2024 9:37 am
From the PCI_Express wiki:
Why subtract the starting bus address here? From my reading of the PCI firmware specification, the starting bus address is where you must start enumerating relative to the ECAM base. Whatever PCI device bdfs you successfully enumerate from there, you would just use those bus numbers directly relative to the base. They would be greater than the starting bus address anyway.To access a specific register within a device's PCI configuration space, you have to use the device's PCI Segment Group and bus to determine which memory mapped PCI configuration space area to use, and obtain the starting physical address and starting bus number for that memory mapped area. Once you have the correct starting physical address and starting bus number for that memory mapped area you would use the following formula to determine where the (4096-byte) area for a function's PCI configuration space is: Physical_Address = MMIO_Starting_Physical_Address + ((Bus - MMIO_Starting_Bus) << 20 | Device << 15 | Function << 12).