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