Enumerating PCI Devices

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
Zerith
Posts: 14
Joined: Sun Jul 05, 2009 4:01 pm

Enumerating PCI Devices

Post by Zerith »

Hello, i'm trying to enumerate all class codes for existing pci devices.

All i seem to get are 4 devices whose class code is 0x00.. is this normal?

There's my code: http://codepad.org/z05RIkvq

I'm running on bochs.
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: Enumerating PCI Devices

Post by Combuster »

You are mixing up words (16 bits) and doublewords (32 bits) on many occasions. Fix that and you'll have a good chance to get rid of the spurious readings. If you end up getting no devices, you might need to enable PCI in the configuration.

Also, don't read functions beyond the first without checking they actually exist.
"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 ]
Zerith
Posts: 14
Joined: Sun Jul 05, 2009 4:01 pm

Re: Enumerating PCI Devices

Post by Zerith »

Well i seem to have reduced the number of devices i find, but i still get 2 whose class code is 0x00.
http://pastebin.ca/1883085

And, if i do have to enable pci, how would i do that in bochs?
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: Enumerating PCI Devices

Post by Combuster »

There are still some doubleword-size issues (this time versus bytes) in place here. You pass offsets into byte-sized configuration space, while the code you grabbed off the internet treats offsets as entries into doubleword sized configuration space (which is how it works in reality). In the end you are not reading anything near the class code or header type. You may want to compare your version with this.

As for the pci option, may I recommend reading the manual first? (It's most likely on since you do seem to get the right number of devices given your current bug status)
"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 ]
Zerith
Posts: 14
Joined: Sun Jul 05, 2009 4:01 pm

Re: Enumerating PCI Devices

Post by Zerith »

Thank you very much for you help.

I seem to get 9 devices right now, 3 of which are "Bridge Devices" (according ot the Base Class code), 1 is a mass storage controller
and 5 are Class code 0xFF.

shouldn't i also be getting the Processor and several other devices?
http://codepad.org/hiKMbk5I
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: Enumerating PCI Devices

Post by Combuster »

I see you copied random sources again (including mine) - It'd be best if learn to do your own debugging work instead of relying on copy-paste. Especially if you have to do the error-prone translation from language X to Y as well.

Also, why are you only interested in the class codes? The device-vendor pair is usually more interesting. (I only use the class codes to find out which PCI device maps to an ISA function - like whether the video card installed is PCI or ISA)

Also, PCI lists only the devices attached to the PCI bus. The link to the processor is there, only you fail to recognise it. (look up the various device IDs to find out).
"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 ]
Post Reply