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