\r
#include "PiSmmCorePrivateData.h"\r
\r
+#define SMRAM_CAPABILITIES (EFI_MEMORY_WB | EFI_MEMORY_UC)\r
+\r
+#define MEMORY_CACHE_ATTRIBUTES (EFI_MEMORY_UC | EFI_MEMORY_WC | \\r
+ EFI_MEMORY_WT | EFI_MEMORY_WB | \\r
+ EFI_MEMORY_WP | EFI_MEMORY_UCE)\r
+\r
+#define MEMORY_PAGE_ATTRIBUTES (EFI_MEMORY_XP | EFI_MEMORY_RP | EFI_MEMORY_RO)\r
+\r
//\r
// Function prototypes from produced protocols\r
//\r
\r
GetSmramCacheRange (mCurrentSmramRange, &mSmramCacheBase, &mSmramCacheSize);\r
//\r
+ // Make sure we can change the desired memory attributes.\r
+ //\r
+ Status = gDS->GetMemorySpaceDescriptor (\r
+ mSmramCacheBase,\r
+ &MemDesc\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+ if ((MemDesc.Capabilities & SMRAM_CAPABILITIES) != SMRAM_CAPABILITIES) {\r
+ gDS->SetMemorySpaceCapabilities (\r
+ mSmramCacheBase,\r
+ mSmramCacheSize,\r
+ MemDesc.Capabilities | SMRAM_CAPABILITIES\r
+ );\r
+ }\r
+ //\r
// If CPU AP is present, attempt to set SMRAM cacheability to WB and clear\r
- // XP if it's set.\r
+ // all paging attributes.\r
// Note that it is expected that cacheability of SMRAM has been set to WB if CPU AP\r
// is not available here.\r
//\r
CpuArch = NULL;\r
Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&CpuArch);\r
if (!EFI_ERROR (Status)) {\r
- Status = gDS->SetMemorySpaceAttributes(\r
- mSmramCacheBase, \r
+ MemDesc.Attributes &= ~(MEMORY_CACHE_ATTRIBUTES | MEMORY_PAGE_ATTRIBUTES);\r
+ MemDesc.Attributes |= EFI_MEMORY_WB;\r
+ Status = gDS->SetMemorySpaceAttributes (\r
+ mSmramCacheBase,\r
mSmramCacheSize,\r
- EFI_MEMORY_WB\r
+ MemDesc.Attributes\r
);\r
if (EFI_ERROR (Status)) {\r
DEBUG ((DEBUG_WARN, "SMM IPL failed to set SMRAM window to EFI_MEMORY_WB\n"));\r
}\r
\r
- Status = gDS->GetMemorySpaceDescriptor(\r
- mCurrentSmramRange->PhysicalStart,\r
- &MemDesc\r
- );\r
- if (!EFI_ERROR (Status) && (MemDesc.Attributes & EFI_MEMORY_XP) != 0) {\r
- gDS->SetMemorySpaceAttributes (\r
- mCurrentSmramRange->PhysicalStart,\r
- mCurrentSmramRange->PhysicalSize,\r
- MemDesc.Attributes & (~EFI_MEMORY_XP)\r
+ DEBUG_CODE (\r
+ gDS->GetMemorySpaceDescriptor (\r
+ mSmramCacheBase,\r
+ &MemDesc\r
);\r
- }\r
+ DEBUG ((DEBUG_INFO, "SMRAM attributes: %016lx\n", MemDesc.Attributes));\r
+ ASSERT ((MemDesc.Attributes & MEMORY_PAGE_ATTRIBUTES) == 0);\r
+ );\r
}\r
//\r
// if Loading module at Fixed Address feature is enabled, save the SMRAM base to Load\r