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  * Read byte from PCI configuration space
27  *
28  * @v pci PCI device
29  * @v where Location within PCI configuration space
30  * @v value Value read
31  * @ret rc Return status code
32  */
33 static inline __always_inline int
34 PCIAPI_INLINE ( linux, pci_read_config_byte ) ( struct pci_device *pci,
35  unsigned int where,
37  int rc;
38  unsigned long tmp;
39 
40  rc = linux_pci_read ( pci, where, &tmp, sizeof ( *value ) );
41  *value = tmp;
42  return rc;
43 }
44 
45 /**
46  * Read word from PCI configuration space
47  *
48  * @v pci PCI device
49  * @v where Location within PCI configuration space
50  * @v value Value read
51  * @ret rc Return status code
52  */
53 static inline __always_inline int
54 PCIAPI_INLINE ( linux, pci_read_config_word ) ( struct pci_device *pci,
55  unsigned int where,
56  uint16_t *value ) {
57  int rc;
58  unsigned long tmp;
59 
60  rc = linux_pci_read ( pci, where, &tmp, sizeof ( *value ) );
61  *value = tmp;
62  return rc;
63 }
64 
65 /**
66  * Read dword from PCI configuration space
67  *
68  * @v pci PCI device
69  * @v where Location within PCI configuration space
70  * @v value Value read
71  * @ret rc Return status code
72  */
73 static inline __always_inline int
74 PCIAPI_INLINE ( linux, pci_read_config_dword ) ( struct pci_device *pci,
75  unsigned int where,
76  uint32_t *value ) {
77  int rc;
78  unsigned long tmp;
79 
80  rc = linux_pci_read ( pci, where, &tmp, sizeof ( *value ) );
81  *value = tmp;
82  return rc;
83 }
84 
85 /**
86  * Write byte to PCI configuration space
87  *
88  * @v pci PCI device
89  * @v where Location within PCI configuration space
90  * @v value Value to be written
91  * @ret rc Return status code
92  */
93 static inline __always_inline int
94 PCIAPI_INLINE ( linux, pci_write_config_byte ) ( struct pci_device *pci,
95  unsigned int where,
96  uint8_t value ) {
97  return linux_pci_write ( pci, where, value, sizeof ( value ) );
98 }
99 
100 /**
101  * Write word 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_word ) ( struct pci_device *pci,
110  unsigned int where,
111  uint16_t value ) {
112  return linux_pci_write ( pci, where, value, sizeof ( value ) );
113 }
114 
115 /**
116  * Write dword 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_dword ) ( struct pci_device *pci,
125  unsigned int where,
126  uint32_t value ) {
127  return linux_pci_write ( pci, where, value, sizeof ( value ) );
128 }
129 
130 #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 int unsigned int where
Definition: linux_pci.h:35
rc
Definition: linux_pci.h:40
static __always_inline int unsigned int uint8_t * value
Definition: linux_pci.h:36
unsigned long tmp
Definition: linux_pci.h:38
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:187
#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
static __always_inline int PCIAPI_INLINE(linux, pci_read_config_byte)(struct pci_device *pci
Read byte from PCI configuration space.
uint32_t len
Length.
Definition: ena.h:14
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword 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.