OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 4:11 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Scanning PCI devices
PostPosted: Thu Feb 09, 2017 2:12 am 
Offline
Member
Member

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

_________________
drugstore-onlinecatalog.com


Top
 Profile  
 
 Post subject: Re: Scanning PCI devices
PostPosted: Thu Feb 09, 2017 4:07 am 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: Scanning PCI devices
PostPosted: Thu Feb 09, 2017 5:00 am 
Offline
Member
Member
User avatar

Joined: Sat Dec 27, 2014 9:11 am
Posts: 901
Location: Maadi, Cairo, Egypt
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.


Top
 Profile  
 
 Post subject: Re: Scanning PCI devices
PostPosted: Thu Feb 09, 2017 6:10 am 
Offline
Member
Member
User avatar

Joined: Sun Sep 19, 2010 10:05 pm
Posts: 1074
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


Top
 Profile  
 
 Post subject: Re: Scanning PCI devices
PostPosted: Thu Feb 09, 2017 6:57 am 
Offline
Member
Member

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

_________________
drugstore-onlinecatalog.com


Top
 Profile  
 
 Post subject: Re: Scanning PCI devices
PostPosted: Thu Feb 09, 2017 7:01 am 
Offline
Member
Member
User avatar

Joined: Sun Sep 19, 2010 10:05 pm
Posts: 1074
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 142 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group