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/ecam_io.h>
63 #include <ipxe/efi/efi_pci_api.h>
64 #include <ipxe/linux/linux_pci.h>
65 
66 /* Include all architecture-dependent I/O API headers */
67 #include <bits/pci_io.h>
68 
69 /**
70  * Find next PCI bus:dev.fn address range in system
71  *
72  * @v busdevfn Starting PCI bus:dev.fn address
73  * @v range PCI bus:dev.fn address range to fill in
74  */
75 void pci_discover ( uint32_t busdevfn, struct pci_range *range );
76 
77 /**
78  * Read byte from PCI configuration space
79  *
80  * @v pci PCI device
81  * @v where Location within PCI configuration space
82  * @v value Value read
83  * @ret rc Return status code
84  */
85 int pci_read_config_byte ( struct pci_device *pci, unsigned int where,
86  uint8_t *value );
87 
88 /**
89  * Read 16-bit word 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_word ( struct pci_device *pci, unsigned int where,
97  uint16_t *value );
98 
99 /**
100  * Read 32-bit dword 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_dword ( struct pci_device *pci, unsigned int where,
108  uint32_t *value );
109 
110 /**
111  * Write byte to PCI configuration space
112  *
113  * @v pci PCI device
114  * @v where Location within PCI configuration space
115  * @v value Value to be written
116  * @ret rc Return status code
117  */
118 int pci_write_config_byte ( struct pci_device *pci, unsigned int where,
119  uint8_t value );
120 
121 /**
122  * Write 16-bit word 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_word ( struct pci_device *pci, unsigned int where,
130  uint16_t value );
131 
132 /**
133  * Write 32-bit dword 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_dword ( struct pci_device *pci, unsigned int where,
141  uint32_t value );
142 
143 /**
144  * Map PCI bus address as an I/O address
145  *
146  * @v bus_addr PCI bus address
147  * @v len Length of region
148  * @ret io_addr I/O address, or NULL on error
149  */
150 void * pci_ioremap ( struct pci_device *pci, unsigned long bus_addr,
151  size_t len );
152 
153 /** A runtime selectable PCI I/O API */
154 struct pci_api {
155  const char *name;
156  typeof ( pci_discover ) ( * pci_discover );
157  typeof ( pci_read_config_byte ) ( * pci_read_config_byte );
158  typeof ( pci_read_config_word ) ( * pci_read_config_word );
159  typeof ( pci_read_config_dword ) ( * pci_read_config_dword );
160  typeof ( pci_write_config_byte ) ( * pci_write_config_byte );
161  typeof ( pci_write_config_word ) ( * pci_write_config_word );
162  typeof ( pci_write_config_dword ) ( * pci_write_config_dword );
163  typeof ( pci_ioremap ) ( * pci_ioremap );
164 };
165 
166 /** Provide a runtime selectable PCI I/O API */
167 #define PCIAPI_RUNTIME( _subsys ) { \
168  .name = #_subsys, \
169  .pci_discover = PCIAPI_INLINE ( _subsys, pci_discover ), \
170  .pci_read_config_byte = \
171  PCIAPI_INLINE ( _subsys, pci_read_config_byte ), \
172  .pci_read_config_word = \
173  PCIAPI_INLINE ( _subsys, pci_read_config_word ), \
174  .pci_read_config_dword = \
175  PCIAPI_INLINE ( _subsys, pci_read_config_dword ), \
176  .pci_write_config_byte = \
177  PCIAPI_INLINE ( _subsys, pci_write_config_byte ), \
178  .pci_write_config_word = \
179  PCIAPI_INLINE ( _subsys, pci_write_config_word ), \
180  .pci_write_config_dword = \
181  PCIAPI_INLINE ( _subsys, pci_write_config_dword ), \
182  .pci_ioremap = PCIAPI_INLINE ( _subsys, pci_ioremap ), \
183  }
184 
185 #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
static __always_inline void struct pci_range * range
Definition: efi_pci_api.h:43
typeof() pci_discover * pci_discover
Definition: pci_io.h:156
iPXE internal APIs
typeof() pci_read_config_word * pci_read_config_word
Definition: pci_io.h:158
typeof() pci_write_config_byte * pci_write_config_byte
Definition: pci_io.h:160
typeof() pci_read_config_dword * pci_read_config_dword
Definition: pci_io.h:159
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.
uint16_t busdevfn
PCI bus:dev.fn address.
Definition: ena.h:28
const char * name
Definition: pci_io.h:155
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
typeof() pci_write_config_word * pci_write_config_word
Definition: pci_io.h:161
A PCI bus:dev.fn address range.
Definition: pci_io.h:21
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
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:154
typeof() pci_read_config_byte * pci_read_config_byte
Definition: pci_io.h:157
typeof() pci_ioremap * pci_ioremap
Definition: pci_io.h:163
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
i386-specific PCI I/O API implementations
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.
uint32_t len
Length.
Definition: ena.h:14
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword to PCI configuration space.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
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.
static __always_inline void unsigned long bus_addr
Definition: ecam_io.h:135
static __always_inline int unsigned int where
Definition: ecam_io.h:46
iPXE I/O mapping API
typeof() pci_write_config_dword * pci_write_config_dword
Definition: pci_io.h:162
int pci_read_config_byte(struct pci_device *pci, unsigned int where, uint8_t *value)
Read byte from PCI configuration space.