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_NORMAL   02
 Normal drivers. More...
 
#define EFI_DRIVER_LATE   03
 Late drivers. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
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_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 59 of file efi_driver.h.

◆ __efi_driver

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

Declare an EFI driver.

Definition at line 62 of file efi_driver.h.

◆ EFI_DRIVER_EARLY

#define EFI_DRIVER_EARLY   01

Early drivers.

Definition at line 64 of file efi_driver.h.

◆ EFI_DRIVER_NORMAL

#define EFI_DRIVER_NORMAL   02

Normal drivers.

Definition at line 65 of file efi_driver.h.

◆ EFI_DRIVER_LATE

#define EFI_DRIVER_LATE   03

Late drivers.

Definition at line 66 of file efi_driver.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ 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 74 of file efi_driver.h.

75  {
76  efidev->priv = priv;
77 }
void * priv
Driver-private data.
Definition: efi_driver.h:29
static struct tlan_private * priv
Definition: tlan.c:224

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 85 of file efi_driver.h.

85  {
86  return efidev->priv;
87 }
void * priv
Driver-private data.
Definition: efi_driver.h:29

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 70 of file efi_driver.c.

70  {
72  struct efi_device *efidev = NULL;
73  union {
75  void *interface;
76  } path;
77  EFI_DEVICE_PATH_PROTOCOL *path_end;
78  size_t path_len;
79  EFI_STATUS efirc;
80  int rc;
81 
82  /* Open device path */
83  if ( ( efirc = bs->OpenProtocol ( device,
85  &path.interface, efi_image_handle,
86  device,
88  rc = -EEFI ( efirc );
89  DBGC ( device, "EFIDRV %s could not open device path: %s\n",
90  efi_handle_name ( device ), strerror ( rc ) );
91  goto err_open_path;
92  }
93  path_len = ( efi_path_len ( path.path ) + sizeof ( *path_end ) );
94 
95  /* Allocate and initialise structure */
96  efidev = zalloc ( sizeof ( *efidev ) + path_len );
97  if ( ! efidev )
98  goto err_alloc;
99  efidev->device = device;
100  efidev->dev.desc.bus_type = BUS_TYPE_EFI;
101  efidev->path = ( ( ( void * ) efidev ) + sizeof ( *efidev ) );
102  memcpy ( efidev->path, path.path, path_len );
103  INIT_LIST_HEAD ( &efidev->dev.children );
104  list_add ( &efidev->dev.siblings, &efi_devices );
105 
106  err_alloc:
109  err_open_path:
110  return efidev;
111 }
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
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:171
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
#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:144
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:21
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:45
uint16_t device
Device ID.
Definition: ena.h:24
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1987
A hardware device.
Definition: device.h:73
void * memcpy(void *dest, const void *src, size_t len) __nonnull
An object interface.
Definition: interface.h:124
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
Definition: UefiSpec.h:1344
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:808
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
EFI Boot Services Table.
Definition: UefiSpec.h:1917
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:34
struct list_head siblings
Devices on the same bus.
Definition: device.h:81
An EFI device.
Definition: efi_driver.h:17
EFI_GUID efi_device_path_protocol_guid
Device path protocol GUID.
Definition: efi_guid.c:143
#define BUS_TYPE_EFI
EFI bus type.
Definition: device.h:61
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
unsigned int bus_type
Bus type.
Definition: device.h:24
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
struct list_head children
Devices attached to this device.
Definition: device.h:83
struct device_description desc
Device description.
Definition: device.h:79
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1986
EFI_DEVICE_PATH_PROTOCOL * path
EFI device path copy.
Definition: efi_driver.h:25
struct device dev
Generic device.
Definition: efi_driver.h:19
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References EFI_SYSTEM_TABLE::BootServices, device_description::bus_type, BUS_TYPE_EFI, device::children, EFI_BOOT_SERVICES::CloseProtocol, DBGC, device::desc, efi_device::dev, efi_device::device, device, EEFI, efi_device_path_protocol_guid, efi_handle_name(), efi_image_handle, EFI_OPEN_PROTOCOL_GET_PROTOCOL, efi_path_len(), efi_systab, INIT_LIST_HEAD, list_add, memcpy(), NULL, EFI_BOOT_SERVICES::OpenProtocol, 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 118 of file efi_driver.c.

118  {
119 
120  assert ( list_empty ( &efidev->dev.children ) );
121  list_del ( &efidev->dev.siblings );
122  free ( efidev );
123 }
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
struct list_head siblings
Devices on the same bus.
Definition: device.h:81
struct list_head children
Devices attached to this device.
Definition: device.h:83
struct device dev
Generic device.
Definition: efi_driver.h:19

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 155 of file efi_driver.c.

155  {
156  struct device *parent;
157  struct efi_device *efidev;
158 
159  /* Walk upwards until we find a registered EFI device */
160  while ( ( parent = dev->parent ) ) {
161  list_for_each_entry ( efidev, &efi_devices, dev.siblings ) {
162  if ( parent == &efidev->dev )
163  return efidev;
164  }
165  dev = parent;
166  }
167 
168  return NULL;
169 }
struct device * parent
Bus device.
Definition: device.h:85
A hardware device.
Definition: device.h:73
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:431
struct list_head siblings
Devices on the same bus.
Definition: device.h:81
An EFI device.
Definition: efi_driver.h:17
struct device dev
Generic device.
Definition: efi_driver.h:19
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

Referenced by efi_ib_srp_path(), efi_netdev_path(), efi_snp_probe(), and efi_usb_path().

◆ efi_driver_install()

int efi_driver_install ( void  )

Install EFI driver.

Return values
rcReturn status code

Definition at line 414 of file efi_driver.c.

414  {
416  EFI_STATUS efirc;
417  int rc;
418 
419  /* Calculate driver version number. We use the build
420  * timestamp (in seconds since the Epoch) shifted right by six
421  * bits: this gives us an approximately one-minute resolution
422  * and a scheme which will last until the year 10680.
423  */
425 
426  /* Install protocols on image handle */
429  if ( ( efirc = bs->InstallMultipleProtocolInterfaces (
433  NULL ) ) != 0 ) {
434  rc = -EEFI ( efirc );
435  DBGC ( &efi_driver_binding, "EFIDRV could not install "
436  "protocols: %s\n", strerror ( rc ) );
437  return rc;
438  }
439 
440  return 0;
441 }
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
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:171
#define DBGC(...)
Definition: compiler.h:505
EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES InstallMultipleProtocolInterfaces
Definition: UefiSpec.h:1996
unsigned long build_timestamp
Build timestamp.
Definition: version.c:58
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
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_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:135
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:56
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
EFI_SYSTEM_TABLE * efi_systab
static EFI_COMPONENT_NAME2_PROTOCOL efi_wtf
EFI component name protocol.
Definition: efi_driver.c:403
EFI_GUID efi_driver_binding_protocol_guid
Driver binding protocol GUID.
Definition: efi_guid.c:183
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
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 447 of file efi_driver.c.

447  {
449 
450  /* Uninstall protocols */
455 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2081
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_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces
Definition: UefiSpec.h:1997
EFI_GUID efi_component_name2_protocol_guid
Component name 2 protocol GUID.
Definition: efi_guid.c:135
static EFI_DRIVER_BINDING_PROTOCOL efi_driver_binding
EFI driver binding protocol.
Definition: efi_driver.c:56
EFI_SYSTEM_TABLE * efi_systab
static EFI_COMPONENT_NAME2_PROTOCOL efi_wtf
EFI component name protocol.
Definition: efi_driver.c:403
EFI_GUID efi_driver_binding_protocol_guid
Driver binding protocol GUID.
Definition: efi_guid.c:183
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

int efi_driver_connect_all ( void  )

Connect EFI driver to all possible devices.

Return values
rcReturn status code

Definition at line 602 of file efi_driver.c.

602  {
603 
604  DBGC ( &efi_driver_binding, "EFIDRV connecting our drivers\n" );
606 }
static int efi_driver_connect(EFI_HANDLE device)
Try to connect EFI driver.
Definition: efi_driver.c:463
#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:562
static EFI_DRIVER_BINDING_PROTOCOL efi_driver_binding
EFI driver binding protocol.
Definition: efi_driver.c:56

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 613 of file efi_driver.c.

613  {
614 
615  DBGC ( &efi_driver_binding, "EFIDRV disconnecting our drivers\n" );
617 }
#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:562
static EFI_DRIVER_BINDING_PROTOCOL efi_driver_binding
EFI driver binding protocol.
Definition: efi_driver.c:56
static int efi_driver_disconnect(EFI_HANDLE device)
Try to disconnect EFI driver.
Definition: efi_driver.c:529

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 624 of file efi_driver.c.

624  {
625 
626  DBGC ( &efi_driver_binding, "EFIDRV reconnecting old drivers\n" );
628 }
#define DBGC(...)
Definition: compiler.h:505
static int efi_driver_reconnect(EFI_HANDLE device)
Reconnect original EFI driver.
Definition: efi_driver.c:547
static int efi_driver_handles(int(*method)(EFI_HANDLE handle))
Connect/disconnect EFI driver from all handles.
Definition: efi_driver.c:562
static EFI_DRIVER_BINDING_PROTOCOL efi_driver_binding
EFI driver binding protocol.
Definition: efi_driver.c:56

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

Referenced by _efi_start(), and efi_image_exec().