OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 16, 2024 9:52 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Do I understand the PCI page correctly?
PostPosted: Sun Dec 22, 2013 3:23 pm 
Offline

Joined: Sat Jun 27, 2009 8:15 am
Posts: 3
Hello,
I've been trying to learn about PCI, so I turned to the PCI page of the OSDEV wiki:
http://wiki.osdev.org/PCI

Looking at the CONFIG_ADDRESS table, it shows the bottom two bits zeroed out,
and bits 7 - 2 are the Register Number.

The page provides example C code for 'Configuration Mechanism #1'.

For quick & easy reference I cut & pasted the code below:
Code:
unsigned short pciConfigReadWord (unsigned short bus, unsigned short slot,
                                  unsigned short func, unsigned short offset)
{
    unsigned long address;
    unsigned long lbus = (unsigned long)bus;
    unsigned long lslot = (unsigned long)slot;
    unsigned long lfunc = (unsigned long)func;
    unsigned short tmp = 0;

    /* create configuration address as per Figure 1 */
    address = (unsigned long)((lbus << 16) | (lslot << 11) |
              (lfunc << 8) | (offset & 0xfc) | ((UINT32)0x80000000));

    /* write out the address */
    sysOutLong (0xCF8, address);
    /* read in the data */
    /* (offset & 2) * 8) = 0 will choose the fisrt word of the 32 bits register */
    tmp = (unsigned short)((sysInLong (0xCFC) >> ((offset & 2) * 8)) & 0xffff);
    return (tmp);
}


My questions are:
- Does the 'offset' parameter correspond to the Register Number?
- If it does, I understand that '& 0xFC' will zero out the bottom two bits,
but shouldn't it be shifted left two bits first?

Thanks,
Tarkin


Top
 Profile  
 
 Post subject: Re: Do I understand the PCI page correctly?
PostPosted: Mon Dec 23, 2013 8:53 am 
Offline
Member
Member

Joined: Mon Jan 07, 2013 10:38 am
Posts: 62
Tarkin wrote:
My questions are:
- Does the 'offset' parameter correspond to the Register Number?

yes it does
Quote:
- If it does, I understand that '& 0xFC' will zero out the bottom two bits,
but shouldn't it be shifted left two bits first?

register num are multiples of 4(100 in binary) ie 0,4,8....making bottom 2 bits always zero so no need to shift anything


Top
 Profile  
 
 Post subject: Re: Do I understand the PCI page correctly?
PostPosted: Mon Dec 23, 2013 12:04 pm 
Offline

Joined: Sat Jun 27, 2009 8:15 am
Posts: 3
dansmahajan wrote:
register num are multiples of 4(100 in binary) ie 0,4,8....making bottom 2 bits always zero so no need to shift anything


Ok, thanks for clearing that up!


Top
 Profile  
 
 Post subject: Re: Do I understand the PCI page correctly?
PostPosted: Tue Dec 24, 2013 4:36 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
Updated the PCI page because this gets asked too often and nobody mentioned the real reasoning behind all of this so far.

Also,
Quote:
register num are multiples of 4
This is not true actually. For the snippet given they are actually multiples of two.

_________________
"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 ]


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

All times are UTC - 6 hours


Who is online

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