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_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)
 
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...
 
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...
 
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_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

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  )

◆ 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 89 of file efi_path.c.

89  {
90 
91  /* Check for non-existent device path */
92  if ( ! path )
93  return NULL;
94 
95  /* Check for end of device path */
96  if ( path->Type == END_DEVICE_PATH_TYPE )
97  return NULL;
98 
99  /* Move to next component of the device path */
100  path = ( ( ( void * ) path ) +
101  /* There's this amazing new-fangled thing known as
102  * a UINT16, but who wants to use one of those? */
103  ( ( path->Length[1] << 8 ) | path->Length[0] ) );
104 
105  return path;
106 }
#define END_DEVICE_PATH_TYPE
Definition: DevicePath.h:1371
UINT8 Length[2]
Specific Device Path data.
Definition: DevicePath.h:58
UINT8 Type
0x01 Hardware Device Path.
Definition: DevicePath.h:46
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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_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 115 of file efi_path.c.

116  {
118 
119  /* Find immediately preceding element */
120  while ( ( tmp = efi_path_next ( path ) ) != curr ) {
121  path = tmp;
122  }
123 
124  return path;
125 }
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:45
unsigned long tmp
Definition: linux_pci.h:53
EFI_DEVICE_PATH_PROTOCOL * efi_path_next(EFI_DEVICE_PATH_PROTOCOL *path)
Find next element in device path.
Definition: efi_path.c:89

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 133 of file efi_path.c.

133  {
134 
135  return efi_path_prev ( path, NULL );
136 }
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:115
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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 144 of file efi_path.c.

144  {
146 
147  return ( ( ( void * ) end ) - ( ( void * ) path ) );
148 }
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:45
uint32_t end
Ending offset.
Definition: netvsc.h:18
EFI_DEVICE_PATH_PROTOCOL * efi_path_end(EFI_DEVICE_PATH_PROTOCOL *path)
Find end of device path.
Definition: efi_path.c:133

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_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 156 of file efi_path.c.

156  {
159 
160  /* Search for MAC address path */
161  for ( ; ( next = efi_path_next ( path ) ) ; path = next ) {
162  if ( ( path->Type == MESSAGING_DEVICE_PATH ) &&
163  ( path->SubType == MSG_MAC_ADDR_DP ) ) {
165  Header );
166  return &mac->MacAddress;
167  }
168  }
169 
170  /* No MAC address found */
171  return NULL;
172 }
uint32_t next
Next descriptor address.
Definition: myson.h:18
#define MSG_MAC_ADDR_DP
MAC Address Device Path SubType.
Definition: DevicePath.h:552
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:45
uint8_t mac[ETH_ALEN]
MAC address.
Definition: ena.h:24
#define MESSAGING_DEVICE_PATH
Messaging Device Paths.
Definition: DevicePath.h:323
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
EFI_DEVICE_PATH_PROTOCOL * efi_path_next(EFI_DEVICE_PATH_PROTOCOL *path)
Find next element in device path.
Definition: efi_path.c:89
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:53
UINT8 Type
0x01 Hardware Device Path.
Definition: DevicePath.h:46
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
PACKED union @478::@492 Header
Definition: Acpi10.h:155

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 180 of file efi_path.c.

180  {
182  VLAN_DEVICE_PATH *vlan;
183 
184  /* Search for VLAN device path */
185  for ( ; ( next = efi_path_next ( path ) ) ; path = next ) {
186  if ( ( path->Type == MESSAGING_DEVICE_PATH ) &&
187  ( path->SubType == MSG_VLAN_DP ) ) {
188  vlan = container_of ( path, VLAN_DEVICE_PATH, Header );
189  return vlan->VlanId;
190  }
191  }
192 
193  /* No VLAN device path found */
194  return 0;
195 }
uint32_t next
Next descriptor address.
Definition: myson.h:18
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:45
#define MESSAGING_DEVICE_PATH
Messaging Device Paths.
Definition: DevicePath.h:323
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
UINT16 VlanId
VLAN identifier (0-4094).
Definition: DevicePath.h:952
EFI_DEVICE_PATH_PROTOCOL * efi_path_next(EFI_DEVICE_PATH_PROTOCOL *path)
Find next element in device path.
Definition: efi_path.c:89
#define MSG_VLAN_DP
VLAN Device Path SubType.
Definition: DevicePath.h:946
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:53
UINT8 Type
0x01 Hardware Device Path.
Definition: DevicePath.h:46
PACKED union @478::@492 Header
Definition: Acpi10.h:155

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 204 of file efi_path.c.

