pci.c (886B)
1 #include <libc.h> 2 #include <pci.h> 3 #include <uefi.h> 4 #include <draw.h> 5 #include <console.h> 6 7 #include "pci.h" 8 9 const uint16 pci_config_address = 0xcf8; 10 const uint16 pci_config_data = 0xcfc; 11 12 uint16 13 pci_config_read16(uint8 bus, uint8 dev, uint8 func, uint8 offset) 14 { 15 uint32 addr, tmp; 16 addr = 1 << 31 | // enable bit. 17 (uint32) bus << 16 | 18 (uint32) (dev&0x1f) << 11 | 19 (uint32) (func&3) << 8 | 20 (offset&0xfc); // the least 2 bits should be 0. 21 io_out32(pci_config_address, addr); 22 tmp = io_in32(pci_config_data); 23 return (tmp >> (offset&2)*8) & 0xffff; 24 } 25 26 uint32 27 pci_config_read32(uint8 bus, uint8 dev, uint8 func, uint8 offset) 28 { 29 uint32 addr; 30 addr = 1 << 31 | // enable bit. 31 (uint32) bus << 16 | 32 (uint32) (dev&0x1f) << 11 | 33 (uint32) (func&3) << 8 | 34 (offset&0xfc); // the least 2 bits should be 0. 35 io_out32(pci_config_address, addr); 36 return io_in32(pci_config_data); 37 }