iPXE
Functions
efi_path.c File Reference

EFI device paths. More...

#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <byteswap.h>
#include <ipxe/netdevice.h>
#include <ipxe/vlan.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/efi/efi.h>
#include <ipxe/efi/efi_driver.h>
#include <ipxe/efi/efi_path.h>

Go to the source code of this file.

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...
 
unsigned int efi_path_vlan (EFI_DEVICE_PATH_PROTOCOL *path)
 Get VLAN tag 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...
 

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

51  {
52 
53  /* Check for non-existent device path */
54  if ( ! path )
55  return NULL;
56 
57  /* Check for end of device path */
58  if ( path->Type == END_DEVICE_PATH_TYPE )
59  return NULL;
60 
61  /* Move to next component of the device path */
62  path = ( ( ( void * ) path ) +
63  /* There's this amazing new-fangled thing known as
64  * a UINT16, but who wants to use one of those? */
65  ( ( path->Length[1] << 8 ) | path->Length[0] ) );
66 
67  return path;
68 }
#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_prev(), 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 77 of file efi_path.c.

78  {
80 
81  /* Find immediately preceding element */
82  while ( ( tmp = efi_path_next ( path ) ) != curr ) {
83  path = tmp;
84  }
85 
86  return path;
87 }
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:51

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

95  {
96 
97  return efi_path_prev ( path, NULL );
98 }
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:77
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References efi_path_prev(), and NULL.

Referenced by efi_block_boot_image(), 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 106 of file efi_path.c.

106  {
108 
109  return ( ( ( void * ) end ) - ( ( void * ) path ) );
110 }
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:95

References efi_path_end(), and end.

Referenced by efi_block_boot_image(), efi_devpath_text(), efi_driver_start(), 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(), and usbio_path().

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

118  {
120  VLAN_DEVICE_PATH *vlan;
121 
122  /* Search for VLAN device path */
123  for ( ; ( next = efi_path_next ( path ) ) ; path = next ) {
124  if ( ( path->Type == MESSAGING_DEVICE_PATH ) &&
125  ( path->SubType == MSG_VLAN_DP ) ) {
126  vlan = container_of ( path, VLAN_DEVICE_PATH, Header );
127  return vlan->VlanId;
128  }
129  }
130 
131  /* No VLAN device path found */
132  return 0;
133 }
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:51
#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(), and efi_set_autoboot_ll_addr().

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

144  {
149  va_list args;
150  size_t len;
151 
152  /* Calculate device path length */
153  va_start ( args, first );
154  len = 0;
155  src = first;
156  while ( src ) {
157  len += efi_path_len ( src );
158  src = va_arg ( args, EFI_DEVICE_PATH_PROTOCOL * );
159  }
160  va_end ( args );
161 
162  /* Allocate device path */
163  path = zalloc ( len + sizeof ( *end ) );
164  if ( ! path )
165  return NULL;
166 
167  /* Populate device path */
168  va_start ( args, first );
169  dst = path;
170  src = first;
171  while ( src ) {
172  len = efi_path_len ( src );
173  memcpy ( dst, src, len );
174  dst = ( ( ( void * ) dst ) + len );
175  src = va_arg ( args, EFI_DEVICE_PATH_PROTOCOL * );
176  }
177  va_end ( args );
178  end = dst;
180 
181  return path;
182 }
#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:106
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:29
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define va_arg(ap, type)
Definition: stdarg.h:8
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, 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 193 of file efi_path.c.

