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
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11FILE_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
19struct pci_device;
20struct pci_api;
21
22/** A PCI bus:dev.fn address range */
23struct 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>
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 */
79int 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 */
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 */
97int 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 */
108int 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 */
119int 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 */
130int 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 */
141int 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 */
152int 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 */
162void * pci_ioremap ( struct pci_device *pci, unsigned long bus_addr,
163 size_t len );
164
165/** A runtime selectable PCI I/O API */
166struct 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 */
typeof(acpi_finder=acpi_find)
ACPI table finder.
Definition acpi.c:48
iPXE internal APIs
pseudo_bit_t value[0x00020]
Definition arbel.h:2
unsigned short uint16_t
Definition stdint.h:11
unsigned int uint32_t
Definition stdint.h:12
unsigned char uint8_t
Definition stdint.h:10
i386-specific PCI I/O API implementations
ring len
Length.
Definition dwmac.h:226
PCI I/O API for Enhanced Configuration Access Mechanism (ECAM)
iPXE PCI I/O API for EFI
uint16_t busdevfn
PCI bus:dev.fn address.
Definition ena.h:17
#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
iPXE I/O mapping API
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
int pci_can_probe(struct pci_device *pci)
Check if PCI bus probing is allowed.
void pci_discover(uint32_t busdevfn, struct pci_range *range)
Find next PCI bus:dev.fn address range in system.
int pci_read_config_word(struct pci_device *pci, unsigned int where, uint16_t *value)
Read 16-bit word from PCI configuration space.
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
int pci_write_config_byte(struct pci_device *pci, unsigned int where, uint8_t value)
Write byte to PCI configuration space.
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_byte(struct pci_device *pci, unsigned int where, uint8_t *value)
Read byte from PCI configuration space.
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword to PCI configuration space.
I/O API configuration.
iPXE PCI API for Linux
Null PCI API.
static __always_inline void unsigned long bus_addr
Definition pcibios.h:156
static __always_inline int unsigned int where
Definition pcibios.h:57
struct pci_range range
PCI bus:dev.fn address range.
Definition pcicloud.c:40
Cloud VM PCI configuration space access.
A runtime selectable PCI I/O API.
Definition pci_io.h:166
typeof pci_write_config_byte * pci_write_config_byte
Definition pci_io.h:173
typeof pci_read_config_word * pci_read_config_word
Definition pci_io.h:171
typeof pci_discover * pci_discover
Definition pci_io.h:169
typeof pci_read_config_byte * pci_read_config_byte
Definition pci_io.h:170
typeof pci_write_config_word * pci_write_config_word
Definition pci_io.h:174
typeof pci_read_config_dword * pci_read_config_dword
Definition pci_io.h:172
typeof pci_write_config_dword * pci_write_config_dword
Definition pci_io.h:175
typeof pci_ioremap * pci_ioremap
Definition pci_io.h:176
const char * name
Definition pci_io.h:167
typeof pci_can_probe * pci_can_probe
Definition pci_io.h:168
A PCI device.
Definition pci.h:211
A PCI bus:dev.fn address range.
Definition pci_io.h:23
unsigned int count
Number of bus:dev.fn addresses within this range.
Definition pci_io.h:27
uint32_t start
Starting bus:dev.fn address.
Definition pci_io.h:25
Linker tables.