Add pci_to_bdf() helper function.
[seabios.git] / src / pci.h
1 #ifndef __PCI_H
2 #define __PCI_H
3
4 #include "types.h" // u32
5
6 static inline u8 pci_bdf_to_bus(u16 bdf) {
7     return bdf >> 8;
8 }
9 static inline u8 pci_bdf_to_devfn(u16 bdf) {
10     return bdf & 0xff;
11 }
12 static inline u8 pci_bdf_to_dev(u16 bdf) {
13     return (bdf >> 3) & 0x1f;
14 }
15 static inline u8 pci_bdf_to_fn(u16 bdf) {
16     return bdf & 0x07;
17 }
18 static inline u16 pci_to_bdf(int bus, int dev, int fn) {
19     return (bus<<8) | (dev<<3) | fn;
20 }
21
22 void pci_config_writel(u16 bdf, u32 addr, u32 val);
23 void pci_config_writew(u16 bdf, u32 addr, u16 val);
24 void pci_config_writeb(u16 bdf, u32 addr, u8 val);
25 u32 pci_config_readl(u16 bdf, u32 addr);
26 u16 pci_config_readw(u16 bdf, u32 addr);
27 u8 pci_config_readb(u16 bdf, u32 addr);
28
29 int pci_find_device(u16 vendid, u16 devid);
30 int pci_find_class(u16 classid);
31
32 int pci_next(int bdf, int *pmax);
33 #define foreachpci(BDF, MAX)                    \
34     for (MAX=0x0100, BDF=pci_next(0, &MAX)      \
35          ; BDF >= 0                             \
36          ; BDF=pci_next(BDF+1, &MAX))
37
38 // pirtable.c
39 void create_pirtable();
40
41
42 /****************************************************************
43  * PIR table
44  ****************************************************************/
45
46 extern u16 PirOffset;
47
48 struct link_info {
49     u8 link;
50     u16 bitmap;
51 } PACKED;
52
53 struct pir_slot {
54     u8 bus;
55     u8 dev;
56     struct link_info links[4];
57     u8 slot_nr;
58     u8 reserved;
59 } PACKED;
60
61 struct pir_header {
62     u32 signature;
63     u16 version;
64     u16 size;
65     u8 router_bus;
66     u8 router_devfunc;
67     u16 exclusive_irqs;
68     u32 compatible_devid;
69     u32 miniport_data;
70     u8 reserved[11];
71     u8 checksum;
72     struct pir_slot slots[0];
73 } PACKED;
74
75 #define PIR_SIGNATURE 0x52495024 // $PIR
76
77
78 #endif