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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #include <errno.h>
  19. #include <gpxe/pci.h>
  20. #include <gpxe/efi/efi.h>
  21. #include <gpxe/efi/Protocol/PciRootBridgeIo.h>
  22. /** @file
  23. *
  24. * gPXE PCI I/O API for EFI
  25. *
  26. */
  27. /** PCI root bridge I/O protocol */
  28. static EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *efipci;
  29. EFI_REQUIRE_PROTOCOL ( EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL, &efipci );
  30. static unsigned long efipci_address ( struct pci_device *pci,
  31. unsigned long location ) {
  32. return EFI_PCI_ADDRESS ( pci->bus, PCI_SLOT ( pci->devfn ),
  33. PCI_FUNC ( pci->devfn ),
  34. EFIPCI_OFFSET ( location ) );
  35. }
  36. int efipci_read ( struct pci_device *pci, unsigned long location,
  37. void *value ) {
  38. EFI_STATUS efirc;
  39. if ( ( efirc = efipci->Pci.Read ( efipci, EFIPCI_WIDTH ( location ),
  40. efipci_address ( pci, location ), 1,
  41. value ) ) != 0 ) {
  42. DBG ( "EFIPCI config read from %02x:%02x.%x offset %02lx "
  43. "failed: %s\n", pci->bus, PCI_SLOT ( pci->devfn ),
  44. PCI_FUNC ( pci->devfn ), EFIPCI_OFFSET ( location ),
  45. efi_strerror ( efirc ) );
  46. return -EIO;
  47. }
  48. return 0;
  49. }
  50. int efipci_write ( struct pci_device *pci, unsigned long location,
  51. unsigned long value ) {
  52. EFI_STATUS efirc;
  53. if ( ( efirc = efipci->Pci.Write ( efipci, EFIPCI_WIDTH ( location ),
  54. efipci_address ( pci, location ), 1,
  55. &value ) ) != 0 ) {
  56. DBG ( "EFIPCI config write to %02x:%02x.%x offset %02lx "
  57. "failed: %s\n", pci->bus, PCI_SLOT ( pci->devfn ),
  58. PCI_FUNC ( pci->devfn ), EFIPCI_OFFSET ( location ),
  59. efi_strerror ( efirc ) );
  60. return -EIO;
  61. }
  62. return 0;
  63. }
  64. PROVIDE_PCIAPI_INLINE ( efi, pci_max_bus );
  65. PROVIDE_PCIAPI_INLINE ( efi, pci_read_config_byte );
  66. PROVIDE_PCIAPI_INLINE ( efi, pci_read_config_word );
  67. PROVIDE_PCIAPI_INLINE ( efi, pci_read_config_dword );
  68. PROVIDE_PCIAPI_INLINE ( efi, pci_write_config_byte );
  69. PROVIDE_PCIAPI_INLINE ( efi, pci_write_config_word );
  70. PROVIDE_PCIAPI_INLINE ( efi, pci_write_config_dword );