iPXE
Data Structures | Macros | Functions
efi_driver.h File Reference

EFI driver interface. More...

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

Go to the source code of this file.

Data Structures

struct  efi_device
 An EFI device. More...
 
struct  efi_driver
 An EFI driver. More...
 

Macros

#define EFI_DRIVERS   __table ( struct efi_driver, "efi_drivers" )
 EFI driver table. More...
 
#define __efi_driver(order)   __table_entry ( EFI_DRIVERS, order )
 Declare an EFI driver. More...
 
#define EFI_DRIVER_EARLY   01
 Early drivers. More...
 
#define EFI_DRIVER_HARDWARE   02
 Hardware drivers. More...
 
#define EFI_DRIVER_NII   03
 NII protocol drivers. More...
 
#define EFI_DRIVER_SNP   04
 SNP protocol drivers. More...
 
#define EFI_DRIVER_MNP   05
 MNP protocol drivers. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 FILE_SECBOOT (PERMITTED)
 
static void efidev_set_drvdata (struct efi_device *efidev, void *priv)
 Set EFI driver-private data. More...
 
static void * efidev_get_drvdata (struct efi_device *efidev)
 Get EFI driver-private data. More...
 
struct efi_deviceefidev_alloc (EFI_HANDLE device)
 Allocate new EFI device. More...
 
void efidev_free (struct efi_device *efidev)
 Free EFI device. More...
 
struct efi_deviceefidev_parent (struct device *dev)
 Get parent EFI device. More...
 
int efi_driver_install (void)
 Install EFI driver. More...
 
void efi_driver_uninstall (void)
 Uninstall EFI driver. More...
 
int efi_driver_exclude (EFI_HANDLE device, EFI_GUID *protocol)
 Try to disconnect an existing EFI driver. More...
 
int efi_driver_connect_all (void)
 Connect EFI driver to all possible devices. More...
 
void efi_driver_disconnect_all (void)
 Disconnect EFI driver from all possible devices. More...
 
void efi_driver_reconnect_all (void)
 Reconnect original EFI drivers to all possible devices. More...
 

Detailed Description

EFI driver interface.

Definition in file efi_driver.h.

Macro Definition Documentation

◆ EFI_DRIVERS

#define EFI_DRIVERS   __table ( struct efi_driver, "efi_drivers" )

EFI driver table.

Definition at line 67 of file efi_driver.h.

◆ __efi_driver

#define __efi_driver (   order)    __table_entry ( EFI_DRIVERS, order )

Declare an EFI driver.

Definition at line 70 of file efi_driver.h.

◆ EFI_DRIVER_EARLY

#define EFI_DRIVER_EARLY   01

Early drivers.

Definition at line 72 of file efi_driver.h.

◆ EFI_DRIVER_HARDWARE

#define EFI_DRIVER_HARDWARE   02

Hardware drivers.

Definition at line 73 of file efi_driver.h.

◆ EFI_DRIVER_NII

#define EFI_DRIVER_NII   03

NII protocol drivers.

Definition at line 74 of file efi_driver.h.

◆ EFI_DRIVER_SNP

#define EFI_DRIVER_SNP   04

SNP protocol drivers.

Definition at line 75 of file efi_driver.h.

◆ EFI_DRIVER_MNP

#define EFI_DRIVER_MNP   05

MNP protocol drivers.

Definition at line 76 of file efi_driver.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ efidev_set_drvdata()

static void efidev_set_drvdata ( struct efi_device efidev,
void *  priv 
)
inlinestatic

Set EFI driver-private data.

Parameters
efidevEFI device
privPrivate data

Definition at line 84 of file efi_driver.h.

85  {
86  efidev->priv = priv;
87 }
void * priv
Driver-private data.
Definition: efi_driver.h:30
static struct tlan_private * priv
Definition: tlan.c:225

References efi_device::priv, and priv.

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

◆ efidev_get_drvdata()

static void* efidev_get_drvdata ( struct efi_device efidev)
inlinestatic

Get EFI driver-private data.

Parameters
efidevEFI device
Return values
privPrivate data

