Untitled
By: a guest | Mar 20th, 2010 | Syntax:
None | Size: 1.56 KB | Hits: 61 | Expires: Never
uint32_t pci_config_read( uint8_t bus, uint8_t device, uint8_t func, uint16_t content )
{
// example: PCI_VENDOR_ID 0x0200 ==> length: 0x02 reg: 0x00 offset: 0x00
uint8_t length = content >> 8;
uint8_t reg_off = content & 0x00FF;
uint8_t reg = reg_off & 0xFC; // bit mask: 11111100b
uint8_t offset = reg_off % 0x04; // remainder of modulo operation provides offset
outportl(PCI_CONFIGURATION_ADDRESS,
0x80000000
| (bus << 16)
| (device << 11)
| (func << 8)
| (reg ));
// use offset to find searched content
uint32_t readVal = inportl(PCI_CONFIGURATION_DATA) >> (8 * offset);
switch(length)
{
case 1:
readVal &= 0x000000FF;
break;
case 2:
readVal &= 0x0000FFFF;
break;
case 4:
readVal &= 0xFFFFFFFF;
break;
}
return readVal;
}
void pci_config_write_byte( uint8_t bus, uint8_t device, uint8_t func, uint8_t reg, uint8_t val )
{
outportl(PCI_CONFIGURATION_ADDRESS,
0x80000000
| (bus << 16)
| (device << 11)
| (func << 8)
| reg );
outportb(PCI_CONFIGURATION_DATA, val);
}
void pci_config_write_dword( uint8_t bus, uint8_t device, uint8_t func, uint8_t reg, uint32_t val )
{
outportl(PCI_CONFIGURATION_ADDRESS,
0x80000000
| (bus << 16)
| (device << 11)
| (func << 8)
| (reg & 0xFC ));
outportl(PCI_CONFIGURATION_DATA, val);
}