EFI_MEMORY_TYPE_INFORMATION *PreviousMemoryTypeInformation;\r
EFI_MEMORY_TYPE_INFORMATION *CurrentMemoryTypeInformation;\r
UINTN VariableSize;\r
- BOOLEAN UpdateRequired;\r
UINTN Index;\r
UINTN Index1;\r
UINT32 Previous;\r
UINT32 Current;\r
UINT32 Next;\r
EFI_HOB_GUID_TYPE *GuidHob;\r
+ BOOLEAN MemoryTypeInformationModified;\r
BOOLEAN MemoryTypeInformationVariableExists;\r
\r
- UpdateRequired = TRUE;\r
+ MemoryTypeInformationModified = FALSE;\r
MemoryTypeInformationVariableExists = FALSE;\r
\r
+ //\r
+ // Only get 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
if (GetBootModeHob () != BOOT_WITH_DEFAULT_SETTINGS) {\r
VariableSize = 0;\r
Status = gRT->GetVariable (\r
);\r
if (Status == EFI_BUFFER_TOO_SMALL) {\r
MemoryTypeInformationVariableExists = TRUE;\r
- UpdateRequired = FALSE;\r
}\r
}\r
\r
\r
if (Next != Previous) {\r
PreviousMemoryTypeInformation[Index].NumberOfPages = Next;\r
- UpdateRequired = TRUE;\r
+ MemoryTypeInformationModified = 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
+ // If any changes were made to the Memory Type Information settings, then set the new variable value;\r
+ // Or create the variable in first boot.\r
//\r
- if (UpdateRequired || !MemoryTypeInformationVariableExists) {\r
+ if (MemoryTypeInformationModified || !MemoryTypeInformationVariableExists) {\r
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
- VariableSize,\r
- PreviousMemoryTypeInformation\r
- );\r
+ EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,\r
+ &gEfiMemoryTypeInformationGuid,\r
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_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) {\r
+ DEBUG ((EFI_D_ERROR, "Memory Type Information settings change. Warm Reset!!!\n"));\r
+ gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);\r
+ }\r
}\r
}\r
\r