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 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 
12 #include <stdint.h>
13 
14 #ifdef PCIAPI_ECAM
15 #define PCIAPI_PREFIX_ecam
16 #else
17 #define PCIAPI_PREFIX_ecam __ecam_
18 #endif
19 
20 struct pci_device;
21 
22 /** Construct ECAM location */
23 #define ECAM_LOC( where, len ) ( ( (len) << 16 ) | where )
24 
25 /** Extract offset from ECAM location */
26 #define ECAM_WHERE( location ) ( (location) & 0xffff )
27 
28 /** Extract length from ECAM location */
29 #define ECAM_LEN( location ) ( (location) >> 16 )
30 
31 extern int ecam_read ( struct pci_device *pci, unsigned int location,
32  void *value );
33 extern int ecam_write ( struct pci_device *pci, unsigned int location,
34  unsigned long value );
35 
36 /**
37  * Read byte from PCI configuration space via ECAM
38  *
39  * @v pci PCI device
40  * @v where Location within PCI configuration space
41  * @v value Value read
42  * @ret rc Return status code
43  */
44 static inline __always_inline int
46  unsigned int where,
48  return ecam_read ( pci, ECAM_LOC ( where, sizeof ( *value ) ), value );
49 }
50 
51 /**
52  * Read word from PCI configuration space via ECAM
53  *
54  * @v pci PCI device
55  * @v where Location within PCI configuration space
56  * @v value Value read
57  * @ret rc Return status code
58  */
59 static inline __always_inline int
61  unsigned int where,
62  uint16_t *value ) {
63  return ecam_read ( pci, ECAM_LOC ( where, sizeof ( *value ) ), value );
64 }
65 
66 /**
67  * Read dword from PCI configuration space via ECAM
68  *
69  * @v pci PCI device
70  * @v where Location within PCI configuration space
71  * @v value Value read
72  * @ret rc Return status code
73  */
74 static inline __always_inline int
76  unsigned int where,
77  uint32_t *value ) {
78  return ecam_read ( pci, ECAM_LOC ( where, sizeof ( *value ) ), value );
79 }
80 
81 /**
82  * Write byte to PCI configuration space via ECAM
83  *
84  * @v pci PCI device
85  * @v where Location within PCI configuration space
86  * @v value Value to be written
87  * @ret rc Return status code
88  */
89 static inline __always_inline int
91  unsigned int where,
92  uint8_t value ) {
93  return ecam_write ( pci, ECAM_LOC ( where, sizeof ( value ) ), value );
94 }
95 
96 /**
97  * Write word to PCI configuration space via ECAM
98  *
99  * @v pci PCI device
100  * @v where Location within PCI configuration space
101  * @v value Value to be written
102  * @ret rc Return status code
103  */
104 static inline __always_inline int
106  unsigned int where,
107  uint16_t value ) {
108  return ecam_write ( pci, ECAM_LOC ( where, sizeof ( value ) ), value );
109 }
110 
111 /**
112  * Write dword to PCI configuration space via ECAM
113  *
114  * @v pci PCI device
115  * @v where Location within PCI configuration space
116  * @v value Value to be written
117  * @ret rc Return status code
118  */
119 static inline __always_inline int
121  unsigned int where,
122  uint32_t value ) {
123  return ecam_write ( pci, ECAM_LOC ( where, sizeof ( value ) ), value );
124 }
125 
126 /**
127  * Map PCI bus address as an I/O address
128  *
129  * @v bus_addr PCI bus address
130  * @v len Length of region
131  * @ret io_addr I/O address, or NULL on error
132  */
133 static inline __always_inline void *
135  unsigned long bus_addr, size_t len ) {
136  return ioremap ( bus_addr, len );
137 }
138 
139 #endif /* _IPXE_ECAM_IO_H */
unsigned short uint16_t
Definition: stdint.h:11
int pci_write_config_word(struct pci_device *pci, unsigned int where, uint16_t value)
Write 16-bit word to PCI configuration space.
static struct ecam_mapping ecam
Cached mapped ECAM allocation.
Definition: ecam.c:37
int pci_read_config_word(struct pci_device *pci, unsigned int where, uint16_t *value)
Read 16-bit word from PCI configuration space.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
int ecam_write(struct pci_device *pci, unsigned int location, unsigned long value)
Write to PCI configuration space.
Definition: ecam.c:238
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
#define __always_inline
Declare a function to be always inline.
Definition: compiler.h:611
unsigned char uint8_t
Definition: stdint.h:10
unsigned int uint32_t
Definition: stdint.h:12
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
static __always_inline int PCIAPI_INLINE(ecam, pci_read_config_byte)(struct pci_device *pci
Read byte from PCI configuration space via ECAM.
static __always_inline void unsigned long size_t len
Definition: ecam_io.h:135
static __always_inline int unsigned int uint8_t * value
Definition: ecam_io.h:47
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword to PCI configuration space.
void * ioremap(unsigned long bus_addr, size_t len)
Map bus address as an I/O address.
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
#define ECAM_LOC(where, len)
Construct ECAM location.
Definition: ecam_io.h:23
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
int ecam_read(struct pci_device *pci, unsigned int location, void *value)
Read from PCI configuration space.
Definition: ecam.c:196
int pci_read_config_byte(struct pci_device *pci, unsigned int where, uint8_t *value)
Read byte from PCI configuration space.