1 #ifndef _GPXE_EFI_PCI_H
2 #define _GPXE_EFI_PCI_H
6 * gPXE PCI I/O API for EFI
11 #define PCIAPI_PREFIX_efi
13 #define PCIAPI_PREFIX_efi __efi_
16 /* EFI PCI width codes defined by EFI spec */
17 #define EFIPCI_WIDTH_BYTE 0
18 #define EFIPCI_WIDTH_WORD 1
19 #define EFIPCI_WIDTH_DWORD 2
21 #define EFIPCI_LOCATION( _offset, _width ) \
22 ( (_offset) | ( (_width) << 16 ) )
23 #define EFIPCI_OFFSET( _location ) ( (_location) & 0xffff )
24 #define EFIPCI_WIDTH( _location ) ( (_location) >> 16 )
28 extern int efipci_read ( struct pci_device *pci, unsigned long location,
30 extern int efipci_write ( struct pci_device *pci, unsigned long location,
31 unsigned long value );
34 * Determine maximum PCI bus number within system
36 * @ret max_bus Maximum bus number
38 static inline __always_inline int
39 PCIAPI_INLINE ( efi, pci_max_bus ) ( void ) {
40 /* No way to work this out via EFI */
45 * Read byte from PCI configuration space via EFI
48 * @v where Location within PCI configuration space
50 * @ret rc Return status code
52 static inline __always_inline int
53 PCIAPI_INLINE ( efi, pci_read_config_byte ) ( struct pci_device *pci,
56 return efipci_read ( pci,
57 EFIPCI_LOCATION ( where, EFIPCI_WIDTH_BYTE ),
62 * Read word from PCI configuration space via EFI
65 * @v where Location within PCI configuration space
67 * @ret rc Return status code
69 static inline __always_inline int
70 PCIAPI_INLINE ( efi, pci_read_config_word ) ( struct pci_device *pci,
73 return efipci_read ( pci,
74 EFIPCI_LOCATION ( where, EFIPCI_WIDTH_WORD ),
79 * Read dword from PCI configuration space via EFI
82 * @v where Location within PCI configuration space
84 * @ret rc Return status code
86 static inline __always_inline int
87 PCIAPI_INLINE ( efi, pci_read_config_dword ) ( struct pci_device *pci,
90 return efipci_read ( pci,
91 EFIPCI_LOCATION ( where, EFIPCI_WIDTH_DWORD ),
96 * Write byte to PCI configuration space via EFI
99 * @v where Location within PCI configuration space
100 * @v value Value to be written
101 * @ret rc Return status code
103 static inline __always_inline int
104 PCIAPI_INLINE ( efi, pci_write_config_byte ) ( struct pci_device *pci,
107 return efipci_write ( pci,
108 EFIPCI_LOCATION ( where, EFIPCI_WIDTH_BYTE ),
113 * Write word to PCI configuration space via EFI
116 * @v where Location within PCI configuration space
117 * @v value Value to be written
118 * @ret rc Return status code
120 static inline __always_inline int
121 PCIAPI_INLINE ( efi, pci_write_config_word ) ( struct pci_device *pci,
124 return efipci_write ( pci,
125 EFIPCI_LOCATION ( where, EFIPCI_WIDTH_WORD ),
130 * Write dword to PCI configuration space via EFI
133 * @v where Location within PCI configuration space
134 * @v value Value to be written
135 * @ret rc Return status code
137 static inline __always_inline int
138 PCIAPI_INLINE ( efi, pci_write_config_dword ) ( struct pci_device *pci,
141 return efipci_write ( pci,
142 EFIPCI_LOCATION ( where, EFIPCI_WIDTH_DWORD ),
146 #endif /* _GPXE_EFI_PCI_H */