1 #ifndef _IPXE_EFI_PCI_API_H
2 #define _IPXE_EFI_PCI_API_H
6 * iPXE PCI I/O API for EFI
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
13 #define PCIAPI_PREFIX_efi
15 #define PCIAPI_PREFIX_efi __efi_
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
23 #define EFIPCI_LOCATION( _offset, _width ) \
24 ( (_offset) | ( (_width) << 16 ) )
25 #define EFIPCI_OFFSET( _location ) ( (_location) & 0xffff )
26 #define EFIPCI_WIDTH( _location ) ( (_location) >> 16 )
30 extern int efipci_read ( struct pci_device *pci, unsigned long location,
32 extern int efipci_write ( struct pci_device *pci, unsigned long location,
33 unsigned long value );
36 * Determine number of PCI buses within system
38 * @ret num_bus Number of buses
40 static inline __always_inline int
41 PCIAPI_INLINE ( efi, pci_num_bus ) ( void ) {
42 /* EFI does not want us to scan the PCI bus ourselves */
47 * Read byte from PCI configuration space via EFI
50 * @v where Location within PCI configuration space
52 * @ret rc Return status code
54 static inline __always_inline int
55 PCIAPI_INLINE ( efi, pci_read_config_byte ) ( struct pci_device *pci,
59 return efipci_read ( pci,
60 EFIPCI_LOCATION ( where, EFIPCI_WIDTH_BYTE ),
65 * Read word from PCI configuration space via EFI
68 * @v where Location within PCI configuration space
70 * @ret rc Return status code
72 static inline __always_inline int
73 PCIAPI_INLINE ( efi, pci_read_config_word ) ( struct pci_device *pci,
77 return efipci_read ( pci,
78 EFIPCI_LOCATION ( where, EFIPCI_WIDTH_WORD ),
83 * Read dword from PCI configuration space via EFI
86 * @v where Location within PCI configuration space
88 * @ret rc Return status code
90 static inline __always_inline int
91 PCIAPI_INLINE ( efi, pci_read_config_dword ) ( struct pci_device *pci,
94 *value = 0xffffffffUL;
95 return efipci_read ( pci,
96 EFIPCI_LOCATION ( where, EFIPCI_WIDTH_DWORD ),
101 * Write byte to PCI configuration space via EFI
104 * @v where Location within PCI configuration space
105 * @v value Value to be written
106 * @ret rc Return status code
108 static inline __always_inline int
109 PCIAPI_INLINE ( efi, pci_write_config_byte ) ( struct pci_device *pci,
112 return efipci_write ( pci,
113 EFIPCI_LOCATION ( where, EFIPCI_WIDTH_BYTE ),
118 * Write word to PCI configuration space via EFI
121 * @v where Location within PCI configuration space
122 * @v value Value to be written
123 * @ret rc Return status code
125 static inline __always_inline int
126 PCIAPI_INLINE ( efi, pci_write_config_word ) ( struct pci_device *pci,
129 return efipci_write ( pci,
130 EFIPCI_LOCATION ( where, EFIPCI_WIDTH_WORD ),
135 * Write dword to PCI configuration space via EFI
138 * @v where Location within PCI configuration space
139 * @v value Value to be written
140 * @ret rc Return status code
142 static inline __always_inline int
143 PCIAPI_INLINE ( efi, pci_write_config_dword ) ( struct pci_device *pci,
146 return efipci_write ( pci,
147 EFIPCI_LOCATION ( where, EFIPCI_WIDTH_DWORD ),
151 #endif /* _IPXE_EFI_PCI_API_H */