iPXE
Data Structures | Functions | Variables
efi_path.c File Reference

EFI device paths. More...

#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/netdevice.h>
#include <ipxe/vlan.h>
#include <ipxe/uuid.h>
#include <ipxe/tcpip.h>
#include <ipxe/uri.h>
#include <ipxe/iscsi.h>
#include <ipxe/aoe.h>
#include <ipxe/fcp.h>
#include <ipxe/ib_srp.h>
#include <ipxe/usb.h>
#include <ipxe/settings.h>
#include <ipxe/dhcp.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_driver.h>
#include <ipxe/efi/efi_strings.h>
#include <ipxe/efi/efi_path.h>

Go to the source code of this file.

Data Structures

struct  efi_path_settings
 An EFI device path settings block. More...
 
struct  efi_path_setting
 An EFI device path setting. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER)
 
 FILE_SECBOOT (PERMITTED)
 
EFI_DEVICE_PATH_PROTOCOLefi_path_next (EFI_DEVICE_PATH_PROTOCOL *path)
 Find next element in device path. More...
 
EFI_DEVICE_PATH_PROTOCOLefi_path_prev (EFI_DEVICE_PATH_PROTOCOL *path, EFI_DEVICE_PATH_PROTOCOL *curr)
 Find previous element of device path. More...
 
EFI_DEVICE_PATH_PROTOCOLefi_path_end (EFI_DEVICE_PATH_PROTOCOL *path)
 Find end of device path. More...
 
size_t efi_path_len (EFI_DEVICE_PATH_PROTOCOL *path)
 Find length of device path (excluding terminator) More...
 
int efi_path_check (EFI_DEVICE_PATH_PROTOCOL *path, size_t max)
 Check that device path is well-formed. More...
 
void * efi_path_mac (EFI_DEVICE_PATH_PROTOCOL *path)
 Get MAC address from device path. More...
 
unsigned int efi_path_vlan (EFI_DEVICE_PATH_PROTOCOL *path)
 Get VLAN tag from device path. More...
 
int efi_path_guid (EFI_DEVICE_PATH_PROTOCOL *path, union uuid *guid)
 Get partition GUID from device path. More...
 
struct uriefi_path_uri (EFI_DEVICE_PATH_PROTOCOL *path)
 Parse URI from device path. More...
 
EFI_DEVICE_PATH_PROTOCOLefi_paths (EFI_DEVICE_PATH_PROTOCOL *first,...)
 Concatenate EFI device paths. More...
 
static EFI_DEVICE_PATH_PROTOCOLefi_parent_path (struct device *dev)
 Construct EFI parent device path. More...
 
EFI_DEVICE_PATH_PROTOCOLefi_netdev_path (struct net_device *netdev)
 Construct EFI device path for network device. More...
 
EFI_DEVICE_PATH_PROTOCOLefi_uri_path (struct uri *uri)
 Construct EFI device path for URI. More...
 
EFI_DEVICE_PATH_PROTOCOLefi_iscsi_path (struct iscsi_session *iscsi)
 Construct EFI device path for iSCSI device. More...
 
EFI_DEVICE_PATH_PROTOCOLefi_aoe_path (struct aoe_device *aoedev)
 Construct EFI device path for AoE device. More...
 
EFI_DEVICE_PATH_PROTOCOLefi_fcp_path (struct fcp_description *desc)
 Construct EFI device path for Fibre Channel device. More...
 
EFI_DEVICE_PATH_PROTOCOLefi_ib_srp_path (struct ib_srp_device *ib_srp)
 Construct EFI device path for Infiniband SRP device. More...
 
EFI_DEVICE_PATH_PROTOCOLefi_usb_path (struct usb_function *func)
 Construct EFI device path for USB function. More...
 
EFI_DEVICE_PATH_PROTOCOLefi_load_path (EFI_LOAD_OPTION *load, size_t len)
 Get EFI device path from load option. More...
 
EFI_DEVICE_PATH_PROTOCOLefi_boot_path (unsigned int number)
 Get EFI device path for numbered boot option. More...
 
EFI_DEVICE_PATH_PROTOCOLefi_current_boot_path (void)
 Get EFI device path for current boot option. More...
 
EFI_DEVICE_PATH_PROTOCOLefi_describe (struct interface *intf)
 Describe object as an EFI device path. More...
 
static int efi_path_fetch_fixed (struct efi_path_setting *pathset, EFI_DEVICE_PATH_PROTOCOL *path, void *data, size_t len)
 Fetch an EFI device path fixed-size setting. More...
 
static int efi_path_fetch_dns (struct efi_path_setting *pathset, EFI_DEVICE_PATH_PROTOCOL *path, void *data, size_t len)
 Fetch an EFI device path DNS setting. More...
 
static int efi_path_fetch (struct settings *settings, struct setting *setting, void *data, size_t len)
 Fetch value of EFI device path setting. More...
 
static int efi_path_net_probe (struct net_device *netdev, void *priv)
 Create per-netdevice EFI path settings. More...
 

Variables

struct {
   BBS_BBS_DEVICE_PATH   bbs
 
   CHAR8   tring [4]
 
   EFI_DEVICE_PATH_PROTOCOL   end
 
efi_dummy_parent_path
 Dummy parent device path. More...
 
static struct efi_path_setting efi_path_settings []
 EFI device path settings. More...
 
static struct settings_operations efi_path_settings_operations
 EFI device path settings operations. More...
 
struct net_driver efi_path_net_driver __net_driver
 EFI path settings per-netdevice driver. More...
 

Detailed Description

EFI device paths.

Definition in file efi_path.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ efi_path_next()

Find next element in device path.

Parameters
pathDevice path, or NULL
nextNext element in device path, or NULL if at end

Definition at line 119 of file efi_path.c.

119  {
120 
121  /* Check for non-existent device path */
122  if ( ! path )
123  return NULL;
124 
125  /* Check for end of device path */
126  if ( path->Type == END_DEVICE_PATH_TYPE )
127  return NULL;
128 
129  /* Move to next component of the device path */
130  path = ( ( ( void * ) path ) +
131  /* There's this amazing new-fangled thing known as
132  * a UINT16, but who wants to use one of those? */
133  ( ( path->Length[1] << 8 ) | path->Length[0] ) );
134 
135  return path;
136 }
#define END_DEVICE_PATH_TYPE
Definition: DevicePath.h:1394
UINT8 Length[2]
Specific Device Path data.
Definition: DevicePath.h:59
UINT8 Type
0x01 Hardware Device Path.
Definition: DevicePath.h:47
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

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

Referenced by efi_local_open_path(), efi_path_check(), efi_path_fetch(), efi_path_guid(), efi_path_mac(), efi_path_prev(), efi_path_uri(), and efi_path_vlan().

◆ efi_path_prev()

Find previous element of device path.

Parameters
pathDevice path, or NULL for no path
currCurrent element in device path, or NULL for end of path
Return values
prevPrevious element in device path, or NULL

Definition at line 145 of file efi_path.c.

146  {
148 
149  /* Find immediately preceding element */
150  while ( ( tmp = efi_path_next ( path ) ) != curr ) {
151  path = tmp;
152  }
153 
154  return path;
155 }
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:46
unsigned long tmp
Definition: linux_pci.h:65
EFI_DEVICE_PATH_PROTOCOL * efi_path_next(EFI_DEVICE_PATH_PROTOCOL *path)
Find next element in device path.
Definition: efi_path.c:119

References efi_path_next(), and tmp.

Referenced by efi_locate_device(), and efi_path_end().

◆ efi_path_end()

Find end of device path.

Parameters
pathDevice path, or NULL
Return values
path_endEnd of device path, or NULL

Definition at line 163 of file efi_path.c.

163  {
164 
165  return efi_path_prev ( path, NULL );
166 }
EFI_DEVICE_PATH_PROTOCOL * efi_path_prev(EFI_DEVICE_PATH_PROTOCOL *path, EFI_DEVICE_PATH_PROTOCOL *curr)
Find previous element of device path.
Definition: efi_path.c:145
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References efi_path_prev(), and NULL.

Referenced by efi_block_exec(), efi_path_len(), and usbio_open().

◆ efi_path_len()

size_t efi_path_len ( EFI_DEVICE_PATH_PROTOCOL path)

Find length of device path (excluding terminator)

Parameters
pathDevice path, or NULL
Return values
path_lenLength of device path

Definition at line 174 of file efi_path.c.

174  {
176 
177  return ( ( ( void * ) end ) - ( ( void * ) path ) );
178 }
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:46
EFI_DEVICE_PATH_PROTOCOL end
Definition: efi_path.c:59
EFI_DEVICE_PATH_PROTOCOL * efi_path_end(EFI_DEVICE_PATH_PROTOCOL *path)
Find end of device path.
Definition: efi_path.c:163

References efi_path_end(), and end.

Referenced by efi_block_match(), efi_devpath_text(), efi_ib_srp_path(), efi_image_path(), efi_init(), efi_iscsi_path(), efi_local_open_path(), efi_locate_device(), efi_netdev_path(), efi_paths(), efi_snp_hii_install(), efi_usb_path(), efidev_alloc(), and usbio_path().

◆ efi_path_check()

int efi_path_check ( EFI_DEVICE_PATH_PROTOCOL path,
size_t  max 
)

Check that device path is well-formed.

Parameters
pathDevice path, or NULL
maxMaximum device path length
Return values
rcReturn status code

Definition at line 187 of file efi_path.c.

187  {
189  size_t remaining = max;
190  size_t len;
191 
192  /* Check that path terminates within maximum length */
193  for ( ; ; path = next ) {
194  if ( remaining < sizeof ( *path ) )
195  return -EINVAL;
196  next = efi_path_next ( path );
197  if ( ! next )
198  break;
199  len = ( ( ( void * ) next ) - ( ( void * ) path ) );
200  if ( remaining < len )
201  return -EINVAL;
202  }
203 
204  return 0;
205 }
#define EINVAL
Invalid argument.
Definition: errno.h:429
#define max(x, y)
Definition: ath.h:41
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:46
ring len
Length.
Definition: dwmac.h:231
uint32_t next
Next descriptor address.
Definition: dwmac.h:22
EFI_DEVICE_PATH_PROTOCOL * efi_path_next(EFI_DEVICE_PATH_PROTOCOL *path)
Find next element in device path.
Definition: efi_path.c:119

References efi_path_next(), EINVAL, len, max, and next.

Referenced by efi_load_path().

◆ efi_path_mac()

void* efi_path_mac ( EFI_DEVICE_PATH_PROTOCOL path)

Get MAC address from device path.

Parameters
pathDevice path
Return values
macMAC address, or NULL if not found

Definition at line 213 of file efi_path.c.

213  {
216 
217  /* Search for MAC address path */
218  for ( ; ( next = efi_path_next ( path ) ) ; path = next ) {
219  if ( ( path->Type == MESSAGING_DEVICE_PATH ) &&
220  ( path->SubType == MSG_MAC_ADDR_DP ) ) {
222  Header );
223  return &mac->MacAddress;
224  }
225  }
226 
227  /* No MAC address found */
228  return NULL;
229 }
#define MSG_MAC_ADDR_DP
MAC Address Device Path SubType.
Definition: DevicePath.h:553
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:46
uint8_t mac[ETH_ALEN]
MAC address.
Definition: ena.h:24
#define MESSAGING_DEVICE_PATH
Messaging Device Paths.
Definition: DevicePath.h:324
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:36
uint32_t next
Next descriptor address.
Definition: dwmac.h:22
EFI_DEVICE_PATH_PROTOCOL * efi_path_next(EFI_DEVICE_PATH_PROTOCOL *path)
Find next element in device path.
Definition: efi_path.c:119
UINT8 SubType
Varies by Type 0xFF End Entire Device Path, or 0x01 End This Instance of a Device Path and start a ne...
Definition: DevicePath.h:54
UINT8 Type
0x01 Hardware Device Path.
Definition: DevicePath.h:47
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
PACKED union @541::@555 Header
Definition: Acpi10.h:156

