Scanning 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
dream21
Member
Member
Posts: 25
Joined: Thu Aug 18, 2016 12:54 pm

Scanning PCI devices

Post 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.
mikegonta
Member
Member
Posts: 229
Joined: Thu May 19, 2011 5:13 am
Contact:

Re: Scanning PCI devices

Post 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
Mike Gonta
look and see - many look but few see

https://mikegonta.com
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: Scanning PCI devices

Post 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.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: Scanning PCI devices

Post 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.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
dream21
Member
Member
Posts: 25
Joined: Thu Aug 18, 2016 12:54 pm

Re: Scanning PCI devices

Post 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. :)
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: Scanning PCI devices

Post 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.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
Post Reply