VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RedfishRestExDxe/RedfishRestExDriver.c@ 99404

Last change on this file since 99404 was 99404, checked in by vboxsync, 2 years ago

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette