iPXE
pci_io.h
Go to the documentation of this file.
1 #ifndef _IPXE_PCI_IO_H
2 #define _IPXE_PCI_IO_H
3 
4 /** @file
5  *
6  * PCI I/O API
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 FILE_SECBOOT ( PERMITTED );
12 
13 #include <stdint.h>
14 #include <ipxe/api.h>
15 #include <ipxe/tables.h>
16 #include <ipxe/iomap.h>
17 #include <config/ioapi.h>
18 
19 struct pci_device;
20 struct pci_api;
21 
22 /** A PCI bus:dev.fn address range */
23 struct pci_range {
24  /** Starting bus:dev.fn address */
26  /** Number of bus:dev.fn addresses within this range */
27  unsigned int count;
28 };
29 
30 #define PCI_BUSDEVFN( segment, bus, slot, func ) \
31  ( ( (segment) << 16 ) | ( (bus) << 8 ) | \
32  ( (slot) << 3 ) | ( (func) << 0 ) )
33 
34 /**
35  * Calculate static inline PCI I/O API function name
36  *
37  * @v _prefix Subsystem prefix
38  * @v _api_func API function
39  * @ret _subsys_func Subsystem API function
40  */
41 #define PCIAPI_INLINE( _subsys, _api_func ) \
42  SINGLE_API_INLINE ( PCIAPI_PREFIX_ ## _subsys, _api_func )
43 
44 /**
45  * Provide a PCI I/O API implementation
46  *
47  * @v _prefix Subsystem prefix
48  * @v _api_func API function
49  * @v _func Implementing function
50  */
51 #define PROVIDE_PCIAPI( _subsys, _api_func, _func ) \
52  PROVIDE_SINGLE_API ( PCIAPI_PREFIX_ ## _subsys, _api_func, _func )
53 
54 /**
55  * Provide a static inline PCI I/O API implementation
56  *
57  * @v _prefix Subsystem prefix
58  * @v _api_func API function
59  */
60 #define PROVIDE_PCIAPI_INLINE( _subsys, _api_func ) \
61  PROVIDE_SINGLE_API_INLINE ( PCIAPI_PREFIX_ ## _subsys, _api_func )
62 
63 /* Include all architecture-independent I/O API headers */
64 #include <ipxe/null_pci.h>
65 #include <ipxe/ecam_io.h>
66 #include <ipxe/pcicloud.h>
67 #include <ipxe/efi/efi_pci_api.h>
68 #include <ipxe/linux/linux_pci.h>
69 
70 /* Include all architecture-dependent I/O API headers */
71 #include <bits/pci_io.h>
72 
73 /**
74  * Check if PCI bus probing is allowed
75  *
76  * @v pci PCI device
77  * @ret ok Bus probing is allowed
78  */
79 int pci_can_probe ( struct pci_device *pci );
80 
81 /**
82  * Find next PCI bus:dev.fn address range in system
83  *
84  * @v busdevfn Starting PCI bus:dev.fn address
85  * @v range PCI bus:dev.fn address range to fill in
86  */
87 void pci_discover ( uint32_t busdevfn, struct pci_range *range );
88 
89 /**
90  * Read byte from PCI configuration space
91  *
92  * @v pci PCI device
93  * @v where Location within PCI configuration space
94  * @v value Value read
95  * @ret rc Return status code
96  */
97 int pci_read_config_byte ( struct pci_device *pci, unsigned int where,
98  uint8_t *value );
99 
100 /**
101  * Read 16-bit word from PCI configuration space
102  *
103  * @v pci PCI device
104  * @v where Location within PCI configuration space
105  * @v value Value read
106  * @ret rc Return status code
107  */
108 int pci_read_config_word ( struct pci_device *pci, unsigned int where,
109  uint16_t *value );
110 
111 /**
112  * Read 32-bit dword from PCI configuration space
113  *
114  * @v pci PCI device
115  * @v where Location within PCI configuration space
116  * @v value Value read
117  * @ret rc Return status code
118  */
119 int pci_read_config_dword ( struct pci_device *pci, unsigned int where,
120  uint32_t *value );
121 
122 /**
123  * Write byte to PCI configuration space
124  *
125  * @v pci PCI device
126  * @v where Location within PCI configuration space
127  * @v value Value to be written
128  * @ret rc Return status code
129  */
130 int pci_write_config_byte ( struct pci_device *pci, unsigned int where,
131  uint8_t value );
132 
133 /**
134  * Write 16-bit word to PCI configuration space
135  *
136  * @v pci PCI device
137  * @v where Location within PCI configuration space
138  * @v value Value to be written
139  * @ret rc Return status code
140  */
141 int pci_write_config_word ( struct pci_device *pci, unsigned int where,
142  uint16_t value );
143 
144 /**
145  * Write 32-bit dword to PCI configuration space
146  *
147  * @v pci PCI device
148  * @v where Location within PCI configuration space
149  * @v value Value to be written
150  * @ret rc Return status code
151  */
152 int pci_write_config_dword ( struct pci_device *pci, unsigned int where,
153  uint32_t value );
154 
155 /**
156  * Map PCI bus address as an I/O address
157  *
158  * @v bus_addr PCI bus address
159  * @v len Length of region
160  * @ret io_addr I/O address, or NULL on error
161  */
162 void * pci_ioremap ( struct pci_device *pci, unsigned long bus_addr,
163  size_t len );
164 
165 /** A runtime selectable PCI I/O API */
166 struct pci_api {
167  const char *name;
168  typeof ( pci_can_probe ) ( * pci_can_probe );
169  typeof ( pci_discover ) ( * pci_discover );
170  typeof ( pci_read_config_byte ) ( * pci_read_config_byte );
171  typeof ( pci_read_config_word ) ( * pci_read_config_word );
172  typeof ( pci_read_config_dword ) ( * pci_read_config_dword );
173  typeof ( pci_write_config_byte ) ( * pci_write_config_byte );
174  typeof ( pci_write_config_word ) ( * pci_write_config_word );
175  typeof ( pci_write_config_dword ) ( * pci_write_config_dword );
176  typeof ( pci_ioremap ) ( * pci_ioremap );
177 };
178 
179 /** Runtime selectable PCI API table */
180 #define PCI_APIS __table ( struct pci_api, "pci_apis" )
181 
182 /**
183  * Declare a runtime selectable PCI API
184  *
185  * In the common case of a non-runtime-selectable PCI I/O API, allow
186  * the runtime API code to be garbage-collected at link time to save
187  * space.
188  */
189 #ifdef PCIAPI_CLOUD
190 #define __pci_api( priority ) __table_entry ( PCI_APIS, priority )
191 #else
192 #define __pci_api( priority )
193 #endif
194 
195 /* PCI runtime selectable API priorities */
196 #define PCIAPI_PRIORITY_EFI 01 /**< EFI PCI I/O protocols */
197 #define PCIAPI_PRIORITY_ECAM 02 /**< ACPI ECAM */
198 #define PCIAPI_PRIORITY_PCBIOS 03 /**< PCI BIOS calls */
199 #define PCIAPI_PRIORITY_DIRECT 04 /**< Direct Type 1 accesses */
200 
201 /** Provide a runtime selectable PCI I/O API */
202 #define PROVIDE_PCIAPI_RUNTIME( subsys, priority ) \
203  struct pci_api pciapi_ ## subsys __pci_api ( priority ) = { \
204  .name = #subsys, \
205  .pci_can_probe = PCIAPI_INLINE ( subsys, pci_can_probe ), \
206  .pci_discover = PCIAPI_INLINE ( subsys, pci_discover ), \
207  .pci_read_config_byte = \
208  PCIAPI_INLINE ( subsys, pci_read_config_byte ), \
209  .pci_read_config_word = \
210  PCIAPI_INLINE ( subsys, pci_read_config_word ), \
211  .pci_read_config_dword = \
212  PCIAPI_INLINE ( subsys, pci_read_config_dword ), \
213  .pci_write_config_byte = \
214  PCIAPI_INLINE ( subsys, pci_write_config_byte ), \
215  .pci_write_config_word = \
216  PCIAPI_INLINE ( subsys, pci_write_config_word ), \
217  .pci_write_config_dword = \
218  PCIAPI_INLINE ( subsys, pci_write_config_dword ), \
219  .pci_ioremap = PCIAPI_INLINE ( subsys, pci_ioremap ), \
220  }
221 
222 #endif /* _IPXE_PCI_IO_H */
iPXE PCI I/O API for EFI
uint32_t start
Starting bus:dev.fn address.
Definition: pci_io.h:25
unsigned short uint16_t
Definition: stdint.h:11
typeof() pci_discover * pci_discover
Definition: pci_io.h:169
struct pci_range range
PCI bus:dev.fn address range.
Definition: pcicloud.c:40
iPXE internal APIs
typeof() pci_read_config_word * pci_read_config_word
Definition: pci_io.h:171
int pci_can_probe(struct pci_device *pci)
Check if PCI bus probing is allowed.
typeof() pci_write_config_byte * pci_write_config_byte
Definition: pci_io.h:173
typeof() pci_read_config_dword * pci_read_config_dword
Definition: pci_io.h:172
int pci_write_config_word(struct pci_device *pci, unsigned int where, uint16_t value)
Write 16-bit word to PCI configuration space.
int pci_read_config_word(struct pci_device *pci, unsigned int where, uint16_t *value)
Read 16-bit word from PCI configuration space.
static __always_inline void unsigned long bus_addr
Definition: pcibios.h:156
Cloud VM PCI configuration space access.
uint16_t busdevfn
PCI bus:dev.fn address.
Definition: ena.h:28
typeof() pci_can_probe * pci_can_probe
Definition: pci_io.h:168
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
const char * name
Definition: pci_io.h:167
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
ring len
Length.
Definition: dwmac.h:231
typeof() pci_write_config_word * pci_write_config_word
Definition: pci_io.h:174
A PCI bus:dev.fn address range.
Definition: pci_io.h:23
int pci_write_config_byte(struct pci_device *pci, unsigned int where, uint8_t value)
Write byte to PCI configuration space.
A PCI device.
Definition: pci.h:211
A runtime selectable PCI I/O API.
Definition: pci_io.h:166
typeof() pci_read_config_byte * pci_read_config_byte
Definition: pci_io.h:170
typeof() pci_ioremap * pci_ioremap
Definition: pci_io.h:176
unsigned char uint8_t
Definition: stdint.h:10
FILE_SECBOOT(PERMITTED)
unsigned int uint32_t
Definition: stdint.h:12
unsigned int count
Number of bus:dev.fn addresses within this range.
Definition: pci_io.h:27
void pci_discover(uint32_t busdevfn, struct pci_range *range)
Find next PCI bus:dev.fn address range in system.
iPXE PCI API for Linux
PCI I/O API for Enhanced Configuration Access Mechanism (ECAM)
I/O API configuration.
Null PCI API.
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword to PCI configuration space.
Linker tables.
static __always_inline int unsigned int where
Definition: pcibios.h:57
typeof(acpi_finder=acpi_find)
ACPI table finder.
Definition: acpi.c:48
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
iPXE I/O mapping API
typeof() pci_write_config_dword * pci_write_config_dword
Definition: pci_io.h:175
int pci_read_config_byte(struct pci_device *pci, unsigned int where, uint8_t *value)
Read byte from PCI configuration space.