Do I understand the PCI page correctly?
Posted: Sun Dec 22, 2013 3:23 pm
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:
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
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: Select all
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);
}
- 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