1 | /*
|
---|
2 | * (C) Copyright IBM Corporation 2006
|
---|
3 | * All Rights Reserved.
|
---|
4 | *
|
---|
5 | * Permission is hereby granted, free of charge, to any person obtaining a
|
---|
6 | * copy of this software and associated documentation files (the "Software"),
|
---|
7 | * to deal in the Software without restriction, including without limitation
|
---|
8 | * on the rights to use, copy, modify, merge, publish, distribute, sub
|
---|
9 | * license, and/or sell copies of the Software, and to permit persons to whom
|
---|
10 | * the Software is furnished to do so, subject to the following conditions:
|
---|
11 | *
|
---|
12 | * The above copyright notice and this permission notice (including the next
|
---|
13 | * paragraph) shall be included in all copies or substantial portions of the
|
---|
14 | * Software.
|
---|
15 | *
|
---|
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
---|
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
|
---|
19 | * IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
---|
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
---|
21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
---|
22 | * DEALINGS IN THE SOFTWARE.
|
---|
23 | */
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * \file pciaccess.h
|
---|
27 | *
|
---|
28 | * \author Ian Romanick <[email protected]>
|
---|
29 | */
|
---|
30 |
|
---|
31 | #ifndef PCIACCESS_H
|
---|
32 | #define PCIACCESS_H
|
---|
33 |
|
---|
34 | #include <inttypes.h>
|
---|
35 |
|
---|
36 | #if __GNUC__ >= 3
|
---|
37 | #define __deprecated __attribute__((deprecated))
|
---|
38 | #else
|
---|
39 | #define __deprecated
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | typedef uint64_t pciaddr_t;
|
---|
43 |
|
---|
44 | struct pci_device;
|
---|
45 | struct pci_device_iterator;
|
---|
46 | struct pci_id_match;
|
---|
47 | struct pci_slot_match;
|
---|
48 |
|
---|
49 | int pci_device_read_rom(struct pci_device *dev, void *buffer);
|
---|
50 |
|
---|
51 | int __deprecated pci_device_map_region(struct pci_device *dev,
|
---|
52 | unsigned region, int write_enable);
|
---|
53 |
|
---|
54 | int __deprecated pci_device_unmap_region(struct pci_device *dev,
|
---|
55 | unsigned region);
|
---|
56 |
|
---|
57 | int pci_device_map_range(struct pci_device *dev, pciaddr_t base,
|
---|
58 | pciaddr_t size, unsigned map_flags, void **addr);
|
---|
59 |
|
---|
60 | int pci_device_unmap_range(struct pci_device *dev, void *memory,
|
---|
61 | pciaddr_t size);
|
---|
62 |
|
---|
63 | int __deprecated pci_device_map_memory_range(struct pci_device *dev,
|
---|
64 | pciaddr_t base, pciaddr_t size, int write_enable, void **addr);
|
---|
65 |
|
---|
66 | int __deprecated pci_device_unmap_memory_range(struct pci_device *dev,
|
---|
67 | void *memory, pciaddr_t size);
|
---|
68 |
|
---|
69 | int pci_device_probe(struct pci_device *dev);
|
---|
70 |
|
---|
71 | const struct pci_agp_info *pci_device_get_agp_info(struct pci_device *dev);
|
---|
72 |
|
---|
73 | const struct pci_bridge_info *pci_device_get_bridge_info(
|
---|
74 | struct pci_device *dev);
|
---|
75 |
|
---|
76 | const struct pci_pcmcia_bridge_info *pci_device_get_pcmcia_bridge_info(
|
---|
77 | struct pci_device *dev);
|
---|
78 |
|
---|
79 | int pci_device_get_bridge_buses(struct pci_device *dev, int *primary_bus,
|
---|
80 | int *secondary_bus, int *subordinate_bus);
|
---|
81 |
|
---|
82 | int pci_system_init(void);
|
---|
83 |
|
---|
84 | void pci_system_cleanup(void);
|
---|
85 |
|
---|
86 | struct pci_device_iterator *pci_slot_match_iterator_create(
|
---|
87 | const struct pci_slot_match *match);
|
---|
88 |
|
---|
89 | struct pci_device_iterator *pci_id_match_iterator_create(
|
---|
90 | const struct pci_id_match *match);
|
---|
91 |
|
---|
92 | void pci_iterator_destroy(struct pci_device_iterator *iter);
|
---|
93 |
|
---|
94 | struct pci_device *pci_device_next(struct pci_device_iterator *iter);
|
---|
95 |
|
---|
96 | struct pci_device *pci_device_find_by_slot(uint32_t domain, uint32_t bus,
|
---|
97 | uint32_t dev, uint32_t func);
|
---|
98 |
|
---|
99 | void pci_get_strings(const struct pci_id_match *m,
|
---|
100 | const char **device_name, const char **vendor_name,
|
---|
101 | const char **subdevice_name, const char **subvendor_name);
|
---|
102 | const char *pci_device_get_device_name(const struct pci_device *dev);
|
---|
103 | const char *pci_device_get_subdevice_name(const struct pci_device *dev);
|
---|
104 | const char *pci_device_get_vendor_name(const struct pci_device *dev);
|
---|
105 | const char *pci_device_get_subvendor_name(const struct pci_device *dev);
|
---|
106 |
|
---|
107 | int pci_device_cfg_read (struct pci_device *dev, void *data,
|
---|
108 | pciaddr_t offset, pciaddr_t size, pciaddr_t *bytes_read);
|
---|
109 | int pci_device_cfg_read_u8 (struct pci_device *dev, uint8_t *data,
|
---|
110 | pciaddr_t offset);
|
---|
111 | int pci_device_cfg_read_u16(struct pci_device *dev, uint16_t *data,
|
---|
112 | pciaddr_t offset);
|
---|
113 | int pci_device_cfg_read_u32(struct pci_device *dev, uint32_t *data,
|
---|
114 | pciaddr_t offset);
|
---|
115 |
|
---|
116 | int pci_device_cfg_write (struct pci_device *dev, const void *data,
|
---|
117 | pciaddr_t offset, pciaddr_t size, pciaddr_t *bytes_written);
|
---|
118 | int pci_device_cfg_write_u8 (struct pci_device *dev, uint8_t data,
|
---|
119 | pciaddr_t offset);
|
---|
120 | int pci_device_cfg_write_u16(struct pci_device *dev, uint16_t data,
|
---|
121 | pciaddr_t offset);
|
---|
122 | int pci_device_cfg_write_u32(struct pci_device *dev, uint32_t data,
|
---|
123 | pciaddr_t offset);
|
---|
124 | int pci_device_cfg_write_bits(struct pci_device *dev, uint32_t mask,
|
---|
125 | uint32_t data, pciaddr_t offset);
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * \name Mapping flags passed to \c pci_device_map_range
|
---|
129 | */
|
---|
130 | /*@{*/
|
---|
131 | #define PCI_DEV_MAP_FLAG_WRITABLE (1U<<0)
|
---|
132 | #define PCI_DEV_MAP_FLAG_WRITE_COMBINE (1U<<1)
|
---|
133 | #define PCI_DEV_MAP_FLAG_CACHABLE (1U<<2)
|
---|
134 | /*@}*/
|
---|
135 |
|
---|
136 |
|
---|
137 | #define PCI_MATCH_ANY (~0)
|
---|
138 |
|
---|
139 | /**
|
---|
140 | * Compare two PCI ID values (either vendor or device). This is used
|
---|
141 | * internally to compare the fields of \c pci_id_match to the fields of
|
---|
142 | * \c pci_device.
|
---|
143 | */
|
---|
144 | #define PCI_ID_COMPARE(a, b) \
|
---|
145 | (((a) == PCI_MATCH_ANY) || ((a) == (b)))
|
---|
146 |
|
---|
147 | /**
|
---|
148 | */
|
---|
149 | struct pci_id_match {
|
---|
150 | /**
|
---|
151 | * \name Device / vendor matching controls
|
---|
152 | *
|
---|
153 | * Control the search based on the device, vendor, subdevice, or subvendor
|
---|
154 | * IDs. Setting any of these fields to \c PCI_MATCH_ANY will cause the
|
---|
155 | * field to not be used in the comparison.
|
---|
156 | */
|
---|
157 | /*@{*/
|
---|
158 | uint32_t vendor_id;
|
---|
159 | uint32_t device_id;
|
---|
160 | uint32_t subvendor_id;
|
---|
161 | uint32_t subdevice_id;
|
---|
162 | /*@}*/
|
---|
163 |
|
---|
164 |
|
---|
165 | /**
|
---|
166 | * \name Device class matching controls
|
---|
167 | *
|
---|
168 | */
|
---|
169 | /*@{*/
|
---|
170 | uint32_t device_class;
|
---|
171 | uint32_t device_class_mask;
|
---|
172 | /*@}*/
|
---|
173 |
|
---|
174 | intptr_t match_data;
|
---|
175 | };
|
---|
176 |
|
---|
177 |
|
---|
178 | /**
|
---|
179 | */
|
---|
180 | struct pci_slot_match {
|
---|
181 | /**
|
---|
182 | * \name Device slot matching controls
|
---|
183 | *
|
---|
184 | * Control the search based on the domain, bus, slot, and function of
|
---|
185 | * the device. Setting any of these fields to \c PCI_MATCH_ANY will cause
|
---|
186 | * the field to not be used in the comparison.
|
---|
187 | */
|
---|
188 | /*@{*/
|
---|
189 | uint32_t domain;
|
---|
190 | uint32_t bus;
|
---|
191 | uint32_t dev;
|
---|
192 | uint32_t func;
|
---|
193 | /*@}*/
|
---|
194 |
|
---|
195 | intptr_t match_data;
|
---|
196 | };
|
---|
197 |
|
---|
198 | /**
|
---|
199 | * BAR descriptor for a PCI device.
|
---|
200 | */
|
---|
201 | struct pci_mem_region {
|
---|
202 | /**
|
---|
203 | * When the region is mapped, this is the pointer to the memory.
|
---|
204 | *
|
---|
205 | * This field is \b only set when the deprecated \c pci_device_map_region
|
---|
206 | * interface is used. Use \c pci_device_map_range instead.
|
---|
207 | *
|
---|
208 | * \deprecated
|
---|
209 | */
|
---|
210 | void *memory;
|
---|
211 |
|
---|
212 |
|
---|
213 | /**
|
---|
214 | * Base physical address of the region within its bus / domain.
|
---|
215 | *
|
---|
216 | * \warning
|
---|
217 | * This address is really only useful to other devices in the same
|
---|
218 | * domain. It's probably \b not the address applications will ever
|
---|
219 | * use.
|
---|
220 | *
|
---|
221 | * \warning
|
---|
222 | * Most (all?) platform back-ends leave this field unset.
|
---|
223 | */
|
---|
224 | pciaddr_t bus_addr;
|
---|
225 |
|
---|
226 |
|
---|
227 | /**
|
---|
228 | * Base physical address of the region from the CPU's point of view.
|
---|
229 | *
|
---|
230 | * This address is typically passed to \c pci_device_map_range to create
|
---|
231 | * a mapping of the region to the CPU's virtual address space.
|
---|
232 | */
|
---|
233 | pciaddr_t base_addr;
|
---|
234 |
|
---|
235 |
|
---|
236 | /**
|
---|
237 | * Size, in bytes, of the region.
|
---|
238 | */
|
---|
239 | pciaddr_t size;
|
---|
240 |
|
---|
241 |
|
---|
242 | /**
|
---|
243 | * Is the region I/O ports or memory?
|
---|
244 | */
|
---|
245 | unsigned is_IO:1;
|
---|
246 |
|
---|
247 | /**
|
---|
248 | * Is the memory region prefetchable?
|
---|
249 | *
|
---|
250 | * \note
|
---|
251 | * This can only be set if \c is_IO is not set.
|
---|
252 | */
|
---|
253 | unsigned is_prefetchable:1;
|
---|
254 |
|
---|
255 |
|
---|
256 | /**
|
---|
257 | * Is the memory at a 64-bit address?
|
---|
258 | *
|
---|
259 | * \note
|
---|
260 | * This can only be set if \c is_IO is not set.
|
---|
261 | */
|
---|
262 | unsigned is_64:1;
|
---|
263 | };
|
---|
264 |
|
---|
265 |
|
---|
266 | /**
|
---|
267 | * PCI device.
|
---|
268 | *
|
---|
269 | * Contains all of the information about a particular PCI device.
|
---|
270 | */
|
---|
271 | struct pci_device {
|
---|
272 | /**
|
---|
273 | * \name Device bus identification.
|
---|
274 | *
|
---|
275 | * Complete bus identification, including domain, of the device. On
|
---|
276 | * platforms that do not support PCI domains (e.g., 32-bit x86 hardware),
|
---|
277 | * the domain will always be zero.
|
---|
278 | */
|
---|
279 | /*@{*/
|
---|
280 | uint16_t domain;
|
---|
281 | uint8_t bus;
|
---|
282 | uint8_t dev;
|
---|
283 | uint8_t func;
|
---|
284 | /*@}*/
|
---|
285 |
|
---|
286 |
|
---|
287 | /**
|
---|
288 | * \name Vendor / device ID
|
---|
289 | *
|
---|
290 | * The vendor ID, device ID, and sub-IDs for the device.
|
---|
291 | */
|
---|
292 | /*@{*/
|
---|
293 | uint16_t vendor_id;
|
---|
294 | uint16_t device_id;
|
---|
295 | uint16_t subvendor_id;
|
---|
296 | uint16_t subdevice_id;
|
---|
297 | /*@}*/
|
---|
298 |
|
---|
299 | /**
|
---|
300 | * Device's class, subclass, and programming interface packed into a
|
---|
301 | * single 32-bit value. The class is at bits [23:16], subclass is at
|
---|
302 | * bits [15:8], and programming interface is at [7:0].
|
---|
303 | */
|
---|
304 | uint32_t device_class;
|
---|
305 |
|
---|
306 |
|
---|
307 | /**
|
---|
308 | * Device revision number, as read from the configuration header.
|
---|
309 | */
|
---|
310 | uint8_t revision;
|
---|
311 |
|
---|
312 |
|
---|
313 | /**
|
---|
314 | * BAR descriptors for the device.
|
---|
315 | */
|
---|
316 | struct pci_mem_region regions[6];
|
---|
317 |
|
---|
318 |
|
---|
319 | /**
|
---|
320 | * Size, in bytes, of the device's expansion ROM.
|
---|
321 | */
|
---|
322 | pciaddr_t rom_size;
|
---|
323 |
|
---|
324 |
|
---|
325 | /**
|
---|
326 | * IRQ associated with the device. If there is no IRQ, this value will
|
---|
327 | * be -1.
|
---|
328 | */
|
---|
329 | int irq;
|
---|
330 |
|
---|
331 |
|
---|
332 | /**
|
---|
333 | * Storage for user data. Users of the library can store arbitrary
|
---|
334 | * data in this pointer. The library will not use it for any purpose.
|
---|
335 | * It is the user's responsability to free this memory before destroying
|
---|
336 | * the \c pci_device structure.
|
---|
337 | */
|
---|
338 | intptr_t user_data;
|
---|
339 | };
|
---|
340 |
|
---|
341 |
|
---|
342 | /**
|
---|
343 | * Description of the AGP capability of the device.
|
---|
344 | *
|
---|
345 | * \sa pci_device_get_agp_info
|
---|
346 | */
|
---|
347 | struct pci_agp_info {
|
---|
348 | /**
|
---|
349 | * Offset of the AGP registers in the devices configuration register
|
---|
350 | * space. This is generally used so that the offset of the AGP command
|
---|
351 | * register can be determined.
|
---|
352 | */
|
---|
353 | unsigned config_offset;
|
---|
354 |
|
---|
355 |
|
---|
356 | /**
|
---|
357 | * \name AGP major / minor version.
|
---|
358 | */
|
---|
359 | /*@{*/
|
---|
360 | uint8_t major_version;
|
---|
361 | uint8_t minor_version;
|
---|
362 | /*@}*/
|
---|
363 |
|
---|
364 | /**
|
---|
365 | * Logical OR of the supported AGP rates. For example, a value of 0x07
|
---|
366 | * means that the device can support 1x, 2x, and 4x. A value of 0x0c
|
---|
367 | * means that the device can support 8x and 4x.
|
---|
368 | */
|
---|
369 | uint8_t rates;
|
---|
370 |
|
---|
371 | unsigned int fast_writes:1; /**< Are fast-writes supported? */
|
---|
372 | unsigned int addr64:1;
|
---|
373 | unsigned int htrans:1;
|
---|
374 | unsigned int gart64:1;
|
---|
375 | unsigned int coherent:1;
|
---|
376 | unsigned int sideband:1; /**< Is side-band addressing supported? */
|
---|
377 | unsigned int isochronus:1;
|
---|
378 |
|
---|
379 | uint8_t async_req_size;
|
---|
380 | uint8_t calibration_cycle_timing;
|
---|
381 | uint8_t max_requests;
|
---|
382 | };
|
---|
383 |
|
---|
384 | /**
|
---|
385 | * Description of a PCI-to-PCI bridge device.
|
---|
386 | *
|
---|
387 | * \sa pci_device_get_bridge_info
|
---|
388 | */
|
---|
389 | struct pci_bridge_info {
|
---|
390 | uint8_t primary_bus;
|
---|
391 | uint8_t secondary_bus;
|
---|
392 | uint8_t subordinate_bus;
|
---|
393 | uint8_t secondary_latency_timer;
|
---|
394 |
|
---|
395 | uint8_t io_type;
|
---|
396 | uint8_t mem_type;
|
---|
397 | uint8_t prefetch_mem_type;
|
---|
398 |
|
---|
399 | uint16_t secondary_status;
|
---|
400 | uint16_t bridge_control;
|
---|
401 |
|
---|
402 | uint32_t io_base;
|
---|
403 | uint32_t io_limit;
|
---|
404 |
|
---|
405 | uint32_t mem_base;
|
---|
406 | uint32_t mem_limit;
|
---|
407 |
|
---|
408 | uint64_t prefetch_mem_base;
|
---|
409 | uint64_t prefetch_mem_limit;
|
---|
410 | };
|
---|
411 |
|
---|
412 | /**
|
---|
413 | * Description of a PCI-to-PCMCIA bridge device.
|
---|
414 | *
|
---|
415 | * \sa pci_device_get_pcmcia_bridge_info
|
---|
416 | */
|
---|
417 | struct pci_pcmcia_bridge_info {
|
---|
418 | uint8_t primary_bus;
|
---|
419 | uint8_t card_bus;
|
---|
420 | uint8_t subordinate_bus;
|
---|
421 | uint8_t cardbus_latency_timer;
|
---|
422 |
|
---|
423 | uint16_t secondary_status;
|
---|
424 | uint16_t bridge_control;
|
---|
425 |
|
---|
426 | struct {
|
---|
427 | uint32_t base;
|
---|
428 | uint32_t limit;
|
---|
429 | } io[2];
|
---|
430 |
|
---|
431 | struct {
|
---|
432 | uint32_t base;
|
---|
433 | uint32_t limit;
|
---|
434 | } mem[2];
|
---|
435 |
|
---|
436 | };
|
---|
437 |
|
---|
438 | #endif /* PCIACCESS_H */
|
---|