iPXE
Data Structures | Macros | Functions
efi_snp.h File Reference

iPXE EFI SNP interface More...

#include <ipxe/list.h>
#include <ipxe/netdevice.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/Protocol/SimpleNetwork.h>
#include <ipxe/efi/Protocol/NetworkInterfaceIdentifier.h>
#include <ipxe/efi/Protocol/ComponentName2.h>
#include <ipxe/efi/Protocol/DevicePath.h>
#include <ipxe/efi/Protocol/HiiConfigAccess.h>
#include <ipxe/efi/Protocol/HiiDatabase.h>
#include <ipxe/efi/Protocol/LoadFile.h>

Go to the source code of this file.

Data Structures

struct  efi_snp_device
 An SNP device. More...
 

Macros

#define EFI_SNP_NUM_TX   32
 SNP transmit completion ring size. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER)
 
int efi_snp_hii_install (struct efi_snp_device *snpdev)
 Install HII protocol and packages for SNP device. More...
 
void efi_snp_hii_uninstall (struct efi_snp_device *snpdev)
 Uninstall HII protocol and package for SNP device. More...
 
struct efi_snp_devicefind_snpdev (EFI_HANDLE handle)
 Find SNP device by EFI device handle. More...
 
struct efi_snp_devicelast_opened_snpdev (void)
 Get most recently opened SNP device. More...
 
void efi_snp_add_claim (int delta)
 Add to SNP claimed/released count. More...
 
static void efi_snp_claim (void)
 Claim network devices for use by iPXE. More...
 
static void efi_snp_release (void)
 Release network devices for use via SNP. More...
 

Detailed Description

iPXE EFI SNP interface

Definition in file efi_snp.h.

Macro Definition Documentation

◆ EFI_SNP_NUM_TX

#define EFI_SNP_NUM_TX   32

SNP transmit completion ring size.

Definition at line 24 of file efi_snp.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER  )

◆ efi_snp_hii_install()

int efi_snp_hii_install ( struct efi_snp_device snpdev)

Install HII protocol and packages for SNP device.

Parameters
snpdevSNP device
Return values
rcReturn status code

Definition at line 655 of file efi_snp_hii.c.

