efi_pci.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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 /** @file
00027  *
00028  * gPXE PCI I/O API for EFI
00029  *
00030  */
00031 
00032 /** PCI root bridge I/O protocol */
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 );

Generated on Tue Apr 6 20:01:09 2010 for gPXE by  doxygen 1.5.7.1