Question about PCI enumeration
Posted: Wed Sep 28, 2011 9:01 am
I've been reading the Wiki, and the linux PCI reference linked to it, and I was wondering, does each device usually get enumerated or does each FUNCTION of each device get enumerated (assuming some devices are multifunction). In the linux definition of a PCI device (http://tldp.org/LDP/tlk/ds/ds.html) they save the device AND function (pci_dev::devfn), but the page linked to by the wiki ( http://tldp.org/LDP/tlk/dd/pci.html#tthFrefAAB same site different page), does not mention that. It's mentions enumerating the devices. I think I would want to enumerate all functions, since each "function" could be thought of as a completely seperate device (since, as the name implies, it functions differently), but I just wanted some input from people who have done it before, so I don't get knee deep in bad code
My first thought was something like this (psuedo):
My first thought was something like this (psuedo):
Code: Select all
void enumerate_bus(pci_bus* bus)
{
u8 dev = 0, fn = 1;
for(dev; dev < 32; ++dev)
{
if( !does_device_exist(bus, dev) ) continue;
enumerate_device(bus, dev, 0);
if( is_device_multifunction(bus, dev) ){
for(fn = 1; fn < 3; ++fn) enumerate_device(bus, dev, fn);
}
}
}
void enumerate_device(pci_bus* bus, u8 dev, u8 func)
{
... // add the device to the list, and create buses if needed... etc...etc....
}