193  {
194  struct efi_device *efidev;
196  MAC_ADDR_DEVICE_PATH *macpath;
197  VLAN_DEVICE_PATH *vlanpath;
199  unsigned int tag;
200  size_t prefix_len;
201  size_t len;
202 
203  /* Find parent EFI device */
204  efidev = efidev_parent ( netdev->dev );
205  if ( ! efidev )
206  return NULL;
207 
208  /* Calculate device path length */
209  prefix_len = efi_path_len ( efidev->path );
210  len = ( prefix_len + sizeof ( *macpath ) + sizeof ( *vlanpath ) +
211  sizeof ( *end ) );
212 
213  /* Allocate device path */
214  path = zalloc ( len );
215  if ( ! path )
216  return NULL;
217 
218  /* Construct device path */
219  memcpy ( path, efidev->path, prefix_len );
220  macpath = ( ( ( void * ) path ) + prefix_len );
221  macpath->Header.Type = MESSAGING_DEVICE_PATH;
222  macpath->Header.SubType = MSG_MAC_ADDR_DP;
223  macpath->Header.Length[0] = sizeof ( *macpath );
225  sizeof ( macpath->MacAddress ) );
226  memcpy ( &macpath->MacAddress, netdev->ll_addr,
228  macpath->IfType = ntohs ( netdev->ll_protocol->ll_proto );
229  if ( ( tag = vlan_tag ( netdev ) ) ) {
230  vlanpath = ( ( ( void * ) macpath ) + sizeof ( *macpath ) );
231  vlanpath->Header.Type = MESSAGING_DEVICE_PATH;
232  vlanpath->Header.SubType = MSG_VLAN_DP;
233  vlanpath->Header.Length[0] = sizeof ( *vlanpath );
234  vlanpath->VlanId = tag;
235  end = ( ( ( void * ) vlanpath ) + sizeof ( *vlanpath ) );
236  } else {
237  end = ( ( ( void * ) macpath ) + sizeof ( *macpath ) );
238  }
240 
241  return path;
242 }
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:106
#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:29
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:23
struct efi_device * efidev_parent(struct device *dev)
Get parent EFI device.
Definition: efi_driver.c:88
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 253 of file efi_path.c.

253  {
256  URI_DEVICE_PATH *uripath;
257  size_t uri_len;
258  size_t uripath_len;
259  size_t len;
260 
261  /* Calculate device path length */
262  uri_len = ( format_uri ( uri, NULL, 0 ) + 1 /* NUL */ );
263  uripath_len = ( sizeof ( *uripath ) + uri_len );
264  len = ( uripath_len + sizeof ( *end ) );
265 
266  /* Allocate device path */
267  path = zalloc ( len );
268  if ( ! path )
269  return NULL;
270 
271  /* Construct device path */
272  uripath = ( ( void * ) path );
273  uripath->Header.Type = MESSAGING_DEVICE_PATH;
274  uripath->Header.SubType = MSG_URI_DP;
275  uripath->Header.Length[0] = ( uripath_len & 0xff );
276  uripath->Header.Length[1] = ( uripath_len >> 8 );
277  format_uri ( uri, uripath->Uri, uri_len );
278  end = ( ( ( void * ) path ) + uripath_len );
280 
281  return path;
282 }
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:29
#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:23
#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 290 of file efi_path.c.

290  {
291  struct sockaddr_tcpip *st_target;
292  struct net_device *netdev;
293  EFI_DEVICE_PATH_PROTOCOL *netpath;
296  ISCSI_DEVICE_PATH *iscsipath;
297  char *name;
298  size_t prefix_len;
299  size_t name_len;
300  size_t iscsi_len;
301  size_t len;
302 
303  /* Get network device associated with target address */
304  st_target = ( ( struct sockaddr_tcpip * ) &iscsi->target_sockaddr );
305  netdev = tcpip_netdev ( st_target );
306  if ( ! netdev )
307  goto err_netdev;
308 
309  /* Get network device path */
310  netpath = efi_netdev_path ( netdev );
311  if ( ! netpath )
312  goto err_netpath;
313 
314  /* Calculate device path length */
315  prefix_len = efi_path_len ( netpath );
316  name_len = ( strlen ( iscsi->target_iqn ) + 1 /* NUL */ );
317  iscsi_len = ( sizeof ( *iscsipath ) + name_len );
318  len = ( prefix_len + iscsi_len + sizeof ( *end ) );
319 
320  /* Allocate device path */
321  path = zalloc ( len );
322  if ( ! path )
323  goto err_alloc;
324 
325  /* Construct device path */
326  memcpy ( path, netpath, prefix_len );
327  iscsipath = ( ( ( void * ) path ) + prefix_len );
328  iscsipath->Header.Type = MESSAGING_DEVICE_PATH;
329  iscsipath->Header.SubType = MSG_ISCSI_DP;
330  iscsipath->Header.Length[0] = iscsi_len;
332  memcpy ( &iscsipath->Lun, &iscsi->lun, sizeof ( iscsipath->Lun ) );
333  name = ( ( ( void * ) iscsipath ) + sizeof ( *iscsipath ) );
334  memcpy ( name, iscsi->target_iqn, name_len );
335  end = ( ( ( void * ) name ) + name_len );
337 
338  /* Free temporary paths */
339  free ( netpath );
340 
341  return path;
342 
343  err_alloc:
344  free ( netpath );
345  err_netpath:
346  err_netdev:
347  return NULL;
348 }
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:106
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:29
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:193
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 356 of file efi_path.c.

