Generate PIR table at post time.
[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
12 pci_bd(u8 bus, u8 devfn)
13 {
14     struct PCIDevice d = {bus, devfn};
15     return d;
16 }
17
18 void pci_config_writel(PCIDevice d, u32 addr, u32 val);
19 void pci_config_writew(PCIDevice d, u32 addr, u16 val);
20 void pci_config_writeb(PCIDevice d, u32 addr, u8 val);
21 u32 pci_config_readl(PCIDevice d, u32 addr);
22 u16 pci_config_readw(PCIDevice d, u32 addr);
23 u8 pci_config_readb(PCIDevice d, u32 addr);
24
25 int pci_find_device(u16 vendid, u16 devid, int index, PCIDevice *dev);
26 int pci_find_class(u32 classid, int index, PCIDevice *dev);
27
28 // pirtable.c
29 void create_pirtable();
30
31
32 /****************************************************************
33  * PCI definitions
34  ****************************************************************/
35
36 #define PCI_VENDOR_ID           0x00    /* 16 bits */
37 #define PCI_DEVICE_ID           0x02    /* 16 bits */
38 #define PCI_COMMAND             0x04    /* 16 bits */
39 #define  PCI_COMMAND_IO         0x1     /* Enable response in I/O space */
40 #define  PCI_COMMAND_MEMORY     0x2     /* Enable response in Memory space */
41 #define PCI_CLASS_DEVICE        0x0a    /* Device class */
42 #define PCI_INTERRUPT_LINE      0x3c    /* 8 bits */
43 #define PCI_INTERRUPT_PIN       0x3d    /* 8 bits */
44 #define PCI_MIN_GNT             0x3e    /* 8 bits */
45 #define PCI_MAX_LAT             0x3f    /* 8 bits */
46
47
48 /****************************************************************
49  * PIR table
50  ****************************************************************/
51
52 struct link_info {
53     u8 link;
54     u16 bitmap;
55 } PACKED;
56
57 struct pir_slot {
58     u8 bus;
59     u8 dev;
60     struct link_info links[4];
61     u8 slot_nr;
62     u8 reserved;
63 } PACKED;
64
65 struct pir_header {
66     u32 signature;
67     u16 version;
68     u16 size;
69     u8 router_bus;
70     u8 router_devfunc;
71     u16 exclusive_irqs;
72     u32 compatible_devid;
73     u32 miniport_data;
74     u8 reserved[11];
75     u8 checksum;
76     struct pir_slot slots[0];
77 } PACKED;
78
79 #define PIR_SIGNATURE 0x52495024 // $PIR
80
81
82 #endif