UINT32 Current;\r
UINT32 Next;\r
EFI_HOB_GUID_TYPE *GuidHob;\r
-\r
- UpdateRequired = FALSE;\r
+ BOOLEAN MemoryTypeInformationVariableExists;\r
+\r
+ UpdateRequired = TRUE;\r
+ MemoryTypeInformationVariableExists = FALSE;\r
+\r
+ if (GetBootModeHob () != BOOT_WITH_DEFAULT_SETTINGS) {\r
+ VariableSize = 0;\r
+ Status = gRT->GetVariable (\r
+ EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,\r
+ &gEfiMemoryTypeInformationGuid,\r
+ NULL, \r
+ &VariableSize, \r
+ NULL\r
+ );\r
+ if (Status == EFI_BUFFER_TOO_SMALL) {\r
+ MemoryTypeInformationVariableExists = TRUE;\r
+ UpdateRequired = FALSE;\r
+ }\r
+ }\r
\r
//\r
// Retrieve the current memory usage statistics. If they are not found, then\r
//\r
// Use a heuristic to adjust the Memory Type Information for the next boot\r
//\r
+ DEBUG ((EFI_D_INFO, "Memory Previous Current Next \n"));\r
+ DEBUG ((EFI_D_INFO, " Type Pages Pages Pages \n"));\r
+ DEBUG ((EFI_D_INFO, "====== ======== ======== ========\n"));\r
+\r
for (Index = 0; PreviousMemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) {\r
\r
Current = 0;\r
//\r
// Write next varible to 125% * current and Inconsistent Memory Reserved across bootings may lead to S4 fail\r
//\r
- if (Current > Previous) {\r
+ if (!MemoryTypeInformationVariableExists && Current < Previous) {\r
+ Next = Current + (Current >> 2);\r
+ } else if (Current > Previous) {\r
Next = Current + (Current >> 2);\r
} else {\r
Next = Previous;\r
UpdateRequired = TRUE;\r
}\r
\r
+ DEBUG ((EFI_D_INFO, " %02x %08x %08x %08x\n", PreviousMemoryTypeInformation[Index].Type, Previous, Current, Next));\r
}\r
\r
//\r
// If any changes were made to the Memory Type Information settings, then set the new variable value\r
//\r
- if (UpdateRequired) {\r
+ if (UpdateRequired || !MemoryTypeInformationVariableExists) {\r
Status = gRT->SetVariable (\r
EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,\r
&gEfiMemoryTypeInformationGuid,\r
PreviousMemoryTypeInformation\r
);\r
}\r
-\r
- return;\r
}\r
\r
/**\r
if (EFI_ERROR (Status)) {\r
DEBUG ((DEBUG_ERROR,"Bds Set Memory Type Informationa Variable Fails\n"));\r
}\r
-\r
}\r
\r
\r