356  {
357  struct {
358  SATA_DEVICE_PATH sata;
360  } satapath;
361  EFI_DEVICE_PATH_PROTOCOL *netpath;
363 
364  /* Get network device path */
365  netpath = efi_netdev_path ( aoedev->netdev );
366  if ( ! netpath )
367  goto err_netdev;
368 
369  /* Construct SATA path */
370  memset ( &satapath, 0, sizeof ( satapath ) );
371  satapath.sata.Header.Type = MESSAGING_DEVICE_PATH;
372  satapath.sata.Header.SubType = MSG_SATA_DP;
373  satapath.sata.Header.Length[0] = sizeof ( satapath.sata );
374  satapath.sata.HBAPortNumber = aoedev->major;
375  satapath.sata.PortMultiplierPortNumber = aoedev->minor;
376  efi_path_terminate ( &satapath.end );
377 
378  /* Construct overall device path */
379  path = efi_paths ( netpath, &satapath, NULL );
380  if ( ! path )
381  goto err_paths;
382 
383  /* Free temporary paths */
384  free ( netpath );
385 
386  return path;
387 
388  err_paths:
389  free ( netpath );
390  err_netdev:
391  return NULL;
392 }
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:29
EFI_DEVICE_PATH_PROTOCOL * efi_paths(EFI_DEVICE_PATH_PROTOCOL *first,...)
Concatenate EFI device paths.
Definition: efi_path.c:144
#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:193
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 400 of file efi_path.c.

400  {
401  struct {
404  } __attribute__ (( packed )) *path;
405 
406  /* Allocate device path */
407  path = zalloc ( sizeof ( *path ) );
408  if ( ! path )
409  return NULL;
410 
411  /* Construct device path */
412  path->fc.Header.Type = MESSAGING_DEVICE_PATH;
413  path->fc.Header.SubType = MSG_FIBRECHANNELEX_DP;
414  path->fc.Header.Length[0] = sizeof ( path->fc );
415  memcpy ( path->fc.WWN, &desc->wwn, sizeof ( path->fc.WWN ) );
416  memcpy ( path->fc.Lun, &desc->lun, sizeof ( path->fc.Lun ) );
417  efi_path_terminate ( &path->end );
418 
419  return &path->fc.Header;
420 }
#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
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
struct fc_name wwn
Fibre Channel WWN.
Definition: fcp.h:169
static void efi_path_terminate(EFI_DEVICE_PATH_PROTOCOL *end)
Terminate device path.
Definition: efi_path.h:29
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
struct scsi_lun lun
SCSI LUN.
Definition: fcp.h:171
uint32_t end
Ending offset.
Definition: netvsc.h:18
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References __attribute__, efi_path_terminate(), end, fc, fcp_description::lun, memcpy(), MESSAGING_DEVICE_PATH, MSG_FIBRECHANNELEX_DP, NULL, fcp_description::wwn, 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 428 of file efi_path.c.

