Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <[email protected]>
Cc: Feng Tian <[email protected]>
---
 MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c | 96 ++++++++++++++++------
 1 file changed, 73 insertions(+), 23 deletions(-)

diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c 
b/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c
index af303e8..4cc4fb4 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c
@@ -1,7 +1,7 @@
 /** @file
   Hotkey library functions.
 
-Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>
 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
@@ -441,6 +441,54 @@ BmHotkeyCallback (
 }
 
 /**
+  Return the active Simple Text Input Ex handle array.
+  If the SystemTable.ConsoleInHandle is NULL, the function returns all
+  founded Simple Text Input Ex handles.
+  Otherwise, it just returns the ConsoleInHandle.
+
+  @param Count  Return the handle count.
+
+  @retval The active console handles.
+**/
+EFI_HANDLE *
+BmGetActiveConsoleIn (
+  OUT UINTN                             *Count
+  )
+{
+  EFI_STATUS                            Status;
+  EFI_HANDLE                            *Handles;
+
+  if (gST->ConsoleInHandle != NULL) {
+    Status = gBS->OpenProtocol (
+                    gST->ConsoleInHandle,
+                    &gEfiSimpleTextInputExProtocolGuid,
+                    NULL,
+                    gImageHandle,
+                    NULL,
+                    EFI_OPEN_PROTOCOL_TEST_PROTOCOL
+                    );
+    if (!EFI_ERROR (Status)) {
+      Handles = AllocateCopyPool (sizeof (EFI_HANDLE *), 
&gST->ConsoleInHandle);
+      *Count  = 1;
+    }
+  } else {
+    Status = gBS->LocateHandleBuffer (
+                    ByProtocol,
+                    &gEfiSimpleTextInputExProtocolGuid,
+                    NULL,
+                    Count,
+                    &Handles
+                    );
+  }
+  if (EFI_ERROR (Status)) {
+    Handles = NULL;
+    *Count  = 0;
+  }
+
+  return Handles;
+}
+
+/**
   Unregister hotkey notify list.
 
   @param    Hotkey                Hotkey list.
@@ -461,13 +509,7 @@ BmUnregisterHotkeyNotify (
   EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL     *TxtInEx;
   VOID                                  *NotifyHandle;
 
-  gBS->LocateHandleBuffer (
-          ByProtocol,
-          &gEfiSimpleTextInputExProtocolGuid,
-          NULL,
-          &HandleCount,
-          &Handles
-          );
+  Handles = BmGetActiveConsoleIn (&HandleCount);
   for (Index = 0; Index < HandleCount; Index++) {
     Status = gBS->HandleProtocol (Handles[Index], 
&gEfiSimpleTextInputExProtocolGuid, (VOID **) &TxtInEx);
     ASSERT_EFI_ERROR (Status);
@@ -485,6 +527,10 @@ BmUnregisterHotkeyNotify (
     }
   }
 
+  if (Handles != NULL) {
+    FreePool (Handles);
+  }
+
   return EFI_SUCCESS;
 }
 
@@ -636,6 +682,8 @@ BmProcessKeyOption (
 
   EfiAcquireLock (&mBmHotkeyLock);
 
+  Handles = BmGetActiveConsoleIn (&HandleCount);
+
   for (Index = 0; Index < KeyShiftStateCount; Index++) {
     Hotkey = AllocateZeroPool (sizeof (BM_HOTKEY));
     ASSERT (Hotkey != NULL);
@@ -651,13 +699,6 @@ BmProcessKeyOption (
     }
     InsertTailList (&mBmHotkeyList, &Hotkey->Link);
 
-    gBS->LocateHandleBuffer (
-            ByProtocol,
-            &gEfiSimpleTextInputExProtocolGuid,
-            NULL,
-            &HandleCount,
-            &Handles
-            );
     for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
       Status = gBS->HandleProtocol (Handles[HandleIndex], 
&gEfiSimpleTextInputExProtocolGuid, (VOID **) &TxtInEx);
       ASSERT_EFI_ERROR (Status);
@@ -665,6 +706,9 @@ BmProcessKeyOption (
     }
   }
 
+  if (Handles != NULL) {
+    FreePool (Handles);
+  }
   EfiReleaseLock (&mBmHotkeyLock);
 
   return EFI_SUCCESS;
@@ -875,13 +919,20 @@ EfiBootManagerStartHotkeyService (
     BmProcessKeyOption (mBmContinueKeyOption);
   }
 
-  EfiCreateProtocolNotifyEvent (
-    &gEfiSimpleTextInputExProtocolGuid,
-    TPL_CALLBACK,
-    BmTxtInExCallback,
-    NULL,
-    &mBmTxtInExRegistration
-    );
+  //
+  // Hook hotkey on every future SimpleTextInputEx instance when
+  // SystemTable.ConsoleInHandle == NULL, which means the console
+  // manager (ConSplitter) is absent.
+  //
+  if (gST->ConsoleInHandle == NULL) {
+    EfiCreateProtocolNotifyEvent (
+      &gEfiSimpleTextInputExProtocolGuid,
+      TPL_CALLBACK,
+      BmTxtInExCallback,
+      NULL,
+      &mBmTxtInExRegistration
+      );
+  }
 
   Status = EfiCreateEventReadyToBootEx (
              TPL_CALLBACK,
@@ -891,7 +942,6 @@ EfiBootManagerStartHotkeyService (
              );
   ASSERT_EFI_ERROR (Status);
 
-
   mBmHotkeyServiceStarted = TRUE;
   return Status;
 }
-- 
2.7.0.windows.1

_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to