X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=OvmfPkg%2FPlatformPei%2FMemDetect.c;h=bd7bb0227d8c338173780a41bc8ce3db163cfa1d;hb=c404616199df383226df1b70940008c01cfaec81;hp=11c79687c435da5fcccaa962660b5119540aba39;hpb=8e54500fd48b56d8cf660c18656e10fe89ee3af7;p=mirror_edk2.git diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c index 11c79687c4..bd7bb0227d 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -24,6 +24,7 @@ Module Name: // // The Library classes this module consumes // +#include #include #include #include @@ -55,7 +56,7 @@ GetSystemMemorySizeBelow4gb ( Cmos0x34 = (UINT8) CmosRead8 (0x34); Cmos0x35 = (UINT8) CmosRead8 (0x35); - return (((UINTN)((Cmos0x35 << 8) + Cmos0x34) << 16) + SIZE_16MB); + return (UINT32) (((UINTN)((Cmos0x35 << 8) + Cmos0x34) << 16) + SIZE_16MB); } @@ -147,18 +148,22 @@ QemuInitializeRam ( LowerMemorySize = GetSystemMemorySizeBelow4gb (); UpperMemorySize = GetSystemMemorySizeAbove4gb (); - // - // Create memory HOBs - // - AddMemoryRangeHob (BASE_1MB, LowerMemorySize); - AddMemoryRangeHob (0, BASE_512KB + BASE_128KB); + if (mBootMode != BOOT_ON_S3_RESUME) { + // + // Create memory HOBs + // + AddMemoryRangeHob (BASE_1MB, LowerMemorySize); + AddMemoryRangeHob (0, BASE_512KB + BASE_128KB); + } MtrrSetMemoryAttribute (BASE_1MB, LowerMemorySize - BASE_1MB, CacheWriteBack); MtrrSetMemoryAttribute (0, BASE_512KB + BASE_128KB, CacheWriteBack); if (UpperMemorySize != 0) { - AddUntestedMemoryBaseSizeHob (BASE_4GB, UpperMemorySize); + if (mBootMode != BOOT_ON_S3_RESUME) { + AddUntestedMemoryBaseSizeHob (BASE_4GB, UpperMemorySize); + } MtrrSetMemoryAttribute (BASE_4GB, UpperMemorySize, CacheWriteBack); } @@ -188,5 +193,61 @@ InitializeRamRegions ( (UINT64)(UINTN) PcdGet32 (PcdS3AcpiReservedMemorySize), EfiACPIMemoryNVS ); + + // + // Cover the initial RAM area used as stack and temporary PEI heap. + // + // This is reserved as ACPI NVS so it can be used on S3 resume. + // + BuildMemoryAllocationHob ( + PcdGet32 (PcdOvmfSecPeiTempRamBase), + PcdGet32 (PcdOvmfSecPeiTempRamSize), + EfiACPIMemoryNVS + ); + + // + // SEC stores its table of GUIDed section handlers here. + // + BuildMemoryAllocationHob ( + PcdGet64 (PcdGuidedExtractHandlerTableAddress), + PcdGet32 (PcdGuidedExtractHandlerTableSize), + EfiACPIMemoryNVS + ); + +#ifdef MDE_CPU_X64 + // + // Reserve the initial page tables built by the reset vector code. + // + // Since this memory range will be used by the Reset Vector on S3 + // resume, it must be reserved as ACPI NVS. + // + BuildMemoryAllocationHob ( + (EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfSecPageTablesBase), + (UINT64)(UINTN) PcdGet32 (PcdOvmfSecPageTablesSize), + EfiACPIMemoryNVS + ); +#endif + } + + if (mBootMode != BOOT_ON_S3_RESUME) { + // + // Reserve the lock box storage area + // + // Since this memory range will be used on S3 resume, it must be + // reserved as ACPI NVS. + // + // If S3 is unsupported, then various drivers might still write to the + // LockBox area. We ought to prevent DXE from serving allocation requests + // such that they would overlap the LockBox storage. + // + ZeroMem ( + (VOID*)(UINTN) PcdGet32 (PcdOvmfLockBoxStorageBase), + (UINTN) PcdGet32 (PcdOvmfLockBoxStorageSize) + ); + BuildMemoryAllocationHob ( + (EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfLockBoxStorageBase), + (UINT64)(UINTN) PcdGet32 (PcdOvmfLockBoxStorageSize), + mS3Supported ? EfiACPIMemoryNVS : EfiBootServicesData + ); } }