1 2 #define PCI_OFFSET_VENDORID 0x00 3 #define PCI_OFFSET_DEVICEID 0x02 4 #define PCI_OFFSET_COMMAND 0x04 5 #define PCI_OFFSET_STATUS 0x06 6 #define PCI_OFFSET_REVISIONID 0x08 7 #define PCI_OFFSET_PROGIF 0x09 8 #define PCI_OFFSET_SUBCLASS 0x0A 9 #define PCI_OFFSET_CLASS 0x0B 10 #define PCI_OFFSET_CACHELINE 0x0C 11 #define PCI_OFFSET_LATENCYTMR 0x0D 12 #define PCI_OFFSET_HEADERTYPE 0x0E 13 #define PCI_OFFSET_BIST 0x0F 14 15 #define PCI_OFFSET_BARFIRST 0x10 16 #define PCI_OFFSET_BARLAST 0x24 17 18 #define PCI_OFFSET_IRQLINE 0x3C 19 20 #define PCI_COMMAND_IOENABLE 0x0001 21 #define PCI_COMMAND_MEMENABLE 0x0002 22 #define PCI_COMMAND_BUSMASTER 0x0004 23 24 #define PCI_MAX_BARS 6 25 26 #define PCI_CLASS_STORAGE 0x01 27 #define PCI_CLASS_NETWORK 0x02 28 #define PCI_CLASS_GRAPHICS 0x03 29 #define PCI_CLASS_BRIDGE 0x06 30 #define PCI_CLASS_BUS 0x0C 31 32 #define PCI_SCLASS_STORAGE_IDE 0x01 33 #define PCI_SCLASS_STORAGE_SATA 0x06 34 35 #define PCI_SCLASS_BRIDGE_HOST 0x00 36 #define PCI_SCLASS_BRIDGE_ISA 0x01 37 #define PCI_SCLASS_BRIDGE_PCI 0x04 38 #define PCI_SCLASS_BRIDGE_MISC 0x80 39 40 #define PCI_SCLASS_BUS_FW 0x00 41 #define PCI_SCLASS_BUS_USB 0x03 42 #define PCI_SCLASS_BUS_SMBUS 0x05 43 44 #define PCIBAR_TYPE_NULL 0 45 #define PCIBAR_TYPE_IO 1 46 #define PCIBAR_TYPE_MEM 2 47 48 typedef struct PCIBAR 49 { 50 uint32_t base; 51 uint32_t size; 52 uint32_t type; 53 } PCIBAR; 54 55 typedef struct PCIDevice 56 { 57 uint16_t vendor; 58 uint16_t device; 59 60 uint8_t bus; 61 uint8_t slot; 62 uint8_t func; 63 64 uint8_t irq; 65 66 PCIBAR bars[PCI_MAX_BARS]; 67 } PCIDevice; 68 69 void PCI_Init(); 70 71 uint8_t PCI_CfgRead8(PCIDevice *dev, uint32_t reg); 72 uint16_t PCI_CfgRead16(PCIDevice *dev, uint32_t reg); 73 uint32_t PCI_CfgRead32(PCIDevice *dev, uint32_t reg); 74 void PCI_CfgWrite8(PCIDevice *dev, uint32_t reg, uint8_t data); 75 void PCI_CfgWrite16(PCIDevice *dev, uint32_t reg, uint16_t data); 76 void PCI_CfgWrite32(PCIDevice *dev, uint32_t reg, uint32_t data); 77 78 uint16_t PCI_GetDeviceID(PCIDevice *dev); 79 uint16_t PCI_GetVendorID(PCIDevice *dev); 80 uint8_t PCI_GetBaseClass(PCIDevice *dev); 81 uint8_t PCI_GetSubClass(PCIDevice *dev); 82 uint8_t PCI_GetHeaderType(PCIDevice *dev); 83 84 void PCI_Configure(PCIDevice *dev); 85 86