iPXE
pcidirect.h
Go to the documentation of this file.
00001 #ifndef _PCIDIRECT_H
00002 #define _PCIDIRECT_H
00003 
00004 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00005 
00006 #include <stdint.h>
00007 #include <ipxe/io.h>
00008 
00009 #ifdef PCIAPI_DIRECT
00010 #define PCIAPI_PREFIX_direct
00011 #else
00012 #define PCIAPI_PREFIX_direct __direct_
00013 #endif
00014 
00015 /** @file
00016  *
00017  * PCI configuration space access via Type 1 accesses
00018  *
00019  */
00020 
00021 #define PCIDIRECT_CONFIG_ADDRESS        0xcf8
00022 #define PCIDIRECT_CONFIG_DATA           0xcfc
00023 
00024 struct pci_device;
00025 
00026 extern void pcidirect_prepare ( struct pci_device *pci, int where );
00027 
00028 /**
00029  * Determine number of PCI buses within system
00030  *
00031  * @ret num_bus         Number of buses
00032  */
00033 static inline __always_inline int
00034 PCIAPI_INLINE ( direct, pci_num_bus ) ( void ) {
00035         /* No way to work this out via Type 1 accesses */
00036         return 0x100;
00037 }
00038 
00039 /**
00040  * Read byte from PCI configuration space via Type 1 access
00041  *
00042  * @v pci       PCI device
00043  * @v where     Location within PCI configuration space
00044  * @v value     Value read
00045  * @ret rc      Return status code
00046  */
00047 static inline __always_inline int
00048 PCIAPI_INLINE ( direct, pci_read_config_byte ) ( struct pci_device *pci,
00049                                                  unsigned int where,
00050                                                  uint8_t *value ) {
00051         pcidirect_prepare ( pci, where );
00052         *value = inb ( PCIDIRECT_CONFIG_DATA + ( where & 3 ) );
00053         return 0;
00054 }
00055 
00056 /**
00057  * Read word from PCI configuration space via Type 1 access
00058  *
00059  * @v pci       PCI device
00060  * @v where     Location within PCI configuration space
00061  * @v value     Value read
00062  * @ret rc      Return status code
00063  */
00064 static inline __always_inline int
00065 PCIAPI_INLINE ( direct, pci_read_config_word ) ( struct pci_device *pci,
00066                                                  unsigned int where,
00067                                                  uint16_t *value ) {
00068         pcidirect_prepare ( pci, where );
00069         *value = inw ( PCIDIRECT_CONFIG_DATA + ( where & 2 ) );
00070         return 0;
00071 }
00072 
00073 /**
00074  * Read dword from PCI configuration space via Type 1 access
00075  *
00076  * @v pci       PCI device
00077  * @v where     Location within PCI configuration space
00078  * @v value     Value read
00079  * @ret rc      Return status code
00080  */
00081 static inline __always_inline int
00082 PCIAPI_INLINE ( direct, pci_read_config_dword ) ( struct pci_device *pci,
00083                                                   unsigned int where,
00084                                                   uint32_t *value ) {
00085         pcidirect_prepare ( pci, where );
00086         *value = inl ( PCIDIRECT_CONFIG_DATA );
00087         return 0;
00088 }
00089 
00090 /**
00091  * Write byte to PCI configuration space via Type 1 access
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 ( direct, pci_write_config_byte ) ( struct pci_device *pci,
00100                                                   unsigned int where,
00101                                                   uint8_t value ) {
00102         pcidirect_prepare ( pci, where );
00103         outb ( value, PCIDIRECT_CONFIG_DATA + ( where & 3 ) );
00104         return 0;
00105 }
00106 
00107 /**
00108  * Write word to PCI configuration space via Type 1 access
00109  *
00110  * @v pci       PCI device
00111  * @v where     Location within PCI configuration space
00112  * @v value     Value to be written
00113  * @ret rc      Return status code
00114  */
00115 static inline __always_inline int
00116 PCIAPI_INLINE ( direct, pci_write_config_word ) ( struct pci_device *pci,
00117                                                   unsigned int where,
00118                                                   uint16_t value ) {
00119         pcidirect_prepare ( pci, where );
00120         outw ( value, PCIDIRECT_CONFIG_DATA + ( where & 2 ) );
00121         return 0;
00122 }
00123 
00124 /**
00125  * Write dword to PCI configuration space via Type 1 access
00126  *
00127  * @v pci       PCI device
00128  * @v where     Location within PCI configuration space
00129  * @v value     Value to be written
00130  * @ret rc      Return status code
00131  */
00132 static inline __always_inline int
00133 PCIAPI_INLINE ( direct, pci_write_config_dword ) ( struct pci_device *pci,
00134                                                    unsigned int where,
00135                                                    uint32_t value ) {
00136         pcidirect_prepare ( pci, where );
00137         outl ( value, PCIDIRECT_CONFIG_DATA );
00138         return 0;
00139 }
00140 
00141 #endif /* _PCIDIRECT_H */