204  {
207  int rc;
208 
209  /* Search for most specific partition device path */
210  rc = -ENOENT;
211  for ( ; ( next = efi_path_next ( path ) ) ; path = next ) {
212 
213  /* Skip non-harddrive device paths */
214  if ( path->Type != MEDIA_DEVICE_PATH )
215  continue;
216  if ( path->SubType != MEDIA_HARDDRIVE_DP )
217  continue;
218 
219  /* Skip non-GUID signatures */
220  hd = container_of ( path, HARDDRIVE_DEVICE_PATH, Header );
221  if ( hd->SignatureType != SIGNATURE_TYPE_GUID )
222  continue;
223 
224  /* Extract GUID */
225  memcpy ( guid, hd->Signature, sizeof ( *guid ) );
226  uuid_mangle ( guid );
227 
228  /* Record success, but continue searching in case
229  * there exists a more specific GUID (e.g. a partition
230  * GUID rather than a disk GUID).
231  */
232  rc = 0;
233  }
234 
235  return rc;
236 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint32_t next
Next descriptor address.
Definition: myson.h:18
UINT8 SignatureType
Type of Disk Signature: (Unused values reserved).
Definition: DevicePath.h:1038
#define ENOENT
No such file or directory.
Definition: errno.h:514
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:45
static void uuid_mangle(union uuid *uuid)
Change UUID endianness.
Definition: uuid.h:43
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
#define MEDIA_HARDDRIVE_DP
Hard Drive Media Device Path SubType.
Definition: DevicePath.h:996
#define MEDIA_DEVICE_PATH
Definition: DevicePath.h:991
EFI_DEVICE_PATH_PROTOCOL * efi_path_next(EFI_DEVICE_PATH_PROTOCOL *path)
Find next element in device path.
Definition: efi_path.c:89
uint64_t guid
GUID.
Definition: edd.h:30
UINT8 Signature[16]
Signature unique to this partition: If SignatureType is 0, this field has to be initialized with 16 z...
Definition: DevicePath.h:1025
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:53
The Hard Drive Media Device Path is used to represent a partition on a hard drive.
Definition: DevicePath.h:1001
UINT8 Type
0x01 Hardware Device Path.
Definition: DevicePath.h:46
#define SIGNATURE_TYPE_GUID
Definition: DevicePath.h:1046
PACKED union @478::@492 Header
Definition: Acpi10.h:155

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 244 of file efi_path.c.

244  {
246  URI_DEVICE_PATH *uripath;
247  char *uristring;
248  struct uri *uri;
249  size_t len;
250 
251  /* Search for URI device path */
252  for ( ; ( next = efi_path_next ( path ) ) ; path = next ) {
253  if ( ( path->Type == MESSAGING_DEVICE_PATH ) &&
254  ( path->SubType == MSG_URI_DP ) ) {
255 
256  /* Calculate path length */
257  uripath = container_of ( path, URI_DEVICE_PATH,
258  Header );
259  len = ( ( ( path->Length[1] << 8 ) | path->Length[0] )
260  - offsetof ( typeof ( *uripath ), Uri ) );
261 
262  /* Parse URI */
263  uristring = zalloc ( len + 1 /* NUL */ );
264  if ( ! uristring )
265  return NULL;
266  memcpy ( uristring, uripath->Uri, len );
267  uri = parse_uri ( uristring );
268  free ( uristring );
269 
270  return uri;
271  }
272  }
273 
274  /* No URI path found */
275  return NULL;
276 }
uint32_t next
Next descriptor address.
Definition: myson.h:18
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:45
#define offsetof(type, field)
Get offset of a field within a structure.
Definition: stddef.h:24
#define MESSAGING_DEVICE_PATH
Messaging Device Paths.
Definition: DevicePath.h:323
#define MSG_URI_DP
Uniform Resource Identifiers (URI) Device Path SubType.
Definition: DevicePath.h:861
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
const char * path
Path (after URI decoding)
Definition: uri.h:80
CHAR8 Uri[]
Instance of the URI pursuant to RFC 3986.
Definition: DevicePath.h:867
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
EFI_DEVICE_PATH_PROTOCOL * efi_path_next(EFI_DEVICE_PATH_PROTOCOL *path)
Find next element in device path.
Definition: efi_path.c:89
uint32_t len
Length.
Definition: ena.h:14
A Uniform Resource Identifier.
Definition: uri.h:64
typeof(acpi_finder=acpi_find)
ACPI table finder.
Definition: acpi.c:45
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct uri * parse_uri(const char *uri_string)
Parse URI.
Definition: uri.c:296
PACKED union @478::@492 Header
Definition: Acpi10.h:155

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 287 of file efi_path.c.

287  {
292  va_list args;
293  size_t len;
294 
295  /* Calculate device path length */
296  va_start ( args, first );
297  len = 0;
298  src = first;
299  while ( src ) {
300  len += efi_path_len ( src );
301  src = va_arg ( args, EFI_DEVICE_PATH_PROTOCOL * );
302  }
303  va_end ( args );
304 
305  /* Allocate device path */
306  path = zalloc ( len + sizeof ( *end ) );
307  if ( ! path )
308  return NULL;
309 
310  /* Populate device path */
311  va_start ( args, first );
312  dst = path;
313  src = first;
314  while ( src ) {
315  len = efi_path_len ( src );
316  memcpy ( dst, src, len );
317  dst = ( ( ( void * ) dst ) + len );
318  src = va_arg ( args, EFI_DEVICE_PATH_PROTOCOL * );
319  }
320  va_end ( args );
321  end = dst;
323 
324  return path;
325 }
#define va_end(ap)
Definition: stdarg.h:9
static void const void void * dst
Definition: crypto.h:244
static void const void * src
Definition: crypto.h:244
size_t efi_path_len(EFI_DEVICE_PATH_PROTOCOL *path)
Find length of device path (excluding terminator)
Definition: efi_path.c:144
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:45
static void efi_path_terminate(EFI_DEVICE_PATH_PROTOCOL *end)
Terminate device path.
Definition: efi_path.h:30
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define va_arg(ap, type)
Definition: stdarg.h:8
const char * path
Path (after URI decoding)
Definition: uri.h:80
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
uint32_t len
Length.
Definition: ena.h:14
__builtin_va_list va_list
Definition: stdarg.h:6
uint32_t end
Ending offset.
Definition: netvsc.h:18
#define va_start(ap, last)
Definition: stdarg.h:7
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
uint32_t first
Length to skip in first segment.
Definition: pccrc.h:23

References dst, 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_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 336 of file efi_path.c.

336  {
337  struct efi_device *efidev;
339  MAC_ADDR_DEVICE_PATH *macpath;
340  VLAN_DEVICE_PATH *vlanpath;
342  unsigned int tag;
343  size_t prefix_len;
344  size_t len;
345 
346  /* Find parent EFI device */
347  efidev = efidev_parent ( netdev->dev );
348  if ( ! efidev )
349  return NULL;
350 
351  /* Calculate device path length */
352  prefix_len = efi_path_len ( efidev->path );
353  len = ( prefix_len + sizeof ( *macpath ) + sizeof ( *vlanpath ) +
354  sizeof ( *end ) );
355 
356  /* Allocate device path */
357  path = zalloc ( len );
358  if ( ! path )
359  return NULL;
360 
361  /* Construct device path */
362  memcpy ( path, efidev->path, prefix_len );
363  macpath = ( ( ( void * ) path ) + prefix_len );
364  macpath->Header.Type = MESSAGING_DEVICE_PATH;
365  macpath->Header.SubType = MSG_MAC_ADDR_DP;
366  macpath->Header.Length[0] = sizeof ( *macpath );
368  sizeof ( macpath->MacAddress ) );
369  memcpy ( &macpath->MacAddress, netdev->ll_addr,
371  macpath->IfType = ntohs ( netdev->ll_protocol->ll_proto );
372  if ( ( tag = vlan_tag ( netdev ) ) ) {
373  vlanpath = ( ( ( void * ) macpath ) + sizeof ( *macpath ) );
374  vlanpath->Header.Type = MESSAGING_DEVICE_PATH;
375  vlanpath->Header.SubType = MSG_VLAN_DP;
376  vlanpath->Header.Length[0] = sizeof ( *vlanpath );
377  vlanpath->VlanId = tag;
378  end = ( ( ( void * ) vlanpath ) + sizeof ( *vlanpath ) );
379  } else {
380  end = ( ( ( void * ) macpath ) + sizeof ( *macpath ) );
381  }
383 
384  return path;
385 }
uint8_t ll_addr_len
Link-layer address length.
Definition: netdevice.h:198
UINT8 IfType
Network interface type(i.e.
Definition: DevicePath.h:562
EFI_MAC_ADDRESS MacAddress
The MAC address for a network interface padded with 0s.
Definition: DevicePath.h:558
#define MSG_MAC_ADDR_DP
MAC Address Device Path SubType.
Definition: DevicePath.h:552
size_t efi_path_len(EFI_DEVICE_PATH_PROTOCOL *path)
Find length of device path (excluding terminator)
Definition: efi_path.c:144
#define ntohs(value)
Definition: byteswap.h:136
EFI_DEVICE_PATH_PROTOCOL Header
Definition: DevicePath.h:554
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:45
#define MESSAGING_DEVICE_PATH
Messaging Device Paths.
Definition: DevicePath.h:323
static void efi_path_terminate(EFI_DEVICE_PATH_PROTOCOL *end)
Terminate device path.
Definition: efi_path.h:30
void * memcpy(void *dest, const void *src, size_t len) __nonnull
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static struct net_device * netdev
Definition: gdbudp.c:52
UINT16 VlanId
VLAN identifier (0-4094).
Definition: DevicePath.h:952
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
An EFI device.
Definition: efi_driver.h:17
uint16_t ll_proto
Link-layer protocol.
Definition: netdevice.h:194
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
#define MSG_VLAN_DP
VLAN Device Path SubType.
Definition: DevicePath.h:946
EFI_DEVICE_PATH_PROTOCOL Header
Definition: DevicePath.h:948
UINT8 Length[2]
Specific Device Path data.
Definition: DevicePath.h:58
uint32_t len
Length.
Definition: ena.h:14
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:53
uint32_t end
Ending offset.
Definition: netvsc.h:18
UINT8 Type
0x01 Hardware Device Path.
Definition: DevicePath.h:46
EFI_DEVICE_PATH_PROTOCOL * path
EFI device path copy.
Definition: efi_driver.h:25
struct efi_device * efidev_parent(struct device *dev)
Get parent EFI device.
Definition: efi_driver.c:155
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387
static unsigned int vlan_tag(struct net_device *netdev)
Get the VLAN tag.
Definition: vlan.h:73
uint64_t tag
Identity tag.
Definition: edd.h:30
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372

References assert(), net_device::dev, efi_path_len(), efi_path_terminate(), efidev_parent(), 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 396 of file efi_path.c.

396  {
399  URI_DEVICE_PATH *uripath;
400  size_t uri_len;
401  size_t uripath_len;
402  size_t len;
403 
404  /* Calculate device path length */
405  uri_len = ( format_uri ( uri, NULL, 0 ) + 1 /* NUL */ );
406  uripath_len = ( sizeof ( *uripath ) + uri_len );
407  len = ( uripath_len + sizeof ( *end ) );
408 
409  /* Allocate device path */
410  path = zalloc ( len );
411  if ( ! path )
412  return NULL;
413 
414  /* Construct device path */
415  uripath = ( ( void * ) path );
416  uripath->Header.Type = MESSAGING_DEVICE_PATH;
417  uripath->Header.SubType = MSG_URI_DP;
418  uripath->Header.Length[0] = ( uripath_len & 0xff );
419  uripath->Header.Length[1] = ( uripath_len >> 8 );
420  format_uri ( uri, uripath->Uri, uri_len );
421  end = ( ( ( void * ) path ) + uripath_len );
423 
424  return path;
425 }
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:45
#define MESSAGING_DEVICE_PATH
Messaging Device Paths.
Definition: DevicePath.h:323
static void efi_path_terminate(EFI_DEVICE_PATH_PROTOCOL *end)
Terminate device path.
Definition: efi_path.h:30
#define MSG_URI_DP
Uniform Resource Identifiers (URI) Device Path SubType.
Definition: DevicePath.h:861
EFI_DEVICE_PATH_PROTOCOL Header
Definition: DevicePath.h:863
size_t format_uri(const struct uri *uri, char *buf, size_t len)
Format URI.
Definition: uri.c:471
CHAR8 Uri[]
Instance of the URI pursuant to RFC 3986.
Definition: DevicePath.h:867
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
UINT8 Length[2]
Specific Device Path data.
Definition: DevicePath.h:58
uint32_t len
Length.
Definition: ena.h:14
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:53
uint32_t end
Ending offset.
Definition: netvsc.h:18
UINT8 Type
0x01 Hardware Device Path.
Definition: DevicePath.h:46
A Uniform Resource Identifier.
Definition: uri.h:64
EFI_DEVICE_PATH_PROTOCOL * path
EFI device path copy.
Definition: efi_driver.h:25
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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 433 of file efi_path.c.

433  {
434  struct sockaddr_tcpip *st_target;
435  struct net_device *netdev;
436  EFI_DEVICE_PATH_PROTOCOL *netpath;
439  ISCSI_DEVICE_PATH *iscsipath;
440  char *name;
441  size_t prefix_len;
442  size_t name_len;
443  size_t iscsi_len;
444  size_t len;
445 
446  /* Get network device associated with target address */
447  st_target = ( ( struct sockaddr_tcpip * ) &iscsi->target_sockaddr );
448  netdev = tcpip_netdev ( st_target );
449  if ( ! netdev )
450  goto err_netdev;
451 
452  /* Get network device path */
453  netpath = efi_netdev_path ( netdev );
454  if ( ! netpath )
455  goto err_netpath;
456 
457  /* Calculate device path length */
458  prefix_len = efi_path_len ( netpath );
459  name_len = ( strlen ( iscsi->target_iqn ) + 1 /* NUL */ );
460  iscsi_len = ( sizeof ( *iscsipath ) + name_len );
461  len = ( prefix_len + iscsi_len + sizeof ( *end ) );
462 
463  /* Allocate device path */
464  path = zalloc ( len );
465  if ( ! path )
466  goto err_alloc;
467 
468  /* Construct device path */
469  memcpy ( path, netpath, prefix_len );
470  iscsipath = ( ( ( void * ) path ) + prefix_len );
471  iscsipath->Header.Type = MESSAGING_DEVICE_PATH;
472  iscsipath->Header.SubType = MSG_ISCSI_DP;
473  iscsipath->Header.Length[0] = iscsi_len;
475  memcpy ( &iscsipath->Lun, &iscsi->lun, sizeof ( iscsipath->Lun ) );
476  name = ( ( ( void * ) iscsipath ) + sizeof ( *iscsipath ) );
477  memcpy ( name, iscsi->target_iqn, name_len );
478  end = ( ( ( void * ) name ) + name_len );
480 
481  /* Free temporary paths */
482  free ( netpath );
483 
484  return path;
485 
486  err_alloc:
487  free ( netpath );
488  err_netpath:
489  err_netdev:
490  return NULL;
491 }
TCP/IP socket address.
Definition: tcpip.h:75
const char * name
Definition: ath9k_hw.c:1984
struct net_device * tcpip_netdev(struct sockaddr_tcpip *st_dest)
Determine transmitting network device.
Definition: tcpip.c:114
#define ISCSI_LOGIN_OPTION_AUTHMETHOD_NON
Definition: DevicePath.h:939
struct sockaddr target_sockaddr
Target socket address (for boot firmware table)
Definition: iscsi.h:661
size_t efi_path_len(EFI_DEVICE_PATH_PROTOCOL *path)
Find length of device path (excluding terminator)
Definition: efi_path.c:144
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:45
UINT16 LoginOption
iSCSI Login Options.
Definition: DevicePath.h:917
#define MESSAGING_DEVICE_PATH
Messaging Device Paths.
Definition: DevicePath.h:323
static void efi_path_terminate(EFI_DEVICE_PATH_PROTOCOL *end)
Terminate device path.
Definition: efi_path.h:30
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static struct net_device * netdev
Definition: gdbudp.c:52
UINT64 Lun
iSCSI Logical Unit Number.
Definition: DevicePath.h:921
EFI_DEVICE_PATH_PROTOCOL * efi_netdev_path(struct net_device *netdev)
Construct EFI device path for network device.
Definition: efi_path.c:336
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
struct scsi_lun lun
SCSI LUN (for boot firmware table)
Definition: iscsi.h:663
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
A network device.
Definition: netdevice.h:352
#define MSG_ISCSI_DP
iSCSI Device Path SubType
Definition: DevicePath.h:907
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
char * target_iqn
Target IQN.
Definition: iscsi.h:562
UINT8 Length[2]
Specific Device Path data.
Definition: DevicePath.h:58
uint32_t len
Length.
Definition: ena.h:14
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:53
uint32_t end
Ending offset.
Definition: netvsc.h:18
UINT8 Type
0x01 Hardware Device Path.
Definition: DevicePath.h:46
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
EFI_DEVICE_PATH_PROTOCOL Header
Definition: DevicePath.h:909

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 499 of file efi_path.c.

499  {
500  struct {
501  SATA_DEVICE_PATH sata;
503  } satapath;
504  EFI_DEVICE_PATH_PROTOCOL *netpath;
506 
507  /* Get network device path */
508  netpath = efi_netdev_path ( aoedev->netdev );
509  if ( ! netpath )
510  goto err_netdev;
511 
512  /* Construct SATA path */
513  memset ( &satapath, 0, sizeof ( satapath ) );
514  satapath.sata.Header.Type = MESSAGING_DEVICE_PATH;
515  satapath.sata.Header.SubType = MSG_SATA_DP;
516  satapath.sata.Header.Length[0] = sizeof ( satapath.sata );
517  satapath.sata.HBAPortNumber = aoedev->major;
518  satapath.sata.PortMultiplierPortNumber = aoedev->minor;
519  efi_path_terminate ( &satapath.end );
520 
521  /* Construct overall device path */
522  path = efi_paths ( netpath, &satapath, NULL );
523  if ( ! path )
524  goto err_paths;
525 
526  /* Free temporary paths */
527  free ( netpath );
528 
529  return path;
530 
531  err_paths:
532  free ( netpath );
533  err_netdev:
534  return NULL;
535 }
uint16_t major
Major number.
Definition: aoe.h:125
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:45
#define MESSAGING_DEVICE_PATH
Messaging Device Paths.
Definition: DevicePath.h:323
static void efi_path_terminate(EFI_DEVICE_PATH_PROTOCOL *end)
Terminate device path.
Definition: efi_path.h:30
EFI_DEVICE_PATH_PROTOCOL * efi_paths(EFI_DEVICE_PATH_PROTOCOL *first,...)
Concatenate EFI device paths.
Definition: efi_path.c:287
#define MSG_SATA_DP
SATA Device Path SubType.
Definition: DevicePath.h:512
EFI_DEVICE_PATH_PROTOCOL * efi_netdev_path(struct net_device *netdev)
Construct EFI device path for network device.
Definition: efi_path.c:336
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
uint8_t minor
Minor number.
Definition: aoe.h:127
uint32_t end
Ending offset.
Definition: netvsc.h:18
struct net_device * netdev
Network device.
Definition: aoe.h:120
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
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 543 of file efi_path.c.

543  {
544  struct {
547  } __attribute__ (( packed )) *path;
548 
549  /* Allocate device path */
550  path = zalloc ( sizeof ( *path ) );
551  if ( ! path )
552  return NULL;
553 
554  /* Construct device path */
555  path->fc.Header.Type = MESSAGING_DEVICE_PATH;
556  path->fc.Header.SubType = MSG_FIBRECHANNELEX_DP;
557  path->fc.Header.Length[0] = sizeof ( path->fc );
558  memcpy ( path->fc.WWN, &desc->wwn, sizeof ( path->fc.WWN ) );
559  memcpy ( path->fc.Lun, &desc->lun, sizeof ( path->fc.Lun ) );
560  efi_path_terminate ( &path->end );
561 
562  return &path->fc.Header;
563 }
#define MSG_FIBRECHANNELEX_DP
Fibre Channel Ex SubType.
Definition: DevicePath.h:384
#define __attribute__(x)
Definition: compiler.h:10
u16 fc
802.11 Frame Control field
Definition: ieee80211.h:14
uint64_t desc
Microcode descriptor list physical address.
Definition: ucode.h:12
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:45
#define MESSAGING_DEVICE_PATH
Messaging Device Paths.
Definition: DevicePath.h:323
static void efi_path_terminate(EFI_DEVICE_PATH_PROTOCOL *end)
Terminate device path.
Definition: efi_path.h:30
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
uint32_t end
Ending offset.
Definition: netvsc.h:18
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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 571 of file efi_path.c.

571  {
572  const struct ipxe_ib_sbft *sbft = &ib_srp->sbft;
573  union ib_srp_target_port_id *id =
575  srp );
576  struct efi_device *efidev;
578  INFINIBAND_DEVICE_PATH *ibpath;
580  size_t prefix_len;
581  size_t len;
582 
583  /* Find parent EFI device */
584  efidev = efidev_parent ( ib_srp->ibdev->dev );
585  if ( ! efidev )
586  return NULL;
587 
588  /* Calculate device path length */
589  prefix_len = efi_path_len ( efidev->path );
590  len = ( prefix_len + sizeof ( *ibpath ) + sizeof ( *end ) );
591 
592  /* Allocate device path */
593  path = zalloc ( len );
594  if ( ! path )
595  return NULL;
596 
597  /* Construct device path */
598  memcpy ( path, efidev->path, prefix_len );
599  ibpath = ( ( ( void * ) path ) + prefix_len );
601  ibpath->Header.SubType = MSG_INFINIBAND_DP;
602  ibpath->Header.Length[0] = sizeof ( *ibpath );
604  memcpy ( ibpath->PortGid, &sbft->ib.dgid, sizeof ( ibpath->PortGid ) );
605  memcpy ( &ibpath->ServiceId, &sbft->ib.service_id,
606  sizeof ( ibpath->ServiceId ) );
607  memcpy ( &ibpath->TargetPortId, &id->ib.ioc_guid,
608  sizeof ( ibpath->TargetPortId ) );
609  memcpy ( &ibpath->DeviceId, &id->ib.id_ext,
610  sizeof ( ibpath->DeviceId ) );
611  end = ( ( ( void * ) ibpath ) + sizeof ( *ibpath ) );
613 
614  return path;
615 }
union srp_port_id srp
SRP version of port identifier.
Definition: ib_srp.h:34
struct ipxe_ib_sbft sbft
Boot firmware table parameters.
Definition: ib_srp.h:90
#define INFINIBAND_RESOURCE_FLAG_STORAGE_PROTOCOL
Definition: DevicePath.h:688
SRP target port identifier for Infiniband.
Definition: ib_srp.h:32
struct device * dev
Underlying device.
Definition: infiniband.h:410
union srp_port_id target
Target port identifier.
Definition: srp.h:819
size_t efi_path_len(EFI_DEVICE_PATH_PROTOCOL *path)
Find length of device path (excluding terminator)
Definition: efi_path.c:144
EFI_DEVICE_PATH_PROTOCOL Header
Definition: DevicePath.h:655
union ib_gid dgid
Destination GID.
Definition: ib_srp.h:51
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:45
#define MESSAGING_DEVICE_PATH
Messaging Device Paths.
Definition: DevicePath.h:323
UINT32 ResourceFlags
Flags to help identify/manage InfiniBand device path elements: Bit 0 - IOC/Service (0b = IOC,...
Definition: DevicePath.h:665
static void efi_path_terminate(EFI_DEVICE_PATH_PROTOCOL *end)
Terminate device path.
Definition: efi_path.h:30
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
struct sbft_srp_subtable srp
The SRP subtable.
Definition: ib_srp.h:69
An Infiniband SRP sBFT created by iPXE.
Definition: ib_srp.h:63
union ib_guid service_id
Service ID.
Definition: ib_srp.h:53
uint8_t id
Request identifier.
Definition: ena.h:12
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
UINT64 DeviceId
64-bit persistent ID of remote device.
Definition: DevicePath.h:682
#define MSG_INFINIBAND_DP
InfiniBand Device Path SubType.
Definition: DevicePath.h:653
An EFI device.
Definition: efi_driver.h:17
UINT64 TargetPortId
64-bit persistent ID of remote IOC port.
Definition: DevicePath.h:678
UINT64 ServiceId
64-bit unique identifier to remote IOC or server process.
Definition: DevicePath.h:674
UINT8 Length[2]
Specific Device Path data.
Definition: DevicePath.h:58
uint32_t len
Length.
Definition: ena.h:14
UINT8 PortGid[16]
128-bit Global Identifier for remote fabric port.
Definition: DevicePath.h:669
struct ib_device * ibdev
Infiniband device.
Definition: ib_srp.h:85
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:53
uint32_t end
Ending offset.
Definition: netvsc.h:18
struct sbft_ib_subtable ib
The Infiniband subtable.
Definition: ib_srp.h:71
UINT8 Type
0x01 Hardware Device Path.
Definition: DevicePath.h:46
EFI_DEVICE_PATH_PROTOCOL * path
EFI device path copy.
Definition: efi_driver.h:25
struct efi_device * efidev_parent(struct device *dev)
Get parent EFI device.
Definition: efi_driver.c:155
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References container_of, ib_device::dev, INFINIBAND_DEVICE_PATH::DeviceId, sbft_ib_subtable::dgid, efi_path_len(), efi_path_terminate(), efidev_parent(), 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, efi_device::path, 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 626 of file efi_path.c.

626  {
627  struct usb_device *usb = func->usb;
628  struct efi_device *efidev;
631  USB_DEVICE_PATH *usbpath;
632  unsigned int count;
633  size_t prefix_len;
634  size_t len;
635 
636  /* Sanity check */
637  assert ( func->desc.count >= 1 );
638 
639  /* Find parent EFI device */
640  efidev = efidev_parent ( &func->dev );
641  if ( ! efidev )
642  return NULL;
643 
644  /* Calculate device path length */
645  count = ( usb_depth ( usb ) + 1 );
646  prefix_len = efi_path_len ( efidev->path );
647  len = ( prefix_len + ( count * sizeof ( *usbpath ) ) +
648  sizeof ( *end ) );
649 
650  /* Allocate device path */
651  path = zalloc ( len );
652  if ( ! path )
653  return NULL;
654 
655  /* Construct device path */
656  memcpy ( path, efidev->path, prefix_len );
657  end = ( ( ( void * ) path ) + len - sizeof ( *end ) );
659  usbpath = ( ( ( void * ) end ) - sizeof ( *usbpath ) );
660  usbpath->InterfaceNumber = func->interface[0];
661  for ( ; usb ; usbpath--, usb = usb->port->hub->usb ) {
662  usbpath->Header.Type = MESSAGING_DEVICE_PATH;
663  usbpath->Header.SubType = MSG_USB_DP;
664  usbpath->Header.Length[0] = sizeof ( *usbpath );
665  usbpath->ParentPortNumber = ( usb->port->address - 1 );
666  }
667 
668  return path;
669 }
uint8_t interface[0]
List of interface numbers.
Definition: usb.h:682
unsigned int count
Number of interfaces.
Definition: usb.h:650
size_t efi_path_len(EFI_DEVICE_PATH_PROTOCOL *path)
Find length of device path (excluding terminator)
Definition: efi_path.c:144
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:45
#define MESSAGING_DEVICE_PATH
Messaging Device Paths.
Definition: DevicePath.h:323
static void efi_path_terminate(EFI_DEVICE_PATH_PROTOCOL *end)
Terminate device path.
Definition: efi_path.h:30
struct usb_device * usb
Underlying USB device, if any.
Definition: usb.h:832
void * memcpy(void *dest, const void *src, size_t len) __nonnull
struct usb_port * port
USB port.
Definition: usb.h:712
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
UINT8 ParentPortNumber
USB Parent Port Number.
Definition: DevicePath.h:426
A USB device.
Definition: usb.h:708
static unsigned int usb_depth(struct usb_device *usb)
Get USB depth.
Definition: usb.h:1248
EFI_DEVICE_PATH_PROTOCOL Header
Definition: DevicePath.h:422
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
UINT8 InterfaceNumber
USB Interface Number.
Definition: DevicePath.h:430
An EFI device.
Definition: efi_driver.h:17
struct usb_device * usb
USB device.
Definition: usb.h:663
UINT8 Length[2]
Specific Device Path data.
Definition: DevicePath.h:58
uint32_t len
Length.
Definition: ena.h:14
struct usb_hub * hub
USB hub.
Definition: usb.h:800
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:53
uint16_t count
Number of entries.
Definition: ena.h:22
uint32_t end
Ending offset.
Definition: netvsc.h:18
UINT8 Type
0x01 Hardware Device Path.
Definition: DevicePath.h:46
struct usb_function_descriptor desc
Function descriptor.
Definition: usb.h:665
EFI_DEVICE_PATH_PROTOCOL * path
EFI device path copy.
Definition: efi_driver.h:25
struct efi_device * efidev_parent(struct device *dev)
Get parent EFI device.
Definition: efi_driver.c:155
struct device dev
Generic device.
Definition: usb.h:667
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
#define MSG_USB_DP
USB Device Path SubType.
Definition: DevicePath.h:420

References assert(), count, usb_function_descriptor::count, usb_function::desc, usb_function::dev, efi_path_len(), efi_path_terminate(), efidev_parent(), 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, efi_device::path, 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_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 680 of file efi_path.c.

680  {
681  struct interface *dest;
682  efi_describe_TYPE ( void * ) *op =
684  void *object = intf_object ( dest );
686 
687  if ( op ) {
688  path = op ( object );
689  } else {
690  path = NULL;
691  }
692 
693  intf_put ( dest );
694  return path;
695 }
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:45
void * intf_object(struct interface *intf)
Get pointer to object containing object interface.
Definition: interface.c:159
struct interface * intf
Original interface.
Definition: interface.h:158
An object interface.
Definition: interface.h:124
static void * dest
Definition: strings.h:176
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:680
void intf_put(struct interface *intf)
Decrement reference count on an object interface.
Definition: interface.c:149
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
#define intf_get_dest_op(intf, type, dest)
Get object interface destination and operation method.
Definition: interface.h:269
#define efi_describe_TYPE(object_type)
Definition: efi_path.h:63

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 706 of file efi_path.c.

708  {
709 
710  /* Copy data */
711  if ( len > pathset->len )
712  len = pathset->len;
713  memcpy ( data, ( ( ( void * ) path ) + pathset->offset ), len );
714 
715  return pathset->len;
716 }
uint8_t offset
Offset within device path.
Definition: efi_path.c:78
void * memcpy(void *dest, const void *src, size_t len) __nonnull
uint8_t len
Length (if fixed)
Definition: efi_path.c:80
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22

References data, len, efi_path_setting::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 727 of file efi_path.c.

729  {
731  unsigned int count;
732  unsigned int i;
733  size_t frag_len;
734 
735  /* Check applicability */
736  if ( ( !! dns->IsIPv6 ) !=
737  ( pathset->setting->type == &setting_type_ipv6 ) )
738  return -ENOENT;
739 
740  /* Calculate number of addresses */
741  count = ( ( ( ( path->Length[1] << 8 ) | path->Length[0] ) -
742  pathset->offset ) / sizeof ( dns->DnsServerIp[0] ) );
743 
744  /* Copy data */
745  for ( i = 0 ; i < count ; i++ ) {
746  frag_len = len;
747  if ( frag_len > pathset->len )
748  frag_len = pathset->len;
749  memcpy ( data, &dns->DnsServerIp[i], frag_len );
750  data += frag_len;
751  len -= frag_len;
752  }
753 
754  return ( count * pathset->len );
755 }
uint8_t offset
Offset within device path.
Definition: efi_path.c:78
#define ENOENT
No such file or directory.
Definition: errno.h:514
EFI_IP_ADDRESS DnsServerIp[]
Instance of the DNS server address.
Definition: DevicePath.h:855
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
const struct setting_type * type
Setting type.
Definition: settings.h:36
uint8_t len
Length (if fixed)
Definition: efi_path.c:80
UINT8 Length[2]
Specific Device Path data.
Definition: DevicePath.h:58
uint32_t len
Length.
Definition: ena.h:14
uint16_t count
Number of entries.
Definition: ena.h:22
const struct setting * setting
Setting.
Definition: efi_path.c:60
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:851
PACKED union @478::@492 Header
Definition: Acpi10.h:155

References container_of, count, data, DNS_DEVICE_PATH::DnsServerIp, ENOENT, Header, DNS_DEVICE_PATH::IsIPv6, len, efi_path_setting::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 794 of file efi_path.c.

795  {
796  struct efi_path_settings *pathsets =
798  EFI_DEVICE_PATH_PROTOCOL *path = pathsets->path;
800  struct efi_path_setting *pathset;
801  unsigned int i;
802  int ret;
803 
804  /* Find matching path setting, if any */
805  for ( i = 0 ; i < ( sizeof ( efi_path_settings ) /
806  sizeof ( efi_path_settings[0] ) ) ; i++ ) {
807 
808  /* Check for a matching setting */
809  pathset = &efi_path_settings[i];
810  if ( setting_cmp ( setting, pathset->setting ) != 0 )
811  continue;
812 
813  /* Find matching device path element, if any */
814  for ( ; ( next = efi_path_next ( path ) ) ; path = next ) {
815 
816  /* Check for a matching path type */
817  if ( ( path->Type != pathset->type ) ||
818  ( path->SubType != pathset->subtype ) )
819  continue;
820 
821  /* Fetch value */
822  if ( ( ret = pathset->fetch ( pathset, path,
823  data, len ) ) < 0 )
824  return ret;
825 
826  /* Apply default type, if not already set */
827  if ( ! setting->type )
828  setting->type = pathset->setting->type;
829 
830  return ret;
831  }
832  break;
833  }
834 
835  return -ENOENT;
836 }
uint32_t next
Next descriptor address.
Definition: myson.h:18
int(* fetch)(struct efi_path_setting *pathset, EFI_DEVICE_PATH_PROTOCOL *path, void *data, size_t len)
Fetch setting.
Definition: efi_path.c:70
EFI_DEVICE_PATH_PROTOCOL * path
Device path.
Definition: efi_path.c:54
#define ENOENT
No such file or directory.
Definition: errno.h:514
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:45
An EFI device path settings block.
Definition: efi_path.c:50
uint8_t type
Path type.
Definition: efi_path.c:74
An EFI device path setting.
Definition: efi_path.c:58
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
const struct setting_type * type
Setting type.
Definition: settings.h:36
A settings block.
Definition: settings.h:132
EFI_DEVICE_PATH_PROTOCOL * efi_path_next(EFI_DEVICE_PATH_PROTOCOL *path)
Find next element in device path.
Definition: efi_path.c:89
A setting.
Definition: settings.h:23
static struct efi_path_setting efi_path_settings[]
EFI device path settings.
Definition: efi_path.c:758
uint32_t len
Length.
Definition: ena.h:14
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:53
const struct setting * setting
Setting.
Definition: efi_path.c:60
uint8_t data[48]
Additional event data.
Definition: ena.h:22
UINT8 Type
0x01 Hardware Device Path.
Definition: DevicePath.h:46
uint8_t subtype
Path subtype.
Definition: efi_path.c:76
int setting_cmp(const struct setting *a, const struct setting *b)
Compare two settings.
Definition: settings.c:1120

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 850 of file efi_path.c.

850  {
851  struct efi_path_settings *pathsets = priv;
852  struct settings *settings = &pathsets->settings;
854  unsigned int vlan;
855  void *mac;
856  int rc;
857 
858  /* Check applicability */
859  pathsets->path = path;
860  mac = efi_path_mac ( path );
861  vlan = efi_path_vlan ( path );
862  if ( ( mac == NULL ) ||
863  ( memcmp ( mac, netdev->ll_addr,
864  netdev->ll_protocol->ll_addr_len ) != 0 ) ||
865  ( vlan != vlan_tag ( netdev ) ) ) {
866  DBGC ( settings, "EFI path %s does not apply to %s\n",
867  efi_devpath_text ( path ), netdev->name );
868  return 0;
869  }
870 
871  /* Never override a real DHCP settings block */
873  DHCP_SETTINGS_NAME ) ) {
874  DBGC ( settings, "EFI path %s not overriding %s DHCP "
875  "settings\n", efi_devpath_text ( path ), netdev->name );
876  return 0;
877  }
878 
879  /* Initialise and register settings */
881  &netdev->refcnt, NULL );
883  DHCP_SETTINGS_NAME ) ) != 0 ) {
884  DBGC ( settings, "EFI path %s could not register for %s: %s\n",
885  efi_devpath_text ( path ), netdev->name,
886  strerror ( rc ) );
887  return rc;
888  }
889  DBGC ( settings, "EFI path %s registered for %s\n",
890  efi_devpath_text ( path ), netdev->name );
891 
892  return 0;
893 }
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:180
uint8_t ll_addr_len
Link-layer address length.
Definition: netdevice.h:198
#define DBGC(...)
Definition: compiler.h:505
EFI_DEVICE_PATH_PROTOCOL * path
Device path.
Definition: efi_path.c:54
static struct settings_operations efi_path_settings_operations
EFI device path settings operations.
Definition: efi_path.c:839
struct settings settings
Settings interface.
Definition: efi_path.c:52
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:45
uint8_t mac[ETH_ALEN]
MAC address.
Definition: ena.h:24
An EFI device path settings block.
Definition: efi_path.c:50
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:583
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:500
EFI_DEVICE_PATH_PROTOCOL * efi_loaded_image_path
Device path for the loaded image's device handle.
Definition: efi_init.c:40
#define DHCP_SETTINGS_NAME
Settings block name used for DHCP responses.
Definition: dhcp.h:708
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:156
const char * efi_devpath_text(EFI_DEVICE_PATH_PROTOCOL *path)
Get textual representation of device path.
Definition: efi_debug.c:461
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
struct refcnt refcnt
Reference counter.
Definition: netdevice.h:354
A settings block.
Definition: settings.h:132
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
static struct tlan_private * priv
Definition: tlan.c:224
int register_settings(struct settings *settings, struct settings *parent, const char *name)
Register settings block.
Definition: settings.c:475
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387
static unsigned int vlan_tag(struct net_device *netdev)
Get the VLAN tag.
Definition: vlan.h:73
struct settings * find_child_settings(struct settings *parent, const char *name)
Find child settings block.
Definition: settings.c:279
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:114
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372

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

◆ 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:706
#define offsetof(type, field)
Get offset of a field within a structure.
Definition: stddef.h:24
#define MESSAGING_DEVICE_PATH
Messaging Device Paths.
Definition: DevicePath.h:323
IP6 address structure.
Definition: in.h:48
#define MSG_IPv4_DP
IPv4 Device Path SubType.
Definition: DevicePath.h:568
IP address structure.
Definition: in.h:39
#define MSG_IPv6_DP
IPv6 Device Path SubType.
Definition: DevicePath.h:609
unsigned char uint8_t
Definition: stdint.h:10
#define MSG_DNS_DP
DNS Device Path SubType.
Definition: DevicePath.h:845
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:727

EFI device path settings.

Definition at line 758 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:794

EFI device path settings operations.

Definition at line 839 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:50
static int efi_path_net_probe(struct net_device *netdev, void *priv)
Create per-netdevice EFI path settings.
Definition: efi_path.c:850

EFI path settings per-netdevice driver.

Definition at line 896 of file efi_path.c.