iPXE
linux_pci.h
Go to the documentation of this file.
1 #ifndef _IPXE_LINUX_PCI_H
2 #define _IPXE_LINUX_PCI_H
3 
4 /** @file
5  *
6  * iPXE PCI API for Linux
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 
12 #ifdef PCIAPI_LINUX
13 #define PCIAPI_PREFIX_linux
14 #else
15 #define PCIAPI_PREFIX_linux __linux_
16 #endif
17 
18 struct pci_device;
19 
20 extern int linux_pci_read ( struct pci_device *pci, unsigned long where,
21  unsigned long *value, size_t len );
22 extern int linux_pci_write ( struct pci_device *pci, unsigned long where,
23  unsigned long value, size_t len );
24 
25 /**
26  * Check if PCI bus probing is allowed
27  *
28  * @ret ok Bus probing is allowed
29  */
30 static inline __always_inline int
31 PCIAPI_INLINE ( linux, pci_can_probe ) ( void ) {
32  return 1;
33 }
34 
35 /**
36  * Find next PCI bus:dev.fn address range in system
37  *
38  * @v busdevfn Starting PCI bus:dev.fn address
39  * @v range PCI bus:dev.fn address range to fill in
40  */
41 static inline __always_inline void
43  struct pci_range *range ) {
44 
45  /* Assume all buses in segment 0 may exist */
46  range->start = PCI_BUSDEVFN ( 0, 0, 0, 0 );
47  range->count = PCI_BUSDEVFN ( 1, 0, 0, 0 );
48 }
49 
50 /**
51  * Read byte from PCI configuration space
52  *
53  * @v pci PCI device
54  * @v where Location within PCI configuration space
55  * @v value Value read
56  * @ret rc Return status code
57  */
58 static inline __always_inline int
59 PCIAPI_INLINE ( linux, pci_read_config_byte ) ( struct pci_device *pci,
60  unsigned int where,
62  int rc;
63  unsigned long tmp;
64 
65  rc = linux_pci_read ( pci, where, &tmp, sizeof ( *value ) );
66  *value = tmp;
67  return rc;
68 }
69 
70 /**
71  * Read word from PCI configuration space
72  *
73  * @v pci PCI device
74  * @v where Location within PCI configuration space
75  * @v value Value read
76  * @ret rc Return status code
77  */
78 static inline __always_inline int
79 PCIAPI_INLINE ( linux, pci_read_config_word ) ( struct pci_device *pci,
80  unsigned int where,
81  uint16_t *value ) {
82  int rc;
83  unsigned long tmp;
84 
85  rc = linux_pci_read ( pci, where, &tmp, sizeof ( *value ) );
86  *value = tmp;
87  return rc;
88 }
89 
90 /**
91  * Read dword from PCI configuration space
92  *
93  * @v pci PCI device
94  * @v where Location within PCI configuration space
95  * @v value Value read
96  * @ret rc Return status code
97  */
98 static inline __always_inline int
99 PCIAPI_INLINE ( linux, pci_read_config_dword ) ( struct pci_device *pci,
100  unsigned int where,
101  uint32_t *value ) {
102  int rc;
103  unsigned long tmp;
104 
105  rc = linux_pci_read ( pci, where, &tmp, sizeof ( *value ) );
106  *value = tmp;
107  return rc;
108 }
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 static inline __always_inline int
119 PCIAPI_INLINE ( linux, pci_write_config_byte ) ( struct pci_device *pci,
120  unsigned int where,
121  uint8_t value ) {
122  return linux_pci_write ( pci, where, value, sizeof ( value ) );
123 }
124 
125 /**
126  * Write word to PCI configuration space
127  *
128  * @v pci PCI device
129  * @v where Location within PCI configuration space
130  * @v value Value to be written
131  * @ret rc Return status code
132  */
133 static inline __always_inline int
134 PCIAPI_INLINE ( linux, pci_write_config_word ) ( struct pci_device *pci,
135  unsigned int where,
136  uint16_t value ) {
137  return linux_pci_write ( pci, where, value, sizeof ( value ) );
138 }
139 
140 /**
141  * Write 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 static inline __always_inline int
149 PCIAPI_INLINE ( linux, pci_write_config_dword ) ( struct pci_device *pci,
150  unsigned int where,
151  uint32_t value ) {
152  return linux_pci_write ( pci, where, value, sizeof ( value ) );
153 }
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  */
162 static inline __always_inline void *
163 PCIAPI_INLINE ( linux, pci_ioremap ) ( struct pci_device *pci __unused,
164  unsigned long bus_addr, size_t len ) {
165  return ioremap ( bus_addr, len );
166 }
167 
168 #endif /* _IPXE_LINUX_PCI_H */
uint32_t start
Starting bus:dev.fn address.
Definition: pci_io.h:23
unsigned short uint16_t
Definition: stdint.h:11
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
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 size_t len
Definition: linux_pci.h:164
static __always_inline int unsigned int where
Definition: linux_pci.h:60
rc
Definition: linux_pci.h:65
static __always_inline void struct pci_range * range
Definition: linux_pci.h:43
static __always_inline int unsigned int uint8_t * value
Definition: linux_pci.h:61
unsigned long tmp
Definition: linux_pci.h:63
uint16_t busdevfn
PCI bus:dev.fn address.
Definition: ena.h:28
static __always_inline void unsigned long bus_addr
Definition: linux_pci.h:164
int linux_pci_write(struct pci_device *pci, unsigned long where, unsigned long value, size_t len)
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
A PCI bus:dev.fn address range.
Definition: pci_io.h:21
#define PCI_BUSDEVFN(segment, bus, slot, func)
Definition: pci_io.h:28
int pci_write_config_byte(struct pci_device *pci, unsigned int where, uint8_t value)
Write byte to PCI configuration space.
int linux_pci_read(struct pci_device *pci, unsigned long where, unsigned long *value, size_t len)
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
unsigned int count
Number of bus:dev.fn addresses within this range.
Definition: pci_io.h:25
static __always_inline int PCIAPI_INLINE(linux, pci_can_probe)(void)
Check if PCI bus probing is allowed.
Definition: linux_pci.h:31
void pci_discover(uint32_t busdevfn, struct pci_range *range)
Find next PCI bus:dev.fn address range in system.
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.
int pci_read_config_byte(struct pci_device *pci, unsigned int where, uint8_t *value)
Read byte from PCI configuration space.