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  * Find next PCI bus:dev.fn address range in system
37  *
38  * @v busdevfn Starting PCI bus:dev.fn address
39  * @v range PCI bus:dev.fn address range to fill in
40  */
41 static inline __always_inline void
43  struct pci_range *range ) {
44 
45  /* EFI does not want us to scan the PCI bus ourselves */
46  range->count = 0;
47 }
48 
49 /**
50  * Read byte from PCI configuration space via EFI
51  *
52  * @v pci PCI device
53  * @v where Location within PCI configuration space
54  * @v value Value read
55  * @ret rc Return status code
56  */
57 static inline __always_inline int
58 PCIAPI_INLINE ( efi, pci_read_config_byte ) ( struct pci_device *pci,
59  unsigned int where,
61  *value = 0xff;
62  return efipci_read ( pci,
64  value );
65 }
66 
67 /**
68  * Read word from PCI configuration space via EFI
69  *
70  * @v pci PCI device
71  * @v where Location within PCI configuration space
72  * @v value Value read
73  * @ret rc Return status code
74  */
75 static inline __always_inline int
76 PCIAPI_INLINE ( efi, pci_read_config_word ) ( struct pci_device *pci,
77  unsigned int where,
78  uint16_t *value ) {
79  *value = 0xffff;
80  return efipci_read ( pci,
82  value );
83 }
84 
85 /**
86  * Read dword from PCI configuration space via EFI
87  *
88  * @v pci PCI device
89  * @v where Location within PCI configuration space
90  * @v value Value read
91  * @ret rc Return status code
92  */
93 static inline __always_inline int
94 PCIAPI_INLINE ( efi, pci_read_config_dword ) ( struct pci_device *pci,
95  unsigned int where,
96  uint32_t *value ) {
97  *value = 0xffffffffUL;
98  return efipci_read ( pci,
100  value );
101 }
102 
103 /**
104  * Write byte to PCI configuration space via EFI
105  *
106  * @v pci PCI device
107  * @v where Location within PCI configuration space
108  * @v value Value to be written
109  * @ret rc Return status code
110  */
111 static inline __always_inline int
112 PCIAPI_INLINE ( efi, pci_write_config_byte ) ( struct pci_device *pci,
113  unsigned int where,
114  uint8_t value ) {
115  return efipci_write ( pci,
117  value );
118 }
119 
120 /**
121  * Write word to PCI configuration space via EFI
122  *
123  * @v pci PCI device
124  * @v where Location within PCI configuration space
125  * @v value Value to be written
126  * @ret rc Return status code
127  */
128 static inline __always_inline int
129 PCIAPI_INLINE ( efi, pci_write_config_word ) ( struct pci_device *pci,
130  unsigned int where,
131  uint16_t value ) {
132  return efipci_write ( pci,
134  value );
135 }
136 
137 /**
138  * Write dword to PCI configuration space via EFI
139  *
140  * @v pci PCI device
141  * @v where Location within PCI configuration space
142  * @v value Value to be written
143  * @ret rc Return status code
144  */
145 static inline __always_inline int
146 PCIAPI_INLINE ( efi, pci_write_config_dword ) ( struct pci_device *pci,
147  unsigned int where,
148  uint32_t value ) {
149  return efipci_write ( pci,
151  value );
152 }
153 
154 #endif /* _IPXE_EFI_PCI_API_H */
unsigned short uint16_t
Definition: stdint.h:11
static __always_inline void struct pci_range * range
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.
#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:228
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
uint16_t busdevfn
PCI bus:dev.fn address.
Definition: ena.h:28
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
A PCI bus:dev.fn address range.
Definition: pci_io.h:21
#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:59
unsigned char uint8_t
Definition: stdint.h:10
unsigned int uint32_t
Definition: stdint.h:12
unsigned int count
Number of bus:dev.fn addresses within this range.
Definition: pci_io.h:25
void pci_discover(uint32_t busdevfn, struct pci_range *range)
Find next PCI bus:dev.fn address range in system.
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
static __always_inline void PCIAPI_INLINE(efi, pci_discover)(uint32_t busdevfn __unused
Find next PCI bus:dev.fn address range in system.
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:60
int efipci_write(struct pci_device *pci, unsigned long location, unsigned long value)
Write to PCI configuration space.
Definition: efi_pci.c:264
int pci_read_config_byte(struct pci_device *pci, unsigned int where, uint8_t *value)
Read byte from PCI configuration space.