References container_of, efi_path_next(), Header, mac, MESSAGING_DEVICE_PATH, MSG_MAC_ADDR_DP, next, NULL, EFI_DEVICE_PATH_PROTOCOL::SubType, and EFI_DEVICE_PATH_PROTOCOL::Type.

Referenced by efi_path_net_probe().

◆ efi_path_vlan()

unsigned int efi_path_vlan ( EFI_DEVICE_PATH_PROTOCOL path)

Get VLAN tag from device path.

Parameters
pathDevice path
Return values
tagVLAN tag, or 0 if not a VLAN

Definition at line 237 of file efi_path.c.

237  {
239  VLAN_DEVICE_PATH *vlan;
240 
241  /* Search for VLAN device path */
242  for ( ; ( next = efi_path_next ( path ) ) ; path = next ) {
243  if ( ( path->Type == MESSAGING_DEVICE_PATH ) &&
244  ( path->SubType == MSG_VLAN_DP ) ) {
245  vlan = container_of ( path, VLAN_DEVICE_PATH, Header );
246  return vlan->VlanId;
247  }
248  }
249 
250  /* No VLAN device path found */
251  return 0;
252 }
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:46
#define MESSAGING_DEVICE_PATH
Messaging Device Paths.
Definition: DevicePath.h:324
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:36
UINT16 VlanId
VLAN identifier (0-4094).
Definition: DevicePath.h:973
uint32_t next
Next descriptor address.
Definition: dwmac.h:22
EFI_DEVICE_PATH_PROTOCOL * efi_path_next(EFI_DEVICE_PATH_PROTOCOL *path)
Find next element in device path.
Definition: efi_path.c:119
#define MSG_VLAN_DP
VLAN Device Path SubType.
Definition: DevicePath.h:967
UINT8 SubType
Varies by Type 0xFF End Entire Device Path, or 0x01 End This Instance of a Device Path and start a ne...
Definition: DevicePath.h:54
UINT8 Type
0x01 Hardware Device Path.
Definition: DevicePath.h:47
PACKED union @541::@555 Header
Definition: Acpi10.h:156

References container_of, efi_path_next(), Header, MESSAGING_DEVICE_PATH, MSG_VLAN_DP, next, EFI_DEVICE_PATH_PROTOCOL::SubType, EFI_DEVICE_PATH_PROTOCOL::Type, and VLAN_DEVICE_PATH::VlanId.

Referenced by efi_cachedhcp_record(), efi_path_net_probe(), and efi_set_autoboot_ll_addr().

◆ efi_path_guid()

int efi_path_guid ( EFI_DEVICE_PATH_PROTOCOL path,
union uuid guid 
)

Get partition GUID from device path.

Parameters
pathDevice path
guidPartition GUID to fill in
Return values
rcReturn status code

Definition at line 261 of file efi_path.c.