Definition at line 95 of file efi_driver.h.

95  {
96  return efidev->priv;
97 }
void * priv
Driver-private data.
Definition: efi_driver.h:30

References efi_device::priv.

Referenced by efipci_stop(), mnpnet_stop(), mnptemp_create(), nii_stop(), snpnet_stop(), and usbio_stop().

◆ efidev_alloc()

struct efi_device* efidev_alloc ( EFI_HANDLE  device)

Allocate new EFI device.

Parameters
deviceEFI device handle
Return values
efidevEFI device, or NULL on error

Definition at line 57 of file efi_driver.c.

57  {
58  struct efi_device *efidev = NULL;
60  EFI_DEVICE_PATH_PROTOCOL *path_end;
61  size_t path_len;
62  int rc;
63 
64  /* Open device path */
66  &path ) ) != 0 ) {
67  DBGC ( device, "EFIDRV %s could not open device path: %s\n",
68  efi_handle_name ( device ), strerror ( rc ) );
69  return NULL;
70  }
71  path_len = ( efi_path_len ( path ) + sizeof ( *path_end ) );
72 
73  /* Allocate and initialise structure */
74  efidev = zalloc ( sizeof ( *efidev ) + path_len );
75  if ( ! efidev )
76  return NULL;
77  efidev->device = device;
78  efidev->dev.desc.bus_type = BUS_TYPE_EFI;
79  efidev->path = ( ( ( void * ) efidev ) + sizeof ( *efidev ) );
80  memcpy ( efidev->path, path, path_len );
81  INIT_LIST_HEAD ( &efidev->dev.children );
82  list_add ( &efidev->dev.siblings, &efi_devices );
83 
84  return efidev;
85 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:70
#define DBGC(...)
Definition: compiler.h:505
size_t efi_path_len(EFI_DEVICE_PATH_PROTOCOL *path)
Find length of device path (excluding terminator)
Definition: efi_path.c:174
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:22
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:46
uint16_t device
Device ID.
Definition: ena.h:24
A hardware device.
Definition: device.h:77
void * memcpy(void *dest, const void *src, size_t len) __nonnull
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:652
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:662
struct list_head siblings
Devices on the same bus.
Definition: device.h:85
#define efi_open(handle, protocol, interface)
Open protocol for ephemeral use.
Definition: efi.h:444
An EFI device.
Definition: efi_driver.h:18
EFI_GUID efi_device_path_protocol_guid
Device path protocol GUID.
Definition: efi_guid.c:169
#define BUS_TYPE_EFI
EFI bus type.
Definition: device.h:62
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:46
unsigned int bus_type
Bus type.
Definition: device.h:25
struct list_head children
Devices attached to this device.
Definition: device.h:87
struct device_description desc
Device description.
Definition: device.h:83
EFI_DEVICE_PATH_PROTOCOL * path
EFI device path copy.
Definition: efi_driver.h:26
struct device dev
Generic device.
Definition: efi_driver.h:20
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References device_description::bus_type, BUS_TYPE_EFI, device::children, DBGC, device::desc, efi_device::dev, efi_device::device, device, efi_device_path_protocol_guid, efi_handle_name(), efi_open, efi_path_len(), INIT_LIST_HEAD, list_add, memcpy(), NULL, efi_device::path, rc, device::siblings, strerror(), and zalloc().

Referenced by efi_driver_start(), and mnptemp_create().

◆ efidev_free()

void efidev_free ( struct efi_device efidev)

Free EFI device.

Parameters
efidevEFI device

Definition at line 92 of file efi_driver.c.

92  {
93 
94  assert ( list_empty ( &efidev->dev.children ) );
95  list_del ( &efidev->dev.siblings );
96  free ( efidev );
97 }
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:137
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
struct list_head siblings
Devices on the same bus.
Definition: device.h:85
struct list_head children
Devices attached to this device.
Definition: device.h:87
struct device dev
Generic device.
Definition: efi_driver.h:20

References assert(), device::children, efi_device::dev, free, list_del, list_empty, and device::siblings.

