Page 1 of 1

Scanning PCI devices

Posted: Thu Feb 09, 2017 2:12 am
by dream21
I am trying to understand the PCI spec to write my PCI driver. I am having a couple of questions:

1) For probing the pci devices mainly 4 things are important, Bus_Number, Device_Number, Function_Number and Register_Number. Do I have to go to every device and look at the Vendor_ID which is not 0xFFFFFFFF. Do I have to do it for every 255 buses.

2) What if we try to set the Vendor_ID to a specific value (I am right now trying it in a virtualized environment). How do we use the ports 0xCF8 & 0xCFC?

I couldn't find a good resource which explains PCI spec and give some demo code. I find out http://members.hyperlink.net.au/~chart/pci.htm but the site seems down.

Re: Scanning PCI devices

Posted: Thu Feb 09, 2017 4:07 am
by mikegonta
dream21 wrote:I couldn't find a good resource which explains PCI spec and give some demo code.
I find out http://members.hyperlink.net.au/~chart/pci.htm but the site seems down.
The wayback machine is your friend here.
https://web.archive.org/web/20030628011 ... rt/pci.htm

Re: Scanning PCI devices

Posted: Thu Feb 09, 2017 5:00 am
by BrightLight
This wiki page has everything you need. In a nutshell, you use ports 0xCFC and 0xCF8 to read and write PCI configuration registers.

Re: Scanning PCI devices

Posted: Thu Feb 09, 2017 6:10 am
by SpyderTL
The bus, device and function numbers can be combined to make a single 16-bit number, so you can just check every value between 0 and 65535 to see if the vendor/device ID is 0xFFFFFFFF.

This is what I'm currently doing, and it's plenty fast for my needs, and I would recommend going this route if you are just getting started.

Once you have everything working, you can speed things up quite a bit by starting with bus zero, and only scanning additional bus numbers that are referenced by a device on that bus, recursively.

And, by the way, there is no reason to "set" the vendor ID on a device. You simply read it to help figure out what type of device it is.

Re: Scanning PCI devices

Posted: Thu Feb 09, 2017 6:57 am
by dream21
Thank you everyone for your replies. I read a lot about PCI from different forums and references and when I came back to this http://wiki.osdev.org/PCI tutorial, everything became clear. :)

Re: Scanning PCI devices

Posted: Thu Feb 09, 2017 7:01 am
by SpyderTL
That's why this is the best site on the internet, by far.

Let us know if you have any other questions. We'll help where we can.