261  {
264  int rc;
265 
266  /* Search for most specific partition device path */
267  rc = -ENOENT;
268  for ( ; ( next = efi_path_next ( path ) ) ; path = next ) {
269 
270  /* Skip non-harddrive device paths */
271  if ( path->Type != MEDIA_DEVICE_PATH )
272  continue;
273  if ( path->SubType != MEDIA_HARDDRIVE_DP )
274  continue;
275 
276  /* Skip non-GUID signatures */
277  hd = container_of ( path, HARDDRIVE_DEVICE_PATH, Header );
278  if ( hd->SignatureType != SIGNATURE_TYPE_GUID )
279  continue;
280 
281  /* Extract GUID */
282  memcpy ( guid, hd->Signature, sizeof ( *guid ) );
283  uuid_mangle ( guid );
284 
285  /* Record success, but continue searching in case
286  * there exists a more specific GUID (e.g. a partition
287  * GUID rather than a disk GUID).
288  */
289  rc = 0;
290  }
291 
292  return rc;
293 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
UINT8 SignatureType
Type of Disk Signature: (Unused values reserved).
Definition: DevicePath.h:1059
#define ENOENT
No such file or directory.
Definition: errno.h:515
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:46
static void uuid_mangle(union uuid *uuid)
Change UUID endianness.
Definition: uuid.h:44
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:36
#define MEDIA_HARDDRIVE_DP
Hard Drive Media Device Path SubType.
Definition: DevicePath.h:1017
#define MEDIA_DEVICE_PATH
Definition: DevicePath.h:1012
uint32_t next
Next descriptor address.
Definition: dwmac.h:22
EFI_DEVICE_PATH_PROTOCOL * efi_path_next(EFI_DEVICE_PATH_PROTOCOL *path)
Find next element in device path.
Definition: efi_path.c:119
uint64_t guid
GUID.
Definition: edd.h:31
UINT8 Signature[16]
Signature unique to this partition: If SignatureType is 0, this field has to be initialized with 16 z...
Definition: DevicePath.h:1046
UINT8 SubType
Varies by Type 0xFF End Entire Device Path, or 0x01 End This Instance of a Device Path and start a ne...
Definition: DevicePath.h:54
The Hard Drive Media Device Path is used to represent a partition on a hard drive.
Definition: DevicePath.h:1022
UINT8 Type
0x01 Hardware Device Path.
Definition: DevicePath.h:47
#define SIGNATURE_TYPE_GUID
Definition: DevicePath.h:1067
PACKED union @541::@555 Header
Definition: Acpi10.h:156

References container_of, efi_path_next(), ENOENT, guid, Header, MEDIA_DEVICE_PATH, MEDIA_HARDDRIVE_DP, memcpy(), next, rc, HARDDRIVE_DEVICE_PATH::Signature, SIGNATURE_TYPE_GUID, HARDDRIVE_DEVICE_PATH::SignatureType, EFI_DEVICE_PATH_PROTOCOL::SubType, EFI_DEVICE_PATH_PROTOCOL::Type, and uuid_mangle().

Referenced by efi_block_match().

◆ efi_path_uri()

struct uri* efi_path_uri ( EFI_DEVICE_PATH_PROTOCOL path)

Parse URI from device path.

Parameters
pathDevice path
Return values
uriURI, or NULL if not a URI

Definition at line 301 of file efi_path.c.

301  {
303  URI_DEVICE_PATH *uripath;
304  char *uristring;
305  struct uri *uri;
306  size_t len;
307 
308  /* Search for URI device path */
309  for ( ; ( next = efi_path_next ( path ) ) ; path = next ) {
310  if ( ( path->Type == MESSAGING_DEVICE_PATH ) &&
311  ( path->SubType == MSG_URI_DP ) ) {
312 
313  /* Calculate path length */
314  uripath = container_of ( path, URI_DEVICE_PATH,
315  Header );
316  len = ( ( ( path->Length[1] << 8 ) | path->Length[0] )
317  - offsetof ( typeof ( *uripath ), Uri ) );
318 
319  /* Parse URI */
320  uristring = zalloc ( len + 1 /* NUL */ );
321  if ( ! uristring )
322  return NULL;
323  memcpy ( uristring, uripath->Uri, len );
324  uri = parse_uri ( uristring );
325  free ( uristring );
326 
327  return uri;
328  }
329  }
330 
331  /* No URI path found */
332  return NULL;
333 }
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:46
#define offsetof(type, field)
Get offset of a field within a structure.
Definition: stddef.h:25
#define MESSAGING_DEVICE_PATH
Messaging Device Paths.
Definition: DevicePath.h:324
#define MSG_URI_DP
Uniform Resource Identifiers (URI) Device Path SubType.
Definition: DevicePath.h:882
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:36
ring len
Length.
Definition: dwmac.h:231
const char * path
Path (after URI decoding)
Definition: uri.h:81
CHAR8 Uri[]
Instance of the URI pursuant to RFC 3986.
Definition: DevicePath.h:888
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:662
uint32_t next
Next descriptor address.
Definition: dwmac.h:22
EFI_DEVICE_PATH_PROTOCOL * efi_path_next(EFI_DEVICE_PATH_PROTOCOL *path)
Find next element in device path.
Definition: efi_path.c:119
A Uniform Resource Identifier.
Definition: uri.h:65
typeof(acpi_finder=acpi_find)
ACPI table finder.
Definition: acpi.c:48
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
struct uri * parse_uri(const char *uri_string)
Parse URI.
Definition: uri.c:297
PACKED union @541::@555 Header
Definition: Acpi10.h:156

References container_of, efi_path_next(), free, Header, len, memcpy(), MESSAGING_DEVICE_PATH, MSG_URI_DP, next, NULL, offsetof, parse_uri(), uri::path, typeof(), URI_DEVICE_PATH::Uri, and zalloc().

Referenced by efi_init_application().

◆ efi_paths()

EFI_DEVICE_PATH_PROTOCOL* efi_paths ( EFI_DEVICE_PATH_PROTOCOL first,
  ... 
)

Concatenate EFI device paths.

Parameters
...List of device paths (NULL terminated)
Return values
pathConcatenated device path, or NULL on error

The caller is responsible for eventually calling free() on the allocated device path.

Definition at line 344 of file efi_path.c.

344  {
349  va_list args;
350  size_t len;
351 
352  /* Calculate device path length */
353  va_start ( args, first );
354  len = 0;
355  src = first;
356  while ( src ) {
357  len += efi_path_len ( src );
358  src = va_arg ( args, EFI_DEVICE_PATH_PROTOCOL * );
359  }
360  va_end ( args );
361 
362  /* Allocate device path */
363  path = zalloc ( len + sizeof ( *end ) );
364  if ( ! path )
365  return NULL;
366 
367  /* Populate device path */
368  va_start ( args, first );
369  dst = path;
370  src = first;
371  while ( src ) {
372  len = efi_path_len ( src );
373  memcpy ( dst, src, len );
374  dst = ( ( ( void * ) dst ) + len );
375  src = va_arg ( args, EFI_DEVICE_PATH_PROTOCOL * );
376  }
377  va_end ( args );
378  end = dst;
380 
381  return path;
382 }
#define va_end(ap)
Definition: stdarg.h:10
uint32_t first
First block in range.
Definition: pccrr.h:15
size_t efi_path_len(EFI_DEVICE_PATH_PROTOCOL *path)
Find length of device path (excluding terminator)
Definition: efi_path.c:174
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:46
static void efi_path_terminate(EFI_DEVICE_PATH_PROTOCOL *end)
Terminate device path.
Definition: efi_path.h:31
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define va_arg(ap, type)
Definition: stdarg.h:9
static const void * src
Definition: string.h:48
ring len
Length.
Definition: dwmac.h:231
const char * path
Path (after URI decoding)
Definition: uri.h:81
EFI_DEVICE_PATH_PROTOCOL end
Definition: efi_path.c:59
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:662
__builtin_va_list va_list
Definition: stdarg.h:7
#define va_start(ap, last)
Definition: stdarg.h:8
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References efi_path_len(), efi_path_terminate(), end, first, len, memcpy(), NULL, uri::path, src, va_arg, va_end, va_start, and zalloc().

Referenced by efi_aoe_path().

◆ efi_parent_path()

static EFI_DEVICE_PATH_PROTOCOL* efi_parent_path ( struct device dev)
static

Construct EFI parent device path.

Parameters
devGeneric device
Return values
pathParent (or dummy) device path

Definition at line 390 of file efi_path.c.

390  {
391  struct efi_device *efidev;
392 
393  /* Use EFI parent device's path, if possible */
394  efidev = efidev_parent ( dev );
395  if ( efidev )
396  return efidev->path;
397 
398  /* Otherwise, use a dummy parent device path */
399  return &efi_dummy_parent_path.bbs.Header;
400 }
static struct @438 efi_dummy_parent_path
Dummy parent device path.
An EFI device.
Definition: efi_driver.h:18
EFI_DEVICE_PATH_PROTOCOL * path
EFI device path copy.
Definition: efi_driver.h:26
struct efi_device * efidev_parent(struct device *dev)
Get parent EFI device.
Definition: efi_driver.c:129
struct device dev
Generic device.
Definition: efi_driver.h:20

References efi_device::dev, efi_dummy_parent_path, efidev_parent(), and efi_device::path.

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

◆ efi_netdev_path()

EFI_DEVICE_PATH_PROTOCOL* efi_netdev_path ( struct net_device netdev)

Construct EFI device path for network device.

Parameters
netdevNetwork device
Return values
pathEFI device path, or NULL on error

The caller is responsible for eventually calling free() on the allocated device path.

Definition at line 411 of file efi_path.c.

411  {
412  EFI_DEVICE_PATH_PROTOCOL *parent;
414  MAC_ADDR_DEVICE_PATH *macpath;
415  VLAN_DEVICE_PATH *vlanpath;
417  unsigned int tag;
418  size_t prefix_len;
419  size_t len;
420 
421  /* Get parent EFI device path */
422  parent = efi_parent_path ( netdev->dev );
423 
424  /* Calculate device path length */
425  prefix_len = efi_path_len ( parent );
426  len = ( prefix_len + sizeof ( *macpath ) + sizeof ( *vlanpath ) +
427  sizeof ( *end ) );
428 
429  /* Allocate device path */
430  path = zalloc ( len );
431  if ( ! path )
432  return NULL;
433 
434  /* Construct device path */
435  memcpy ( path, parent, prefix_len );
436  macpath = ( ( ( void * ) path ) + prefix_len );
437  macpath->Header.Type = MESSAGING_DEVICE_PATH;
438  macpath->Header.SubType = MSG_MAC_ADDR_DP;
439  macpath->Header.Length[0] = sizeof ( *macpath );
441  sizeof ( macpath->MacAddress ) );
442  memcpy ( &macpath->MacAddress, netdev->ll_addr,
444  macpath->IfType = ntohs ( netdev->ll_protocol->ll_proto );
445  if ( ( tag = vlan_tag ( netdev ) ) ) {
446  vlanpath = ( ( ( void * ) macpath ) + sizeof ( *macpath ) );
447  vlanpath->Header.Type = MESSAGING_DEVICE_PATH;
448  vlanpath->Header.SubType = MSG_VLAN_DP;
449  vlanpath->Header.Length[0] = sizeof ( *vlanpath );
450  vlanpath->VlanId = tag;
451  end = ( ( ( void * ) vlanpath ) + sizeof ( *vlanpath ) );
452  } else {
453  end = ( ( ( void * ) macpath ) + sizeof ( *macpath ) );
454  }
456 
457  return path;
458 }
uint8_t ll_addr_len
Link-layer address length.
Definition: netdevice.h:199
static EFI_DEVICE_PATH_PROTOCOL * efi_parent_path(struct device *dev)
Construct EFI parent device path.
Definition: efi_path.c:390
UINT8 IfType
Network interface type(i.e.
Definition: DevicePath.h:563
EFI_MAC_ADDRESS MacAddress
The MAC address for a network interface padded with 0s.
Definition: DevicePath.h:559
#define MSG_MAC_ADDR_DP
MAC Address Device Path SubType.
Definition: DevicePath.h:553
size_t efi_path_len(EFI_DEVICE_PATH_PROTOCOL *path)
Find length of device path (excluding terminator)
Definition: efi_path.c:174
#define ntohs(value)
Definition: byteswap.h:137
EFI_DEVICE_PATH_PROTOCOL Header
Definition: DevicePath.h:555
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:46
#define MESSAGING_DEVICE_PATH
Messaging Device Paths.
Definition: DevicePath.h:324
static void efi_path_terminate(EFI_DEVICE_PATH_PROTOCOL *end)
Terminate device path.
Definition: efi_path.h:31
void * memcpy(void *dest, const void *src, size_t len) __nonnull
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
ring len
Length.
Definition: dwmac.h:231
static struct net_device * netdev
Definition: gdbudp.c:52
UINT16 VlanId
VLAN identifier (0-4094).
Definition: DevicePath.h:973
EFI_DEVICE_PATH_PROTOCOL end
Definition: efi_path.c:59
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:662
uint16_t ll_proto
Link-layer protocol.
Definition: netdevice.h:195
struct device * dev
Underlying hardware device.
Definition: netdevice.h:365
#define MSG_VLAN_DP
VLAN Device Path SubType.
Definition: DevicePath.h:967
EFI_DEVICE_PATH_PROTOCOL Header
Definition: DevicePath.h:969
UINT8 Length[2]
Specific Device Path data.
Definition: DevicePath.h:59
UINT8 SubType
Varies by Type 0xFF End Entire Device Path, or 0x01 End This Instance of a Device Path and start a ne...
Definition: DevicePath.h:54
UINT8 Type
0x01 Hardware Device Path.
Definition: DevicePath.h:47
EFI_DEVICE_PATH_PROTOCOL * path
EFI device path copy.
Definition: efi_driver.h:26
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:388
static unsigned int vlan_tag(struct net_device *netdev)
Get the VLAN tag.
Definition: vlan.h:74
uint64_t tag
Identity tag.
Definition: edd.h:31
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:373

References assert(), net_device::dev, efi_parent_path(), efi_path_len(), efi_path_terminate(), end, MAC_ADDR_DEVICE_PATH::Header, VLAN_DEVICE_PATH::Header, MAC_ADDR_DEVICE_PATH::IfType, len, EFI_DEVICE_PATH_PROTOCOL::Length, net_device::ll_addr, ll_protocol::ll_addr_len, ll_protocol::ll_proto, net_device::ll_protocol, MAC_ADDR_DEVICE_PATH::MacAddress, memcpy(), MESSAGING_DEVICE_PATH, MSG_MAC_ADDR_DP, MSG_VLAN_DP, netdev, ntohs, NULL, efi_device::path, EFI_DEVICE_PATH_PROTOCOL::SubType, tag, EFI_DEVICE_PATH_PROTOCOL::Type, vlan_tag(), VLAN_DEVICE_PATH::VlanId, and zalloc().

Referenced by efi_aoe_path(), efi_iscsi_path(), and efi_snp_probe().

◆ efi_uri_path()

EFI_DEVICE_PATH_PROTOCOL* efi_uri_path ( struct uri uri)

Construct EFI device path for URI.

Parameters
uriURI
Return values
pathEFI device path, or NULL on error

The caller is responsible for eventually calling free() on the allocated device path.

Definition at line 469 of file efi_path.c.

469  {
472  URI_DEVICE_PATH *uripath;
473  size_t uri_len;
474  size_t uripath_len;
475  size_t len;
476 
477  /* Calculate device path length */
478  uri_len = ( format_uri ( uri, NULL, 0 ) + 1 /* NUL */ );
479  uripath_len = ( sizeof ( *uripath ) + uri_len );
480  len = ( uripath_len + sizeof ( *end ) );
481 
482  /* Allocate device path */
483  path = zalloc ( len );
484  if ( ! path )
485  return NULL;
486 
487  /* Construct device path */
488  uripath = ( ( void * ) path );
489  uripath->Header.Type = MESSAGING_DEVICE_PATH;
490  uripath->Header.SubType = MSG_URI_DP;
491  uripath->Header.Length[0] = ( uripath_len & 0xff );
492  uripath->Header.Length[1] = ( uripath_len >> 8 );
493  format_uri ( uri, uripath->Uri, uri_len );
494  end = ( ( ( void * ) path ) + uripath_len );
496 
497  return path;
498 }
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:46
#define MESSAGING_DEVICE_PATH
Messaging Device Paths.
Definition: DevicePath.h:324
static void efi_path_terminate(EFI_DEVICE_PATH_PROTOCOL *end)
Terminate device path.
Definition: efi_path.h:31
#define MSG_URI_DP
Uniform Resource Identifiers (URI) Device Path SubType.
Definition: DevicePath.h:882
EFI_DEVICE_PATH_PROTOCOL Header
Definition: DevicePath.h:884
ring len
Length.
Definition: dwmac.h:231
size_t format_uri(const struct uri *uri, char *buf, size_t len)
Format URI.
Definition: uri.c:472
EFI_DEVICE_PATH_PROTOCOL end
Definition: efi_path.c:59
CHAR8 Uri[]
Instance of the URI pursuant to RFC 3986.
Definition: DevicePath.h:888
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:662
UINT8 Length[2]
Specific Device Path data.
Definition: DevicePath.h:59
UINT8 SubType
Varies by Type 0xFF End Entire Device Path, or 0x01 End This Instance of a Device Path and start a ne...
Definition: DevicePath.h:54
UINT8 Type
0x01 Hardware Device Path.
Definition: DevicePath.h:47
A Uniform Resource Identifier.
Definition: uri.h:65
EFI_DEVICE_PATH_PROTOCOL * path
EFI device path copy.
Definition: efi_driver.h:26
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References efi_path_terminate(), end, format_uri(), URI_DEVICE_PATH::Header, len, EFI_DEVICE_PATH_PROTOCOL::Length, MESSAGING_DEVICE_PATH, MSG_URI_DP, NULL, efi_device::path, EFI_DEVICE_PATH_PROTOCOL::SubType, EFI_DEVICE_PATH_PROTOCOL::Type, URI_DEVICE_PATH::Uri, and zalloc().

Referenced by http_efi_describe().

◆ efi_iscsi_path()

EFI_DEVICE_PATH_PROTOCOL* efi_iscsi_path ( struct iscsi_session iscsi)

Construct EFI device path for iSCSI device.

Parameters
iscsiiSCSI session
Return values
pathEFI device path, or NULL on error

Definition at line 506 of file efi_path.c.

506  {
507  struct sockaddr_tcpip *st_target;
508  struct net_device *netdev;
509  EFI_DEVICE_PATH_PROTOCOL *netpath;
512  ISCSI_DEVICE_PATH *iscsipath;
513  char *name;
514  size_t prefix_len;
515  size_t name_len;
516  size_t iscsi_len;
517  size_t len;
518 
519  /* Get network device associated with target address */
520  st_target = ( ( struct sockaddr_tcpip * ) &iscsi->target_sockaddr );
521  netdev = tcpip_netdev ( st_target );
522  if ( ! netdev )
523  goto err_netdev;
524 
525  /* Get network device path */
526  netpath = efi_netdev_path ( netdev );
527  if ( ! netpath )
528  goto err_netpath;
529 
530  /* Calculate device path length */
531  prefix_len = efi_path_len ( netpath );
532  name_len = ( strlen ( iscsi->target_iqn ) + 1 /* NUL */ );
533  iscsi_len = ( sizeof ( *iscsipath ) + name_len );
534  len = ( prefix_len + iscsi_len + sizeof ( *end ) );
535 
536  /* Allocate device path */
537  path = zalloc ( len );
538  if ( ! path )
539  goto err_alloc;
540 
541  /* Construct device path */
542  memcpy ( path, netpath, prefix_len );
543  iscsipath = ( ( ( void * ) path ) + prefix_len );
544  iscsipath->Header.Type = MESSAGING_DEVICE_PATH;
545  iscsipath->Header.SubType = MSG_ISCSI_DP;
546  iscsipath->Header.Length[0] = iscsi_len;
548  memcpy ( &iscsipath->Lun, &iscsi->lun, sizeof ( iscsipath->Lun ) );
549  name = ( ( ( void * ) iscsipath ) + sizeof ( *iscsipath ) );
550  memcpy ( name, iscsi->target_iqn, name_len );
551  end = ( ( ( void * ) name ) + name_len );
553 
554  /* Free temporary paths */
555  free ( netpath );
556 
557  return path;
558 
559  err_alloc:
560  free ( netpath );
561  err_netpath:
562  err_netdev:
563  return NULL;
564 }
TCP/IP socket address.
Definition: tcpip.h:76
const char * name
Definition: ath9k_hw.c:1986
struct net_device * tcpip_netdev(struct sockaddr_tcpip *st_dest)
Determine transmitting network device.
Definition: tcpip.c:115
#define ISCSI_LOGIN_OPTION_AUTHMETHOD_NON
Definition: DevicePath.h:960
struct sockaddr target_sockaddr
Target socket address (for boot firmware table)
Definition: iscsi.h:662
size_t efi_path_len(EFI_DEVICE_PATH_PROTOCOL *path)
Find length of device path (excluding terminator)
Definition: efi_path.c:174
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:46
UINT16 LoginOption
iSCSI Login Options.
Definition: DevicePath.h:938
#define MESSAGING_DEVICE_PATH
Messaging Device Paths.
Definition: DevicePath.h:324
static void efi_path_terminate(EFI_DEVICE_PATH_PROTOCOL *end)
Terminate device path.
Definition: efi_path.h:31
void * memcpy(void *dest, const void *src, size_t len) __nonnull
ring len
Length.
Definition: dwmac.h:231
static struct net_device * netdev
Definition: gdbudp.c:52
UINT64 Lun
iSCSI Logical Unit Number.
Definition: DevicePath.h:942
EFI_DEVICE_PATH_PROTOCOL end
Definition: efi_path.c:59
EFI_DEVICE_PATH_PROTOCOL * efi_netdev_path(struct net_device *netdev)
Construct EFI device path for network device.
Definition: efi_path.c:411
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
struct scsi_lun lun
SCSI LUN (for boot firmware table)
Definition: iscsi.h:664
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:662
A network device.
Definition: netdevice.h:353
#define MSG_ISCSI_DP
iSCSI Device Path SubType
Definition: DevicePath.h:928
size_t strlen(const char *src)
Get length of string.
Definition: string.c:244
char * target_iqn
Target IQN.
Definition: iscsi.h:563
UINT8 Length[2]
Specific Device Path data.
Definition: DevicePath.h:59
UINT8 SubType
Varies by Type 0xFF End Entire Device Path, or 0x01 End This Instance of a Device Path and start a ne...
Definition: DevicePath.h:54
UINT8 Type
0x01 Hardware Device Path.
Definition: DevicePath.h:47
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
EFI_DEVICE_PATH_PROTOCOL Header
Definition: DevicePath.h:930

References efi_netdev_path(), efi_path_len(), efi_path_terminate(), end, free, ISCSI_DEVICE_PATH::Header, ISCSI_LOGIN_OPTION_AUTHMETHOD_NON, len, EFI_DEVICE_PATH_PROTOCOL::Length, ISCSI_DEVICE_PATH::LoginOption, iscsi_session::lun, ISCSI_DEVICE_PATH::Lun, memcpy(), MESSAGING_DEVICE_PATH, MSG_ISCSI_DP, name, netdev, NULL, strlen(), EFI_DEVICE_PATH_PROTOCOL::SubType, iscsi_session::target_iqn, iscsi_session::target_sockaddr, tcpip_netdev(), EFI_DEVICE_PATH_PROTOCOL::Type, and zalloc().

◆ efi_aoe_path()

EFI_DEVICE_PATH_PROTOCOL* efi_aoe_path ( struct aoe_device aoedev)

Construct EFI device path for AoE device.

Parameters
aoedevAoE device
Return values
pathEFI device path, or NULL on error

Definition at line 572 of file efi_path.c.

572  {
573  struct {
574  SATA_DEVICE_PATH sata;
576  } satapath;
577  EFI_DEVICE_PATH_PROTOCOL *netpath;
579 
580  /* Get network device path */
581  netpath = efi_netdev_path ( aoedev->netdev );
582  if ( ! netpath )
583  goto err_netdev;
584 
585  /* Construct SATA path */
586  memset ( &satapath, 0, sizeof ( satapath ) );
587  satapath.sata.Header.Type = MESSAGING_DEVICE_PATH;
588  satapath.sata.Header.SubType = MSG_SATA_DP;
589  satapath.sata.Header.Length[0] = sizeof ( satapath.sata );
590  satapath.sata.HBAPortNumber = aoedev->major;
591  satapath.sata.PortMultiplierPortNumber = aoedev->minor;
592  efi_path_terminate ( &satapath.end );
593 
594  /* Construct overall device path */
595  path = efi_paths ( netpath, &satapath, NULL );
596  if ( ! path )
597  goto err_paths;
598 
599  /* Free temporary paths */
600  free ( netpath );
601 
602  return path;
603 
604  err_paths:
605  free ( netpath );
606  err_netdev:
607  return NULL;
608 }
uint16_t major
Major number.
Definition: aoe.h:126
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:46
#define MESSAGING_DEVICE_PATH
Messaging Device Paths.
Definition: DevicePath.h:324
static void efi_path_terminate(EFI_DEVICE_PATH_PROTOCOL *end)
Terminate device path.
Definition: efi_path.h:31
EFI_DEVICE_PATH_PROTOCOL * efi_paths(EFI_DEVICE_PATH_PROTOCOL *first,...)
Concatenate EFI device paths.
Definition: efi_path.c:344
#define MSG_SATA_DP
SATA Device Path SubType.
Definition: DevicePath.h:513
EFI_DEVICE_PATH_PROTOCOL end
Definition: efi_path.c:59
EFI_DEVICE_PATH_PROTOCOL * efi_netdev_path(struct net_device *netdev)
Construct EFI device path for network device.
Definition: efi_path.c:411
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
uint8_t minor
Minor number.
Definition: aoe.h:128
struct net_device * netdev
Network device.
Definition: aoe.h:121
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
void * memset(void *dest, int character, size_t len) __nonnull

References efi_netdev_path(), efi_path_terminate(), efi_paths(), end, free, aoe_device::major, memset(), MESSAGING_DEVICE_PATH, aoe_device::minor, MSG_SATA_DP, aoe_device::netdev, and NULL.

◆ efi_fcp_path()

EFI_DEVICE_PATH_PROTOCOL* efi_fcp_path ( struct fcp_description desc)

Construct EFI device path for Fibre Channel device.

Parameters
descFCP device description
Return values
pathEFI device path, or NULL on error

Definition at line 616 of file efi_path.c.

616  {
617  struct {
620  } __attribute__ (( packed )) *path;
621 
622  /* Allocate device path */
623  path = zalloc ( sizeof ( *path ) );
624  if ( ! path )
625  return NULL;
626 
627  /* Construct device path */
628  path->fc.Header.Type = MESSAGING_DEVICE_PATH;
629  path->fc.Header.SubType = MSG_FIBRECHANNELEX_DP;
630  path->fc.Header.Length[0] = sizeof ( path->fc );
631  memcpy ( path->fc.WWN, &desc->wwn, sizeof ( path->fc.WWN ) );
632  memcpy ( path->fc.Lun, &desc->lun, sizeof ( path->fc.Lun ) );
633  efi_path_terminate ( &path->end );
634 
635  return &path->fc.Header;
636 }
#define MSG_FIBRECHANNELEX_DP
Fibre Channel Ex SubType.
Definition: DevicePath.h:385
#define __attribute__(x)
Definition: compiler.h:10
u16 fc
802.11 Frame Control field
Definition: ieee80211.h:14
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:46
#define MESSAGING_DEVICE_PATH
Messaging Device Paths.
Definition: DevicePath.h:324
static void efi_path_terminate(EFI_DEVICE_PATH_PROTOCOL *end)
Terminate device path.
Definition: efi_path.h:31
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
void * memcpy(void *dest, const void *src, size_t len) __nonnull
EFI_DEVICE_PATH_PROTOCOL end
Definition: efi_path.c:59
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:662
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References __attribute__, desc, efi_path_terminate(), end, fc, memcpy(), MESSAGING_DEVICE_PATH, MSG_FIBRECHANNELEX_DP, NULL, and zalloc().

Referenced by fcpdev_efi_describe().

◆ efi_ib_srp_path()

EFI_DEVICE_PATH_PROTOCOL* efi_ib_srp_path ( struct ib_srp_device ib_srp)

Construct EFI device path for Infiniband SRP device.

Parameters
ib_srpInfiniband SRP device
Return values
pathEFI device path, or NULL on error

Definition at line 644 of file efi_path.c.

644  {
645  const struct ipxe_ib_sbft *sbft = &ib_srp->sbft;
646  union ib_srp_target_port_id *id =
648  srp );
649  EFI_DEVICE_PATH_PROTOCOL *parent;
651  INFINIBAND_DEVICE_PATH *ibpath;
653  size_t prefix_len;
654  size_t len;
655 
656  /* Get parent EFI device path */
657  parent = efi_parent_path ( ib_srp->ibdev->dev );
658 
659  /* Calculate device path length */
660  prefix_len = efi_path_len ( parent );
661  len = ( prefix_len + sizeof ( *ibpath ) + sizeof ( *end ) );
662 
663  /* Allocate device path */
664  path = zalloc ( len );
665  if ( ! path )
666  return NULL;
667 
668  /* Construct device path */
669  memcpy ( path, parent, prefix_len );
670  ibpath = ( ( ( void * ) path ) + prefix_len );
672  ibpath->Header.SubType = MSG_INFINIBAND_DP;
673  ibpath->Header.Length[0] = sizeof ( *ibpath );
675  memcpy ( ibpath->PortGid, &sbft->ib.dgid, sizeof ( ibpath->PortGid ) );
676  memcpy ( &ibpath->ServiceId, &sbft->ib.service_id,
677  sizeof ( ibpath->ServiceId ) );
678  memcpy ( &ibpath->TargetPortId, &id->ib.ioc_guid,
679  sizeof ( ibpath->TargetPortId ) );
680  memcpy ( &ibpath->DeviceId, &id->ib.id_ext,
681  sizeof ( ibpath->DeviceId ) );
682  end = ( ( ( void * ) ibpath ) + sizeof ( *ibpath ) );
684 
685  return path;
686 }
union srp_port_id srp
SRP version of port identifier.
Definition: ib_srp.h:35
struct ipxe_ib_sbft sbft
Boot firmware table parameters.
Definition: ib_srp.h:91
static EFI_DEVICE_PATH_PROTOCOL * efi_parent_path(struct device *dev)
Construct EFI parent device path.
Definition: efi_path.c:390
#define INFINIBAND_RESOURCE_FLAG_STORAGE_PROTOCOL
Definition: DevicePath.h:689
SRP target port identifier for Infiniband.
Definition: ib_srp.h:33
struct device * dev
Underlying device.
Definition: infiniband.h:411
union srp_port_id target
Target port identifier.
Definition: srp.h:820
size_t efi_path_len(EFI_DEVICE_PATH_PROTOCOL *path)
Find length of device path (excluding terminator)
Definition: efi_path.c:174
EFI_DEVICE_PATH_PROTOCOL Header
Definition: DevicePath.h:656
union ib_gid dgid
Destination GID.
Definition: ib_srp.h:52
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:46
#define MESSAGING_DEVICE_PATH
Messaging Device Paths.
Definition: DevicePath.h:324
UINT32 ResourceFlags
Flags to help identify/manage InfiniBand device path elements: Bit 0 - IOC/Service (0b = IOC,...
Definition: DevicePath.h:666
static void efi_path_terminate(EFI_DEVICE_PATH_PROTOCOL *end)
Terminate device path.
Definition: efi_path.h:31
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:36
ring len
Length.
Definition: dwmac.h:231
struct sbft_srp_subtable srp
The SRP subtable.
Definition: ib_srp.h:70
An Infiniband SRP sBFT created by iPXE.
Definition: ib_srp.h:64
EFI_DEVICE_PATH_PROTOCOL end
Definition: efi_path.c:59
union ib_guid service_id
Service ID.
Definition: ib_srp.h:54
uint8_t id
Request identifier.
Definition: ena.h:12
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:662
UINT64 DeviceId
64-bit persistent ID of remote device.
Definition: DevicePath.h:683
#define MSG_INFINIBAND_DP
InfiniBand Device Path SubType.
Definition: DevicePath.h:654
UINT64 TargetPortId
64-bit persistent ID of remote IOC port.
Definition: DevicePath.h:679
UINT64 ServiceId
64-bit unique identifier to remote IOC or server process.
Definition: DevicePath.h:675
UINT8 Length[2]
Specific Device Path data.
Definition: DevicePath.h:59
UINT8 PortGid[16]
128-bit Global Identifier for remote fabric port.
Definition: DevicePath.h:670
struct ib_device * ibdev
Infiniband device.
Definition: ib_srp.h:86
UINT8 SubType
Varies by Type 0xFF End Entire Device Path, or 0x01 End This Instance of a Device Path and start a ne...
Definition: DevicePath.h:54
struct sbft_ib_subtable ib
The Infiniband subtable.
Definition: ib_srp.h:72
UINT8 Type
0x01 Hardware Device Path.
Definition: DevicePath.h:47
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References container_of, ib_device::dev, INFINIBAND_DEVICE_PATH::DeviceId, sbft_ib_subtable::dgid, efi_parent_path(), efi_path_len(), efi_path_terminate(), end, INFINIBAND_DEVICE_PATH::Header, ipxe_ib_sbft::ib, ib_srp_device::ibdev, id, INFINIBAND_RESOURCE_FLAG_STORAGE_PROTOCOL, len, EFI_DEVICE_PATH_PROTOCOL::Length, memcpy(), MESSAGING_DEVICE_PATH, MSG_INFINIBAND_DP, NULL, INFINIBAND_DEVICE_PATH::PortGid, INFINIBAND_DEVICE_PATH::ResourceFlags, ib_srp_device::sbft, sbft_ib_subtable::service_id, INFINIBAND_DEVICE_PATH::ServiceId, ib_srp_target_port_id::srp, ipxe_ib_sbft::srp, EFI_DEVICE_PATH_PROTOCOL::SubType, sbft_srp_subtable::target, INFINIBAND_DEVICE_PATH::TargetPortId, EFI_DEVICE_PATH_PROTOCOL::Type, and zalloc().

◆ efi_usb_path()

EFI_DEVICE_PATH_PROTOCOL* efi_usb_path ( struct usb_function func)

Construct EFI device path for USB function.

Parameters
funcUSB function
Return values
pathEFI device path, or NULL on error

The caller is responsible for eventually calling free() on the allocated device path.

Definition at line 697 of file efi_path.c.

697  {
698  struct usb_device *usb = func->usb;
699  EFI_DEVICE_PATH_PROTOCOL *parent;
702  USB_DEVICE_PATH *usbpath;
703  unsigned int count;
704  size_t prefix_len;
705  size_t len;
706 
707  /* Sanity check */
708  assert ( func->desc.count >= 1 );
709 
710  /* Get parent EFI device path */
711  parent = efi_parent_path ( &func->dev );
712 
713  /* Calculate device path length */
714  count = ( usb_depth ( usb ) + 1 );
715  prefix_len = efi_path_len ( parent );
716  len = ( prefix_len + ( count * sizeof ( *usbpath ) ) +
717  sizeof ( *end ) );
718 
719  /* Allocate device path */
720  path = zalloc ( len );
721  if ( ! path )
722  return NULL;
723 
724  /* Construct device path */
725  memcpy ( path, parent, prefix_len );
726  end = ( ( ( void * ) path ) + len - sizeof ( *end ) );
728  usbpath = ( ( ( void * ) end ) - sizeof ( *usbpath ) );
729  usbpath->InterfaceNumber = func->interface[0];
730  for ( ; usb ; usbpath--, usb = usb->port->hub->usb ) {
731  usbpath->Header.Type = MESSAGING_DEVICE_PATH;
732  usbpath->Header.SubType = MSG_USB_DP;
733  usbpath->Header.Length[0] = sizeof ( *usbpath );
734  usbpath->ParentPortNumber = ( usb->port->address - 1 );
735  }
736 
737  return path;
738 }
uint8_t interface[0]
List of interface numbers.
Definition: usb.h:697
static EFI_DEVICE_PATH_PROTOCOL * efi_parent_path(struct device *dev)
Construct EFI parent device path.
Definition: efi_path.c:390
unsigned int count
Number of interfaces.
Definition: usb.h:665
size_t efi_path_len(EFI_DEVICE_PATH_PROTOCOL *path)
Find length of device path (excluding terminator)
Definition: efi_path.c:174
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:46
#define MESSAGING_DEVICE_PATH
Messaging Device Paths.
Definition: DevicePath.h:324
static void efi_path_terminate(EFI_DEVICE_PATH_PROTOCOL *end)
Terminate device path.
Definition: efi_path.h:31
struct usb_device * usb
Underlying USB device, if any.
Definition: usb.h:847
void * memcpy(void *dest, const void *src, size_t len) __nonnull
struct usb_port * port
USB port.
Definition: usb.h:727
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
ring len
Length.
Definition: dwmac.h:231
UINT8 ParentPortNumber
USB Parent Port Number.
Definition: DevicePath.h:427
static unsigned int count
Number of entries.
Definition: dwmac.h:225
EFI_DEVICE_PATH_PROTOCOL end
Definition: efi_path.c:59
A USB device.
Definition: usb.h:723
static unsigned int usb_depth(struct usb_device *usb)
Get USB depth.
Definition: usb.h:1269
EFI_DEVICE_PATH_PROTOCOL Header
Definition: DevicePath.h:423
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:662
UINT8 InterfaceNumber
USB Interface Number.
Definition: DevicePath.h:431
struct usb_device * usb
USB device.
Definition: usb.h:678
UINT8 Length[2]
Specific Device Path data.
Definition: DevicePath.h:59
struct usb_hub * hub
USB hub.
Definition: usb.h:815
UINT8 SubType
Varies by Type 0xFF End Entire Device Path, or 0x01 End This Instance of a Device Path and start a ne...
Definition: DevicePath.h:54
UINT8 Type
0x01 Hardware Device Path.
Definition: DevicePath.h:47
struct usb_function_descriptor desc
Function descriptor.
Definition: usb.h:680
struct device dev
Generic device.
Definition: usb.h:682
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
#define MSG_USB_DP
USB Device Path SubType.
Definition: DevicePath.h:421

References assert(), count, usb_function_descriptor::count, usb_function::desc, usb_function::dev, efi_parent_path(), efi_path_len(), efi_path_terminate(), end, USB_DEVICE_PATH::Header, usb_port::hub, usb_function::interface, USB_DEVICE_PATH::InterfaceNumber, len, EFI_DEVICE_PATH_PROTOCOL::Length, memcpy(), MESSAGING_DEVICE_PATH, MSG_USB_DP, NULL, USB_DEVICE_PATH::ParentPortNumber, usb_device::port, EFI_DEVICE_PATH_PROTOCOL::SubType, EFI_DEVICE_PATH_PROTOCOL::Type, usb_function::usb, usb_hub::usb, usb_depth(), and zalloc().

Referenced by efi_usb_install(), and usbblk_efi_describe().

◆ efi_load_path()

EFI_DEVICE_PATH_PROTOCOL* efi_load_path ( EFI_LOAD_OPTION load,
size_t  len 
)

Get EFI device path from load option.

Parameters
loadEFI load option
lenLength of EFI load option
Return values
pathEFI device path, or NULL on error

The caller is responsible for eventually calling free() on the allocated device path.

Definition at line 750 of file efi_path.c.

751  {
754  CHAR16 *wdesc;
755  size_t path_max;
756  size_t wmax;
757  size_t wlen;
758 
759  /* Check basic structure size */
760  if ( len < sizeof ( *load ) ) {
761  DBGC ( load, "EFI load option too short for header:\n" );
762  DBGC_HDA ( load, 0, load, len );
763  return NULL;
764  }
765 
766  /* Get length of description */
767  wdesc = ( ( ( void * ) load ) + sizeof ( *load ) );
768  wmax = ( ( len - sizeof ( *load ) ) / sizeof ( wdesc[0] ) );
769  wlen = wcsnlen ( wdesc, wmax );
770  if ( wlen == wmax ) {
771  DBGC ( load, "EFI load option has unterminated "
772  "description:\n" );
773  DBGC_HDA ( load, 0, load, len );
774  return NULL;
775  }
776 
777  /* Get inline device path */
778  path = ( ( ( void * ) load ) + sizeof ( *load ) +
779  ( wlen * sizeof ( wdesc[0] ) ) + 2 /* wNUL */ );
780  path_max = ( len - sizeof ( *load ) - ( wlen * sizeof ( wdesc[0] ) )
781  - 2 /* wNUL */ );
782  if ( load->FilePathListLength > path_max ) {
783  DBGC ( load, "EFI load option too short for path(s):\n" );
784  DBGC_HDA ( load, 0, load, len );
785  return NULL;
786  }
787 
788  /* Check path length */
789  if ( efi_path_check ( path, path_max ) != 0 ) {
790  DBGC ( load, "EFI load option has unterminated device "
791  "path:\n" );
792  DBGC_HDA ( load, 0, load, len );
793  return NULL;
794  }
795 
796  /* Allocate copy of path */
797  copy = malloc ( path_max );
798  if ( ! copy )
799  return NULL;
800  memcpy ( copy, path, path_max );
801 
802  return copy;
803 }
UINT16 FilePathListLength
Length in bytes of the FilePathList.
Definition: UefiSpec.h:2149
size_t wcsnlen(const wchar_t *string, size_t max)
Calculate length of wide-character string.
Definition: wchar.c:43
#define DBGC(...)
Definition: compiler.h:505
unsigned short CHAR16
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:46
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define DBGC_HDA(...)
Definition: compiler.h:506
int efi_path_check(EFI_DEVICE_PATH_PROTOCOL *path, size_t max)
Check that device path is well-formed.
Definition: efi_path.c:187
ring len
Length.
Definition: dwmac.h:231
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:621
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References DBGC, DBGC_HDA, efi_path_check(), _EFI_LOAD_OPTION::FilePathListLength, len, malloc(), memcpy(), NULL, and wcsnlen().

Referenced by efi_boot_path().

◆ efi_boot_path()

EFI_DEVICE_PATH_PROTOCOL* efi_boot_path ( unsigned int  number)

Get EFI device path for numbered boot option.

Parameters
numberBoot option number
Return values
pathEFI device path, or NULL on error

The caller is responsible for eventually calling free() on the allocated device path.

Definition at line 814 of file efi_path.c.

814  {
817  CHAR16 wname[ 9 /* "BootXXXX" + wNUL */ ];
818  EFI_LOAD_OPTION *load;
819  EFI_DEVICE_PATH *path;
820  UINT32 attrs;
821  UINTN size;
822  EFI_STATUS efirc;
823  int rc;
824 
825  /* Construct variable name */
826  efi_snprintf ( wname, ( sizeof ( wname ) / sizeof ( wname[0] ) ),
827  "Boot%04X", number );
828 
829  /* Get variable length */
830  size = 0;
831  if ( ( efirc = rs->GetVariable ( wname, guid, &attrs, &size,
832  NULL ) != EFI_BUFFER_TOO_SMALL ) ) {
833  rc = -EEFI ( efirc );
834  DBGC ( rs, "EFI could not get size of %ls: %s\n",
835  wname, strerror ( rc ) );
836  goto err_size;
837  }
838 
839  /* Allocate temporary buffer for EFI_LOAD_OPTION */
840  load = malloc ( size );
841  if ( ! load ) {
842  rc = -ENOMEM;
843  goto err_alloc;
844  }
845 
846  /* Read variable */
847  if ( ( efirc = rs->GetVariable ( wname, guid, &attrs, &size,
848  load ) != 0 ) ) {
849  rc = -EEFI ( efirc );
850  DBGC ( rs, "EFI could not read %ls: %s\n",
851  wname, strerror ( rc ) );
852  goto err_read;
853  }
854  DBGC2 ( rs, "EFI boot option %ls is:\n", wname );
855  DBGC2_HDA ( rs, 0, load, size );
856 
857  /* Get device path from load option */
858  path = efi_load_path ( load, size );
859  if ( ! path ) {
860  rc = -EINVAL;
861  DBGC ( rs, "EFI could not parse %ls: %s\n",
862  wname, strerror ( rc ) );
863  goto err_path;
864  }
865 
866  /* Free temporary buffer */
867  free ( load );
868 
869  return path;
870 
871  err_path:
872  err_read:
873  free ( load );
874  err_alloc:
875  err_size:
876  return NULL;
877 }
#define EINVAL
Invalid argument.
Definition: errno.h:429
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
128 bit buffer containing a unique identifier value.
Definition: Base.h:216
uint16_t size
Buffer size.
Definition: dwmac.h:14
#define DBGC(...)
Definition: compiler.h:505
unsigned int UINT32
Definition: ProcessorBind.h:99
unsigned short CHAR16
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:46
#define EFI_BUFFER_TOO_SMALL
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:120
#define ENOMEM
Not enough space.
Definition: errno.h:535
int efi_snprintf(wchar_t *wbuf, size_t wsize, const char *fmt,...)
Write a formatted string to a buffer.
Definition: efi_strings.c:107
EFI_GUID efi_global_variable
Global variable GUID.
Definition: efi_guid.c:469
EFI_GET_VARIABLE GetVariable
Definition: UefiSpec.h:1903
#define DBGC2_HDA(...)
Definition: compiler.h:523
EFI Runtime Services Table.
Definition: UefiSpec.h:1880
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
UINT64 UINTN
Unsigned value of native width.
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:621
uint64_t guid
GUID.
Definition: edd.h:31
EFI_RUNTIME_SERVICES * RuntimeServices
A pointer to the EFI Runtime Services Table.
Definition: UefiSpec.h:2095
#define DBGC2(...)
Definition: compiler.h:522
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:32
EFI_SYSTEM_TABLE * efi_systab
EFI_DEVICE_PATH_PROTOCOL * efi_load_path(EFI_LOAD_OPTION *load, size_t len)
Get EFI device path from load option.
Definition: efi_path.c:750
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References DBGC, DBGC2, DBGC2_HDA, EEFI, EFI_BUFFER_TOO_SMALL, efi_global_variable, efi_load_path(), efi_snprintf(), efi_systab, EINVAL, ENOMEM, free, EFI_RUNTIME_SERVICES::GetVariable, guid, malloc(), NULL, rc, EFI_SYSTEM_TABLE::RuntimeServices, size, and strerror().

Referenced by efi_current_boot_path().

◆ efi_current_boot_path()

EFI_DEVICE_PATH_PROTOCOL* efi_current_boot_path ( void  )

Get EFI device path for current boot option.

Return values
pathEFI device path, or NULL on error

The caller is responsible for eventually calling free() on the allocated device path.

Definition at line 887 of file efi_path.c.

887  {
890  CHAR16 wname[] = L"BootCurrent";
891  UINT16 current;
892  UINT32 attrs;
893  UINTN size;
894  EFI_STATUS efirc;
895  int rc;
896 
897  /* Read current boot option index */
898  size = sizeof ( current );
899  if ( ( efirc = rs->GetVariable ( wname, guid, &attrs, &size,
900  &current ) != 0 ) ) {
901  rc = -EEFI ( efirc );
902  DBGC ( rs, "EFI could not read %ls: %s\n",
903  wname, strerror ( rc ) );
904  return NULL;
905  }
906 
907  /* Get device path from this boot option */
908  return efi_boot_path ( current );
909 }
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
128 bit buffer containing a unique identifier value.
Definition: Base.h:216
uint16_t size
Buffer size.
Definition: dwmac.h:14
#define DBGC(...)
Definition: compiler.h:505
unsigned int UINT32
Definition: ProcessorBind.h:99
unsigned short CHAR16
EFI_DEVICE_PATH_PROTOCOL * efi_boot_path(unsigned int number)
Get EFI device path for numbered boot option.
Definition: efi_path.c:814
EFI_GUID efi_global_variable
Global variable GUID.
Definition: efi_guid.c:469
EFI_GET_VARIABLE GetVariable
Definition: UefiSpec.h:1903
unsigned short UINT16
EFI Runtime Services Table.
Definition: UefiSpec.h:1880
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
UINT64 UINTN
Unsigned value of native width.
uint64_t guid
GUID.
Definition: edd.h:31
EFI_RUNTIME_SERVICES * RuntimeServices
A pointer to the EFI Runtime Services Table.
Definition: UefiSpec.h:2095
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:32
EFI_SYSTEM_TABLE * efi_systab
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References DBGC, EEFI, efi_boot_path(), efi_global_variable, efi_systab, EFI_RUNTIME_SERVICES::GetVariable, guid, NULL, rc, EFI_SYSTEM_TABLE::RuntimeServices, size, and strerror().

Referenced by efi_init_application().

◆ efi_describe()

EFI_DEVICE_PATH_PROTOCOL* efi_describe ( struct interface intf)

Describe object as an EFI device path.

Parameters
intfInterface
Return values
pathEFI device path, or NULL

The caller is responsible for eventually calling free() on the allocated device path.

Definition at line 920 of file efi_path.c.

920  {
921  struct interface *dest;
922  efi_describe_TYPE ( void * ) *op =
924  void *object = intf_object ( dest );
926 
927  if ( op ) {
928  path = op ( object );
929  } else {
930  path = NULL;
931  }
932 
933  intf_put ( dest );
934  return path;
935 }
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:46
void * intf_object(struct interface *intf)
Get pointer to object containing object interface.
Definition: interface.c:160
struct interface * intf
Original interface.
Definition: interface.h:159
An object interface.
Definition: interface.h:125
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
EFI_DEVICE_PATH_PROTOCOL * efi_describe(struct interface *intf)
Describe object as an EFI device path.
Definition: efi_path.c:920
void intf_put(struct interface *intf)
Decrement reference count on an object interface.
Definition: interface.c:150
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" return dest
Definition: string.h:151
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
#define intf_get_dest_op(intf, type, dest)
Get object interface destination and operation method.
Definition: interface.h:270
#define efi_describe_TYPE(object_type)
Definition: efi_path.h:69

References dest, efi_describe(), efi_describe_TYPE, interface::intf, intf_get_dest_op, intf_object(), intf_put(), NULL, and op.

Referenced by efi_block_hook(), and efi_describe().

◆ efi_path_fetch_fixed()

static int efi_path_fetch_fixed ( struct efi_path_setting pathset,
EFI_DEVICE_PATH_PROTOCOL path,
void *  data,
size_t  len 
)
static

Fetch an EFI device path fixed-size setting.

Parameters
pathsetPath setting
pathDevice path
dataBuffer to fill with setting data
lenLength of buffer
Return values
lenLength of setting data, or negative error

Definition at line 946 of file efi_path.c.

948  {
949 
950  /* Copy data */
951  if ( len > pathset->len )
952  len = pathset->len;
953  memcpy ( data, ( ( ( void * ) path ) + pathset->offset ), len );
954 
955  return pathset->len;
956 }
uint8_t offset
Offset within device path.
Definition: efi_path.c:108
void * memcpy(void *dest, const void *src, size_t len) __nonnull
ring len
Length.
Definition: dwmac.h:231
uint8_t len
Length (if fixed)
Definition: efi_path.c:110
uint8_t data[48]
Additional event data.
Definition: ena.h:22

References data, efi_path_setting::len, len, memcpy(), and efi_path_setting::offset.

◆ efi_path_fetch_dns()

static int efi_path_fetch_dns ( struct efi_path_setting pathset,
EFI_DEVICE_PATH_PROTOCOL path,
void *  data,
size_t  len 
)
static

Fetch an EFI device path DNS setting.

Parameters
pathsetPath setting
pathDevice path
dataBuffer to fill with setting data
lenLength of buffer
Return values
lenLength of setting data, or negative error

Definition at line 967 of file efi_path.c.

969  {
971  unsigned int count;
972  unsigned int i;
973  size_t frag_len;
974 
975  /* Check applicability */
976  if ( ( !! dns->IsIPv6 ) !=
977  ( pathset->setting->type == &setting_type_ipv6 ) )
978  return -ENOENT;
979 
980  /* Calculate number of addresses */
981  count = ( ( ( ( path->Length[1] << 8 ) | path->Length[0] ) -
982  pathset->offset ) / sizeof ( dns->DnsServerIp[0] ) );
983 
984  /* Copy data */
985  for ( i = 0 ; i < count ; i++ ) {
986  frag_len = len;
987  if ( frag_len > pathset->len )
988  frag_len = pathset->len;
989  memcpy ( data, &dns->DnsServerIp[i], frag_len );
990  data += frag_len;
991  len -= frag_len;
992  }
993 
994  return ( count * pathset->len );
995 }
uint8_t offset
Offset within device path.
Definition: efi_path.c:108
#define ENOENT
No such file or directory.
Definition: errno.h:515
EFI_IP_ADDRESS DnsServerIp[]
Instance of the DNS server address.
Definition: DevicePath.h:876
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:36
ring len
Length.
Definition: dwmac.h:231
static unsigned int count
Number of entries.
Definition: dwmac.h:225
const struct setting_type * type
Setting type.
Definition: settings.h:37
uint8_t len
Length (if fixed)
Definition: efi_path.c:110
UINT8 Length[2]
Specific Device Path data.
Definition: DevicePath.h:59
const struct setting * setting
Setting.
Definition: efi_path.c:90
uint8_t data[48]
Additional event data.
Definition: ena.h:22
UINT8 IsIPv6
Indicates the DNS server address is IPv4 or IPv6 address.
Definition: DevicePath.h:872
PACKED union @541::@555 Header
Definition: Acpi10.h:156

References container_of, count, data, DNS_DEVICE_PATH::DnsServerIp, ENOENT, Header, DNS_DEVICE_PATH::IsIPv6, efi_path_setting::len, len, EFI_DEVICE_PATH_PROTOCOL::Length, memcpy(), efi_path_setting::offset, efi_path_setting::setting, and setting::type.

◆ efi_path_fetch()

static int efi_path_fetch ( struct settings settings,
struct setting setting,
void *  data,
size_t  len 
)
static

Fetch value of EFI device path setting.

Parameters
settingsSettings block
settingSetting to fetch
dataBuffer to fill with setting data
lenLength of buffer
Return values
lenLength of setting data, or negative error

Definition at line 1034 of file efi_path.c.

1035  {
1036  struct efi_path_settings *pathsets =
1038  EFI_DEVICE_PATH_PROTOCOL *path = pathsets->path;
1040  struct efi_path_setting *pathset;
1041  unsigned int i;
1042  int ret;
1043 
1044  /* Find matching path setting, if any */
1045  for ( i = 0 ; i < ( sizeof ( efi_path_settings ) /
1046  sizeof ( efi_path_settings[0] ) ) ; i++ ) {
1047 
1048  /* Check for a matching setting */
1049  pathset = &efi_path_settings[i];
1050  if ( setting_cmp ( setting, pathset->setting ) != 0 )
1051  continue;
1052 
1053  /* Find matching device path element, if any */
1054  for ( ; ( next = efi_path_next ( path ) ) ; path = next ) {
1055 
1056  /* Check for a matching path type */
1057  if ( ( path->Type != pathset->type ) ||
1058  ( path->SubType != pathset->subtype ) )
1059  continue;
1060 
1061  /* Fetch value */
1062  if ( ( ret = pathset->fetch ( pathset, path,
1063  data, len ) ) < 0 )
1064  return ret;
1065 
1066  /* Apply default type, if not already set */
1067  if ( ! setting->type )
1068  setting->type = pathset->setting->type;
1069 
1070  return ret;
1071  }
1072  break;
1073  }
1074 
1075  return -ENOENT;
1076 }
int(* fetch)(struct efi_path_setting *pathset, EFI_DEVICE_PATH_PROTOCOL *path, void *data, size_t len)
Fetch setting.
Definition: efi_path.c:100
EFI_DEVICE_PATH_PROTOCOL * path
Device path.
Definition: efi_path.c:84
#define ENOENT
No such file or directory.
Definition: errno.h:515
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:46
An EFI device path settings block.
Definition: efi_path.c:80
uint8_t type
Path type.
Definition: efi_path.c:104
An EFI device path setting.
Definition: efi_path.c:88
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:36
ring len
Length.
Definition: dwmac.h:231
const struct setting_type * type
Setting type.
Definition: settings.h:37
A settings block.
Definition: settings.h:133
uint32_t next
Next descriptor address.
Definition: dwmac.h:22
EFI_DEVICE_PATH_PROTOCOL * efi_path_next(EFI_DEVICE_PATH_PROTOCOL *path)
Find next element in device path.
Definition: efi_path.c:119
A setting.
Definition: settings.h:24
static struct efi_path_setting efi_path_settings[]
EFI device path settings.
Definition: efi_path.c:998
UINT8 SubType
Varies by Type 0xFF End Entire Device Path, or 0x01 End This Instance of a Device Path and start a ne...
Definition: DevicePath.h:54
const struct setting * setting
Setting.
Definition: efi_path.c:90
uint8_t data[48]
Additional event data.
Definition: ena.h:22
UINT8 Type
0x01 Hardware Device Path.
Definition: DevicePath.h:47
uint8_t subtype
Path subtype.
Definition: efi_path.c:106
int setting_cmp(const struct setting *a, const struct setting *b)
Compare two settings.
Definition: settings.c:1121

References container_of, data, efi_path_next(), efi_path_settings, ENOENT, efi_path_setting::fetch, len, next, efi_path_settings::path, efi_path_setting::setting, setting_cmp(), EFI_DEVICE_PATH_PROTOCOL::SubType, efi_path_setting::subtype, setting::type, EFI_DEVICE_PATH_PROTOCOL::Type, and efi_path_setting::type.

◆ efi_path_net_probe()

static int efi_path_net_probe ( struct net_device netdev,
void *  priv 
)
static

Create per-netdevice EFI path settings.

Parameters
netdevNetwork device
privPrivate data
Return values
rcReturn status code

Definition at line 1090 of file efi_path.c.

1090  {
1091  struct efi_path_settings *pathsets = priv;
1092  struct settings *settings = &pathsets->settings;
1094  unsigned int vlan;
1095  void *mac;
1096  int rc;
1097 
1098  /* Check applicability */
1099  pathsets->path = path;
1100  mac = efi_path_mac ( path );
1101  vlan = efi_path_vlan ( path );
1102  if ( ( mac == NULL ) ||
1103  ( memcmp ( mac, netdev->ll_addr,
1104  netdev->ll_protocol->ll_addr_len ) != 0 ) ||
1105  ( vlan != vlan_tag ( netdev ) ) ) {
1106  DBGC ( settings, "EFI path %s does not apply to %s\n",
1107  efi_devpath_text ( path ), netdev->name );
1108  return 0;
1109  }
1110 
1111  /* Never override a real DHCP settings block */
1113  DHCP_SETTINGS_NAME ) ) {
1114  DBGC ( settings, "EFI path %s not overriding %s DHCP "
1115  "settings\n", efi_devpath_text ( path ), netdev->name );
1116  return 0;
1117  }
1118 
1119  /* Initialise and register settings */
1121  &netdev->refcnt, NULL );
1123  DHCP_SETTINGS_NAME ) ) != 0 ) {
1124  DBGC ( settings, "EFI path %s could not register for %s: %s\n",
1125  efi_devpath_text ( path ), netdev->name,
1126  strerror ( rc ) );
1127  return rc;
1128  }
1129  DBGC ( settings, "EFI path %s registered for %s\n",
1130  efi_devpath_text ( path ), netdev->name );
1131 
1132  return 0;
1133 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned int efi_path_vlan(EFI_DEVICE_PATH_PROTOCOL *path)
Get VLAN tag from device path.
Definition: efi_path.c:237
uint8_t ll_addr_len
Link-layer address length.
Definition: netdevice.h:199
#define DBGC(...)
Definition: compiler.h:505
EFI_DEVICE_PATH_PROTOCOL * path
Device path.
Definition: efi_path.c:84
static struct settings_operations efi_path_settings_operations
EFI device path settings operations.
Definition: efi_path.c:1079
struct settings settings
Settings interface.
Definition: efi_path.c:82
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:46
uint8_t mac[ETH_ALEN]
MAC address.
Definition: ena.h:24
An EFI device path settings block.
Definition: efi_path.c:80
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:587
static void settings_init(struct settings *settings, struct settings_operations *op, struct refcnt *refcnt, const struct settings_scope *default_scope)
Initialise a settings block.
Definition: settings.h:503
EFI_DEVICE_PATH_PROTOCOL * efi_loaded_image_path
Device path for the loaded image's device handle.
Definition: efi_init.c:42
#define DHCP_SETTINGS_NAME
Settings block name used for DHCP responses.
Definition: dhcp.h:711
static struct net_device * netdev
Definition: gdbudp.c:52
void * efi_path_mac(EFI_DEVICE_PATH_PROTOCOL *path)
Get MAC address from device path.
Definition: efi_path.c:213
const char * efi_devpath_text(EFI_DEVICE_PATH_PROTOCOL *path)
Get textual representation of device path.
Definition: efi_debug.c:247
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
struct refcnt refcnt
Reference counter.
Definition: netdevice.h:355
A settings block.
Definition: settings.h:133
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:363
static struct tlan_private * priv
Definition: tlan.c:225
int register_settings(struct settings *settings, struct settings *parent, const char *name)
Register settings block.
Definition: settings.c:476
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:388
static unsigned int vlan_tag(struct net_device *netdev)
Get the VLAN tag.
Definition: vlan.h:74
struct settings * find_child_settings(struct settings *parent, const char *name)
Find child settings block.
Definition: settings.c:280
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:115
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:373

