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