Question about PCI enumeration

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
Caleb1994
Member
Member
Posts: 83
Joined: Sun Feb 13, 2011 4:55 pm

Question about PCI enumeration

Post 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....
}
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Question about PCI enumeration

Post 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
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Caleb1994
Member
Member
Posts: 83
Joined: Sun Feb 13, 2011 4:55 pm

Re: Question about PCI enumeration

Post 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?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Question about PCI enumeration

Post by Combuster »

00 is two bits, 000 is three. #-o
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Caleb1994
Member
Member
Posts: 83
Joined: Sun Feb 13, 2011 4:55 pm

Re: Question about PCI enumeration

Post 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
Post Reply