From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by mx.groups.io with SMTP id smtpd.web08.5944.1666171356243007568 for ; Wed, 19 Oct 2022 02:22:36 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NEzOKtDx; spf=pass (domain: kernel.org, ip: 145.40.68.75, mailfrom: ardb@kernel.org) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A82D7B80D47; Wed, 19 Oct 2022 09:22:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04ECDC433C1; Wed, 19 Oct 2022 09:22:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666171354; bh=vIpcAgQ1Hc1H1HKjDi7RZCfY8QKUpmzSp7Ok/ow1+No=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NEzOKtDxB4CV4dJQ2/I0qUUFIannxpIQzelwj+kpS2ZTtun+vmCpkMSGT7p7odqzu IMHSoFk1CK5kToBOQbVejJxNO9oAFX2abOM+O5UDIhoJrJtfNM53zgSM31Ft+odDjt Od66vgAgHsYn3wPLHaQt84TWFVWhMdmrPU/uGOSNY21TVtcngPmrG1GUrfKVyv2Dcy vQlNspw60yqlU24i7X8hxiuJVheisggjqa694h1EkIeabI9Dogy+REEKkSTYEFB642 OVrX1g5uml2yugjR+RRj4rQc6aWLdxGLp0wfBPTs0ZgCgP6rcT4Q4G9HBpfoa+iKp/ bxcG51MEMmDuw== From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Leif Lindholm , Alexander Graf , Gerd Hoffmann , Sami Mujawar Subject: [PATCH v3 resend 06/11] ArmVirtPkg/ArmVirtQemu: use first 128 MiB as permanent PEI memory Date: Wed, 19 Oct 2022 11:22:06 +0200 Message-Id: <20221019092211.465699-7-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221019092211.465699-1-ardb@kernel.org> References: <20221019092211.465699-1-ardb@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In order to allow booting with the MMU and caches enabled really early, we need to ensure that the code that populates the page tables can access those page tables with the statically defined ID map active. So let's put the permanent PEI RAM in the first 128 MiB of memory, which we will cover with this initial ID map (as it is the minimum supported DRAM size for ArmVirtQemu). Signed-off-by: Ard Biesheuvel --- ArmVirtPkg/MemoryInitPei/MemoryInitPeim.c | 104 ++++++++++++++++++++ ArmVirtPkg/MemoryInitPei/MemoryInitPeim.inf | 59 +++++++++++ 2 files changed, 163 insertions(+) diff --git a/ArmVirtPkg/MemoryInitPei/MemoryInitPeim.c b/ArmVirtPkg/MemoryI= nitPei/MemoryInitPeim.c new file mode 100644 index 000000000000..ef88a9df1d62 --- /dev/null +++ b/ArmVirtPkg/MemoryInitPei/MemoryInitPeim.c @@ -0,0 +1,104 @@ +/** @file=0D +=0D + Copyright (c) 2011, ARM Limited. All rights reserved.=0D + Copyright (c) 2022, Google LLC. All rights reserved.=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +=0D +EFI_STATUS=0D +EFIAPI=0D +MemoryPeim (=0D + IN EFI_PHYSICAL_ADDRESS UefiMemoryBase,=0D + IN UINT64 UefiMemorySize=0D + );=0D +=0D +/**=0D + Build the memory type information HOB that describes how many pages of e= ach=0D + type to preallocate when initializing the GCD memory map.=0D +**/=0D +VOID=0D +EFIAPI=0D +BuildMemoryTypeInformationHob (=0D + VOID=0D + )=0D +{=0D + EFI_MEMORY_TYPE_INFORMATION Info[10];=0D +=0D + Info[0].Type =3D EfiACPIReclaimMemory;=0D + Info[0].NumberOfPages =3D FixedPcdGet32 (PcdMemoryTypeEfiACPIReclaimMemo= ry);=0D + Info[1].Type =3D EfiACPIMemoryNVS;=0D + Info[1].NumberOfPages =3D FixedPcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS);= =0D + Info[2].Type =3D EfiReservedMemoryType;=0D + Info[2].NumberOfPages =3D FixedPcdGet32 (PcdMemoryTypeEfiReservedMemoryT= ype);=0D + Info[3].Type =3D EfiRuntimeServicesData;=0D + Info[3].NumberOfPages =3D FixedPcdGet32 (PcdMemoryTypeEfiRuntimeServices= Data);=0D + Info[4].Type =3D EfiRuntimeServicesCode;=0D + Info[4].NumberOfPages =3D FixedPcdGet32 (PcdMemoryTypeEfiRuntimeServices= Code);=0D + Info[5].Type =3D EfiBootServicesCode;=0D + Info[5].NumberOfPages =3D FixedPcdGet32 (PcdMemoryTypeEfiBootServicesCod= e);=0D + Info[6].Type =3D EfiBootServicesData;=0D + Info[6].NumberOfPages =3D FixedPcdGet32 (PcdMemoryTypeEfiBootServicesDat= a);=0D + Info[7].Type =3D EfiLoaderCode;=0D + Info[7].NumberOfPages =3D FixedPcdGet32 (PcdMemoryTypeEfiLoaderCode);=0D + Info[8].Type =3D EfiLoaderData;=0D + Info[8].NumberOfPages =3D FixedPcdGet32 (PcdMemoryTypeEfiLoaderData);=0D +=0D + // Terminator for the list=0D + Info[9].Type =3D EfiMaxMemoryType;=0D + Info[9].NumberOfPages =3D 0;=0D +=0D + BuildGuidDataHob (&gEfiMemoryTypeInformationGuid, &Info, sizeof (Info));= =0D +}=0D +=0D +/**=0D + Module entry point.=0D +=0D + @param[in] FileHandle Handle of the file being invoked.=0D + @param[in] PeiServices Describes the list of possible PEI Services.= =0D +=0D + @return EFI_SUCCESS unless the operation failed.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +InitializeMemory (=0D + IN EFI_PEI_FILE_HANDLE FileHandle,=0D + IN CONST EFI_PEI_SERVICES **PeiServices=0D + )=0D +{=0D + UINTN UefiMemoryBase;=0D + EFI_STATUS Status;=0D +=0D + ASSERT (FixedPcdGet64 (PcdSystemMemoryBase) < (UINT64)MAX_ALLOC_ADDRESS)= ;=0D +=0D + //=0D + // Put the permanent PEI memory in the first 128 MiB of DRAM so that=0D + // it is covered by the statically configured ID map.=0D + //=0D + UefiMemoryBase =3D (UINTN)FixedPcdGet64 (PcdSystemMemoryBase) + SIZE_128= MB=0D + - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);=0D +=0D + Status =3D PeiServicesInstallPeiMemory (=0D + UefiMemoryBase,=0D + FixedPcdGet32 (PcdSystemMemoryUefiRegionSize)=0D + );=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + Status =3D MemoryPeim (=0D + UefiMemoryBase,=0D + FixedPcdGet32 (PcdSystemMemoryUefiRegionSize)=0D + );=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + return Status;=0D +}=0D diff --git a/ArmVirtPkg/MemoryInitPei/MemoryInitPeim.inf b/ArmVirtPkg/Memor= yInitPei/MemoryInitPeim.inf new file mode 100644 index 000000000000..2039f71a0ebe --- /dev/null +++ b/ArmVirtPkg/MemoryInitPei/MemoryInitPeim.inf @@ -0,0 +1,59 @@ +## @file=0D +# Implementation of MemoryInitPeim that uses the first 128 MiB at the bas= e of=0D +# DRAM as permanent PEI memory=0D +#=0D +# Copyright (c) 2011-2014, ARM Ltd. All rights reserved.
=0D +# Copyright (c) 2022, Google LLC. All rights reserved.
=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 1.27=0D + BASE_NAME =3D MemoryInit=0D + FILE_GUID =3D 0fbffd44-f98f-4e1c-9922-e9b21f13c3f8= =0D + MODULE_TYPE =3D PEIM=0D + VERSION_STRING =3D 1.0=0D + ENTRY_POINT =3D InitializeMemory=0D +=0D +[Sources]=0D + MemoryInitPeim.c=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + MdeModulePkg/MdeModulePkg.dec=0D + EmbeddedPkg/EmbeddedPkg.dec=0D + ArmPkg/ArmPkg.dec=0D + ArmPlatformPkg/ArmPlatformPkg.dec=0D +=0D +[LibraryClasses]=0D + PeimEntryPoint=0D + DebugLib=0D + HobLib=0D + ArmLib=0D + ArmPlatformLib=0D + MemoryInitPeiLib=0D +=0D +[Guids]=0D + gEfiMemoryTypeInformationGuid=0D +=0D +[FeaturePcd]=0D + gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob=0D +=0D +[FixedPcd]=0D + gArmTokenSpaceGuid.PcdSystemMemoryBase=0D + gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize=0D +=0D + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory=0D + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS=0D + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType=0D + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData=0D + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode=0D + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode=0D + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData=0D + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode=0D + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData=0D +=0D +[Depex]=0D + TRUE=0D --=20 2.35.1