]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/BootManagerUiLib/BootManager.c
MdeModulePkg/UefiBootManagerLib: Generate boot description for NVME
[mirror_edk2.git] / MdeModulePkg / Library / BootManagerUiLib / BootManager.c
index 3ca3e74f27f1edae6541d2c5ed400be4d858ce06..bf872f867e0800bcfee8ad925e53ea9a1c2eeb2d 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The boot manager reference implementation\r
 \r
-Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials are licensed and made available under\r
 the terms and conditions of the BSD License that accompanies this distribution.\r
 The full text of the license may be found at\r
@@ -31,6 +31,8 @@ UINT32    mBmSetupTextModeRow            = 0;
 UINT32    mBmSetupHorizontalResolution   = 0;\r
 UINT32    mBmSetupVerticalResolution     = 0;\r
 \r
+BOOLEAN   mBmModeInitialized             = FALSE;\r
+\r
 CHAR16             *mDeviceTypeStr[] = {\r
   L"Legacy BEV",\r
   L"Legacy Floppy",\r
@@ -89,8 +91,7 @@ BOOT_MANAGER_CALLBACK_DATA  gBootManagerPrivate = {
 \r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-BmBdsSetConsoleMode (\r
+BmSetConsoleMode (\r
   BOOLEAN  IsSetupMode\r
   )\r
 {\r
@@ -142,7 +143,7 @@ BmBdsSetConsoleMode (
 \r
   if (IsSetupMode) {\r
     //\r
-    // The requried resolution and text mode is setup mode.\r
+    // The required resolution and text mode is setup mode.\r
     //\r
     NewHorizontalResolution = mBmSetupHorizontalResolution;\r
     NewVerticalResolution   = mBmSetupVerticalResolution;\r
@@ -198,7 +199,7 @@ BmBdsSetConsoleMode (
             return EFI_SUCCESS;\r
           } else {\r
             //\r
-            // If current text mode is different from requried text mode.  Set new video mode\r
+            // If current text mode is different from required text mode.  Set new video mode\r
             //\r
             for (Index = 0; Index < MaxTextMode; Index++) {\r
               Status = SimpleTextOut->QueryMode (SimpleTextOut, Index, &CurrentColumn, &CurrentRow);\r
@@ -223,7 +224,7 @@ BmBdsSetConsoleMode (
             }\r
             if (Index == MaxTextMode) {\r
               //\r
-              // If requried text mode is not supported, return error.\r
+              // If required text mode is not supported, return error.\r
               //\r
               FreePool (Info);\r
               return EFI_UNSUPPORTED;\r
@@ -342,7 +343,7 @@ GroupMultipleLegacyBootOption4SameType (
       // Legacy Boot Option\r
       //\r
       DEBUG ((EFI_D_ERROR, "[BootManagerDxe] ==== Find Legacy Boot Option  0x%x! ==== \n", Index));\r
-      ASSERT ((((BBS_BBS_DEVICE_PATH *) BootOption.FilePath)->DeviceType & 0xF) < sizeof (DeviceTypeIndex) / sizeof (DeviceTypeIndex[0]));\r
+      ASSERT ((((BBS_BBS_DEVICE_PATH *) BootOption.FilePath)->DeviceType & 0xF) < ARRAY_SIZE (DeviceTypeIndex));\r
       NextIndex = &DeviceTypeIndex[((BBS_BBS_DEVICE_PATH *) BootOption.FilePath)->DeviceType & 0xF];\r
 \r
       if (*NextIndex == (UINTN) -1) {\r
@@ -361,7 +362,7 @@ GroupMultipleLegacyBootOption4SameType (
         //\r
         // Update the DeviceTypeIndex array to reflect the right shift operation\r
         //\r
-        for (DeviceIndex = 0; DeviceIndex < sizeof (DeviceTypeIndex) / sizeof (DeviceTypeIndex[0]); DeviceIndex++) {\r
+        for (DeviceIndex = 0; DeviceIndex < ARRAY_SIZE (DeviceTypeIndex); DeviceIndex++) {\r
           if (DeviceTypeIndex[DeviceIndex] != (UINTN) -1 && DeviceTypeIndex[DeviceIndex] >= *NextIndex) {\r
             DeviceTypeIndex[DeviceIndex]++;\r
           }\r
@@ -418,8 +419,7 @@ BmDevicePathToStr (
 }\r
 \r
 /**\r
-  This function invokes Boot Manager. If all devices have not a chance to be connected,\r
-  the connect all will be triggered. It then enumerate all boot options. If \r
+  This function invokes Boot Manager. It then enumerate all boot options. If\r
   a boot option from the Boot Manager page is selected, Boot Manager will boot\r
   from this boot option.\r
   \r
@@ -449,8 +449,6 @@ UpdateBootManager (
 \r
   DeviceType = (UINT16) -1;\r
 \r
-  EfiBootManagerConnectAll ();\r
-\r
   //\r
   // for better user experience\r
   // 1. User changes HD configuration (e.g.: unplug HDD), here we have a chance to remove the HDD boot option\r
@@ -528,7 +526,7 @@ UpdateBootManager (
                      HiiHandle,\r
                      0,\r
                      mDeviceTypeStr[\r
-                       MIN (DeviceType & 0xF, sizeof (mDeviceTypeStr) / sizeof (mDeviceTypeStr[0]) - 1)\r
+                       MIN (DeviceType & 0xF, ARRAY_SIZE (mDeviceTypeStr) - 1)\r
                        ],\r
                      NULL\r
                      );\r
@@ -649,6 +647,77 @@ BootManagerRouteConfig (
   return EFI_NOT_FOUND;\r
 }\r
 \r
+/**\r
+  Initial the boot mode related parameters.\r
+\r
+**/\r
+VOID\r
+BmInitialBootModeInfo (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS                         Status;\r
+  EFI_GRAPHICS_OUTPUT_PROTOCOL       *GraphicsOutput;\r
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *SimpleTextOut;\r
+  UINTN                              BootTextColumn;\r
+  UINTN                              BootTextRow;\r
+\r
+  if (mBmModeInitialized) {\r
+    return;\r
+  }\r
+\r
+  //\r
+  // After the console is ready, get current video resolution\r
+  // and text mode before launching setup at first time.\r
+  //\r
+  Status = gBS->HandleProtocol (\r
+                  gST->ConsoleOutHandle,\r
+                  &gEfiGraphicsOutputProtocolGuid,\r
+                  (VOID**)&GraphicsOutput\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    GraphicsOutput = NULL;\r
+  }\r
+\r
+  Status = gBS->HandleProtocol (\r
+                  gST->ConsoleOutHandle,\r
+                  &gEfiSimpleTextOutProtocolGuid,\r
+                  (VOID**)&SimpleTextOut\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    SimpleTextOut = NULL;\r
+  }\r
+\r
+  if (GraphicsOutput != NULL) {\r
+    //\r
+    // Get current video resolution and text mode.\r
+    //\r
+    mBmBootHorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution;\r
+    mBmBootVerticalResolution   = GraphicsOutput->Mode->Info->VerticalResolution;\r
+  }\r
+\r
+  if (SimpleTextOut != NULL) {\r
+    Status = SimpleTextOut->QueryMode (\r
+                              SimpleTextOut,\r
+                              SimpleTextOut->Mode->Mode,\r
+                              &BootTextColumn,\r
+                              &BootTextRow\r
+                              );\r
+    mBmBootTextModeColumn = (UINT32)BootTextColumn;\r
+    mBmBootTextModeRow    = (UINT32)BootTextRow;\r
+  }\r
+\r
+  //\r
+  // Get user defined text mode for setup.\r
+  //\r
+  mBmSetupHorizontalResolution = PcdGet32 (PcdSetupVideoHorizontalResolution);\r
+  mBmSetupVerticalResolution   = PcdGet32 (PcdSetupVideoVerticalResolution);\r
+  mBmSetupTextModeColumn       = PcdGet32 (PcdSetupConOutColumn);\r
+  mBmSetupTextModeRow          = PcdGet32 (PcdSetupConOutRow);\r
+\r
+  mBmModeInitialized           = TRUE;\r
+}\r
+\r
 /**\r
   This call back function is registered with Boot Manager formset.\r
   When user selects a boot option, this call back function will\r
@@ -715,9 +784,9 @@ BootManagerCallback (
   //\r
   // parse the selected option\r
   //\r
-  BmBdsSetConsoleMode (FALSE);\r
+  BmSetConsoleMode (FALSE);\r
   EfiBootManagerBoot (&BootOption[QuestionId - 1]);\r
-  BmBdsSetConsoleMode (TRUE);\r
+  BmSetConsoleMode (TRUE);\r
 \r
   if (EFI_ERROR (BootOption[QuestionId - 1].Status)) {\r
     gST->ConOut->OutputString (\r
@@ -778,6 +847,7 @@ BootManagerUiLibConstructor (
                                     );\r
   ASSERT (gBootManagerPrivate.HiiHandle != NULL);\r
 \r
+  BmInitialBootModeInfo ();\r
 \r
   return EFI_SUCCESS;\r
 }\r