iPXE
Functions
efi_service.c File Reference

EFI service binding. More...

#include <string.h>
#include <errno.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_service.h>
#include <ipxe/efi/Protocol/ServiceBinding.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int efi_service_add (EFI_HANDLE service, EFI_GUID *binding, EFI_HANDLE *handle)
 Add service to child handle. More...
 
int efi_service_del (EFI_HANDLE service, EFI_GUID *binding, EFI_HANDLE handle)
 Remove service from child handle. More...
 

Detailed Description

EFI service binding.

Definition in file efi_service.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ efi_service_add()

int efi_service_add ( EFI_HANDLE  service,
EFI_GUID binding,
EFI_HANDLE handle 
)

Add service to child handle.

Parameters
serviceService binding handle
bindingService binding protocol GUID
handleHandle on which to install child
Return values
rcReturn status code

Definition at line 46 of file efi_service.c.

47  {
49  union {
51  void *interface;
52  } u;
53  EFI_STATUS efirc;
54  int rc;
55 
56  /* Open service binding protocol */
57  if ( ( efirc = bs->OpenProtocol ( service, binding, &u.interface,
58  efi_image_handle, service,
60  rc = -EEFI ( efirc );
61  DBGC ( service, "EFISVC %s cannot open %s binding: %s\n",
62  efi_handle_name ( service ), efi_guid_ntoa ( binding ),
63  strerror ( rc ) );
64  goto err_open;
65  }
66 
67  /* Create child handle */
68  if ( ( efirc = u.sb->CreateChild ( u.sb, handle ) ) != 0 ) {
69  rc = -EEFI ( efirc );
70  DBGC ( service, "EFISVC %s could not create %s child: %s\n",
71  efi_handle_name ( service ), efi_guid_ntoa ( binding ),
72  strerror ( rc ) );
73  goto err_create;
74  }
75 
76  /* Success */
77  rc = 0;
78  DBGC ( service, "EFISVC %s created %s child ",
79  efi_handle_name ( service ), efi_guid_ntoa ( binding ) );
80  DBGC ( service, "%s\n", efi_handle_name ( *handle ) );
81 
82  err_create:
83  bs->CloseProtocol ( service, binding, efi_image_handle, service );
84  err_open:
85  return rc;
86 }
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
#define DBGC(...)
Definition: compiler.h:505
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1987
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
The EFI_SERVICE_BINDING_PROTOCOL provides member functions to create and destroy child handles.
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
union @17 u
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1986
uint16_t handle
Handle.
Definition: smbios.h:16

References EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, DBGC, EEFI, efi_guid_ntoa(), efi_handle_name(), efi_image_handle, EFI_OPEN_PROTOCOL_GET_PROTOCOL, efi_systab, handle, EFI_BOOT_SERVICES::OpenProtocol, rc, strerror(), and u.

Referenced by mnpnet_start().

◆ efi_service_del()

int efi_service_del ( EFI_HANDLE  service,
EFI_GUID binding,
EFI_HANDLE  handle 
)

Remove service from child handle.

Parameters
serviceService binding handle
bindingService binding protocol GUID
handleChild handle
Return values
rcReturn status code

Definition at line 96 of file efi_service.c.

97  {
99  union {
101  void *interface;
102  } u;
103  EFI_STATUS efirc;
104  int rc;
105 
106  DBGC ( service, "EFISVC %s removing %s child ",
107  efi_handle_name ( service ), efi_guid_ntoa ( binding ) );
108  DBGC ( service, "%s\n", efi_handle_name ( handle ) );
109 
110  /* Open service binding protocol */
111  if ( ( efirc = bs->OpenProtocol ( service, binding, &u.interface,
112  efi_image_handle, service,
114  rc = -EEFI ( efirc );
115  DBGC ( service, "EFISVC %s cannot open %s binding: %s\n",
116  efi_handle_name ( service ), efi_guid_ntoa ( binding ),
117  strerror ( rc ) );
118  goto err_open;
119  }
120 
121  /* Destroy child handle */
122  if ( ( efirc = u.sb->DestroyChild ( u.sb, handle ) ) != 0 ) {
123  rc = -EEFI ( efirc );
124  DBGC ( service, "EFISVC %s could not destroy %s child ",
125  efi_handle_name ( service ), efi_guid_ntoa ( binding ) );
126  DBGC ( service, "%s: %s\n",
127  efi_handle_name ( handle ), strerror ( rc ) );
128  goto err_destroy;
129  }
130 
131  /* Success */
132  rc = 0;
133 
134  err_destroy:
135  bs->CloseProtocol ( service, binding, efi_image_handle, service );
136  err_open:
137  return rc;
138 }
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
#define DBGC(...)
Definition: compiler.h:505
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1987
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
The EFI_SERVICE_BINDING_PROTOCOL provides member functions to create and destroy child handles.
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
union @17 u
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1986
uint16_t handle
Handle.
Definition: smbios.h:16

References EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, DBGC, EEFI, efi_guid_ntoa(), efi_handle_name(), efi_image_handle, EFI_OPEN_PROTOCOL_GET_PROTOCOL, efi_systab, handle, EFI_BOOT_SERVICES::OpenProtocol, rc, strerror(), and u.

Referenced by mnpnet_start(), and mnpnet_stop().