From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from loongson.cn (loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web09.3538.1668157962294333985 for ; Fri, 11 Nov 2022 01:12:43 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: loongson.cn, ip: 114.242.206.163, mailfrom: lixianglai@loongson.cn) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8DxC7YIEm5jixMGAA--.7123S3; Fri, 11 Nov 2022 17:12:40 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxFlcAEm5jXc0QAA--.27651S9; Fri, 11 Nov 2022 17:12:38 +0800 (CST) From: "xianglai" To: devel@edk2.groups.io Cc: Bibo Mao , Chao Li , Leif Lindholm , Liming Gao , Michael D Kinney Subject: [edk2-platforms][PATCH V5 07/15] Platform/Loongson: Support PEI phase. Date: Fri, 11 Nov 2022 17:12:22 +0800 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 X-CM-TRANSID: AQAAf8BxFlcAEm5jXc0QAA--.27651S9 X-CM-SenderInfo: 5ol0xt5qjotxo6or00hjvr0hdfq/ X-Coremail-Antispam: 1Uk129KBjvAXoWfAw1ktFyftF13KF1rKryUZFb_yoW5Xr17to W8JF92kw4UGr4rXw1UG3ZxtrWIv3WYva1Yqr1rZayUAFs0yr13tF98J3s7Gr15AFn8Awn8 G3yfGaykJFW2q3s5n29KB7ZKAUJUUUU3529EdanIXcx71UUUUU7KY7ZEXasCq-sGcSsGvf J3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnRJU UUkv1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64 kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW5JVW7JwA2z4x0Y4vE2Ix0cI8IcVCY 1x0267AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIE14v26F4UJVW0owA2z4x0Y4vEx4A2jsIEc7 CjxVAFwI0_Cr1j6rxdM2kKe7AKxVWUAVWUtwAS0I0E0xvYzxvE52x082IY62kv0487Mc80 4VCY07AIYIkI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VCjz48v1sIEY2 0_WwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2AFwI0_JF0_ Jw1l42xK82IYc2Ij64vIr41l42xK82IY6x8ErcxFaVAv8VWrMxC20s026xCaFVCjc4AY6r 1j6r4UMxCIbckI1I0E14v26r126r1DMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xv wVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjx v20xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20E Y4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Cr0_Gr1UMIIF0xvEx4A2jsIEc7CjxV AFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0zR9iSdUUUUU= Content-Transfer-Encoding: quoted-printable Platform PEI module for LoongArch platform initialization.=0D =0D REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4054=0D =0D Cc: Bibo Mao =0D Cc: Chao Li =0D Cc: Leif Lindholm =0D Cc: Liming Gao =0D Cc: Michael D Kinney =0D Signed-off-by: xianglai li =0D ---=0D .../Loongson/LoongArchQemuPkg/Loongson.dec | 23 ++=0D .../Loongson/LoongArchQemuPkg/Loongson.dsc | 64 +++++=0D .../Loongson/LoongArchQemuPkg/Loongson.fdf | 51 ++++=0D .../LoongArchQemuPkg/PlatformPei/Fv.c | 58 ++++=0D .../LoongArchQemuPkg/PlatformPei/MemDetect.c | 104 +++++++=0D .../LoongArchQemuPkg/PlatformPei/Platform.c | 261 ++++++++++++++++++=0D .../LoongArchQemuPkg/PlatformPei/Platform.h | 86 ++++++=0D .../PlatformPei/PlatformPei.inf | 72 +++++=0D 8 files changed, 719 insertions(+)=0D create mode 100644 Platform/Loongson/LoongArchQemuPkg/PlatformPei/Fv.c=0D create mode 100644 Platform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetec= t.c=0D create mode 100644 Platform/Loongson/LoongArchQemuPkg/PlatformPei/Platform= .c=0D create mode 100644 Platform/Loongson/LoongArchQemuPkg/PlatformPei/Platform= .h=0D create mode 100644 Platform/Loongson/LoongArchQemuPkg/PlatformPei/Platform= Pei.inf=0D =0D diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.dec b/Platform/Loo= ngson/LoongArchQemuPkg/Loongson.dec=0D index 61f600b20d..aeae75a678 100644=0D --- a/Platform/Loongson/LoongArchQemuPkg/Loongson.dec=0D +++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.dec=0D @@ -32,7 +32,30 @@=0D [PcdsFixedAtBuild, PcdsDynamic]=0D gLoongArchQemuPkgTokenSpaceGuid.PcdFlashPeiFvBase|0x0|UINT64|0x00000000= =0D gLoongArchQemuPkgTokenSpaceGuid.PcdFlashPeiFvSize|0x0|UINT32|0x00000001= =0D + gLoongArchQemuPkgTokenSpaceGuid.PcdFlashDxeFvBase|0x0|UINT64|0x00000003= =0D + gLoongArchQemuPkgTokenSpaceGuid.PcdFlashDxeFvSize|0x0|UINT32|0x00000004= =0D + gLoongArchQemuPkgTokenSpaceGuid.PcdDeviceTreeBase|0x0|UINT64|0x00000009= =0D + gLoongArchQemuPkgTokenSpaceGuid.PcdDeviceTreePadding|256|UINT32|0x000000= 0a=0D +=0D gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamBase|0|UINT64|0x0000000b= =0D gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamSize|0|UINT32|0x0000000c= =0D + gLoongArchQemuPkgTokenSpaceGuid.PcdUefiRamTop|0x0|UINT64|0x0000000d=0D + gLoongArchQemuPkgTokenSpaceGuid.PcdRamRegionsBottom|0x0|UINT64|0x0000000= e=0D gLoongArchQemuPkgTokenSpaceGuid.PcdFlashSecFvBase|0x0|UINT64|0x0000000f= =0D gLoongArchQemuPkgTokenSpaceGuid.PcdFlashSecFvSize|0x0|UINT32|0x00000010= =0D +=0D +## In the PcdsFixedAtBuild.LOONGARCH64 area, numbers start at 0x10000.=0D +[PcdsFixedAtBuild.LOONGARCH64]=0D + gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize|32|UINT8|0x00010000=0D + gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize|0|UINT8|0x00010001=0D +=0D +## In the PcdsDynamic area, numbers start at 0x20000.=0D +[PcdsDynamic]=0D + gLoongArchQemuPkgTokenSpaceGuid.PcdRamSize|0x40000000|UINT64|0x00020000= =0D + gLoongArchQemuPkgTokenSpaceGuid.PcdFwCfgSelectorAddress|0x0|UINT64|0x000= 20001=0D + gLoongArchQemuPkgTokenSpaceGuid.PcdFwCfgDataAddress|0x0|UINT64|0x0002000= 2=0D + gLoongArchQemuPkgTokenSpaceGuid.PcdSwapPageDir|0x0|UINT64|0x00020003=0D + gLoongArchQemuPkgTokenSpaceGuid.PcdInvalidPgd|0x0|UINT64|0x00020004=0D + gLoongArchQemuPkgTokenSpaceGuid.PcdInvalidPud|0x0|UINT64|0x00020005=0D + gLoongArchQemuPkgTokenSpaceGuid.PcdInvalidPmd|0x0|UINT64|0x00020006=0D + gLoongArchQemuPkgTokenSpaceGuid.PcdInvalidPte|0x0|UINT64|0x00020007=0D diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc b/Platform/Loo= ngson/LoongArchQemuPkg/Loongson.dsc=0D index b506f70625..b78a7e3b49 100644=0D --- a/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc=0D +++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc=0D @@ -56,16 +56,53 @@=0D =0D [LibraryClasses.common]=0D PcdLib | MdePkg/Library/BasePcdLibNull/BasePcd= LibNull.inf=0D + TimerLib | Platform/Loongson/LoongArchQemuPkg/Li= brary/StableTimerLib/TimerLib.inf=0D PrintLib | MdePkg/Library/BasePrintLib/BasePrint= Lib.inf=0D BaseMemoryLib | MdePkg/Library/BaseMemoryLib/BaseMemo= ryLib.inf=0D BaseLib | MdePkg/Library/BaseLib/BaseLib.inf=0D + PerformanceLib | MdePkg/Library/BasePerformanceLibNull= /BasePerformanceLibNull.inf=0D PeCoffLib | MdePkg/Library/BasePeCoffLib/BasePeCo= ffLib.inf=0D + CacheMaintenanceLib | MdePkg/Library/BaseCacheMaintenanceLi= b/BaseCacheMaintenanceLib.inf=0D + UefiDecompressLib | MdePkg/Library/BaseUefiDecompressLib/= BaseUefiDecompressLib.inf=0D PeCoffGetEntryPointLib | MdePkg/Library/BasePeCoffGetEntryPoin= tLib/BasePeCoffGetEntryPointLib.inf=0D IoLib | MdePkg/Library/BaseIoLibIntrinsic/Bas= eIoLibIntrinsic.inf=0D SerialPortLib | Platform/Loongson/LoongArchQemuPkg/Li= brary/SerialPortLib/SerialPortLib.inf=0D DebugPrintErrorLevelLib | MdePkg/Library/BaseDebugPrintErrorLev= elLib/BaseDebugPrintErrorLevelLib.inf=0D + FdtLib | EmbeddedPkg/Library/FdtLib/FdtLib.inf= =0D PeCoffExtraActionLib | MdePkg/Library/BasePeCoffExtraActionL= ibNull/BasePeCoffExtraActionLibNull.inf=0D DebugAgentLib | MdeModulePkg/Library/DebugAgentLibNul= l/DebugAgentLibNull.inf=0D + PeiServicesLib | MdePkg/Library/PeiServicesLib/PeiServ= icesLib.inf=0D +=0D +[LibraryClasses.common.SEC]=0D + ReportStatusCodeLib | MdeModulePkg/Library/PeiReportStatusC= odeLib/PeiReportStatusCodeLib.inf=0D + HobLib | MdePkg/Library/PeiHobLib/PeiHobLib.in= f=0D + MemoryAllocationLib | MdePkg/Library/PeiMemoryAllocationLib= /PeiMemoryAllocationLib.inf=0D +=0D +[LibraryClasses.common.PEI_CORE]=0D + HobLib | MdePkg/Library/PeiHobLib/PeiHobLib.in= f=0D + PeiServicesTablePointerLib | Platform/Loongson/LoongArchQemuPkg/Li= brary/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf=0D + MemoryAllocationLib | MdePkg/Library/PeiMemoryAllocationLib= /PeiMemoryAllocationLib.inf=0D + PeiCoreEntryPoint | MdePkg/Library/PeiCoreEntryPoint/PeiC= oreEntryPoint.inf=0D + ReportStatusCodeLib | MdeModulePkg/Library/PeiReportStatusC= odeLib/PeiReportStatusCodeLib.inf=0D + OemHookStatusCodeLib | MdeModulePkg/Library/OemHookStatusCod= eLibNull/OemHookStatusCodeLibNull.inf=0D + PeCoffGetEntryPointLib | MdePkg/Library/BasePeCoffGetEntryPoin= tLib/BasePeCoffGetEntryPointLib.inf=0D + QemuFwCfgLib | Platform/Loongson/LoongArchQemuPkg/Li= brary/QemuFwCfgLib/QemuFwCfgPeiLib.inf=0D + MmuLib | Platform/Loongson/LoongArchQemuPkg/Li= brary/MmuLib/MmuBaseLibPei.inf=0D +=0D +[LibraryClasses.common.PEIM]=0D + HobLib | MdePkg/Library/PeiHobLib/PeiHobLib.in= f=0D + PeiServicesTablePointerLib | Platform/Loongson/LoongArchQemuPkg/Li= brary/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf=0D + MemoryAllocationLib | MdePkg/Library/PeiMemoryAllocationLib= /PeiMemoryAllocationLib.inf=0D + PeimEntryPoint | MdePkg/Library/PeimEntryPoint/PeimEnt= ryPoint.inf=0D + ReportStatusCodeLib | MdeModulePkg/Library/PeiReportStatusC= odeLib/PeiReportStatusCodeLib.inf=0D + OemHookStatusCodeLib | MdeModulePkg/Library/OemHookStatusCod= eLibNull/OemHookStatusCodeLibNull.inf=0D + PeCoffGetEntryPointLib | MdePkg/Library/BasePeCoffGetEntryPoin= tLib/BasePeCoffGetEntryPointLib.inf=0D + PeiResourcePublicationLib | MdePkg/Library/PeiResourcePublication= Lib/PeiResourcePublicationLib.inf=0D + ExtractGuidedSectionLib | MdePkg/Library/PeiExtractGuidedSectio= nLib/PeiExtractGuidedSectionLib.inf=0D + PcdLib | MdePkg/Library/PeiPcdLib/PeiPcdLib.in= f=0D + QemuFwCfgS3Lib | OvmfPkg/Library/QemuFwCfgS3Lib/PeiQem= uFwCfgS3LibFwCfg.inf=0D + QemuFwCfgLib | Platform/Loongson/LoongArchQemuPkg/Li= brary/QemuFwCfgLib/QemuFwCfgPeiLib.inf=0D + MmuLib | Platform/Loongson/LoongArchQemuPkg/Li= brary/MmuLib/MmuBaseLibPei.inf=0D =0D ##########################################################################= ######=0D #=0D @@ -111,8 +148,16 @@=0D # ASSERT_BREAKPOINT_ENABLED 0x10=0D # ASSERT_DEADLOOP_ENABLED 0x20=0D =0D +##########################################################################= #############=0D gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamBase | 0= x10000=0D gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamSize | 0= x10000=0D + gLoongArchQemuPkgTokenSpaceGuid.PcdDeviceTreeBase | 0= x200000=0D + #=0D + # minimal memory for uefi bios should be 512M=0D + # 0x00000000 - 0x10000000=0D + # 0x90000000 - 0xA0000000=0D + #=0D + gLoongArchQemuPkgTokenSpaceGuid.PcdUefiRamTop | 0= x10000000=0D =0D [Components]=0D =0D @@ -120,3 +165,22 @@=0D # SEC Phase modules=0D #=0D Platform/Loongson/LoongArchQemuPkg/Sec/SecMain.inf=0D +=0D + #=0D + # PEI Phase modules=0D + #=0D + MdeModulePkg/Core/Pei/PeiMain.inf=0D + MdeModulePkg/Universal/PCD/Pei/Pcd.inf {=0D + =0D + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf=0D + }=0D + MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf= =0D + MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf {=0D + =0D + NULL|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompre= ssLib.inf=0D + }=0D +=0D + Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf {=0D + =0D + PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf=0D + }=0D diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf b/Platform/Loo= ngson/LoongArchQemuPkg/Loongson.fdf=0D index 9685795cda..8e257f2392 100644=0D --- a/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf=0D +++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf=0D @@ -45,9 +45,60 @@ READ_LOCK_STATUS =3D TRUE=0D =0D INF Platform/Loongson/LoongArchQemuPkg/Sec/SecMain.inf=0D =0D +##########################################################################= ###########################=0D +[FV.PEIFV]=0D +FvNameGuid =3D 6f856a84-de7d-4af9-93a3-342b4ecb46eb=0D +BlockSize =3D $(BLOCK_SIZE)=0D +FvAlignment =3D 16=0D +ERASE_POLARITY =3D 1=0D +MEMORY_MAPPED =3D TRUE=0D +STICKY_WRITE =3D TRUE=0D +LOCK_CAP =3D TRUE=0D +LOCK_STATUS =3D TRUE=0D +READ_DISABLED_CAP =3D TRUE=0D +READ_ENABLED_CAP =3D TRUE=0D +READ_STATUS =3D TRUE=0D +READ_LOCK_CAP =3D TRUE=0D +READ_LOCK_STATUS =3D TRUE=0D +WRITE_DISABLED_CAP =3D TRUE=0D +WRITE_ENABLED_CAP =3D TRUE=0D +WRITE_STATUS =3D TRUE=0D +WRITE_LOCK_CAP =3D TRUE=0D +WRITE_LOCK_STATUS =3D TRUE=0D +=0D +APRIORI PEI {=0D + INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf=0D +}=0D +=0D +#=0D +# PEI Phase modules=0D +#=0D +=0D +INF MdeModulePkg/Core/Pei/PeiMain.inf=0D +INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf=0D +INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf=0D +INF Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf=0D +=0D ##########################################################################= ###########################=0D [Rule.Common.SEC]=0D FILE SEC =3D $(NAMED_GUID) {=0D TE TE Align =3D Auto $(INF_OUTPUT)/$(MODULE_NAME).efi=0D UI STRING =3D"$(MODULE_NAME)" Optional=0D }=0D +=0D +##########################################################################= ###########################=0D +[Rule.Common.PEI_CORE]=0D + FILE PEI_CORE =3D $(NAMED_GUID) {=0D + TE TE Align=3DAuto $(INF_OUTPUT)/$(MODULE_NAME).efi=0D + UI STRING =3D"$(MODULE_NAME)" Optional=0D + }=0D +=0D +##########################################################################= ###########################=0D +[Rule.Common.PEIM]=0D + FILE PEIM =3D $(NAMED_GUID) {=0D + PEI_DEPEX PEI_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depe= x=0D + PE32 PE32 Align=3DAuto $(INF_OUTPUT)/$(MODULE_NAME).ef= i=0D + UI STRING=3D"$(MODULE_NAME)" Optional=0D + }=0D +=0D +##########################################################################= ###########################=0D diff --git a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/Fv.c b/Platform= /Loongson/LoongArchQemuPkg/PlatformPei/Fv.c=0D new file mode 100644=0D index 0000000000..06b2807d6c=0D --- /dev/null=0D +++ b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/Fv.c=0D @@ -0,0 +1,58 @@=0D +/** @file=0D + Build FV related hobs for platform.=0D +=0D + Copyright (c) 2022 Loongson Technology Corporation Limited. All rights r= eserved.
=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include "PiPei.h"=0D +#include "Platform.h"=0D +#include =0D +#include =0D +#include =0D +#include =0D +=0D +/**=0D + Publish PEI & DXE (Decompressed) Memory based FVs to let PEI=0D + and DXE know about them.=0D +=0D + @retval EFI_SUCCESS Platform PEI FVs were initialized successfully.=0D +**/=0D +EFI_STATUS=0D +PeiFvInitialization (=0D + VOID=0D + )=0D +{=0D + DEBUG ((DEBUG_INFO, "Platform PEI Firmware Volume Initialization\n"));=0D +=0D + //=0D + // Create a memory allocation HOB for the PEI FV.=0D + //=0D + BuildMemoryAllocationHob (=0D + PcdGet64 (PcdSecPeiTempRamBase),=0D + PcdGet32 (PcdSecPeiTempRamSize),=0D + EfiBootServicesData=0D + );=0D +=0D + //=0D + // Let DXE know about the DXE FV=0D + //=0D + BuildFvHob (PcdGet64 (PcdFlashDxeFvBase), PcdGet32 (PcdFlashDxeFvSize));= =0D +=0D + //=0D + // Let PEI know about the DXE FV so it can find the DXE Core=0D + //=0D + DEBUG ((DEBUG_INFO, "DXEFV base:%p size:%x\n", (VOID *) (UINTN)PcdGet64 = (PcdFlashDxeFvBase),=0D + PcdGet32 (PcdFlashDxeFvSize)));=0D + PeiServicesInstallFvInfoPpi (=0D + NULL,=0D + (VOID *) (UINTN)PcdGet64 (PcdFlashDxeFvBase),=0D + PcdGet32 (PcdFlashDxeFvSize),=0D + NULL,=0D + NULL=0D + );=0D +=0D + return EFI_SUCCESS;=0D +}=0D diff --git a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetect.c b/P= latform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetect.c=0D new file mode 100644=0D index 0000000000..fad4cff8d8=0D --- /dev/null=0D +++ b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetect.c=0D @@ -0,0 +1,104 @@=0D +/** @file=0D + Memory Detection for Virtual Machines.=0D +=0D + Copyright (c) 2022 Loongson Technology Corporation Limited. All rights r= eserved.
=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +//=0D +// The package level header files this module uses=0D +//=0D +#include =0D +=0D +//=0D +// The Library classes this module consumes=0D +//=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include "Platform.h"=0D +=0D +/**=0D + Publish PEI core memory=0D +=0D + @return EFI_SUCCESS The PEIM initialized successfully.=0D +**/=0D +EFI_STATUS=0D +PublishPeiMemory (=0D + VOID=0D + )=0D +{=0D + EFI_STATUS Status;=0D + UINT64 Base;=0D + UINT64 Size;=0D + UINT64 RamTop;=0D +=0D + //=0D + // Determine the range of memory to use during PEI=0D + //=0D + Base =3D PcdGet64 (PcdSecPeiTempRamBase) + PcdGet32 (PcdSecPeiTempRamSiz= e);=0D + RamTop =3D PcdGet64 (PcdUefiRamTop);=0D + Size =3D RamTop - Base;=0D +=0D + //=0D + // Publish this memory to the PEI Core=0D + //=0D + Status =3D PublishSystemMemory (Base, Size);=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + DEBUG ((DEBUG_INFO, "Publish Memory Initialize done.\n"));=0D + return Status;=0D +}=0D +=0D +/**=0D + Peform Memory Detection=0D + Publish system RAM and reserve memory regions=0D +**/=0D +VOID=0D +InitializeRamRegions (=0D + VOID=0D + )=0D +{=0D + EFI_STATUS Status;=0D + FIRMWARE_CONFIG_ITEM FwCfgItem;=0D + UINTN FwCfgSize;=0D + LOONGARCH_MEMMAP_ENTRY MemoryMapEntry;=0D + LOONGARCH_MEMMAP_ENTRY *StartEntry;=0D + LOONGARCH_MEMMAP_ENTRY *pEntry;=0D + UINTN Processed;=0D +=0D + Status =3D QemuFwCfgFindFile ("etc/memmap", &FwCfgItem, &FwCfgSize);=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_ERROR, "%a %d read etc/memmap error Status %d \n", __fun= c__, __LINE__, Status));=0D + return ;=0D + }=0D + if (FwCfgSize % sizeof MemoryMapEntry !=3D 0) {=0D + DEBUG ((DEBUG_ERROR, "no MemoryMapEntry FwCfgSize:%d\n", FwCfgSize));= =0D + return ;=0D + }=0D +=0D + QemuFwCfgSelectItem (FwCfgItem);=0D + StartEntry =3D AllocatePages (EFI_SIZE_TO_PAGES (FwCfgSize));=0D + QemuFwCfgReadBytes (FwCfgSize, StartEntry);=0D + for (Processed =3D 0; Processed < (FwCfgSize / sizeof MemoryMapEntry); P= rocessed++) {=0D + pEntry =3D StartEntry + Processed;=0D + if (pEntry->Length =3D=3D 0) {=0D + continue;=0D + }=0D +=0D + DEBUG ((DEBUG_INFO, "MemmapEntry Base %p length %p type %d\n", pEntry= ->BaseAddr, pEntry->Length, pEntry->Type));=0D + if (pEntry->Type !=3D EfiAcpiAddressRangeMemory) {=0D + continue;=0D + }=0D +=0D + AddMemoryRangeHob ( pEntry->BaseAddr, pEntry->BaseAddr + pEntry->Lengt= h);=0D + }=0D +}=0D diff --git a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/Platform.c b/Pl= atform/Loongson/LoongArchQemuPkg/PlatformPei/Platform.c=0D new file mode 100644=0D index 0000000000..262e2750e4=0D --- /dev/null=0D +++ b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/Platform.c=0D @@ -0,0 +1,261 @@=0D +/** @file=0D + Platform PEI driver=0D +=0D + Copyright (c) 2022 Loongson Technology Corporation Limited. All rights r= eserved.
=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D + @par Glossary:=0D + - Mem - Memory=0D +**/=0D +=0D +//=0D +// The package level header files this module uses=0D +//=0D +#include =0D +//=0D +// The Library classes this module consumes=0D +//=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +=0D +#include "Platform.h"=0D +=0D +/* TODO */=0D +EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] =3D {=0D + { EfiReservedMemoryType, 0x004 },=0D + { EfiRuntimeServicesData, 0x024 },=0D + { EfiRuntimeServicesCode, 0x030 },=0D + { EfiBootServicesCode, 0x180 },=0D + { EfiBootServicesData, 0xF00 },=0D + { EfiMaxMemoryType, 0x000 }=0D +};=0D +=0D +//=0D +// Module globals=0D +//=0D +CONST EFI_PEI_PPI_DESCRIPTOR mPpiListBootMode =3D {=0D + (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),=0D + &gEfiPeiMasterBootModePpiGuid,=0D + NULL=0D +};=0D +=0D +/**=0D + Create Reserved type memory range hand off block.=0D +=0D + @param MemoryBase memory base address.=0D + @param MemoryLimit memory length.=0D +=0D + @return VOID=0D +**/=0D +VOID=0D +AddReservedMemoryBaseSizeHob (=0D + EFI_PHYSICAL_ADDRESS MemoryBase,=0D + UINT64 MemorySize=0D + )=0D +{=0D + BuildResourceDescriptorHob (=0D + EFI_RESOURCE_MEMORY_RESERVED,=0D + EFI_RESOURCE_ATTRIBUTE_PRESENT |=0D + EFI_RESOURCE_ATTRIBUTE_INITIALIZED |=0D + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |=0D + EFI_RESOURCE_ATTRIBUTE_TESTED,=0D + MemoryBase,=0D + MemorySize=0D + );=0D +}=0D +/**=0D + Create system type memory range hand off block.=0D +=0D + @param MemoryBase memory base address.=0D + @param MemoryLimit memory length.=0D +=0D + @return VOID=0D +**/=0D +VOID=0D +AddMemoryBaseSizeHob (=0D + EFI_PHYSICAL_ADDRESS MemoryBase,=0D + UINT64 MemorySize=0D + )=0D +{=0D + BuildResourceDescriptorHob (=0D + EFI_RESOURCE_SYSTEM_MEMORY,=0D + EFI_RESOURCE_ATTRIBUTE_PRESENT |=0D + EFI_RESOURCE_ATTRIBUTE_INITIALIZED |=0D + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |=0D + EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |=0D + EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |=0D + EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |=0D + EFI_RESOURCE_ATTRIBUTE_TESTED,=0D + MemoryBase,=0D + MemorySize=0D + );=0D +}=0D +=0D +/**=0D + Create memory range hand off block.=0D +=0D + @param MemoryBase memory base address.=0D + @param MemoryLimit memory length.=0D +=0D + @return VOID=0D +**/=0D +VOID=0D +AddMemoryRangeHob (=0D + EFI_PHYSICAL_ADDRESS MemoryBase,=0D + EFI_PHYSICAL_ADDRESS MemoryLimit=0D + )=0D +{=0D + AddMemoryBaseSizeHob (MemoryBase, (UINT64) (MemoryLimit - MemoryBase));= =0D +}=0D +/**=0D + Create memory type information hand off block.=0D +=0D + @param VOID=0D +=0D + @return VOID=0D +**/=0D +VOID=0D +MemMapInitialization (=0D + VOID=0D + )=0D +{=0D + DEBUG ((DEBUG_INFO, "=3D=3D%a=3D=3D\n", __func__));=0D + //=0D + // Create Memory Type Information HOB=0D + //=0D + BuildGuidDataHob (=0D + &gEfiMemoryTypeInformationGuid,=0D + mDefaultMemoryTypeInformation,=0D + sizeof (mDefaultMemoryTypeInformation)=0D + );=0D +}=0D +=0D +/**=0D + Misc Initialization.=0D +=0D + @param VOID=0D +=0D + @return VOID=0D +**/=0D +VOID=0D +MiscInitialization (=0D + VOID=0D + )=0D +{=0D + DEBUG ((DEBUG_INFO, "=3D=3D%a=3D=3D\n", __func__));=0D + //=0D + // Creat CPU HOBs.=0D + //=0D + BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize= ));=0D +}=0D +/**=0D + add fdt hand off block.=0D +=0D + @param VOID=0D +=0D + @return VOID=0D +**/=0D +VOID=0D +AddFdtHob (VOID)=0D +{=0D + VOID *Base;=0D + VOID *NewBase;=0D + UINTN FdtSize;=0D + UINTN FdtPages;=0D + UINT64 *FdtHobData;=0D +=0D + Base =3D (VOID*)(UINTN)PcdGet64 (PcdDeviceTreeBase);=0D + ASSERT (Base !=3D NULL);=0D +=0D + FdtSize =3D fdt_totalsize (Base) + PcdGet32 (PcdDeviceTreePadding);=0D + FdtPages =3D EFI_SIZE_TO_PAGES (FdtSize);=0D + NewBase =3D AllocatePages (FdtPages);=0D + ASSERT (NewBase !=3D NULL);=0D + fdt_open_into (Base, NewBase, EFI_PAGES_TO_SIZE (FdtPages));=0D +=0D + FdtHobData =3D BuildGuidHob (&gFdtHobGuid, sizeof *FdtHobData);=0D + ASSERT (FdtHobData !=3D NULL);=0D + *FdtHobData =3D (UINTN)NewBase;=0D +}=0D +=0D +/**=0D + Fetch the size of system memory from QEMU.=0D +=0D + @param VOID=0D +=0D + @return VOID=0D +**/=0D +VOID=0D +SystemMemorySizeInitialization (=0D + VOID=0D + )=0D +{=0D + UINT64 RamSize;=0D + RETURN_STATUS PcdStatus;=0D +=0D + QemuFwCfgSelectItem (QemuFwCfgItemRamSize);=0D + RamSize=3D QemuFwCfgRead64 ();=0D + DEBUG ((DEBUG_INFO, "%a: QEMU reports %dM system memory\n", __FUNCTION__= ,=0D + RamSize/1024/1024));=0D +=0D + //=0D + // If the fw_cfg key or fw_cfg entirely is unavailable, no change to PCD= .=0D + //=0D + if (RamSize =3D=3D 0) {=0D + return;=0D + }=0D +=0D + //=0D + // Otherwise, set RamSize to PCD.=0D + //=0D + PcdStatus =3D PcdSet64S (PcdRamSize, RamSize);=0D + ASSERT_RETURN_ERROR (PcdStatus);=0D +}=0D +=0D +/**=0D + Perform Platform PEI initialization.=0D +=0D + @param FileHandle Handle of the file being invoked.=0D + @param PeiServices Describes the list of possible PEI Services.=0D +=0D + @return EFI_SUCCESS The PEIM initialized successfully.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +InitializePlatform (=0D + IN EFI_PEI_FILE_HANDLE FileHandle,=0D + IN CONST EFI_PEI_SERVICES **PeiServices=0D + )=0D +{=0D + EFI_STATUS Status;=0D +=0D + DEBUG ((DEBUG_INFO, "Platform PEIM Loaded\n"));=0D +=0D + Status =3D PeiServicesInstallPpi (&mPpiListBootMode);=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + SystemMemorySizeInitialization ();=0D + PublishPeiMemory ();=0D + PeiFvInitialization ();=0D + InitializeRamRegions ();=0D + MemMapInitialization ();=0D + MiscInitialization ();=0D + AddFdtHob ();=0D + ConfigureMmu ();=0D +=0D + return EFI_SUCCESS;=0D +}=0D diff --git a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/Platform.h b/Pl= atform/Loongson/LoongArchQemuPkg/PlatformPei/Platform.h=0D new file mode 100644=0D index 0000000000..38d358b335=0D --- /dev/null=0D +++ b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/Platform.h=0D @@ -0,0 +1,86 @@=0D +/** @file=0D + Platform PEI module include file.=0D +=0D + Copyright (c) 2022 Loongson Technology Corporation Limited. All rights r= eserved.
=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#ifndef PLATFORM_H_=0D +#define PLATFORM_H_=0D +=0D +#include =0D +=0D +/**=0D + Create system type memory range hand off block.=0D +=0D + @param MemoryBase memory base address.=0D + @param MemoryLimit memory length.=0D +=0D + @return VOID=0D +**/=0D +VOID=0D +AddMemoryBaseSizeHob (=0D + EFI_PHYSICAL_ADDRESS MemoryBase,=0D + UINT64 MemorySize=0D + );=0D +=0D +/**=0D + Create memory range hand off block.=0D +=0D + @param MemoryBase memory base address.=0D + @param MemoryLimit memory length.=0D +=0D + @return VOID=0D +**/=0D +VOID=0D +AddMemoryRangeHob (=0D + EFI_PHYSICAL_ADDRESS MemoryBase,=0D + EFI_PHYSICAL_ADDRESS MemoryLimit=0D + );=0D +=0D +/**=0D + Create Reserved type memory range hand off block.=0D +=0D + @param MemoryBase memory base address.=0D + @param MemoryLimit memory length.=0D +=0D + @return VOID=0D +**/=0D +VOID=0D +AddReservedMemoryBaseSizeHob (=0D + EFI_PHYSICAL_ADDRESS MemoryBase,=0D + UINT64 MemorySize=0D + );=0D +/**=0D + Publish PEI core memory=0D +=0D + @return EFI_SUCCESS The PEIM initialized successfully.=0D +**/=0D +EFI_STATUS=0D +PublishPeiMemory (=0D + VOID=0D + );=0D +/**=0D + Publish system RAM and reserve memory regions=0D +=0D + @return VOID=0D +**/=0D +VOID=0D +InitializeRamRegions (=0D + VOID=0D + );=0D +=0D +/**=0D + Publish PEI & DXE (Decompressed) Memory based FVs to let PEI=0D + and DXE know about them.=0D +=0D + @retval EFI_SUCCESS Platform PEI FVs were initialized successfully.=0D +**/=0D +EFI_STATUS=0D +PeiFvInitialization (=0D + VOID=0D + );=0D +=0D +#endif // PLATFORM_H_=0D diff --git a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf= b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf=0D new file mode 100644=0D index 0000000000..417c5e586a=0D --- /dev/null=0D +++ b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf=0D @@ -0,0 +1,72 @@=0D +## @file=0D +# Platform PEI driver=0D +#=0D +# Copyright (c) 2022 Loongson Technology Corporation Limited. All rights = reserved.
=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D PlatformPei=0D + FILE_GUID =3D 4c0e81e5-e8e3-4eef-b24b-19b686e9ab53= =0D + MODULE_TYPE =3D PEIM=0D + VERSION_STRING =3D 1.0=0D + ENTRY_POINT =3D InitializePlatform=0D +=0D +#=0D +# VALID_ARCHITECTURES =3D LOONGARCH64=0D +#=0D +=0D +[Sources]=0D + Fv.c=0D + MemDetect.c=0D + Platform.c=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + MdeModulePkg/MdeModulePkg.dec=0D + EmbeddedPkg/EmbeddedPkg.dec=0D + Platform/Loongson/LoongArchQemuPkg/Loongson.dec=0D + OvmfPkg/OvmfPkg.dec=0D +=0D +[Ppis]=0D + gEfiPeiMasterBootModePpiGuid=0D +=0D +[Guids]=0D + gEfiMemoryTypeInformationGuid=0D + gFdtHobGuid=0D +=0D +[LibraryClasses]=0D + DebugLib=0D + BaseMemoryLib=0D + HobLib=0D + IoLib=0D + PeiResourcePublicationLib=0D + PeiServicesLib=0D + PeiServicesTablePointerLib=0D + PeimEntryPoint=0D + QemuFwCfgLib=0D + PcdLib=0D + TimerLib=0D + MmuLib=0D + MemoryAllocationLib=0D +=0D +[Pcd]=0D + gLoongArchQemuPkgTokenSpaceGuid.PcdRamSize=0D + gLoongArchQemuPkgTokenSpaceGuid.PcdDeviceTreeBase=0D + gLoongArchQemuPkgTokenSpaceGuid.PcdDeviceTreePadding=0D +=0D +[FixedPcd]=0D + gLoongArchQemuPkgTokenSpaceGuid.PcdFlashDxeFvBase=0D + gLoongArchQemuPkgTokenSpaceGuid.PcdFlashDxeFvSize=0D + gLoongArchQemuPkgTokenSpaceGuid.PcdRamRegionsBottom=0D + gLoongArchQemuPkgTokenSpaceGuid.PcdUefiRamTop=0D + gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamBase=0D + gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamSize=0D + gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize=0D + gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize=0D +=0D +[Depex]=0D + TRUE=0D -- =0D 2.31.1=0D =0D