From nobody Tue Feb 10 19:49:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+87208+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+87208+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1646210716; cv=none; d=zohomail.com; s=zohoarc; b=U5A1EvREtl5cwet+nTbK8im/mkS5SMfiOUFgmdHy6ai7duDeazwiG+J3WWIQWDnB7A9GzTiniUxVxvYGf2avJQkbk0d2jqoYardfwtZRIOBBXz+FS92wt3U05E4EwxnrtcmfpLyGkVenVtqZ4SmehDNUdkSzD1McJ+8ZtnjaD6A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646210716; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=xWkWsbVihpjs4KmwAasHv1Yl+0j0bs0EpLuyGlVwq/I=; b=lixZNJ+7dvcdghrWOpVMT/ivSQm60pPZAyh6gxROeY9jDBUlZDFRMLIPQsSO1MF4duZNIdKMheP2603CjMwbpFaum9f+GJVEf3nL4fs0RMmVxlwjBwQUfFlO1geLDPnA+QBpH6+xselt3GW+QsYLCQP/8kQkODS7CAiDDcg7aSo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+87208+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1646210716471197.1531561519481; Wed, 2 Mar 2022 00:45:16 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id Zqc9YY1788612xFMFAjVKBpO; Wed, 02 Mar 2022 00:45:15 -0800 X-Received: from loongson.cn (loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web08.5314.1646210697980169129 for ; Wed, 02 Mar 2022 00:45:10 -0800 X-Received: from localhost.localdomain (unknown [10.2.5.185]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dxn89_Lh9i7TkBAA--.6283S10; Wed, 02 Mar 2022 16:44:52 +0800 (CST) From: "xianglai" To: devel@edk2.groups.io Subject: [edk2-devel] [edk2-platforms][PATCH V1 08/15] Platform/Loongson: Support PEI phase. Date: Wed, 2 Mar 2022 03:44:40 -0500 Message-Id: <20220302084447.2991355-9-lixianglai@loongson.cn> In-Reply-To: <20220302084447.2991355-1-lixianglai@loongson.cn> References: <20220302084447.2991355-1-lixianglai@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf9Dxn89_Lh9i7TkBAA--.6283S10 X-Coremail-Antispam: 1UD129KBjvAXoWfAw1ktFy7Kw17JFWkXrWfGrg_yoW5Xr1kto W8JFyIkw4UGr1rXw1UG3ZrtrWIvF1Yva1Yqr1rZayUAFs0yr13tF98J3srGw15AFn8Awn8 G3yfGaykJFW2q3s5n29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7v73VFW2AGmfu7bjvjm3 AaLaJ3UjIYCTnIWjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRUUUUUUUUU= X-CM-SenderInfo: 5ol0xt5qjotxo6or00hjvr0hdfq/ Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lixianglai@loongson.cn X-Gm-Message-State: pez7GlbbrxIEyR4tq4IAYVKfx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1646210715; bh=15TfMDStr6/2feI4VwMpuUfumb+qOQQWTmcRIdC3u2w=; h=Date:From:Reply-To:Subject:To; b=vvUqlreOievUEGepATwMSa/g/fZmL0OkppngMHowXRspGNBOP7qD1+8p46NrdXtZMES a+hwvThaBFe86BKDj0/AoLhN/BNvtkDTwxs2gKfc7ck7peJhvWJmQX4TODo3gLpG7xEVK LfvkscGT+tC9NTrm1a1pf1gcj7dHWxdLXu0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1646210718709100056 Content-Type: text/plain; charset="utf-8" Platform PEI module for LoongArch platform initialization. Signed-off-by: xianglai li --- .../Loongson/LoongArchQemuPkg/Loongson.dec | 22 ++ .../Loongson/LoongArchQemuPkg/Loongson.dsc | 66 ++++- .../Loongson/LoongArchQemuPkg/Loongson.fdf | 51 ++++ .../LoongArchQemuPkg/PlatformPei/Fv.c | 61 ++++ .../LoongArchQemuPkg/PlatformPei/MemDetect.c | 116 ++++++++ .../LoongArchQemuPkg/PlatformPei/Platform.c | 264 ++++++++++++++++++ .../LoongArchQemuPkg/PlatformPei/Platform.h | 87 ++++++ .../PlatformPei/PlatformPei.inf | 72 +++++ 8 files changed, 738 insertions(+), 1 deletion(-) create mode 100644 Platform/Loongson/LoongArchQemuPkg/PlatformPei/Fv.c create mode 100644 Platform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetec= t.c create mode 100644 Platform/Loongson/LoongArchQemuPkg/PlatformPei/Platform= .c create mode 100644 Platform/Loongson/LoongArchQemuPkg/PlatformPei/Platform= .h create mode 100644 Platform/Loongson/LoongArchQemuPkg/PlatformPei/Platform= Pei.inf diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.dec b/Platform/Loo= ngson/LoongArchQemuPkg/Loongson.dec index 248b668fd1..aca53583f1 100644 --- a/Platform/Loongson/LoongArchQemuPkg/Loongson.dec +++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.dec @@ -30,9 +30,31 @@ [PcdsFixedAtBuild, PcdsDynamic] gLoongArchQemuPkgTokenSpaceGuid.PcdFlashPeiFvBase|0x0|UINT64|0x00000003 gLoongArchQemuPkgTokenSpaceGuid.PcdFlashPeiFvSize|0x0|UINT32|0x00000004 + gLoongArchQemuPkgTokenSpaceGuid.PcdFlashDxeFvBase|0x0|UINT64|0x00000008 + gLoongArchQemuPkgTokenSpaceGuid.PcdFlashDxeFvSize|0x0|UINT32|0x00000009 gLoongArchQemuPkgTokenSpaceGuid.PcdGuidedExtractHandlerTableSize|0|UINT3= 2|0x00000016 gLoongArchQemuPkgTokenSpaceGuid.PcdGuidedExtractHandlerTableAddress|0|UI= NT32|0x00000017 + gLoongArchQemuPkgTokenSpaceGuid.PcdDeviceTreeBase|0x0|UINT64|0x00000018 + gLoongArchQemuPkgTokenSpaceGuid.PcdDeviceTreePadding|256|UINT32|0x000000= 19 + gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamBase|0|UINT64|0x0000001c gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamSize|0|UINT32|0x0000001d + gLoongArchQemuPkgTokenSpaceGuid.PcdUefiRamTop|0x0|UINT64|0x0000001e + gLoongArchQemuPkgTokenSpaceGuid.PcdRamRegionsBottom|0x0|UINT64|0x00000022 gLoongArchQemuPkgTokenSpaceGuid.PcdFlashSecFvBase|0x0|UINT64|0x00000028 gLoongArchQemuPkgTokenSpaceGuid.PcdFlashSecFvSize|0x0|UINT32|0x00000029 + +[PcdsFixedAtBuild.LOONGARCH64] + gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize|32|UINT8|0x00000010 + gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize|0|UINT8|0x00000011 + +[PcdsDynamic] + gLoongArchQemuPkgTokenSpaceGuid.PcdRamSize|0x40000000|UINT64|0x00000041 + gLoongArchQemuPkgTokenSpaceGuid.PcdFwCfgSelectorAddress|0x0|UINT64|0x000= 00042 + gLoongArchQemuPkgTokenSpaceGuid.PcdFwCfgDataAddress|0x0|UINT64|0x00000043 + gLoongArchQemuPkgTokenSpaceGuid.PcdSwapPageDir|0x0|UINT64|0x00000044 + gLoongArchQemuPkgTokenSpaceGuid.PcdInvalidPgd|0x0|UINT64|0x00000045 + gLoongArchQemuPkgTokenSpaceGuid.PcdInvalidPud|0x0|UINT64|0x00000046 + gLoongArchQemuPkgTokenSpaceGuid.PcdInvalidPmd|0x0|UINT64|0x00000047 + gLoongArchQemuPkgTokenSpaceGuid.PcdInvalidPte|0x0|UINT64|0x00000048 + diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc b/Platform/Loo= ngson/LoongArchQemuPkg/Loongson.dsc index f23fed77e6..09b324c3f7 100644 --- a/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc +++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc @@ -57,22 +57,58 @@ =20 [LibraryClasses.common] PcdLib | MdePkg/Library/BasePcdLibNull/BasePcd= LibNull.inf + TimerLib | Platform/Loongson/LoongArchQemuPkg/Li= brary/StableTimerLib/TimerLib.inf PrintLib | MdePkg/Library/BasePrintLib/BasePrint= Lib.inf BaseMemoryLib | MdePkg/Library/BaseMemoryLib/BaseMemo= ryLib.inf =20 =20 BaseLib | MdePkg/Library/BaseLib/BaseLib.inf + PerformanceLib | MdePkg/Library/BasePerformanceLibNull= /BasePerformanceLibNull.inf PeCoffLib | MdePkg/Library/BasePeCoffLib/BasePeCo= ffLib.inf + CacheMaintenanceLib | MdePkg/Library/BaseCacheMaintenanceLi= b/BaseCacheMaintenanceLib.inf + UefiDecompressLib | MdePkg/Library/BaseUefiDecompressLib/= BaseUefiDecompressLib.inf PeCoffGetEntryPointLib | MdePkg/Library/BasePeCoffGetEntryPoin= tLib/BasePeCoffGetEntryPointLib.inf IoLib | MdePkg/Library/BaseIoLibIntrinsic/Bas= eIoLibIntrinsic.inf SerialPortLib | Platform/Loongson/LoongArchQemuPkg/Li= brary/SerialPortLib/SerialPortLib.inf DebugPrintErrorLevelLib | MdePkg/Library/BaseDebugPrintErrorLev= elLib/BaseDebugPrintErrorLevelLib.inf + FdtLib | EmbeddedPkg/Library/FdtLib/FdtLib.inf PeCoffExtraActionLib | MdePkg/Library/BasePeCoffExtraActionL= ibNull/BasePeCoffExtraActionLibNull.inf DebugAgentLib | MdeModulePkg/Library/DebugAgentLibNul= l/DebugAgentLibNull.inf =20 DebugLib | MdePkg/Library/BaseDebugLibSerialPort= /BaseDebugLibSerialPort.inf =20 + PeiServicesLib | MdePkg/Library/PeiServicesLib/PeiServ= icesLib.inf +[LibraryClasses.common.SEC] + ReportStatusCodeLib | MdeModulePkg/Library/PeiReportStatusC= odeLib/PeiReportStatusCodeLib.inf + HobLib | MdePkg/Library/PeiHobLib/PeiHobLib.inf + MemoryAllocationLib | MdePkg/Library/PeiMemoryAllocationLib= /PeiMemoryAllocationLib.inf + +[LibraryClasses.common.PEI_CORE] + HobLib | MdePkg/Library/PeiHobLib/PeiHobLib.inf + PeiServicesTablePointerLib | Platform/Loongson/LoongArchQemuPkg/Li= brary/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf + MemoryAllocationLib | MdePkg/Library/PeiMemoryAllocationLib= /PeiMemoryAllocationLib.inf + PeiCoreEntryPoint | MdePkg/Library/PeiCoreEntryPoint/PeiC= oreEntryPoint.inf + ReportStatusCodeLib | MdeModulePkg/Library/PeiReportStatusC= odeLib/PeiReportStatusCodeLib.inf + OemHookStatusCodeLib | MdeModulePkg/Library/OemHookStatusCod= eLibNull/OemHookStatusCodeLibNull.inf + PeCoffGetEntryPointLib | MdePkg/Library/BasePeCoffGetEntryPoin= tLib/BasePeCoffGetEntryPointLib.inf + QemuFwCfgLib | Platform/Loongson/LoongArchQemuPkg/Li= brary/QemuFwCfgLib/QemuFwCfgLib.inf + MmuLib | Platform/Loongson/LoongArchQemuPkg/Li= brary/MmuLib/MmuBaseLibPei.inf + +[LibraryClasses.common.PEIM] + HobLib | MdePkg/Library/PeiHobLib/PeiHobLib.inf + PeiServicesTablePointerLib | Platform/Loongson/LoongArchQemuPkg/Li= brary/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf + MemoryAllocationLib | MdePkg/Library/PeiMemoryAllocationLib= /PeiMemoryAllocationLib.inf + PeimEntryPoint | MdePkg/Library/PeimEntryPoint/PeimEnt= ryPoint.inf + ReportStatusCodeLib | MdeModulePkg/Library/PeiReportStatusC= odeLib/PeiReportStatusCodeLib.inf + OemHookStatusCodeLib | MdeModulePkg/Library/OemHookStatusCod= eLibNull/OemHookStatusCodeLibNull.inf + PeCoffGetEntryPointLib | MdePkg/Library/BasePeCoffGetEntryPoin= tLib/BasePeCoffGetEntryPointLib.inf + PeiResourcePublicationLib | MdePkg/Library/PeiResourcePublication= Lib/PeiResourcePublicationLib.inf + ExtractGuidedSectionLib | MdePkg/Library/PeiExtractGuidedSectio= nLib/PeiExtractGuidedSectionLib.inf + PcdLib | MdePkg/Library/PeiPcdLib/PeiPcdLib.inf + QemuFwCfgS3Lib | OvmfPkg/Library/QemuFwCfgS3Lib/PeiQem= uFwCfgS3LibFwCfg.inf + QemuFwCfgLib | Platform/Loongson/LoongArchQemuPkg/Li= brary/QemuFwCfgLib/QemuFwCfgLib.inf =20 + MmuLib | Platform/Loongson/LoongArchQemuPkg/Librar= y/MmuLib/MmuBaseLibPei.inf =20 =20 ##########################################################################= ###### @@ -119,11 +155,19 @@ # ASSERT_BREAKPOINT_ENABLED 0x10 # ASSERT_DEADLOOP_ENABLED 0x20 =20 +##########################################################################= ############# + gLoongArchQemuPkgTokenSpaceGuid.PcdRamRegionsBottom | 0= x90000000 gEfiMdePkgTokenSpaceGuid.PcdGuidedExtractHandlerTableAddress | 0= x90000000 gLoongArchQemuPkgTokenSpaceGuid.PcdGuidedExtractHandlerTableSize | 0= x10000 gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamBase | 0= x90010000 gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamSize | 0= x10000 - + gLoongArchQemuPkgTokenSpaceGuid.PcdDeviceTreeBase | 0= x1c400000 + # + # minimal memory for uefi bios should be 512M + # 0x00000000 - 0x10000000 + # 0x90000000 - 0xA0000000 + # + gLoongArchQemuPkgTokenSpaceGuid.PcdUefiRamTop | 0= xA0000000 =20 [Components] =20 @@ -131,3 +175,23 @@ # SEC Phase modules # Platform/Loongson/LoongArchQemuPkg/Sec/SecMain.inf + + # + # PEI Phase modules + # + MdeModulePkg/Core/Pei/PeiMain.inf + MdeModulePkg/Universal/PCD/Pei/Pcd.inf { + + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + } + MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf + MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf { + + NULL|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompre= ssLib.inf + } + + Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf { + + PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf + } + diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf b/Platform/Loo= ngson/LoongArchQemuPkg/Loongson.fdf index 128b3843db..f964304fdc 100644 --- a/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf +++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf @@ -45,9 +45,60 @@ READ_LOCK_STATUS =3D TRUE =20 INF Platform/Loongson/LoongArchQemuPkg/Sec/SecMain.inf =20 +##########################################################################= ########################### +[FV.PEIFV] +FvNameGuid =3D 6f856a84-de7d-4af9-93a3-342b4ecb46eb +BlockSize =3D $(BLOCK_SIZE) +FvAlignment =3D 16 +ERASE_POLARITY =3D 1 +MEMORY_MAPPED =3D TRUE +STICKY_WRITE =3D TRUE +LOCK_CAP =3D TRUE +LOCK_STATUS =3D TRUE +READ_DISABLED_CAP =3D TRUE +READ_ENABLED_CAP =3D TRUE +READ_STATUS =3D TRUE +READ_LOCK_CAP =3D TRUE +READ_LOCK_STATUS =3D TRUE +WRITE_DISABLED_CAP =3D TRUE +WRITE_ENABLED_CAP =3D TRUE +WRITE_STATUS =3D TRUE +WRITE_LOCK_CAP =3D TRUE +WRITE_LOCK_STATUS =3D TRUE + +APRIORI PEI { + INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf +} + +# +# PEI Phase modules +# + +INF MdeModulePkg/Core/Pei/PeiMain.inf +INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf +INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf +INF Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf + ##########################################################################= ########################### [Rule.Common.SEC] FILE SEC =3D $(NAMED_GUID) { TE TE Align =3D Auto $(INF_OUTPUT)/$(MODULE_NAME).efi UI STRING =3D"$(MODULE_NAME)" Optional } + +##########################################################################= ########################### +[Rule.Common.PEI_CORE] + FILE PEI_CORE =3D $(NAMED_GUID) { + TE TE Align=3DAuto $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING =3D"$(MODULE_NAME)" Optional + } + +##########################################################################= ########################### +[Rule.Common.PEIM] + FILE PEIM =3D $(NAMED_GUID) { + PEI_DEPEX PEI_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + PE32 PE32 Align=3DAuto $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING=3D"$(MODULE_NAME)" Optional + } + +##########################################################################= ########################### diff --git a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/Fv.c b/Platform= /Loongson/LoongArchQemuPkg/PlatformPei/Fv.c new file mode 100644 index 0000000000..f79d4506b1 --- /dev/null +++ b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/Fv.c @@ -0,0 +1,61 @@ +/** @file + Build FV related hobs for platform. + + Copyright (c) 2021 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + + +#include "PiPei.h" +#include "Platform.h" +#include +#include +#include +#include + + +/** + Publish PEI & DXE (Decompressed) Memory based FVs to let PEI + and DXE know about them. + + @retval EFI_SUCCESS Platform PEI FVs were initialized successfully. + +**/ +EFI_STATUS +PeiFvInitialization ( + VOID + ) +{ + DEBUG ((DEBUG_INFO, "Platform PEI Firmware Volume Initialization\n")); + + // + // Create a memory allocation HOB for the PEI FV. + // + BuildMemoryAllocationHob ( + PcdGet64 (PcdSecPeiTempRamBase), + PcdGet32 (PcdSecPeiTempRamSize), + EfiBootServicesData + ); + + // + // Let DXE know about the DXE FV + // + BuildFvHob (PcdGet64 (PcdFlashDxeFvBase), PcdGet32 (PcdFlashDxeFvSize)); + + // + // Let PEI know about the DXE FV so it can find the DXE Core + // + DEBUG ((DEBUG_INFO, "DXEFV base:%p size:%x\n", (VOID *) (UINTN)PcdGet64 = (PcdFlashDxeFvBase), + PcdGet32 (PcdFlashDxeFvSize))); + PeiServicesInstallFvInfoPpi ( + NULL, + (VOID *) (UINTN)PcdGet64 (PcdFlashDxeFvBase), + PcdGet32 (PcdFlashDxeFvSize), + NULL, + NULL + ); + + return EFI_SUCCESS; +} diff --git a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetect.c b/P= latform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetect.c new file mode 100644 index 0000000000..c40d7d5c71 --- /dev/null +++ b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetect.c @@ -0,0 +1,116 @@ +/** @file + Memory Detection for Virtual Machines. + + Copyright (c) 2021 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + + +// +// The package level header files this module uses +// +#include + +// +// The Library classes this module consumes +// +#include +#include +#include +#include +#include +#include +#include + +#include "Platform.h" + +/** + Publish PEI core memory + + @return EFI_SUCCESS The PEIM initialized successfully. + +**/ +EFI_STATUS +PublishPeiMemory ( + VOID + ) +{ + EFI_STATUS Status; + UINT64 Base; + UINT64 Size; + UINT64 RamTop; + + // + // Determine the range of memory to use during PEI + // + Base =3D PcdGet64 (PcdSecPeiTempRamBase) + PcdGet32 (PcdSecPeiTempRamSiz= e); + RamTop =3D PcdGet64 (PcdUefiRamTop); + Size =3D RamTop - Base; + + + // + // Publish this memory to the PEI Core + // + Status =3D PublishSystemMemory (Base, Size); + ASSERT_EFI_ERROR (Status); + + DEBUG ((DEBUG_INFO, "Publish Memory Initialize done.\n")); + return Status; +} + +/** + Peform Memory Detection + Publish system RAM and reserve memory regions +**/ +VOID +InitializeRamRegions ( + VOID + ) +{ + UINT64 Base; + UINT64 End; + + + // + // DDR memory space address range + // 0x00000000 - 0x10000000 lower 256M memory space + // 0x90000000 - BASE_4GB if there is + // BASE_4GB - + Base =3D PcdGet64 (PcdRamRegionsBottom); + End =3D Base + PcdGet64 (PcdRamSize) - 0x10000000; + + // + // Create memory HOBs. + // Put memory below 4G address space at the first memory HOB + // + DEBUG ((DEBUG_INFO, "%a: MemoryBase=3D%llx, MemoryEnd=3D%llx\n", __FUNCT= ION__, Base, End)); + + if (End > BASE_4GB) { + AddMemoryRangeHob (Base, BASE_4GB); + AddMemoryRangeHob (BASE_4GB, End); + } else { + + AddMemoryRangeHob (Base, End); + } + AddMemoryRangeHob (0x0, 0x10000000); + + // + // Lock the scope of the cache. + // + BuildMemoryAllocationHob ( + PcdGet64 (PcdSecPeiTempRamBase), + PcdGet32 (PcdSecPeiTempRamSize), + EfiACPIMemoryNVS + ); + + // + // SEC stores its table of GUIDed section handlers here. + // + BuildMemoryAllocationHob ( + PcdGet64 (PcdGuidedExtractHandlerTableAddress), + PcdGet32 (PcdGuidedExtractHandlerTableSize), + EfiACPIMemoryNVS + ); +} diff --git a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/Platform.c b/Pl= atform/Loongson/LoongArchQemuPkg/PlatformPei/Platform.c new file mode 100644 index 0000000000..6f6c53fcab --- /dev/null +++ b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/Platform.c @@ -0,0 +1,264 @@ +/** @file + Platform PEI driver + + Copyright (c) 2021 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - Mem - Memory +**/ + + +// +// The package level header files this module uses +// +#include +// +// The Library classes this module consumes +// +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Platform.h" + +/* TODO */ +EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] =3D { + { EfiReservedMemoryType, 0x004 }, + { EfiRuntimeServicesData, 0x024 }, + { EfiRuntimeServicesCode, 0x030 }, + { EfiBootServicesCode, 0x180 }, + { EfiBootServicesData, 0xF00 }, + { EfiMaxMemoryType, 0x000 } +}; + +// +// Module globals +// +CONST EFI_PEI_PPI_DESCRIPTOR mPpiListBootMode =3D { + (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), + &gEfiPeiMasterBootModePpiGuid, + NULL +}; + +/** + Create Reserved type memory range hand off block. + + @param MemoryBase memory base address. + @param MemoryLimit memory length. + + @return VOID +**/ +VOID +AddReservedMemoryBaseSizeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + UINT64 MemorySize + ) +{ + BuildResourceDescriptorHob ( + EFI_RESOURCE_MEMORY_RESERVED, + EFI_RESOURCE_ATTRIBUTE_PRESENT | + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | + EFI_RESOURCE_ATTRIBUTE_TESTED, + MemoryBase, + MemorySize + ); +} +/** + Create system type memory range hand off block. + + @param MemoryBase memory base address. + @param MemoryLimit memory length. + + @return VOID +**/ +VOID +AddMemoryBaseSizeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + UINT64 MemorySize + ) +{ + BuildResourceDescriptorHob ( + EFI_RESOURCE_SYSTEM_MEMORY, + EFI_RESOURCE_ATTRIBUTE_PRESENT | + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | + EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE | + EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE | + EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE | + EFI_RESOURCE_ATTRIBUTE_TESTED, + MemoryBase, + MemorySize + ); +} + +/** + Create memory range hand off block. + + @param MemoryBase memory base address. + @param MemoryLimit memory length. + + @return VOID +**/ +VOID +AddMemoryRangeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + EFI_PHYSICAL_ADDRESS MemoryLimit + ) +{ + AddMemoryBaseSizeHob (MemoryBase, (UINT64) (MemoryLimit - MemoryBase)); +} +/** + Create memory type information hand off block. + + @param VOID + + @return VOID +**/ +VOID +MemMapInitialization ( + VOID + ) +{ + DEBUG ((DEBUG_INFO, "=3D=3D%a=3D=3D\n", __func__)); + // + // Create Memory Type Information HOB + // + BuildGuidDataHob ( + &gEfiMemoryTypeInformationGuid, + mDefaultMemoryTypeInformation, + sizeof (mDefaultMemoryTypeInformation) + ); +} + +/** + Misc Initialization. + + @param VOID + + @return VOID +**/ +VOID +MiscInitialization ( + VOID + ) +{ + DEBUG ((DEBUG_INFO, "=3D=3D%a=3D=3D\n", __func__)); + // + // Creat CPU HOBs. + // + BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize= )); +} +/** + add fdt hand off block. + + @param VOID + + @return VOID +**/ +VOID +AddFdtHob (VOID) +{ + VOID *Base; + VOID *NewBase; + UINTN FdtSize; + UINTN FdtPages; + UINT64 *FdtHobData; + + Base =3D (VOID*)(UINTN)PcdGet64 (PcdDeviceTreeBase); + ASSERT (Base !=3D NULL); + + FdtSize =3D fdt_totalsize (Base) + PcdGet32 (PcdDeviceTreePadding); + FdtPages =3D EFI_SIZE_TO_PAGES (FdtSize); + NewBase =3D AllocatePages (FdtPages); + ASSERT (NewBase !=3D NULL); + fdt_open_into (Base, NewBase, EFI_PAGES_TO_SIZE (FdtPages)); + + FdtHobData =3D BuildGuidHob (&gFdtHobGuid, sizeof *FdtHobData); + ASSERT (FdtHobData !=3D NULL); + *FdtHobData =3D (UINTN)NewBase; + +} + +/** + Fetch the size of system memory from QEMU. + + @param VOID + + @return VOID +**/ +VOID +SystemMemorySizeInitialization ( + VOID + ) +{ + UINT64 RamSize; + RETURN_STATUS PcdStatus; + + QemuFwCfgSelectItem (QemuFwCfgItemRamSize); + RamSize=3D QemuFwCfgRead64 (); + DEBUG ((DEBUG_INFO, "%a: QEMU reports %dM system memory\n", __FUNCTION__, + RamSize/1024/1024)); + + // + // If the fw_cfg key or fw_cfg entirely is unavailable, no change to PCD. + // + if (RamSize =3D=3D 0) { + return; + } + + // + // Otherwise, set RamSize to PCD. + // + PcdStatus =3D PcdSet64S (PcdRamSize, RamSize); + ASSERT_RETURN_ERROR (PcdStatus); +} + +/** + Perform Platform PEI initialization. + + @param FileHandle Handle of the file being invoked. + @param PeiServices Describes the list of possible PEI Services. + + @return EFI_SUCCESS The PEIM initialized successfully. + +**/ +EFI_STATUS +EFIAPI +InitializePlatform ( + IN EFI_PEI_FILE_HANDLE FileHandle, + IN CONST EFI_PEI_SERVICES **PeiServices + ) +{ + EFI_STATUS Status; + + DEBUG ((DEBUG_INFO, "Platform PEIM Loaded\n")); + + Status =3D PeiServicesInstallPpi (&mPpiListBootMode); + ASSERT_EFI_ERROR (Status); + + SystemMemorySizeInitialization (); + PublishPeiMemory (); + PeiFvInitialization (); + InitializeRamRegions (); + MemMapInitialization (); + MiscInitialization (); + AddFdtHob (); + ConfigureMmu (); + + return EFI_SUCCESS; +} diff --git a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/Platform.h b/Pl= atform/Loongson/LoongArchQemuPkg/PlatformPei/Platform.h new file mode 100644 index 0000000000..bc44f233e7 --- /dev/null +++ b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/Platform.h @@ -0,0 +1,87 @@ +/** @file + Platform PEI module include file. + + Copyright (c) 2021 Loongson Technology Corporation Limited. All rights r= eserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef PLATFORM_H_ +#define PLATFORM_H_ + +#include + +/** + Create system type memory range hand off block. + + @param MemoryBase memory base address. + @param MemoryLimit memory length. + + @return VOID +**/ +VOID +AddMemoryBaseSizeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + UINT64 MemorySize + ); + +/** + Create memory range hand off block. + + @param MemoryBase memory base address. + @param MemoryLimit memory length. + + @return VOID +**/ +VOID +AddMemoryRangeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + EFI_PHYSICAL_ADDRESS MemoryLimit + ); + +/** + Create Reserved type memory range hand off block. + + @param MemoryBase memory base address. + @param MemoryLimit memory length. + + @return VOID +**/ +VOID +AddReservedMemoryBaseSizeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + UINT64 MemorySize + ); +/** + Publish PEI core memory + + @return EFI_SUCCESS The PEIM initialized successfully. + +**/ +EFI_STATUS +PublishPeiMemory ( + VOID + ); +/** + Publish system RAM and reserve memory regions + +**/ +VOID +InitializeRamRegions ( + VOID + ); + +/** + Publish PEI & DXE (Decompressed) Memory based FVs to let PEI + and DXE know about them. + + @retval EFI_SUCCESS Platform PEI FVs were initialized successfully. + +**/ +EFI_STATUS +PeiFvInitialization ( + VOID + ); + +#endif // _PLATFORM_PEI_H_INCLUDED_ diff --git a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf= b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf new file mode 100644 index 0000000000..e8d3ed0008 --- /dev/null +++ b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf @@ -0,0 +1,72 @@ + +## @file +# Platform PEI driver +# +# Copyright (c) 2021 Loongson Technology Corporation Limited. All rights = reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D PlatformPei + FILE_GUID =3D 4c0e81e5-e8e3-4eef-b24b-19b686e9ab53 + MODULE_TYPE =3D PEIM + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D InitializePlatform + +[Sources] + Fv.c + MemDetect.c + Platform.c + + +[Packages] + ArmVirtPkg/ArmVirtPkg.dec + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + EmbeddedPkg/EmbeddedPkg.dec + Platform/Loongson/LoongArchQemuPkg/Loongson.dec + OvmfPkg/OvmfPkg.dec + +[Ppis] + gEfiPeiMasterBootModePpiGuid + +[Guids] + gEfiMemoryTypeInformationGuid + gFdtHobGuid + +[LibraryClasses] + DebugLib + BaseMemoryLib + HobLib + IoLib + PeiResourcePublicationLib + PeiServicesLib + PeiServicesTablePointerLib + PeimEntryPoint + QemuFwCfgLib + PcdLib + TimerLib + MmuLib + +[Pcd] + gLoongArchQemuPkgTokenSpaceGuid.PcdRamSize + gLoongArchQemuPkgTokenSpaceGuid.PcdDeviceTreeBase + gLoongArchQemuPkgTokenSpaceGuid.PcdDeviceTreePadding + +[FixedPcd] + gLoongArchQemuPkgTokenSpaceGuid.PcdFlashDxeFvBase + gLoongArchQemuPkgTokenSpaceGuid.PcdFlashDxeFvSize + gLoongArchQemuPkgTokenSpaceGuid.PcdRamRegionsBottom + gLoongArchQemuPkgTokenSpaceGuid.PcdUefiRamTop + gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamBase + gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamSize + gLoongArchQemuPkgTokenSpaceGuid.PcdGuidedExtractHandlerTableSize + gEfiMdePkgTokenSpaceGuid.PcdGuidedExtractHandlerTableAddress + gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize + gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize + +[Depex] + TRUE --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#87208): https://edk2.groups.io/g/devel/message/87208 Mute This Topic: https://groups.io/mt/89497237/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-