iPXE
linux_pci.h
Go to the documentation of this file.
00001 #ifndef _IPXE_LINUX_PCI_H
00002 #define _IPXE_LINUX_PCI_H
00003 
00004 /** @file
00005  *
00006  * iPXE PCI API for Linux
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00011 
00012 #ifdef PCIAPI_LINUX
00013 #define PCIAPI_PREFIX_linux
00014 #else
00015 #define PCIAPI_PREFIX_linux __linux_
00016 #endif
00017 
00018 struct pci_device;
00019 
00020 extern int linux_pci_read ( struct pci_device *pci, unsigned long where,
00021                             unsigned long *value, size_t len );
00022 extern int linux_pci_write ( struct pci_device *pci, unsigned long where,
00023                              unsigned long value, size_t len );
00024 
00025 /**
00026  * Read byte from PCI configuration space
00027  *
00028  * @v pci       PCI device
00029  * @v where     Location within PCI configuration space
00030  * @v value     Value read
00031  * @ret rc      Return status code
00032  */
00033 static inline __always_inline int
00034 PCIAPI_INLINE ( linux, pci_read_config_byte ) ( struct pci_device *pci,
00035                                                 unsigned int where,
00036                                                 uint8_t *value ) {
00037         int rc;
00038         unsigned long tmp;
00039 
00040         rc = linux_pci_read ( pci, where, &tmp, sizeof ( *value ) );
00041         *value = tmp;
00042         return rc;
00043 }
00044 
00045 /**
00046  * Read word from PCI configuration space
00047  *
00048  * @v pci       PCI device
00049  * @v where     Location within PCI configuration space
00050  * @v value     Value read
00051  * @ret rc      Return status code
00052  */
00053 static inline __always_inline int
00054 PCIAPI_INLINE ( linux, pci_read_config_word ) ( struct pci_device *pci,
00055                                                 unsigned int where,
00056                                                 uint16_t *value ) {
00057         int rc;
00058         unsigned long tmp;
00059 
00060         rc = linux_pci_read ( pci, where, &tmp, sizeof ( *value ) );
00061         *value = tmp;
00062         return rc;
00063 }
00064 
00065 /**
00066  * Read dword from PCI configuration space
00067  *
00068  * @v pci       PCI device
00069  * @v where     Location within PCI configuration space
00070  * @v value     Value read
00071  * @ret rc      Return status code
00072  */
00073 static inline __always_inline int
00074 PCIAPI_INLINE ( linux, pci_read_config_dword ) ( struct pci_device *pci,
00075                                                  unsigned int where,
00076                                                  uint32_t *value ) {
00077         int rc;
00078         unsigned long tmp;
00079 
00080         rc = linux_pci_read ( pci, where, &tmp, sizeof ( *value ) );
00081         *value = tmp;
00082         return rc;
00083 }
00084 
00085 /**
00086  * Write byte to PCI configuration space
00087  *
00088  * @v pci       PCI device
00089  * @v where     Location within PCI configuration space
00090  * @v value     Value to be written
00091  * @ret rc      Return status code
00092  */
00093 static inline __always_inline int
00094 PCIAPI_INLINE ( linux, pci_write_config_byte ) ( struct pci_device *pci,
00095                                                  unsigned int where,
00096                                                  uint8_t value ) {
00097         return linux_pci_write ( pci, where, value, sizeof ( value ) );
00098 }
00099 
00100 /**
00101  * Write word to PCI configuration space
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 ( linux, pci_write_config_word ) ( struct pci_device *pci,
00110                                                  unsigned int where,
00111                                                  uint16_t value ) {
00112         return linux_pci_write ( pci, where, value, sizeof ( value ) );
00113 }
00114 
00115 /**
00116  * Write dword to PCI configuration space
00117  *
00118  * @v pci       PCI device
00119  * @v where     Location within PCI configuration space
00120  * @v value     Value to be written
00121  * @ret rc      Return status code
00122  */
00123 static inline __always_inline int
00124 PCIAPI_INLINE ( linux, pci_write_config_dword ) ( struct pci_device *pci,
00125                                                   unsigned int where,
00126                                                   uint32_t value ) {
00127         return linux_pci_write ( pci, where, value, sizeof ( value ) );
00128 }
00129 
00130 #endif /* _IPXE_LINUX_PCI_H */