428  {
429  const struct ipxe_ib_sbft *sbft = &ib_srp->sbft;
430  union ib_srp_target_port_id *id =
432  srp );
433  struct efi_device *efidev;
435  INFINIBAND_DEVICE_PATH *ibpath;
437  size_t prefix_len;
438  size_t len;
439 
440  /* Find parent EFI device */
441  efidev = efidev_parent ( ib_srp->ibdev->dev );
442  if ( ! efidev )
443  return NULL;
444 
445  /* Calculate device path length */
446  prefix_len = efi_path_len ( efidev->path );
447  len = ( prefix_len + sizeof ( *ibpath ) + sizeof ( *end ) );
448 
449  /* Allocate device path */
450  path = zalloc ( len );
451  if ( ! path )
452  return NULL;
453 
454  /* Construct device path */
455  memcpy ( path, efidev->path, prefix_len );
456  ibpath = ( ( ( void * ) path ) + prefix_len );
458  ibpath->Header.SubType = MSG_INFINIBAND_DP;
459  ibpath->Header.Length[0] = sizeof ( *ibpath );
461  memcpy ( ibpath->PortGid, &sbft->ib.dgid, sizeof ( ibpath->PortGid ) );
462  memcpy ( &ibpath->ServiceId, &sbft->ib.service_id,
463  sizeof ( ibpath->ServiceId ) );
464  memcpy ( &ibpath->TargetPortId, &id->ib.ioc_guid,
465  sizeof ( ibpath->TargetPortId ) );
466  memcpy ( &ibpath->DeviceId, &id->ib.id_ext,
467  sizeof ( ibpath->DeviceId ) );
468  end = ( ( ( void * ) ibpath ) + sizeof ( *ibpath ) );
470 
471  return path;
472 }
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:106
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:29
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:23
struct efi_device * efidev_parent(struct device *dev)
Get parent EFI device.
Definition: efi_driver.c:88
#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 483 of file efi_path.c.

483  {
484  struct usb_device *usb = func->usb;
485  struct efi_device *efidev;
488  USB_DEVICE_PATH *usbpath;
489  unsigned int count;
490  size_t prefix_len;
491  size_t len;
492 
493  /* Sanity check */
494  assert ( func->desc.count >= 1 );
495 
496  /* Find parent EFI device */
497  efidev = efidev_parent ( &func->dev );
498  if ( ! efidev )
499  return NULL;
500 
501  /* Calculate device path length */
502  count = ( usb_depth ( usb ) + 1 );
503  prefix_len = efi_path_len ( efidev->path );
504  len = ( prefix_len + ( count * sizeof ( *usbpath ) ) +
505  sizeof ( *end ) );
506 
507  /* Allocate device path */
508  path = zalloc ( len );
509  if ( ! path )
510  return NULL;
511 
512  /* Construct device path */
513  memcpy ( path, efidev->path, prefix_len );
514  end = ( ( ( void * ) path ) + len - sizeof ( *end ) );
516  usbpath = ( ( ( void * ) end ) - sizeof ( *usbpath ) );
517  usbpath->InterfaceNumber = func->interface[0];
518  for ( ; usb ; usbpath--, usb = usb->port->hub->usb ) {
519  usbpath->Header.Type = MESSAGING_DEVICE_PATH;
520  usbpath->Header.SubType = MSG_USB_DP;
521  usbpath->Header.Length[0] = sizeof ( *usbpath );
522  usbpath->ParentPortNumber = ( usb->port->address - 1 );
523  }
524 
525  return path;
526 }
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:106
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:29
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:23
struct efi_device * efidev_parent(struct device *dev)
Get parent EFI device.
Definition: efi_driver.c:88
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 537 of file efi_path.c.

537  {
538  struct interface *dest;
539  efi_describe_TYPE ( void * ) *op =
541  void *object = intf_object ( dest );
543 
544  if ( op ) {
545  path = op ( object );
546  } else {
547  path = NULL;
548  }
549 
550  intf_put ( dest );
551  return path;
552 }
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:537
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:59

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