6 #if !(defined(PCI_CONFIG_1) || defined(PCI_CONFIG_2))
7 #define PCI_CONFIG_1 1 /* default */
12 /* PCI Configuration Mechanism #1 */
14 /* Have pci_addr in the same format as the values written to 0xcf8
15 * so register accesses can be made easy. */
16 #define PCI_ADDR(bus, dev, fn) \
17 ((pci_addr) (0x80000000u \
18 | (uint32_t) (bus) << 16 \
19 | (uint32_t) (dev) << 11 \
20 | (uint32_t) (fn) << 8))
22 #define PCI_BUS(pcidev) ((uint8_t) ((pcidev) >> 16))
23 #define PCI_DEV(pcidev) ((uint8_t) ((pcidev) >> 11) & 0x1f)
24 #define PCI_FN(pcidev) ((uint8_t) ((pcidev) >> 8) & 7)
26 static inline uint8_t pci_config_read8(pci_addr dev, uint8_t reg)
28 outl(dev | (reg & ~3), 0xcf8);
29 return inb(0xcfc | (reg & 3));
32 static inline uint16_t pci_config_read16(pci_addr dev, uint8_t reg)
34 outl(dev | (reg & ~3), 0xcf8);
35 return inw(0xcfc | (reg & 2));
38 static inline uint32_t pci_config_read32(pci_addr dev, uint8_t reg)
40 outl(dev | reg, 0xcf8);
41 return inl(0xcfc | reg);
44 static inline void pci_config_write8(pci_addr dev, uint8_t reg, uint8_t val)
46 outl(dev | (reg & ~3), 0xcf8);
47 outb(val, 0xcfc | (reg & 3));
50 static inline void pci_config_write16(pci_addr dev, uint8_t reg, uint16_t val)
52 outl(dev | (reg & ~3), 0xcf8);
53 outw(val, 0xcfc | (reg & 2));
56 static inline void pci_config_write32(pci_addr dev, uint8_t reg, uint32_t val)
58 outl(dev | reg, 0xcf8);
62 #else /* !PCI_CONFIG_1 */
63 #error PCI Configuration Mechanism is not specified or implemented
66 #endif /* i386_PCI_H */