655  {
657  VENDOR_DEVICE_PATH *vendor_path;
658  EFI_DEVICE_PATH_PROTOCOL *path_end;
659  size_t path_prefix_len;
660  int efirc;
661  int rc;
662 
663  /* Do nothing if HII database protocol is not supported */
664  if ( ! efihii ) {
665  rc = -ENOTSUP;
666  goto err_no_hii;
667  }
668 
669  /* Initialise HII protocol */
670  memcpy ( &snpdev->hii, &efi_snp_device_hii, sizeof ( snpdev->hii ) );
671 
672  /* Create HII package list */
673  snpdev->package_list = efi_snp_hii_package_list ( snpdev );
674  if ( ! snpdev->package_list ) {
675  DBGC ( snpdev, "SNPDEV %p could not create HII package list\n",
676  snpdev );
677  rc = -ENOMEM;
678  goto err_build_package_list;
679  }
680 
681  /* Allocate the new device path */
682  path_prefix_len = efi_devpath_len ( snpdev->path );
683  snpdev->hii_child_path = zalloc ( path_prefix_len +
684  sizeof ( *vendor_path ) +
685  sizeof ( *path_end ) );
686  if ( ! snpdev->hii_child_path ) {
687  DBGC ( snpdev,
688  "SNPDEV %p could not allocate HII child device path\n",
689  snpdev );
690  rc = -ENOMEM;
691  goto err_alloc_child_path;
692  }
693 
694  /* Populate the device path */
695  memcpy ( snpdev->hii_child_path, snpdev->path, path_prefix_len );
696  vendor_path = ( ( ( void * ) snpdev->hii_child_path ) +
697  path_prefix_len );
698  vendor_path->Header.Type = HARDWARE_DEVICE_PATH;
699  vendor_path->Header.SubType = HW_VENDOR_DP;
700  vendor_path->Header.Length[0] = sizeof ( *vendor_path );
701  efi_snp_hii_random_guid ( &vendor_path->Guid );
702  path_end = ( ( void * ) ( vendor_path + 1 ) );
703  path_end->Type = END_DEVICE_PATH_TYPE;
705  path_end->Length[0] = sizeof ( *path_end );
706 
707  /* Create device path and child handle for HII association */
708  if ( ( efirc = bs->InstallMultipleProtocolInterfaces (
709  &snpdev->hii_child_handle,
711  NULL ) ) != 0 ) {
712  rc = -EEFI ( efirc );
713  DBGC ( snpdev, "SNPDEV %p could not create HII child handle: "
714  "%s\n", snpdev, strerror ( rc ) );
715  goto err_hii_child_handle;
716  }
717 
718  /* Add HII packages */
719  if ( ( efirc = efihii->NewPackageList ( efihii, snpdev->package_list,
720  snpdev->hii_child_handle,
721  &snpdev->hii_handle ) ) != 0 ) {
722  rc = -EEFI ( efirc );
723  DBGC ( snpdev, "SNPDEV %p could not add HII packages: %s\n",
724  snpdev, strerror ( rc ) );
725  goto err_new_package_list;
726  }
727 
728  /* Install HII protocol */
729  if ( ( efirc = bs->InstallMultipleProtocolInterfaces (
730  &snpdev->hii_child_handle,
732  NULL ) ) != 0 ) {
733  rc = -EEFI ( efirc );
734  DBGC ( snpdev, "SNPDEV %p could not install HII protocol: %s\n",
735  snpdev, strerror ( rc ) );
736  goto err_install_protocol;
737  }
738 
739  /* Add as child of handle with SNP instance */
740  if ( ( rc = efi_child_add ( snpdev->handle,
741  snpdev->hii_child_handle ) ) != 0 ) {
742  DBGC ( snpdev,
743  "SNPDEV %p could not adopt HII child handle: %s\n",
744  snpdev, strerror ( rc ) );
745  goto err_efi_child_add;
746  }
747 
748  return 0;
749 
750  efi_child_del ( snpdev->handle, snpdev->hii_child_handle );
751  err_efi_child_add:
753  snpdev->hii_child_handle,
755  NULL );
756  err_install_protocol:
758  err_new_package_list:
760  snpdev->hii_child_handle,
762  NULL );
763  err_hii_child_handle:
764  free ( snpdev->hii_child_path );
765  snpdev->hii_child_path = NULL;
766  err_alloc_child_path:
767  free ( snpdev->package_list );
768  snpdev->package_list = NULL;
769  err_build_package_list:
770  err_no_hii:
771  return rc;
772 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:159
#define END_DEVICE_PATH_TYPE
Definition: DevicePath.h:1327
static void efi_snp_hii_random_guid(EFI_GUID *guid)
Generate a random GUID.
Definition: efi_snp_hii.c:111
EFI_HII_DATABASE_REMOVE_PACK RemovePackageList
Definition: HiiDatabase.h:517
#define HARDWARE_DEVICE_PATH
Hardware Device Paths.
Definition: DevicePath.h:77
#define DBGC(...)
Definition: compiler.h:505
EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES InstallMultipleProtocolInterfaces
Definition: UefiSpec.h:1915
size_t efi_devpath_len(EFI_DEVICE_PATH_PROTOCOL *path)
Find length of device path (excluding terminator)
Definition: efi_utils.c:59
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:51
int efi_child_add(EFI_HANDLE parent, EFI_HANDLE child)
Add EFI device as child of another EFI device.
Definition: efi_utils.c:124
EFI_HANDLE hii_child_handle
EFI child handle for HII association.
Definition: efi_snp.h:63
EFI_HII_CONFIG_ACCESS_PROTOCOL hii
HII configuration access protocol.
Definition: efi_snp.h:59
EFI_HANDLE handle
EFI device handle.
Definition: efi_snp.h:35
EFI_GUID efi_hii_config_access_protocol_guid
HII configuration access protocol GUID.
Definition: efi_guid.c:156
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
void efi_child_del(EFI_HANDLE parent, EFI_HANDLE child)
Remove EFI device as child of another EFI device.
Definition: efi_utils.c:158
EFI_HII_HANDLE hii_handle
HII handle.
Definition: efi_snp.h:67
EFI_GUID Guid
Vendor-assigned GUID that defines the data that follows.
Definition: DevicePath.h:154
#define ENOMEM
Not enough space.
Definition: errno.h:534
void * memcpy(void *dest, const void *src, size_t len) __nonnull
EFI_DEVICE_PATH_PROTOCOL Header
Definition: DevicePath.h:150
EFI_HII_PACKAGE_LIST_HEADER * package_list
HII package list.
Definition: efi_snp.h:61
#define HW_VENDOR_DP
Hardware Vendor Device Path SubType.
Definition: DevicePath.h:142
The Vendor Device Path allows the creation of vendor-defined Device Paths.
Definition: DevicePath.h:149
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces
Definition: UefiSpec.h:1916
static EFI_HII_PACKAGE_LIST_HEADER * efi_snp_hii_package_list(struct efi_snp_device *snpdev)
Build HII package list for SNP device.
Definition: efi_snp_hii.c:161
EFI_DEVICE_PATH_PROTOCOL * hii_child_path
Device path of HII child handle.
Definition: efi_snp.h:65
static EFI_HII_CONFIG_ACCESS_PROTOCOL efi_snp_device_hii
HII configuration access protocol.
Definition: efi_snp_hii.c:643
EFI_GUID efi_device_path_protocol_guid
Device path protocol GUID.
Definition: efi_guid.c:132
#define END_ENTIRE_DEVICE_PATH_SUBTYPE
Definition: DevicePath.h:1328
UINT8 Length[2]
Specific Device Path data.
Definition: DevicePath.h:64
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:59
EFI_HII_DATABASE_NEW_PACK NewPackageList
Definition: HiiDatabase.h:516
UINT8 Type
0x01 Hardware Device Path.
Definition: DevicePath.h:52
EFI_SYSTEM_TABLE * efi_systab
EFI_DEVICE_PATH_PROTOCOL * path
The device path.
Definition: efi_snp.h:75
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
static EFI_HII_DATABASE_PROTOCOL * efihii
EFI HII database protocol.
Definition: efi_snp_hii.c:78

