You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

efi_pci.c 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. FILE_LICENCE ( GPL2_OR_LATER );
  19. #include <errno.h>
  20. #include <gpxe/pci.h>
  21. #include <gpxe/efi/efi.h>
  22. #include <gpxe/efi/Protocol/PciRootBridgeIo.h>
  23. /** @file
  24. *
  25. * gPXE PCI I/O API for EFI
  26. *
  27. */
  28. /** PCI root bridge I/O protocol */
  29. static EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *efipci;
  30. EFI_REQUIRE_PROTOCOL ( EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL, &efipci );
  31. static unsigned long efipci_address ( struct pci_device *pci,
  32. unsigned long location ) {
  33. return EFI_PCI_ADDRESS ( pci->bus, PCI_SLOT ( pci->devfn ),
  34. PCI_FUNC ( pci->devfn ),
  35. EFIPCI_OFFSET ( location ) );
  36. }
  37. int efipci_read ( struct pci_device *pci, unsigned long location,
  38. void *value ) {
  39. EFI_STATUS efirc;
  40. if ( ( efirc = efipci->Pci.Read ( efipci, EFIPCI_WIDTH ( location ),
  41. efipci_address ( pci, location ), 1,
  42. value ) ) != 0 ) {
  43. DBG ( "EFIPCI config read from %02x:%02x.%x offset %02lx "
  44. "failed: %s\n", pci->bus, PCI_SLOT ( pci->devfn ),
  45. PCI_FUNC ( pci->devfn ), EFIPCI_OFFSET ( location ),
  46. efi_strerror ( efirc ) );
  47. return -EIO;
  48. }
  49. return 0;
  50. }
  51. int efipci_write ( struct pci_device *pci, unsigned long location,
  52. unsigned long value ) {
  53. EFI_STATUS efirc;
  54. if ( ( efirc = efipci->Pci.Write ( efipci, EFIPCI_WIDTH ( location ),
  55. efipci_address ( pci, location ), 1,
  56. &value ) ) != 0 ) {
  57. DBG ( "EFIPCI config write to %02x:%02x.%x offset %02lx "
  58. "failed: %s\n", pci->bus, PCI_SLOT ( pci->devfn ),
  59. PCI_FUNC ( pci->devfn ), EFIPCI_OFFSET ( location ),
  60. efi_strerror ( efirc ) );
  61. return -EIO;
  62. }
  63. return 0;
  64. }
  65. PROVIDE_PCIAPI_INLINE ( efi, pci_max_bus );
  66. PROVIDE_PCIAPI_INLINE ( efi, pci_read_config_byte );
  67. PROVIDE_PCIAPI_INLINE ( efi, pci_read_config_word );
  68. PROVIDE_PCIAPI_INLINE ( efi, pci_read_config_dword );
  69. PROVIDE_PCIAPI_INLINE ( efi, pci_write_config_byte );
  70. PROVIDE_PCIAPI_INLINE ( efi, pci_write_config_word );
  71. PROVIDE_PCIAPI_INLINE ( efi, pci_write_config_dword );