Referenced by efi_driver_start(), efi_driver_stop(), mnptemp_create(), and mnptemp_destroy().

◆ efidev_parent()

struct efi_device* efidev_parent ( struct device dev)

Get parent EFI device.

Parameters
devGeneric device
Return values
efidevParent EFI device, or NULL

Definition at line 129 of file efi_driver.c.

129  {
130  struct device *parent;
131  struct efi_device *efidev;
132 
133  /* Walk upwards until we find a registered EFI device */
134  while ( ( parent = dev->parent ) ) {
135  list_for_each_entry ( efidev, &efi_devices, dev.siblings ) {
136  if ( parent == &efidev->dev )
137  return efidev;
138  }
139  dev = parent;
140  }
141 
142  return NULL;
143 }
struct device * parent
Bus device.
Definition: device.h:89
A hardware device.
Definition: device.h:77
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:432
struct list_head siblings
Devices on the same bus.
Definition: device.h:85
An EFI device.
Definition: efi_driver.h:18
struct device dev
Generic device.
Definition: efi_driver.h:20
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References efi_device::dev, list_for_each_entry, NULL, device::parent, and device::siblings.

Referenced by efi_parent_path(), and efi_snp_probe().

◆ efi_driver_install()

int efi_driver_install ( void  )

Install EFI driver.

Return values
rcReturn status code

Definition at line 388 of file efi_driver.c.

