X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=NetworkPkg%2FMtftp6Dxe%2FMtftp6Driver.c;h=5f47938c2d5f3fa6f698cb29a2ce71c6ed727fbd;hb=823005621ef4757130f009c48dc96b099cccadf7;hp=9aa401e408970ee1d1c2eee4b014d141957702bc;hpb=76389e18c04833a87811550ed6db06f1790aacde;p=mirror_edk2.git diff --git a/NetworkPkg/Mtftp6Dxe/Mtftp6Driver.c b/NetworkPkg/Mtftp6Dxe/Mtftp6Driver.c index 9aa401e408..5f47938c2d 100644 --- a/NetworkPkg/Mtftp6Dxe/Mtftp6Driver.c +++ b/NetworkPkg/Mtftp6Dxe/Mtftp6Driver.c @@ -2,7 +2,7 @@ Driver Binding functions and Service Binding functions implementation for Mtftp6 Driver. - Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -33,7 +33,7 @@ EFI_SERVICE_BINDING_PROTOCOL gMtftp6ServiceBindingTemplate = { /** - Destory the MTFTP6 service. The MTFTP6 service may be partly initialized, + Destroy the MTFTP6 service. The MTFTP6 service may be partly initialized, or partly destroyed. If a resource is destroyed, it is marked as such in case the destroy failed and is called again later. @@ -46,7 +46,7 @@ Mtftp6DestroyService ( ) { // - // Make sure all children instances have been already destoryed. + // Make sure all children instances have been already destroyed. // ASSERT (Service->ChildrenNum == 0); @@ -98,7 +98,6 @@ Mtftp6CreateService ( Mtftp6Srv->Signature = MTFTP6_SERVICE_SIGNATURE; Mtftp6Srv->Controller = Controller; Mtftp6Srv->Image = Image; - Mtftp6Srv->InDestory = FALSE; Mtftp6Srv->ChildrenNum = 0; CopyMem ( @@ -219,7 +218,7 @@ Mtftp6CreateInstance ( } Mtftp6Ins->Signature = MTFTP6_INSTANCE_SIGNATURE; - Mtftp6Ins->InDestory = FALSE; + Mtftp6Ins->InDestroy = FALSE; Mtftp6Ins->Service = Service; CopyMem ( @@ -237,6 +236,45 @@ Mtftp6CreateInstance ( } +/** + Callback function which provided by user to remove one node in NetDestroyLinkList process. + + @param[in] Entry The entry to be removed. + @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList. + + @retval EFI_SUCCESS The entry has been removed successfully. + @retval Others Fail to remove the entry. + +**/ +EFI_STATUS +EFIAPI +Mtftp6DestroyChildEntryInHandleBuffer ( + IN LIST_ENTRY *Entry, + IN VOID *Context + ) +{ + MTFTP6_INSTANCE *Instance; + EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding; + UINTN NumberOfChildren; + EFI_HANDLE *ChildHandleBuffer; + + if (Entry == NULL || Context == NULL) { + return EFI_INVALID_PARAMETER; + } + + Instance = NET_LIST_USER_STRUCT_S (Entry, MTFTP6_INSTANCE, Link, MTFTP6_INSTANCE_SIGNATURE); + ServiceBinding = ((MTFTP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ServiceBinding; + NumberOfChildren = ((MTFTP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->NumberOfChildren; + ChildHandleBuffer = ((MTFTP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ChildHandleBuffer; + + if (!NetIsInHandleBuffer (Instance->Handle, NumberOfChildren, ChildHandleBuffer)) { + return EFI_SUCCESS; + } + + return ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle); +} + + /** This is the declaration of an EFI image entry point. This entry point is the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers, including @@ -429,20 +467,20 @@ Mtftp6DriverBindingStop ( IN EFI_HANDLE *ChildHandleBuffer ) { - EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding; - MTFTP6_SERVICE *Service; - MTFTP6_INSTANCE *Instance; - EFI_HANDLE NicHandle; - EFI_STATUS Status; - EFI_TPL OldTpl; - + EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding; + MTFTP6_SERVICE *Service; + EFI_HANDLE NicHandle; + EFI_STATUS Status; + LIST_ENTRY *List; + MTFTP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context; + // // Locate the Nic handle to retrieve the Mtftp6 private data. // NicHandle = NetLibGetNicHandle (Controller, &gEfiUdp6ProtocolGuid); if (NicHandle == NULL) { - return EFI_DEVICE_ERROR; + return EFI_SUCCESS; } Status = gBS->OpenProtocol ( @@ -460,18 +498,26 @@ Mtftp6DriverBindingStop ( Service = MTFTP6_SERVICE_FROM_THIS (ServiceBinding); - if (Service->InDestory) { - return EFI_SUCCESS; + if (!IsListEmpty (&Service->Children)) { + // + // Destroy the Mtftp6 child instance in ChildHandleBuffer. + // + List = &Service->Children; + Context.ServiceBinding = ServiceBinding; + Context.NumberOfChildren = NumberOfChildren; + Context.ChildHandleBuffer = ChildHandleBuffer; + Status = NetDestroyLinkList ( + List, + Mtftp6DestroyChildEntryInHandleBuffer, + &Context, + NULL + ); } - OldTpl = gBS->RaiseTPL (TPL_CALLBACK); - - if (NumberOfChildren == 0) { + if (NumberOfChildren == 0 && IsListEmpty (&Service->Children)) { // - // Destory the Mtftp6 service if there is no Mtftp6 child instance left. + // Destroy the Mtftp6 service if there is no Mtftp6 child instance left. // - Service->InDestory = TRUE; - gBS->UninstallProtocolInterface ( NicHandle, &gEfiMtftp6ServiceBindingProtocolGuid, @@ -479,22 +525,9 @@ Mtftp6DriverBindingStop ( ); Mtftp6DestroyService (Service); - - } else { - // - // Destory the Mtftp6 child instance one by one. - // - while (!IsListEmpty (&Service->Children)) { - Instance = NET_LIST_HEAD (&Service->Children, MTFTP6_INSTANCE, Link); - Mtftp6ServiceBindingDestroyChild (ServiceBinding, Instance->Handle); - } - - if (Service->ChildrenNum != 0) { - Status = EFI_DEVICE_ERROR; - } + Status = EFI_SUCCESS; } - gBS->RestoreTPL (OldTpl); return Status; } @@ -612,7 +645,7 @@ ON_ERROR: @retval EFI_SUCCES The protocol was removed from ChildHandle. @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed. - @retval EFI_INVALID_PARAMETER Child handle is not a valid UEFI Handle. + @retval EFI_INVALID_PARAMETER Child handle is NULL. @retval Others The child handle was not destroyed **/ @@ -657,15 +690,15 @@ Mtftp6ServiceBindingDestroyChild ( } // - // Check whether the instance already in destory state. + // Check whether the instance already in Destroy state. // - if (Instance->InDestory) { + if (Instance->InDestroy) { return EFI_SUCCESS; } OldTpl = gBS->RaiseTPL (TPL_CALLBACK); - Instance->InDestory = TRUE; + Instance->InDestroy = TRUE; gBS->CloseProtocol ( Service->DummyUdpIo->UdpHandle, @@ -674,17 +707,36 @@ Mtftp6ServiceBindingDestroyChild ( ChildHandle ); + if (Instance->UdpIo != NULL) { + gBS->CloseProtocol ( + Instance->UdpIo->UdpHandle, + &gEfiUdp6ProtocolGuid, + gMtftp6DriverBinding.DriverBindingHandle, + Instance->Handle + ); + } + + if (Instance->McastUdpIo != NULL) { + gBS->CloseProtocol ( + Instance->McastUdpIo->UdpHandle, + &gEfiUdp6ProtocolGuid, + gMtftp6DriverBinding.DriverBindingHandle, + Instance->Handle + ); + } + // // Uninstall the MTFTP6 protocol first to enable a top down destruction. // + gBS->RestoreTPL (OldTpl); Status = gBS->UninstallProtocolInterface ( ChildHandle, &gEfiMtftp6ProtocolGuid, Mtftp6 ); - + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); if (EFI_ERROR (Status)) { - Instance->InDestory = FALSE; + Instance->InDestroy = FALSE; gBS->RestoreTPL (OldTpl); return Status; } @@ -695,9 +747,9 @@ Mtftp6ServiceBindingDestroyChild ( RemoveEntryList (&Instance->Link); Service->ChildrenNum --; - Mtftp6DestroyInstance (Instance); - gBS->RestoreTPL (OldTpl); + Mtftp6DestroyInstance (Instance); + return EFI_SUCCESS; }