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