]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c
Do not reset system when the MemoryTypeInformation variable cannot be written.
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / GenericBdsLib / BdsMisc.c
index 3d1ccf9dc2c5ffd3872a85e26733d01696742c39..cafbe71e25993f28fc5976713f2768168e13f2db 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Misc BDS library function\r
 \r
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2014, 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
@@ -825,6 +825,7 @@ BdsLibGetVariableAndSize (
     //\r
     Buffer = AllocateZeroPool (BufferSize);\r
     if (Buffer == NULL) {\r
+      *VariableSize = 0;\r
       return NULL;\r
     }\r
     //\r
@@ -832,10 +833,15 @@ BdsLibGetVariableAndSize (
     //\r
     Status = gRT->GetVariable (Name, VendorGuid, NULL, &BufferSize, Buffer);\r
     if (EFI_ERROR (Status)) {\r
+      FreePool (Buffer);\r
       BufferSize = 0;\r
+      Buffer     = NULL;\r
     }\r
   }\r
 \r
+  ASSERT (((Buffer == NULL) && (BufferSize == 0)) ||\r
+          ((Buffer != NULL) && (BufferSize != 0))\r
+          );\r
   *VariableSize = BufferSize;\r
   return Buffer;\r
 }\r
@@ -1118,24 +1124,19 @@ SetupResetReminder (
       ASSERT (StringBuffer1 != NULL);\r
       StringBuffer2 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));\r
       ASSERT (StringBuffer2 != NULL);\r
-      StrCpy (StringBuffer1, L"Configuration changed. Reset to apply it Now ? ");\r
-      StrCpy (StringBuffer2, L"Enter (YES)  /   Esc (NO)");\r
+      StrCpy (StringBuffer1, L"Configuration changed. Reset to apply it Now.");\r
+      StrCpy (StringBuffer2, L"Press ENTER to reset");\r
       //\r
       // Popup a menu to notice user\r
       //\r
       do {\r
         CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, NULL);\r
-      } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));\r
+      } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
 \r
       FreePool (StringBuffer1);\r
       FreePool (StringBuffer2);\r
-      //\r
-      // If the user hits the YES Response key, reset\r
-      //\r
-      if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
-        gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);\r
-      }\r
-      gST->ConOut->ClearScreen (gST->ConOut);\r
+\r
+      gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);\r
     }\r
   }\r
 }\r
@@ -1282,10 +1283,8 @@ BdsLibGetImageHeader (
 }\r
 \r
 /**\r
-  This routine adjusts the memory information for different memory type and \r
-  saves them into the variables for next boot. It conditionally resets the\r
-  system when the memory information changes. Platform can reserve memory \r
-  large enough (125% of actual requirement) to avoid the reset in the first boot.\r
+  This routine adjust the memory information for different memory type and \r
+  save them into the variables for next boot.\r
 **/\r
 VOID\r
 BdsSetMemoryTypeInformationVariable (\r
@@ -1391,13 +1390,14 @@ BdsSetMemoryTypeInformationVariable (
     Next     = Previous;\r
 \r
     //\r
-    // Write next varible to 125% * current and Inconsistent Memory Reserved across bootings may lead to S4 fail\r
+    // Inconsistent Memory Reserved across bootings may lead to S4 fail\r
+    // Write next varible to 125% * current when the pre-allocated memory is:\r
+    //  1. More than 150% of needed memory and boot mode is BOOT_WITH_DEFAULT_SETTING\r
+    //  2. Less than the needed memory\r
     //\r
-    if (Current < Previous) {\r
+    if ((Current + (Current >> 1)) < Previous) {\r
       if (BootMode == BOOT_WITH_DEFAULT_SETTINGS) {\r
         Next = Current + (Current >> 2);\r
-      } else if (!MemoryTypeInformationVariableExists) {\r
-        Next = MAX (Current + (Current >> 2), Previous);\r
       }\r
     } else if (Current > Previous) {\r
       Next = Current + (Current >> 2);\r
@@ -1422,19 +1422,23 @@ BdsSetMemoryTypeInformationVariable (
     Status = gRT->SetVariable (\r
                     EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,\r
                     &gEfiMemoryTypeInformationGuid,\r
-                    EFI_VARIABLE_NON_VOLATILE  | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+                    EFI_VARIABLE_NON_VOLATILE  | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
                     VariableSize,\r
                     PreviousMemoryTypeInformation\r
                     );\r
 \r
-    //\r
-    // If the Memory Type Information settings have been modified, then reset the platform\r
-    // so the new Memory Type Information setting will be used to guarantee that an S4\r
-    // entry/resume cycle will not fail.\r
-    //\r
-    if (MemoryTypeInformationModified && PcdGetBool (PcdResetOnMemoryTypeInformationChange)) {\r
-      DEBUG ((EFI_D_INFO, "Memory Type Information settings change. Warm Reset!!!\n"));\r
-      gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);\r
+    if (!EFI_ERROR (Status)) {\r
+      //\r
+      // If the Memory Type Information settings have been modified, then reset the platform\r
+      // so the new Memory Type Information setting will be used to guarantee that an S4\r
+      // entry/resume cycle will not fail.\r
+      //\r
+      if (MemoryTypeInformationModified && PcdGetBool (PcdResetOnMemoryTypeInformationChange)) {\r
+        DEBUG ((EFI_D_INFO, "Memory Type Information settings change. Warm Reset!!!\n"));\r
+        gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);\r
+      }\r
+    } else {\r
+      DEBUG ((EFI_D_ERROR, "Memory Type Information settings cannot be saved. OS S4 may fail!\n"));\r
     }\r
   }\r
 }\r