iPXE
ecam_io.h
Go to the documentation of this file.
1#ifndef _IPXE_ECAM_IO_H
2#define _IPXE_ECAM_IO_H
3
4/** @file
5 *
6 * PCI I/O API for Enhanced Configuration Access Mechanism (ECAM)
7 *
8 */
9
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11FILE_SECBOOT ( PERMITTED );
12
13#include <stdint.h>
14
15#ifdef PCIAPI_ECAM
16#define PCIAPI_PREFIX_ecam
17#else
18#define PCIAPI_PREFIX_ecam __ecam_
19#endif
20
21struct pci_device;
22
23/** Construct ECAM location */
24#define ECAM_LOC( where, len ) ( ( (len) << 16 ) | where )
25
26/** Extract offset from ECAM location */
27#define ECAM_WHERE( location ) ( (location) & 0xffff )
28
29/** Extract length from ECAM location */
30#define ECAM_LEN( location ) ( (location) >> 16 )
31
32extern int ecam_read ( struct pci_device *pci, unsigned int location,
33 void *value );
34extern int ecam_write ( struct pci_device *pci, unsigned int location,
35 unsigned long value );
36
37/**
38 * Read byte from PCI configuration space via ECAM
39 *
40 * @v pci PCI device
41 * @v where Location within PCI configuration space
42 * @v value Value read
43 * @ret rc Return status code
44 */
45static inline __always_inline int
47 unsigned int where,
49 return ecam_read ( pci, ECAM_LOC ( where, sizeof ( *value ) ), value );
50}
51
52/**
53 * Read word from PCI configuration space via ECAM
54 *
55 * @v pci PCI device
56 * @v where Location within PCI configuration space
57 * @v value Value read
58 * @ret rc Return status code
59 */
60static inline __always_inline int
62 unsigned int where,
63 uint16_t *value ) {
64 return ecam_read ( pci, ECAM_LOC ( where, sizeof ( *value ) ), value );
65}
66
67/**
68 * Read dword from PCI configuration space via ECAM
69 *
70 * @v pci PCI device
71 * @v where Location within PCI configuration space
72 * @v value Value read
73 * @ret rc Return status code
74 */
75static inline __always_inline int
77 unsigned int where,
78 uint32_t *value ) {
79 return ecam_read ( pci, ECAM_LOC ( where, sizeof ( *value ) ), value );
80}
81
82/**
83 * Write byte to PCI configuration space via ECAM
84 *
85 * @v pci PCI device
86 * @v where Location within PCI configuration space
87 * @v value Value to be written
88 * @ret rc Return status code
89 */
90static inline __always_inline int
92 unsigned int where,
93 uint8_t value ) {
94 return ecam_write ( pci, ECAM_LOC ( where, sizeof ( value ) ), value );
95}
96
97/**
98 * Write word to PCI configuration space via ECAM
99 *
100 * @v pci PCI device
101 * @v where Location within PCI configuration space
102 * @v value Value to be written
103 * @ret rc Return status code
104 */
105static inline __always_inline int
107 unsigned int where,
108 uint16_t value ) {
109 return ecam_write ( pci, ECAM_LOC ( where, sizeof ( value ) ), value );
110}
111
112/**
113 * Write dword to PCI configuration space via ECAM
114 *
115 * @v pci PCI device
116 * @v where Location within PCI configuration space
117 * @v value Value to be written
118 * @ret rc Return status code
119 */
120static inline __always_inline int
122 unsigned int where,
123 uint32_t value ) {
124 return ecam_write ( pci, ECAM_LOC ( where, sizeof ( value ) ), value );
125}
126
127/**
128 * Map PCI bus address as an I/O address
129 *
130 * @v bus_addr PCI bus address
131 * @v len Length of region
132 * @ret io_addr I/O address, or NULL on error
133 */
134static inline __always_inline void *
136 unsigned long bus_addr, size_t len ) {
137 return ioremap ( bus_addr, len );
138}
139
140/**
141 * Check if PCI bus probing is allowed
142 *
143 * @v pci PCI device
144 * @ret ok Bus probing is allowed
145 */
146static inline __always_inline int
148 return 1;
149}
150
151#endif /* _IPXE_ECAM_IO_H */
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
ring len
Length.
Definition dwmac.h:226
static struct ecam_mapping ecam
Cached mapped ECAM allocation.
Definition ecam.c:37
#define ECAM_LOC(where, len)
Construct ECAM location.
Definition ecam_io.h:24
int ecam_write(struct pci_device *pci, unsigned int location, unsigned long value)
Write to PCI configuration space.
Definition ecam.c:232
int ecam_read(struct pci_device *pci, unsigned int location, void *value)
Read from PCI configuration space.
Definition ecam.c:190
#define __always_inline
Declare a function to be always inline.
Definition compiler.h:611
#define __unused
Declare a variable or data structure as unused.
Definition compiler.h:573
#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
void * ioremap(unsigned long bus_addr, size_t len)
Map bus address as an I/O address.
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.
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.
#define PCIAPI_INLINE(_subsys, _api_func)
Calculate static inline PCI I/O API function name.
Definition pci_io.h:41
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 void unsigned long bus_addr
Definition pcibios.h:156
static __always_inline int unsigned int where
Definition pcibios.h:57
A PCI device.
Definition pci.h:211