diff --git a/ArmPlatformPkg/Include/Library/ArmPlatformLib.h b/ArmPlatformPkg/Include/Library/ArmPlatformLib.h index cd87743eba..1b58c31b16 100644 --- a/ArmPlatformPkg/Include/Library/ArmPlatformLib.h +++ b/ArmPlatformPkg/Include/Library/ArmPlatformLib.h @@ -136,4 +136,24 @@ ArmPlatformGetPlatformPpiList ( OUT EFI_PEI_PPI_DESCRIPTOR **PpiList ); +// MU_CHANGE START: Allow platform to customize initial memory region. + +/** + Checks if the platform requires a special initial EFI memory region. + + @param[out] EfiMemoryBase The custom memory base, will be unchanged if FALSE is returned. + @param[out] EfiMemorySize The custom memory size, will be unchanged if FALSE is returned. + + @retval TRUE A custom memory region was set. + @retval FALSE A custom memory region was not set. +**/ +BOOLEAN +EFIAPI +ArmPlatformGetPeiMemory ( + OUT UINTN *EfiMemoryBase, + OUT UINT32 *EfiMemorySize + ); + +// MU_CHANGE END + #endif diff --git a/ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibNullMem.c b/ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibNullMem.c index 7151c96625..4d123b91e5 100644 --- a/ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibNullMem.c +++ b/ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibNullMem.c @@ -26,3 +26,26 @@ ArmPlatformGetVirtualMemoryMap ( { ASSERT (0); } + +// MU_CHANGE START + +/** + Checks if the platform requires a special initial EFI memory region. + + @param[out] EfiMemoryBase The custom memory base, will be unchanged if FALSE is returned. + @param[out] EfiMemorySize The custom memory size, will be unchanged if FALSE is returned. + + @retval TRUE A custom memory region was set. + @retval FALSE A custom memory region was not set. +**/ +BOOLEAN +EFIAPI +ArmPlatformGetPeiMemory ( + OUT UINTN *EfiMemoryBase, + OUT UINT32 *EfiMemorySize + ) +{ + return FALSE; +} + +// MU_CHANGE END diff --git a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.c b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.c index bc8eb713ef..e1920ee324 100644 --- a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.c +++ b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.c @@ -89,6 +89,7 @@ InitializeMemory ( UINTN FdBase; UINTN FdTop; UINTN UefiMemoryBase; + UINT32 UefiMemorySize; // MU_CHANGE DEBUG ((DEBUG_LOAD | DEBUG_INFO, "Memory Init PEIM Loaded\n")); @@ -109,8 +110,16 @@ InitializeMemory ( // Declare the UEFI memory to PEI // - // In case the firmware has been shadowed in the System Memory - if ((FdBase >= SystemMemoryBase) && (FdTop <= SystemMemoryTop)) { + // MU_CHANGE START: Allow platform to customize initial memory region. + UefiMemorySize = FixedPcdGet32 (PcdSystemMemoryUefiRegionSize); + if (ArmPlatformGetPeiMemory (&UefiMemoryBase, &UefiMemorySize)) { + // Check the Firmware does not intersect with the provided memory region. + ASSERT ((FdBase < UefiMemoryBase) || (FdBase >= (UefiMemoryBase + UefiMemorySize))); + ASSERT ((FdTop <= UefiMemoryBase) || (FdTop > (UefiMemoryBase + UefiMemorySize))); + } else if ((FdBase >= SystemMemoryBase) && (FdTop <= SystemMemoryTop)) { + // In case the firmware has been shadowed in the System Memory + // MU_CHANGE END + // 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)) { @@ -129,7 +138,7 @@ InitializeMemory ( UefiMemoryBase = SystemMemoryTop - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize); } - Status = PeiServicesInstallPeiMemory (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize)); + Status = PeiServicesInstallPeiMemory (UefiMemoryBase, UefiMemorySize); // MU_CHANGE: Allow platform to customize initial memory region. ASSERT_EFI_ERROR (Status); // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)