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 FILE_SECBOOT ( PERMITTED );
12 
13 #ifdef PCIAPI_LINUX
14 #define PCIAPI_PREFIX_linux
15 #else
16 #define PCIAPI_PREFIX_linux __linux_
17 #endif
18 
19 struct pci_device;
20 
21 extern int linux_pci_read ( struct pci_device *pci, unsigned long where,
22  unsigned long *value, size_t len );
23 extern int linux_pci_write ( struct pci_device *pci, unsigned long where,
24  unsigned long value, size_t len );
25 
26 /**
27  * Check if PCI bus probing is allowed
28  *
29  * @v pci PCI device
30  * @ret ok Bus probing is allowed
31  */
32 static inline __always_inline int
33 PCIAPI_INLINE ( linux, pci_can_probe ) ( struct pci_device *pci __unused ) {
34  return 1;
35 }
36 
37 /**
38  * Find next PCI bus:dev.fn address range in system
39  *
40  * @v busdevfn Starting PCI bus:dev.fn address
41  * @v range PCI bus:dev.fn address range to fill in
42  */
43 static inline __always_inline void
45  struct pci_range *range ) {
46 
47  /* Assume all buses in segment 0 may exist */
48  range->start = PCI_BUSDEVFN ( 0, 0, 0, 0 );
49  range->count = PCI_BUSDEVFN ( 1, 0, 0, 0 );
50 }
51 
52 /**
53  * Read byte from PCI configuration space
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  */
60 static inline __always_inline int
61 PCIAPI_INLINE ( linux, pci_read_config_byte ) ( struct pci_device *pci,
62  unsigned int where,
64  int rc;
65  unsigned long tmp;
66 
67  rc = linux_pci_read ( pci, where, &tmp, sizeof ( *value ) );
68  *value = tmp;
69  return rc;
70 }
71 
72 /**
73  * Read word from PCI configuration space
74  *
75  * @v pci PCI device
76  * @v where Location within PCI configuration space
77  * @v value Value read
78  * @ret rc Return status code
79  */
80 static inline __always_inline int
81 PCIAPI_INLINE ( linux, pci_read_config_word ) ( struct pci_device *pci,
82  unsigned int where,
83  uint16_t *value ) {
84  int rc;
85  unsigned long tmp;
86 
87  rc = linux_pci_read ( pci, where, &tmp, sizeof ( *value ) );
88  *value = tmp;
89  return rc;
90 }
91 
92 /**
93  * Read dword from PCI configuration space
94  *
95  * @v pci PCI device
96  * @v where Location within PCI configuration space
97  * @v value Value read
98  * @ret rc Return status code
99  */
100 static inline __always_inline int
101 PCIAPI_INLINE ( linux, pci_read_config_dword ) ( struct pci_device *pci,
102  unsigned int where,
103  uint32_t *value ) {
104  int rc;
105  unsigned long tmp;
106 
107  rc = linux_pci_read ( pci, where, &tmp, sizeof ( *value ) );
108  *value = tmp;
109  return rc;
110 }
111 
112 /**
113  * Write byte to PCI configuration space
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  */
120 static inline __always_inline int
121 PCIAPI_INLINE ( linux, pci_write_config_byte ) ( struct pci_device *pci,
122  unsigned int where,
123  uint8_t value ) {
124  return linux_pci_write ( pci, where, value, sizeof ( value ) );
125 }
126 
127 /**
128  * Write word to PCI configuration space
129  *
130  * @v pci PCI device
131  * @v where Location within PCI configuration space
132  * @v value Value to be written
133  * @ret rc Return status code
134  */
135 static inline __always_inline int
136 PCIAPI_INLINE ( linux, pci_write_config_word ) ( struct pci_device *pci,
137  unsigned int where,
138  uint16_t value ) {
139  return linux_pci_write ( pci, where, value, sizeof ( value ) );
140 }
141 
142 /**
143  * Write dword to PCI configuration space
144  *
145  * @v pci PCI device
146  * @v where Location within PCI configuration space
147  * @v value Value to be written
148  * @ret rc Return status code
149  */
150 static inline __always_inline int
151 PCIAPI_INLINE ( linux, pci_write_config_dword ) ( struct pci_device *pci,
152  unsigned int where,
153  uint32_t value ) {
154  return linux_pci_write ( pci, where, value, sizeof ( value ) );
155 }
156 
157 /**
158  * Map PCI bus address as an I/O address
159  *
160  * @v bus_addr PCI bus address
161  * @v len Length of region
162  * @ret io_addr I/O address, or NULL on error
163  */
164 static inline __always_inline void *
165 PCIAPI_INLINE ( linux, pci_ioremap ) ( struct pci_device *pci __unused,
166  unsigned long bus_addr, size_t len ) {
167  return ioremap ( bus_addr, len );
168 }
169 
170 #endif /* _IPXE_LINUX_PCI_H */
uint32_t start
Starting bus:dev.fn address.
Definition: pci_io.h:25
unsigned short uint16_t
Definition: stdint.h:11
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
int pci_can_probe(struct pci_device *pci)
Check if PCI bus probing is allowed.
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.
static __always_inline void unsigned long size_t len
Definition: linux_pci.h:166
static __always_inline int unsigned int where
Definition: linux_pci.h:62
rc
Definition: linux_pci.h:67
static __always_inline void struct pci_range * range
Definition: linux_pci.h:45
static __always_inline int unsigned int uint8_t * value
Definition: linux_pci.h:63
unsigned long tmp
Definition: linux_pci.h:65
uint16_t busdevfn
PCI bus:dev.fn address.
Definition: ena.h:28
static __always_inline void unsigned long bus_addr
Definition: linux_pci.h:166
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:23
#define PCI_BUSDEVFN(segment, bus, slot, func)
Definition: pci_io.h:30
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:211
#define __always_inline
Declare a function to be always inline.
Definition: compiler.h:611
static __always_inline int PCIAPI_INLINE(linux, pci_can_probe)(struct pci_device *pci __unused)
Check if PCI bus probing is allowed.
Definition: linux_pci.h:33
unsigned char uint8_t
Definition: stdint.h:10
FILE_SECBOOT(PERMITTED)
unsigned int uint32_t
Definition: stdint.h:12
unsigned int count
Number of bus:dev.fn addresses within this range.
Definition: pci_io.h:27
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.