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