iPXE
Data Structures | Functions
efi_pci.h File Reference

EFI driver interface. More...

#include <ipxe/pci.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/Protocol/PciIo.h>

Go to the source code of this file.

Data Structures

struct  efi_pci_device
 An EFI PCI device. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static EFIAPI uint64_t LShiftU64 (UINT64 value, UINTN shift)
 
int efipci_open (EFI_HANDLE device, UINT32 attributes, struct efi_pci_device *efipci)
 Open EFI PCI device. More...
 
void efipci_close (EFI_HANDLE device)
 Close EFI PCI device. More...
 
int efipci_info (EFI_HANDLE device, struct efi_pci_device *efipci)
 Get EFI PCI device information. More...
 

Detailed Description

EFI driver interface.

Definition in file efi_pci.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ LShiftU64()

static EFIAPI uint64_t LShiftU64 ( UINT64  value,
UINTN  shift 
)
inlinestatic

Definition at line 16 of file efi_pci.h.

16  {
17  return ( value << shift );
18 }
pseudo_bit_t value[0x00020]
Definition: arbel.h:13

References value.

◆ efipci_open()

int efipci_open ( EFI_HANDLE  device,
UINT32  attributes,
struct efi_pci_device efipci 
)

Open EFI PCI device.

Parameters
deviceEFI device handle
attributesProtocol opening attributes
efipciEFI PCI device to fill in
Return values
rcReturn status code

Definition at line 668 of file efi_pci.c.

