diff options
Diffstat (limited to '')
-rw-r--r-- | src/drivers/pci.c (renamed from src/arch/amd64/drivers/pci.c) | 55 |
1 files changed, 14 insertions, 41 deletions
diff --git a/src/arch/amd64/drivers/pci.c b/src/drivers/pci.c index 7aa11c8..6e87b86 100644 --- a/src/arch/amd64/drivers/pci.c +++ b/src/drivers/pci.c @@ -1,12 +1,9 @@ -#include <stdint.h> #include <pci.h> -#include <panic.h> #include <lib.h> +#include <panic.h> -#include "../bindings.h" - -#define CONF_ADDR 0xCF8 -#define CONF_DATA 0xCFC +#define PCI_INTERNAL +#include <sys/pci.h> #define TABLE_LEN 16 @@ -20,58 +17,34 @@ struct pci_table_entry { uint8_t revision; }; -static struct pci_table_entry pci_table[TABLE_LEN]; -static size_t pci_table_next = 0; - uint32_t pci_rcfg_d(struct pci_device dev, uint8_t offset) { - uint32_t addr = 0x80000000; - addr |= ((uint32_t)dev.bus) << 16; - addr |= ((uint32_t)dev.device) << 11; - addr |= ((uint32_t)dev.function) << 8; - addr |= offset & 0xFC; - - outl(CONF_ADDR, addr); - uint32_t in = inl(CONF_DATA); - return in; + return pci_sys_rcfg_d(dev, offset); } uint16_t pci_rcfg_w(struct pci_device dev, uint8_t offset) { - uint32_t dword = pci_rcfg_d(dev, offset); - return (uint16_t)((dword >> ((offset & 2) * 8)) & 0xFFFF); + return pci_sys_rcfg_w(dev, offset); } -uint8_t pci_rcfg_b(struct pci_device dev, uint8_t offset) { - uint32_t dword = pci_rcfg_d(dev, offset); - return (uint8_t)((dword >> ((offset & 3) * 8)) & 0xFF); +uint8_t pci_rcfg_b(struct pci_device dev, uint8_t offset) { + return pci_sys_rcfg_b(dev, offset); } void pci_wcfg_d(struct pci_device dev, uint8_t offset, uint32_t dword) { - uint32_t addr = 0x80000000; - addr |= ((uint32_t)dev.bus) << 16; - addr |= ((uint32_t)dev.device) << 11; - addr |= ((uint32_t)dev.function) << 8; - addr |= offset & 0xFC; - - outl(CONF_ADDR, addr); - outl(CONF_DATA, dword); + pci_sys_wcfg_d(dev, offset, dword); } void pci_wcfg_w(struct pci_device dev, uint8_t offset, uint16_t word) { - size_t shift = (offset & 2) * 8; - uint32_t dword = pci_rcfg_d(dev, offset); - dword &= ~(0xFFFF << shift); - dword |= word << shift; - pci_wcfg_d(dev, offset, dword); + pci_sys_wcfg_w(dev, offset, word); } void pci_wcfg_b(struct pci_device dev, uint8_t offset, uint8_t byte) { - size_t shift = (offset & 3) * 8; - uint32_t dword = pci_rcfg_d(dev, offset); - dword &= ~(0xFF << shift); - dword |= byte << shift; - pci_wcfg_d(dev, offset, dword); + pci_sys_wcfg_b(dev, offset, byte); } +static struct pci_table_entry pci_table[TABLE_LEN]; +static size_t pci_table_next = 0; + + static void print_device(struct pci_table_entry *entry) { kprintf( "BUS: %#-4x DEV: %#-4x FUNC: %#-4x ID: %04x:%04x CLASS: %02x:%02x:%02x REV: %#02x\n", |