iPXE
pcibios.h
Go to the documentation of this file.
00001 #ifndef _IPXE_PCIBIOS_H
00002 #define _IPXE_PCIBIOS_H
00003 
00004 #include <stdint.h>
00005 
00006 /** @file
00007  *
00008  * PCI configuration space access via PCI BIOS
00009  *
00010  */
00011 
00012 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00013 
00014 #ifdef PCIAPI_PCBIOS
00015 #define PCIAPI_PREFIX_pcbios
00016 #else
00017 #define PCIAPI_PREFIX_pcbios __pcbios_
00018 #endif
00019 
00020 struct pci_device;
00021 
00022 #define PCIBIOS_INSTALLATION_CHECK      0xb1010000
00023 #define PCIBIOS_READ_CONFIG_BYTE        0xb1080000
00024 #define PCIBIOS_READ_CONFIG_WORD        0xb1090000
00025 #define PCIBIOS_READ_CONFIG_DWORD       0xb10a0000
00026 #define PCIBIOS_WRITE_CONFIG_BYTE       0xb10b0000
00027 #define PCIBIOS_WRITE_CONFIG_WORD       0xb10c0000
00028 #define PCIBIOS_WRITE_CONFIG_DWORD      0xb10d0000
00029 
00030 extern int pcibios_read ( struct pci_device *pci, uint32_t command,
00031                           uint32_t *value );
00032 extern int pcibios_write ( struct pci_device *pci, uint32_t command,
00033                            uint32_t value );
00034 
00035 /**
00036  * Read byte from PCI configuration space via PCI BIOS
00037  *
00038  * @v pci       PCI device
00039  * @v where     Location within PCI configuration space
00040  * @v value     Value read
00041  * @ret rc      Return status code
00042  */
00043 static inline __always_inline int
00044 PCIAPI_INLINE ( pcbios, pci_read_config_byte ) ( struct pci_device *pci,
00045                                                  unsigned int where,
00046                                                  uint8_t *value ) {
00047         uint32_t tmp;
00048         int rc;
00049 
00050         rc = pcibios_read ( pci, PCIBIOS_READ_CONFIG_BYTE | where, &tmp );
00051         *value = tmp;
00052         return rc;
00053 }
00054 
00055 /**
00056  * Read word from PCI configuration space via PCI BIOS
00057  *
00058  * @v pci       PCI device
00059  * @v where     Location within PCI configuration space
00060  * @v value     Value read
00061  * @ret rc      Return status code
00062  */
00063 static inline __always_inline int
00064 PCIAPI_INLINE ( pcbios, pci_read_config_word ) ( struct pci_device *pci,
00065                                                  unsigned int where,
00066                                                  uint16_t *value ) {
00067         uint32_t tmp;
00068         int rc;
00069 
00070         rc = pcibios_read ( pci, PCIBIOS_READ_CONFIG_WORD | where, &tmp );
00071         *value = tmp;
00072         return rc;
00073 }
00074 
00075 /**
00076  * Read dword from PCI configuration space via PCI BIOS
00077  *
00078  * @v pci       PCI device
00079  * @v where     Location within PCI configuration space
00080  * @v value     Value read
00081  * @ret rc      Return status code
00082  */
00083 static inline __always_inline int
00084 PCIAPI_INLINE ( pcbios, pci_read_config_dword ) ( struct pci_device *pci,
00085                                                   unsigned int where,
00086                                                   uint32_t *value ) {
00087         return pcibios_read ( pci, PCIBIOS_READ_CONFIG_DWORD | where, value );
00088 }
00089 
00090 /**
00091  * Write byte to PCI configuration space via PCI BIOS
00092  *
00093  * @v pci       PCI device
00094  * @v where     Location within PCI configuration space
00095  * @v value     Value to be written
00096  * @ret rc      Return status code
00097  */
00098 static inline __always_inline int
00099 PCIAPI_INLINE ( pcbios, pci_write_config_byte ) ( struct pci_device *pci,
00100                                                   unsigned int where,
00101                                                   uint8_t value ) {
00102         return pcibios_write ( pci, PCIBIOS_WRITE_CONFIG_BYTE | where, value );
00103 }
00104 
00105 /**
00106  * Write word to PCI configuration space via PCI BIOS
00107  *
00108  * @v pci       PCI device
00109  * @v where     Location within PCI configuration space
00110  * @v value     Value to be written
00111  * @ret rc      Return status code
00112  */
00113 static inline __always_inline int
00114 PCIAPI_INLINE ( pcbios, pci_write_config_word ) ( struct pci_device *pci,
00115                                                   unsigned int where,
00116                                                   uint16_t value ) {
00117         return pcibios_write ( pci, PCIBIOS_WRITE_CONFIG_WORD | where, value );
00118 }
00119 
00120 /**
00121  * Write dword to PCI configuration space via PCI BIOS
00122  *
00123  * @v pci       PCI device
00124  * @v where     Location within PCI configuration space
00125  * @v value     Value to be written
00126  * @ret rc      Return status code
00127  */
00128 static inline __always_inline int
00129 PCIAPI_INLINE ( pcbios, pci_write_config_dword ) ( struct pci_device *pci,
00130                                                    unsigned int where,
00131                                                    uint32_t value ) {
00132         return pcibios_write ( pci, PCIBIOS_WRITE_CONFIG_DWORD | where, value);
00133 }
00134 
00135 #endif /* _IPXE_PCIBIOS_H */