MemorySize = PcdGet32 (PcdS3AcpiReservedMemorySize);\r
} else {\r
LowerMemorySize = GetSystemMemorySizeBelow4gb ();\r
+ if (FeaturePcdGet (PcdSmmSmramRequire)) {\r
+ //\r
+ // TSEG is chipped from the end of low RAM\r
+ //\r
+ LowerMemorySize -= FixedPcdGet8 (PcdQ35TsegMbytes) * SIZE_1MB;\r
+ }\r
\r
PeiMemoryCap = GetPeiMemoryCap ();\r
DEBUG ((EFI_D_INFO, "%a: mPhysMemAddressWidth=%d PeiMemoryCap=%u KB\n",\r
//\r
// Determine the range of memory to use during PEI\r
//\r
- MemoryBase = PcdGet32 (PcdOvmfDxeMemFvBase) + PcdGet32 (PcdOvmfDxeMemFvSize);\r
+ // Technically we could lay the permanent PEI RAM over SEC's temporary\r
+ // decompression and scratch buffer even if "secure S3" is needed, since\r
+ // their lifetimes don't overlap. However, PeiFvInitialization() will cover\r
+ // RAM up to PcdOvmfDecompressionScratchEnd with an EfiACPIMemoryNVS memory\r
+ // allocation HOB, and other allocations served from the permanent PEI RAM\r
+ // shouldn't overlap with that HOB.\r
+ //\r
+ MemoryBase = mS3Supported && FeaturePcdGet (PcdSmmSmramRequire) ?\r
+ PcdGet32 (PcdOvmfDecompressionScratchEnd) :\r
+ PcdGet32 (PcdOvmfDxeMemFvBase) + PcdGet32 (PcdOvmfDxeMemFvSize);\r
MemorySize = LowerMemorySize - MemoryBase;\r
if (MemorySize > PeiMemoryCap) {\r
MemoryBase = LowerMemorySize - PeiMemoryCap;\r
// Create memory HOBs\r
//\r
AddMemoryRangeHob (0, BASE_512KB + BASE_128KB);\r
- AddMemoryRangeHob (BASE_1MB, LowerMemorySize);\r
+\r
+ if (FeaturePcdGet (PcdSmmSmramRequire)) {\r
+ UINT32 TsegSize;\r
+\r
+ TsegSize = FixedPcdGet8 (PcdQ35TsegMbytes) * SIZE_1MB;\r
+ AddMemoryRangeHob (BASE_1MB, LowerMemorySize - TsegSize);\r
+ AddReservedMemoryBaseSizeHob (LowerMemorySize - TsegSize, TsegSize,\r
+ TRUE);\r
+ } else {\r
+ AddMemoryRangeHob (BASE_1MB, LowerMemorySize);\r
+ }\r
+\r
if (UpperMemorySize != 0) {\r
AddUntestedMemoryBaseSizeHob (BASE_4GB, UpperMemorySize);\r
}\r
}\r
\r
if (mBootMode != BOOT_ON_S3_RESUME) {\r
- //\r
- // Reserve the lock box storage area\r
- //\r
- // Since this memory range will be used on S3 resume, it must be\r
- // reserved as ACPI NVS.\r
- //\r
- // If S3 is unsupported, then various drivers might still write to the\r
- // LockBox area. We ought to prevent DXE from serving allocation requests\r
- // such that they would overlap the LockBox storage.\r
- //\r
- ZeroMem (\r
- (VOID*)(UINTN) PcdGet32 (PcdOvmfLockBoxStorageBase),\r
- (UINTN) PcdGet32 (PcdOvmfLockBoxStorageSize)\r
- );\r
- BuildMemoryAllocationHob (\r
- (EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfLockBoxStorageBase),\r
- (UINT64)(UINTN) PcdGet32 (PcdOvmfLockBoxStorageSize),\r
- mS3Supported ? EfiACPIMemoryNVS : EfiBootServicesData\r
- );\r
+ if (!FeaturePcdGet (PcdSmmSmramRequire)) {\r
+ //\r
+ // Reserve the lock box storage area\r
+ //\r
+ // Since this memory range will be used on S3 resume, it must be\r
+ // reserved as ACPI NVS.\r
+ //\r
+ // If S3 is unsupported, then various drivers might still write to the\r
+ // LockBox area. We ought to prevent DXE from serving allocation requests\r
+ // such that they would overlap the LockBox storage.\r
+ //\r
+ ZeroMem (\r
+ (VOID*)(UINTN) PcdGet32 (PcdOvmfLockBoxStorageBase),\r
+ (UINTN) PcdGet32 (PcdOvmfLockBoxStorageSize)\r
+ );\r
+ BuildMemoryAllocationHob (\r
+ (EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfLockBoxStorageBase),\r
+ (UINT64)(UINTN) PcdGet32 (PcdOvmfLockBoxStorageSize),\r
+ mS3Supported ? EfiACPIMemoryNVS : EfiBootServicesData\r
+ );\r
+ }\r
+\r
+ if (FeaturePcdGet (PcdSmmSmramRequire)) {\r
+ UINT32 TsegSize;\r
+\r
+ //\r
+ // Make sure the TSEG area that we reported as a reserved memory resource\r
+ // cannot be used for reserved memory allocations.\r
+ //\r
+ TsegSize = FixedPcdGet8 (PcdQ35TsegMbytes) * SIZE_1MB;\r
+ BuildMemoryAllocationHob (\r
+ GetSystemMemorySizeBelow4gb() - TsegSize,\r
+ TsegSize,\r
+ EfiReservedMemoryType\r
+ );\r
+ }\r
}\r
}\r