]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Enhance BDS to avoid the additional reset when the platform pre-allocated memory...
authorniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 6 Jul 2011 03:23:15 +0000 (03:23 +0000)
committerniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 6 Jul 2011 03:23:15 +0000 (03:23 +0000)
Signed-off-by: niruiyu
Reviewed-by: mdkinney
Reviewed-by: lgao4
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11983 6f19259b-4bc3-4df7-8a09-765794883524

IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c

index bd0a5f423724b65b450169bc4d2afc6efcb0ea9a..68ddfc334f3b87cc2c0c4b59a14952392d4a4976 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Misc BDS library function\r
 \r
-Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 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
@@ -1096,8 +1096,10 @@ BdsLibGetImageHeader (
 }\r
 \r
 /**\r
-  This routine adjust the memory information for different memory type and \r
-  save them into the variables for next boot.\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
 **/\r
 VOID\r
 BdsSetMemoryTypeInformationVariable (\r
@@ -1131,7 +1133,7 @@ BdsSetMemoryTypeInformationVariable (
   }\r
 \r
   //\r
-  // Only get the the Memory Type Information variable in the boot mode \r
+  // Only check the the Memory Type Information variable in the boot mode \r
   // other than BOOT_WITH_DEFAULT_SETTINGS because the Memory Type\r
   // Information is not valid in this boot mode.\r
   //\r
@@ -1185,29 +1187,34 @@ BdsSetMemoryTypeInformationVariable (
 \r
   for (Index = 0; PreviousMemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) {\r
 \r
-    Current = 0;\r
     for (Index1 = 0; CurrentMemoryTypeInformation[Index1].Type != EfiMaxMemoryType; Index1++) {\r
       if (PreviousMemoryTypeInformation[Index].Type == CurrentMemoryTypeInformation[Index1].Type) {\r
-        Current = CurrentMemoryTypeInformation[Index1].NumberOfPages;\r
         break;\r
       }\r
     }\r
-\r
     if (CurrentMemoryTypeInformation[Index1].Type == EfiMaxMemoryType) {\r
       continue;\r
     }\r
 \r
+    //\r
+    // Previous is the number of pages pre-allocated\r
+    // Current is the number of pages actually needed\r
+    //\r
     Previous = PreviousMemoryTypeInformation[Index].NumberOfPages;\r
+    Current  = CurrentMemoryTypeInformation[Index1].NumberOfPages;\r
+    Next     = Previous;\r
 \r
     //\r
     // Write next varible to 125% * current and Inconsistent Memory Reserved across bootings may lead to S4 fail\r
     //\r
-    if (!MemoryTypeInformationVariableExists && Current < Previous) {\r
-      Next = Current + (Current >> 2);\r
+    if (Current < 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
-    } else {\r
-      Next = Previous;\r
     }\r
     if (Next > 0 && Next < 4) {\r
       Next = 4;\r