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

EFI chainloaded-device-only driver. More...

#include <string.h>
#include <errno.h>
#include <ipxe/init.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_driver.h>
#include <ipxe/efi/efi_utils.h>
#include <ipxe/efi/mnpnet.h>
#include <ipxe/efi/Protocol/SimpleNetwork.h>
#include <ipxe/efi/Protocol/NetworkInterfaceIdentifier.h>
#include "snpnet.h"
#include "nii.h"

Go to the source code of this file.

Data Structures

struct  chained_protocol
 A chainloaded protocol. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static void chained_locate (struct chained_protocol *chained)
 Locate chainloaded protocol. More...
 
static int chained_supported (EFI_HANDLE device, struct chained_protocol *chained)
 Check to see if driver supports a device. More...
 
static int snponly_supported (EFI_HANDLE device)
 Check to see if driver supports a device. More...
 
static int niionly_supported (EFI_HANDLE device)
 Check to see if driver supports a device. More...
 
static int mnponly_supported (EFI_HANDLE device)
 Check to see if driver supports a device. More...
 
struct efi_driver snponly_driver __efi_driver (EFI_DRIVER_NORMAL)
 EFI SNP chainloading-device-only driver. More...
 
static void chained_init (void)
 Initialise EFI chainloaded-device-only driver. More...
 
struct init_fn chained_init_fn __init_fn (INIT_LATE)
 EFI chainloaded-device-only initialisation function. More...
 

Variables

static struct chained_protocol chained_snp
 Chainloaded SNP protocol. More...
 
static struct chained_protocol chained_nii
 Chainloaded NII protocol. More...
 
static struct chained_protocol chained_mnp
 Chainloaded MNP protocol. More...
 

Detailed Description

EFI chainloaded-device-only driver.

Definition in file snponly.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ chained_locate()

static void chained_locate ( struct chained_protocol chained)
static

Locate chainloaded protocol.

Parameters
chainedChainloaded protocol

Definition at line 88 of file snponly.c.

