iPXE
efi_pci_api.h
Go to the documentation of this file.
00001 #ifndef _IPXE_EFI_PCI_API_H
00002 #define _IPXE_EFI_PCI_API_H
00003 
00004 /** @file
00005  *
00006  * iPXE PCI I/O API for EFI
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00011 
00012 #ifdef PCIAPI_EFI
00013 #define PCIAPI_PREFIX_efi
00014 #else
00015 #define PCIAPI_PREFIX_efi __efi_
00016 #endif
00017 
00018 /* EFI PCI width codes defined by EFI spec */
00019 #define EFIPCI_WIDTH_BYTE 0
00020 #define EFIPCI_WIDTH_WORD 1
00021 #define EFIPCI_WIDTH_DWORD 2
00022 
00023 #define EFIPCI_LOCATION( _offset, _width ) \
00024         ( (_offset) | ( (_width) << 16 ) )
00025 #define EFIPCI_OFFSET( _location ) ( (_location) & 0xffff )
00026 #define EFIPCI_WIDTH( _location ) ( (_location) >> 16 )
00027 
00028 struct pci_device;
00029 
00030 extern int efipci_read ( struct pci_device *pci, unsigned long location,
00031                          void *value );
00032 extern int efipci_write ( struct pci_device *pci, unsigned long location,
00033                           unsigned long value );
00034 
00035 /**
00036  * Determine number of PCI buses within system
00037  *
00038  * @ret num_bus         Number of buses
00039  */
00040 static inline __always_inline int
00041 PCIAPI_INLINE ( efi, pci_num_bus ) ( void ) {
00042         /* EFI does not want us to scan the PCI bus ourselves */
00043         return 0;
00044 }
00045 
00046 /**
00047  * Read byte from PCI configuration space via EFI
00048  *
00049  * @v pci       PCI device
00050  * @v where     Location within PCI configuration space
00051  * @v value     Value read
00052  * @ret rc      Return status code
00053  */
00054 static inline __always_inline int
00055 PCIAPI_INLINE ( efi, pci_read_config_byte ) ( struct pci_device *pci,
00056                                               unsigned int where,
00057                                               uint8_t *value ) {
00058         *value = 0xff;
00059         return efipci_read ( pci,
00060                              EFIPCI_LOCATION ( where, EFIPCI_WIDTH_BYTE ),
00061                              value );
00062 }
00063 
00064 /**
00065  * Read word from PCI configuration space via EFI
00066  *
00067  * @v pci       PCI device
00068  * @v where     Location within PCI configuration space
00069  * @v value     Value read
00070  * @ret rc      Return status code
00071  */
00072 static inline __always_inline int
00073 PCIAPI_INLINE ( efi, pci_read_config_word ) ( struct pci_device *pci,
00074                                               unsigned int where,
00075                                               uint16_t *value ) {
00076         *value = 0xffff;
00077         return efipci_read ( pci,
00078                              EFIPCI_LOCATION ( where, EFIPCI_WIDTH_WORD ),
00079                              value );
00080 }
00081 
00082 /**
00083  * Read dword from PCI configuration space via EFI
00084  *
00085  * @v pci       PCI device
00086  * @v where     Location within PCI configuration space
00087  * @v value     Value read
00088  * @ret rc      Return status code
00089  */
00090 static inline __always_inline int
00091 PCIAPI_INLINE ( efi, pci_read_config_dword ) ( struct pci_device *pci,
00092                                                unsigned int where,
00093                                                uint32_t *value ) {
00094         *value = 0xffffffffUL;
00095         return efipci_read ( pci,
00096                              EFIPCI_LOCATION ( where, EFIPCI_WIDTH_DWORD ),
00097                              value );
00098 }
00099 
00100 /**
00101  * Write byte to PCI configuration space via EFI
00102  *
00103  * @v pci       PCI device
00104  * @v where     Location within PCI configuration space
00105  * @v value     Value to be written
00106  * @ret rc      Return status code
00107  */
00108 static inline __always_inline int
00109 PCIAPI_INLINE ( efi, pci_write_config_byte ) ( struct pci_device *pci,
00110                                                unsigned int where,
00111                                                uint8_t value ) {
00112         return efipci_write ( pci,
00113                               EFIPCI_LOCATION ( where, EFIPCI_WIDTH_BYTE ),
00114                               value );
00115 }
00116 
00117 /**
00118  * Write word to PCI configuration space via EFI
00119  *
00120  * @v pci       PCI device
00121  * @v where     Location within PCI configuration space
00122  * @v value     Value to be written
00123  * @ret rc      Return status code
00124  */
00125 static inline __always_inline int
00126 PCIAPI_INLINE ( efi, pci_write_config_word ) ( struct pci_device *pci,
00127                                                unsigned int where,
00128                                                uint16_t value ) {
00129         return efipci_write ( pci,
00130                               EFIPCI_LOCATION ( where, EFIPCI_WIDTH_WORD ),
00131                               value );
00132 }
00133 
00134 /**
00135  * Write dword to PCI configuration space via EFI
00136  *
00137  * @v pci       PCI device
00138  * @v where     Location within PCI configuration space
00139  * @v value     Value to be written
00140  * @ret rc      Return status code
00141  */
00142 static inline __always_inline int
00143 PCIAPI_INLINE ( efi, pci_write_config_dword ) ( struct pci_device *pci,
00144                                                 unsigned int where,
00145                                                 uint32_t value ) {
00146         return efipci_write ( pci,
00147                               EFIPCI_LOCATION ( where, EFIPCI_WIDTH_DWORD ),
00148                               value );
00149 }
00150 
00151 #endif /* _IPXE_EFI_PCI_API_H */