iPXE
Functions
efi_utils.c File Reference

EFI utilities. More...

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_pci.h>
#include <ipxe/efi/efi_utils.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
 
int efi_locate_device (EFI_HANDLE device, EFI_GUID *protocol, EFI_HANDLE *parent)
 Locate parent device supporting a given protocol. More...
 
int efi_child_add (EFI_HANDLE parent, EFI_HANDLE child)
 Add EFI device as child of another EFI device. More...
 
void efi_child_del (EFI_HANDLE parent, EFI_HANDLE child)
 Remove EFI device as child of another EFI device. More...
 
static int efi_pci_info (EFI_HANDLE device, const char *prefix, struct device *dev)
 Get underlying PCI device information. More...
 
void efi_device_info (EFI_HANDLE device, const char *prefix, struct device *dev)
 Get underlying device information. More...
 

Detailed Description

EFI utilities.

Definition in file efi_utils.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER  )

◆ efi_locate_device()

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 43 of file efi_utils.c.

44  {
46  union {
48  void *interface;
49  } path;
50  EFI_DEVICE_PATH_PROTOCOL *devpath;
51  EFI_STATUS efirc;
52  int rc;
53 
54  /* Get device path */
55  if ( ( efirc = bs->OpenProtocol ( device,
57  &path.interface,
60  rc = -EEFI ( efirc );
61  DBGC ( device, "EFIDEV %s cannot open device path: %s\n",
62  efi_handle_name ( device ), strerror ( rc ) );
63  goto err_open_device_path;
64  }
65  devpath = path.path;
66 
67  /* Check for presence of specified protocol */
68  if ( ( efirc = bs->LocateDevicePath ( protocol, &devpath,
69  parent ) ) != 0 ) {
70  rc = -EEFI ( efirc );
71  DBGC ( device, "EFIDEV %s has no parent supporting %s: %s\n",
73  efi_guid_ntoa ( protocol ), strerror ( rc ) );
74  goto err_locate_protocol;
75  }
76 
77  /* Success */
78  rc = 0;
79 
80  err_locate_protocol:
83  err_open_device_path:
84  return rc;
85 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
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:162
#define DBGC(...)
Definition: compiler.h:505
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:51
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1906
A hardware device.
Definition: device.h:73
An object interface.
Definition: interface.h:124
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
Definition: UefiSpec.h:1271
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:722
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
Definition: efi_debug.c:192
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:33
EFI_GUID efi_device_path_protocol_guid
Device path protocol GUID.
Definition: efi_guid.c:132
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1905
uint16_t protocol
Protocol ID.
Definition: stp.h:18
EFI_LOCATE_DEVICE_PATH LocateDevicePath
Definition: UefiSpec.h:1877

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, protocol, rc, and strerror().

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

◆ efi_child_add()

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 94 of file efi_utils.c.

94  {
96  void *devpath;
97  EFI_STATUS efirc;
98  int rc;
99 
100  /* Re-open the device path protocol */
101  if ( ( efirc = bs->OpenProtocol ( parent,
103  &devpath,
104  efi_image_handle, child,
106  ) ) != 0 ) {
107  rc = -EEFI ( efirc );
108  DBGC ( parent, "EFIDEV %s could not add child",
109  efi_handle_name ( parent ) );
110  DBGC ( parent, " %s: %s\n",
111  efi_handle_name ( child ), strerror ( rc ) );
112  DBGC_EFI_OPENERS ( parent, parent,
114  return rc;
115  }
116 
117  DBGC2 ( parent, "EFIDEV %s added child", efi_handle_name ( parent ) );
118  DBGC2 ( parent, " %s\n", efi_handle_name ( child ) );
119  return 0;
120 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
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:162
#define EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
Definition: UefiSpec.h:1273
#define DBGC(...)
Definition: compiler.h:505
#define DBGC_EFI_OPENERS(...)
Definition: efi.h:285
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:722
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:33
EFI_GUID efi_device_path_protocol_guid
Device path protocol GUID.
Definition: efi_guid.c:132
#define DBGC2(...)
Definition: compiler.h:522
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1905

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

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 128 of file efi_utils.c.

128  {
130 
132  efi_image_handle, child );
133  DBGC2 ( parent, "EFIDEV %s removed child", efi_handle_name ( parent ) );
134  DBGC2 ( parent, " %s\n", efi_handle_name ( child ) );
135 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1906
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:722
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:33
EFI_GUID efi_device_path_protocol_guid
Device path protocol GUID.
Definition: efi_guid.c:132
#define DBGC2(...)
Definition: compiler.h:522
EFI_SYSTEM_TABLE * efi_systab

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

static int efi_pci_info ( EFI_HANDLE  device,
const char *  prefix,
struct device dev 
)
static

Get underlying PCI device information.

Parameters
deviceEFI device handle
prefixDevice name prefix
devGeneric device to fill in
Return values
rcReturn status code

Definition at line 145 of file efi_utils.c.

146  {
148  struct efi_pci_device efipci;
149  int rc;
150 
151  /* Find parent PCI device */
153  &pci_device ) ) != 0 ) {
154  DBGC ( device, "EFIDEV %s is not a PCI device: %s\n",
155  efi_handle_name ( device ), strerror ( rc ) );
156  return rc;
157  }
158 
159  /* Get PCI device information */
160  if ( ( rc = efipci_info ( pci_device, &efipci ) ) != 0 ) {
161  DBGC ( device, "EFIDEV %s could not get PCI information: %s\n",
162  efi_handle_name ( device ), strerror ( rc ) );
163  return rc;
164  }
165 
166  /* Populate device information */
167  memcpy ( &dev->desc, &efipci.pci.dev.desc, sizeof ( dev->desc ) );
168  snprintf ( dev->name, sizeof ( dev->name ), "%s-%s",
169  prefix, efipci.pci.dev.name );
170 
171  return 0;
172 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int efipci_info(EFI_HANDLE device, struct efi_pci_device *efipci)
Get EFI PCI device information.
Definition: efi_pci.c:756
EFI_GUID efi_pci_io_protocol_guid
PCI I/O protocol GUID.
Definition: efi_guid.c:216
#define DBGC(...)
Definition: compiler.h:505
char name[40]
Name.
Definition: device.h:75
char prefix[4]
Definition: vmconsole.c:53
A hardware device.
Definition: device.h:73
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:722
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
A PCI device.
Definition: pci.h:191
An EFI PCI device.
Definition: efi_pci.h:21
struct device_description desc
Device description.
Definition: device.h:79
int efi_locate_device(EFI_HANDLE device, EFI_GUID *protocol, EFI_HANDLE *parent)
Locate parent device supporting a given protocol.
Definition: efi_utils.c:43
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
Definition: efi.h:50

References DBGC, device::desc, pci_device::dev, efi_handle_name(), efi_locate_device(), efi_pci_io_protocol_guid, efipci_info(), memcpy(), device::name, efi_pci_device::pci, prefix, rc, snprintf(), and strerror().

Referenced by efi_device_info().

◆ efi_device_info()

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 181 of file efi_utils.c.

182  {
183  int rc;
184 
185  /* Try getting underlying PCI device information */
186  if ( ( rc = efi_pci_info ( device, prefix, dev ) ) == 0 )
187  return;
188 
189  /* If we cannot get any underlying device information, fall
190  * back to providing information about the EFI handle.
191  */
192  DBGC ( device, "EFIDEV %s could not get underlying device "
193  "information\n", efi_handle_name ( device ) );
194  dev->desc.bus_type = BUS_TYPE_EFI;
195  snprintf ( dev->name, sizeof ( dev->name ), "%s-%p", prefix, device );
196 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
char name[40]
Name.
Definition: device.h:75
char prefix[4]
Definition: vmconsole.c:53
static int efi_pci_info(EFI_HANDLE device, const char *prefix, struct device *dev)
Get underlying PCI device information.
Definition: efi_utils.c:145
A hardware device.
Definition: device.h:73
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:722
#define BUS_TYPE_EFI
EFI bus type.
Definition: device.h:61
unsigned int bus_type
Bus type.
Definition: device.h:24
struct device_description desc
Device description.
Definition: device.h:79
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382

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

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