OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Jun 14, 2024 6:17 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: ECAM access formula in PCI Express page is wrong
PostPosted: Tue Apr 30, 2024 9:37 am 
Offline

Joined: Sat Mar 12, 2022 1:43 am
Posts: 3
From the PCI_Express wiki:
Quote:
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).

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.


Top
 Profile  
 
 Post subject: Re: ECAM access formula in PCI Express page is wrong
PostPosted: Tue Apr 30, 2024 10:41 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5215
I'm not sure if that's outright wrong or just poor wording. The address given in the MCFG table represents where bus 0 would be mapped if bus 0 is mapped, which means the actual base address of the MMIO might be a higher address if bus 0 is not mapped. If you calculate the real MMIO base address according to the lowest mapped bus, then you would need to subtract the starting bus to get back to the address given by the MCFG table.

In practice, bus 0 is always mapped.

You should be able to log in to the wiki, so feel free to correct that page as you see fit.


Top
 Profile  
 
 Post subject: Re: ECAM access formula in PCI Express page is wrong
PostPosted: Tue Apr 30, 2024 10:58 am 
Offline

Joined: Sat Mar 12, 2022 1:43 am
Posts: 3
You're right, the subtraction would be required if someone were using a base address relative to the lowest mapped bus. However, the address in the MCFG table is always relative to bus zero, as I quote from the PCI firmware spec:

Quote:
For PCI-X and PCI Express platforms utilizing the enhanced
configuration access method, the base address of the memory mapped configuration space
always corresponds to bus number 0 (regardless of the start bus number decoded by the host
bridge) and further must comply with alignment requirements of the corresponding local bus
specification.

So someone would have to modify the address they read from MCFG to end up in this situation. I'll add this context to the wiki. Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group