From: Pankaj Bansal <pankaj.ban...@nxp.com> Add PEI phase to LS1043aRdb. This is needed because we need to have dynamic PCDs support to be able to reserve memory before reporting memory to UEFI firmware. Using PEI phase we are now also dynamically setting the PcdSystemMemoryBase and PcdSystemMemorySize depending upon the DRAM regions detected. This in turn would depend on the DDR DIMMs installed on board.
Signed-off-by: Pankaj Bansal <pankaj.ban...@nxp.com> --- Notes: V4: - Use ArmPkg version of PeiServicesTablePointerLib instead of MdePkg. This allows us to run PEI phase from memory mapped flash devices V3: - Update commit description Silicon/NXP/NxpQoriqLs.dsc.inc | 63 +++++++++++++----- Platform/NXP/LS1043aRdbPkg/LS1043aRdbPkg.dsc | 9 --- Platform/NXP/LS1043aRdbPkg/LS1043aRdbPkg.fdf | 18 ++++-- Silicon/NXP/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf | 3 +- Silicon/NXP/Library/MemoryInitPeiLib/MemoryInitPeiLib.c | 67 +++++++++++--------- 5 files changed, 99 insertions(+), 61 deletions(-) diff --git a/Silicon/NXP/NxpQoriqLs.dsc.inc b/Silicon/NXP/NxpQoriqLs.dsc.inc index 3c8b11d9e04c..03759c7cee7c 100644 --- a/Silicon/NXP/NxpQoriqLs.dsc.inc +++ b/Silicon/NXP/NxpQoriqLs.dsc.inc @@ -93,46 +93,53 @@ CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf NonDiscoverableDeviceRegistrationLib|MdeModulePkg/Library/NonDiscoverableDeviceRegistrationLib/NonDiscoverableDeviceRegistrationLib.inf ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf + UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf I2cLib|Silicon/NXP/Library/I2cLib/I2cLib.inf ResetSystemLib|ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.inf IoAccessLib|Silicon/NXP/Library/IoAccessLib/IoAccessLib.inf + PlatformPeiLib|ArmPlatformPkg/PlatformPei/PlatformPeiLib.inf MemoryInitPeiLib|Silicon/NXP/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf [LibraryClasses.common.SEC] PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf - UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf - ExtractGuidedSectionLib|EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.inf - LzmaDecompressLib|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf - PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf - HobLib|EmbeddedPkg/Library/PrePiHobLib/PrePiHobLib.inf - PrePiHobListPointerLib|ArmPlatformPkg/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf - MemoryAllocationLib|EmbeddedPkg/Library/PrePiMemoryAllocationLib/PrePiMemoryAllocationLib.inf + DebugAgentLib|ArmPkg/Library/DebugAgentSymbolsBaseLib/DebugAgentSymbolsBaseLib.inf + HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf + PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf + PeiServicesTablePointerLib|ArmPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf + MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf + +[LibraryClasses.common.PEI_CORE] + PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf + HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf + PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf + MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf + PeiCoreEntryPoint|MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.inf PerformanceLib|MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf - PlatformPeiLib|ArmPlatformPkg/PlatformPei/PlatformPeiLib.inf + ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf + ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf + OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf - # 1/123 faster than Stm or Vstm version - BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf - - # Uncomment to turn on GDB stub in SEC. - #DebugAgentLib|EmbeddedPkg/Library/GdbDebugAgent/GdbDebugAgent.inf + PeiServicesTablePointerLib|ArmPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf [LibraryClasses.common.PEIM] PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf - PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf + PeiServicesTablePointerLib|ArmPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf + PerformanceLib|MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf + ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf + OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf [LibraryClasses.common.DXE_CORE] HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf MemoryAllocationLib|MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.inf DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf - UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf PerformanceLib|MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.inf @@ -204,6 +211,9 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoHorizontalResolution|640 gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoVerticalResolution|480 + gArmTokenSpaceGuid.PcdSystemMemoryBase|0 + gArmTokenSpaceGuid.PcdSystemMemorySize|0 + [PcdsDynamicHii.common.DEFAULT] gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut|L"Timeout"|gEfiGlobalVariableGuid|0x0|10 @@ -224,6 +234,12 @@ gEfiMdePkgTokenSpaceGuid.PcdPostCodePropertyMask|0 gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|320 + ## Base of DRAM + ## since TFA puts Fd at 0x2000000 offset from DRAM base, we can use this space + ## for temporary ram + gArmPlatformTokenSpaceGuid.PcdCPUCoresStackBase|0x80000000 + gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x02000000 + !if $(TARGET) == RELEASE gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x27 gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x81000001 @@ -281,13 +297,26 @@ ################################################################################ [Components.common] # - # SEC + # PEI Phase modules # - ArmPlatformPkg/PrePi/PeiUniCore.inf + ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore.inf + + MdeModulePkg/Core/Pei/PeiMain.inf MdeModulePkg/Universal/PCD/Pei/Pcd.inf { <LibraryClasses> PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf } + MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.inf + MdeModulePkg/Universal/Variable/Pei/VariablePei.inf + + ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf + ArmPkg/Drivers/CpuPei/CpuPei.inf + ArmPlatformPkg/PlatformPei/PlatformPeim.inf + + MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf { + <LibraryClasses> + NULL|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf + } # # DXE diff --git a/Platform/NXP/LS1043aRdbPkg/LS1043aRdbPkg.dsc b/Platform/NXP/LS1043aRdbPkg/LS1043aRdbPkg.dsc index d486c9b36fab..d45fd67c03b5 100644 --- a/Platform/NXP/LS1043aRdbPkg/LS1043aRdbPkg.dsc +++ b/Platform/NXP/LS1043aRdbPkg/LS1043aRdbPkg.dsc @@ -30,15 +30,6 @@ RealTimeClockLib|Silicon/Maxim/Library/Ds1307RtcLib/Ds1307RtcLib.inf [PcdsFixedAtBuild.common] - - # - # LS1043a board Specific PCDs - # XX (DRAM - Region 1 2GB) - # (NOR - IFC Region 1 512MB) - gArmTokenSpaceGuid.PcdSystemMemoryBase|0x80000000 - gArmTokenSpaceGuid.PcdSystemMemorySize|0x7BE00000 - gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x02000000 - # # RTC Pcds # diff --git a/Platform/NXP/LS1043aRdbPkg/LS1043aRdbPkg.fdf b/Platform/NXP/LS1043aRdbPkg/LS1043aRdbPkg.fdf index 99fbc87e1200..931d0bb14f9b 100644 --- a/Platform/NXP/LS1043aRdbPkg/LS1043aRdbPkg.fdf +++ b/Platform/NXP/LS1043aRdbPkg/LS1043aRdbPkg.fdf @@ -24,10 +24,10 @@ [FD.LS1043ARDB_EFI] BaseAddress = 0x82000000|gArmTokenSpaceGuid.PcdFdBaseAddress #The base address of the FLASH Device. -Size = 0x000ED000|gArmTokenSpaceGuid.PcdFdSize #The size in bytes of the FLASH Device +Size = 0x00140000|gArmTokenSpaceGuid.PcdFdSize #The size in bytes of the FLASH Device ErasePolarity = 1 -BlockSize = 0x1 -NumBlocks = 0xED000 +BlockSize = 0x40000 +NumBlocks = 0x5 ################################################################################ # @@ -44,7 +44,7 @@ NumBlocks = 0xED000 # RegionType <FV, DATA, or FILE> # ################################################################################ -0x00000000|0x000ED000 +0x00000000|0x00140000 gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize FV = FVMAIN_COMPACT @@ -159,7 +159,15 @@ READ_STATUS = TRUE READ_LOCK_CAP = TRUE READ_LOCK_STATUS = TRUE - INF ArmPlatformPkg/PrePi/PeiUniCore.inf + INF ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore.inf + INF MdeModulePkg/Core/Pei/PeiMain.inf + INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf + INF MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.inf + INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf + INF ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf + INF ArmPkg/Drivers/CpuPei/CpuPei.inf + INF ArmPlatformPkg/PlatformPei/PlatformPeim.inf + INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 { SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE { diff --git a/Silicon/NXP/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf b/Silicon/NXP/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf index ad2371115b17..a33f8cd3f743 100644 --- a/Silicon/NXP/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf +++ b/Silicon/NXP/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf @@ -13,7 +13,8 @@ FILE_GUID = 55ddb6e0-70b5-11e0-b33e-0002a5d5c51b MODULE_TYPE = BASE VERSION_STRING = 1.0 - LIBRARY_CLASS = MemoryInitPeiLib|SEC PEIM DXE_DRIVER + LIBRARY_CLASS = MemoryInitPeiLib|PEIM + CONSTRUCTOR = MemoryInitPeiLibConstructor [Sources] MemoryInitPeiLib.c diff --git a/Silicon/NXP/Library/MemoryInitPeiLib/MemoryInitPeiLib.c b/Silicon/NXP/Library/MemoryInitPeiLib/MemoryInitPeiLib.c index 905d326893e5..5599239ede4a 100644 --- a/Silicon/NXP/Library/MemoryInitPeiLib/MemoryInitPeiLib.c +++ b/Silicon/NXP/Library/MemoryInitPeiLib/MemoryInitPeiLib.c @@ -120,22 +120,17 @@ GetDramRegionsInfo ( /** Get the installed RAM information. - Initialize MMU and Memory HOBs (Resource Descriptor HOBs) + Initialize Memory HOBs (Resource Descriptor HOBs) + Set the PcdSystemMemoryBase and PcdSystemMemorySize. - @param[in] UefiMemoryBase Base address of region used by UEFI in - permanent memory - @param[in] UefiMemorySize Size of the region used by UEFI in permanent memory - - @return EFI_SUCCESS Successfuly Initialize MMU and Memory HOBs. + @return EFI_SUCCESS Successfuly retrieved the system memory information **/ EFI_STATUS EFIAPI -MemoryPeim ( - IN EFI_PHYSICAL_ADDRESS UefiMemoryBase, - IN UINT64 UefiMemorySize +MemoryInitPeiLibConstructor ( + VOID ) { - ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable; INT32 Index; UINTN BaseAddress; UINTN Size; @@ -147,18 +142,6 @@ MemoryPeim ( BOOLEAN FoundSystemMem; EFI_STATUS Status; - // Get Virtual Memory Map from the Platform Library - ArmPlatformGetVirtualMemoryMap (&MemoryTable); - - // - // Ensure MemoryTable[0].Length which is size of DRAM has been set - // by ArmPlatformGetVirtualMemoryMap () - // - ASSERT (MemoryTable[0].Length != 0); - - // - // Now, the permanent memory has been installed, we can call AllocatePages() - // ResourceAttributes = ( EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | @@ -174,8 +157,8 @@ MemoryPeim ( Status = GetDramRegionsInfo (DramRegions, ARRAY_SIZE (DramRegions)); ASSERT_EFI_ERROR (Status); - FdBase = (UINTN)FixedPcdGet64 (PcdFdBaseAddress); - FdTop = FdBase + (UINTN)FixedPcdGet32 (PcdFdSize); + FdBase = (UINTN)PcdGet64 (PcdFdBaseAddress); + FdTop = FdBase + (UINTN)PcdGet32 (PcdFdSize); // Declare memory regions to system // The DRAM region info is sorted based on the RAM address is SOC memory map. @@ -228,8 +211,8 @@ MemoryPeim ( ); }; // Mark the memory covering the Firmware Device as boot services data - BuildMemoryAllocationHob (FixedPcdGet64 (PcdFdBaseAddress), - FixedPcdGet32 (PcdFdSize), + BuildMemoryAllocationHob (PcdGet64 (PcdFdBaseAddress), + PcdGet32 (PcdFdSize), EfiBootServicesData); } else { BuildResourceDescriptorHob ( @@ -247,17 +230,43 @@ MemoryPeim ( Size = DramRegions[Index].Size; if (FdBase >= BaseAddress && FdTop <= Top) { - Size -= (UINTN)FixedPcdGet32 (PcdFdSize); + Size -= (UINTN)PcdGet32 (PcdFdSize); } - if ((UefiMemoryBase >= BaseAddress) && (Size >= UefiMemorySize)) { + if (Size >= FixedPcdGet32 (PcdSystemMemoryUefiRegionSize)) { FoundSystemMem = TRUE; + PcdSet64S (PcdSystemMemoryBase, BaseAddress); + PcdSet64S (PcdSystemMemorySize, Size); } } ASSERT (FoundSystemMem == TRUE); - // Build Memory Allocation Hob + return EFI_SUCCESS; +} + +/** + Initialize MMU + + @param[in] UefiMemoryBase Base address of region used by UEFI in + permanent memory + @param[in] UefiMemorySize Size of the region used by UEFI in permanent memory + + @return EFI_SUCCESS Successfuly Initialize MMU +**/ +EFI_STATUS +EFIAPI +MemoryPeim ( + IN EFI_PHYSICAL_ADDRESS UefiMemoryBase, + IN UINT64 UefiMemorySize + ) +{ + ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable; + + // Get Virtual Memory Map from the Platform Library + ArmPlatformGetVirtualMemoryMap (&MemoryTable); + + // Initialize Mmu InitMmu (MemoryTable); if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob)) { -- 2.17.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#58391): https://edk2.groups.io/g/devel/message/58391 Mute This Topic: https://groups.io/mt/73370147/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-