From nobody Tue Feb 10 12:45:10 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+94334+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+94334+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1664180735; cv=none; d=zohomail.com; s=zohoarc; b=O+l2z0fc5FtP5UR+EuAndbMU+ujUEmovVZmvxsyd9DaUN63plGPqHeZ1SSL3iyS1TpM5HxXHZb9xShI5bzvAZ9Kgp7nlpOH65PZOYedCt75aLGTbLNXd6b/ylJL57T/CENSjNIEFDYVeFErMu7PKCLXdf2howhQGfbIr9pkFAZc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664180735; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=hF8Gn4NZFrknocuOCav2qzgRIh9PCCId3gbBiAZ0d7w=; b=hFhjjvDCxwXG6hy1XlxWGRfFOotUnNZr/MCPULK8oyxbdad5OcWmTI4+kcdJtsSTTri7LBtc+LW0rwh4jzpRQa9wNUeh80LGY+sVldJzAEOEPEKOsqoQIfKnr82kkt4bpCCyaCbbria07LTb0JJ/UCgrfvaM8P/wUckFQ8rVNWA= 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+94334+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1664180735970878.4850738465336; Mon, 26 Sep 2022 01:25:35 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id VuN7YY1788612xk1scPi6PN8; Mon, 26 Sep 2022 01:25:35 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web09.26236.1664180734504824694 for ; Mon, 26 Sep 2022 01:25:34 -0700 X-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 dfw.source.kernel.org (Postfix) with ESMTPS id E2C4461908; Mon, 26 Sep 2022 08:25:33 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6B7CC433D7; Mon, 26 Sep 2022 08:25:32 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Leif Lindholm , Alexander Graf Subject: [edk2-devel] [PATCH v3 11/16] ArmVirtPkg/ArmVirtQemu: use first 128 MiB as permanent PEI memory Date: Mon, 26 Sep 2022 10:25:06 +0200 Message-Id: <20220926082511.2110797-12-ardb@kernel.org> In-Reply-To: <20220926082511.2110797-1-ardb@kernel.org> References: <20220926082511.2110797-1-ardb@kernel.org> MIME-Version: 1.0 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,ardb@kernel.org X-Gm-Message-State: DmynYxwhxJx5QnVLduSBfvF3x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1664180735; bh=6bidM8/EHaDAcY+1dtXVVcaeiZRwcFJlf7l0w/LLhr8=; h=Cc:Date:From:Reply-To:Subject:To; b=VCML26X7CbEfHujkf6e74h/g5OTl5B/cHhBe12aclJogMn3041OIPiQNsyVfw50KaLp 7Ri3XCLISOkmhcm25Y/SxL8bBc9vs7W+5ApllV0dGZ5F9eKn3BY6So+RHxbCUJav4wQqC sT53EStU9QwoO8iGozRdxjRzi5PVf4J0C+s= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1664180736388100008 Content-Type: text/plain; charset="utf-8" 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 + + Copyright (c) 2011, ARM Limited. All rights reserved. + Copyright (c) 2022, Google LLC. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include + +EFI_STATUS +EFIAPI +MemoryPeim ( + IN EFI_PHYSICAL_ADDRESS UefiMemoryBase, + IN UINT64 UefiMemorySize + ); + +/** + Build the memory type information HOB that describes how many pages of e= ach + type to preallocate when initializing the GCD memory map. +**/ +VOID +EFIAPI +BuildMemoryTypeInformationHob ( + VOID + ) +{ + EFI_MEMORY_TYPE_INFORMATION Info[10]; + + Info[0].Type =3D EfiACPIReclaimMemory; + Info[0].NumberOfPages =3D FixedPcdGet32 (PcdMemoryTypeEfiACPIReclaimMemo= ry); + Info[1].Type =3D EfiACPIMemoryNVS; + Info[1].NumberOfPages =3D FixedPcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS); + Info[2].Type =3D EfiReservedMemoryType; + Info[2].NumberOfPages =3D FixedPcdGet32 (PcdMemoryTypeEfiReservedMemoryT= ype); + Info[3].Type =3D EfiRuntimeServicesData; + Info[3].NumberOfPages =3D FixedPcdGet32 (PcdMemoryTypeEfiRuntimeServices= Data); + Info[4].Type =3D EfiRuntimeServicesCode; + Info[4].NumberOfPages =3D FixedPcdGet32 (PcdMemoryTypeEfiRuntimeServices= Code); + Info[5].Type =3D EfiBootServicesCode; + Info[5].NumberOfPages =3D FixedPcdGet32 (PcdMemoryTypeEfiBootServicesCod= e); + Info[6].Type =3D EfiBootServicesData; + Info[6].NumberOfPages =3D FixedPcdGet32 (PcdMemoryTypeEfiBootServicesDat= a); + Info[7].Type =3D EfiLoaderCode; + Info[7].NumberOfPages =3D FixedPcdGet32 (PcdMemoryTypeEfiLoaderCode); + Info[8].Type =3D EfiLoaderData; + Info[8].NumberOfPages =3D FixedPcdGet32 (PcdMemoryTypeEfiLoaderData); + + // Terminator for the list + Info[9].Type =3D EfiMaxMemoryType; + Info[9].NumberOfPages =3D 0; + + BuildGuidDataHob (&gEfiMemoryTypeInformationGuid, &Info, sizeof (Info)); +} + +/** + Module entry point. + + @param[in] FileHandle Handle of the file being invoked. + @param[in] PeiServices Describes the list of possible PEI Services. + + @return EFI_SUCCESS unless the operation failed. +**/ +EFI_STATUS +EFIAPI +InitializeMemory ( + IN EFI_PEI_FILE_HANDLE FileHandle, + IN CONST EFI_PEI_SERVICES **PeiServices + ) +{ + UINTN UefiMemoryBase; + EFI_STATUS Status; + + ASSERT (FixedPcdGet64 (PcdSystemMemoryBase) < (UINT64)MAX_ALLOC_ADDRESS); + + // + // Put the permanent PEI memory in the first 128 MiB of DRAM so that + // it is covered by the statically configured ID map. + // + UefiMemoryBase =3D (UINTN)FixedPcdGet64 (PcdSystemMemoryBase) + SIZE_128= MB + - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize); + + Status =3D PeiServicesInstallPeiMemory ( + UefiMemoryBase, + FixedPcdGet32 (PcdSystemMemoryUefiRegionSize) + ); + ASSERT_EFI_ERROR (Status); + + Status =3D MemoryPeim ( + UefiMemoryBase, + FixedPcdGet32 (PcdSystemMemoryUefiRegionSize) + ); + ASSERT_EFI_ERROR (Status); + + return Status; +} 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 +# Implementation of MemoryInitPeim that uses the first 128 MiB at the bas= e of +# DRAM as permanent PEI memory +# +# Copyright (c) 2011-2014, ARM Ltd. All rights reserved.
+# Copyright (c) 2022, Google LLC. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 1.27 + BASE_NAME =3D MemoryInit + FILE_GUID =3D 0fbffd44-f98f-4e1c-9922-e9b21f13c3f8 + MODULE_TYPE =3D PEIM + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D InitializeMemory + +[Sources] + MemoryInitPeim.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + EmbeddedPkg/EmbeddedPkg.dec + ArmPkg/ArmPkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + +[LibraryClasses] + PeimEntryPoint + DebugLib + HobLib + ArmLib + ArmPlatformLib + MemoryInitPeiLib + +[Guids] + gEfiMemoryTypeInformationGuid + +[FeaturePcd] + gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob + +[FixedPcd] + gArmTokenSpaceGuid.PcdSystemMemoryBase + gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize + + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData + +[Depex] + TRUE --=20 2.35.1 -=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 (#94334): https://edk2.groups.io/g/devel/message/94334 Mute This Topic: https://groups.io/mt/93922701/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-