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.web10.75329.1656957203238433270 for ; Mon, 04 Jul 2022 10:53:23 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=T5PdSC3m; 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 C1A36B81187; Mon, 4 Jul 2022 17:53:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1BCE9C341D1; Mon, 4 Jul 2022 17:53:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1656957201; bh=nbdVGTalB2AtVaSfg0pbaFimLKSJVc2/L03cjAhhntE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T5PdSC3mCaagYn0JwfYTUvu2VDTa6vLMRHEYERmIl97J4qGk8YzQOttA8392DFmYG PpUhhnALUlJE4FZ15GICj8Cucwb1MvDW20R6ZReZ0wBO1ucIYjHd4ZWnbVLe3rogyy smurotUFvUClAsA6ya+GccqJU/ku2dZcNQlLsMgIBoaYpr5+yHCXQm/U013pP0sdSE XzzFoV+o7sRr1KFa3nT/GM0FhYaOo+vqdFz/5iDBi2395grjUQaGV5POUQrVWRDQuF bSOIkYRA9O0Tpj/iDdcdutxrb4BPaQISaYacT1G9P/S1pcLl+wohWyvwrvTbKoCWBZ WT3ZhmtcZGWrg== From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: quic_llindhol@quicinc.com, sami.mujawar@arm.com, Ard Biesheuvel , Marc Zyngier , Alexander Graf Subject: [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> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220704175252.4015120-1-ardb@kernel.org> References: <20220704175252.4015120-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 | 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=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 +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 PcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory);= =0D + Info[1].Type =3D EfiACPIMemoryNVS;=0D + Info[1].NumberOfPages =3D PcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS);=0D + Info[2].Type =3D EfiReservedMemoryType;=0D + Info[2].NumberOfPages =3D PcdGet32 (PcdMemoryTypeEfiReservedMemoryType);= =0D + Info[3].Type =3D EfiRuntimeServicesData;=0D + Info[3].NumberOfPages =3D PcdGet32 (PcdMemoryTypeEfiRuntimeServicesData)= ;=0D + Info[4].Type =3D EfiRuntimeServicesCode;=0D + Info[4].NumberOfPages =3D PcdGet32 (PcdMemoryTypeEfiRuntimeServicesCode)= ;=0D + Info[5].Type =3D EfiBootServicesCode;=0D + Info[5].NumberOfPages =3D PcdGet32 (PcdMemoryTypeEfiBootServicesCode);=0D + Info[6].Type =3D EfiBootServicesData;=0D + Info[6].NumberOfPages =3D PcdGet32 (PcdMemoryTypeEfiBootServicesData);=0D + Info[7].Type =3D EfiLoaderCode;=0D + Info[7].NumberOfPages =3D PcdGet32 (PcdMemoryTypeEfiLoaderCode);=0D + Info[8].Type =3D EfiLoaderData;=0D + Info[8].NumberOfPages =3D PcdGet32 (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 +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 (PcdGet64 (PcdSystemMemorySize) >=3D SIZE_128MB);=0D + ASSERT (PcdGet64 (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)PcdGet64 (PcdSystemMemoryBase) + SIZE_128MB=0D + - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);=0D +=0D + Status =3D PeiServicesInstallPeiMemory (UefiMemoryBase,=0D + FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + Status =3D MemoryPeim (UefiMemoryBase,=0D + FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));=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..4c56b15bd342 --- /dev/null +++ b/ArmVirtPkg/MemoryInitPei/MemoryInitPeim.inf @@ -0,0 +1,66 @@ +#/** @file=0D +#=0D +# Copyright (c) 2011-2014, ARM Ltd. All rights reserved.
=0D +# Copyright (c) 2022, Google LLC. All rights reserved.
=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 +=0D + ENTRY_POINT =3D InitializeMemory=0D +=0D +#=0D +# The following information is for reference only and not required by the = build tools.=0D +#=0D +# VALID_ARCHITECTURES =3D IA32 X64 EBC ARM=0D +#=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 + 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 +[Pcd]=0D + gArmTokenSpaceGuid.PcdSystemMemoryBase=0D + gArmTokenSpaceGuid.PcdSystemMemorySize=0D +=0D +[Depex]=0D + TRUE=0D --=20 2.35.1