2
* (C) Copyright IBM Corporation 2006
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:
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
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.
28
* \author Ian Romanick <idr@us.ibm.com>
37
#define __deprecated __attribute__((deprecated))
42
typedef uint64_t pciaddr_t;
45
struct pci_device_iterator;
47
struct pci_slot_match;
49
int pci_device_read_rom(struct pci_device *dev, void *buffer);
51
int __deprecated pci_device_map_region(struct pci_device *dev,
52
unsigned region, int write_enable);
54
int __deprecated pci_device_unmap_region(struct pci_device *dev,
57
int pci_device_map_range(struct pci_device *dev, pciaddr_t base,
58
pciaddr_t size, unsigned map_flags, void **addr);
60
int pci_device_unmap_range(struct pci_device *dev, void *memory,
63
int __deprecated pci_device_map_memory_range(struct pci_device *dev,
64
pciaddr_t base, pciaddr_t size, int write_enable, void **addr);
66
int __deprecated pci_device_unmap_memory_range(struct pci_device *dev,
67
void *memory, pciaddr_t size);
69
int pci_device_probe(struct pci_device *dev);
71
const struct pci_agp_info *pci_device_get_agp_info(struct pci_device *dev);
73
const struct pci_bridge_info *pci_device_get_bridge_info(
74
struct pci_device *dev);
76
const struct pci_pcmcia_bridge_info *pci_device_get_pcmcia_bridge_info(
77
struct pci_device *dev);
79
int pci_device_get_bridge_buses(struct pci_device *dev, int *primary_bus,
80
int *secondary_bus, int *subordinate_bus);
82
int pci_system_init(void);
84
void pci_system_cleanup(void);
86
struct pci_device_iterator *pci_slot_match_iterator_create(
87
const struct pci_slot_match *match);
89
struct pci_device_iterator *pci_id_match_iterator_create(
90
const struct pci_id_match *match);
92
void pci_iterator_destroy(struct pci_device_iterator *iter);
94
struct pci_device *pci_device_next(struct pci_device_iterator *iter);
96
struct pci_device *pci_device_find_by_slot(uint32_t domain, uint32_t bus,
97
uint32_t dev, uint32_t func);
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);
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,
111
int pci_device_cfg_read_u16(struct pci_device *dev, uint16_t *data,
113
int pci_device_cfg_read_u32(struct pci_device *dev, uint32_t *data,
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,
120
int pci_device_cfg_write_u16(struct pci_device *dev, uint16_t data,
122
int pci_device_cfg_write_u32(struct pci_device *dev, uint32_t data,
124
int pci_device_cfg_write_bits(struct pci_device *dev, uint32_t mask,
125
uint32_t data, pciaddr_t offset);
128
* \name Mapping flags passed to \c pci_device_map_range
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)
137
#define PCI_MATCH_ANY (~0)
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
144
#define PCI_ID_COMPARE(a, b) \
145
(((a) == PCI_MATCH_ANY) || ((a) == (b)))
149
struct pci_id_match {
151
* \name Device / vendor matching controls
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.
160
uint32_t subvendor_id;
161
uint32_t subdevice_id;
166
* \name Device class matching controls
170
uint32_t device_class;
171
uint32_t device_class_mask;
180
struct pci_slot_match {
182
* \name Device slot matching controls
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.
199
* BAR descriptor for a PCI device.
201
struct pci_mem_region {
203
* When the region is mapped, this is the pointer to the memory.
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.
214
* Base physical address of the region within its bus / domain.
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
222
* Most (all?) platform back-ends leave this field unset.
228
* Base physical address of the region from the CPU's point of view.
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.
237
* Size, in bytes, of the region.
243
* Is the region I/O ports or memory?
248
* Is the memory region prefetchable?
251
* This can only be set if \c is_IO is not set.
253
unsigned is_prefetchable:1;
257
* Is the memory at a 64-bit address?
260
* This can only be set if \c is_IO is not set.
269
* Contains all of the information about a particular PCI device.
273
* \name Device bus identification.
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.
288
* \name Vendor / device ID
290
* The vendor ID, device ID, and sub-IDs for the device.
295
uint16_t subvendor_id;
296
uint16_t subdevice_id;
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].
304
uint32_t device_class;
308
* Device revision number, as read from the configuration header.
314
* BAR descriptors for the device.
316
struct pci_mem_region regions[6];
320
* Size, in bytes, of the device's expansion ROM.
326
* IRQ associated with the device. If there is no IRQ, this value will
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.
343
* Description of the AGP capability of the device.
345
* \sa pci_device_get_agp_info
347
struct pci_agp_info {
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.
353
unsigned config_offset;
357
* \name AGP major / minor version.
360
uint8_t major_version;
361
uint8_t minor_version;
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.
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;
379
uint8_t async_req_size;
380
uint8_t calibration_cycle_timing;
381
uint8_t max_requests;
385
* Description of a PCI-to-PCI bridge device.
387
* \sa pci_device_get_bridge_info
389
struct pci_bridge_info {
391
uint8_t secondary_bus;
392
uint8_t subordinate_bus;
393
uint8_t secondary_latency_timer;
397
uint8_t prefetch_mem_type;
399
uint16_t secondary_status;
400
uint16_t bridge_control;
408
uint64_t prefetch_mem_base;
409
uint64_t prefetch_mem_limit;
413
* Description of a PCI-to-PCMCIA bridge device.
415
* \sa pci_device_get_pcmcia_bridge_info
417
struct pci_pcmcia_bridge_info {
420
uint8_t subordinate_bus;
421
uint8_t cardbus_latency_timer;
423
uint16_t secondary_status;
424
uint16_t bridge_control;
438
#endif /* PCIACCESS_H */