References DBGC, DHCP_SETTINGS_NAME, efi_devpath_text(), efi_loaded_image_path, efi_path_mac(), efi_path_settings_operations, efi_path_vlan(), find_child_settings(), net_device::ll_addr, ll_protocol::ll_addr_len, net_device::ll_protocol, mac, memcmp(), net_device::name, netdev, netdev_settings(), NULL, efi_path_settings::path, priv, rc, net_device::refcnt, register_settings(), efi_path_settings::settings, settings_init(), strerror(), and vlan_tag().

Variable Documentation

◆ bbs

Definition at line 57 of file efi_path.c.

◆ tring

CHAR8 tring[4]

Definition at line 58 of file efi_path.c.

◆ end

◆ efi_dummy_parent_path

struct { ... } efi_dummy_parent_path
Initial value:
= {
.bbs = {
.Header = {
.Type = BBS_DEVICE_PATH,
.SubType = BBS_BBS_DP,
.Length[0] = ( sizeof ( efi_dummy_parent_path.bbs ) +
sizeof ( efi_dummy_parent_path.tring )),
},
.DeviceType = BBS_TYPE_UNKNOWN,
.String[0] = 'i',
},
.tring = "PXE",
.end = {
.Length[0] = sizeof ( efi_dummy_parent_path.end ),
},
}
#define BBS_BBS_DP
BIOS Boot Specification Device Path SubType.
Definition: DevicePath.h:1241
#define END_DEVICE_PATH_TYPE
Definition: DevicePath.h:1394
#define BBS_TYPE_UNKNOWN
Definition: DevicePath.h:1272
static struct @438 efi_dummy_parent_path
Dummy parent device path.
#define BBS_DEVICE_PATH
BIOS Boot Specification Device Path.
Definition: DevicePath.h:1236
#define END_ENTIRE_DEVICE_PATH_SUBTYPE
Definition: DevicePath.h:1395

