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