]> git.proxmox.com Git - mirror_edk2.git/blame - RedfishPkg/RedfishRestExDxe/RedfishRestExDriver.c
CryptoPkg/BaseCryptLib: Enabled CryptSha512 for Smm/Runtime drivers
[mirror_edk2.git] / RedfishPkg / RedfishRestExDxe / RedfishRestExDriver.c
CommitLineData
10dc8c56
AC
1/** @file\r
2 The driver binding and service binding protocol for Redfish RestExDxe driver.\r
3\r
4 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
5 (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>\r
6\r
7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
8\r
9**/\r
10\r
11#include <Uefi.h>\r
12#include "RedfishRestExDriver.h"\r
13\r
14EFI_DRIVER_BINDING_PROTOCOL gRedfishRestExDriverBinding = {\r
15 RedfishRestExDriverBindingSupported,\r
16 RedfishRestExDriverBindingStart,\r
17 RedfishRestExDriverBindingStop,\r
18 REDFISH_RESTEX_DRIVER_VERSION,\r
19 NULL,\r
20 NULL\r
21};\r
22\r
23EFI_SERVICE_BINDING_PROTOCOL mRedfishRestExServiceBinding = {\r
24 RedfishRestExServiceBindingCreateChild,\r
25 RedfishRestExServiceBindingDestroyChild\r
26};\r
27\r
28/**\r
29 Callback function which provided by user to remove one node in NetDestroyLinkList process.\r
30\r
31 @param[in] Entry The entry to be removed.\r
32 @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.\r
33\r
34 @retval EFI_SUCCESS The entry has been removed successfully.\r
35 @retval Others Fail to remove the entry.\r
36\r
37**/\r
38EFI_STATUS\r
39EFIAPI\r
40RestExDestroyChildEntryInHandleBuffer (\r
41 IN LIST_ENTRY *Entry,\r
42 IN VOID *Context\r
43 )\r
44{\r
45 RESTEX_INSTANCE *Instance;\r
46 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;\r
47 UINTN NumberOfChildren;\r
48 EFI_HANDLE *ChildHandleBuffer;\r
49\r
50 if (Entry == NULL || Context == NULL) {\r
51 return EFI_INVALID_PARAMETER;\r
52 }\r
53\r
54 Instance = NET_LIST_USER_STRUCT_S (Entry, RESTEX_INSTANCE, Link, RESTEX_INSTANCE_SIGNATURE);\r
55 ServiceBinding = ((RESTEX_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ServiceBinding;\r
56 NumberOfChildren = ((RESTEX_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->NumberOfChildren;\r
57 ChildHandleBuffer = ((RESTEX_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ChildHandleBuffer;\r
58\r
59 if (!NetIsInHandleBuffer (Instance->ChildHandle, NumberOfChildren, ChildHandleBuffer)) {\r
60 return EFI_SUCCESS;\r
61 }\r
62\r
63 return ServiceBinding->DestroyChild (ServiceBinding, Instance->ChildHandle);\r
64}\r
65\r
66/**\r
67 Destroy the RestEx instance and recycle the resources.\r
68\r
69 @param[in] Instance The pointer to the RestEx instance.\r
70\r
71**/\r
72VOID\r
73RestExDestroyInstance (\r
74 IN RESTEX_INSTANCE *Instance\r
75 )\r
76{\r
77 HttpIoDestroyIo (&(Instance->HttpIo));\r
78\r
79 FreePool (Instance);\r
80}\r
81\r
82/**\r
83 Create the RestEx instance and initialize it.\r
84\r
85 @param[in] Service The pointer to the RestEx service.\r
86 @param[out] Instance The pointer to the RestEx instance.\r
87\r
88 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.\r
89 @retval EFI_SUCCESS The RestEx instance is created.\r
90\r
91**/\r
92EFI_STATUS\r
93RestExCreateInstance (\r
94 IN RESTEX_SERVICE *Service,\r
95 OUT RESTEX_INSTANCE **Instance\r
96 )\r
97{\r
98 RESTEX_INSTANCE *RestExIns;\r
99 EFI_STATUS Status;\r
100\r
101 *Instance = NULL;\r
102 Status = EFI_SUCCESS;\r
103\r
104 RestExIns = AllocateZeroPool (sizeof (RESTEX_INSTANCE));\r
105 if (RestExIns == NULL) {\r
106 return EFI_OUT_OF_RESOURCES;\r
107 }\r
108\r
109 RestExIns->Signature = RESTEX_INSTANCE_SIGNATURE;\r
110 InitializeListHead (&RestExIns->Link);\r
111 RestExIns->InDestroy = FALSE;\r
112 RestExIns->Service = Service;\r
113\r
114 CopyMem (&RestExIns->RestEx, &mRedfishRestExProtocol, sizeof (RestExIns->RestEx));\r
115\r
116 //\r
117 // Create a HTTP_IO to access the HTTP service.\r
118 //\r
119 Status = HttpIoCreateIo (\r
120 RestExIns->Service->ImageHandle,\r
121 RestExIns->Service->ControllerHandle,\r
122 IP_VERSION_4,\r
123 NULL,\r
124 NULL,\r
125 NULL,\r
126 &(RestExIns->HttpIo)\r
127 );\r
128 if (EFI_ERROR (Status)) {\r
129 FreePool (RestExIns);\r
130 return Status;\r
131 }\r
132\r
133 *Instance = RestExIns;\r
134\r
135 return EFI_SUCCESS;\r
136}\r
137\r
138/**\r
139 Release all the resource used the RestEx service binding instance.\r
140\r
141 @param[in] RestExSb The RestEx service binding instance.\r
142\r
143**/\r
144VOID\r
145RestExDestroyService (\r
146 IN RESTEX_SERVICE *RestExSb\r
147 )\r
148{\r
149 if (RestExSb->HttpChildHandle != NULL) {\r
150 gBS->CloseProtocol (\r
151 RestExSb->HttpChildHandle,\r
152 &gEfiHttpProtocolGuid,\r
153 RestExSb->ImageHandle,\r
154 RestExSb->ControllerHandle\r
155 );\r
156\r
157 NetLibDestroyServiceChild (\r
158 RestExSb->ControllerHandle,\r
159 RestExSb->ImageHandle,\r
160 &gEfiHttpServiceBindingProtocolGuid,\r
161 RestExSb->HttpChildHandle\r
162 );\r
163\r
164 RestExSb->HttpChildHandle = NULL;\r
165 }\r
166\r
167 gBS->UninstallProtocolInterface (\r
168 RestExSb->ControllerHandle,\r
169 &gEfiCallerIdGuid,\r
170 &RestExSb->Id\r
171 );\r
172\r
173 FreePool (RestExSb);\r
174}\r
175\r
176/**\r
177 Check the NIC controller handle represents an in-band or out-of-band Redfish host\r
178 interface device. If not in-band, treat it as out-of-band interface device.\r
179\r
180 @param[in] Controller The NIC controller handle needs to be checked.\r
181\r
182 @return EFI_REST_EX_SERVICE_ACCESS_MODE of the device.\r
183\r
184**/\r
185EFI_REST_EX_SERVICE_ACCESS_MODE\r
186RestExServiceAccessMode (\r
187 IN EFI_HANDLE Controller\r
188 )\r
189{\r
190 //\r
191 // This is EFI REST EX driver instance to connect\r
192 // to Redfish service using HTTP in out of band.\r
193 //\r
194 if (FixedPcdGetBool (PcdRedfishRestExServiceAccessModeInBand)) {\r
195 return EfiRestExServiceInBandAccess;\r
196 } else {\r
197 return EfiRestExServiceOutOfBandAccess;\r
198 }\r
199}\r
200\r
201/**\r
202 Create then initialize a RestEx service binding instance.\r
203\r
204 @param[in] Controller The controller to install the RestEx service\r
205 binding on.\r
206 @param[in] Image The driver binding image of the RestEx driver.\r
207 @param[out] Service The variable to receive the created service\r
208 binding instance.\r
209\r
210 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource to create the instance.\r
211 @retval EFI_SUCCESS The service instance is created for the controller.\r
212\r
213**/\r
214EFI_STATUS\r
215RestExCreateService (\r
216 IN EFI_HANDLE Controller,\r
217 IN EFI_HANDLE Image,\r
218 OUT RESTEX_SERVICE **Service\r
219 )\r
220{\r
221 EFI_STATUS Status;\r
222 RESTEX_SERVICE *RestExSb;\r
223\r
224 Status = EFI_SUCCESS;\r
225 RestExSb = NULL;\r
226\r
227 *Service = NULL;\r
228\r
229 RestExSb = AllocateZeroPool (sizeof (RESTEX_SERVICE));\r
230 if (RestExSb == NULL) {\r
231 return EFI_OUT_OF_RESOURCES;\r
232 }\r
233\r
234 RestExSb->Signature = RESTEX_SERVICE_SIGNATURE;\r
235\r
236 RestExSb->ServiceBinding = mRedfishRestExServiceBinding;\r
237\r
238 RestExSb->RestExChildrenNum = 0;\r
239 InitializeListHead (&RestExSb->RestExChildrenList);\r
240\r
241 RestExSb->ControllerHandle = Controller;\r
242 RestExSb->ImageHandle = Image;\r
243\r
244 RestExSb->RestExServiceInfo.EfiRestExServiceInfoV10.EfiRestExServiceInfoHeader.Length = sizeof (EFI_REST_EX_SERVICE_INFO);\r
245 RestExSb->RestExServiceInfo.EfiRestExServiceInfoV10.EfiRestExServiceInfoHeader.RestServiceInfoVer.Major = 1;\r
246 RestExSb->RestExServiceInfo.EfiRestExServiceInfoV10.EfiRestExServiceInfoHeader.RestServiceInfoVer.Minor = 0;\r
247 RestExSb->RestExServiceInfo.EfiRestExServiceInfoV10.RestServiceType = EfiRestExServiceRedfish;\r
248 RestExSb->RestExServiceInfo.EfiRestExServiceInfoV10.RestServiceAccessMode = RestExServiceAccessMode (Controller);\r
249 RestExSb->RestExServiceInfo.EfiRestExServiceInfoV10.RestExConfigType = EfiRestExConfigHttp;\r
250 RestExSb->RestExServiceInfo.EfiRestExServiceInfoV10.RestExConfigDataLength = sizeof (EFI_REST_EX_HTTP_CONFIG_DATA);\r
251\r
252 Status = gBS->InstallProtocolInterface (\r
253 &Controller,\r
254 &gEfiCallerIdGuid,\r
255 EFI_NATIVE_INTERFACE,\r
256 &RestExSb->Id\r
257 );\r
258 if (EFI_ERROR (Status)) {\r
259 FreePool (RestExSb);\r
260 RestExSb = NULL;\r
261 }\r
262\r
263 *Service = RestExSb;\r
264 return Status;\r
265}\r
266\r
267/**\r
268 This is the declaration of an EFI image entry point. This entry point is\r
269 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including\r
270 both device drivers and bus drivers.\r
271\r
272 @param[in] ImageHandle The firmware allocated handle for the UEFI image.\r
273 @param[in] SystemTable A pointer to the EFI System Table.\r
274\r
275 @retval EFI_SUCCESS The operation completed successfully.\r
276 @retval Others An unexpected error occurred.\r
277**/\r
278EFI_STATUS\r
279EFIAPI\r
280RedfishRestExDriverEntryPoint (\r
281 IN EFI_HANDLE ImageHandle,\r
282 IN EFI_SYSTEM_TABLE *SystemTable\r
283 )\r
284{\r
285 EFI_STATUS Status;\r
286\r
287 Status = EFI_SUCCESS;\r
288\r
289 //\r
290 // Install the RestEx Driver Binding Protocol.\r
291 //\r
292 Status = EfiLibInstallDriverBindingComponentName2 (\r
293 ImageHandle,\r
294 SystemTable,\r
295 &gRedfishRestExDriverBinding,\r
296 ImageHandle,\r
297 &gRedfishRestExComponentName,\r
298 &gRedfishRestExComponentName2\r
299 );\r
300 if (EFI_ERROR (Status)) {\r
301 return Status;\r
302 }\r
303\r
304 return Status;\r
305}\r
306\r
307/**\r
308 Tests to see if this driver supports a given controller. If a child device is provided,\r
309 it further tests to see if this driver supports creating a handle for the specified child device.\r
310\r
311 This function checks to see if the driver specified by This supports the device specified by\r
312 ControllerHandle. Drivers will typically use the device path attached to\r
313 ControllerHandle and/or the services from the bus I/O abstraction attached to\r
314 ControllerHandle to determine if the driver supports ControllerHandle. This function\r
315 may be called many times during platform initialization. In order to reduce boot times, the tests\r
316 performed by this function must be very small, and take as little time as possible to execute. This\r
317 function must not change the state of any hardware devices, and this function must be aware that the\r
318 device specified by ControllerHandle may already be managed by the same driver or a\r
319 different driver. This function must match its calls to AllocatePages() with FreePages(),\r
320 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r
321 Because ControllerHandle may have been previously started by the same driver, if a protocol is\r
322 already in the opened state, then it must not be closed with CloseProtocol(). This is required\r
323 to guarantee the state of ControllerHandle is not modified by this function.\r
324\r
325 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
326 @param[in] ControllerHandle The handle of the controller to test. This handle\r
327 must support a protocol interface that supplies\r
328 an I/O abstraction to the driver.\r
329 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
330 parameter is ignored by device drivers, and is optional for bus\r
331 drivers. For bus drivers, if this parameter is not NULL, then\r
332 the bus driver must determine if the bus controller specified\r
333 by ControllerHandle and the child controller specified\r
334 by RemainingDevicePath are both supported by this\r
335 bus driver.\r
336\r
337 @retval EFI_SUCCESS The device specified by ControllerHandle and\r
338 RemainingDevicePath is supported by the driver specified by This.\r
339 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r
340 RemainingDevicePath is already being managed by the driver\r
341 specified by This.\r
342 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r
343 RemainingDevicePath is already being managed by a different\r
344 driver or an application that requires exclusive access.\r
345 Currently not implemented.\r
346 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r
347 RemainingDevicePath is not supported by the driver specified by This.\r
348**/\r
349EFI_STATUS\r
350EFIAPI\r
351RedfishRestExDriverBindingSupported (\r
352 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
353 IN EFI_HANDLE ControllerHandle,\r
354 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
355 )\r
356{\r
357\r
358 //\r
359 // Test for the HttpServiceBinding Protocol.\r
360 //\r
361 return gBS->OpenProtocol (\r
362 ControllerHandle,\r
363 &gEfiHttpServiceBindingProtocolGuid,\r
364 NULL,\r
365 This->DriverBindingHandle,\r
366 ControllerHandle,\r
367 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
368 );\r
369\r
370}\r
371\r
372/**\r
373 Starts a device controller or a bus controller.\r
374\r
375 The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
376 As a result, much of the error checking on the parameters to Start() has been moved into this\r
377 common boot service. It is legal to call Start() from other locations,\r
378 but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
379 1. ControllerHandle must be a valid EFI_HANDLE.\r
380 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
381 EFI_DEVICE_PATH_PROTOCOL.\r
382 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
383 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r
384\r
385 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
386 @param[in] ControllerHandle The handle of the controller to start. This handle\r
387 must support a protocol interface that supplies\r
388 an I/O abstraction to the driver.\r
389 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
390 parameter is ignored by device drivers, and is optional for bus\r
391 drivers. For a bus driver, if this parameter is NULL, then handles\r
392 for all the children of Controller are created by this driver.\r
393 If this parameter is not NULL and the first Device Path Node is\r
394 not the End of Device Path Node, then only the handle for the\r
395 child device specified by the first Device Path Node of\r
396 RemainingDevicePath is created by this driver.\r
397 If the first Device Path Node of RemainingDevicePath is\r
398 the End of Device Path Node, no child handle is created by this\r
399 driver.\r
400\r
401 @retval EFI_SUCCESS The device was started.\r
402 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r
403 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
404 @retval Others The driver failded to start the device.\r
405\r
406**/\r
407EFI_STATUS\r
408EFIAPI\r
409RedfishRestExDriverBindingStart (\r
410 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
411 IN EFI_HANDLE ControllerHandle,\r
412 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
413 )\r
414{\r
415 RESTEX_SERVICE *RestExSb;\r
416 EFI_STATUS Status;\r
417 UINT32 *Id;\r
418 VOID *Interface;\r
419\r
420 Status = gBS->OpenProtocol (\r
421 ControllerHandle,\r
422 &gEfiCallerIdGuid,\r
423 (VOID **) &Id,\r
424 This->DriverBindingHandle,\r
425 ControllerHandle,\r
426 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
427 );\r
428 if (!EFI_ERROR (Status)) {\r
429 return EFI_ALREADY_STARTED;\r
430 }\r
431\r
432 Status = RestExCreateService (ControllerHandle, This->DriverBindingHandle, &RestExSb);\r
433 if (EFI_ERROR (Status)) {\r
434 return Status;\r
435 }\r
436\r
437 ASSERT (RestExSb != NULL);\r
438\r
439 //\r
440 // Create a Http child instance, but do not configure it.\r
441 // This will establish the parent-child relationship.\r
442 //\r
443 Status = NetLibCreateServiceChild (\r
444 ControllerHandle,\r
445 This->DriverBindingHandle,\r
446 &gEfiHttpServiceBindingProtocolGuid,\r
447 &RestExSb->HttpChildHandle\r
448 );\r
449 if (EFI_ERROR (Status)) {\r
450 goto ON_ERROR;\r
451 }\r
452\r
453 Status = gBS->OpenProtocol (\r
454 RestExSb->HttpChildHandle,\r
455 &gEfiHttpProtocolGuid,\r
456 &Interface,\r
457 This->DriverBindingHandle,\r
458 ControllerHandle,\r
459 EFI_OPEN_PROTOCOL_BY_DRIVER\r
460 );\r
461 if (EFI_ERROR (Status)) {\r
462 goto ON_ERROR;\r
463 }\r
464\r
465 //\r
466 // Install the RestEx ServiceBinding Protocol onto ControllerHandle.\r
467 //\r
468 Status = gBS->InstallMultipleProtocolInterfaces (\r
469 &ControllerHandle,\r
470 &gEfiRestExServiceBindingProtocolGuid,\r
471 &RestExSb->ServiceBinding,\r
472 NULL\r
473 );\r
474 if (EFI_ERROR (Status)) {\r
475 goto ON_ERROR;\r
476 }\r
477\r
478 return EFI_SUCCESS;\r
479\r
480ON_ERROR:\r
481 RestExDestroyService (RestExSb);\r
482\r
483 return Status;\r
484}\r
485\r
486/**\r
487 Stops a device controller or a bus controller.\r
488\r
489 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r
490 As a result, much of the error checking on the parameters to Stop() has been moved\r
491 into this common boot service. It is legal to call Stop() from other locations,\r
492 but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
493 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
494 same driver's Start() function.\r
495 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
496 EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
497 Start() function, and the Start() function must have called OpenProtocol() on\r
498 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
499\r
500 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
501 @param[in] ControllerHandle A handle to the device being stopped. The handle must\r
502 support a bus specific I/O protocol for the driver\r
503 to use to stop the device.\r
504 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r
505 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r
506 if NumberOfChildren is 0.\r
507\r
508 @retval EFI_SUCCESS The device was stopped.\r
509 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
510\r
511**/\r
512EFI_STATUS\r
513EFIAPI\r
514RedfishRestExDriverBindingStop (\r
515 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
516 IN EFI_HANDLE ControllerHandle,\r
517 IN UINTN NumberOfChildren,\r
518 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL\r
519 )\r
520{\r
521 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;\r
522 RESTEX_SERVICE *RestExSb;\r
523 EFI_HANDLE NicHandle;\r
524 EFI_STATUS Status;\r
525 LIST_ENTRY *List;\r
526 RESTEX_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context;\r
527\r
528 //\r
529 // RestEx driver opens HTTP child, So, Controller is a HTTP\r
530 // child handle. Locate the Nic handle first. Then get the\r
531 // RestEx private data back.\r
532 //\r
533 NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiHttpProtocolGuid);\r
534 if (NicHandle == NULL) {\r
535 return EFI_SUCCESS;\r
536 }\r
537\r
538 Status = gBS->OpenProtocol (\r
539 NicHandle,\r
540 &gEfiRestExServiceBindingProtocolGuid,\r
541 (VOID **) &ServiceBinding,\r
542 This->DriverBindingHandle,\r
543 NicHandle,\r
544 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
545 );\r
546 if (EFI_ERROR (Status)) {\r
547 return EFI_DEVICE_ERROR;\r
548 }\r
549\r
550 RestExSb = RESTEX_SERVICE_FROM_THIS (ServiceBinding);\r
551\r
552 if (!IsListEmpty (&RestExSb->RestExChildrenList)) {\r
553 //\r
554 // Destroy the RestEx child instance in ChildHandleBuffer.\r
555 //\r
556 List = &RestExSb->RestExChildrenList;\r
557 Context.ServiceBinding = ServiceBinding;\r
558 Context.NumberOfChildren = NumberOfChildren;\r
559 Context.ChildHandleBuffer = ChildHandleBuffer;\r
560 Status = NetDestroyLinkList (\r
561 List,\r
562 RestExDestroyChildEntryInHandleBuffer,\r
563 &Context,\r
564 NULL\r
565 );\r
566 }\r
567\r
568 if (NumberOfChildren == 0 && IsListEmpty (&RestExSb->RestExChildrenList)) {\r
569 gBS->UninstallProtocolInterface (\r
570 NicHandle,\r
571 &gEfiRestExServiceBindingProtocolGuid,\r
572 ServiceBinding\r
573 );\r
574\r
575 RestExDestroyService (RestExSb);\r
576\r
577 if (gRedfishRestExControllerNameTable != NULL) {\r
578 FreeUnicodeStringTable (gRedfishRestExControllerNameTable);\r
579 gRedfishRestExControllerNameTable = NULL;\r
580 }\r
581\r
582 Status = EFI_SUCCESS;\r
583 }\r
584\r
585 return Status;\r
586}\r
587\r
588/**\r
589 Creates a child handle and installs a protocol.\r
590\r
591 The CreateChild() function installs a protocol on ChildHandle.\r
592 If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.\r
593 If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.\r
594\r
595 @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.\r
596 @param[in] ChildHandle Pointer to the handle of the child to create. If it is NULL,\r
597 then a new handle is created. If it is a pointer to an existing UEFI handle,\r
598 then the protocol is added to the existing UEFI handle.\r
599\r
600 @retval EFI_SUCCES The protocol was added to ChildHandle.\r
601 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.\r
602 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create\r
603 the child\r
604 @retval other The child handle was not created\r
605\r
606**/\r
607EFI_STATUS\r
608EFIAPI\r
609RedfishRestExServiceBindingCreateChild (\r
610 IN EFI_SERVICE_BINDING_PROTOCOL *This,\r
611 IN EFI_HANDLE *ChildHandle\r
612 )\r
613{\r
614 RESTEX_SERVICE *RestExSb;\r
615 RESTEX_INSTANCE *Instance;\r
616 EFI_STATUS Status;\r
617 EFI_TPL OldTpl;\r
618 VOID *Http;\r
619\r
620 if ((This == NULL) || (ChildHandle == NULL)) {\r
621 return EFI_INVALID_PARAMETER;\r
622 }\r
623\r
624 RestExSb = RESTEX_SERVICE_FROM_THIS (This);\r
625\r
626 Status = RestExCreateInstance (RestExSb, &Instance);\r
627 if (EFI_ERROR (Status)) {\r
628 return Status;\r
629 }\r
630 ASSERT (Instance != NULL);\r
631\r
632 //\r
633 // Install the RestEx protocol onto ChildHandle\r
634 //\r
635 Status = gBS->InstallMultipleProtocolInterfaces (\r
636 ChildHandle,\r
637 &gEfiRestExProtocolGuid,\r
638 &Instance->RestEx,\r
639 NULL\r
640 );\r
641 if (EFI_ERROR (Status)) {\r
642 goto ON_ERROR;\r
643 }\r
644\r
645 Instance->ChildHandle = *ChildHandle;\r
646\r
647 //\r
648 // Open the Http protocol BY_CHILD.\r
649 //\r
650 Status = gBS->OpenProtocol (\r
651 RestExSb->HttpChildHandle,\r
652 &gEfiHttpProtocolGuid,\r
653 (VOID **) &Http,\r
654 gRedfishRestExDriverBinding.DriverBindingHandle,\r
655 Instance->ChildHandle,\r
656 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
657 );\r
658 if (EFI_ERROR (Status)) {\r
659 gBS->UninstallMultipleProtocolInterfaces (\r
660 Instance->ChildHandle,\r
661 &gEfiRestExProtocolGuid,\r
662 &Instance->RestEx,\r
663 NULL\r
664 );\r
665\r
666 goto ON_ERROR;\r
667 }\r
668\r
669 //\r
670 // Open the Http protocol by child.\r
671 //\r
672 Status = gBS->OpenProtocol (\r
673 Instance->HttpIo.Handle,\r
674 &gEfiHttpProtocolGuid,\r
675 (VOID **) &Http,\r
676 gRedfishRestExDriverBinding.DriverBindingHandle,\r
677 Instance->ChildHandle,\r
678 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
679 );\r
680 if (EFI_ERROR (Status)) {\r
681 //\r
682 // Close the Http protocol.\r
683 //\r
684 gBS->CloseProtocol (\r
685 RestExSb->HttpChildHandle,\r
686 &gEfiHttpProtocolGuid,\r
687 gRedfishRestExDriverBinding.DriverBindingHandle,\r
688 ChildHandle\r
689 );\r
690\r
691 gBS->UninstallMultipleProtocolInterfaces (\r
692 Instance->ChildHandle,\r
693 &gEfiRestExProtocolGuid,\r
694 &Instance->RestEx,\r
695 NULL\r
696 );\r
697\r
698 goto ON_ERROR;\r
699 }\r
700\r
701 //\r
702 // Add it to the parent's child list.\r
703 //\r
704 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
705\r
706 InsertTailList (&RestExSb->RestExChildrenList, &Instance->Link);\r
707 RestExSb->RestExChildrenNum++;\r
708\r
709 gBS->RestoreTPL (OldTpl);\r
710\r
711 return EFI_SUCCESS;\r
712\r
713ON_ERROR:\r
714\r
715 RestExDestroyInstance (Instance);\r
716 return Status;\r
717}\r
718\r
719/**\r
720 Destroys a child handle with a protocol installed on it.\r
721\r
722 The DestroyChild() function does the opposite of CreateChild(). It removes a protocol\r
723 that was installed by CreateChild() from ChildHandle. If the removed protocol is the\r
724 last protocol on ChildHandle, then ChildHandle is destroyed.\r
725\r
726 @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.\r
727 @param[in] ChildHandle Handle of the child to destroy\r
728\r
729 @retval EFI_SUCCES The protocol was removed from ChildHandle.\r
730 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.\r
731 @retval EFI_INVALID_PARAMETER Child handle is NULL.\r
732 @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle\r
733 because its services are being used.\r
734 @retval other The child handle was not destroyed\r
735\r
736**/\r
737EFI_STATUS\r
738EFIAPI\r
739RedfishRestExServiceBindingDestroyChild (\r
740 IN EFI_SERVICE_BINDING_PROTOCOL *This,\r
741 IN EFI_HANDLE ChildHandle\r
742 )\r
743{\r
744 RESTEX_SERVICE *RestExSb;\r
745 RESTEX_INSTANCE *Instance;\r
746\r
747 EFI_REST_EX_PROTOCOL *RestEx;\r
748 EFI_STATUS Status;\r
749 EFI_TPL OldTpl;\r
750\r
751 if ((This == NULL) || (ChildHandle == NULL)) {\r
752 return EFI_INVALID_PARAMETER;\r
753 }\r
754\r
755 //\r
756 // Retrieve the private context data structures\r
757 //\r
758 Status = gBS->OpenProtocol (\r
759 ChildHandle,\r
760 &gEfiRestExProtocolGuid,\r
761 (VOID **) &RestEx,\r
762 NULL,\r
763 NULL,\r
764 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
765 );\r
766\r
767 if (EFI_ERROR (Status)) {\r
768 return EFI_UNSUPPORTED;\r
769 }\r
770\r
771 Instance = RESTEX_INSTANCE_FROM_THIS (RestEx);\r
772 RestExSb = RESTEX_SERVICE_FROM_THIS (This);\r
773\r
774 if (Instance->Service != RestExSb) {\r
775 return EFI_INVALID_PARAMETER;\r
776 }\r
777\r
778 if (Instance->InDestroy) {\r
779 return EFI_SUCCESS;\r
780 }\r
781\r
782 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
783\r
784 Instance->InDestroy = TRUE;\r
785\r
786 //\r
787 // Close the Http protocol.\r
788 //\r
789 gBS->CloseProtocol (\r
790 RestExSb->HttpChildHandle,\r
791 &gEfiHttpProtocolGuid,\r
792 gRedfishRestExDriverBinding.DriverBindingHandle,\r
793 ChildHandle\r
794 );\r
795\r
796 gBS->CloseProtocol (\r
797 Instance->HttpIo.Handle,\r
798 &gEfiHttpProtocolGuid,\r
799 gRedfishRestExDriverBinding.DriverBindingHandle,\r
800 ChildHandle\r
801 );\r
802\r
803\r
804 gBS->RestoreTPL (OldTpl);\r
805\r
806 //\r
807 // Uninstall the RestEx protocol first to enable a top down destruction.\r
808 //\r
809 Status = gBS->UninstallProtocolInterface (\r
810 ChildHandle,\r
811 &gEfiRestExProtocolGuid,\r
812 RestEx\r
813 );\r
814\r
815 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
816\r
817 if (EFI_ERROR (Status)) {\r
818 Instance->InDestroy = FALSE;\r
819 gBS->RestoreTPL (OldTpl);\r
820 return Status;\r
821 }\r
822\r
823 RemoveEntryList (&Instance->Link);\r
824 RestExSb->RestExChildrenNum--;\r
825\r
826 gBS->RestoreTPL (OldTpl);\r
827\r
828 RestExDestroyInstance (Instance);\r
829 return EFI_SUCCESS;\r
830}\r
831\r