iPXE
efi_service.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2024 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 FILE_SECBOOT ( PERMITTED );
26 
27 /** @file
28  *
29  * EFI service binding
30  *
31  */
32 
33 #include <string.h>
34 #include <errno.h>
35 #include <ipxe/efi/efi.h>
36 #include <ipxe/efi/efi_service.h>
38 
39 /**
40  * Add service to child handle
41  *
42  * @v service Service binding handle
43  * @v binding Service binding protocol GUID
44  * @v handle Handle on which to install child
45  * @ret rc Return status code
46  */
47 int efi_service_add ( EFI_HANDLE service, EFI_GUID *binding,
48  EFI_HANDLE *handle ) {
50  EFI_STATUS efirc;
51  int rc;
52 
53  /* Open service binding protocol */
54  if ( ( rc = efi_open ( service, binding, &sb ) ) != 0 ) {
55  DBGC ( service, "EFISVC %s cannot open %s binding: %s\n",
56  efi_handle_name ( service ), efi_guid_ntoa ( binding ),
57  strerror ( rc ) );
58  return rc;
59  }
60 
61  /* Create child handle */
62  if ( ( efirc = sb->CreateChild ( sb, handle ) ) != 0 ) {
63  rc = -EEFI ( efirc );
64  DBGC ( service, "EFISVC %s could not create %s child: %s\n",
65  efi_handle_name ( service ), efi_guid_ntoa ( binding ),
66  strerror ( rc ) );
67  return rc;
68  }
69 
70  DBGC ( service, "EFISVC %s created %s child ",
71  efi_handle_name ( service ), efi_guid_ntoa ( binding ) );
72  DBGC ( service, "%s\n", efi_handle_name ( *handle ) );
73  return 0;
74 }
75 
76 /**
77  * Remove service from child handle
78  *
79  * @v service Service binding handle
80  * @v binding Service binding protocol GUID
81  * @v handle Child handle
82  * @ret rc Return status code
83  */
84 int efi_service_del ( EFI_HANDLE service, EFI_GUID *binding,
85  EFI_HANDLE handle ) {
87  EFI_STATUS efirc;
88  int rc;
89 
90  DBGC ( service, "EFISVC %s removing %s child ",
91  efi_handle_name ( service ), efi_guid_ntoa ( binding ) );
92  DBGC ( service, "%s\n", efi_handle_name ( handle ) );
93 
94  /* Open service binding protocol */
95  if ( ( rc = efi_open ( service, binding, &sb ) ) != 0 ) {
96  DBGC ( service, "EFISVC %s cannot open %s binding: %s\n",
97  efi_handle_name ( service ), efi_guid_ntoa ( binding ),
98  strerror ( rc ) );
99  return rc;
100  }
101 
102  /* Destroy child handle */
103  if ( ( efirc = sb->DestroyChild ( sb, handle ) ) != 0 ) {
104  rc = -EEFI ( efirc );
105  DBGC ( service, "EFISVC %s could not destroy %s child ",
106  efi_handle_name ( service ), efi_guid_ntoa ( binding ) );
107  DBGC ( service, "%s: %s\n",
108  efi_handle_name ( handle ), strerror ( rc ) );
109  return rc;
110  }
111 
112  return 0;
113 }
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:175
128 bit buffer containing a unique identifier value.
Definition: Base.h:216
Error codes.
int efi_service_del(EFI_HANDLE service, EFI_GUID *binding, EFI_HANDLE handle)
Remove service from child handle.
Definition: efi_service.c:84
#define DBGC(...)
Definition: compiler.h:505
EFI_SERVICE_BINDING_CREATE_CHILD CreateChild
EFI service binding.
EFI_SERVICE_BINDING_DESTROY_CHILD DestroyChild
UEFI Service Binding Protocol is defined in UEFI specification.
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:652
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
#define efi_open(handle, protocol, interface)
Open protocol for ephemeral use.
Definition: efi.h:444
The EFI_SERVICE_BINDING_PROTOCOL provides member functions to create and destroy child handles.
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
Definition: efi_guid.c:726
int efi_service_add(EFI_HANDLE service, EFI_GUID *binding, EFI_HANDLE *handle)
Add service to child handle.
Definition: efi_service.c:47
EFI API.
FILE_SECBOOT(PERMITTED)
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:32
uint16_t handle
Handle.
Definition: smbios.h:17
String functions.
Definition: efi.h:62