Dummy parent device path.

This is used as the parent device path when we need to construct a path for a device that has no EFI parent device.

Referenced by efi_parent_path().

◆ efi_path_settings

Initial value:
= {
MSG_IPv4_DP, offsetof ( IPv4_DEVICE_PATH, LocalIpAddress ),
sizeof ( struct in_addr ) },
sizeof ( struct in_addr ) },
MSG_IPv4_DP, offsetof ( IPv4_DEVICE_PATH, GatewayIpAddress ),
sizeof ( struct in_addr ) },
MSG_IPv6_DP, offsetof ( IPv6_DEVICE_PATH, LocalIpAddress ),
sizeof ( struct in6_addr ) },
sizeof ( uint8_t ) },
MSG_IPv6_DP, offsetof ( IPv6_DEVICE_PATH, GatewayIpAddress ),
sizeof ( struct in6_addr ) },
MSG_DNS_DP, offsetof ( DNS_DEVICE_PATH, DnsServerIp ),
sizeof ( struct in_addr ) },
MSG_DNS_DP, offsetof ( DNS_DEVICE_PATH, DnsServerIp ),
sizeof ( struct in6_addr ) },
}
static int efi_path_fetch_fixed(struct efi_path_setting *pathset, EFI_DEVICE_PATH_PROTOCOL *path, void *data, size_t len)
Fetch an EFI device path fixed-size setting.
Definition: efi_path.c:946
#define offsetof(type, field)
Get offset of a field within a structure.
Definition: stddef.h:25
#define MESSAGING_DEVICE_PATH
Messaging Device Paths.
Definition: DevicePath.h:324
IP6 address structure.
Definition: in.h:51
#define MSG_IPv4_DP
IPv4 Device Path SubType.
Definition: DevicePath.h:569
IP address structure.
Definition: in.h:42
#define MSG_IPv6_DP
IPv6 Device Path SubType.
Definition: DevicePath.h:610
unsigned char uint8_t
Definition: stdint.h:10
#define MSG_DNS_DP
DNS Device Path SubType.
Definition: DevicePath.h:866
static int efi_path_fetch_dns(struct efi_path_setting *pathset, EFI_DEVICE_PATH_PROTOCOL *path, void *data, size_t len)
Fetch an EFI device path DNS setting.
Definition: efi_path.c:967

EFI device path settings.

Definition at line 998 of file efi_path.c.

Referenced by efi_path_fetch().

◆ efi_path_settings_operations

struct settings_operations efi_path_settings_operations
static
Initial value:
= {
.fetch = efi_path_fetch,
}
static int efi_path_fetch(struct settings *settings, struct setting *setting, void *data, size_t len)
Fetch value of EFI device path setting.
Definition: efi_path.c:1034

EFI device path settings operations.

Definition at line 1079 of file efi_path.c.

Referenced by efi_path_net_probe().

◆ __net_driver

struct net_driver efi_path_net_driver __net_driver
Initial value:
= {
.name = "EFI path",
.priv_len = sizeof ( struct efi_path_settings ),
}
An EFI device path settings block.
Definition: efi_path.c:80
static int efi_path_net_probe(struct net_device *netdev, void *priv)
Create per-netdevice EFI path settings.
Definition: efi_path.c:1090

EFI path settings per-netdevice driver.

Definition at line 1136 of file efi_path.c.