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
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11FILE_SECBOOT ( PERMITTED );
12
13#ifdef PCIAPI_LINUX
14#define PCIAPI_PREFIX_linux
15#else
16#define PCIAPI_PREFIX_linux __linux_
17#endif
18
19struct pci_device;
20
21extern int linux_pci_read ( struct pci_device *pci, unsigned long where,
22 unsigned long *value, size_t len );
23extern 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 */
32static inline __always_inline int
33PCIAPI_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 */
43static 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 */
60static inline __always_inline int
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 */
80static inline __always_inline int
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 */
100static inline __always_inline int
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 */
120static inline __always_inline int
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 */
135static inline __always_inline int
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 */
150static inline __always_inline int
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 */
164static inline __always_inline void *
166 unsigned long bus_addr, size_t len ) {
167 return ioremap ( bus_addr, len );
168}
169
170#endif /* _IPXE_LINUX_PCI_H */
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
pseudo_bit_t value[0x00020]
Definition arbel.h:2
unsigned short uint16_t
Definition stdint.h:11
unsigned int uint32_t
Definition stdint.h:12
unsigned char uint8_t
Definition stdint.h:10
ring len
Length.
Definition dwmac.h:226
uint16_t busdevfn
PCI bus:dev.fn address.
Definition ena.h:17
#define __always_inline
Declare a function to be always inline.
Definition compiler.h:611
#define __unused
Declare a variable or data structure as unused.
Definition compiler.h:573
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
void * ioremap(unsigned long bus_addr, size_t len)
Map bus address as an I/O address.
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
int pci_can_probe(struct pci_device *pci)
Check if PCI bus probing is allowed.
void pci_discover(uint32_t busdevfn, struct pci_range *range)
Find next PCI bus:dev.fn address range in system.
int pci_read_config_word(struct pci_device *pci, unsigned int where, uint16_t *value)
Read 16-bit word from PCI configuration space.
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
#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 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_byte(struct pci_device *pci, unsigned int where, uint8_t *value)
Read byte from PCI configuration space.
#define PCIAPI_INLINE(_subsys, _api_func)
Calculate static inline PCI I/O API function name.
Definition pci_io.h:41
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword to PCI configuration space.
unsigned long tmp
Definition linux_pci.h:65
int linux_pci_write(struct pci_device *pci, unsigned long where, unsigned long value, size_t len)
int linux_pci_read(struct pci_device *pci, unsigned long where, unsigned long *value, size_t len)
static __always_inline void unsigned long bus_addr
Definition pcibios.h:156
static __always_inline int unsigned int where
Definition pcibios.h:57
struct pci_range range
PCI bus:dev.fn address range.
Definition pcicloud.c:40
A PCI device.
Definition pci.h:211
A PCI bus:dev.fn address range.
Definition pci_io.h:23