iPXE
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.

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 pci_device *pci)
 Open EFI PCI device.
void efipci_close (EFI_HANDLE device)
 Close EFI PCI device.
int efipci_info (EFI_HANDLE device, struct pci_device *pci)
 Get EFI PCI device information.

Detailed Description

EFI driver interface.

Definition in file efi_pci.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static EFIAPI uint64_t LShiftU64 ( UINT64  value,
UINTN  shift 
) [inline, static]

Definition at line 16 of file efi_pci.h.

                                                                      {
        return ( value << shift );
}
int efipci_open ( EFI_HANDLE  device,
UINT32  attributes,
struct pci_device pci 
)

Open EFI PCI device.

Parameters:
deviceEFI device handle
attributesProtocol opening attributes
pciPCI device to fill in
Return values:
rcReturn status code

Definition at line 241 of file efi_pci.c.

References EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, DBGC, DBGCP, 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, EfiPciIoAttributeOperationEnable, NULL, EFI_BOOT_SERVICES::OpenProtocol, PCI_ARGS, PCI_BUSDEVFN, PCI_FMT, pci_init(), pci_read_config(), rc, and strerror().

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

                                           {
        EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
        union {
                EFI_PCI_IO_PROTOCOL *pci_io;
                void *interface;
        } pci_io;
        UINTN pci_segment, pci_bus, pci_dev, pci_fn;
        unsigned int busdevfn;
        EFI_STATUS efirc;
        int rc;

        /* See if device is a PCI device */
        if ( ( efirc = bs->OpenProtocol ( device, &efi_pci_io_protocol_guid,
                                          &pci_io.interface, efi_image_handle,
                                          device, attributes ) ) != 0 ) {
                rc = -EEFI_PCI ( efirc );
                DBGCP ( device, "EFIPCI %s cannot open PCI protocols: %s\n",
                        efi_handle_name ( device ), strerror ( rc ) );
                goto err_open_protocol;
        }

        /* Get PCI bus:dev.fn address */
        if ( ( efirc = pci_io.pci_io->GetLocation ( pci_io.pci_io, &pci_segment,
                                                    &pci_bus, &pci_dev,
                                                    &pci_fn ) ) != 0 ) {
                rc = -EEFI ( efirc );
                DBGC ( device, "EFIPCI %s could not get PCI location: %s\n",
                       efi_handle_name ( device ), strerror ( rc ) );
                goto err_get_location;
        }
        busdevfn = PCI_BUSDEVFN ( pci_segment, pci_bus, pci_dev, pci_fn );
        pci_init ( pci, busdevfn );
        DBGCP ( device, "EFIPCI " PCI_FMT " is %s\n",
                PCI_ARGS ( pci ), efi_handle_name ( device ) );

        /* Try to enable I/O cycles, memory cycles, and bus mastering.
         * Some platforms will 'helpfully' report errors if these bits
         * can't be enabled (for example, if the card doesn't actually
         * support I/O cycles).  Work around any such platforms by
         * enabling bits individually and simply ignoring any errors.
         */
        pci_io.pci_io->Attributes ( pci_io.pci_io,
                                    EfiPciIoAttributeOperationEnable,
                                    EFI_PCI_IO_ATTRIBUTE_IO, NULL );
        pci_io.pci_io->Attributes ( pci_io.pci_io,
                                    EfiPciIoAttributeOperationEnable,
                                    EFI_PCI_IO_ATTRIBUTE_MEMORY, NULL );
        pci_io.pci_io->Attributes ( pci_io.pci_io,
                                    EfiPciIoAttributeOperationEnable,
                                    EFI_PCI_IO_ATTRIBUTE_BUS_MASTER, NULL );

        /* Populate PCI device */
        if ( ( rc = pci_read_config ( pci ) ) != 0 ) {
                DBGC ( device, "EFIPCI " PCI_FMT " cannot read PCI "
                       "configuration: %s\n",
                       PCI_ARGS ( pci ), strerror ( rc ) );
                goto err_pci_read_config;
        }

        return 0;

 err_pci_read_config:
 err_get_location:
        bs->CloseProtocol ( device, &efi_pci_io_protocol_guid,
                            efi_image_handle, device );
 err_open_protocol:
        return rc;
}
void efipci_close ( EFI_HANDLE  device)

Close EFI PCI device.

Parameters:
deviceEFI device handle

Definition at line 316 of file efi_pci.c.

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().

int efipci_info ( EFI_HANDLE  device,
struct pci_device pci 
)

Get EFI PCI device information.

Parameters:
deviceEFI device handle
pciPCI device to fill in
Return values:
rcReturn status code

Definition at line 330 of file efi_pci.c.

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

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

                                                              {
        int rc;

        /* Open PCI device, if possible */
        if ( ( rc = efipci_open ( device, EFI_OPEN_PROTOCOL_GET_PROTOCOL,
                                  pci ) ) != 0 )
                return rc;

        /* Close PCI device */
        efipci_close ( device );

        return 0;
}