iPXE
efi_pci_api.h
Go to the documentation of this file.
1 #ifndef _IPXE_EFI_PCI_API_H
2 #define _IPXE_EFI_PCI_API_H
3 
4 /** @file
5  *
6  * iPXE PCI I/O API for EFI
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 
12 #ifdef PCIAPI_EFI
13 #define PCIAPI_PREFIX_efi
14 #else
15 #define PCIAPI_PREFIX_efi __efi_
16 #endif
17 
18 /* EFI PCI width codes defined by EFI spec */
19 #define EFIPCI_WIDTH_BYTE 0
20 #define EFIPCI_WIDTH_WORD 1
21 #define EFIPCI_WIDTH_DWORD 2
22 
23 #define EFIPCI_LOCATION( _offset, _width ) \
24  ( (_offset) | ( (_width) << 16 ) )
25 #define EFIPCI_OFFSET( _location ) ( (_location) & 0xffff )
26 #define EFIPCI_WIDTH( _location ) ( (_location) >> 16 )
27 
28 struct pci_device;
29 
30 extern int efipci_read ( struct pci_device *pci, unsigned long location,
31  void *value );
32 extern int efipci_write ( struct pci_device *pci, unsigned long location,
33  unsigned long value );
34 
35 /**
36  * Check if PCI bus probing is allowed
37  *
38  * @ret ok Bus probing is allowed
39  */
40 static inline __always_inline int
41 PCIAPI_INLINE ( efi, pci_can_probe ) ( void ) {
42  return 0;
43 }
44 
45 /**
46  * Read byte from PCI configuration space via EFI
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 ( efi, pci_read_config_byte ) ( struct pci_device *pci,
55  unsigned int where,
57  *value = 0xff;
58  return efipci_read ( pci,
60  value );
61 }
62 
63 /**
64  * Read word from PCI configuration space via EFI
65  *
66  * @v pci PCI device
67  * @v where Location within PCI configuration space
68  * @v value Value read
69  * @ret rc Return status code
70  */
71 static inline __always_inline int
72 PCIAPI_INLINE ( efi, pci_read_config_word ) ( struct pci_device *pci,
73  unsigned int where,
74  uint16_t *value ) {
75  *value = 0xffff;
76  return efipci_read ( pci,
78  value );
79 }
80 
81 /**
82  * Read dword from PCI configuration space via EFI
83  *
84  * @v pci PCI device
85  * @v where Location within PCI configuration space
86  * @v value Value read
87  * @ret rc Return status code
88  */
89 static inline __always_inline int
90 PCIAPI_INLINE ( efi, pci_read_config_dword ) ( struct pci_device *pci,
91  unsigned int where,
92  uint32_t *value ) {
93  *value = 0xffffffffUL;
94  return efipci_read ( pci,
96  value );
97 }
98 
99 /**
100  * Write byte to PCI configuration space via EFI
101  *
102  * @v pci PCI device
103  * @v where Location within PCI configuration space
104  * @v value Value to be written
105  * @ret rc Return status code
106  */
107 static inline __always_inline int
108 PCIAPI_INLINE ( efi, pci_write_config_byte ) ( struct pci_device *pci,
109  unsigned int where,
110  uint8_t value ) {
111  return efipci_write ( pci,
113  value );
114 }
115 
116 /**
117  * Write word to PCI configuration space via EFI
118  *
119  * @v pci PCI device
120  * @v where Location within PCI configuration space
121  * @v value Value to be written
122  * @ret rc Return status code
123  */
124 static inline __always_inline int
125 PCIAPI_INLINE ( efi, pci_write_config_word ) ( struct pci_device *pci,
126  unsigned int where,
127  uint16_t value ) {
128  return efipci_write ( pci,
130  value );
131 }
132 
133 /**
134  * Write dword to PCI configuration space via EFI
135  *
136  * @v pci PCI device
137  * @v where Location within PCI configuration space
138  * @v value Value to be written
139  * @ret rc Return status code
140  */
141 static inline __always_inline int
142 PCIAPI_INLINE ( efi, pci_write_config_dword ) ( struct pci_device *pci,
143  unsigned int where,
144  uint32_t value ) {
145  return efipci_write ( pci,
147  value );
148 }
149 
150 #endif /* _IPXE_EFI_PCI_API_H */
unsigned short uint16_t
Definition: stdint.h:11
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_can_probe(void)
Check if PCI bus probing is allowed.
int pci_read_config_word(struct pci_device *pci, unsigned int where, uint16_t *value)
Read 16-bit word from PCI configuration space.
#define EFIPCI_WIDTH_BYTE
Definition: efi_pci_api.h:19
int efipci_read(struct pci_device *pci, unsigned long location, void *value)
Read from PCI configuration space.
Definition: efi_pci.c:340
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
static __always_inline int PCIAPI_INLINE(efi, pci_can_probe)(void)
Check if PCI bus probing is allowed.
Definition: efi_pci_api.h:41
#define EFIPCI_WIDTH_DWORD
Definition: efi_pci_api.h:21
int pci_write_config_byte(struct pci_device *pci, unsigned int where, uint8_t value)
Write byte to PCI configuration space.
A PCI device.
Definition: pci.h:206
#define __always_inline
Declare a function to be always inline.
Definition: compiler.h:611
static __always_inline int unsigned int where
Definition: efi_pci_api.h:55
unsigned char uint8_t
Definition: stdint.h:10
unsigned int uint32_t
Definition: stdint.h:12
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword to PCI configuration space.
#define EFIPCI_LOCATION(_offset, _width)
Definition: efi_pci_api.h:23
#define EFIPCI_WIDTH_WORD
Definition: efi_pci_api.h:20
static __always_inline int unsigned int uint8_t * value
Definition: efi_pci_api.h:56
int efipci_write(struct pci_device *pci, unsigned long location, unsigned long value)
Write to PCI configuration space.
Definition: efi_pci.c:376
int pci_read_config_byte(struct pci_device *pci, unsigned int where, uint8_t *value)
Read byte from PCI configuration space.