iPXE
Functions
efi_utils.h File Reference

EFI utilities. More...

#include <ipxe/efi/efi.h>
#include <ipxe/efi/Protocol/DevicePath.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
EFI_DEVICE_PATH_PROTOCOLefi_devpath_end (EFI_DEVICE_PATH_PROTOCOL *path)
 Find end of device path.
size_t efi_devpath_len (EFI_DEVICE_PATH_PROTOCOL *path)
 Find length of device path (excluding terminator)
int efi_locate_device (EFI_HANDLE device, EFI_GUID *protocol, EFI_HANDLE *parent)
 Locate parent device supporting a given protocol.
int efi_child_add (EFI_HANDLE parent, EFI_HANDLE child)
 Add EFI device as child of another EFI device.
void efi_child_del (EFI_HANDLE parent, EFI_HANDLE child)
 Remove EFI device as child of another EFI device.
void efi_device_info (EFI_HANDLE device, const char *prefix, struct device *dev)
 Get underlying device information.

Detailed Description

EFI utilities.

Definition in file efi_utils.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

Find end of device path.

Parameters:
pathPath to device
Return values:
path_endEnd of device path

Definition at line 41 of file efi_utils.c.

References END_DEVICE_PATH_TYPE, EFI_DEVICE_PATH_PROTOCOL::Length, and EFI_DEVICE_PATH_PROTOCOL::Type.

Referenced by efi_block_boot_image(), efi_devpath_len(), and usbio_open().

                                                                              {

        while ( path->Type != END_DEVICE_PATH_TYPE ) {
                path = ( ( ( void * ) path ) +
                         /* There's this amazing new-fangled thing known as
                          * a UINT16, but who wants to use one of those? */
                         ( ( path->Length[1] << 8 ) | path->Length[0] ) );
        }

        return path;
}

Find length of device path (excluding terminator)

Parameters:
pathPath to device
Return values:
path_lenLength of device path

Definition at line 59 of file efi_utils.c.

References efi_devpath_end(), and end.

Referenced by efi_block_boot_image(), efi_block_hook(), efi_devpath_text(), efi_driver_start(), efi_image_path(), efi_local_open_path(), efi_snp_hii_install(), efi_snp_probe(), efi_usb_install(), and usbio_path().

                                                          {
        EFI_DEVICE_PATH_PROTOCOL *end = efi_devpath_end ( path );

        return ( ( ( void * ) end ) - ( ( void * ) path ) );
}
int efi_locate_device ( EFI_HANDLE  device,
EFI_GUID protocol,
EFI_HANDLE parent 
)

Locate parent device supporting a given protocol.

Parameters:
deviceEFI device handle
protocolProtocol GUID
parentParent EFI device handle to fill in
Return values:
rcReturn status code

Definition at line 73 of file efi_utils.c.

References EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, DBGC, EEFI, efi_device_path_protocol_guid, efi_guid_ntoa(), efi_handle_name(), efi_image_handle, EFI_OPEN_PROTOCOL_GET_PROTOCOL, efi_systab, EFI_BOOT_SERVICES::LocateDevicePath, EFI_BOOT_SERVICES::OpenProtocol, rc, and strerror().

