]> git.proxmox.com Git - mirror_edk2.git/blob - RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCommon.c
OvmfPkg: raise DXEFV size to 13 MB in the traditional platform FDFs
[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 //
119 // Locate Redfish Credential Protocol to get credential for
120 // accessing to Redfish service.
121 //
122 Status = gBS->LocateProtocol (&gEdkIIRedfishCredentialProtocolGuid, NULL, (VOID **)&gCredential);
123 if (EFI_ERROR (Status)) {
124 DEBUG ((DEBUG_INFO, "%a: No Redfish Credential Protocol is installed on system.", __FUNCTION__));
125 return Status;
126 }
127
128 //
129 // Create EndOfDxe Event.
130 //
131 Status = gBS->CreateEventEx (
132 EVT_NOTIFY_SIGNAL,
133 TPL_CALLBACK,
134 RedfishConfigOnEndOfDxe,
135 NULL,
136 &gEfiEndOfDxeEventGroupGuid,
137 &gEndOfDxeEvent
138 );
139 if (EFI_ERROR (Status)) {
140 DEBUG ((DEBUG_ERROR, "%a: Fail to register End Of DXE event.", __FUNCTION__));
141 return Status;
142 }
143
144 //
145 // Create Exit Boot Service event.
146 //
147 Status = gBS->CreateEventEx (
148 EVT_NOTIFY_SIGNAL,
149 TPL_CALLBACK,
150 RedfishConfigOnExitBootService,
151 NULL,
152 &gEfiEventExitBootServicesGuid,
153 &gExitBootServiceEvent
154 );
155 if (EFI_ERROR (Status)) {
156 gBS->CloseEvent (gEndOfDxeEvent);
157 gEndOfDxeEvent = NULL;
158 DEBUG ((DEBUG_ERROR, "%a: Fail to register Exit Boot Service event.", __FUNCTION__));
159 return Status;
160 }
161
162 return EFI_SUCCESS;
163 }
164
165 /**
166 This is the common code to stop EDK2 Redfish feature driver.
167
168 @retval EFI_SUCCESS All EDK2 Redfish feature drivers are
169 stopped.
170 @retval Others An unexpected error occurred.
171 **/
172 EFI_STATUS
173 RedfishConfigCommonStop (
174 VOID
175 )
176 {
177 EFI_STATUS Status;
178 EFI_HANDLE *HandleBuffer;
179 UINTN NumberOfHandles;
180 UINTN Index;
181 EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *ConfigHandler;
182
183 Status = gBS->LocateHandleBuffer (
184 ByProtocol,
185 &gEdkIIRedfishConfigHandlerProtocolGuid,
186 NULL,
187 &NumberOfHandles,
188 &HandleBuffer
189 );
190 if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
191 return Status;
192 }
193
194 Status = EFI_SUCCESS;
195 for (Index = 0; Index < NumberOfHandles; Index++) {
196 Status = gBS->HandleProtocol (
197 HandleBuffer[Index],
198 &gEdkIIRedfishConfigHandlerProtocolGuid,
199 (VOID **)&ConfigHandler
200 );
201 ASSERT_EFI_ERROR (Status);
202
203 Status = ConfigHandler->Stop (ConfigHandler);
204 if (EFI_ERROR (Status) && (Status != EFI_UNSUPPORTED)) {
205 DEBUG ((DEBUG_ERROR, "ERROR: Failed to stop Redfish config handler %p.\n", ConfigHandler));
206 break;
207 }
208 }
209
210 return Status;
211 }
212
213 /**
214 Callback function executed when a Redfish Config Handler Protocol is installed
215 by EDK2 Redfish Feature Drivers.
216
217 **/
218 VOID
219 RedfishConfigHandlerInitialization (
220 VOID
221 )
222 {
223 EFI_STATUS Status;
224 EFI_HANDLE *HandleBuffer;
225 UINTN NumberOfHandles;
226 EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *ConfigHandler;
227 UINTN Index;
228 UINT32 Id;
229
230 Status = gBS->LocateHandleBuffer (
231 ByProtocol,
232 &gEdkIIRedfishConfigHandlerProtocolGuid,
233 NULL,
234 &NumberOfHandles,
235 &HandleBuffer
236 );
237 if (EFI_ERROR (Status)) {
238 return;
239 }
240
241 for (Index = 0; Index < NumberOfHandles; Index++) {
242 Status = gBS->HandleProtocol (
243 HandleBuffer[Index],
244 &gEfiCallerIdGuid,
245 (VOID **)&Id
246 );
247 if (!EFI_ERROR (Status)) {
248 continue;
249 }
250
251 Status = gBS->HandleProtocol (
252 HandleBuffer[Index],
253 &gEdkIIRedfishConfigHandlerProtocolGuid,
254 (VOID **)&ConfigHandler
255 );
256 ASSERT_EFI_ERROR (Status);
257 Status = ConfigHandler->Init (ConfigHandler, &gRedfishConfigData.RedfishServiceInfo);
258 if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
259 DEBUG ((DEBUG_ERROR, "ERROR: Failed to init Redfish config handler %p.\n", ConfigHandler));
260 }
261
262 //
263 // Install caller ID to indicate Redfish Configure Handler is initialized.
264 //
265 Status = gBS->InstallProtocolInterface (
266 &HandleBuffer[Index],
267 &gEfiCallerIdGuid,
268 EFI_NATIVE_INTERFACE,
269 (VOID *)&gRedfishConfigData.CallerId
270 );
271 ASSERT_EFI_ERROR (Status);
272 }
273 }