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