669  {
671  union {
672  EFI_PCI_IO_PROTOCOL *pci_io;
673  void *interface;
674  } pci_io;
675  UINTN pci_segment, pci_bus, pci_dev, pci_fn;
676  unsigned int busdevfn;
677  EFI_STATUS efirc;
678  int rc;
679 
680  /* See if device is a PCI device */
681  if ( ( efirc = bs->OpenProtocol ( device, &efi_pci_io_protocol_guid,
682  &pci_io.interface, efi_image_handle,
683  device, attributes ) ) != 0 ) {
684  rc = -EEFI_PCI ( efirc );
685  DBGCP ( device, "EFIPCI %s cannot open PCI protocols: %s\n",
686  efi_handle_name ( device ), strerror ( rc ) );
687  goto err_open_protocol;
688  }
689  efipci->io = pci_io.pci_io;
690 
691  /* Get PCI bus:dev.fn address */
692  if ( ( efirc = pci_io.pci_io->GetLocation ( pci_io.pci_io, &pci_segment,
693  &pci_bus, &pci_dev,
694  &pci_fn ) ) != 0 ) {
695  rc = -EEFI ( efirc );
696  DBGC ( device, "EFIPCI %s could not get PCI location: %s\n",
697  efi_handle_name ( device ), strerror ( rc ) );
698  goto err_get_location;
699  }
700  busdevfn = PCI_BUSDEVFN ( pci_segment, pci_bus, pci_dev, pci_fn );
701  pci_init ( &efipci->pci, busdevfn );
702  dma_init ( &efipci->pci.dma, &efipci_dma_operations );
703  DBGCP ( device, "EFIPCI " PCI_FMT " is %s\n",
704  PCI_ARGS ( &efipci->pci ), efi_handle_name ( device ) );
705 
706  /* Try to enable I/O cycles, memory cycles, and bus mastering.
707  * Some platforms will 'helpfully' report errors if these bits
708  * can't be enabled (for example, if the card doesn't actually
709  * support I/O cycles). Work around any such platforms by
710  * enabling bits individually and simply ignoring any errors.
711  */
712  pci_io.pci_io->Attributes ( pci_io.pci_io,
715  pci_io.pci_io->Attributes ( pci_io.pci_io,
718  pci_io.pci_io->Attributes ( pci_io.pci_io,
721 
722  /* Populate PCI device */
723  if ( ( rc = pci_read_config ( &efipci->pci ) ) != 0 ) {
724  DBGC ( device, "EFIPCI " PCI_FMT " cannot read PCI "
725  "configuration: %s\n",
726  PCI_ARGS ( &efipci->pci ), strerror ( rc ) );
727  goto err_pci_read_config;
728  }
729 
730  return 0;
731 
732  err_pci_read_config:
733  err_get_location:
736  err_open_protocol:
737  return rc;
738 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2081
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct dma_device dma
DMA device.
Definition: pci.h:210
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:171
struct pci_device pci
PCI device.
Definition: efi_pci.h:23
EFI_GUID efi_pci_io_protocol_guid
PCI I/O protocol GUID.
Definition: efi_guid.c:283
static __always_inline void dma_init(struct dma_device *dma, struct dma_operations *op)
Initialise DMA device.
Definition: dma.h:461
#define DBGC(...)
Definition: compiler.h:505
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1987
uint16_t busdevfn
PCI bus:dev.fn address.
Definition: ena.h:28
A hardware device.
Definition: device.h:73
#define EFI_PCI_IO_ATTRIBUTE_MEMORY
Enable the Memory decode bit in the PCI Config Header.
Definition: PciIo.h:60
An object interface.
Definition: interface.h:124
#define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER
Enable the DMA bit in the PCI Config Header.
Definition: PciIo.h:61
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:808
#define PCI_BUSDEVFN(segment, bus, slot, func)
Definition: pci_io.h:28
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1917
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:307
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:34
int pci_read_config(struct pci_device *pci)
Read PCI device configuration.
Definition: pci.c:182
UINT64 UINTN
Unsigned value of native width.
#define EFI_PCI_IO_ATTRIBUTE_IO
Enable the I/O decode bit in the PCI Config Header.
Definition: PciIo.h:59
Enable the attributes specified by the bits that are set in Attributes for this PCI controller.
Definition: PciIo.h:113
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
Definition: efi_pci.h:25
#define EEFI_PCI(efirc)
Definition: efi_pci.c:54
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:310
#define DBGCP(...)
Definition: compiler.h:539
EFI_SYSTEM_TABLE * efi_systab
static struct dma_operations efipci_dma_operations
EFI PCI DMA operations.
Definition: efi_pci.c:643
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1986
static void pci_init(struct pci_device *pci, unsigned int busdevfn)
Initialise PCI device.
Definition: pci.h:334
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
Definition: PciIo.h:518
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References EFI_SYSTEM_TABLE::BootServices, busdevfn, EFI_BOOT_SERVICES::CloseProtocol, DBGC, DBGCP, pci_device::dma, dma_init(), EEFI, EEFI_PCI, efi_handle_name(), efi_image_handle, EFI_PCI_IO_ATTRIBUTE_BUS_MASTER, EFI_PCI_IO_ATTRIBUTE_IO, EFI_PCI_IO_ATTRIBUTE_MEMORY, efi_pci_io_protocol_guid, efi_systab, efipci_dma_operations, EfiPciIoAttributeOperationEnable, efi_pci_device::io, NULL, EFI_BOOT_SERVICES::OpenProtocol, efi_pci_device::pci, PCI_ARGS, PCI_BUSDEVFN, PCI_FMT, pci_init(), pci_read_config(), rc, and strerror().

Referenced by efi_bofm_start(), efipci_info(), and efipci_start().

◆ efipci_close()

void efipci_close ( EFI_HANDLE  device)

Close EFI PCI device.

Parameters
deviceEFI device handle

Definition at line 745 of file efi_pci.c.

745  {
747 
750 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2081
EFI_GUID efi_pci_io_protocol_guid
PCI I/O protocol GUID.
Definition: efi_guid.c:283
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1987
A hardware device.
Definition: device.h:73
EFI Boot Services Table.
Definition: UefiSpec.h:1917
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:34
EFI_SYSTEM_TABLE * efi_systab

References EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, efi_image_handle, efi_pci_io_protocol_guid, and efi_systab.

Referenced by efi_bofm_start(), efipci_info(), efipci_start(), and efipci_stop().

◆ efipci_info()

int efipci_info ( EFI_HANDLE  device,
struct efi_pci_device efipci 
)

Get EFI PCI device information.

Parameters
deviceEFI device handle
efipciEFI PCI device to fill in
Return values
rcReturn status code

Definition at line 759 of file efi_pci.c.

759  {
760  int rc;
761 
762  /* Open PCI device, if possible */
764  efipci ) ) != 0 )
765  return rc;
766 
767  /* Close PCI device */
768  efipci_close ( device );
769 
770  return 0;
771 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int efipci_open(EFI_HANDLE device, UINT32 attributes, struct efi_pci_device *efipci)
Open EFI PCI device.
Definition: efi_pci.c:668
A hardware device.
Definition: device.h:73
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
Definition: UefiSpec.h:1344
void efipci_close(EFI_HANDLE device)
Close EFI PCI device.
Definition: efi_pci.c:745

References EFI_OPEN_PROTOCOL_GET_PROTOCOL, efipci_close(), efipci_open(), and rc.

Referenced by efi_bofm_supported(), efi_pci_info(), and efipci_supported().