From nobody Sun Feb 8 19:39:43 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+91041+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+91041+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1656957205; cv=none; d=zohomail.com; s=zohoarc; b=GYiPWqv+k0cevS4ARmldVdpsVOVvFDvlPve1GIJYDyiNR87lNC9gY9YbbhjdzMRjGMd7pYG4twKU3EHESnvMhxyXlDEs8jaUFWTCvpYPZeFksd1DPq7JXZWU9LpqauWm5iDls5cilEj5LYrm9odrqVxT6eTc06pS4c8N/zjMgtw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656957205; 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=0oLb95uful7jy6lE3v24OsODcxBv5f874xelS7P7Np4=; b=YU3eVF2TfCmfqG1jeb+xPhIyhiiCrHnKMJnAigd+rMT0XhRv9pZNMFnjeF4dtWG86WLfwPf8f7QCNe3Pk+KtwogywetKB8TpIZRunDd7oHEdw8n380WDUf7pIqkx/wBrZ+JeR5s04eOyhayiWm8YL/QhvED8IUcKmL9zbfHjCps= 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+91041+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 1656957205414603.1356212809213; Mon, 4 Jul 2022 10:53:25 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id KiMpYY1788612x77SO2bbCY2; Mon, 04 Jul 2022 10:53:24 -0700 X-Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by mx.groups.io with SMTP id smtpd.web10.75329.1656957203238433270 for ; Mon, 04 Jul 2022 10:53:23 -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 ams.source.kernel.org (Postfix) with ESMTPS id C1A36B81187; Mon, 4 Jul 2022 17:53:21 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1BCE9C341D1; Mon, 4 Jul 2022 17:53:19 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: quic_llindhol@quicinc.com, sami.mujawar@arm.com, Ard Biesheuvel , Marc Zyngier , Alexander Graf Subject: [edk2-devel] [PATCH 6/7] ArmVirtPkg/ArmVirtQemu: use first 128 MiB as permanent PEI memory Date: Mon, 4 Jul 2022 19:52:51 +0200 Message-Id: <20220704175252.4015120-7-ardb@kernel.org> In-Reply-To: <20220704175252.4015120-1-ardb@kernel.org> References: <20220704175252.4015120-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: 1OwdnVr8rnl9qXbwNeWR5umlx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656957204; bh=Tr/pcXYL46m/eRvTWTOTE49OhtR9WYONnDev9h0fmf4=; h=Cc:Date:From:Reply-To:Subject:To; b=RXxuBOKCGb2JBzed3v3CTGW1J9gyL8W3K/dXJJkLbOS4seGvCpBx8PlRR4aIoPWBOSP ZKQAU45T228wMlnA/U7d6IHB+hdCadUjdEcyHptIh35ncCderRv0bAfJSRwxrKjUXLWEz jks974vzqaKbBaI1T82FJjeUwpOcIGYYPl4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656957206930100014 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 | 89 ++++++++++++++++++++ ArmVirtPkg/MemoryInitPei/MemoryInitPeim.inf | 66 +++++++++++++++ 2 files changed, 155 insertions(+) diff --git a/ArmVirtPkg/MemoryInitPei/MemoryInitPeim.c b/ArmVirtPkg/MemoryI= nitPei/MemoryInitPeim.c new file mode 100644 index 000000000000..a48830396e48 --- /dev/null +++ b/ArmVirtPkg/MemoryInitPei/MemoryInitPeim.c @@ -0,0 +1,89 @@ +/** @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 + ); + +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)); +} + +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..4c56b15bd342 --- /dev/null +++ b/ArmVirtPkg/MemoryInitPei/MemoryInitPeim.inf @@ -0,0 +1,66 @@ +#/** @file +# +# 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 (#91041): https://edk2.groups.io/g/devel/message/91041 Mute This Topic: https://groups.io/mt/92170211/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-