1 | /** @file
|
---|
2 | The UEFI driver model driver which is responsible for locating the
|
---|
3 | Redfish service through Redfish host interface and executing EDKII
|
---|
4 | Redfish feature drivers.
|
---|
5 |
|
---|
6 | Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
|
---|
7 | (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
|
---|
8 |
|
---|
9 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
10 |
|
---|
11 | **/
|
---|
12 |
|
---|
13 | #include "RedfishConfigHandlerDriver.h"
|
---|
14 |
|
---|
15 | EFI_EVENT gEfiRedfishDiscoverProtocolEvent = NULL;
|
---|
16 |
|
---|
17 | //
|
---|
18 | // Variables for using RFI Redfish Discover Protocol
|
---|
19 | //
|
---|
20 | VOID *gEfiRedfishDiscoverRegistration;
|
---|
21 | EFI_HANDLE gEfiRedfishDiscoverControllerHandle = NULL;
|
---|
22 | EFI_REDFISH_DISCOVER_PROTOCOL *gEfiRedfishDiscoverProtocol = NULL;
|
---|
23 | BOOLEAN gRedfishDiscoverActivated = FALSE;
|
---|
24 | BOOLEAN gRedfishServiceDiscovered = FALSE;
|
---|
25 | EFI_REDFISH_DISCOVER_NETWORK_INTERFACE *mNetworkInterfaces = NULL;
|
---|
26 | UINTN mNumberOfNetworkInterfaces;
|
---|
27 | EFI_EVENT mEdkIIRedfishHostInterfaceReadyEvent;
|
---|
28 | VOID *mEdkIIRedfishHostInterfaceRegistration;
|
---|
29 |
|
---|
30 | ///
|
---|
31 | /// Driver Binding Protocol instance
|
---|
32 | ///
|
---|
33 | EFI_DRIVER_BINDING_PROTOCOL gRedfishConfigDriverBinding = {
|
---|
34 | RedfishConfigDriverBindingSupported,
|
---|
35 | RedfishConfigDriverBindingStart,
|
---|
36 | RedfishConfigDriverBindingStop,
|
---|
37 | REDFISH_CONFIG_VERSION,
|
---|
38 | NULL,
|
---|
39 | NULL
|
---|
40 | };
|
---|
41 |
|
---|
42 | /**
|
---|
43 | Stop acquiring Redfish service.
|
---|
44 |
|
---|
45 | **/
|
---|
46 | VOID
|
---|
47 | RedfishConfigStopRedfishDiscovery (
|
---|
48 | VOID
|
---|
49 | )
|
---|
50 | {
|
---|
51 | if (gRedfishDiscoverActivated) {
|
---|
52 | //
|
---|
53 | // No more EFI Discover Protocol.
|
---|
54 | //
|
---|
55 | if (gEfiRedfishDiscoverProtocolEvent != NULL) {
|
---|
56 | gBS->CloseEvent (gEfiRedfishDiscoverProtocolEvent);
|
---|
57 | }
|
---|
58 |
|
---|
59 | gEfiRedfishDiscoverControllerHandle = NULL;
|
---|
60 | gEfiRedfishDiscoverProtocol = NULL;
|
---|
61 | gRedfishDiscoverActivated = FALSE;
|
---|
62 | gRedfishServiceDiscovered = FALSE;
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | /**
|
---|
67 | Callback function executed when a Redfish Config Handler Protocol is installed.
|
---|
68 |
|
---|
69 | @param[in] Event Event whose notification function is being invoked.
|
---|
70 | @param[in] Context Pointer to the REDFISH_CONFIG_DRIVER_DATA buffer.
|
---|
71 |
|
---|
72 | **/
|
---|
73 | VOID
|
---|
74 | EFIAPI
|
---|
75 | RedfishConfigHandlerInstalledCallback (
|
---|
76 | IN EFI_EVENT Event,
|
---|
77 | IN VOID *Context
|
---|
78 | )
|
---|
79 | {
|
---|
80 | if (!gRedfishDiscoverActivated) {
|
---|
81 | //
|
---|
82 | // No Redfish service is discovered yet.
|
---|
83 | //
|
---|
84 | return;
|
---|
85 | }
|
---|
86 |
|
---|
87 | RedfishConfigHandlerInitialization ();
|
---|
88 | }
|
---|
89 |
|
---|
90 | /**
|
---|
91 | Tests to see if this driver supports a given controller. If a child device is provided,
|
---|
92 | it further tests to see if this driver supports creating a handle for the specified child device.
|
---|
93 |
|
---|
94 | This function checks to see if the driver specified by This supports the device specified by
|
---|
95 | ControllerHandle. Drivers will typically use the device path attached to
|
---|
96 | ControllerHandle and/or the services from the bus I/O abstraction attached to
|
---|
97 | ControllerHandle to determine if the driver supports ControllerHandle. This function
|
---|
98 | may be called many times during platform initialization. In order to reduce boot times, the tests
|
---|
99 | performed by this function must be very small, and take as little time as possible to execute. This
|
---|
100 | function must not change the state of any hardware devices, and this function must be aware that the
|
---|
101 | device specified by ControllerHandle may already be managed by the same driver or a
|
---|
102 | different driver. This function must match its calls to AllocatePages() with FreePages(),
|
---|
103 | AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
|
---|
104 | Because ControllerHandle may have been previously started by the same driver, if a protocol is
|
---|
105 | already in the opened state, then it must not be closed with CloseProtocol(). This is required
|
---|
106 | to guarantee the state of ControllerHandle is not modified by this function.
|
---|
107 |
|
---|
108 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
|
---|
109 | @param[in] ControllerHandle The handle of the controller to test. This handle
|
---|
110 | must support a protocol interface that supplies
|
---|
111 | an I/O abstraction to the driver.
|
---|
112 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
|
---|
113 | parameter is ignored by device drivers, and is optional for bus
|
---|
114 | drivers. For bus drivers, if this parameter is not NULL, then
|
---|
115 | the bus driver must determine if the bus controller specified
|
---|
116 | by ControllerHandle and the child controller specified
|
---|
117 | by RemainingDevicePath are both supported by this
|
---|
118 | bus driver.
|
---|
119 |
|
---|
120 | @retval EFI_SUCCESS The device specified by ControllerHandle and
|
---|
121 | RemainingDevicePath is supported by the driver specified by This.
|
---|
122 | @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
|
---|
123 | RemainingDevicePath is not supported by the driver specified by This.
|
---|
124 | **/
|
---|
125 | EFI_STATUS
|
---|
126 | EFIAPI
|
---|
127 | RedfishConfigDriverBindingSupported (
|
---|
128 | IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
---|
129 | IN EFI_HANDLE ControllerHandle,
|
---|
130 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
|
---|
131 | )
|
---|
132 | {
|
---|
133 | EFI_REST_EX_PROTOCOL *RestEx;
|
---|
134 | EFI_STATUS Status;
|
---|
135 | EFI_HANDLE ChildHandle;
|
---|
136 |
|
---|
137 | ChildHandle = NULL;
|
---|
138 |
|
---|
139 | //
|
---|
140 | // Check if REST EX is ready. This just makes sure
|
---|
141 | // the network stack is brought up.
|
---|
142 | //
|
---|
143 | Status = NetLibCreateServiceChild (
|
---|
144 | ControllerHandle,
|
---|
145 | This->ImageHandle,
|
---|
146 | &gEfiRestExServiceBindingProtocolGuid,
|
---|
147 | &ChildHandle
|
---|
148 | );
|
---|
149 | if (EFI_ERROR (Status)) {
|
---|
150 | return EFI_UNSUPPORTED;
|
---|
151 | }
|
---|
152 |
|
---|
153 | //
|
---|
154 | // Test if REST EX protocol is ready.
|
---|
155 | //
|
---|
156 | Status = gBS->OpenProtocol (
|
---|
157 | ChildHandle,
|
---|
158 | &gEfiRestExProtocolGuid,
|
---|
159 | (VOID **)&RestEx,
|
---|
160 | This->DriverBindingHandle,
|
---|
161 | ControllerHandle,
|
---|
162 | EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
---|
163 | );
|
---|
164 | if (EFI_ERROR (Status)) {
|
---|
165 | Status = EFI_UNSUPPORTED;
|
---|
166 | }
|
---|
167 |
|
---|
168 | NetLibDestroyServiceChild (
|
---|
169 | ControllerHandle,
|
---|
170 | This->ImageHandle,
|
---|
171 | &gEfiRestExServiceBindingProtocolGuid,
|
---|
172 | ChildHandle
|
---|
173 | );
|
---|
174 | return Status;
|
---|
175 | }
|
---|
176 |
|
---|
177 | /**
|
---|
178 | Starts a device controller or a bus controller.
|
---|
179 |
|
---|
180 | The Start() function is designed to be invoked from the EFI boot service ConnectController().
|
---|
181 | As a result, much of the error checking on the parameters to Start() has been moved into this
|
---|
182 | common boot service. It is legal to call Start() from other locations,
|
---|
183 | but the following calling restrictions must be followed, or the system behavior will not be deterministic.
|
---|
184 | 1. ControllerHandle must be a valid EFI_HANDLE.
|
---|
185 | 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
|
---|
186 | EFI_DEVICE_PATH_PROTOCOL.
|
---|
187 | 3. Prior to calling Start(), the Supported() function for the driver specified by This must
|
---|
188 | have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
|
---|
189 |
|
---|
190 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
|
---|
191 | @param[in] ControllerHandle The handle of the controller to start. This handle
|
---|
192 | must support a protocol interface that supplies
|
---|
193 | an I/O abstraction to the driver.
|
---|
194 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
|
---|
195 | parameter is ignored by device drivers, and is optional for bus
|
---|
196 | drivers. For a bus driver, if this parameter is NULL, then handles
|
---|
197 | for all the children of Controller are created by this driver.
|
---|
198 | If this parameter is not NULL and the first Device Path Node is
|
---|
199 | not the End of Device Path Node, then only the handle for the
|
---|
200 | child device specified by the first Device Path Node of
|
---|
201 | RemainingDevicePath is created by this driver.
|
---|
202 | If the first Device Path Node of RemainingDevicePath is
|
---|
203 | the End of Device Path Node, no child handle is created by this
|
---|
204 | driver.
|
---|
205 |
|
---|
206 | @retval EFI_SUCCESS The driver is started.
|
---|
207 | @retval EFI_ALREADY_STARTED The driver was already started.
|
---|
208 |
|
---|
209 | **/
|
---|
210 | EFI_STATUS
|
---|
211 | EFIAPI
|
---|
212 | RedfishConfigDriverBindingStart (
|
---|
213 | IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
---|
214 | IN EFI_HANDLE ControllerHandle,
|
---|
215 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
|
---|
216 | )
|
---|
217 | {
|
---|
218 | VOID *ConfigHandlerRegistration;
|
---|
219 |
|
---|
220 | if (gRedfishConfigData.Event != NULL) {
|
---|
221 | return EFI_ALREADY_STARTED;
|
---|
222 | }
|
---|
223 |
|
---|
224 | gRedfishConfigData.Event = EfiCreateProtocolNotifyEvent (
|
---|
225 | &gEdkIIRedfishConfigHandlerProtocolGuid,
|
---|
226 | TPL_CALLBACK,
|
---|
227 | RedfishConfigHandlerInstalledCallback,
|
---|
228 | (VOID *)&gRedfishConfigData,
|
---|
229 | &ConfigHandlerRegistration
|
---|
230 | );
|
---|
231 | return EFI_SUCCESS;
|
---|
232 | }
|
---|
233 |
|
---|
234 | /**
|
---|
235 | Stops a device controller or a bus controller.
|
---|
236 |
|
---|
237 | The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
|
---|
238 | As a result, much of the error checking on the parameters to Stop() has been moved
|
---|
239 | into this common boot service. It is legal to call Stop() from other locations,
|
---|
240 | but the following calling restrictions must be followed, or the system behavior will not be deterministic.
|
---|
241 | 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
|
---|
242 | same driver's Start() function.
|
---|
243 | 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
|
---|
244 | EFI_HANDLE. In addition, all of these handles must have been created in this driver's
|
---|
245 | Start() function, and the Start() function must have called OpenProtocol() on
|
---|
246 | ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
|
---|
247 |
|
---|
248 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
|
---|
249 | @param[in] ControllerHandle A handle to the device being stopped. The handle must
|
---|
250 | support a bus specific I/O protocol for the driver
|
---|
251 | to use to stop the device.
|
---|
252 | @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
|
---|
253 | @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
|
---|
254 | if NumberOfChildren is 0.
|
---|
255 |
|
---|
256 | @retval EFI_SUCCESS The device was stopped.
|
---|
257 | @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
|
---|
258 |
|
---|
259 | **/
|
---|
260 | EFI_STATUS
|
---|
261 | EFIAPI
|
---|
262 | RedfishConfigDriverBindingStop (
|
---|
263 | IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
---|
264 | IN EFI_HANDLE ControllerHandle,
|
---|
265 | IN UINTN NumberOfChildren,
|
---|
266 | IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
|
---|
267 | )
|
---|
268 | {
|
---|
269 | EFI_STATUS Status;
|
---|
270 |
|
---|
271 | if (ControllerHandle == gEfiRedfishDiscoverControllerHandle) {
|
---|
272 | RedfishConfigStopRedfishDiscovery ();
|
---|
273 | }
|
---|
274 |
|
---|
275 | gBS->CloseProtocol (
|
---|
276 | ControllerHandle,
|
---|
277 | &gEfiRedfishDiscoverProtocolGuid,
|
---|
278 | gRedfishConfigData.Image,
|
---|
279 | gRedfishConfigData.Image
|
---|
280 | );
|
---|
281 |
|
---|
282 | Status = RedfishConfigCommonStop ();
|
---|
283 | if (EFI_ERROR (Status)) {
|
---|
284 | return EFI_DEVICE_ERROR;
|
---|
285 | }
|
---|
286 |
|
---|
287 | if (gRedfishConfigData.Event != NULL) {
|
---|
288 | gBS->CloseEvent (gRedfishConfigData.Event);
|
---|
289 | gRedfishConfigData.Event = NULL;
|
---|
290 | }
|
---|
291 |
|
---|
292 | return EFI_SUCCESS;
|
---|
293 | }
|
---|
294 |
|
---|
295 | /**
|
---|
296 | Callback function when Redfish service is discovered.
|
---|
297 |
|
---|
298 | @param[in] Event Event whose notification function is being invoked.
|
---|
299 | @param[out] Context Pointer to the Context buffer
|
---|
300 |
|
---|
301 | **/
|
---|
302 | VOID
|
---|
303 | EFIAPI
|
---|
304 | RedfishServiceDiscoveredCallback (
|
---|
305 | IN EFI_EVENT Event,
|
---|
306 | OUT VOID *Context
|
---|
307 | )
|
---|
308 | {
|
---|
309 | EFI_REDFISH_DISCOVERED_TOKEN *RedfishDiscoveredToken;
|
---|
310 | EFI_REDFISH_DISCOVERED_INSTANCE *RedfishInstance;
|
---|
311 |
|
---|
312 | RedfishDiscoveredToken = (EFI_REDFISH_DISCOVERED_TOKEN *)Context;
|
---|
313 | gBS->CloseEvent (RedfishDiscoveredToken->Event);
|
---|
314 |
|
---|
315 | //
|
---|
316 | // Only support one Redfish service on platform.
|
---|
317 | //
|
---|
318 | if (!gRedfishServiceDiscovered) {
|
---|
319 | RedfishInstance = RedfishDiscoveredToken->DiscoverList.RedfishInstances;
|
---|
320 | //
|
---|
321 | // Only pick up the first found Redfish service.
|
---|
322 | //
|
---|
323 | if (RedfishInstance->Status == EFI_SUCCESS) {
|
---|
324 | gRedfishConfigData.RedfishServiceInfo.RedfishServiceRestExHandle = RedfishInstance->Information.RedfishRestExHandle;
|
---|
325 | gRedfishConfigData.RedfishServiceInfo.RedfishServiceVersion = RedfishInstance->Information.RedfishVersion;
|
---|
326 | gRedfishConfigData.RedfishServiceInfo.RedfishServiceLocation = RedfishInstance->Information.Location;
|
---|
327 | gRedfishConfigData.RedfishServiceInfo.RedfishServiceUuid = RedfishInstance->Information.Uuid;
|
---|
328 | gRedfishConfigData.RedfishServiceInfo.RedfishServiceOs = RedfishInstance->Information.Os;
|
---|
329 | gRedfishConfigData.RedfishServiceInfo.RedfishServiceOsVersion = RedfishInstance->Information.OsVersion;
|
---|
330 | gRedfishConfigData.RedfishServiceInfo.RedfishServiceProduct = RedfishInstance->Information.Product;
|
---|
331 | gRedfishConfigData.RedfishServiceInfo.RedfishServiceProductVer = RedfishInstance->Information.ProductVer;
|
---|
332 | gRedfishConfigData.RedfishServiceInfo.RedfishServiceUseHttps = RedfishInstance->Information.UseHttps;
|
---|
333 | gRedfishServiceDiscovered = TRUE;
|
---|
334 | }
|
---|
335 |
|
---|
336 | //
|
---|
337 | // Invoke RedfishConfigHandlerInstalledCallback to execute
|
---|
338 | // the initialization of Redfish Configure Handler instance.
|
---|
339 | //
|
---|
340 | RedfishConfigHandlerInstalledCallback (gRedfishConfigData.Event, &gRedfishConfigData);
|
---|
341 | }
|
---|
342 |
|
---|
343 | FreePool (RedfishDiscoveredToken);
|
---|
344 | }
|
---|
345 |
|
---|
346 | /**
|
---|
347 | Callback function executed when the gEdkIIRedfishHostInterfaceReadyProtocolGuid
|
---|
348 | protocol interface is installed.
|
---|
349 |
|
---|
350 | @param[in] Event Event whose notification function is being invoked.
|
---|
351 | @param[in] Context Pointer to the Context buffer
|
---|
352 |
|
---|
353 | **/
|
---|
354 | VOID
|
---|
355 | EFIAPI
|
---|
356 | AcquireRedfishServiceOnNetworkInterfaceCallback (
|
---|
357 | IN EFI_EVENT Event,
|
---|
358 | IN VOID *Context
|
---|
359 | )
|
---|
360 | {
|
---|
361 | EFI_STATUS Status;
|
---|
362 | EFI_REDFISH_DISCOVER_NETWORK_INTERFACE *ThisNetworkInterface;
|
---|
363 | UINTN NetworkInterfaceIndex;
|
---|
364 | EFI_REDFISH_DISCOVERED_TOKEN *ThisRedfishDiscoveredToken;
|
---|
365 |
|
---|
366 | ThisNetworkInterface = mNetworkInterfaces;
|
---|
367 | //
|
---|
368 | // Loop to discover Redfish service on each network interface.
|
---|
369 | //
|
---|
370 | for (NetworkInterfaceIndex = 0; NetworkInterfaceIndex < mNumberOfNetworkInterfaces; NetworkInterfaceIndex++) {
|
---|
371 | ThisRedfishDiscoveredToken = (EFI_REDFISH_DISCOVERED_TOKEN *)AllocateZeroPool (sizeof (EFI_REDFISH_DISCOVERED_TOKEN));
|
---|
372 | if (ThisRedfishDiscoveredToken == NULL) {
|
---|
373 | DEBUG ((DEBUG_ERROR, "%a: Not enough memory for EFI_REDFISH_DISCOVERED_TOKEN.\n", __func__));
|
---|
374 | return;
|
---|
375 | }
|
---|
376 |
|
---|
377 | ThisRedfishDiscoveredToken->Signature = REDFISH_DISCOVER_TOKEN_SIGNATURE;
|
---|
378 |
|
---|
379 | //
|
---|
380 | // Initial this Redfish Discovered Token
|
---|
381 | //
|
---|
382 | Status = gBS->CreateEvent (
|
---|
383 | EVT_NOTIFY_SIGNAL,
|
---|
384 | TPL_CALLBACK,
|
---|
385 | RedfishServiceDiscoveredCallback,
|
---|
386 | (VOID *)ThisRedfishDiscoveredToken,
|
---|
387 | &ThisRedfishDiscoveredToken->Event
|
---|
388 | );
|
---|
389 | if (EFI_ERROR (Status)) {
|
---|
390 | FreePool (ThisRedfishDiscoveredToken);
|
---|
391 | DEBUG ((DEBUG_ERROR, "%a: Failed to create event for Redfish discovered token.\n", __func__));
|
---|
392 | return;
|
---|
393 | }
|
---|
394 |
|
---|
395 | //
|
---|
396 | // Acquire for Redfish service which is reported by
|
---|
397 | // Redfish Host Interface.
|
---|
398 | //
|
---|
399 | Status = gEfiRedfishDiscoverProtocol->AcquireRedfishService (
|
---|
400 | gEfiRedfishDiscoverProtocol,
|
---|
401 | gRedfishConfigData.Image,
|
---|
402 | ThisNetworkInterface,
|
---|
403 | EFI_REDFISH_DISCOVER_HOST_INTERFACE,
|
---|
404 | ThisRedfishDiscoveredToken
|
---|
405 | );
|
---|
406 |
|
---|
407 | //
|
---|
408 | // Free Redfish Discovered Token if Discover Instance was not created and
|
---|
409 | // Redfish Service Discovered Callback event was not triggered.
|
---|
410 | //
|
---|
411 | if ((ThisRedfishDiscoveredToken->DiscoverList.NumberOfServiceFound == 0) ||
|
---|
412 | EFI_ERROR (ThisRedfishDiscoveredToken->DiscoverList.RedfishInstances->Status))
|
---|
413 | {
|
---|
414 | gBS->CloseEvent (ThisRedfishDiscoveredToken->Event);
|
---|
415 | DEBUG ((DEBUG_MANAGEABILITY, "%a: Free Redfish discovered token - %x.\n", __func__, ThisRedfishDiscoveredToken));
|
---|
416 | FreePool (ThisRedfishDiscoveredToken);
|
---|
417 | }
|
---|
418 |
|
---|
419 | ThisNetworkInterface++;
|
---|
420 | }
|
---|
421 | }
|
---|
422 |
|
---|
423 | /**
|
---|
424 | Callback function executed when the EFI_REDFISH_DISCOVER_PROTOCOL
|
---|
425 | protocol interface is installed.
|
---|
426 |
|
---|
427 | @param[in] Event Event whose notification function is being invoked.
|
---|
428 | @param[in] Context Pointer to the Context buffer
|
---|
429 |
|
---|
430 | **/
|
---|
431 | VOID
|
---|
432 | EFIAPI
|
---|
433 | RedfishDiscoverProtocolInstalled (
|
---|
434 | IN EFI_EVENT Event,
|
---|
435 | IN VOID *Context
|
---|
436 | )
|
---|
437 | {
|
---|
438 | EFI_STATUS Status;
|
---|
439 | UINTN BufferSize;
|
---|
440 | EFI_HANDLE HandleBuffer;
|
---|
441 | VOID *RedfishHostInterfaceReadyProtocol;
|
---|
442 |
|
---|
443 | DEBUG ((DEBUG_MANAGEABILITY, "%a: New network interface is installed on system by EFI Redfish discover driver.\n", __func__));
|
---|
444 |
|
---|
445 | BufferSize = sizeof (EFI_HANDLE);
|
---|
446 | Status = gBS->LocateHandle (
|
---|
447 | ByRegisterNotify,
|
---|
448 | NULL,
|
---|
449 | gEfiRedfishDiscoverRegistration,
|
---|
450 | &BufferSize,
|
---|
451 | &HandleBuffer
|
---|
452 | );
|
---|
453 | if (EFI_ERROR (Status)) {
|
---|
454 | DEBUG ((DEBUG_ERROR, "%a: Can't locate handle with EFI_REDFISH_DISCOVER_PROTOCOL installed.\n", __func__));
|
---|
455 | }
|
---|
456 |
|
---|
457 | gRedfishDiscoverActivated = TRUE;
|
---|
458 | if (gEfiRedfishDiscoverProtocol == NULL) {
|
---|
459 | gEfiRedfishDiscoverControllerHandle = HandleBuffer;
|
---|
460 | //
|
---|
461 | // First time to open EFI_REDFISH_DISCOVER_PROTOCOL.
|
---|
462 | //
|
---|
463 | Status = gBS->OpenProtocol (
|
---|
464 | gEfiRedfishDiscoverControllerHandle,
|
---|
465 | &gEfiRedfishDiscoverProtocolGuid,
|
---|
466 | (VOID **)&gEfiRedfishDiscoverProtocol,
|
---|
467 | gRedfishConfigData.Image,
|
---|
468 | gRedfishConfigData.Image,
|
---|
469 | EFI_OPEN_PROTOCOL_BY_DRIVER
|
---|
470 | );
|
---|
471 | if (EFI_ERROR (Status)) {
|
---|
472 | gEfiRedfishDiscoverProtocol = NULL;
|
---|
473 | gRedfishDiscoverActivated = FALSE;
|
---|
474 | DEBUG ((DEBUG_ERROR, "%a: Can't locate EFI_REDFISH_DISCOVER_PROTOCOL.\n", __func__));
|
---|
475 | return;
|
---|
476 | }
|
---|
477 | }
|
---|
478 |
|
---|
479 | Status = gEfiRedfishDiscoverProtocol->GetNetworkInterfaceList (
|
---|
480 | gEfiRedfishDiscoverProtocol,
|
---|
481 | gRedfishConfigData.Image,
|
---|
482 | &mNumberOfNetworkInterfaces,
|
---|
483 | &mNetworkInterfaces
|
---|
484 | );
|
---|
485 | if (EFI_ERROR (Status) || (mNumberOfNetworkInterfaces == 0)) {
|
---|
486 | DEBUG ((DEBUG_ERROR, "%a: No network interfaces found on the handle.\n", __func__));
|
---|
487 | return;
|
---|
488 | }
|
---|
489 |
|
---|
490 | //
|
---|
491 | // Check if Redfish Host Interface is ready or not.
|
---|
492 | //
|
---|
493 | Status = gBS->LocateProtocol (&gEdkIIRedfishHostInterfaceReadyProtocolGuid, NULL, &RedfishHostInterfaceReadyProtocol);
|
---|
494 | if (!EFI_ERROR (Status)) {
|
---|
495 | // Acquire Redfish service;
|
---|
496 | AcquireRedfishServiceOnNetworkInterfaceCallback ((EFI_EVENT)NULL, (VOID *)NULL);
|
---|
497 | } else {
|
---|
498 | Status = gBS->CreateEvent (
|
---|
499 | EVT_NOTIFY_SIGNAL,
|
---|
500 | TPL_CALLBACK,
|
---|
501 | AcquireRedfishServiceOnNetworkInterfaceCallback,
|
---|
502 | NULL,
|
---|
503 | &mEdkIIRedfishHostInterfaceReadyEvent
|
---|
504 | );
|
---|
505 | if (EFI_ERROR (Status)) {
|
---|
506 | DEBUG ((DEBUG_ERROR, "%a: Failed to create event for gEdkIIRedfishHostInterfaceReadyProtocolGuid installation.", __func__));
|
---|
507 | return;
|
---|
508 | }
|
---|
509 |
|
---|
510 | Status = gBS->RegisterProtocolNotify (
|
---|
511 | &gEdkIIRedfishHostInterfaceReadyProtocolGuid,
|
---|
512 | mEdkIIRedfishHostInterfaceReadyEvent,
|
---|
513 | &mEdkIIRedfishHostInterfaceRegistration
|
---|
514 | );
|
---|
515 | if (EFI_ERROR (Status)) {
|
---|
516 | DEBUG ((DEBUG_ERROR, "%a: Fail to register event for the installation of gEdkIIRedfishHostInterfaceReadyProtocolGuid.", __func__));
|
---|
517 | return;
|
---|
518 | }
|
---|
519 | }
|
---|
520 |
|
---|
521 | return;
|
---|
522 | }
|
---|
523 |
|
---|
524 | /**
|
---|
525 | Unloads an image.
|
---|
526 |
|
---|
527 | @param[in] ImageHandle Handle that identifies the image to be unloaded.
|
---|
528 |
|
---|
529 | @retval EFI_SUCCESS The image has been unloaded.
|
---|
530 |
|
---|
531 | **/
|
---|
532 | EFI_STATUS
|
---|
533 | EFIAPI
|
---|
534 | RedfishConfigHandlerDriverUnload (
|
---|
535 | IN EFI_HANDLE ImageHandle
|
---|
536 | )
|
---|
537 | {
|
---|
538 | RedfishConfigDriverCommonUnload (ImageHandle);
|
---|
539 |
|
---|
540 | RedfishConfigStopRedfishDiscovery ();
|
---|
541 |
|
---|
542 | return EFI_SUCCESS;
|
---|
543 | }
|
---|
544 |
|
---|
545 | /**
|
---|
546 | This is the declaration of an EFI image entry point. This entry point is
|
---|
547 | the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
|
---|
548 | both device drivers and bus drivers.
|
---|
549 |
|
---|
550 | @param[in] ImageHandle The firmware allocated handle for the UEFI image.
|
---|
551 | @param[in] SystemTable A pointer to the EFI System Table.
|
---|
552 |
|
---|
553 | @retval EFI_SUCCESS The operation completed successfully.
|
---|
554 | @retval Others An unexpected error occurred.
|
---|
555 | **/
|
---|
556 | EFI_STATUS
|
---|
557 | EFIAPI
|
---|
558 | RedfishConfigHandlerDriverEntryPoint (
|
---|
559 | IN EFI_HANDLE ImageHandle,
|
---|
560 | IN EFI_SYSTEM_TABLE *SystemTable
|
---|
561 | )
|
---|
562 | {
|
---|
563 | EFI_STATUS Status;
|
---|
564 |
|
---|
565 | ZeroMem ((VOID *)&gRedfishConfigData, sizeof (REDFISH_CONFIG_DRIVER_DATA));
|
---|
566 | gRedfishConfigData.Image = ImageHandle;
|
---|
567 | //
|
---|
568 | // Register event for EFI_REDFISH_DISCOVER_PROTOCOL protocol install
|
---|
569 | // notification.
|
---|
570 | //
|
---|
571 | Status = gBS->CreateEventEx (
|
---|
572 | EVT_NOTIFY_SIGNAL,
|
---|
573 | TPL_CALLBACK,
|
---|
574 | RedfishDiscoverProtocolInstalled,
|
---|
575 | NULL,
|
---|
576 | &gEfiRedfishDiscoverProtocolGuid,
|
---|
577 | &gEfiRedfishDiscoverProtocolEvent
|
---|
578 | );
|
---|
579 | if (EFI_ERROR (Status)) {
|
---|
580 | DEBUG ((DEBUG_ERROR, "%a: Fail to create event for the installation of EFI_REDFISH_DISCOVER_PROTOCOL.", __func__));
|
---|
581 | return Status;
|
---|
582 | }
|
---|
583 |
|
---|
584 | Status = gBS->RegisterProtocolNotify (
|
---|
585 | &gEfiRedfishDiscoverProtocolGuid,
|
---|
586 | gEfiRedfishDiscoverProtocolEvent,
|
---|
587 | &gEfiRedfishDiscoverRegistration
|
---|
588 | );
|
---|
589 | if (EFI_ERROR (Status)) {
|
---|
590 | DEBUG ((DEBUG_ERROR, "%a: Fail to register event for the installation of EFI_REDFISH_DISCOVER_PROTOCOL.", __func__));
|
---|
591 | return Status;
|
---|
592 | }
|
---|
593 |
|
---|
594 | Status = RedfishConfigCommonInit (ImageHandle, SystemTable);
|
---|
595 | if (EFI_ERROR (Status)) {
|
---|
596 | gBS->CloseEvent (gEfiRedfishDiscoverProtocolEvent);
|
---|
597 | gEfiRedfishDiscoverProtocolEvent = NULL;
|
---|
598 | return Status;
|
---|
599 | }
|
---|
600 |
|
---|
601 | //
|
---|
602 | // Install UEFI Driver Model protocol(s).
|
---|
603 | //
|
---|
604 | Status = EfiLibInstallAllDriverProtocols2 (
|
---|
605 | ImageHandle,
|
---|
606 | SystemTable,
|
---|
607 | &gRedfishConfigDriverBinding,
|
---|
608 | ImageHandle,
|
---|
609 | &gRedfishConfigHandlerComponentName,
|
---|
610 | &gRedfishConfigHandlerComponentName2,
|
---|
611 | NULL,
|
---|
612 | NULL,
|
---|
613 | NULL,
|
---|
614 | NULL
|
---|
615 | );
|
---|
616 | if (EFI_ERROR (Status)) {
|
---|
617 | gBS->CloseEvent (gEndOfDxeEvent);
|
---|
618 | gEndOfDxeEvent = NULL;
|
---|
619 | gBS->CloseEvent (gExitBootServiceEvent);
|
---|
620 | gExitBootServiceEvent = NULL;
|
---|
621 | gBS->CloseEvent (gEfiRedfishDiscoverProtocolEvent);
|
---|
622 | gEfiRedfishDiscoverProtocolEvent = NULL;
|
---|
623 | DEBUG ((DEBUG_ERROR, "%a: Fail to install EFI Binding Protocol of EFI Redfish Config driver.", __func__));
|
---|
624 | return Status;
|
---|
625 | }
|
---|
626 |
|
---|
627 | return Status;
|
---|
628 | }
|
---|