References EFI_SYSTEM_TABLE::BootServices, DBGC, EEFI, efi_child_add(), efi_child_del(), efi_device_path_protocol_guid, efi_devpath_len(), efi_hii_config_access_protocol_guid, efi_snp_device_hii, efi_snp_hii_package_list(), efi_snp_hii_random_guid(), efi_systab, efihii, END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, ENOMEM, ENOTSUP, free, VENDOR_DEVICE_PATH::Guid, efi_snp_device::handle, HARDWARE_DEVICE_PATH, VENDOR_DEVICE_PATH::Header, efi_snp_device::hii, efi_snp_device::hii_child_handle, efi_snp_device::hii_child_path, efi_snp_device::hii_handle, HW_VENDOR_DP, EFI_BOOT_SERVICES::InstallMultipleProtocolInterfaces, EFI_DEVICE_PATH_PROTOCOL::Length, memcpy(), _EFI_HII_DATABASE_PROTOCOL::NewPackageList, NULL, efi_snp_device::package_list, efi_snp_device::path, rc, _EFI_HII_DATABASE_PROTOCOL::RemovePackageList, strerror(), EFI_DEVICE_PATH_PROTOCOL::SubType, EFI_DEVICE_PATH_PROTOCOL::Type, EFI_BOOT_SERVICES::UninstallMultipleProtocolInterfaces, and zalloc().

Referenced by efi_snp_probe().

◆ efi_snp_hii_uninstall()

void efi_snp_hii_uninstall ( struct efi_snp_device snpdev)

Uninstall HII protocol and package for SNP device.

Parameters
snpdevSNP device

Definition at line 779 of file efi_snp_hii.c.

