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/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 int chained_locate (struct chained_protocol *chained)
 Locate chainloaded protocol instance. 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...
 
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...
 

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 int chained_locate ( struct chained_protocol chained)
static

Locate chainloaded protocol instance.

Parameters
chainedChainloaded protocol
Return values
rcReturn status code

Definition at line 74 of file snponly.c.

74  {
77  EFI_HANDLE parent;
78  EFI_STATUS efirc;
79  int rc;
80 
81  /* Locate handle supporting this protocol */
82  if ( ( rc = efi_locate_device ( device, chained->protocol,
83  &parent ) ) != 0 ) {
84  DBGC ( device, "CHAINED %s does not support %s: %s\n",
86  efi_guid_ntoa ( chained->protocol ), strerror ( rc ) );
87  goto err_locate_device;
88  }
89  DBGC ( device, "CHAINED %s found %s on ", efi_handle_name ( device ),
90  efi_guid_ntoa ( chained->protocol ) );
91  DBGC ( device, "%s\n", efi_handle_name ( parent ) );
92 
93  /* Get protocol instance */
94  if ( ( efirc = bs->OpenProtocol ( parent, chained->protocol,
95  &chained->interface, efi_image_handle,
96  device,
98  rc = -EEFI ( efirc );
99  DBGC ( device, "CHAINED %s could not open %s on ",
101  efi_guid_ntoa ( chained->protocol ) );
102  DBGC ( device, "%s: %s\n",
103  efi_handle_name ( parent ), strerror ( rc ) );
104  goto err_open_protocol;
105  }
106 
107  err_locate_device:
108  bs->CloseProtocol ( parent, chained->protocol, efi_image_handle,
109  device );
110  err_open_protocol:
111  return rc;
112 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
EFI_LOADED_IMAGE_PROTOCOL * efi_loaded_image
Loaded image protocol for this image.
Definition: efi_init.c:33
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:157
#define DBGC(...)
Definition: compiler.h:505
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1906
A hardware device.
Definition: device.h:73
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
Definition: UefiSpec.h:1271
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:713
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:30
EFI_GUID * protocol
Protocol GUID.
Definition: snponly.c:46
const char * efi_guid_ntoa(EFI_GUID *guid)
Convert GUID to a printable string.
Definition: efi_debug.c:192
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
void * interface
Protocol instance installed on the loaded image's device handle.
Definition: snponly.c:55
int efi_locate_device(EFI_HANDLE device, EFI_GUID *protocol, EFI_HANDLE *parent)
Locate parent device supporting a given protocol.
Definition: efi_utils.c:73
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1905
Definition: efi.h:55
EFI_HANDLE DeviceHandle
The device handle that the EFI Image was loaded from.
Definition: LoadedImage.h:61

References EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, DBGC, 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, chained_protocol::interface, 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 121 of file snponly.c.

122  {
124  EFI_STATUS efirc;
125  void *interface;
126  int rc;
127 
128  /* Get protocol */
129  if ( ( efirc = bs->OpenProtocol ( device, chained->protocol, &interface,
132  rc = -EEFI ( efirc );
133  DBGCP ( device, "CHAINED %s is not a %s device\n",
135  efi_guid_ntoa ( chained->protocol ) );
136  goto err_open_protocol;
137  }
138 
139  /* Test for a match against the chainloading device */
140  if ( interface != chained->interface ) {
141  DBGC ( device, "CHAINED %s %p is not the chainloaded %s\n",
143  efi_guid_ntoa ( chained->protocol ) );
144  rc = -ENOTTY;
145  goto err_no_match;
146  }
147 
148  /* Success */
149  rc = 0;
150  DBGC ( device, "CHAINED %s %p is the chainloaded %s\n",
152  efi_guid_ntoa ( chained->protocol ) );
153 
154  err_no_match:
156  device );
157  err_open_protocol:
158  return rc;
159 }
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:157
#define DBGC(...)
Definition: compiler.h:505
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1906
A hardware device.
Definition: device.h:73
An object interface.
Definition: interface.h:109
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
Definition: UefiSpec.h:1271
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:713
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:30
EFI_GUID * protocol
Protocol GUID.
Definition: snponly.c:46
const char * efi_guid_ntoa(EFI_GUID *guid)
Convert GUID to a printable string.
Definition: efi_debug.c:192
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
void * interface
Protocol instance installed on the loaded image's device handle.
Definition: snponly.c:55
#define DBGCP(...)
Definition: compiler.h:539
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1905

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

Referenced by 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 167 of file snponly.c.

167  {
168 
169  return chained_supported ( device, &chained_snp );
170 }
static int chained_supported(EFI_HANDLE device, struct chained_protocol *chained)
Check to see if driver supports a device.
Definition: snponly.c:121
A hardware device.
Definition: device.h:73
static struct chained_protocol chained_snp
Chainloaded SNP protocol.
Definition: snponly.c:59

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 178 of file snponly.c.

178  {
179 
180  return chained_supported ( device, &chained_nii );
181 }
static int chained_supported(EFI_HANDLE device, struct chained_protocol *chained)
Check to see if driver supports a device.
Definition: snponly.c:121
A hardware device.
Definition: device.h:73
static struct chained_protocol chained_nii
Chainloaded NII protocol.
Definition: snponly.c:64

References chained_nii, and chained_supported().

◆ __efi_driver()

struct efi_driver snponly_driver __efi_driver ( EFI_DRIVER_NORMAL  )

EFI SNP 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 203 of file snponly.c.

203  {
204 
207 }
static struct chained_protocol chained_nii
Chainloaded NII protocol.
Definition: snponly.c:64
static struct chained_protocol chained_snp
Chainloaded SNP protocol.
Definition: snponly.c:59
static int chained_locate(struct chained_protocol *chained)
Locate chainloaded protocol instance.
Definition: snponly.c:74

References chained_locate(), 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:236

Chainloaded SNP protocol.

Definition at line 59 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:212

Chainloaded NII protocol.

Definition at line 64 of file snponly.c.

Referenced by chained_init(), and niionly_supported().