OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 2:09 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: PCI page error?
PostPosted: Tue Dec 11, 2012 12:53 pm 
Offline

Joined: Thu May 17, 2012 12:43 pm
Posts: 18
Location: in front of a computer
In the "Enumerating PCI Buses" section, the code for checking all the functions of a multi-function device starts at function 0 and breaks as soon as a function isn't detected. This requires all the functions of a multi-function device to be numbered consecutively, which I don't think is always true (Bochs for one doesn't appear to).

Code:
void checkDevice(uint8_t bus, uint8_t device) {
     uint8_t function = 0;

     vendorID = getVendorID(bus, device, function);
     if(vendorID = 0xFFFF) return;        // Device doesn't exist
     checkFunction(bus, device, function);
     headerType = getHeaderType(bus, device, function);
     if( (headerType & 0x80) != 0) {
         /* It is a multi-function device, so check remaining functions */
         for(function = 1; function < 8; function++) {
             if(getVendorID(bus, device, function) == 0xFFFF) break;   // I don't think this is right
             checkFunction(bus, device, function);
         }
     }
}


Top
 Profile  
 
 Post subject: Re: PCI page error?
PostPosted: Tue Dec 11, 2012 9:48 pm 
Offline
Member
Member
User avatar

Joined: Wed Feb 09, 2011 2:21 am
Posts: 87
Location: Raipur, India
Removing the line

Code:
if(getVendorID(bus, device, function) == 0xFFFF) break;   // I don't think this is right

may work. In-fact, that line has almost no use.


Top
 Profile  
 
 Post subject: Re: PCI page error?
PostPosted: Tue Dec 11, 2012 9:49 pm 
Offline
Member
Member
User avatar

Joined: Wed Feb 09, 2011 2:21 am
Posts: 87
Location: Raipur, India
So the new code is

Code:
void checkDevice(uint8_t bus, uint8_t device) {
     uint8_t function = 0;

     vendorID = getVendorID(bus, device, function);
     if(vendorID = 0xFFFF) return;        // Device doesn't exist
     checkFunction(bus, device, function);
     headerType = getHeaderType(bus, device, function);
     if( (headerType & 0x80) != 0) {
         /* It is a multi-function device, so check remaining functions */
         for(function = 1; function < 8; function++)
             checkFunction(bus, device, function);
     }
}


Top
 Profile  
 
 Post subject: Re: PCI page error?
PostPosted: Wed Dec 12, 2012 3:40 pm 
Offline

Joined: Thu May 17, 2012 12:43 pm
Posts: 18
Location: in front of a computer
That's what I'm thinking. That line is there to cut down on the number of I/O accesses by exiting the function checking loop at the first function that isn't detected. Problem is I don't believe the functions are always consecutive, so bailing out at the first missing function could cause you to miss some of them.

I would discuss this on the articles talk page, but I did some searching on here and this seems to be a common algorithm. Even the venerable Brendan posted some code a while back that quit the multi-function loop in the same fashion :? . Hence why I'm a bit hesitant to call this an error on the PCI page when it could just as easily be Bochs or me.


Top
 Profile  
 
 Post subject: Re: PCI page error?
PostPosted: Wed Dec 12, 2012 6:00 pm 
Offline
Member
Member
User avatar

Joined: Sat Jul 30, 2011 10:07 am
Posts: 374
Location: Wrocław/Racibórz, Poland
Wouldn't changing the break into continue be smarter than just dropping the condition in this case?

_________________
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations


Top
 Profile  
 
 Post subject: Re: PCI page error?
PostPosted: Thu Dec 13, 2012 12:01 am 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

metallevel wrote:
I would discuss this on the articles talk page, but I did some searching on here and this seems to be a common algorithm. Even the venerable Brendan posted some code a while back that quit the multi-function loop in the same fashion :? . Hence why I'm a bit hesitant to call this an error on the PCI page when it could just as easily be Bochs or me.


A while ago someone was asking questions about PCI device enumeration. I was just going to tell them "here's the relevant part of the wiki page!" but the information wasn't in the wiki, so I couldn't. It's possible that I posted the pseudo-code as a reply, then slapped myself, then added the same pseudo-code to the wiki.

In general, you should never assume anyone is correct, including me. I also think you're right (and that my pseudo-code was wrong). ;)


Cheers,

Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
 Post subject: Re: PCI page error?
PostPosted: Thu Dec 13, 2012 6:23 pm 
Offline

Joined: Thu May 17, 2012 12:43 pm
Posts: 18
Location: in front of a computer
Ok, thanks. I just don't want to be the guy who 'corrects' people who are already right :D .

@Griwes yeah that would be better, fewer IO accesses.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 27 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