]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Universal/BdsDxe/Hotkey.c
The hotkey callback in BDS module should defer loading the boot option until the...
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / BdsDxe / Hotkey.c
index da0a2eef5aa9ff6842acc457c473dacdfc9cb2be..d0d9bb077bfb2b6e14d999abb35ca86a7576388a 100644 (file)
@@ -2,7 +2,7 @@
   Provides a way for 3rd party applications to register themselves for launch by the\r
   Boot Manager based on hot key\r
 \r
-Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2011, 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
@@ -16,10 +16,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include "Hotkey.h"\r
 \r
 \r
-LIST_ENTRY      mHotkeyList = INITIALIZE_LIST_HEAD_VARIABLE (mHotkeyList);\r
-BOOLEAN         mHotkeyCallbackPending = FALSE;\r
-EFI_EVENT       mHotkeyEvent;\r
-VOID            *mHotkeyRegistration;\r
+LIST_ENTRY        mHotkeyList = INITIALIZE_LIST_HEAD_VARIABLE (mHotkeyList);\r
+BDS_COMMON_OPTION *mHotkeyBootOption = NULL;\r
+EFI_EVENT         mHotkeyEvent;\r
+VOID              *mHotkeyRegistration;\r
 \r
 \r
 /**\r
@@ -300,6 +300,50 @@ UnregisterHotkey (
   return Status;\r
 }\r
 \r
+/**\r
+  Try to boot the boot option triggered by hotkey.\r
+**/\r
+VOID\r
+HotkeyBoot (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS           Status;\r
+  UINTN                ExitDataSize;\r
+  CHAR16               *ExitData;\r
+  \r
+  if (mHotkeyBootOption != NULL) {\r
+    BdsLibConnectDevicePath (mHotkeyBootOption->DevicePath);\r
+\r
+    //\r
+    // Clear the screen before launch this BootOption\r
+    //\r
+    gST->ConOut->Reset (gST->ConOut, FALSE);\r
+\r
+    Status = BdsLibBootViaBootOption (mHotkeyBootOption, mHotkeyBootOption->DevicePath, &ExitDataSize, &ExitData);\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // Call platform action to indicate the boot fail\r
+      //\r
+      mHotkeyBootOption->StatusString = GetStringById (STRING_TOKEN (STR_BOOT_FAILED));\r
+      PlatformBdsBootFail (mHotkeyBootOption, Status, ExitData, ExitDataSize);\r
+    } else {\r
+      //\r
+      // Call platform action to indicate the boot success\r
+      //\r
+      mHotkeyBootOption->StatusString = GetStringById (STRING_TOKEN (STR_BOOT_SUCCEEDED));\r
+      PlatformBdsBootSuccess (mHotkeyBootOption);\r
+    }\r
+    FreePool (mHotkeyBootOption->Description);\r
+    FreePool (mHotkeyBootOption->DevicePath);\r
+    FreePool (mHotkeyBootOption->LoadOptions);\r
+    FreePool (mHotkeyBootOption);\r
+\r
+    mHotkeyBootOption = NULL;\r
+  }\r
+}\r
+\r
 /**\r
 \r
   This is the common notification function for HotKeys, it will be registered\r
@@ -322,24 +366,22 @@ HotkeyCallback (
   LIST_ENTRY         *Link;\r
   BDS_HOTKEY_OPTION  *Hotkey;\r
   UINT16             Buffer[10];\r
-  BDS_COMMON_OPTION  *BootOption;\r
-  UINTN              ExitDataSize;\r
-  CHAR16             *ExitData;\r
   EFI_STATUS         Status;\r
   EFI_KEY_DATA       *HotkeyData;\r
 \r
-  if (mHotkeyCallbackPending) {\r
+  if (mHotkeyBootOption != NULL) {\r
     //\r
-    // When responsing to a Hotkey, ignore sequential hotkey stroke until\r
-    // the current Boot#### load option returned\r
+    // Do not process sequential hotkey stroke until the current boot option returns\r
     //\r
     return EFI_SUCCESS;\r
   }\r
 \r
-  Status = EFI_SUCCESS;\r
-  Link = GetFirstNode (&mHotkeyList);\r
+  Status                 = EFI_SUCCESS;\r
 \r
-  while (!IsNull (&mHotkeyList, Link)) {\r
+  for ( Link = GetFirstNode (&mHotkeyList)\r
+      ; !IsNull (&mHotkeyList, Link)\r
+      ; Link = GetNextNode (&mHotkeyList, Link)\r
+      ) {\r
     HotkeyCatched = FALSE;\r
     Hotkey = BDS_HOTKEY_OPTION_FROM_LINK (Link);\r
 \r
@@ -349,26 +391,19 @@ HotkeyCallback (
     ASSERT (Hotkey->WaitingKey < (sizeof (Hotkey->KeyData) / sizeof (Hotkey->KeyData[0])));\r
     HotkeyData = &Hotkey->KeyData[Hotkey->WaitingKey];\r
     if ((KeyData->Key.ScanCode == HotkeyData->Key.ScanCode) &&\r
-       (KeyData->Key.UnicodeChar == HotkeyData->Key.UnicodeChar) &&\r
-       (((HotkeyData->KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) != 0) ? (KeyData->KeyState.KeyShiftState == HotkeyData->KeyState.KeyShiftState) : TRUE)) {\r
+        (KeyData->Key.UnicodeChar == HotkeyData->Key.UnicodeChar) &&\r
+        (((KeyData->KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) != 0) ? \r
+          (KeyData->KeyState.KeyShiftState == HotkeyData->KeyState.KeyShiftState) : TRUE\r
+        )\r
+       ) {\r
       //\r
-      // Receive an expecting key stroke\r
+      // For hotkey of key combination, transit to next waiting state\r
       //\r
-      if (Hotkey->CodeCount > 1) {\r
-        //\r
-        // For hotkey of key combination, transit to next waiting state\r
-        //\r
-        Hotkey->WaitingKey++;\r
+      Hotkey->WaitingKey++;\r
 \r
-        if (Hotkey->WaitingKey == Hotkey->CodeCount) {\r
-          //\r
-          // Received the whole key stroke sequence\r
-          //\r
-          HotkeyCatched = TRUE;\r
-        }\r
-      } else {\r
+      if (Hotkey->WaitingKey == Hotkey->CodeCount) {\r
         //\r
-        // For hotkey of single key stroke\r
+        // Received the whole key stroke sequence\r
         //\r
         HotkeyCatched = TRUE;\r
       }\r
@@ -391,38 +426,8 @@ HotkeyCallback (
       InitializeListHead (&BootLists);\r
 \r
       UnicodeSPrint (Buffer, sizeof (Buffer), L"Boot%04x", Hotkey->BootOptionNumber);\r
-      BootOption = BdsLibVariableToOption (&BootLists, Buffer);\r
-      if (BootOption == NULL) {\r
-        return EFI_NOT_FOUND;\r
-      }\r
-      BootOption->BootCurrent = Hotkey->BootOptionNumber;\r
-      BdsLibConnectDevicePath (BootOption->DevicePath);\r
-\r
-      //\r
-      // Clear the screen before launch this BootOption\r
-      //\r
-      gST->ConOut->Reset (gST->ConOut, FALSE);\r
-\r
-      mHotkeyCallbackPending = TRUE;\r
-      Status = BdsLibBootViaBootOption (BootOption, BootOption->DevicePath, &ExitDataSize, &ExitData);\r
-      mHotkeyCallbackPending = FALSE;\r
-\r
-      if (EFI_ERROR (Status)) {\r
-        //\r
-        // Call platform action to indicate the boot fail\r
-        //\r
-        BootOption->StatusString = GetStringById (STRING_TOKEN (STR_BOOT_FAILED));\r
-        PlatformBdsBootFail (BootOption, Status, ExitData, ExitDataSize);\r
-      } else {\r
-        //\r
-        // Call platform action to indicate the boot success\r
-        //\r
-        BootOption->StatusString = GetStringById (STRING_TOKEN (STR_BOOT_SUCCEEDED));\r
-        PlatformBdsBootSuccess (BootOption);\r
-      }\r
+      mHotkeyBootOption = BdsLibVariableToOption (&BootLists, Buffer);\r
     }\r
-\r
-    Link = GetNextNode (&mHotkeyList, Link);\r
   }\r
 \r
   return Status;\r