4 #include "types.h" // u32
7 #define PCI_NUM_REGIONS 7
9 static inline u8 pci_bdf_to_bus(u16 bdf) {
12 static inline u8 pci_bdf_to_devfn(u16 bdf) {
15 static inline u16 pci_bdf_to_busdev(u16 bdf) {
18 static inline u8 pci_bdf_to_dev(u16 bdf) {
19 return (bdf >> 3) & 0x1f;
21 static inline u8 pci_bdf_to_fn(u16 bdf) {
24 static inline u16 pci_to_bdf(int bus, int dev, int fn) {
25 return (bus<<8) | (dev<<3) | fn;
27 static inline u16 pci_bus_devfn_to_bdf(int bus, u16 devfn) {
28 return (bus << 8) | devfn;
31 void pci_config_writel(u16 bdf, u32 addr, u32 val);
32 void pci_config_writew(u16 bdf, u32 addr, u16 val);
33 void pci_config_writeb(u16 bdf, u32 addr, u8 val);
34 u32 pci_config_readl(u16 bdf, u32 addr);
35 u16 pci_config_readw(u16 bdf, u32 addr);
36 u8 pci_config_readb(u16 bdf, u32 addr);
37 void pci_config_maskw(u16 bdf, u32 addr, u16 off, u16 on);
39 struct pci_device *pci_find_device(u16 vendid, u16 devid);
40 struct pci_device *pci_find_class(u16 classid);
45 struct pci_device *next;
46 struct pci_device *parent;
48 // Configuration space device information
58 } bars[PCI_NUM_REGIONS];
60 // Local information on device.
63 extern struct pci_device *PCIDevices;
65 int pci_probe_host(void);
66 void pci_probe_devices(void);
67 static inline u32 pci_classprog(struct pci_device *pci) {
68 return (pci->class << 8) | pci->prog_if;
71 #define foreachpci(PCI) \
72 for (PCI=PCIDevices; PCI; PCI=PCI->next)
74 int pci_next(int bdf, int bus);
75 #define foreachbdf(BDF, BUS) \
76 for (BDF=pci_next(pci_bus_devfn_to_bdf((BUS), 0)-1, (BUS)) \
78 ; BDF=pci_next(BDF, (BUS)))
80 #define PCI_ANY_ID (~0)
81 struct pci_device_id {
86 void (*func)(struct pci_device *pci, void *arg);
89 #define PCI_DEVICE(vendor_id, device_id, init_func) \
91 .vendid = (vendor_id), \
92 .devid = (device_id), \
93 .class = PCI_ANY_ID, \
98 #define PCI_DEVICE_CLASS(vendor_id, device_id, class_code, init_func) \
100 .vendid = (vendor_id), \
101 .devid = (device_id), \
102 .class = (class_code), \
104 .func = (init_func) \
107 #define PCI_DEVICE_END \
112 int pci_init_device(const struct pci_device_id *ids
113 , struct pci_device *pci, void *arg);
114 struct pci_device *pci_find_init_device(const struct pci_device_id *ids
116 void pci_reboot(void);
118 // helper functions to access pci mmio bars from real mode
119 u32 pci_readl(u32 addr);
120 void pci_writel(u32 addr, u32 val);
123 void create_pirtable(void);
126 /****************************************************************
128 ****************************************************************/
130 extern u16 PirOffset;
140 struct link_info links[4];
152 u32 compatible_devid;
156 struct pir_slot slots[0];
159 #define PIR_SIGNATURE 0x52495024 // $PIR