88  {
92  void *match = NULL;
93  void *interface;
94  unsigned int skip;
95  EFI_STATUS efirc;
96  int rc;
97 
98  /* Identify target device handle */
99  for ( skip = 0 ; ; skip++ ) {
100 
101  /* Locate handle supporting this protocol */
102  if ( ( rc = efi_locate_device ( device, chained->protocol,
103  &handle, skip ) ) != 0 ) {
104  if ( skip == 0 ) {
105  DBGC ( device, "CHAINED %s does not support "
106  "%s: %s\n", efi_handle_name ( device ),
107  efi_guid_ntoa ( chained->protocol ),
108  strerror ( rc ) );
109  }
110  break;
111  }
112 
113  /* Get protocol instance */
114  if ( ( efirc = bs->OpenProtocol (
115  handle, chained->protocol, &interface,
118  rc = -EEFI ( efirc );
119  DBGC ( device, "CHAINED %s could not open %s on ",
121  efi_guid_ntoa ( chained->protocol ) );
122  DBGC ( device, "%s: %s\n",
123  efi_handle_name ( handle ), strerror ( rc ) );
124  break;
125  }
126  bs->CloseProtocol ( handle, chained->protocol,
128 
129  /* Stop if we reach a non-matching protocol instance */
130  if ( match && ( match != interface ) ) {
131  DBGC ( device, "CHAINED %s found non-matching %s on ",
133  efi_guid_ntoa ( chained->protocol ) );
134  DBGC ( device, "%s\n", efi_handle_name ( handle ) );
135  break;
136  }
137 
138  /* Record this handle */
139  chained->device = handle;
140  match = interface;
141  DBGC ( device, "CHAINED %s found %s on ",
143  efi_guid_ntoa ( chained->protocol ) );
144  DBGC ( device, "%s\n", efi_handle_name ( chained->device ) );
145  }
146 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2081
EFI_LOADED_IMAGE_PROTOCOL * efi_loaded_image
Loaded image protocol for this image.
Definition: efi_init.c:37
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:171
EFI_HANDLE device
Target device handle.
Definition: snponly.c:65
#define DBGC(...)
Definition: compiler.h:505
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1987
A hardware device.
Definition: device.h:73
An object interface.
Definition: interface.h:124
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
Definition: UefiSpec.h:1344
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:808
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
Definition: efi_debug.c:254
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1917
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:34
int efi_locate_device(EFI_HANDLE device, EFI_GUID *protocol, EFI_HANDLE *parent, unsigned int skip)
Locate parent device supporting a given protocol.
Definition: efi_utils.c:45
EFI_GUID * protocol
Protocol GUID.
Definition: snponly.c:47
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1986
uint16_t handle
Handle.
Definition: smbios.h:16
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
Definition: efi.h:59
EFI_HANDLE DeviceHandle
The device handle that the EFI Image was loaded from.
Definition: LoadedImage.h:55

References EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, DBGC, chained_protocol::device, EFI_LOADED_IMAGE_PROTOCOL::DeviceHandle, EEFI, efi_guid_ntoa(), efi_handle_name(), efi_image_handle, efi_loaded_image, efi_locate_device(), EFI_OPEN_PROTOCOL_GET_PROTOCOL, efi_systab, handle, NULL, EFI_BOOT_SERVICES::OpenProtocol, chained_protocol::protocol, rc, and strerror().

Referenced by chained_init().

◆ chained_supported()

static int chained_supported ( EFI_HANDLE  device,
struct chained_protocol chained 
)
static

Check to see if driver supports a device.

Parameters
deviceEFI device handle
chainedChainloaded protocol
Return values
rcReturn status code

Definition at line 155 of file snponly.c.

156  {
158  void *interface;
159  EFI_STATUS efirc;
160  int rc;
161 
162  /* Get protocol */
163  if ( ( efirc = bs->OpenProtocol ( device, chained->protocol, &interface,
166  rc = -EEFI ( efirc );
167  DBGCP ( device, "CHAINED %s is not a %s device\n",
169  efi_guid_ntoa ( chained->protocol ) );
170  goto err_open_protocol;
171  }
172 
173  /* Ignore non-matching handles */
174  if ( device != chained->device ) {
175  DBGC2 ( device, "CHAINED %s is not the chainloaded %s\n",
177  efi_guid_ntoa ( chained->protocol ) );
178  rc = -ENOTTY;
179  goto err_no_match;
180  }
181 
182  /* Success */
183  rc = 0;
184  DBGC ( device, "CHAINED %s is the chainloaded %s\n",
186  efi_guid_ntoa ( chained->protocol ) );
187 
188  err_no_match:
190  device );
191  err_open_protocol:
192  return rc;
193 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2081
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:171
EFI_HANDLE device
Target device handle.
Definition: snponly.c:65
#define DBGC(...)
Definition: compiler.h:505
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1987
A hardware device.
Definition: device.h:73
An object interface.
Definition: interface.h:124
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
Definition: UefiSpec.h:1344
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:808
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
Definition: efi_debug.c:254
EFI Boot Services Table.
Definition: UefiSpec.h:1917
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:34
EFI_GUID * protocol
Protocol GUID.
Definition: snponly.c:47
#define DBGC2(...)
Definition: compiler.h:522
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
#define DBGCP(...)
Definition: compiler.h:539
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1986

References EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, DBGC, DBGC2, DBGCP, chained_protocol::device, EEFI, efi_guid_ntoa(), efi_handle_name(), efi_image_handle, EFI_OPEN_PROTOCOL_GET_PROTOCOL, efi_systab, ENOTTY, EFI_BOOT_SERVICES::OpenProtocol, chained_protocol::protocol, and rc.

Referenced by mnponly_supported(), niionly_supported(), and snponly_supported().

◆ snponly_supported()

static int snponly_supported ( EFI_HANDLE  device)
static

Check to see if driver supports a device.

Parameters
deviceEFI device handle
Return values
rcReturn status code

Definition at line 201 of file snponly.c.

201  {
202 
203  return chained_supported ( device, &chained_snp );
204 }
static int chained_supported(EFI_HANDLE device, struct chained_protocol *chained)
Check to see if driver supports a device.
Definition: snponly.c:155
A hardware device.
Definition: device.h:73
static struct chained_protocol chained_snp
Chainloaded SNP protocol.
Definition: snponly.c:69

References chained_snp, and chained_supported().

◆ niionly_supported()

static int niionly_supported ( EFI_HANDLE  device)
static

Check to see if driver supports a device.

Parameters
deviceEFI device handle
Return values
rcReturn status code

Definition at line 212 of file snponly.c.

212  {
213 
214  return chained_supported ( device, &chained_nii );
215 }
static int chained_supported(EFI_HANDLE device, struct chained_protocol *chained)
Check to see if driver supports a device.
Definition: snponly.c:155
A hardware device.
Definition: device.h:73
static struct chained_protocol chained_nii
Chainloaded NII protocol.
Definition: snponly.c:74

References chained_nii, and chained_supported().

◆ mnponly_supported()

static int mnponly_supported ( EFI_HANDLE  device)
static

Check to see if driver supports a device.

Parameters
deviceEFI device handle
Return values
rcReturn status code

Definition at line 223 of file snponly.c.

223  {
224 
225  return chained_supported ( device, &chained_mnp );
226 }
static int chained_supported(EFI_HANDLE device, struct chained_protocol *chained)
Check to see if driver supports a device.
Definition: snponly.c:155
A hardware device.
Definition: device.h:73
static struct chained_protocol chained_mnp
Chainloaded MNP protocol.
Definition: snponly.c:79

References chained_mnp, and chained_supported().

◆ __efi_driver()

struct efi_driver snponly_driver __efi_driver ( EFI_DRIVER_NORMAL  )

EFI SNP chainloading-device-only driver.

EFI MNP chainloading-device-only driver.

EFI NII chainloading-device-only driver.

◆ chained_init()

static void chained_init ( void  )
static

Initialise EFI chainloaded-device-only driver.

Definition at line 256 of file snponly.c.

256  {
257 
261 }
static struct chained_protocol chained_nii
Chainloaded NII protocol.
Definition: snponly.c:74
static struct chained_protocol chained_snp
Chainloaded SNP protocol.
Definition: snponly.c:69
static void chained_locate(struct chained_protocol *chained)
Locate chainloaded protocol.
Definition: snponly.c:88
static struct chained_protocol chained_mnp
Chainloaded MNP protocol.
Definition: snponly.c:79

References chained_locate(), chained_mnp, chained_nii, and chained_snp.

◆ __init_fn()

struct init_fn chained_init_fn __init_fn ( INIT_LATE  )

EFI chainloaded-device-only initialisation function.

Variable Documentation

◆ chained_snp

struct chained_protocol chained_snp
static
Initial value:
= {
}
EFI_GUID efi_simple_network_protocol_guid
Simple network protocol GUID.
Definition: efi_guid.c:307

Chainloaded SNP protocol.

Definition at line 69 of file snponly.c.

Referenced by chained_init(), and snponly_supported().

◆ chained_nii

struct chained_protocol chained_nii
static
Initial value:
= {
}
EFI_GUID efi_nii31_protocol_guid
Network interface identifier protocol GUID (new version)
Definition: efi_guid.c:279

Chainloaded NII protocol.

Definition at line 74 of file snponly.c.

Referenced by chained_init(), and niionly_supported().

◆ chained_mnp

struct chained_protocol chained_mnp
static
Initial value:
= {
}
EFI_GUID efi_managed_network_service_binding_protocol_guid
Managed network service binding protocol GUID.
Definition: efi_guid.c:255

Chainloaded MNP protocol.

Definition at line 79 of file snponly.c.

Referenced by chained_init(), and mnponly_supported().