Page 1 of 1
what is meant by "enumerating the PCI bus"
Posted: Sat Oct 06, 2012 11:48 am
by hegde1997
does it mean that i have to send some values to pci bus and ask it to store it? i am just not understanding what is enumerating pci bus? should i assign to pci bus or read pci bus and do something?
what is function number that is once of the value used while addressing pci bus?
Re: what is meant by "enumerating the PCI bus"
Posted: Sat Oct 06, 2012 12:07 pm
by NickJohnson
Enumerating means listing the contents of. Therefore, enumerating the PCI bus means going through all the PCI addresses where there could be devices (either by recursively finding the buses through PCI-PCI bridges, or if you're lazy, brute force) and reading the information about those devices to make a list of all devices on the system.
Re: what is meant by "enumerating the PCI bus"
Posted: Sat Oct 06, 2012 12:52 pm
by bluemoon
The numbers associated with PCI are like IP address: it comes in the form bus:slot:function.
By convention, bus refer to bus id - to identify a bus; slot identify which slot of that bus; and functions are to index which functionality of that card, some card provide multiple functions.
One of the method is to loop on all possible addresses:
Code: Select all
for ( unsigned int bus_id=0; bus_id<256; bus_id++ ) {
for ( unsigned int slot_id=0; slot_id<32; slot_id++ ) {
for ( unsigned int func_id=0; func_id<8; func_id++ ) {
if ( pci_driver->get_info(&pci, bus_id, slot_id, func_id, &info ) < 0 ) break;
If there is a device on the address, there will be basic info(vendor id, etc) fetch from get_info (check the wiki for detail)
Re: what is meant by "enumerating the PCI bus"
Posted: Sun Oct 07, 2012 2:58 am
by hegde1997
Thank you
Re: what is meant by "enumerating the PCI bus"
Posted: Sun Oct 07, 2012 11:09 am
by hegde1997
NickJohnson wrote:either by recursively finding the buses through PCI-PCI bridges
how to do that?
Re: what is meant by "enumerating the PCI bus"
Posted: Sun Oct 07, 2012 2:34 pm
by Brendan
Hi,
hegde1997 wrote:NickJohnson wrote:either by recursively finding the buses through PCI-PCI bridges
how to do that?
I was going to explain it here; then decided that if I'm explaining it I should try to do it properly and added
Enumerating PCI Buses to the wiki page.
Cheers,
Brendan
Re: what is meant by "enumerating the PCI bus"
Posted: Sun Oct 07, 2012 4:50 pm
by sounds
Brendan wrote:I was going to explain it here; then decided that if I'm explaining it I should try to do it properly and added
Enumerating PCI Buses to the wiki page.
Nice writeup. One assumption I've found (for x86) is that bus numbers are always assigned in increasing order. If that assumption is valid, a no-recursion implementation can set a "goal post" first to bus #0 and then move the goal post each time a PCI-PCI bridge is found. There's a specific value in the PCI-PCI bridge config space that gives the maximum bus number behind the bridge.
Brendan, do you think my assumption is safe?
Re: what is meant by "enumerating the PCI bus"
Posted: Sun Oct 07, 2012 5:17 pm
by Brendan
Hi,
sounds wrote:One assumption I've found (for x86) is that bus numbers are always assigned in increasing order. If that assumption is valid, a no-recursion implementation can set a "goal post" first to bus #0 and then move the goal post each time a PCI-PCI bridge is found. There's a specific value in the PCI-PCI bridge config space that gives the maximum bus number behind the bridge.
Brendan, do you think my assumption is safe?
Nothing (that I know of) says that PCI buses must be numbered sequentially. For example, a bridge may be configured with "secondary bus number = 4; subordinate bus number = 128" where buses 5 to 128 don't actually exist. There may also be valid reasons for leaving holes like this (e.g. avoiding the need to renumber buses for hot-plug PCI where bridges may be plugged in after boot).
If there are gaps in the bus numbering then it would still work and would be safe - worst case would end up being similar to the brute force method (where you search lots of devices on buses that don't exist).
Cheers,
Brendan
Re: what is meant by "enumerating the PCI bus"
Posted: Mon Oct 08, 2012 1:17 am
by hegde1997
Brendan wrote:
I was going to explain it here; then decided that if I'm explaining it I should try to do it properly and added
Enumerating PCI Buses to the wiki page.
Thanks Brendan