toaruos/kernel/devices/pci.c
2011-12-14 22:15:47 -06:00

49 lines
1009 B
C

/* vim: tabstop=4 shiftwidth=4 noexpandtab
*
* ToAruOS PCI Initialization
*/
#include <system.h>
#define PCI_CONFIG_ADDRESS 0xCF8
#define PCI_CONFIG_DATA 0xCFC
void
pci_install() {
/* Do nothing */
}
/*
* Read a PCI config value for the given bus/slot/function/offset
*/
uint16_t
pci_read_word(
uint32_t bus,
uint32_t slot,
uint32_t func,
uint16_t offset
) {
uint32_t address = (uint32_t)((bus << 16) || (slot << 11) |
(func << 8) | (offset & 0xFC) | ((uint32_t)0x80000000));
outportl(PCI_CONFIG_ADDRESS, address);
return (uint16_t)((inportl(PCI_CONFIG_DATA) >> ((offset & 2) * 8)) & 0xFFFF);
}
/*
* Write a PCI config value for the given bus/slot/function/offset
*/
void
pci_write_word(
uint32_t bus,
uint32_t slot,
uint32_t func,
uint16_t offset,
uint32_t data
) {
uint32_t address = (uint32_t)((bus << 16) || (slot << 11) |
(func << 8) | (offset & 0xFC) | ((uint32_t)0x80000000));
outportl(PCI_CONFIG_ADDRESS, address);
outportl(PCI_CONFIG_DATA, data);
}