]> git.proxmox.com Git - mirror_edk2.git/blob - RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCommon.c
RedfishPkg/RedfishConfigHandler: EDKII RedfishConfigHandler Protocol
[mirror_edk2.git] / RedfishPkg / RedfishConfigHandler / RedfishConfigHandlerCommon.c
1 /** @file
2 The common code of EDKII Redfish Configuration Handler driver.
3
4 (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include "RedfishConfigHandlerCommon.h"
11
12 REDFISH_CONFIG_DRIVER_DATA gRedfishConfigData; // Only one Redfish service supproted
13 // on platform for the BIOS
14 // Redfish configuration.
15 EFI_EVENT gEndOfDxeEvent = NULL;
16 EFI_EVENT gExitBootServiceEvent = NULL;
17 EDKII_REDFISH_CREDENTIAL_PROTOCOL *gCredential = NULL;
18
19 /**
20 Callback function executed when the EndOfDxe event group is signaled.
21
22 @param[in] Event Event whose notification function is being invoked.
23 @param[out] Context Pointer to the Context buffer.
24
25 **/
26 VOID
27 EFIAPI
28 RedfishConfigOnEndOfDxe (
29 IN EFI_EVENT Event,
30 OUT VOID *Context
31 )
32 {
33 EFI_STATUS Status;
34
35 Status = gCredential->StopService (gCredential, ServiceStopTypeSecureBootDisabled);
36 if (EFI_ERROR(Status) && Status != EFI_UNSUPPORTED) {
37 DEBUG ((DEBUG_ERROR, "Redfish credential protocol faied to stop service on EndOfDxe: %r", Status));
38 }
39
40 //
41 // Close event, so it will not be invoked again.
42 //
43 gBS->CloseEvent (gEndOfDxeEvent);
44 gEndOfDxeEvent = NULL;
45 }
46
47 /**
48 Callback function executed when the ExitBootService event group is signaled.
49
50 @param[in] Event Event whose notification function is being invoked.
51 @param[out] Context Pointer to the Context buffer
52
53 **/
54 VOID
55 EFIAPI
56 RedfishConfigOnExitBootService (
57 IN EFI_EVENT Event,
58 OUT VOID *Context
59 )
60 {
61 EFI_STATUS Status;
62
63 Status = gCredential->StopService (gCredential, ServiceStopTypeExitBootService);
64 if (EFI_ERROR(Status) && Status != EFI_UNSUPPORTED) {
65 DEBUG ((DEBUG_ERROR, "Redfish credential protocol faied to stop service on ExitBootService: %r", Status));
66 }
67 }
68
69 /**
70 Unloads an image.
71
72 @param[in] ImageHandle Handle that identifies the image to be unloaded.
73
74 @retval EFI_SUCCESS The image has been unloaded.
75
76 **/
77 EFI_STATUS
78 RedfishConfigDriverCommonUnload (
79 IN EFI_HANDLE ImageHandle
80 )
81 {
82 if (gEndOfDxeEvent != NULL) {
83 gBS->CloseEvent (gEndOfDxeEvent);
84 gEndOfDxeEvent = NULL;
85 }
86
87 if (gExitBootServiceEvent != NULL) {
88 gBS->CloseEvent (gExitBootServiceEvent);
89 gExitBootServiceEvent = NULL;
90 }
91
92 if (gRedfishConfigData.Event != NULL) {
93 gBS->CloseEvent (gRedfishConfigData.Event);
94 gRedfishConfigData.Event = NULL;
95 }
96
97 return EFI_SUCCESS;
98 }
99
100 /**
101 This is the common code for Redfish configuration UEFI and DXE driver
102 initialization.
103
104 @param[in] ImageHandle The firmware allocated handle for the UEFI image.
105 @param[in] SystemTable A pointer to the EFI System Table.
106
107 @retval EFI_SUCCESS The operation completed successfully.
108 @retval Others An unexpected error occurred.
109 **/
110 EFI_STATUS
111 RedfishConfigCommonInit (
112 IN EFI_HANDLE ImageHandle,
113 IN EFI_SYSTEM_TABLE *SystemTable
114 )
115 {
116 EFI_STATUS Status;
117 //
118 // Locate Redfish Credential Protocol to get credential for
119 // accessing to Redfish service.
120 //
121 Status = gBS->LocateProtocol (&gEdkIIRedfishCredentialProtocolGuid, NULL, (VOID **) &gCredential);
122 if (EFI_ERROR (Status)) {
123 DEBUG ((DEBUG_INFO, "%a: No Redfish Credential Protocol is installed on system.", __FUNCTION__));
124 return Status;
125 }
126 //
127 // Create EndOfDxe Event.
128 //
129 Status = gBS->CreateEventEx (
130 EVT_NOTIFY_SIGNAL,
131 TPL_CALLBACK,
132 RedfishConfigOnEndOfDxe,
133 NULL,
134 &gEfiEndOfDxeEventGroupGuid,
135 &gEndOfDxeEvent
136 );
137 if (EFI_ERROR (Status)) {
138 DEBUG ((DEBUG_ERROR, "%a: Fail to register End Of DXE event.", __FUNCTION__));
139 return Status;
140 }
141 //
142 // Create Exit Boot Service event.
143 //
144 Status = gBS->CreateEventEx (
145 EVT_NOTIFY_SIGNAL,
146 TPL_CALLBACK,
147 RedfishConfigOnExitBootService,
148 NULL,
149 &gEfiEventExitBootServicesGuid,
150 &gExitBootServiceEvent
151 );
152 if (EFI_ERROR (Status)) {
153 gBS->CloseEvent (gEndOfDxeEvent);
154 gEndOfDxeEvent = NULL;
155 DEBUG ((DEBUG_ERROR, "%a: Fail to register Exit Boot Service event.", __FUNCTION__));
156 return Status;
157 }
158 return EFI_SUCCESS;
159 }
160 /**
161 This is the common code to stop EDK2 Redfish feature driver.
162
163 @retval EFI_SUCCESS All EDK2 Redfish feature drivers are
164 stopped.
165 @retval Others An unexpected error occurred.
166 **/
167 EFI_STATUS
168 RedfishConfigCommonStop (
169 VOID
170 )
171 {
172 EFI_STATUS Status;
173 EFI_HANDLE *HandleBuffer;
174 UINTN NumberOfHandles;
175 UINTN Index;
176 EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *ConfigHandler;
177
178 Status = gBS->LocateHandleBuffer (
179 ByProtocol,
180 &gEdkIIRedfishConfigHandlerProtocolGuid,
181 NULL,
182 &NumberOfHandles,
183 &HandleBuffer
184 );
185 if (EFI_ERROR (Status) && Status != EFI_NOT_FOUND) {
186 return Status;
187 }
188
189 Status = EFI_SUCCESS;
190 for (Index = 0; Index < NumberOfHandles; Index++) {
191 Status = gBS->HandleProtocol (
192 HandleBuffer[Index],
193 &gEdkIIRedfishConfigHandlerProtocolGuid,
194 (VOID**) &ConfigHandler
195 );
196 ASSERT_EFI_ERROR (Status);
197
198 Status = ConfigHandler->Stop (ConfigHandler);
199 if (EFI_ERROR (Status) && Status != EFI_UNSUPPORTED) {
200 DEBUG ((DEBUG_ERROR, "ERROR: Failed to stop Redfish config handler %p.\n", ConfigHandler));
201 break;
202 }
203 }
204 return Status;
205 }
206 /**
207 Callback function executed when a Redfish Config Handler Protocol is installed
208 by EDK2 Redfish Feature Drivers.
209
210 **/
211 VOID
212 RedfishConfigHandlerInitialization (
213 VOID
214 )
215 {
216 EFI_STATUS Status;
217 EFI_HANDLE *HandleBuffer;
218 UINTN NumberOfHandles;
219 EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *ConfigHandler;
220 UINTN Index;
221 UINT32 Id;
222
223 Status = gBS->LocateHandleBuffer (
224 ByProtocol,
225 &gEdkIIRedfishConfigHandlerProtocolGuid,
226 NULL,
227 &NumberOfHandles,
228 &HandleBuffer
229 );
230 if (EFI_ERROR (Status)) {
231 return;
232 }
233
234 for (Index = 0; Index < NumberOfHandles; Index++) {
235 Status = gBS->HandleProtocol (
236 HandleBuffer [Index],
237 &gEfiCallerIdGuid,
238 (VOID **) &Id
239 );
240 if (!EFI_ERROR (Status)) {
241 continue;
242 }
243
244 Status = gBS->HandleProtocol (
245 HandleBuffer [Index],
246 &gEdkIIRedfishConfigHandlerProtocolGuid,
247 (VOID**) &ConfigHandler
248 );
249 ASSERT_EFI_ERROR (Status);
250 Status = ConfigHandler->Init (ConfigHandler, &gRedfishConfigData.RedfishServiceInfo);
251 if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {
252 DEBUG ((DEBUG_ERROR, "ERROR: Failed to init Redfish config handler %p.\n", ConfigHandler));
253 }
254 //
255 // Install caller ID to indicate Redfish Configure Handler is initialized.
256 //
257 Status = gBS->InstallProtocolInterface (
258 &HandleBuffer [Index],
259 &gEfiCallerIdGuid,
260 EFI_NATIVE_INTERFACE,
261 (VOID *)&gRedfishConfigData.CallerId
262 );
263 ASSERT_EFI_ERROR (Status);
264 }
265 }