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 FILE_SECBOOT ( PERMITTED );
12 
13 #ifdef PCIAPI_EFI
14 #define PCIAPI_PREFIX_efi
15 #else
16 #define PCIAPI_PREFIX_efi __efi_
17 #endif
18 
19 /* EFI PCI width codes defined by EFI spec */
20 #define EFIPCI_WIDTH_BYTE 0
21 #define EFIPCI_WIDTH_WORD 1
22 #define EFIPCI_WIDTH_DWORD 2
23 
24 #define EFIPCI_LOCATION( _offset, _width ) \
25  ( (_offset) | ( (_width) << 16 ) )
26 #define EFIPCI_OFFSET( _location ) ( (_location) & 0xffff )
27 #define EFIPCI_WIDTH( _location ) ( (_location) >> 16 )
28 
29 struct pci_device;
30 
31 extern int efipci_read ( struct pci_device *pci, unsigned long location,
32  void *value );
33 extern int efipci_write ( struct pci_device *pci, unsigned long location,
34  unsigned long value );
35 
36 /**
37  * Check if PCI bus probing is allowed
38  *
39  * @v pci PCI device
40  * @ret ok Bus probing is allowed
41  */
42 static inline __always_inline int
43 PCIAPI_INLINE ( efi, pci_can_probe ) ( struct pci_device *pci __unused ) {
44  return 0;
45 }
46 
47 /**
48  * Read byte from PCI configuration space via EFI
49  *
50  * @v pci PCI device
51  * @v where Location within PCI configuration space
52  * @v value Value read
53  * @ret rc Return status code
54  */
55 static inline __always_inline int
56 PCIAPI_INLINE ( efi, pci_read_config_byte ) ( struct pci_device *pci,
57  unsigned int where,
59  *value = 0xff;
60  return efipci_read ( pci,
62  value );
63 }
64 
65 /**
66  * Read word from PCI configuration space via EFI
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 ( efi, pci_read_config_word ) ( struct pci_device *pci,
75  unsigned int where,
76  uint16_t *value ) {
77  *value = 0xffff;
78  return efipci_read ( pci,
80  value );
81 }
82 
83 /**
84  * Read dword from PCI configuration space via EFI
85  *
86  * @v pci PCI device
87  * @v where Location within PCI configuration space
88  * @v value Value read
89  * @ret rc Return status code
90  */
91 static inline __always_inline int
92 PCIAPI_INLINE ( efi, pci_read_config_dword ) ( struct pci_device *pci,
93  unsigned int where,
94  uint32_t *value ) {
95  *value = 0xffffffffUL;
96  return efipci_read ( pci,
98  value );
99 }
100 
101 /**
102  * Write byte to PCI configuration space via EFI
103  *
104  * @v pci PCI device
105  * @v where Location within PCI configuration space
106  * @v value Value to be written
107  * @ret rc Return status code
108  */
109 static inline __always_inline int
110 PCIAPI_INLINE ( efi, pci_write_config_byte ) ( struct pci_device *pci,
111  unsigned int where,
112  uint8_t value ) {
113  return efipci_write ( pci,
115  value );
116 }
117 
118 /**
119  * Write word to PCI configuration space via EFI
120  *
121  * @v pci PCI device
122  * @v where Location within PCI configuration space
123  * @v value Value to be written
124  * @ret rc Return status code
125  */
126 static inline __always_inline int
127 PCIAPI_INLINE ( efi, pci_write_config_word ) ( struct pci_device *pci,
128  unsigned int where,
129  uint16_t value ) {
130  return efipci_write ( pci,
132  value );
133 }
134 
135 /**
136  * Write dword to PCI configuration space via EFI
137  *
138  * @v pci PCI device
139  * @v where Location within PCI configuration space
140  * @v value Value to be written
141  * @ret rc Return status code
142  */
143 static inline __always_inline int
144 PCIAPI_INLINE ( efi, pci_write_config_dword ) ( struct pci_device *pci,
145  unsigned int where,
146  uint32_t value ) {
147  return efipci_write ( pci,
149  value );
150 }
151 
152 #endif /* _IPXE_EFI_PCI_API_H */
unsigned short uint16_t
Definition: stdint.h:11
int pci_can_probe(struct pci_device *pci)
Check if PCI bus probing is allowed.
static __always_inline int PCIAPI_INLINE(efi, pci_can_probe)(struct pci_device *pci __unused)
Check if PCI bus probing is allowed.
Definition: efi_pci_api.h:43
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.
FILE_SECBOOT(PERMITTED)
#define EFIPCI_WIDTH_BYTE
Definition: efi_pci_api.h:20
int efipci_read(struct pci_device *pci, unsigned long location, void *value)
Read from PCI configuration space.
Definition: efi_pci.c:301
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.
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
#define EFIPCI_WIDTH_DWORD
Definition: efi_pci_api.h:22
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:211
#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:57
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:24
#define EFIPCI_WIDTH_WORD
Definition: efi_pci_api.h:21
static __always_inline int unsigned int uint8_t * value
Definition: efi_pci_api.h:58
int efipci_write(struct pci_device *pci, unsigned long location, unsigned long value)
Write to PCI configuration space.
Definition: efi_pci.c:334
int pci_read_config_byte(struct pci_device *pci, unsigned int where, uint8_t *value)
Read byte from PCI configuration space.