Driver Binding functions and Service Binding functions\r
implementation for Mtftp6 Driver.\r
\r
- Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
\r
\r
/**\r
- Destory the MTFTP6 service. The MTFTP6 service may be partly initialized,\r
+ Destroy the MTFTP6 service. The MTFTP6 service may be partly initialized,\r
or partly destroyed. If a resource is destroyed, it is marked as such in\r
case the destroy failed and is called again later.\r
\r
)\r
{\r
//\r
- // Make sure all children instances have been already destoryed.\r
+ // Make sure all children instances have been already destroyed.\r
//\r
ASSERT (Service->ChildrenNum == 0);\r
\r
Mtftp6Srv->Signature = MTFTP6_SERVICE_SIGNATURE;\r
Mtftp6Srv->Controller = Controller;\r
Mtftp6Srv->Image = Image;\r
- Mtftp6Srv->InDestory = FALSE;\r
Mtftp6Srv->ChildrenNum = 0;\r
\r
CopyMem (\r
}\r
\r
Mtftp6Ins->Signature = MTFTP6_INSTANCE_SIGNATURE;\r
- Mtftp6Ins->InDestory = FALSE;\r
+ Mtftp6Ins->InDestroy = FALSE;\r
Mtftp6Ins->Service = Service;\r
\r
CopyMem (\r
}\r
\r
\r
+/**\r
+ Callback function which provided by user to remove one node in NetDestroyLinkList process.\r
+\r
+ @param[in] Entry The entry to be removed.\r
+ @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.\r
+\r
+ @retval EFI_SUCCESS The entry has been removed successfully.\r
+ @retval Others Fail to remove the entry.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Mtftp6DestroyChildEntryInHandleBuffer (\r
+ IN LIST_ENTRY *Entry,\r
+ IN VOID *Context\r
+ )\r
+{\r
+ MTFTP6_INSTANCE *Instance;\r
+ EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;\r
+ UINTN NumberOfChildren;\r
+ EFI_HANDLE *ChildHandleBuffer;\r
+\r
+ if (Entry == NULL || Context == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ Instance = NET_LIST_USER_STRUCT_S (Entry, MTFTP6_INSTANCE, Link, MTFTP6_INSTANCE_SIGNATURE);\r
+ ServiceBinding = ((MTFTP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ServiceBinding;\r
+ NumberOfChildren = ((MTFTP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->NumberOfChildren;\r
+ ChildHandleBuffer = ((MTFTP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ChildHandleBuffer;\r
+\r
+ if (!NetIsInHandleBuffer (Instance->Handle, NumberOfChildren, ChildHandleBuffer)) {\r
+ return EFI_SUCCESS;\r
+ }\r
+\r
+ return ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle);\r
+}\r
+\r
+\r
/**\r
This is the declaration of an EFI image entry point. This entry point is\r
the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers, including\r
\r
\r
/**\r
- Test to see if this driver supports ControllerHandle. This service\r
+ Test to see if this driver supports Controller. This service\r
is called by the EFI boot service ConnectController(). In\r
order to make drivers as small as possible, there are calling\r
restrictions for this service. ConnectController() must\r
Supported(), it must also follow these calling restrictions.\r
\r
@param[in] This Protocol instance pointer.\r
- @param[in] ControllerHandle Handle of device to test\r
+ @param[in] Controller Handle of device to test\r
@param[in] RemainingDevicePath Optional parameter use to pick a specific child.\r
device to start.\r
\r
\r
\r
/**\r
- Start this driver on ControllerHandle. This service is called by the\r
+ Start this driver on Controller. This service is called by the\r
EFI boot service ConnectController(). In order to make\r
drivers as small as possible, there are calling restrictions for\r
this service. ConnectController() must follow these\r
must also follow these calling restrictions.\r
\r
@param[in] This Protocol instance pointer.\r
- @param[in] ControllerHandle Handle of device to bind driver to.\r
+ @param[in] Controller Handle of device to bind driver to.\r
@param[in] RemainingDevicePath Optional parameter use to pick a specific child\r
device to start.\r
\r
- @retval EFI_SUCCESS This driver is added to ControllerHandle.\r
- @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.\r
+ @retval EFI_SUCCESS This driver is added to Controller.\r
+ @retval EFI_ALREADY_STARTED This driver is already running on Controller.\r
@retval Others This driver does not support this device.\r
\r
**/\r
\r
\r
/**\r
- Stop this driver on ControllerHandle. This service is called by the\r
+ Stop this driver on Controller. This service is called by the\r
EFI boot service DisconnectController(). In order to\r
- make drivers as small as possible, there are a few calling\r
+ make drivers as small as possible, there are calling\r
restrictions for this service. DisconnectController()\r
must follow these calling restrictions. If any other agent wishes\r
- to call Stop() it must also follow these calling restrictions.\r
+ to call Stop(), it must also follow these calling restrictions.\r
\r
@param[in] This Protocol instance pointer.\r
- @param[in] ControllerHandle Handle of device to stop driver on\r
+ @param[in] Controller Handle of device to stop driver on\r
@param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
children is zero, stop the entire bus driver.\r
@param[in] ChildHandleBuffer List of Child Handles to Stop.\r
\r
- @retval EFI_SUCCESS This driver is removed ControllerHandle.\r
+ @retval EFI_SUCCESS This driver is removed Controller.\r
@retval EFI_DEVICE_ERROR An unexpected error.\r
@retval Others This driver was not removed from this device.\r
\r
IN EFI_HANDLE *ChildHandleBuffer\r
)\r
{\r
- EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;\r
- MTFTP6_SERVICE *Service;\r
- MTFTP6_INSTANCE *Instance;\r
- EFI_HANDLE NicHandle;\r
- EFI_STATUS Status;\r
- EFI_TPL OldTpl;\r
+ EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;\r
+ MTFTP6_SERVICE *Service;\r
+ EFI_HANDLE NicHandle;\r
+ EFI_STATUS Status;\r
+ LIST_ENTRY *List;\r
+ MTFTP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context;\r
\r
//\r
// Locate the Nic handle to retrieve the Mtftp6 private data.\r
NicHandle = NetLibGetNicHandle (Controller, &gEfiUdp6ProtocolGuid);\r
\r
if (NicHandle == NULL) {\r
- return EFI_DEVICE_ERROR;\r
+ return EFI_SUCCESS;\r
}\r
\r
Status = gBS->OpenProtocol (\r
\r
Service = MTFTP6_SERVICE_FROM_THIS (ServiceBinding);\r
\r
- if (Service->InDestory) {\r
- return EFI_SUCCESS;\r
+ if (!IsListEmpty (&Service->Children)) {\r
+ //\r
+ // Destroy the Mtftp6 child instance in ChildHandleBuffer.\r
+ //\r
+ List = &Service->Children;\r
+ Context.ServiceBinding = ServiceBinding;\r
+ Context.NumberOfChildren = NumberOfChildren;\r
+ Context.ChildHandleBuffer = ChildHandleBuffer;\r
+ Status = NetDestroyLinkList (\r
+ List,\r
+ Mtftp6DestroyChildEntryInHandleBuffer,\r
+ &Context,\r
+ NULL\r
+ );\r
}\r
\r
- OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
-\r
- if (NumberOfChildren == 0) {\r
+ if (NumberOfChildren == 0 && IsListEmpty (&Service->Children)) {\r
//\r
- // Destory the Mtftp6 service if there is no Mtftp6 child instance left.\r
+ // Destroy the Mtftp6 service if there is no Mtftp6 child instance left.\r
//\r
- Service->InDestory = TRUE;\r
-\r
gBS->UninstallProtocolInterface (\r
NicHandle,\r
&gEfiMtftp6ServiceBindingProtocolGuid,\r
);\r
\r
Mtftp6DestroyService (Service);\r
-\r
- } else {\r
- //\r
- // Destory the Mtftp6 child instance one by one.\r
- //\r
- while (!IsListEmpty (&Service->Children)) {\r
- Instance = NET_LIST_HEAD (&Service->Children, MTFTP6_INSTANCE, Link);\r
- Mtftp6ServiceBindingDestroyChild (ServiceBinding, Instance->Handle);\r
- }\r
-\r
- if (Service->ChildrenNum != 0) {\r
- Status = EFI_DEVICE_ERROR;\r
- }\r
+ Status = EFI_SUCCESS;\r
}\r
\r
- gBS->RestoreTPL (OldTpl);\r
return Status;\r
}\r
\r
\r
@retval EFI_SUCCES The protocol was removed from ChildHandle.\r
@retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.\r
- @retval EFI_INVALID_PARAMETER Child handle is not a valid UEFI Handle.\r
+ @retval EFI_INVALID_PARAMETER Child handle is NULL.\r
@retval Others The child handle was not destroyed\r
\r
**/\r
}\r
\r
//\r
- // Check whether the instance already in destory state.\r
+ // Check whether the instance already in Destroy state.\r
//\r
- if (Instance->InDestory) {\r
+ if (Instance->InDestroy) {\r
return EFI_SUCCESS;\r
}\r
\r
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
\r
- Instance->InDestory = TRUE;\r
+ Instance->InDestroy = TRUE;\r
\r
gBS->CloseProtocol (\r
Service->DummyUdpIo->UdpHandle,\r
ChildHandle\r
);\r
\r
+ if (Instance->UdpIo != NULL) {\r
+ gBS->CloseProtocol (\r
+ Instance->UdpIo->UdpHandle,\r
+ &gEfiUdp6ProtocolGuid,\r
+ gMtftp6DriverBinding.DriverBindingHandle,\r
+ Instance->Handle\r
+ );\r
+ }\r
+\r
+ if (Instance->McastUdpIo != NULL) {\r
+ gBS->CloseProtocol (\r
+ Instance->McastUdpIo->UdpHandle,\r
+ &gEfiUdp6ProtocolGuid,\r
+ gMtftp6DriverBinding.DriverBindingHandle,\r
+ Instance->Handle\r
+ );\r
+ }\r
+\r
//\r
// Uninstall the MTFTP6 protocol first to enable a top down destruction.\r
//\r
+ gBS->RestoreTPL (OldTpl);\r
Status = gBS->UninstallProtocolInterface (\r
ChildHandle,\r
&gEfiMtftp6ProtocolGuid,\r
Mtftp6\r
);\r
-\r
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
if (EFI_ERROR (Status)) {\r
- Instance->InDestory = FALSE;\r
+ Instance->InDestroy = FALSE;\r
gBS->RestoreTPL (OldTpl);\r
return Status;\r
}\r
RemoveEntryList (&Instance->Link);\r
Service->ChildrenNum --;\r
\r
- Mtftp6DestroyInstance (Instance);\r
-\r
gBS->RestoreTPL (OldTpl);\r
\r
+ Mtftp6DestroyInstance (Instance);\r
+\r
return EFI_SUCCESS;\r
}\r