From 6310b11b41500cb796246d4504fcb1dc0bc3ba2e Mon Sep 17 00:00:00 2001 From: Kun Qin Date: Tue, 4 Nov 2025 12:07:27 -0800 Subject: [PATCH] ArmPlatformPkg: MemoryInitPeiLib: Read PCDs into local variable Current MemoryPeim has excessive amount of PCD get notations. This makes the code less readable and introduced long if statements. This change reads most of the PCD get calls into local variables and reference the variables instead. Signed-off-by: Kun Qin --- .../MemoryInitPei/MemoryInitPeiLib.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c index d7afccfb85..d6a6ffe766 100644 --- a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c +++ b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c @@ -66,6 +66,7 @@ MemoryPeim ( UINT64 ResourceLength; EFI_PEI_HOB_POINTERS NextHob; EFI_PHYSICAL_ADDRESS FdTop; + EFI_PHYSICAL_ADDRESS SystemMemoryBase; EFI_PHYSICAL_ADDRESS SystemMemoryTop; EFI_PHYSICAL_ADDRESS ResourceTop; BOOLEAN Found; @@ -88,6 +89,12 @@ MemoryPeim ( EFI_RESOURCE_ATTRIBUTE_TESTED ); + // + // Use local variable to avoid multiple PcdGet64 calls + // + SystemMemoryBase = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdSystemMemoryBase); + SystemMemoryTop = SystemMemoryBase + (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdSystemMemorySize); + // // Check if the resource for the main system memory has been declared // @@ -95,8 +102,8 @@ MemoryPeim ( NextHob.Raw = GetHobList (); while ((NextHob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) { if ((NextHob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) && - (PcdGet64 (PcdSystemMemoryBase) >= NextHob.ResourceDescriptor->PhysicalStart) && - (NextHob.ResourceDescriptor->PhysicalStart + NextHob.ResourceDescriptor->ResourceLength <= PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize))) + (SystemMemoryBase >= NextHob.ResourceDescriptor->PhysicalStart) && + (NextHob.ResourceDescriptor->PhysicalStart + NextHob.ResourceDescriptor->ResourceLength <= SystemMemoryTop)) { Found = TRUE; break; @@ -110,7 +117,7 @@ MemoryPeim ( BuildResourceDescriptorHob ( EFI_RESOURCE_SYSTEM_MEMORY, ResourceAttributes, - PcdGet64 (PcdSystemMemoryBase), + SystemMemoryBase, PcdGet64 (PcdSystemMemorySize) ); } @@ -119,13 +126,12 @@ MemoryPeim ( // Reserved the memory space occupied by the firmware volume // - SystemMemoryTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdSystemMemoryBase) + (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdSystemMemorySize); - FdTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFdBaseAddress) + (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFdSize); + FdTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFdBaseAddress) + (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFdSize); // EDK2 does not have the concept of boot firmware copied into DRAM. To avoid the DXE // core to overwrite this area we must create a memory allocation HOB for the region, // but this only works if we split off the underlying resource descriptor as well. - if ((PcdGet64 (PcdFdBaseAddress) >= PcdGet64 (PcdSystemMemoryBase)) && (FdTop <= SystemMemoryTop)) { + if ((PcdGet64 (PcdFdBaseAddress) >= SystemMemoryBase) && (FdTop <= SystemMemoryTop)) { Found = FALSE; // Search for System Memory Hob that contains the firmware