X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=EdkNt32Pkg%2FLibrary%2FEdkGenericBdsLib%2FBdsConsole.c;h=96a1f4b9fd48d84ddc2889e7d1ab25f8ceb165fe;hp=721d74363a077370195054f527e6d9de9544cd77;hb=ebb9ce7a063562f194eec5bcb86a31a6fa2f3fe6;hpb=878ddf1fc3540a715f63594ed22b6929e881afb4 diff --git a/EdkNt32Pkg/Library/EdkGenericBdsLib/BdsConsole.c b/EdkNt32Pkg/Library/EdkGenericBdsLib/BdsConsole.c index 721d74363a..96a1f4b9fd 100644 --- a/EdkNt32Pkg/Library/EdkGenericBdsLib/BdsConsole.c +++ b/EdkNt32Pkg/Library/EdkGenericBdsLib/BdsConsole.c @@ -1,13 +1,13 @@ /*++ -Copyright (c) 2006, 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 - -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +Copyright (c) 2006 - 2007, 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 + +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: @@ -19,6 +19,30 @@ Abstract: --*/ +BOOLEAN +IsNvNeed ( + IN CHAR16 *ConVarName + ) +{ + CHAR16 *Ptr; + + Ptr = ConVarName; + + // + // If the variable includes "Dev" at last, we consider + // it does not support NV attribute. + // + while (*Ptr) { + Ptr++; + } + + if ((*(Ptr - 3) == 'D') && (*(Ptr - 2) == 'e') && (*(Ptr - 1) == 'v')) { + return FALSE; + } else { + return TRUE; + } +} + EFI_STATUS BdsLibUpdateConsoleVariable ( IN CHAR16 *ConVarName, @@ -29,7 +53,7 @@ BdsLibUpdateConsoleVariable ( Routine Description: - This function update console variable based on ConVarName, it can + This function update console variable based on ConVarName, it can add or remove one specific console device path from the variable Arguments: @@ -47,8 +71,8 @@ Arguments: Returns: EFI_UNSUPPORTED - Add or remove the same device path. - - EFI_SUCCESS - Success add or remove the device path from + + EFI_SUCCESS - Success add or remove the device path from the console variable. --*/ @@ -56,12 +80,12 @@ Returns: EFI_STATUS Status; EFI_DEVICE_PATH_PROTOCOL *VarConsole; UINTN DevicePathSize; - EFI_DEVICE_PATH_PROTOCOL *Instance; EFI_DEVICE_PATH_PROTOCOL *NewDevicePath; + EFI_DEVICE_PATH_PROTOCOL *TempNewDevicePath; + UINT32 Attributes; VarConsole = NULL; DevicePathSize = 0; - NewDevicePath = NULL; Status = EFI_UNSUPPORTED; // @@ -80,73 +104,70 @@ Returns: &DevicePathSize ); + // + // Initialize NewDevicePath + // + NewDevicePath = VarConsole; + + // + // If ExclusiveDevicePath is even the part of the instance in VarConsole, delete it. + // In the end, NewDevicePath is the final device path. + // if (ExclusiveDevicePath != NULL && VarConsole != NULL) { - if (BdsLibMatchDevicePaths (VarConsole, ExclusiveDevicePath)) { - - Instance = GetNextDevicePathInstance (&VarConsole, &DevicePathSize); - - while (VarConsole != NULL) { - if (CompareMem ( - Instance, - ExclusiveDevicePath, - DevicePathSize - sizeof (EFI_DEVICE_PATH_PROTOCOL) - ) == 0) { - // - // Remove the match part - // - NewDevicePath = AppendDevicePathInstance (NewDevicePath, VarConsole); - break; - } else { - // - // Continue the next instance - // - NewDevicePath = AppendDevicePathInstance (NewDevicePath, Instance); - } - - Instance = GetNextDevicePathInstance (&VarConsole, &DevicePathSize); - } - // - // Reset the console variable with new device path - // - gRT->SetVariable ( - ConVarName, - &gEfiGlobalVariableGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, - GetDevicePathSize (NewDevicePath), - NewDevicePath - ); - } + NewDevicePath = BdsLibDelPartMatchInstance (VarConsole, ExclusiveDevicePath); } // - // Try to append customized device path + // Try to append customized device path to NewDevicePath. // - VarConsole = BdsLibGetVariableAndSize ( - ConVarName, - &gEfiGlobalVariableGuid, - &DevicePathSize - ); - if (CustomizedConDevicePath != NULL) { - if (!BdsLibMatchDevicePaths (VarConsole, CustomizedConDevicePath)) { + if (!BdsLibMatchDevicePaths (NewDevicePath, CustomizedConDevicePath)) { // - // In the first check, the default console variable will be null, - // just append current customized device path + // Check if there is part of CustomizedConDevicePath in NewDevicePath, delete it. // - VarConsole = AppendDevicePathInstance (VarConsole, CustomizedConDevicePath); - + NewDevicePath = BdsLibDelPartMatchInstance (NewDevicePath, CustomizedConDevicePath); // - // Update the variable of the default console + // In the first check, the default console variable will be null, + // just append current customized device path // - gRT->SetVariable ( - ConVarName, - &gEfiGlobalVariableGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, - GetDevicePathSize (VarConsole), - VarConsole - ); + TempNewDevicePath = NewDevicePath; + NewDevicePath = AppendDevicePathInstance (NewDevicePath, CustomizedConDevicePath); + BdsLibSafeFreePool(TempNewDevicePath); } } + // + // The attribute for ConInDev, ConOutDev and ErrOutDev does not include NV. + // + if (IsNvNeed(ConVarName)) { + // + // ConVarName has NV attribute. + // + Attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE; + } else { + // + // ConVarName does not have NV attribute. + // + Attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS; + } + + // + // Finally, Update the variable of the default console by NewDevicePath + // + gRT->SetVariable ( + ConVarName, + &gEfiGlobalVariableGuid, + Attributes, + GetDevicePathSize (NewDevicePath), + NewDevicePath + ); + + if (VarConsole == NewDevicePath) { + BdsLibSafeFreePool(VarConsole); + } else { + BdsLibSafeFreePool(VarConsole); + BdsLibSafeFreePool(NewDevicePath); + } + return EFI_SUCCESS; } @@ -171,7 +192,7 @@ Arguments: Returns: EFI_NOT_FOUND - There is not any console devices connected success - + EFI_SUCCESS - Success connect any one instance of the console device path base on the variable ConVarName. @@ -201,7 +222,7 @@ Returns: return EFI_UNSUPPORTED; } - CopyOfDevicePath = DuplicateDevicePath (StartDevicePath); + CopyOfDevicePath = StartDevicePath; do { // // Check every instance of the console variable @@ -226,10 +247,10 @@ Returns: } else { DeviceExist = TRUE; } - + BdsLibSafeFreePool(Instance); } while (CopyOfDevicePath != NULL); - gBS->FreePool (StartDevicePath); + FreePool (StartDevicePath); if (DeviceExist == FALSE) { return EFI_NOT_FOUND; @@ -289,6 +310,8 @@ Returns: BdsLibUpdateConsoleVariable (L"ConIn", ConDevicePath, NULL); } + BdsLibSafeFreePool(HandleBuffer); + Status = gBS->LocateHandleBuffer ( ByProtocol, &gEfiSimpleTextOutProtocolGuid, @@ -305,6 +328,9 @@ Returns: BdsLibUpdateConsoleVariable (L"ConOut", ConDevicePath, NULL); BdsLibUpdateConsoleVariable (L"ErrOut", ConDevicePath, NULL); } + + BdsLibSafeFreePool(HandleBuffer); + // // Connect all console variables // @@ -320,7 +346,7 @@ BdsLibConnectAllDefaultConsoles ( Routine Description: - This function will connect console device base on the console + This function will connect console device base on the console device variable ConIn, ConOut and ErrOut. Arguments: @@ -331,23 +357,28 @@ Returns: EFI_SUCCESS - At least one of the ConIn and ConOut device have been connected success. - + EFI_STATUS - Return the status of BdsLibConnectConsoleVariable (). --*/ { EFI_STATUS Status; - EFI_DEVICE_PATH_PROTOCOL *VarErrout; - UINTN DevicePathSize; // // Connect all default console variables // - Status = BdsLibConnectConsoleVariable (L"ConIn"); - if (EFI_ERROR (Status)) { - return Status; - } + // + // Because possibly the platform is legacy free, in such case, + // ConIn devices (Serial Port and PS2 Keyboard ) does not exist, + // so we need not check the status. + // + BdsLibConnectConsoleVariable (L"ConIn"); + + // + // It seems impossible not to have any ConOut device on platform, + // so we check the status here. + // Status = BdsLibConnectConsoleVariable (L"ConOut"); if (EFI_ERROR (Status)) { return Status; @@ -356,14 +387,7 @@ Returns: // Special treat the err out device, becaues the null // err out var is legal. // - VarErrout = BdsLibGetVariableAndSize ( - L"ErrOut", - &gEfiGlobalVariableGuid, - &DevicePathSize - ); - if (VarErrout != NULL) { - BdsLibConnectConsoleVariable (L"ErrOut"); - } + BdsLibConnectConsoleVariable (L"ErrOut"); return EFI_SUCCESS;