iPXE
pci.h
Go to the documentation of this file.
1#ifndef _IPXE_PCI_H
2#define _IPXE_PCI_H
3
4/** @file
5 *
6 * PCI bus
7 *
8 */
9
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11FILE_SECBOOT ( PERMITTED );
12
13#include <stdint.h>
14#include <ipxe/device.h>
15#include <ipxe/tables.h>
16#include <ipxe/dma.h>
17#include <ipxe/pci_io.h>
18
19/** PCI vendor ID */
20#define PCI_VENDOR_ID 0x00
21
22/** PCI device ID */
23#define PCI_DEVICE_ID 0x02
24
25/** PCI command */
26#define PCI_COMMAND 0x04
27#define PCI_COMMAND_IO 0x0001 /**< I/O space */
28#define PCI_COMMAND_MEM 0x0002 /**< Memory space */
29#define PCI_COMMAND_MASTER 0x0004 /**< Bus master */
30#define PCI_COMMAND_INVALIDATE 0x0010 /**< Mem. write & invalidate */
31#define PCI_COMMAND_PARITY 0x0040 /**< Parity error response */
32#define PCI_COMMAND_SERR 0x0100 /**< SERR# enable */
33#define PCI_COMMAND_INTX_DISABLE 0x0400 /**< Interrupt disable */
34
35/** PCI status */
36#define PCI_STATUS 0x06
37#define PCI_STATUS_CAP_LIST 0x0010 /**< Capabilities list */
38#define PCI_STATUS_PARITY 0x0100 /**< Master data parity error */
39#define PCI_STATUS_REC_TARGET_ABORT 0x1000 /**< Received target abort */
40#define PCI_STATUS_REC_MASTER_ABORT 0x2000 /**< Received master abort */
41#define PCI_STATUS_SIG_SYSTEM_ERROR 0x4000 /**< Signalled system error */
42#define PCI_STATUS_DETECTED_PARITY 0x8000 /**< Detected parity error */
43
44/** PCI revision */
45#define PCI_REVISION 0x08
46
47/** PCI cache line size */
48#define PCI_CACHE_LINE_SIZE 0x0c
49
50/** PCI latency timer */
51#define PCI_LATENCY_TIMER 0x0d
52
53/** PCI header type */
54#define PCI_HEADER_TYPE 0x0e
55#define PCI_HEADER_TYPE_NORMAL 0x00 /**< Normal header */
56#define PCI_HEADER_TYPE_BRIDGE 0x01 /**< PCI-to-PCI bridge header */
57#define PCI_HEADER_TYPE_CARDBUS 0x02 /**< CardBus header */
58#define PCI_HEADER_TYPE_MASK 0x7f /**< Header type mask */
59#define PCI_HEADER_TYPE_MULTI 0x80 /**< Multi-function device */
60
61/** PCI base address registers */
62#define PCI_BASE_ADDRESS(n) ( 0x10 + ( 4 * (n) ) )
63#define PCI_BASE_ADDRESS_0 PCI_BASE_ADDRESS ( 0 )
64#define PCI_BASE_ADDRESS_1 PCI_BASE_ADDRESS ( 1 )
65#define PCI_BASE_ADDRESS_2 PCI_BASE_ADDRESS ( 2 )
66#define PCI_BASE_ADDRESS_3 PCI_BASE_ADDRESS ( 3 )
67#define PCI_BASE_ADDRESS_4 PCI_BASE_ADDRESS ( 4 )
68#define PCI_BASE_ADDRESS_5 PCI_BASE_ADDRESS ( 5 )
69#define PCI_BASE_ADDRESS_SPACE_IO 0x00000001UL /**< I/O BAR */
70#define PCI_BASE_ADDRESS_IO_MASK 0x00000003UL /**< I/O BAR mask */
71#define PCI_BASE_ADDRESS_MEM_TYPE_64 0x00000004UL /**< 64-bit memory */
72#define PCI_BASE_ADDRESS_MEM_TYPE_MASK 0x00000006UL /**< Memory type mask */
73#define PCI_BASE_ADDRESS_MEM_MASK 0x0000000fUL /**< Memory BAR mask */
74
75/** PCI subsystem vendor ID */
76#define PCI_SUBSYSTEM_VENDOR_ID 0x2c
77
78/** PCI subsystem ID */
79#define PCI_SUBSYSTEM_ID 0x2e
80
81/** PCI expansion ROM base address */
82#define PCI_ROM_ADDRESS 0x30
83
84/** PCI capabilities pointer */
85#define PCI_CAPABILITY_LIST 0x34
86
87/** CardBus capabilities pointer */
88#define PCI_CB_CAPABILITY_LIST 0x14
89
90/** PCI interrupt line */
91#define PCI_INTERRUPT_LINE 0x3c
92
93/** Capability ID */
94#define PCI_CAP_ID 0x00
95#define PCI_CAP_ID_PM 0x01 /**< Power management */
96#define PCI_CAP_ID_VPD 0x03 /**< Vital product data */
97#define PCI_CAP_ID_VNDR 0x09 /**< Vendor-specific */
98#define PCI_CAP_ID_EXP 0x10 /**< PCI Express */
99#define PCI_CAP_ID_MSIX 0x11 /**< MSI-X */
100#define PCI_CAP_ID_EA 0x14 /**< Enhanced Allocation */
101
102/** Next capability */
103#define PCI_CAP_NEXT 0x01
104
105/** Power management control and status */
106#define PCI_PM_CTRL 0x04
107#define PCI_PM_CTRL_STATE_MASK 0x0003 /**< Current power state */
108#define PCI_PM_CTRL_PME_ENABLE 0x0100 /**< PME pin enable */
109#define PCI_PM_CTRL_PME_STATUS 0x8000 /**< PME pin status */
110
111/** PCI Express */
112#define PCI_EXP_DEVCTL 0x08
113#define PCI_EXP_DEVCTL_FLR 0x8000 /**< Function level reset */
114
115/** MSI-X interrupts */
116#define PCI_MSIX_CTRL 0x02
117#define PCI_MSIX_CTRL_ENABLE 0x8000 /**< Enable MSI-X */
118#define PCI_MSIX_CTRL_MASK 0x4000 /**< Mask all interrupts */
119#define PCI_MSIX_CTRL_SIZE(x) ( (x) & 0x07ff ) /**< Table size */
120#define PCI_MSIX_DESC_TABLE 0x04
121#define PCI_MSIX_DESC_PBA 0x08
122#define PCI_MSIX_DESC_BIR(x) ( (x) & 0x00000007 ) /**< BAR index */
123#define PCI_MSIX_DESC_OFFSET(x) ( (x) & 0xfffffff8 ) /**< BAR offset */
124
125/** Uncorrectable error status */
126#define PCI_ERR_UNCOR_STATUS 0x04
127
128/** Network controller */
129#define PCI_CLASS_NETWORK 0x02
130
131/** Bridge device */
132#define PCI_CLASS_BRIDGE 0x06
133#define PCI_CLASS_BRIDGE_PCI 0x04 /**< PCI-to-PCI bridge */
134
135/** Serial bus controller */
136#define PCI_CLASS_SERIAL 0x0c
137#define PCI_CLASS_SERIAL_USB 0x03 /**< USB controller */
138#define PCI_CLASS_SERIAL_USB_UHCI 0x00 /**< UHCI USB controller */
139#define PCI_CLASS_SERIAL_USB_OHCI 0x10 /**< OHCI USB controller */
140#define PCI_CLASS_SERIAL_USB_EHCI 0x20 /**< ECHI USB controller */
141#define PCI_CLASS_SERIAL_USB_XHCI 0x30 /**< xHCI USB controller */
142
143/** Primary bus number */
144#define PCI_PRIMARY 0x18
145
146/** Secondary bus number */
147#define PCI_SECONDARY 0x19
148
149/** Subordinate bus number */
150#define PCI_SUBORDINATE 0x1a
151
152/** Memory base and limit */
153#define PCI_MEM_BASE 0x20
154#define PCI_MEM_LIMIT 0x22
155#define PCI_MEM_MASK 0x000fUL
156#define PCI_PREFMEM_BASE 0x24
157#define PCI_PREFMEM_LIMIT 0x26
158#define PCI_PREFMEM_BASE_HI 0x28
159#define PCI_PREFMEM_LIMIT_HI 0x2c
160
161/** Construct PCI class
162 *
163 * @v base Base class (or PCI_ANY_ID)
164 * @v sub Subclass (or PCI_ANY_ID)
165 * @v progif Programming interface (or PCI_ANY_ID)
166 */
167#define PCI_CLASS( base, sub, progif ) \
168 ( ( ( (base) & 0xff ) << 16 ) | ( ( (sub) & 0xff ) << 8 ) | \
169 ( ( (progif) & 0xff) << 0 ) )
170
171/** PCI Express function level reset delay (in ms) */
172#define PCI_EXP_FLR_DELAY_MS 100
173
174/** A PCI device ID list entry */
176 /** Name */
177 const char *name;
178 /** PCI vendor ID */
180 /** PCI device ID */
182 /** Arbitrary driver data */
183 unsigned long driver_data;
184};
185
186/** Match-anything ID */
187#define PCI_ANY_ID 0xffff
188
189/** A PCI class ID */
191 /** Class */
192 uint32_t class;
193 /** Class mask */
195};
196
197/** Construct PCI class ID
198 *
199 * @v base Base class (or PCI_ANY_ID)
200 * @v sub Subclass (or PCI_ANY_ID)
201 * @v progif Programming interface (or PCI_ANY_ID)
202 */
203#define PCI_CLASS_ID( base, sub, progif ) { \
204 .class = PCI_CLASS ( base, sub, progif ), \
205 .mask = ( ( ( ( (base) == PCI_ANY_ID ) ? 0x00 : 0xff ) << 16 ) | \
206 ( ( ( (sub) == PCI_ANY_ID ) ? 0x00 : 0xff ) << 8 ) | \
207 ( ( ( (progif) == PCI_ANY_ID ) ? 0x00 : 0xff ) << 0 ) ), \
208 }
209
210/** A PCI device */
212 /** Generic device */
213 struct device dev;
214 /** DMA device */
216 /** Memory base
217 *
218 * This is the physical address of the first valid memory BAR.
219 */
220 unsigned long membase;
221 /**
222 * I/O address
223 *
224 * This is the physical address of the first valid I/O BAR.
225 */
226 unsigned long ioaddr;
227 /** Vendor ID */
229 /** Device ID */
231 /** Device class */
232 uint32_t class;
233 /** Interrupt number */
235 /** Header type */
237 /** Segment, bus, device, and function (bus:dev.fn) number */
239 /** Driver for this device */
241 /** Driver-private data
242 *
243 * Use pci_set_drvdata() and pci_get_drvdata() to access this
244 * field.
245 */
246 void *priv;
247 /** Driver device ID */
249};
250
251/** A PCI driver */
253 /** PCI ID table */
255 /** Number of entries in PCI ID table */
256 unsigned int id_count;
257 /** PCI class ID */
259 /**
260 * Probe device
261 *
262 * @v pci PCI device
263 * @ret rc Return status code
264 */
265 int ( * probe ) ( struct pci_device *pci );
266 /**
267 * Remove device
268 *
269 * @v pci PCI device
270 */
271 void ( * remove ) ( struct pci_device *pci );
272};
273
274/** PCI driver table */
275#define PCI_DRIVERS __table ( struct pci_driver, "pci_drivers" )
276
277/** Declare a PCI driver */
278#define __pci_driver __table_entry ( PCI_DRIVERS, 01 )
279
280/** Declare a fallback PCI driver */
281#define __pci_driver_fallback __table_entry ( PCI_DRIVERS, 02 )
282
283#define PCI_SEG( busdevfn ) ( ( (busdevfn) >> 16 ) & 0xffff )
284#define PCI_BUS( busdevfn ) ( ( (busdevfn) >> 8 ) & 0xff )
285#define PCI_SLOT( busdevfn ) ( ( (busdevfn) >> 3 ) & 0x1f )
286#define PCI_FUNC( busdevfn ) ( ( (busdevfn) >> 0 ) & 0x07 )
287#define PCI_FIRST_FUNC( busdevfn ) ( (busdevfn) & ~0x07 )
288#define PCI_LAST_FUNC( busdevfn ) ( (busdevfn) | 0x07 )
289
290#define PCI_BASE_CLASS( class ) ( (class) >> 16 )
291#define PCI_SUB_CLASS( class ) ( ( (class) >> 8 ) & 0xff )
292#define PCI_PROG_INTF( class ) ( (class) & 0xff )
293
294/*
295 * PCI_ROM is used to build up entries in a struct pci_id array. It
296 * is also parsed by parserom.pl to generate Makefile rules and files
297 * for rom-o-matic.
298 *
299 * PCI_ID can be used to generate entries without creating a
300 * corresponding ROM in the build process.
301 */
302#define PCI_ID( _vendor, _device, _name, _description, _data ) { \
303 .vendor = _vendor, \
304 .device = _device, \
305 .name = _name, \
306 .driver_data = _data \
307}
308#define PCI_ROM( _vendor, _device, _name, _description, _data ) \
309 PCI_ID( _vendor, _device, _name, _description, _data )
310
311/** PCI device debug message format */
312#define PCI_FMT "%04x:%02x:%02x.%x"
313
314/** PCI device debug message arguments */
315#define PCI_ARGS( pci ) \
316 PCI_SEG ( (pci)->busdevfn ), PCI_BUS ( (pci)->busdevfn ), \
317 PCI_SLOT ( (pci)->busdevfn ), PCI_FUNC ( (pci)->busdevfn )
318
319extern void adjust_pci_device ( struct pci_device *pci );
320extern unsigned long pci_bar_start ( struct pci_device *pci,
321 unsigned int reg );
322extern void pci_bar_set ( struct pci_device *pci, unsigned int reg,
323 unsigned long start );
324extern unsigned long pci_bar_size ( struct pci_device *pci, unsigned int reg );
325extern int pci_read_config ( struct pci_device *pci );
326extern int pci_find_next ( struct pci_device *pci, uint32_t *busdevfn );
327extern int pci_find_driver ( struct pci_device *pci );
328extern int pci_probe ( struct pci_device *pci );
329extern void pci_remove ( struct pci_device *pci );
330extern int pci_find_capability ( struct pci_device *pci, int capability );
331extern int pci_find_next_capability ( struct pci_device *pci,
332 int pos, int capability );
333extern void pci_reset ( struct pci_device *pci, unsigned int exp );
334
335/**
336 * Initialise PCI device
337 *
338 * @v pci PCI device
339 * @v busdevfn PCI bus:dev.fn address
340 */
341static inline void pci_init ( struct pci_device *pci, unsigned int busdevfn ) {
342 pci->busdevfn = busdevfn;
343}
344
345/**
346 * Set PCI driver
347 *
348 * @v pci PCI device
349 * @v driver PCI driver
350 * @v id PCI device ID
351 */
352static inline void pci_set_driver ( struct pci_device *pci,
353 struct pci_driver *driver,
354 struct pci_device_id *id ) {
355 pci->driver = driver;
356 pci->id = id;
357 pci->dev.driver_name = id->name;
358}
359
360/**
361 * Set PCI driver-private data
362 *
363 * @v pci PCI device
364 * @v priv Private data
365 */
366static inline void pci_set_drvdata ( struct pci_device *pci, void *priv ) {
367 pci->priv = priv;
368}
369
370/**
371 * Get PCI driver-private data
372 *
373 * @v pci PCI device
374 * @ret priv Private data
375 */
376static inline void * pci_get_drvdata ( struct pci_device *pci ) {
377 return pci->priv;
378}
379
380#endif /* _IPXE_PCI_H */
unsigned short uint16_t
Definition stdint.h:11
unsigned int uint32_t
Definition stdint.h:12
unsigned char uint8_t
Definition stdint.h:10
Device model.
uint8_t id
Request identifier.
Definition ena.h:1
uint16_t busdevfn
PCI bus:dev.fn address.
Definition ena.h:17
uint32_t start
Starting offset.
Definition netvsc.h:1
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
u16 capability
Capability flags.
Definition ieee80211.h:7
PCI I/O API.
DMA mappings.
static unsigned int unsigned int reg
Definition myson.h:162
void pci_reset(struct pci_device *pci, unsigned int exp)
Perform PCI Express function-level reset (FLR)
Definition pciextra.c:89
unsigned long pci_bar_size(struct pci_device *pci, unsigned int reg)
Get the size of a PCI BAR.
Definition pci.c:164
int pci_find_driver(struct pci_device *pci)
Find driver for PCI device.
Definition pci.c:386
int pci_find_next(struct pci_device *pci, uint32_t *busdevfn)
Find next device on PCI bus.
Definition pci.c:323
int pci_probe(struct pci_device *pci)
Probe a PCI device.
Definition pci.c:418
void pci_bar_set(struct pci_device *pci, unsigned int reg, unsigned long start)
Set the start of a PCI BAR.
Definition pci.c:115
static void pci_init(struct pci_device *pci, unsigned int busdevfn)
Initialise PCI device.
Definition pci.h:341
int pci_find_next_capability(struct pci_device *pci, int pos, int capability)
Look for another PCI capability.
Definition pciextra.c:76
int pci_read_config(struct pci_device *pci)
Read PCI device configuration.
Definition pci.c:269
void pci_remove(struct pci_device *pci)
Remove a PCI device.
Definition pci.c:440
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition pci.h:366
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition pci.c:241
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition pci.h:376
unsigned long pci_bar_start(struct pci_device *pci, unsigned int reg)
Find the start of a PCI BAR.
Definition pci.c:97
static void pci_set_driver(struct pci_device *pci, struct pci_driver *driver, struct pci_device_id *id)
Set PCI driver.
Definition pci.h:352
int pci_find_capability(struct pci_device *pci, int capability)
Look for a PCI capability.
Definition pciextra.c:39
const char * driver_name
Driver name.
Definition device.h:81
A DMA-capable device.
Definition dma.h:48
A PCI class ID.
Definition pci.h:190
uint32_t mask
Class mask.
Definition pci.h:194
A PCI device ID list entry.
Definition pci.h:175
unsigned long driver_data
Arbitrary driver data.
Definition pci.h:183
uint16_t vendor
PCI vendor ID.
Definition pci.h:179
const char * name
Name.
Definition pci.h:177
uint16_t device
PCI device ID.
Definition pci.h:181
A PCI device.
Definition pci.h:211
unsigned long ioaddr
I/O address.
Definition pci.h:226
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition pci.h:238
unsigned long membase
Memory base.
Definition pci.h:220
uint8_t hdrtype
Header type.
Definition pci.h:236
uint8_t irq
Interrupt number.
Definition pci.h:234
struct pci_driver * driver
Driver for this device.
Definition pci.h:240
struct device dev
Generic device.
Definition pci.h:213
struct pci_device_id * id
Driver device ID.
Definition pci.h:248
void * priv
Driver-private data.
Definition pci.h:246
uint16_t vendor
Vendor ID.
Definition pci.h:228
uint16_t device
Device ID.
Definition pci.h:230
struct dma_device dma
DMA device.
Definition pci.h:215
A PCI driver.
Definition pci.h:252
void(* remove)(struct pci_device *pci)
Remove device.
Definition pci.h:271
struct pci_class_id class
PCI class ID.
Definition pci.h:258
struct pci_device_id * ids
PCI ID table.
Definition pci.h:254
int(* probe)(struct pci_device *pci)
Probe device.
Definition pci.h:265
unsigned int id_count
Number of entries in PCI ID table.
Definition pci.h:256
Linker tables.
static struct tlan_private * priv
Definition tlan.c:225