Only run the vga option rom of an enabled vga device.
[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_vga();
30 int pci_find_device(u16 vendid, u16 devid);
31 int pci_find_class(u16 classid);
32
33 int pci_next(int bdf, int *pmax);
34 #define foreachpci(BDF, MAX)                    \
35     for (MAX=0x0100, BDF=pci_next(0, &MAX)      \
36          ; BDF >= 0                             \
37          ; BDF=pci_next(BDF+1, &MAX))
38
39 // pirtable.c
40 void create_pirtable();
41
42
43 /****************************************************************
44  * PIR table
45  ****************************************************************/
46
47 extern u16 PirOffset;
48
49 struct link_info {
50     u8 link;
51     u16 bitmap;
52 } PACKED;
53
54 struct pir_slot {
55     u8 bus;
56     u8 dev;
57     struct link_info links[4];
58     u8 slot_nr;
59     u8 reserved;
60 } PACKED;
61
62 struct pir_header {
63     u32 signature;
64     u16 version;
65     u16 size;
66     u8 router_bus;
67     u8 router_devfunc;
68     u16 exclusive_irqs;
69     u32 compatible_devid;
70     u32 miniport_data;
71     u8 reserved[11];
72     u8 checksum;
73     struct pir_slot slots[0];
74 } PACKED;
75
76 #define PIR_SIGNATURE 0x52495024 // $PIR
77
78
79 #endif