]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/Bds: BDS hotkey shouldn't work on inactive consoles
authorRuiyu Ni <ruiyu.ni@intel.com>
Fri, 18 Mar 2016 07:48:49 +0000 (15:48 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Wed, 23 Mar 2016 05:22:30 +0000 (13:22 +0800)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
Reviewed-by: Sunny Wang <sunnywang@intel.com>
MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c

index af303e8469ab8e9fd542581c2e25a370cf7f28ef..4cc4fb4554154361c3de2abac9c065e080c14a6e 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Hotkey library functions.\r
 \r
-Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -440,6 +440,54 @@ BmHotkeyCallback (
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Return the active Simple Text Input Ex handle array.\r
+  If the SystemTable.ConsoleInHandle is NULL, the function returns all\r
+  founded Simple Text Input Ex handles.\r
+  Otherwise, it just returns the ConsoleInHandle.\r
+\r
+  @param Count  Return the handle count.\r
+\r
+  @retval The active console handles.\r
+**/\r
+EFI_HANDLE *\r
+BmGetActiveConsoleIn (\r
+  OUT UINTN                             *Count\r
+  )\r
+{\r
+  EFI_STATUS                            Status;\r
+  EFI_HANDLE                            *Handles;\r
+\r
+  if (gST->ConsoleInHandle != NULL) {\r
+    Status = gBS->OpenProtocol (\r
+                    gST->ConsoleInHandle,\r
+                    &gEfiSimpleTextInputExProtocolGuid,\r
+                    NULL,\r
+                    gImageHandle,\r
+                    NULL,\r
+                    EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
+                    );\r
+    if (!EFI_ERROR (Status)) {\r
+      Handles = AllocateCopyPool (sizeof (EFI_HANDLE *), &gST->ConsoleInHandle);\r
+      *Count  = 1;\r
+    }\r
+  } else {\r
+    Status = gBS->LocateHandleBuffer (\r
+                    ByProtocol,\r
+                    &gEfiSimpleTextInputExProtocolGuid,\r
+                    NULL,\r
+                    Count,\r
+                    &Handles\r
+                    );\r
+  }\r
+  if (EFI_ERROR (Status)) {\r
+    Handles = NULL;\r
+    *Count  = 0;\r
+  }\r
+\r
+  return Handles;\r
+}\r
+\r
 /**\r
   Unregister hotkey notify list.\r
 \r
@@ -461,13 +509,7 @@ BmUnregisterHotkeyNotify (
   EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL     *TxtInEx;\r
   VOID                                  *NotifyHandle;\r
 \r
-  gBS->LocateHandleBuffer (\r
-          ByProtocol,\r
-          &gEfiSimpleTextInputExProtocolGuid,\r
-          NULL,\r
-          &HandleCount,\r
-          &Handles\r
-          );\r
+  Handles = BmGetActiveConsoleIn (&HandleCount);\r
   for (Index = 0; Index < HandleCount; Index++) {\r
     Status = gBS->HandleProtocol (Handles[Index], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &TxtInEx);\r
     ASSERT_EFI_ERROR (Status);\r
@@ -485,6 +527,10 @@ BmUnregisterHotkeyNotify (
     }\r
   }\r
 \r
+  if (Handles != NULL) {\r
+    FreePool (Handles);\r
+  }\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -636,6 +682,8 @@ BmProcessKeyOption (
 \r
   EfiAcquireLock (&mBmHotkeyLock);\r
 \r
+  Handles = BmGetActiveConsoleIn (&HandleCount);\r
+\r
   for (Index = 0; Index < KeyShiftStateCount; Index++) {\r
     Hotkey = AllocateZeroPool (sizeof (BM_HOTKEY));\r
     ASSERT (Hotkey != NULL);\r
@@ -651,13 +699,6 @@ BmProcessKeyOption (
     }\r
     InsertTailList (&mBmHotkeyList, &Hotkey->Link);\r
 \r
-    gBS->LocateHandleBuffer (\r
-            ByProtocol,\r
-            &gEfiSimpleTextInputExProtocolGuid,\r
-            NULL,\r
-            &HandleCount,\r
-            &Handles\r
-            );\r
     for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {\r
       Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &TxtInEx);\r
       ASSERT_EFI_ERROR (Status);\r
@@ -665,6 +706,9 @@ BmProcessKeyOption (
     }\r
   }\r
 \r
+  if (Handles != NULL) {\r
+    FreePool (Handles);\r
+  }\r
   EfiReleaseLock (&mBmHotkeyLock);\r
 \r
   return EFI_SUCCESS;\r
@@ -875,13 +919,20 @@ EfiBootManagerStartHotkeyService (
     BmProcessKeyOption (mBmContinueKeyOption);\r
   }\r
 \r
-  EfiCreateProtocolNotifyEvent (\r
-    &gEfiSimpleTextInputExProtocolGuid,\r
-    TPL_CALLBACK,\r
-    BmTxtInExCallback,\r
-    NULL,\r
-    &mBmTxtInExRegistration\r
-    );\r
+  //\r
+  // Hook hotkey on every future SimpleTextInputEx instance when\r
+  // SystemTable.ConsoleInHandle == NULL, which means the console\r
+  // manager (ConSplitter) is absent.\r
+  //\r
+  if (gST->ConsoleInHandle == NULL) {\r
+    EfiCreateProtocolNotifyEvent (\r
+      &gEfiSimpleTextInputExProtocolGuid,\r
+      TPL_CALLBACK,\r
+      BmTxtInExCallback,\r
+      NULL,\r
+      &mBmTxtInExRegistration\r
+      );\r
+  }\r
 \r
   Status = EfiCreateEventReadyToBootEx (\r
              TPL_CALLBACK,\r
@@ -891,7 +942,6 @@ EfiBootManagerStartHotkeyService (
              );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-\r
   mBmHotkeyServiceStarted = TRUE;\r
   return Status;\r
 }\r