X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FLibrary%2FUefiBootManagerLib%2FBmHotkey.c;h=c2d1447f59289fa20b0a669e0a73088c2b53987c;hb=9639c1f3e7f4f0d2df4072a60f754a9c43f2d784;hp=4cc4fb4554154361c3de2abac9c065e080c14a6e;hpb=2d15a830172675b1685cb413de4187fb9f646695;p=mirror_edk2.git diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c b/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c index 4cc4fb4554..c2d1447f59 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c @@ -1,14 +1,9 @@ /** @file Hotkey library functions. -Copyright (c) 2011 - 2016, 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) 2011 - 2018, Intel Corporation. All rights reserved.
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP
+SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -41,7 +36,7 @@ VOID *mBmTxtInExRegistration = NULL; **/ UINTN BmSizeOfKeyOption ( - EFI_BOOT_MANAGER_KEY_OPTION *KeyOption + IN CONST EFI_BOOT_MANAGER_KEY_OPTION *KeyOption ) { return OFFSET_OF (EFI_BOOT_MANAGER_KEY_OPTION, Keys) @@ -60,8 +55,8 @@ BmSizeOfKeyOption ( **/ BOOLEAN BmIsKeyOptionValid ( - IN EFI_BOOT_MANAGER_KEY_OPTION *KeyOption, - IN UINTN KeyOptionSize + IN CONST EFI_BOOT_MANAGER_KEY_OPTION *KeyOption, + IN UINTN KeyOptionSize ) { UINT16 OptionName[BM_OPTION_NAME_LEN]; @@ -115,7 +110,7 @@ BmIsKeyOptionVariable ( { UINTN Index; UINTN Uint; - + if (!CompareGuid (Guid, &gEfiGlobalVariableGuid) || (StrSize (Name) != sizeof (L"Key####")) || (StrnCmp (Name, L"Key", 3) != 0) @@ -157,16 +152,15 @@ BmCollectKeyOptions ( { UINTN Index; BM_COLLECT_KEY_OPTIONS_PARAM *Param; - EFI_BOOT_MANAGER_KEY_OPTION *KeyOption; + VOID *KeyOption; UINT16 OptionNumber; UINTN KeyOptionSize; Param = (BM_COLLECT_KEY_OPTIONS_PARAM *) Context; if (BmIsKeyOptionVariable (Name, Guid, &OptionNumber)) { - GetEfiGlobalVariable2 (Name, (VOID**) &KeyOption, &KeyOptionSize); + GetEfiGlobalVariable2 (Name, &KeyOption, &KeyOptionSize); ASSERT (KeyOption != NULL); - KeyOption->OptionNumber = OptionNumber; if (BmIsKeyOptionValid (KeyOption, KeyOptionSize)) { Param->KeyOptions = ReallocatePool ( Param->KeyOptionCount * sizeof (EFI_BOOT_MANAGER_KEY_OPTION), @@ -178,12 +172,13 @@ BmCollectKeyOptions ( // Insert the key option in order // for (Index = 0; Index < Param->KeyOptionCount; Index++) { - if (KeyOption->OptionNumber < Param->KeyOptions[Index].OptionNumber) { + if (OptionNumber < Param->KeyOptions[Index].OptionNumber) { break; } } CopyMem (&Param->KeyOptions[Index + 1], &Param->KeyOptions[Index], (Param->KeyOptionCount - Index) * sizeof (EFI_BOOT_MANAGER_KEY_OPTION)); - CopyMem (&Param->KeyOptions[Index], KeyOption, BmSizeOfKeyOption (KeyOption)); + CopyMem (&Param->KeyOptions[Index], KeyOption, KeyOptionSize); + Param->KeyOptions[Index].OptionNumber = OptionNumber; Param->KeyOptionCount++; } FreePool (KeyOption); @@ -219,21 +214,6 @@ BmGetKeyOptions ( return Param.KeyOptions; } -/** - Callback function for event. - - @param Event Event for this callback function. - @param Context Context pass to this function. -**/ -VOID -EFIAPI -BmEmptyFunction ( - IN EFI_EVENT Event, - IN VOID *Context - ) -{ -} - /** Check whether the bit is set in the value. @@ -389,7 +369,7 @@ BmHotkeyCallback ( HotkeyData = &Hotkey->KeyData[Hotkey->WaitingKey]; if ((KeyData->Key.ScanCode == HotkeyData->Key.ScanCode) && (KeyData->Key.UnicodeChar == HotkeyData->Key.UnicodeChar) && - (((KeyData->KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) != 0) ? + (((KeyData->KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) != 0) ? (KeyData->KeyState.KeyShiftState == HotkeyData->KeyState.KeyShiftState) : TRUE ) ) { @@ -458,6 +438,9 @@ BmGetActiveConsoleIn ( EFI_STATUS Status; EFI_HANDLE *Handles; + Handles = NULL; + *Count = 0; + if (gST->ConsoleInHandle != NULL) { Status = gBS->OpenProtocol ( gST->ConsoleInHandle, @@ -468,8 +451,10 @@ BmGetActiveConsoleIn ( EFI_OPEN_PROTOCOL_TEST_PROTOCOL ); if (!EFI_ERROR (Status)) { - Handles = AllocateCopyPool (sizeof (EFI_HANDLE *), &gST->ConsoleInHandle); - *Count = 1; + Handles = AllocateCopyPool (sizeof (EFI_HANDLE), &gST->ConsoleInHandle); + if (Handles != NULL) { + *Count = 1; + } } } else { Status = gBS->LocateHandleBuffer ( @@ -480,10 +465,6 @@ BmGetActiveConsoleIn ( &Handles ); } - if (EFI_ERROR (Status)) { - Handles = NULL; - *Count = 0; - } return Handles; } @@ -678,7 +659,7 @@ BmProcessKeyOption ( KeyShiftStateCount = 0; BmGenerateKeyShiftState (0, KeyOption, EFI_SHIFT_STATE_VALID, KeyShiftStates, &KeyShiftStateCount); - ASSERT (KeyShiftStateCount <= sizeof (KeyShiftStates) / sizeof (KeyShiftStates[0])); + ASSERT (KeyShiftStateCount <= ARRAY_SIZE (KeyShiftStates)); EfiAcquireLock (&mBmHotkeyLock); @@ -812,7 +793,7 @@ EfiBootManagerRegisterContinueKeyOption ( EFI_STATUS Status; EFI_BOOT_MANAGER_KEY_OPTION KeyOption; VA_LIST Args; - + if (mBmContinueKeyOption != NULL) { return EFI_ALREADY_STARTED; } @@ -835,7 +816,7 @@ EfiBootManagerRegisterContinueKeyOption ( /** Stop the hotkey processing. - + @param Event Event pointer related to hotkey service. @param Context Context pass to this function. **/ @@ -865,7 +846,7 @@ BmStopHotkeyService ( /** Start the hot key service so that the key press can trigger the boot option. - @param HotkeyTriggered Return the waitable event and it will be signaled + @param HotkeyTriggered Return the waitable event and it will be signaled when a valid hot key is pressed. @retval EFI_SUCCESS The hot key service is started. @@ -883,13 +864,13 @@ EfiBootManagerStartHotkeyService ( EFI_EVENT Event; UINT32 *BootOptionSupport; - Status = GetEfiGlobalVariable2 (EFI_BOOT_OPTION_SUPPORT_VARIABLE_NAME, (VOID **) &BootOptionSupport, NULL); - ASSERT (BootOptionSupport != NULL); - - if ((*BootOptionSupport & EFI_BOOT_OPTION_SUPPORT_KEY) != 0) { - mBmHotkeySupportCount = ((*BootOptionSupport & EFI_BOOT_OPTION_SUPPORT_COUNT) >> LowBitSet32 (EFI_BOOT_OPTION_SUPPORT_COUNT)); + GetEfiGlobalVariable2 (EFI_BOOT_OPTION_SUPPORT_VARIABLE_NAME, (VOID **) &BootOptionSupport, NULL); + if (BootOptionSupport != NULL) { + if ((*BootOptionSupport & EFI_BOOT_OPTION_SUPPORT_KEY) != 0) { + mBmHotkeySupportCount = ((*BootOptionSupport & EFI_BOOT_OPTION_SUPPORT_COUNT) >> LowBitSet32 (EFI_BOOT_OPTION_SUPPORT_COUNT)); + } + FreePool (BootOptionSupport); } - FreePool (BootOptionSupport); if (mBmHotkeySupportCount == 0) { DEBUG ((EFI_D_INFO, "Bds: BootOptionSupport NV variable forbids starting the hotkey service.\n")); @@ -899,7 +880,7 @@ EfiBootManagerStartHotkeyService ( Status = gBS->CreateEvent ( EVT_NOTIFY_WAIT, TPL_CALLBACK, - BmEmptyFunction, + EfiEventEmptyFunction, NULL, &mBmHotkeyTriggered );