]> git.proxmox.com Git - grub2.git/blob - debian/grub-extras/disabled/gpxe/include_wrap/gpxe/pci.h
grub2 (2.02+dfsg1-20) unstable; urgency=medium
[grub2.git] / debian / grub-extras / disabled / gpxe / include_wrap / gpxe / pci.h
1 /*
2 * Copyright © 2009 Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 FILE_LICENCE ( BSD2 );
32
33 #ifndef _GPXE_PCI_H
34 #define _GPXE_PCI_H
35
36 #include <grub/pci.h>
37 #include <gpxe/wrap.h>
38 #include <gpxe/timer.h>
39
40 static inline grub_uint8_t
41 inb (grub_uint16_t port)
42 {
43 return grub_inb (GRUB_MACHINE_PCI_IO_BASE + port);
44 }
45
46 static inline void
47 outb (grub_uint8_t data, grub_uint16_t port)
48 {
49 return grub_outb (data, GRUB_MACHINE_PCI_IO_BASE + port);
50 }
51
52 static inline void
53 outw (grub_uint16_t data, grub_uint16_t port)
54 {
55 return grub_outw (data, GRUB_MACHINE_PCI_IO_BASE + port);
56 }
57
58 static inline grub_uint16_t
59 inw (grub_uint16_t port)
60 {
61 return grub_inw (GRUB_MACHINE_PCI_IO_BASE + port);
62 }
63
64 static inline void
65 insw (grub_uint16_t port, grub_uint16_t *data, int count)
66 {
67 while (count--)
68 *data++ = grub_inw (GRUB_MACHINE_PCI_IO_BASE + port);
69 }
70
71 static inline void
72 outsw (grub_uint16_t port, grub_uint16_t *data, int count)
73 {
74 while (count--)
75 grub_outw (*data++, GRUB_MACHINE_PCI_IO_BASE + port);
76 }
77
78 static inline void
79 outsb (grub_uint16_t port, grub_uint8_t *data, int count)
80 {
81 while (count--)
82 grub_outb (*data++, GRUB_MACHINE_PCI_IO_BASE + port);
83 }
84
85 static inline void
86 insb (grub_uint16_t port, grub_uint8_t *data, int count)
87 {
88 while (count--)
89 *data++ = grub_inb (GRUB_MACHINE_PCI_IO_BASE + port);
90 }
91
92 static inline void
93 outl (grub_uint32_t data, grub_uint16_t port)
94 {
95 return grub_outw (data, GRUB_MACHINE_PCI_IO_BASE + port);
96 }
97
98 static inline grub_uint16_t
99 inl (grub_uint32_t port)
100 {
101 return grub_inw (GRUB_MACHINE_PCI_IO_BASE + port);
102 }
103
104 struct device_description
105 {
106 enum {BUS_TYPE_PCI, BUS_TYPE_ISA} bus_type;
107 int bus;
108 int location;
109 grub_uint16_t vendor;
110 grub_uint16_t device;
111 };
112
113 struct device
114 {
115 struct device_description desc;
116 char *name;
117 union
118 {
119 grub_pci_device_t pci_dev;
120 };
121 };
122
123 struct pci_device
124 {
125 struct device dev;
126
127 grub_uint16_t ioaddr;
128 grub_uint16_t vendor;
129 grub_uint16_t device;
130
131 int irq;
132
133 void *priv;
134
135 void *drvdata;
136 };
137
138 struct pci_device_id
139 {
140 grub_pci_id_t devid;
141 };
142
143 #define PCI_ROM(vendor, model, short_name, long_name, num) {.devid = ((vendor) | ((model) << 16))}
144 #define __pci_driver
145
146 struct nic;
147
148 struct pci_driver
149 {
150 struct pci_device_id *ids;
151 grub_size_t id_count;
152 int (*probe) (struct pci_device *pci, const struct pci_device_id *id);
153 void (*remove) (struct pci_device *pci);
154 void (*irq) (struct nic *nic, int action);
155 };
156
157 static inline void
158 pci_read_config_byte (struct pci_device *dev, grub_uint32_t reg,
159 grub_uint8_t *val)
160 {
161 grub_pci_address_t addr;
162 addr = grub_pci_make_address (dev->dev.pci_dev, reg);
163 *val = grub_pci_read_byte (addr);
164 }
165
166 static inline void
167 pci_read_config_word (struct pci_device *dev, grub_uint32_t reg,
168 grub_uint16_t *val)
169 {
170 grub_pci_address_t addr;
171 addr = grub_pci_make_address (dev->dev.pci_dev, reg);
172 *val = grub_pci_read_word (addr);
173 }
174
175 static inline void
176 pci_read_config_dword (struct pci_device *dev, grub_uint32_t reg,
177 grub_uint32_t *val)
178 {
179 grub_pci_address_t addr;
180 addr = grub_pci_make_address (dev->dev.pci_dev, reg);
181 *val = grub_pci_read (addr);
182 }
183
184 static inline void
185 pci_write_config_byte (struct pci_device *dev, grub_uint32_t reg,
186 grub_uint8_t val)
187 {
188 grub_pci_address_t addr;
189 addr = grub_pci_make_address (dev->dev.pci_dev, reg);
190 grub_pci_write_byte (addr, val);
191 }
192
193 static inline void
194 pci_write_config_word (struct pci_device *dev, grub_uint32_t reg,
195 grub_uint16_t val)
196 {
197 grub_pci_address_t addr;
198 addr = grub_pci_make_address (dev->dev.pci_dev, reg);
199 grub_pci_write_word (addr, val);
200 }
201
202 static inline void
203 pci_write_config_dword (struct pci_device *dev, grub_uint32_t reg,
204 grub_uint32_t val)
205 {
206 grub_pci_address_t addr;
207 addr = grub_pci_make_address (dev->dev.pci_dev, reg);
208 grub_pci_write (addr, val);
209 }
210
211 static inline void *
212 pci_get_drvdata (struct pci_device *dev)
213 {
214 return dev->drvdata;
215 }
216
217 static inline void
218 pci_set_drvdata (struct pci_device *dev, void *data)
219 {
220 dev->drvdata = data;
221 }
222
223 static inline grub_uint32_t
224 readl (volatile void *ptr)
225 {
226 return *(volatile grub_uint32_t *) ptr;
227 }
228
229 static inline void
230 writel (grub_uint32_t data, volatile void *ptr)
231 {
232 *(volatile grub_uint32_t *) ptr = data;
233 }
234
235 static inline grub_addr_t
236 pci_bar_start (struct pci_device *dev, grub_uint32_t reg)
237 {
238 grub_pci_address_t addr;
239 grub_uint64_t space;
240
241 addr = grub_pci_make_address (dev->dev.pci_dev, reg >> 2);
242 space = grub_pci_read (addr);
243
244 if ((space & GRUB_PCI_ADDR_SPACE_MASK) == GRUB_PCI_ADDR_SPACE_IO)
245 return space & GRUB_PCI_ADDR_IO_MASK;
246
247 if ((space & GRUB_PCI_ADDR_MEM_TYPE_MASK) == GRUB_PCI_ADDR_MEM_TYPE_64)
248 {
249 addr = grub_pci_make_address (dev->dev.pci_dev, (reg >> 2) + 1);
250 space |= ((grub_uint64_t) grub_pci_read (addr)) << 32;
251 }
252
253 return space & GRUB_PCI_ADDR_MEM_MASK;
254 }
255
256 /* XXX: make it use grub_pci_device_map_range. */
257 static inline void *
258 bus_to_virt (grub_uint32_t bus)
259 {
260 return (void *) bus;
261 }
262
263 static inline void *
264 ioremap (grub_uint32_t bus, grub_size_t size __attribute__ ((unused)))
265 {
266 return (void *) bus;
267 }
268
269 static inline grub_uint32_t
270 virt_to_bus (void *virt)
271 {
272 return (grub_addr_t) virt;
273 }
274
275 void
276 grub_gpxe_register_pci_nic (struct pci_driver *nic);
277
278 void
279 grub_gpxe_unregister_pci_nic (struct pci_driver *nic);
280
281 void adjust_pci_device ( struct pci_device *pci );
282
283 #define PCI_VENDOR_ID_DAVICOM 0x0291
284 #define PCI_VENDOR_ID_WINBOND2 0x1050
285 #define PCI_VENDOR_ID_COMPEX 0x11f6
286 #define PCI_COMMAND GRUB_PCI_REG_COMMAND
287 #define PCI_REVISION_ID GRUB_PCI_REG_REVISION
288 #define PCI_REVISION PCI_REVISION_ID
289 #define PCI_LATENCY_TIMER GRUB_PCI_REG_LAT_TIMER
290 #define PCI_BASE_ADDRESS_0 GRUB_PCI_REG_ADDRESS_REG0
291 #define PCI_BASE_ADDRESS_1 GRUB_PCI_REG_ADDRESS_REG1
292 #define PCI_COMMAND_IO 0x1
293 #define PCI_COMMAND_MEM 0x2
294 #define PCI_COMMAND_MASTER 0x4
295
296 #endif