388  {
390  EFI_STATUS efirc;
391  int rc;
392 
393  /* Calculate driver version number. We use the build
394  * timestamp (in seconds since the Epoch) shifted right by six
395  * bits: this gives us an approximately one-minute resolution
396  * and a scheme which will last until the year 10680.
397  */
399 
400  /* Install protocols on image handle */
403  if ( ( efirc = bs->InstallMultipleProtocolInterfaces (
407  NULL ) ) != 0 ) {
408  rc = -EEFI ( efirc );
409  DBGC ( &efi_driver_binding, "EFIDRV could not install "
410  "protocols: %s\n", strerror ( rc ) );
411  return rc;
412  }
413 
414  return 0;
415 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2099
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:175
#define DBGC(...)
Definition: compiler.h:505
EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES InstallMultipleProtocolInterfaces
Definition: UefiSpec.h:2010
unsigned long build_timestamp
Build timestamp.
Definition: version.c:59
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
EFI Boot Services Table.
Definition: UefiSpec.h:1931
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:36
EFI_HANDLE DriverBindingHandle
The handle on which this instance of the EFI_DRIVER_BINDING_PROTOCOL is installed.
EFI_GUID efi_component_name2_protocol_guid
Component name 2 protocol GUID.
Definition: efi_guid.c:161
EFI_HANDLE ImageHandle
The image handle of the UEFI driver that produced this instance of the EFI_DRIVER_BINDING_PROTOCOL.
static EFI_DRIVER_BINDING_PROTOCOL efi_driver_binding
EFI driver binding protocol.
Definition: efi_driver.c:43
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:32
EFI_SYSTEM_TABLE * efi_systab
static EFI_COMPONENT_NAME2_PROTOCOL efi_wtf
EFI component name protocol.
Definition: efi_driver.c:377
EFI_GUID efi_driver_binding_protocol_guid
Driver binding protocol GUID.
Definition: efi_guid.c:209
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
UINT32 Version
The version number of the UEFI driver that produced the EFI_DRIVER_BINDING_PROTOCOL.

References EFI_SYSTEM_TABLE::BootServices, build_timestamp, DBGC, _EFI_DRIVER_BINDING_PROTOCOL::DriverBindingHandle, EEFI, efi_component_name2_protocol_guid, efi_driver_binding, efi_driver_binding_protocol_guid, efi_image_handle, efi_systab, efi_wtf, _EFI_DRIVER_BINDING_PROTOCOL::ImageHandle, EFI_BOOT_SERVICES::InstallMultipleProtocolInterfaces, NULL, rc, strerror(), and _EFI_DRIVER_BINDING_PROTOCOL::Version.

Referenced by efi_init().

◆ efi_driver_uninstall()

void efi_driver_uninstall ( void  )

Uninstall EFI driver.

Definition at line 421 of file efi_driver.c.

421  {
423 
424  /* Uninstall protocols */
429 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2099
EFI Boot Services Table.
Definition: UefiSpec.h:1931
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:36
EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces
Definition: UefiSpec.h:2011
EFI_GUID efi_component_name2_protocol_guid
Component name 2 protocol GUID.
Definition: efi_guid.c:161
static EFI_DRIVER_BINDING_PROTOCOL efi_driver_binding
EFI driver binding protocol.
Definition: efi_driver.c:43
EFI_SYSTEM_TABLE * efi_systab
static EFI_COMPONENT_NAME2_PROTOCOL efi_wtf
EFI component name protocol.
Definition: efi_driver.c:377
EFI_GUID efi_driver_binding_protocol_guid
Driver binding protocol GUID.
Definition: efi_guid.c:209
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References EFI_SYSTEM_TABLE::BootServices, efi_component_name2_protocol_guid, efi_driver_binding, efi_driver_binding_protocol_guid, efi_image_handle, efi_systab, efi_wtf, NULL, and EFI_BOOT_SERVICES::UninstallMultipleProtocolInterfaces.

Referenced by efi_init(), and efi_unload().

◆ efi_driver_exclude()

int efi_driver_exclude ( EFI_HANDLE  device,
EFI_GUID protocol 
)

Try to disconnect an existing EFI driver.

Parameters
deviceEFI device
protocolProtocol GUID
Return values
rcReturn status code

Definition at line 438 of file efi_driver.c.

438  {
443  UINTN count;
444  unsigned int i;
445  EFI_STATUS efirc;
446  int rc;
447 
448  /* Retrieve list of openers */
449  if ( ( efirc = bs->OpenProtocolInformation ( device, protocol, &openers,
450  &count ) ) != 0 ) {
451  rc = -EEFI ( efirc );
452  DBGC ( device, "EFIDRV %s could not list %s openers: %s\n",
454  strerror ( rc ) );
455  goto err_list;
456  }
457 
458  /* Identify BY_DRIVER opener */
459  driver = NULL;
460  for ( i = 0 ; i < count ; i++ ) {
461  opener = &openers[i];
462  if ( opener->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER ) {
463  driver = opener->AgentHandle;
464  break;
465  }
466  }
467 
468  /* Try to disconnect driver */
469  DBGC ( device, "EFIDRV %s disconnecting %s drivers\n",
471  if ( driver ) {
472  DBGC ( device, "EFIDRV %s disconnecting %s driver ",
474  DBGC ( device, "%s\n", efi_handle_name ( driver ) );
475  if ( ( rc = efi_disconnect ( device, driver ) ) != 0 ) {
476  DBGC ( device, "EFIDRV %s could not disconnect ",
477  efi_handle_name ( device ) );
478  DBGC ( device, "%s: %s\n",
479  efi_handle_name ( driver ), strerror ( rc ) );
480  goto err_disconnect;
481  }
482  }
483 
484  /* Success */
485  rc = 0;
486 
487  err_disconnect:
488  bs->FreePool ( openers );
489  err_list:
490  return rc;
491 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2099
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
EFI Oprn Protocol Information Entry.
Definition: UefiSpec.h:1432
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:175
struct efi_driver * driver
Driver for this device.
Definition: efi_driver.h:28
EFI_HANDLE AgentHandle
Definition: UefiSpec.h:1433
#define DBGC(...)
Definition: compiler.h:505
#define EFI_OPEN_PROTOCOL_BY_DRIVER
Definition: UefiSpec.h:1358
A hardware device.
Definition: device.h:77
UINT32 Attributes
Definition: UefiSpec.h:1435
static unsigned int count
Number of entries.
Definition: dwmac.h:225
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:652
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
EFI Boot Services Table.
Definition: UefiSpec.h:1931
UINT64 UINTN
Unsigned value of native width.
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
Definition: efi_guid.c:726
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1950
EFI_OPEN_PROTOCOL_INFORMATION OpenProtocolInformation
Definition: UefiSpec.h:2002
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:32
EFI_SYSTEM_TABLE * efi_systab
uint16_t protocol
Protocol ID.
Definition: stp.h:19
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
Definition: efi.h:62
int efi_disconnect(EFI_HANDLE device, EFI_HANDLE driver)
Disconnect UEFI driver(s)
Definition: efi_connect.c:90

References EFI_OPEN_PROTOCOL_INFORMATION_ENTRY::AgentHandle, EFI_OPEN_PROTOCOL_INFORMATION_ENTRY::Attributes, EFI_SYSTEM_TABLE::BootServices, count, DBGC, EEFI, efi_disconnect(), efi_guid_ntoa(), efi_handle_name(), EFI_OPEN_PROTOCOL_BY_DRIVER, efi_systab, EFI_BOOT_SERVICES::FreePool, NULL, EFI_BOOT_SERVICES::OpenProtocolInformation, protocol, rc, and strerror().

Referenced by efipci_exclude(), nii_exclude(), snpnet_exclude(), and usbio_exclude().

◆ efi_driver_connect_all()

int efi_driver_connect_all ( void  )

Connect EFI driver to all possible devices.

Return values
rcReturn status code

Definition at line 637 of file efi_driver.c.

637  {
638 
639  DBGC ( &efi_driver_binding, "EFIDRV connecting our drivers\n" );
641 }
static int efi_driver_connect(EFI_HANDLE device)
Try to connect EFI driver.
Definition: efi_driver.c:499
#define DBGC(...)
Definition: compiler.h:505
static int efi_driver_handles(int(*method)(EFI_HANDLE handle))
Connect/disconnect EFI driver from all handles.
Definition: efi_driver.c:597
static EFI_DRIVER_BINDING_PROTOCOL efi_driver_binding
EFI driver binding protocol.
Definition: efi_driver.c:43

References DBGC, efi_driver_binding, efi_driver_connect(), and efi_driver_handles().

Referenced by efi_probe().

◆ efi_driver_disconnect_all()

void efi_driver_disconnect_all ( void  )

Disconnect EFI driver from all possible devices.

Return values
rcReturn status code

Definition at line 648 of file efi_driver.c.

648  {
649 
650  DBGC ( &efi_driver_binding, "EFIDRV disconnecting our drivers\n" );
652 }
#define DBGC(...)
Definition: compiler.h:505
static int efi_driver_handles(int(*method)(EFI_HANDLE handle))
Connect/disconnect EFI driver from all handles.
Definition: efi_driver.c:597
static EFI_DRIVER_BINDING_PROTOCOL efi_driver_binding
EFI driver binding protocol.
Definition: efi_driver.c:43
static int efi_driver_disconnect(EFI_HANDLE device)
Try to disconnect EFI driver.
Definition: efi_driver.c:566

References DBGC, efi_driver_binding, efi_driver_disconnect(), and efi_driver_handles().

Referenced by efi_remove(), and efi_unload().

◆ efi_driver_reconnect_all()

void efi_driver_reconnect_all ( void  )

Reconnect original EFI drivers to all possible devices.

Return values
rcReturn status code

Definition at line 659 of file efi_driver.c.

659  {
660 
661  DBGC ( &efi_driver_binding, "EFIDRV reconnecting old drivers\n" );
663 }
#define DBGC(...)
Definition: compiler.h:505
static int efi_driver_reconnect(EFI_HANDLE device)
Reconnect original EFI driver.
Definition: efi_driver.c:583
static int efi_driver_handles(int(*method)(EFI_HANDLE handle))
Connect/disconnect EFI driver from all handles.
Definition: efi_driver.c:597
static EFI_DRIVER_BINDING_PROTOCOL efi_driver_binding
EFI driver binding protocol.
Definition: efi_driver.c:43

References DBGC, efi_driver_binding, efi_driver_handles(), and efi_driver_reconnect().

Referenced by _efi_start(), efi_block_boot(), and efi_image_exec().