X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=ArmPlatformPkg%2FMemoryInitPei%2FMemoryInitPeim.c;h=1de7d38078c506a5684d3f9bf19739a450782c41;hp=3a26c35998ef9dc8cf2f2e29175cdb51b0e8c306;hb=1e57a46299244793beb27e74be171d1540606999;hpb=3a6eaccf2f20b6fac1cdc6f82f041e78eb962e94 diff --git a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.c b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.c index 3a26c35998..1de7d38078 100755 --- a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.c +++ b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.c @@ -95,39 +95,55 @@ InitializeMemory ( ) { EFI_STATUS Status; - EFI_RESOURCE_ATTRIBUTE_TYPE Attributes; - ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR* EfiMemoryMap; - UINTN Index; + UINTN SystemMemoryBase; UINTN SystemMemoryTop; + UINTN FdBase; + UINTN FdTop; UINTN UefiMemoryBase; - UINTN UefiMemorySize; DEBUG ((EFI_D_ERROR, "Memory Init PEIM Loaded\n")); // Ensure PcdSystemMemorySize has been set ASSERT (FixedPcdGet32 (PcdSystemMemorySize) != 0); - SystemMemoryTop = (UINTN)FixedPcdGet32 (PcdSystemMemoryBase) + (UINTN)FixedPcdGet32 (PcdSystemMemorySize); + SystemMemoryBase = (UINTN)FixedPcdGet32 (PcdSystemMemoryBase); + SystemMemoryTop = SystemMemoryBase + (UINTN)FixedPcdGet32 (PcdSystemMemorySize); + FdBase = (UINTN)PcdGet32 (PcdFdBaseAddress); + FdTop = FdBase + (UINTN)PcdGet32 (PcdFdSize); // // Initialize the System Memory (DRAM) // - if (FeaturePcdGet(PcdStandalone)) { - // In case of a standalone version, the DRAM is already initialized - ArmPlatformInitializeSystemMemory(); + if (!FeaturePcdGet (PcdSystemMemoryInitializeInSec)) { + // In case the DRAM has not been initialized by the secure firmware + ArmPlatformInitializeSystemMemory (); } // // Declare the UEFI memory to PEI // - if (FeaturePcdGet(PcdStandalone)) { - // In case of standalone UEFI, we set the UEFI memory region at the top of the DRAM - UefiMemoryBase = SystemMemoryTop - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize); + + // In case the firmware has been shadowed in the System Memory + if ((FdBase >= SystemMemoryBase) && (FdTop <= SystemMemoryTop)) { + // Check if there is enough space between the top of the system memory and the top of the + // firmware to place the UEFI memory (for PEI & DXE phases) + if (SystemMemoryTop - FdTop >= FixedPcdGet32 (PcdSystemMemoryUefiRegionSize)) { + UefiMemoryBase = SystemMemoryTop - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize); + } else { + // Check there is enough space for the UEFI memory + ASSERT (SystemMemoryBase + FixedPcdGet32 (PcdSystemMemoryUefiRegionSize) <= FdBase); + + UefiMemoryBase = FdBase - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize); + } } else { - // In case of a non standalone UEFI, we set the UEFI memory below the Firmware Volume - UefiMemoryBase = FixedPcdGet32 (PcdNormalFdBaseAddress) - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize); + // Check the Firmware does not overlapped with the system memory + ASSERT ((FdBase < SystemMemoryBase) || (FdBase >= SystemMemoryTop)); + ASSERT ((FdTop <= SystemMemoryBase) || (FdTop > SystemMemoryTop)); + + UefiMemoryBase = SystemMemoryTop - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize); } - Status = PeiServicesInstallPeiMemory (UefiMemoryBase,FixedPcdGet32 (PcdSystemMemoryUefiRegionSize)); + + Status = PeiServicesInstallPeiMemory (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize)); ASSERT_EFI_ERROR (Status); // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)