Improve optionrom debugging statements.
[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 u16 pci_bdf_to_busdev(u16 bdf) {
13     return bdf & ~0x07;
14 }
15 static inline u8 pci_bdf_to_dev(u16 bdf) {
16     return (bdf >> 3) & 0x1f;
17 }
18 static inline u8 pci_bdf_to_fn(u16 bdf) {
19     return bdf & 0x07;
20 }
21 static inline u16 pci_to_bdf(int bus, int dev, int fn) {
22     return (bus<<8) | (dev<<3) | fn;
23 }
24
25 static inline u32 pci_vd(u16 vendor, u16 device) {
26     return (device << 16) | vendor;
27 }
28 static inline u16 pci_vd_to_ven(u32 vd) {
29     return vd & 0xffff;
30 }
31 static inline u16 pci_vd_to_dev(u32 vd) {
32     return vd >> 16;
33 }
34
35 void pci_config_writel(u16 bdf, u32 addr, u32 val);
36 void pci_config_writew(u16 bdf, u32 addr, u16 val);
37 void pci_config_writeb(u16 bdf, u32 addr, u8 val);
38 u32 pci_config_readl(u16 bdf, u32 addr);
39 u16 pci_config_readw(u16 bdf, u32 addr);
40 u8 pci_config_readb(u16 bdf, u32 addr);
41 void pci_config_maskw(u16 bdf, u32 addr, u16 off, u16 on);
42
43 int pci_find_vga(void);
44 int pci_find_device(u16 vendid, u16 devid);
45 int pci_find_class(u16 classid);
46
47 int pci_next(int bdf, int *pmax);
48 #define foreachpci(BDF, MAX)                    \
49     for (MAX=0x0100, BDF=pci_next(0, &MAX)      \
50          ; BDF >= 0                             \
51          ; BDF=pci_next(BDF+1, &MAX))
52
53 // pirtable.c
54 void create_pirtable(void);
55
56
57 /****************************************************************
58  * PIR table
59  ****************************************************************/
60
61 extern u16 PirOffset;
62
63 struct link_info {
64     u8 link;
65     u16 bitmap;
66 } PACKED;
67
68 struct pir_slot {
69     u8 bus;
70     u8 dev;
71     struct link_info links[4];
72     u8 slot_nr;
73     u8 reserved;
74 } PACKED;
75
76 struct pir_header {
77     u32 signature;
78     u16 version;
79     u16 size;
80     u8 router_bus;
81     u8 router_devfunc;
82     u16 exclusive_irqs;
83     u32 compatible_devid;
84     u32 miniport_data;
85     u8 reserved[11];
86     u8 checksum;
87     struct pir_slot slots[0];
88 } PACKED;
89
90 #define PIR_SIGNATURE 0x52495024 // $PIR
91
92
93 #endif