This is a fork of the ARM PlatformPeiLib for SbsaQemu platform.The main purpose of having this specific implementation is that it allows us to pass DTB to DXE via HOB.
Signed-off-by: Xiong Yining xiongyining1480@phytium.com.cn Signed-off-by: Chen Baozi chenbaozi@phytium.com.cn --- Platform/Qemu/SbsaQemu/SbsaQemu.dsc | 2 +- .../Library/PlatformPeiLib/PlatformPeiLib.c | 63 +++++++++++++++++++ .../Library/PlatformPeiLib/PlatformPeiLib.inf | 41 ++++++++++++ 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 Silicon/Qemu/SbsaQemu/Library/PlatformPeiLib/PlatformPeiLib.c create mode 100644 Silicon/Qemu/SbsaQemu/Library/PlatformPeiLib/PlatformPeiLib.inf
diff --git a/Platform/Qemu/SbsaQemu/SbsaQemu.dsc b/Platform/Qemu/SbsaQemu/SbsaQemu.dsc index 10c61d0eb6..fcbeb24c97 100644 --- a/Platform/Qemu/SbsaQemu/SbsaQemu.dsc +++ b/Platform/Qemu/SbsaQemu/SbsaQemu.dsc @@ -115,7 +115,7 @@ DEFINE NETWORK_HTTP_BOOT_ENABLE = FALSE ArmHvcLib|ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf ArmGenericTimerCounterLib|ArmPkg/Library/ArmGenericTimerVirtCounterLib/ArmGenericTimerVirtCounterLib.inf
- PlatformPeiLib|ArmPlatformPkg/PlatformPei/PlatformPeiLib.inf + PlatformPeiLib|Silicon/Qemu/SbsaQemu/Library/PlatformPeiLib/PlatformPeiLib.inf MemoryInitPeiLib|ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.inf ResetSystemLib|ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.inf
diff --git a/Silicon/Qemu/SbsaQemu/Library/PlatformPeiLib/PlatformPeiLib.c b/Silicon/Qemu/SbsaQemu/Library/PlatformPeiLib/PlatformPeiLib.c new file mode 100644 index 0000000000..66de307e73 --- /dev/null +++ b/Silicon/Qemu/SbsaQemu/Library/PlatformPeiLib/PlatformPeiLib.c @@ -0,0 +1,63 @@ +/** @file + SbsaQemu PlatformPeiLib library. + + Copyright (c) 2023, Phytium. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include <PiPei.h> +#include <Guid/FdtHob.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/DebugLib.h> +#include <Library/HobLib.h> +#include <Library/PcdLib.h> +#include <libfdt.h> + +/** Initialise Platform HOBs + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_OUT_OF_RESOURCES Out of resources. +**/ +EFI_STATUS +EFIAPI +PlatformPeim ( + VOID + ) +{ + VOID *Base; + VOID *NewBase; + UINTN FdtSize; + UINTN FdtPages; + UINT64 *FdtHobData; + + Base = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeBaseAddress); + if ((Base == NULL) || (fdt_check_header (Base) != 0)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + FdtSize = fdt_totalsize (Base); + FdtPages = EFI_SIZE_TO_PAGES (FdtSize); + NewBase = AllocatePages (FdtPages); + if (NewBase == NULL) { + ASSERT (0); + return EFI_OUT_OF_RESOURCES; + } + + fdt_open_into (Base, NewBase, EFI_PAGES_TO_SIZE (FdtPages)); + + FdtHobData = BuildGuidHob (&gFdtHobGuid, sizeof (*FdtHobData)); + if (FdtHobData == NULL) { + ASSERT (0); + return EFI_OUT_OF_RESOURCES; + } + + *FdtHobData = (UINTN)NewBase; + + BuildFvHob (FixedPcdGet64 (PcdFvBaseAddress), FixedPcdGet32 (PcdFvSize)); + + return EFI_SUCCESS; +} diff --git a/Silicon/Qemu/SbsaQemu/Library/PlatformPeiLib/PlatformPeiLib.inf b/Silicon/Qemu/SbsaQemu/Library/PlatformPeiLib/PlatformPeiLib.inf new file mode 100644 index 0000000000..ac594b423a --- /dev/null +++ b/Silicon/Qemu/SbsaQemu/Library/PlatformPeiLib/PlatformPeiLib.inf @@ -0,0 +1,41 @@ +#/** @file +# +# Copyright (c) 2023, Linaro Ltd. All rights reserved. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = PlatformPeiLib + FILE_GUID = 75781B6E-A547-0BB7-0AEF-EFBFD7D8F609 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = PlatformPeiLib + +[Sources] + PlatformPeiLib.c + +[Packages] + ArmPkg/ArmPkg.dec + Silicon/Qemu/SbsaQemu/SbsaQemu.dec + EmbeddedPkg/EmbeddedPkg.dec + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + DebugLib + HobLib + FdtLib + +[FixedPcd] + gArmTokenSpaceGuid.PcdFvSize + gArmTokenSpaceGuid.PcdFvBaseAddress + gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdDeviceTreeBaseAddress + +[Guids] + gFdtHobGuid + +[Depex] + gEfiPeiMemoryDiscoveredPpiGuid