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