From nobody Mon Feb 9 16:32:52 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+93237+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+93237+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1662476817; cv=none; d=zohomail.com; s=zohoarc; b=YiYikTJ4F4I5ew95T+2H4j1y4HbFY6gPM1N02TvMkB4i5Drzh2rx+S3lcfblU7I23aoM3lwiZOxLzhZhiSjYrI3VGSV9YYN7sp+Y1Gh8UNhScTCEilP2/J7qBTxU/VM3+kN05sX+GXVWJMOeTSTeWBI8ZvyIg+kSvrirzjQ1bL4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662476817; 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=3gCk4ekzU+hZMqSTtYLCxFGJuXEHMHCTK26O09DYMak=; b=HJDRH1GitNL60ym92hg/nl62LMiuF+GvjNixeeGenMHjPvBvC2olN9FFfWjRK2mCXpNesSy73Ih3NQoM7+Tcb2SkaETKEGMgUnyJl2dGzkSxWj8jG8yqb4UGV49viJG/fNyJjPUfx79MYJmzqHNmcwl9AJogQNPhg2eaTXioYIc= 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+93237+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 1662476817845266.7858517860923; Tue, 6 Sep 2022 08:06:57 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id SViyYY1788612xVeQgnqeJu0; Tue, 06 Sep 2022 08:06:57 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.241.1662476816790671295 for ; Tue, 06 Sep 2022 08:06:56 -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 2C73D6154C; Tue, 6 Sep 2022 15:06:56 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9471FC433D6; Tue, 6 Sep 2022 15:06:54 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: quic_llindhol@quicinc.com, sami.mujawar@arm.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH v2 6/7] ArmVirtPkg/ArmVirtQemu: use first 128 MiB as permanent PEI memory Date: Tue, 6 Sep 2022 17:06:38 +0200 Message-Id: <20220906150639.157227-7-ardb@kernel.org> In-Reply-To: <20220906150639.157227-1-ardb@kernel.org> References: <20220906150639.157227-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: khwRk7b7Iy2ViTfMjV1Qm2uSx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1662476817; bh=xTrBL/BRVh+8EJ8UHV3dAAO5mm2UYKtQVgY4LMGgPk0=; h=Cc:Date:From:Reply-To:Subject:To; b=WM2HSrnlFrm7Wl0tQoP0sLlWx2nhqLD9cab3D5PpTwG0es9tayAfoDTvg8O8vikOlDy MezP79ow3pC2ooZWAQIsoT/K0a/6Abp0J/eMY6RGOqUrc9VIVkK3oFhPaA0iVKCDHGybX MJEvzMa1Gy0ZRGqvKd5awF1tmz29n2LzkYQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1662476818298100023 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 | 105 ++++++++++++++++++++ ArmVirtPkg/MemoryInitPei/MemoryInitPeim.inf | 68 +++++++++++++ 2 files changed, 173 insertions(+) diff --git a/ArmVirtPkg/MemoryInitPei/MemoryInitPeim.c b/ArmVirtPkg/MemoryI= nitPei/MemoryInitPeim.c new file mode 100644 index 000000000000..d61fa55efaaa --- /dev/null +++ b/ArmVirtPkg/MemoryInitPei/MemoryInitPeim.c @@ -0,0 +1,105 @@ +/** @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 PcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory); + Info[1].Type =3D EfiACPIMemoryNVS; + Info[1].NumberOfPages =3D PcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS); + Info[2].Type =3D EfiReservedMemoryType; + Info[2].NumberOfPages =3D PcdGet32 (PcdMemoryTypeEfiReservedMemoryType); + Info[3].Type =3D EfiRuntimeServicesData; + Info[3].NumberOfPages =3D PcdGet32 (PcdMemoryTypeEfiRuntimeServicesData); + Info[4].Type =3D EfiRuntimeServicesCode; + Info[4].NumberOfPages =3D PcdGet32 (PcdMemoryTypeEfiRuntimeServicesCode); + Info[5].Type =3D EfiBootServicesCode; + Info[5].NumberOfPages =3D PcdGet32 (PcdMemoryTypeEfiBootServicesCode); + Info[6].Type =3D EfiBootServicesData; + Info[6].NumberOfPages =3D PcdGet32 (PcdMemoryTypeEfiBootServicesData); + Info[7].Type =3D EfiLoaderCode; + Info[7].NumberOfPages =3D PcdGet32 (PcdMemoryTypeEfiLoaderCode); + Info[8].Type =3D EfiLoaderData; + Info[8].NumberOfPages =3D PcdGet32 (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 (PcdGet64 (PcdSystemMemorySize) >=3D SIZE_128MB); + ASSERT (PcdGet64 (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)PcdGet64 (PcdSystemMemoryBase) + SIZE_128MB + - 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..f4492719c350 --- /dev/null +++ b/ArmVirtPkg/MemoryInitPei/MemoryInitPeim.inf @@ -0,0 +1,68 @@ +## @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 + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 EBC ARM +# + +[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] + gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize + + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData + +[Pcd] + gArmTokenSpaceGuid.PcdSystemMemoryBase + gArmTokenSpaceGuid.PcdSystemMemorySize + +[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 (#93237): https://edk2.groups.io/g/devel/message/93237 Mute This Topic: https://groups.io/mt/93503046/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-