X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FMtftp4Dxe%2FMtftp4Driver.c;h=1c74b5b08344cf9014df2ce341f51991f1f2b9da;hp=ceabbfe41f8222036c13f689d13bbbd2e415c89d;hb=e5eed7d3641d71d7ea539e5379ea9c6a5cd97004;hpb=83cbd279b64f3081af5c06d50fa26e15a99fc066 diff --git a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Driver.c b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Driver.c index ceabbfe41f..1c74b5b083 100644 --- a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Driver.c +++ b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Driver.c @@ -1,21 +1,15 @@ /** @file + Implementation of Mtftp drivers. -Copyright (c) 2006 - 2007, Intel Corporation -All rights reserved. This program and the accompanying materials +Copyright (c) 2006 - 2010, 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 which accompanies this distribution. The full text of the license may be found at -http://opensource.org/licenses/bsd-license.php +http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module Name: - - Mtftp4Driver.c - -Abstract: - - **/ #include "Mtftp4Impl.h" @@ -34,29 +28,23 @@ EFI_SERVICE_BINDING_PROTOCOL gMtftp4ServiceBindingTemplete = { Mtftp4ServiceBindingDestroyChild }; + +/** + The driver entry point which installs multiple protocols to the ImageHandle. + + @param ImageHandle The MTFTP's image handle. + @param SystemTable The system table. + + @retval EFI_SUCCESS The handles are successfully installed on the image. + @retval others some EFI_ERROR occured. + +**/ EFI_STATUS EFIAPI Mtftp4DriverEntryPoint ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) -/*++ - -Routine Description: - - The driver entry point which installs multiple protocols to the ImageHandle. - -Arguments: - - ImageHandle - The MTFTP's image handle - SystemTable - The system table - -Returns: - - EFI_SUCCESS - The handles are successfully installed on the image. Otherwise - some EFI_ERROR. - ---*/ { return EfiLibInstallDriverBindingComponentName2 ( ImageHandle, @@ -78,10 +66,20 @@ Returns: @retval EFI_SUCCESS The controller has UDP service binding protocol installed, MTFTP can support it. - @retval Others MTFTP can't support the controller. + @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and + RemainingDevicePath is already being managed by + the driver specified by This. + @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and + RemainingDevicePath is already being managed by a + different driver or an application that requires + exclusive access. + @retval EFI_UNSUPPORTED The device specified by ControllerHandle and + RemainingDevicePath is not supported by the driver + specified by This. **/ EFI_STATUS +EFIAPI Mtftp4DriverBindingSupported ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, @@ -104,19 +102,21 @@ Mtftp4DriverBindingSupported ( /** - Config a NULL UDP that is used to keep the connection between UDP - and MTFTP. Just leave the Udp child unconfigured. When UDP is - unloaded, MTFTP will be informed with DriverBinding Stop. + Config a NULL UDP that is used to keep the connection between UDP and MTFTP. + + Just leave the Udp child unconfigured. When UDP is unloaded, + MTFTP will be informed with DriverBinding Stop. - @param UdpIo The UDP port to configure + @param UdpIo The UDP_IO to configure @param Context The opaque parameter to the callback @retval EFI_SUCCESS It always return EFI_SUCCESS directly. **/ EFI_STATUS +EFIAPI Mtftp4ConfigNullUdp ( - IN UDP_IO_PORT *UdpIo, + IN UDP_IO *UdpIo, IN VOID *Context ) { @@ -142,16 +142,16 @@ Mtftp4ConfigNullUdp ( **/ EFI_STATUS Mtftp4CreateService ( - IN EFI_HANDLE Controller, - IN EFI_HANDLE Image, - OUT MTFTP4_SERVICE **Service + IN EFI_HANDLE Controller, + IN EFI_HANDLE Image, + OUT MTFTP4_SERVICE **Service ) { MTFTP4_SERVICE *MtftpSb; EFI_STATUS Status; *Service = NULL; - MtftpSb = NetAllocatePool (sizeof (MTFTP4_SERVICE)); + MtftpSb = AllocatePool (sizeof (MTFTP4_SERVICE)); if (MtftpSb == NULL) { return EFI_OUT_OF_RESOURCES; @@ -161,7 +161,7 @@ Mtftp4CreateService ( MtftpSb->ServiceBinding = gMtftp4ServiceBindingTemplete; MtftpSb->InDestory = FALSE; MtftpSb->ChildrenNum = 0; - NetListInit (&MtftpSb->Children); + InitializeListHead (&MtftpSb->Children); MtftpSb->Timer = NULL; MtftpSb->TimerToGetMap = NULL; @@ -181,7 +181,7 @@ Mtftp4CreateService ( ); if (EFI_ERROR (Status)) { - NetFreePool (MtftpSb); + FreePool (MtftpSb); return Status; } @@ -198,16 +198,22 @@ Mtftp4CreateService ( ); if (EFI_ERROR (Status)) { gBS->CloseEvent (MtftpSb->Timer); - NetFreePool (MtftpSb); + FreePool (MtftpSb); return Status; } - MtftpSb->ConnectUdp = UdpIoCreatePort (Controller, Image, Mtftp4ConfigNullUdp, NULL); + MtftpSb->ConnectUdp = UdpIoCreateIo ( + Controller, + Image, + Mtftp4ConfigNullUdp, + UDP_IO_UDP4_VERSION, + NULL + ); if (MtftpSb->ConnectUdp == NULL) { gBS->CloseEvent (MtftpSb->TimerToGetMap); gBS->CloseEvent (MtftpSb->Timer); - NetFreePool (MtftpSb); + FreePool (MtftpSb); return EFI_DEVICE_ERROR; } @@ -221,23 +227,22 @@ Mtftp4CreateService ( @param MtftpSb The MTFTP service binding instance. - @return None - **/ VOID Mtftp4CleanService ( IN MTFTP4_SERVICE *MtftpSb ) { - UdpIoFreePort (MtftpSb->ConnectUdp); + UdpIoFreeIo (MtftpSb->ConnectUdp); gBS->CloseEvent (MtftpSb->TimerToGetMap); gBS->CloseEvent (MtftpSb->Timer); } /** - Start the MTFTP driver on this controller. MTFTP driver will - install a MTFTP SERVICE BINDING protocol on the supported + Start the MTFTP driver on this controller. + + MTFTP driver will install a MTFTP SERVICE BINDING protocol on the supported controller, which can be used to create/destroy MTFTP children. @param This The MTFTP driver binding protocol. @@ -251,6 +256,7 @@ Mtftp4CleanService ( **/ EFI_STATUS +EFIAPI Mtftp4DriverBindingStart ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, @@ -281,6 +287,7 @@ Mtftp4DriverBindingStart ( if (EFI_ERROR (Status)) { return Status; } + ASSERT (MtftpSb != NULL); Status = gBS->SetTimer (MtftpSb->Timer, TimerPeriodic, TICKS_PER_SECOND); @@ -306,7 +313,7 @@ Mtftp4DriverBindingStart ( ON_ERROR: Mtftp4CleanService (MtftpSb); - NetFreePool (MtftpSb); + FreePool (MtftpSb); return Status; } @@ -326,11 +333,12 @@ ON_ERROR: **/ EFI_STATUS +EFIAPI Mtftp4DriverBindingStop ( - IN EFI_DRIVER_BINDING_PROTOCOL *This, - IN EFI_HANDLE Controller, - IN UINTN NumberOfChildren, - IN EFI_HANDLE *ChildHandleBuffer + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE Controller, + IN UINTN NumberOfChildren, + IN EFI_HANDLE *ChildHandleBuffer ) { EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding; @@ -348,7 +356,7 @@ Mtftp4DriverBindingStop ( NicHandle = NetLibGetNicHandle (Controller, &gEfiUdp4ProtocolGuid); if (NicHandle == NULL) { - return EFI_SUCCESS; + return EFI_DEVICE_ERROR; } Status = gBS->OpenProtocol ( @@ -370,39 +378,34 @@ Mtftp4DriverBindingStop ( return EFI_SUCCESS; } - OldTpl = NET_RAISE_TPL (NET_TPL_LOCK); - MtftpSb->InDestory = TRUE; + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); - while (!NetListIsEmpty (&MtftpSb->Children)) { - Instance = NET_LIST_HEAD (&MtftpSb->Children, MTFTP4_PROTOCOL, Link); - Mtftp4ServiceBindingDestroyChild (ServiceBinding, Instance->Handle); - } + if (NumberOfChildren == 0) { - if (MtftpSb->ChildrenNum != 0) { - Status = EFI_DEVICE_ERROR; - goto ON_ERROR; - } + MtftpSb->InDestory = TRUE; - Status = gBS->UninstallProtocolInterface ( - NicHandle, - &gEfiMtftp4ServiceBindingProtocolGuid, - ServiceBinding - ); + gBS->UninstallProtocolInterface ( + NicHandle, + &gEfiMtftp4ServiceBindingProtocolGuid, + ServiceBinding + ); - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } + Mtftp4CleanService (MtftpSb); - Mtftp4CleanService (MtftpSb); - NetFreePool (MtftpSb); + FreePool (MtftpSb); + } else { - NET_RESTORE_TPL (OldTpl); - return EFI_SUCCESS; + while (!IsListEmpty (&MtftpSb->Children)) { + Instance = NET_LIST_HEAD (&MtftpSb->Children, MTFTP4_PROTOCOL, Link); + Mtftp4ServiceBindingDestroyChild (ServiceBinding, Instance->Handle); + } -ON_ERROR: - MtftpSb->InDestory = FALSE; + if (MtftpSb->ChildrenNum != 0) { + Status = EFI_DEVICE_ERROR; + } + } - NET_RESTORE_TPL (OldTpl); + gBS->RestoreTPL (OldTpl); return Status; } @@ -413,25 +416,23 @@ ON_ERROR: @param MtftpSb The MTFTP service binding protocol. @param Instance The MTFTP instance to initialize. - @return None - **/ VOID Mtftp4InitProtocol ( - IN MTFTP4_SERVICE *MtftpSb, - IN MTFTP4_PROTOCOL *Instance + IN MTFTP4_SERVICE *MtftpSb, + OUT MTFTP4_PROTOCOL *Instance ) { - NetZeroMem (Instance, sizeof (MTFTP4_PROTOCOL)); + ZeroMem (Instance, sizeof (MTFTP4_PROTOCOL)); Instance->Signature = MTFTP4_PROTOCOL_SIGNATURE; - NetListInit (&Instance->Link); + InitializeListHead (&Instance->Link); CopyMem (&Instance->Mtftp4, &gMtftp4ProtocolTemplate, sizeof (Instance->Mtftp4)); Instance->State = MTFTP4_STATE_UNCONFIGED; - Instance->Indestory = FALSE; + Instance->InDestory = FALSE; Instance->Service = MtftpSb; - NetListInit (&Instance->Blocks); + InitializeListHead (&Instance->Blocks); } @@ -448,9 +449,10 @@ Mtftp4InitProtocol ( **/ EFI_STATUS +EFIAPI Mtftp4ServiceBindingCreateChild ( IN EFI_SERVICE_BINDING_PROTOCOL *This, - IN OUT EFI_HANDLE *ChildHandle + IN EFI_HANDLE *ChildHandle ) { MTFTP4_SERVICE *MtftpSb; @@ -463,7 +465,7 @@ Mtftp4ServiceBindingCreateChild ( return EFI_INVALID_PARAMETER; } - Instance = NetAllocatePool (sizeof (*Instance)); + Instance = AllocatePool (sizeof (*Instance)); if (Instance == NULL) { return EFI_OUT_OF_RESOURCES; @@ -473,15 +475,16 @@ Mtftp4ServiceBindingCreateChild ( Mtftp4InitProtocol (MtftpSb, Instance); - Instance->UnicastPort = UdpIoCreatePort ( + Instance->UnicastPort = UdpIoCreateIo ( MtftpSb->Controller, MtftpSb->Image, Mtftp4ConfigNullUdp, + UDP_IO_UDP4_VERSION, Instance ); if (Instance->UnicastPort == NULL) { - NetFreePool (Instance); + FreePool (Instance); return EFI_OUT_OF_RESOURCES; } @@ -526,18 +529,18 @@ Mtftp4ServiceBindingCreateChild ( // // Add it to the parent's child list. // - OldTpl = NET_RAISE_TPL (NET_TPL_LOCK); + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); - NetListInsertTail (&MtftpSb->Children, &Instance->Link); + InsertTailList (&MtftpSb->Children, &Instance->Link); MtftpSb->ChildrenNum++; - NET_RESTORE_TPL (OldTpl); + gBS->RestoreTPL (OldTpl); ON_ERROR: if (EFI_ERROR (Status)) { - UdpIoFreePort (Instance->UnicastPort); - NetFreePool (Instance); + UdpIoFreeIo (Instance->UnicastPort); + FreePool (Instance); } return Status; @@ -557,6 +560,7 @@ ON_ERROR: **/ EFI_STATUS +EFIAPI Mtftp4ServiceBindingDestroyChild ( IN EFI_SERVICE_BINDING_PROTOCOL *This, IN EFI_HANDLE ChildHandle @@ -595,11 +599,11 @@ Mtftp4ServiceBindingDestroyChild ( return EFI_INVALID_PARAMETER; } - if (Instance->Indestory) { + if (Instance->InDestory) { return EFI_SUCCESS; } - Instance->Indestory = TRUE; + Instance->InDestory = TRUE; // // Close the Udp4 protocol. @@ -621,20 +625,20 @@ Mtftp4ServiceBindingDestroyChild ( ); if (EFI_ERROR (Status)) { - Instance->Indestory = FALSE; + Instance->InDestory = FALSE; return Status; } - OldTpl = NET_RAISE_TPL (NET_TPL_LOCK); + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); Mtftp4CleanOperation (Instance, EFI_DEVICE_ERROR); - UdpIoFreePort (Instance->UnicastPort); + UdpIoFreeIo (Instance->UnicastPort); - NetListRemoveEntry (&Instance->Link); + RemoveEntryList (&Instance->Link); MtftpSb->ChildrenNum--; - NET_RESTORE_TPL (OldTpl); + gBS->RestoreTPL (OldTpl); - NetFreePool (Instance); + FreePool (Instance); return EFI_SUCCESS; }