2 * Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
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.
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.
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.
19 FILE_LICENCE ( GPL2_OR_LATER
);
23 #include <gpxe/efi/efi.h>
24 #include <gpxe/efi/Protocol/PciRootBridgeIo.h>
28 * gPXE PCI I/O API for EFI
32 /** PCI root bridge I/O protocol */
33 static EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*efipci
;
34 EFI_REQUIRE_PROTOCOL ( EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
, &efipci
);
36 static unsigned long efipci_address ( struct pci_device
*pci
,
37 unsigned long location
) {
38 return EFI_PCI_ADDRESS ( pci
->bus
, PCI_SLOT ( pci
->devfn
),
39 PCI_FUNC ( pci
->devfn
),
40 EFIPCI_OFFSET ( location
) );
43 int efipci_read ( struct pci_device
*pci
, unsigned long location
,
47 if ( ( efirc
= efipci
->Pci
.Read ( efipci
, EFIPCI_WIDTH ( location
),
48 efipci_address ( pci
, location
), 1,
50 DBG ( "EFIPCI config read from %02x:%02x.%x offset %02lx "
51 "failed: %s\n", pci
->bus
, PCI_SLOT ( pci
->devfn
),
52 PCI_FUNC ( pci
->devfn
), EFIPCI_OFFSET ( location
),
53 efi_strerror ( efirc
) );
60 int efipci_write ( struct pci_device
*pci
, unsigned long location
,
61 unsigned long value
) {
64 if ( ( efirc
= efipci
->Pci
.Write ( efipci
, EFIPCI_WIDTH ( location
),
65 efipci_address ( pci
, location
), 1,
67 DBG ( "EFIPCI config write to %02x:%02x.%x offset %02lx "
68 "failed: %s\n", pci
->bus
, PCI_SLOT ( pci
->devfn
),
69 PCI_FUNC ( pci
->devfn
), EFIPCI_OFFSET ( location
),
70 efi_strerror ( efirc
) );
77 PROVIDE_PCIAPI_INLINE ( efi
, pci_max_bus
);
78 PROVIDE_PCIAPI_INLINE ( efi
, pci_read_config_byte
);
79 PROVIDE_PCIAPI_INLINE ( efi
, pci_read_config_word
);
80 PROVIDE_PCIAPI_INLINE ( efi
, pci_read_config_dword
);
81 PROVIDE_PCIAPI_INLINE ( efi
, pci_write_config_byte
);
82 PROVIDE_PCIAPI_INLINE ( efi
, pci_write_config_word
);
83 PROVIDE_PCIAPI_INLINE ( efi
, pci_write_config_dword
);