From 3012ce5cf75f938a79c70568595454e27b2f014a Mon Sep 17 00:00:00 2001 From: vanjeff Date: Thu, 17 Jan 2008 05:56:45 +0000 Subject: 1. Fixed bugs in DxeNetLib to meet consistence with network module DriverBinding protocol. 2. Sync bugs in console modules. 3. Sync bugs in PlatDriOverLib. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4571 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/Library/DxeNetLib/DxeNetLib.c | 32 ++--- MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf | 16 ++- .../Library/DxePlatDriOverLib/PlatDriOverLib.c | 144 ++++++++++++++++++--- 3 files changed, 142 insertions(+), 50 deletions(-) (limited to 'MdeModulePkg/Library') diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c index f65489e7ed..ee8b6797e5 100644 --- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c +++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c @@ -25,6 +25,8 @@ Abstract: #include #include #include +#include +#include #include #include @@ -842,8 +844,7 @@ NetLibDefaultUnload ( UINTN Index; EFI_DRIVER_BINDING_PROTOCOL *DriverBinding; EFI_COMPONENT_NAME_PROTOCOL *ComponentName; - EFI_DRIVER_CONFIGURATION_PROTOCOL *DriverConfiguration; - EFI_DRIVER_DIAGNOSTICS_PROTOCOL *DriverDiagnostics; + EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2; // // Get the list of all the handles in the handle database. @@ -912,30 +913,15 @@ NetLibDefaultUnload ( Status = gBS->HandleProtocol ( DeviceHandleBuffer[Index], - &gEfiDriverConfigurationProtocolGuid, - (VOID **) &DriverConfiguration + &gEfiComponentName2ProtocolGuid, + (VOID **) &ComponentName2 ); - if (!EFI_ERROR (Status)) { gBS->UninstallProtocolInterface ( - ImageHandle, - &gEfiDriverConfigurationProtocolGuid, - DriverConfiguration - ); - } - - Status = gBS->HandleProtocol ( - DeviceHandleBuffer[Index], - &gEfiDriverDiagnosticsProtocolGuid, - (VOID **) &DriverDiagnostics - ); - - if (!EFI_ERROR (Status)) { - gBS->UninstallProtocolInterface ( - ImageHandle, - &gEfiDriverDiagnosticsProtocolGuid, - DriverDiagnostics - ); + ImageHandle, + &gEfiComponentName2ProtocolGuid, + ComponentName2 + ); } } diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf index deb8949924..3ce822d831 100644 --- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf +++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf @@ -44,15 +44,17 @@ [LibraryClasses] - BaseLib - DebugLib - BaseMemoryLib - UefiBootServicesTableLib - UefiRuntimeServicesTableLib - UefiLib - MemoryAllocationLib + BaseLib + DebugLib + BaseMemoryLib + UefiBootServicesTableLib + UefiRuntimeServicesTableLib + UefiLib + MemoryAllocationLib [Protocols] gEfiSimpleNetworkProtocolGuid # PROTOCOL ALWAYS_CONSUMED gEfiNicIp4ConfigProtocolGuid # PROTOCOL ALWAYS_CONSUMED gEfiDpcProtocolGuid # PROTOCOL ALWAYS_CONSUMED + gEfiComponentNameProtocolGuid # PROTOCOL ALWAYS_CONSUMED + gEfiComponentName2ProtocolGuid # PROTOCOL ALWAYS_CONSUMED \ No newline at end of file diff --git a/MdeModulePkg/Library/DxePlatDriOverLib/PlatDriOverLib.c b/MdeModulePkg/Library/DxePlatDriOverLib/PlatDriOverLib.c index d32715bb40..0ba63fc512 100644 --- a/MdeModulePkg/Library/DxePlatDriOverLib/PlatDriOverLib.c +++ b/MdeModulePkg/Library/DxePlatDriOverLib/PlatDriOverLib.c @@ -63,7 +63,7 @@ InstallPlatformDriverOverrideProtocol ( // if (!EFI_ERROR (Status)) { if (HandleBuffer != NULL) { - gBS->FreePool (HandleBuffer); + FreePool (HandleBuffer); } return EFI_ALREADY_STARTED; } @@ -536,6 +536,92 @@ SaveOverridesMapping ( return EFI_SUCCESS; } +/** + Get the first Binding protocol which has the specific image handle + + @param Image Image handle + + @return Pointer into the Binding Protocol interface + +**/ +EFI_DRIVER_BINDING_PROTOCOL * +EFIAPI +GetBindingProtocolFromImageHandle ( + IN EFI_HANDLE ImageHandle, + OUT EFI_HANDLE *BindingHandle + ) +{ + EFI_STATUS Status; + UINTN Index; + UINTN DriverBindingHandleCount; + EFI_HANDLE *DriverBindingHandleBuffer; + EFI_DRIVER_BINDING_PROTOCOL *DriverBindingInterface; + + if (BindingHandle == NULL || ImageHandle == NULL) { + return NULL; + } + // + // Get all driver which support binding protocol in second page + // + DriverBindingHandleCount = 0; + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiDriverBindingProtocolGuid, + NULL, + &DriverBindingHandleCount, + &DriverBindingHandleBuffer + ); + if (EFI_ERROR (Status) || (DriverBindingHandleCount == 0)) { + return NULL; + } + + for (Index = 0; Index < DriverBindingHandleCount; Index++) { + DriverBindingInterface =NULL; + Status = gBS->OpenProtocol ( + DriverBindingHandleBuffer[Index], + &gEfiDriverBindingProtocolGuid, + (VOID **) &DriverBindingInterface, + NULL, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + continue; + } + + if (DriverBindingInterface->ImageHandle == ImageHandle) { + *BindingHandle = DriverBindingHandleBuffer[Index]; + FreePool (DriverBindingHandleBuffer); + return DriverBindingInterface; + } + } + + FreePool (DriverBindingHandleBuffer); + *BindingHandle = NULL; + return NULL; +} + +/** + return the current TPL, copied from the EDKII glue lib + + @param VOID + + @return Current TPL + +**/ +EFI_TPL +GetCurrentTpl ( + VOID + ) +{ + EFI_TPL Tpl; + + Tpl = gBS->RaiseTPL (TPL_HIGH_LEVEL); + gBS->RestoreTPL (Tpl); + + return Tpl; +} + /** Retrieves the image handle of the platform override driver for a controller in the system from the memory mapping database. @@ -582,6 +668,7 @@ GetDriverFromMapping ( UINTN Index; EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; EFI_DRIVER_BINDING_PROTOCOL *DriverBinding; + EFI_HANDLE DriverBindingHandle; BOOLEAN FoundLastReturned; PLATFORM_OVERRIDE_ITEM *OverrideItem; DRIVER_IMAGE_INFO *DriverImageInfo; @@ -741,18 +828,27 @@ GetDriverFromMapping ( } if (ImageFound) { - Status = gBS->HandleProtocol ( - ImageHandleBuffer[Index], - &gEfiDriverBindingProtocolGuid, - (VOID **) &DriverBinding - ); - ASSERT (!EFI_ERROR (Status)); + // + // Find its related driver binding protocol + // Driver binding handle may be different with its driver's Image handle, + // + DriverBindingHandle = NULL; + DriverBinding = GetBindingProtocolFromImageHandle ( + ImageHandleBuffer[Index], + &DriverBindingHandle + ); + ASSERT (DriverBinding != NULL); DriverImageInfo->ImageHandle = ImageHandleBuffer[Index]; - } else { + } else if (GetCurrentTpl() <= TPL_CALLBACK){ // // The driver image has not been loaded and started, need try to load and start it now // Try to connect all device in the driver image path // + // Note: LoadImage() and StartImage() should be called under CALLBACK TPL in theory, but + // since many device need to be connected in CALLBACK level environment( e.g. Usb devices ) + // and the Fat and Patition driver can endure executing in CALLBACK level in fact, so here permit + // to use LoadImage() and StartImage() in CALLBACK TPL. + // Status = ConnectDevicePath (DriverImageInfo->DriverImagePath); // // check whether it points to a PCI Option Rom image, and try to use bus override protocol to get its first option rom image driver @@ -774,12 +870,16 @@ GetDriverFromMapping ( &ImageHandle ); if (!EFI_ERROR (Status)) { - Status = gBS->HandleProtocol ( - ImageHandle, - &gEfiDriverBindingProtocolGuid, - (VOID **) &DriverBinding - ); - ASSERT (!EFI_ERROR (Status)); + // + // Find its related driver binding protocol + // Driver binding handle may be different with its driver's Image handle + // + DriverBindingHandle = NULL; + DriverBinding = GetBindingProtocolFromImageHandle ( + ImageHandle, + &DriverBindingHandle + ); + ASSERT (DriverBinding != NULL); DriverImageInfo->ImageHandle = ImageHandle; } } @@ -814,12 +914,16 @@ GetDriverFromMapping ( DriverImageInfo->UnStartable = TRUE; DriverImageInfo->ImageHandle = NULL; } else { - Status = gBS->HandleProtocol ( - ImageHandle, - &gEfiDriverBindingProtocolGuid, - (VOID **) &DriverBinding - ); - ASSERT (!EFI_ERROR (Status)); + // + // Find its related driver binding protocol + // Driver binding handle may be different with its driver's Image handle + // + DriverBindingHandle = NULL; + DriverBinding = GetBindingProtocolFromImageHandle ( + ImageHandle, + &DriverBindingHandle + ); + ASSERT (DriverBinding != NULL); DriverImageInfo->ImageHandle = ImageHandle; } } else { -- cgit v1.2.3