what is meant by "enumerating the PCI bus"

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
hegde1997
Member
Member
Posts: 40
Joined: Mon Jan 30, 2012 7:36 am
Location: Bangalore, India
Contact:

what is meant by "enumerating the PCI bus"

Post 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?
Walking my way in making my OS
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: what is meant by "enumerating the PCI bus"

Post 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.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: what is meant by "enumerating the PCI bus"

Post 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)
User avatar
hegde1997
Member
Member
Posts: 40
Joined: Mon Jan 30, 2012 7:36 am
Location: Bangalore, India
Contact:

Re: what is meant by "enumerating the PCI bus"

Post by hegde1997 »

Thank you
Walking my way in making my OS
User avatar
hegde1997
Member
Member
Posts: 40
Joined: Mon Jan 30, 2012 7:36 am
Location: Bangalore, India
Contact:

Re: what is meant by "enumerating the PCI bus"

Post by hegde1997 »

NickJohnson wrote:either by recursively finding the buses through PCI-PCI bridges
how to do that?
Walking my way in making my OS
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: what is meant by "enumerating the PCI bus"

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
sounds
Member
Member
Posts: 112
Joined: Sat Feb 04, 2012 5:03 pm

Re: what is meant by "enumerating the PCI bus"

Post 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?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: what is meant by "enumerating the PCI bus"

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
hegde1997
Member
Member
Posts: 40
Joined: Mon Jan 30, 2012 7:36 am
Location: Bangalore, India
Contact:

Re: what is meant by "enumerating the PCI bus"

Post 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
Walking my way in making my OS
Post Reply