Referenced by chained_locate(), efi_pci_info(), and nii_pci_open().

                                             {
        EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
        union {
                EFI_DEVICE_PATH_PROTOCOL *path;
                void *interface;
        } path;
        EFI_DEVICE_PATH_PROTOCOL *devpath;
        EFI_STATUS efirc;
        int rc;

        /* Get device path */
        if ( ( efirc = bs->OpenProtocol ( device,
                                          &efi_device_path_protocol_guid,
                                          &path.interface,
                                          efi_image_handle, device,
                                          EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
                rc = -EEFI ( efirc );
                DBGC ( device, "EFIDEV %s cannot open device path: %s\n",
                       efi_handle_name ( device ), strerror ( rc ) );
                goto err_open_device_path;
        }
        devpath = path.path;

        /* Check for presence of specified protocol */
        if ( ( efirc = bs->LocateDevicePath ( protocol, &devpath,
                                              parent ) ) != 0 ) {
                rc = -EEFI ( efirc );
                DBGC ( device, "EFIDEV %s has no parent supporting %s: %s\n",
                       efi_handle_name ( device ),
                       efi_guid_ntoa ( protocol ), strerror ( rc ) );
                goto err_locate_protocol;
        }

        /* Success */
        rc = 0;

 err_locate_protocol:
        bs->CloseProtocol ( device, &efi_device_path_protocol_guid,
                            efi_image_handle, device );
 err_open_device_path:
        return rc;
}
int efi_child_add ( EFI_HANDLE  parent,
EFI_HANDLE  child 
)

Add EFI device as child of another EFI device.

Parameters:
parentEFI parent device handle
childEFI child device handle
Return values:
rcReturn status code

Definition at line 124 of file efi_utils.c.

References EFI_SYSTEM_TABLE::BootServices, DBGC, DBGC2, DBGC_EFI_OPENERS, EEFI, efi_device_path_protocol_guid, efi_handle_name(), efi_image_handle, EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER, efi_systab, EFI_BOOT_SERVICES::OpenProtocol, rc, and strerror().

Referenced by efi_snp_hii_install(), and efi_snp_probe().

                                                          {
        EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
        void *devpath;
        EFI_STATUS efirc;
        int rc;

        /* Re-open the device path protocol */
        if ( ( efirc = bs->OpenProtocol ( parent,
                                          &efi_device_path_protocol_guid,
                                          &devpath,
                                          efi_image_handle, child,
                                          EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
                                          ) ) != 0 ) {
                rc = -EEFI ( efirc );
                DBGC ( parent, "EFIDEV %s could not add child",
                       efi_handle_name ( parent ) );
                DBGC ( parent, " %s: %s\n",
                       efi_handle_name ( child ), strerror ( rc ) );
                DBGC_EFI_OPENERS ( parent, parent,
                                   &efi_device_path_protocol_guid );
                return rc;
        }

        DBGC2 ( parent, "EFIDEV %s added child", efi_handle_name ( parent ) );
        DBGC2 ( parent, " %s\n", efi_handle_name ( child ) );
        return 0;
}
void efi_child_del ( EFI_HANDLE  parent,
EFI_HANDLE  child 
)

Remove EFI device as child of another EFI device.

Parameters:
parentEFI parent device handle
childEFI child device handle

Definition at line 158 of file efi_utils.c.

References EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, DBGC2, efi_device_path_protocol_guid, efi_handle_name(), efi_image_handle, and efi_systab.

Referenced by efi_snp_hii_install(), efi_snp_hii_uninstall(), efi_snp_probe(), and efi_snp_remove().

                                                           {
        EFI_BOOT_SERVICES *bs = efi_systab->BootServices;

        bs->CloseProtocol ( parent, &efi_device_path_protocol_guid,
                            efi_image_handle, child );
        DBGC2 ( parent, "EFIDEV %s removed child", efi_handle_name ( parent ) );
        DBGC2 ( parent, " %s\n", efi_handle_name ( child ) );
}
void efi_device_info ( EFI_HANDLE  device,
const char *  prefix,
struct device dev 
)

Get underlying device information.

Parameters:
deviceEFI device handle
prefixDevice name prefix
devGeneric device to fill in

Definition at line 211 of file efi_utils.c.

References device_description::bus_type, BUS_TYPE_EFI, DBGC, device::desc, efi_handle_name(), efi_pci_info(), device::name, rc, and snprintf().

Referenced by nii_start(), snpnet_start(), and usbio_start().

                                            {
        int rc;

        /* Try getting underlying PCI device information */
        if ( ( rc = efi_pci_info ( device, prefix, dev ) ) == 0 )
                return;

        /* If we cannot get any underlying device information, fall
         * back to providing information about the EFI handle.
         */
        DBGC ( device, "EFIDEV %s could not get underlying device "
               "information\n", efi_handle_name ( device ) );
        dev->desc.bus_type = BUS_TYPE_EFI;
        snprintf ( dev->name, sizeof ( dev->name ), "%s-%p", prefix, device );
}