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