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