From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iIsXUmDG; spf=pass (domain: kernel.org, ip: 139.178.84.217, 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 dfw.source.kernel.org (Postfix) with ESMTPS id 2C73D6154C; Tue, 6 Sep 2022 15:06:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9471FC433D6; Tue, 6 Sep 2022 15:06:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1662476815; bh=8Zpot5fCSBVPQ6/amSo+PGQ17EpKnqZUfveedoChmtE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iIsXUmDGt9JbUH88uLywokR/NLKL/J74BQ7YuJiiwMMoiiHen+rZTSh+8Ap+Z3i2R F4BrUxPjcAKl7l0cY7+GdL9w8CIQBDn4b/RkHRTqq35zfGKxJnke3kvT8qnlQs/fif Ul5Dt8MRivoPH1mJvLyTC/2EGC7/MrtR507myZ+jv4xs5voM+o8BSk9RcOdzYlPhXN zYyOy+lMUUAGjtmG/JfALC5KytPNB4c0J1zquw8yt8zRSkC1TovQFLkiMcpJB+qlR1 B7epWChgR+qd0Tb6FrWDKuAN6P06O+dma1OAxpXocuvfeubjhQXxtRAsId9VeyCXmE YMf+xyPNthc9g== From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: quic_llindhol@quicinc.com, sami.mujawar@arm.com, Ard Biesheuvel Subject: [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> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220906150639.157227-1-ardb@kernel.org> References: <20220906150639.157227-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 | 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=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 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 +/**=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 (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 (=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..f4492719c350 --- /dev/null +++ b/ArmVirtPkg/MemoryInitPei/MemoryInitPeim.inf @@ -0,0 +1,68 @@ +## @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 +#=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