779  {
781 
782  /* Do nothing if HII database protocol is not supported */
783  if ( ! efihii )
784  return;
785 
786  /* Uninstall protocols and remove package list */
787  efi_child_del ( snpdev->handle, snpdev->hii_child_handle );
789  snpdev->hii_child_handle,
791  NULL );
794  snpdev->hii_child_handle,
796  NULL );
797  free ( snpdev->hii_child_path );
798  snpdev->hii_child_path = NULL;
799  free ( snpdev->package_list );
800  snpdev->package_list = NULL;
801 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
EFI_HII_DATABASE_REMOVE_PACK RemovePackageList
Definition: HiiDatabase.h:517
EFI_HANDLE hii_child_handle
EFI child handle for HII association.
Definition: efi_snp.h:63
EFI_HII_CONFIG_ACCESS_PROTOCOL hii
HII configuration access protocol.
Definition: efi_snp.h:59
EFI_HANDLE handle
EFI device handle.
Definition: efi_snp.h:35
EFI_GUID efi_hii_config_access_protocol_guid
HII configuration access protocol GUID.
Definition: efi_guid.c:156
void efi_child_del(EFI_HANDLE parent, EFI_HANDLE child)
Remove EFI device as child of another EFI device.
Definition: efi_utils.c:158
EFI_HII_HANDLE hii_handle
HII handle.
Definition: efi_snp.h:67
EFI_HII_PACKAGE_LIST_HEADER * package_list
HII package list.
Definition: efi_snp.h:61
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces
Definition: UefiSpec.h:1916
EFI_DEVICE_PATH_PROTOCOL * hii_child_path
Device path of HII child handle.
Definition: efi_snp.h:65
EFI_GUID efi_device_path_protocol_guid
Device path protocol GUID.
Definition: efi_guid.c:132
EFI_SYSTEM_TABLE * efi_systab
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
static EFI_HII_DATABASE_PROTOCOL * efihii
EFI HII database protocol.
Definition: efi_snp_hii.c:78

References EFI_SYSTEM_TABLE::BootServices, efi_child_del(), efi_device_path_protocol_guid, efi_hii_config_access_protocol_guid, efi_systab, efihii, free, efi_snp_device::handle, efi_snp_device::hii, efi_snp_device::hii_child_handle, efi_snp_device::hii_child_path, efi_snp_device::hii_handle, NULL, efi_snp_device::package_list, _EFI_HII_DATABASE_PROTOCOL::RemovePackageList, and EFI_BOOT_SERVICES::UninstallMultipleProtocolInterfaces.

Referenced by efi_snp_probe(), and efi_snp_remove().

◆ find_snpdev()

struct efi_snp_device* find_snpdev ( EFI_HANDLE  handle)

Find SNP device by EFI device handle.

Parameters
handleEFI device handle
Return values
snpdevSNP device, or NULL

Definition at line 1939 of file efi_snp.c.

1939  {
1940  struct efi_snp_device *snpdev;
1941 
1942  list_for_each_entry ( snpdev, &efi_snp_devices, list ) {
1943  if ( snpdev->handle == handle )
1944  return snpdev;
1945  }
1946  return NULL;
1947 }
EFI_HANDLE handle
EFI device handle.
Definition: efi_snp.h:35
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
An SNP device.
Definition: efi_snp.h:27
uint16_t handle
Handle.
Definition: smbios.h:16
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct list_head list
List of SNP devices.
Definition: efi_snp.h:29

References handle, efi_snp_device::handle, efi_snp_device::list, list_for_each_entry, and NULL.

Referenced by nii_supported(), and snp_supported().

◆ last_opened_snpdev()

struct efi_snp_device* last_opened_snpdev ( void  )

Get most recently opened SNP device.

Return values
snpdevMost recently opened SNP device, or NULL

Definition at line 1954 of file efi_snp.c.

