Page 1 of 1

Question about PCI enumeration

Posted: Wed Sep 28, 2011 9:01 am
by Caleb1994
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 :P

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....
}

Re: Question about PCI enumeration

Posted: Wed Sep 28, 2011 12:21 pm
by Combuster
Multifunction devices are basically multiple devices in one physical chip. Enumeration always includes multiple functions.

Btw, function numbers go from 0..7 instead of 0..2

Re: Question about PCI enumeration

Posted: Wed Sep 28, 2011 1:51 pm
by Caleb1994
Combuster wrote:Multifunction devices are basically multiple devices in one physical chip. Enumeration always includes multiple functions.
Okay, thanks!
Combuster wrote: Btw, function numbers go from 0..7 instead of 0..2
But according to the wiki, the CONFIG_ADDRESS IO port only has 3 bits for function (bits 8 9 and 10). Wouldn't that make it anywhere from... well I guess 0..3 not 0..2, since the only bit combinations for 3 bits is: 00,01,10,11?

Re: Question about PCI enumeration

Posted: Wed Sep 28, 2011 2:01 pm
by Combuster
00 is two bits, 000 is three. #-o

Re: Question about PCI enumeration

Posted: Wed Sep 28, 2011 3:26 pm
by Caleb1994
Oh wow... I don't even know what to say... I think I need to stop staying up late watching Eureka... I even said "has 3 bits"... thanks again for your help. Lol