efi_pci.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 FILE_LICENCE ( GPL2_OR_LATER );
00020
00021 #include <errno.h>
00022 #include <gpxe/pci.h>
00023 #include <gpxe/efi/efi.h>
00024 #include <gpxe/efi/Protocol/PciRootBridgeIo.h>
00025
00026
00027
00028
00029
00030
00031
00032
00033 static EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *efipci;
00034 EFI_REQUIRE_PROTOCOL ( EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL, &efipci );
00035
00036 static unsigned long efipci_address ( struct pci_device *pci,
00037 unsigned long location ) {
00038 return EFI_PCI_ADDRESS ( pci->bus, PCI_SLOT ( pci->devfn ),
00039 PCI_FUNC ( pci->devfn ),
00040 EFIPCI_OFFSET ( location ) );
00041 }
00042
00043 int efipci_read ( struct pci_device *pci, unsigned long location,
00044 void *value ) {
00045 EFI_STATUS efirc;
00046
00047 if ( ( efirc = efipci->Pci.Read ( efipci, EFIPCI_WIDTH ( location ),
00048 efipci_address ( pci, location ), 1,
00049 value ) ) != 0 ) {
00050 DBG ( "EFIPCI config read from %02x:%02x.%x offset %02lx "
00051 "failed: %s\n", pci->bus, PCI_SLOT ( pci->devfn ),
00052 PCI_FUNC ( pci->devfn ), EFIPCI_OFFSET ( location ),
00053 efi_strerror ( efirc ) );
00054 return -EIO;
00055 }
00056
00057 return 0;
00058 }
00059
00060 int efipci_write ( struct pci_device *pci, unsigned long location,
00061 unsigned long value ) {
00062 EFI_STATUS efirc;
00063
00064 if ( ( efirc = efipci->Pci.Write ( efipci, EFIPCI_WIDTH ( location ),
00065 efipci_address ( pci, location ), 1,
00066 &value ) ) != 0 ) {
00067 DBG ( "EFIPCI config write to %02x:%02x.%x offset %02lx "
00068 "failed: %s\n", pci->bus, PCI_SLOT ( pci->devfn ),
00069 PCI_FUNC ( pci->devfn ), EFIPCI_OFFSET ( location ),
00070 efi_strerror ( efirc ) );
00071 return -EIO;
00072 }
00073
00074 return 0;
00075 }
00076
00077 PROVIDE_PCIAPI_INLINE ( efi, pci_max_bus );
00078 PROVIDE_PCIAPI_INLINE ( efi, pci_read_config_byte );
00079 PROVIDE_PCIAPI_INLINE ( efi, pci_read_config_word );
00080 PROVIDE_PCIAPI_INLINE ( efi, pci_read_config_dword );
00081 PROVIDE_PCIAPI_INLINE ( efi, pci_write_config_byte );
00082 PROVIDE_PCIAPI_INLINE ( efi, pci_write_config_word );
00083 PROVIDE_PCIAPI_INLINE ( efi, pci_write_config_dword );