Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


imported SEABIOS source tree
[palacios.git] / bios / seabios / src / pci.h
1 #ifndef __PCI_H
2 #define __PCI_H
3
4 #include "types.h" // u32
5
6 #define PCI_ROM_SLOT 6
7 #define PCI_NUM_REGIONS 7
8
9 static inline u8 pci_bdf_to_bus(u16 bdf) {
10     return bdf >> 8;
11 }
12 static inline u8 pci_bdf_to_devfn(u16 bdf) {
13     return bdf & 0xff;
14 }
15 static inline u16 pci_bdf_to_busdev(u16 bdf) {
16     return bdf & ~0x07;
17 }
18 static inline u8 pci_bdf_to_dev(u16 bdf) {
19     return (bdf >> 3) & 0x1f;
20 }
21 static inline u8 pci_bdf_to_fn(u16 bdf) {
22     return bdf & 0x07;
23 }
24 static inline u16 pci_to_bdf(int bus, int dev, int fn) {
25     return (bus<<8) | (dev<<3) | fn;
26 }
27 static inline u16 pci_bus_devfn_to_bdf(int bus, u16 devfn) {
28     return (bus << 8) | devfn;
29 }
30
31 void pci_config_writel(u16 bdf, u32 addr, u32 val);
32 void pci_config_writew(u16 bdf, u32 addr, u16 val);
33 void pci_config_writeb(u16 bdf, u32 addr, u8 val);
34 u32 pci_config_readl(u16 bdf, u32 addr);
35 u16 pci_config_readw(u16 bdf, u32 addr);
36 u8 pci_config_readb(u16 bdf, u32 addr);
37 void pci_config_maskw(u16 bdf, u32 addr, u16 off, u16 on);
38
39 struct pci_device *pci_find_device(u16 vendid, u16 devid);
40 struct pci_device *pci_find_class(u16 classid);
41
42 struct pci_device {
43     u16 bdf;
44     u8 rootbus;
45     struct pci_device *next;
46     struct pci_device *parent;
47
48     // Configuration space device information
49     u16 vendor, device;
50     u16 class;
51     u8 prog_if, revision;
52     u8 header_type;
53     u8 secondary_bus;
54     struct {
55         u32 addr;
56         u32 size;
57         int is64;
58     } bars[PCI_NUM_REGIONS];
59
60     // Local information on device.
61     int have_driver;
62 };
63 extern struct pci_device *PCIDevices;
64 extern int MaxPCIBus;
65 int pci_probe_host(void);
66 void pci_probe_devices(void);
67 static inline u32 pci_classprog(struct pci_device *pci) {
68     return (pci->class << 8) | pci->prog_if;
69 }
70
71 #define foreachpci(PCI)                         \
72     for (PCI=PCIDevices; PCI; PCI=PCI->next)
73
74 int pci_next(int bdf, int bus);
75 #define foreachbdf(BDF, BUS)                                    \
76     for (BDF=pci_next(pci_bus_devfn_to_bdf((BUS), 0)-1, (BUS))  \
77          ; BDF >= 0                                             \
78          ; BDF=pci_next(BDF, (BUS)))
79
80 #define PCI_ANY_ID      (~0)
81 struct pci_device_id {
82     u32 vendid;
83     u32 devid;
84     u32 class;
85     u32 class_mask;
86     void (*func)(struct pci_device *pci, void *arg);
87 };
88
89 #define PCI_DEVICE(vendor_id, device_id, init_func)     \
90     {                                                   \
91         .vendid = (vendor_id),                          \
92         .devid = (device_id),                           \
93         .class = PCI_ANY_ID,                            \
94         .class_mask = 0,                                \
95         .func = (init_func)                             \
96     }
97
98 #define PCI_DEVICE_CLASS(vendor_id, device_id, class_code, init_func)   \
99     {                                                                   \
100         .vendid = (vendor_id),                                          \
101         .devid = (device_id),                                           \
102         .class = (class_code),                                          \
103         .class_mask = ~0,                                               \
104         .func = (init_func)                                             \
105     }
106
107 #define PCI_DEVICE_END                          \
108     {                                           \
109         .vendid = 0,                            \
110     }
111
112 int pci_init_device(const struct pci_device_id *ids
113                     , struct pci_device *pci, void *arg);
114 struct pci_device *pci_find_init_device(const struct pci_device_id *ids
115                                         , void *arg);
116 void pci_reboot(void);
117
118 // helper functions to access pci mmio bars from real mode
119 u32 pci_readl(u32 addr);
120 void pci_writel(u32 addr, u32 val);
121
122 // pirtable.c
123 void create_pirtable(void);
124
125
126 /****************************************************************
127  * PIR table
128  ****************************************************************/
129
130 extern u16 PirOffset;
131
132 struct link_info {
133     u8 link;
134     u16 bitmap;
135 } PACKED;
136
137 struct pir_slot {
138     u8 bus;
139     u8 dev;
140     struct link_info links[4];
141     u8 slot_nr;
142     u8 reserved;
143 } PACKED;
144
145 struct pir_header {
146     u32 signature;
147     u16 version;
148     u16 size;
149     u8 router_bus;
150     u8 router_devfunc;
151     u16 exclusive_irqs;
152     u32 compatible_devid;
153     u32 miniport_data;
154     u8 reserved[11];
155     u8 checksum;
156     struct pir_slot slots[0];
157 } PACKED;
158
159 #define PIR_SIGNATURE 0x52495024 // $PIR
160
161
162 #endif