1954  {
1955  struct net_device *netdev;
1956 
1958  if ( ! netdev )
1959  return NULL;
1960 
1961  return efi_snp_demux ( netdev );
1962 }
static struct net_device * netdev
Definition: gdbudp.c:52
struct net_device * last_opened_netdev(void)
Get most recently opened network device.
Definition: netdevice.c:973
A network device.
Definition: netdevice.h:348
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
static struct efi_snp_device * efi_snp_demux(struct net_device *netdev)
Locate SNP device corresponding to network device.
Definition: efi_snp.c:1606

References efi_snp_demux(), last_opened_netdev(), netdev, and NULL.

Referenced by efi_block_hook(), and efi_image_exec().

◆ efi_snp_add_claim()

void efi_snp_add_claim ( int  delta)

Add to SNP claimed/released count.

Parameters
deltaClaim count change

Definition at line 1969 of file efi_snp.c.

1969  {
1971  struct efi_snp_device *snpdev;
1972 
1973  /* Raise TPL if we are about to claim devices */
1974  if ( ! efi_snp_claimed )
1976 
1977  /* Claim SNP devices */
1978  efi_snp_claimed += delta;
1979  assert ( efi_snp_claimed >= 0 );
1980 
1981  /* Update SNP mode state for each interface */
1982  list_for_each_entry ( snpdev, &efi_snp_devices, list )
1983  efi_snp_set_state ( snpdev );
1984 
1985  /* Restore TPL if we have released devices */
1986  if ( ! efi_snp_claimed )
1987  bs->RestoreTPL ( efi_snp_old_tpl );
1988 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
EFI_RAISE_TPL RaiseTPL
Definition: UefiSpec.h:1845
static void efi_snp_set_state(struct efi_snp_device *snpdev)
Set EFI SNP mode state.
Definition: efi_snp.c:89
static int efi_snp_claimed
Network devices are currently claimed for use by iPXE.
Definition: efi_snp.c:46
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
EFI Boot Services Table.
Definition: UefiSpec.h:1836
An SNP device.
Definition: efi_snp.h:27
#define TPL_CALLBACK
Definition: UefiSpec.h:591
EFI_SYSTEM_TABLE * efi_systab
EFI_RESTORE_TPL RestoreTPL
Definition: UefiSpec.h:1846
static EFI_TPL efi_snp_old_tpl
TPL prior to network devices being claimed.
Definition: efi_snp.c:49
struct list_head list
List of SNP devices.
Definition: efi_snp.h:29

References assert(), EFI_SYSTEM_TABLE::BootServices, efi_snp_claimed, efi_snp_old_tpl, efi_snp_set_state(), efi_systab, efi_snp_device::list, list_for_each_entry, EFI_BOOT_SERVICES::RaiseTPL, EFI_BOOT_SERVICES::RestoreTPL, and TPL_CALLBACK.

Referenced by efi_snp_claim(), and efi_snp_release().

◆ efi_snp_claim()

static void efi_snp_claim ( void  )
inlinestatic

Claim network devices for use by iPXE.

Definition at line 88 of file efi_snp.h.

88  {
89  efi_snp_add_claim ( +1 );
90 }
void efi_snp_add_claim(int delta)
Add to SNP claimed/released count.
Definition: efi_snp.c:1969

References efi_snp_add_claim().

Referenced by _efi_start(), efi_block_boot(), efi_block_io_read(), efi_block_io_reset(), efi_block_io_write(), efi_download_start(), efi_image_exec(), efi_pxe_dhcp(), efi_pxe_mtftp(), efi_pxe_udp_open(), and efi_snp_load_file().

◆ efi_snp_release()

static void efi_snp_release ( void  )
inlinestatic

Release network devices for use via SNP.

Definition at line 96 of file efi_snp.h.

96  {
97  efi_snp_add_claim ( -1 );
98 }
void efi_snp_add_claim(int delta)
Add to SNP claimed/released count.
Definition: efi_snp.c:1969

References efi_snp_add_claim().

Referenced by _efi_start(), efi_block_boot(), efi_block_io_read(), efi_block_io_reset(), efi_block_io_write(), efi_download_close(), efi_image_exec(), efi_pxe_dhcp(), efi_pxe_mtftp(), efi_pxe_udp_close(), and efi_snp_load_file().