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.web09.26236.1664180734504824694 for ; Mon, 26 Sep 2022 01:25:34 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eKpvEmzl; 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 E2C4461908; Mon, 26 Sep 2022 08:25:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6B7CC433D7; Mon, 26 Sep 2022 08:25:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664180733; bh=vIpcAgQ1Hc1H1HKjDi7RZCfY8QKUpmzSp7Ok/ow1+No=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eKpvEmzl+smpzq9SVH94a/vTdsjgoz9tGfNb4JBAGxMeJWMk5KVvj/vTOYOrAlWSm tjGzOzwd3AwEdyoM/QqzshG4VAGJTtON8qJDTt3m1mtycfveMOONUu1BDzCjUWq9P/ SJrcz3cTAAdvbEcjyOYEeylMf6uoPNnQtxcPw7ARrtk8wkRXMgsnGXkYDGLso7AW3k XWa4FXnJ5OzU4Lu1MW7OjvutDhc7/p9NIhKmZ2zXiBkT+R3nJJ1itkSsOhIoeDazxr N+FAcIvIu1lJ9mhOZFuD5TKiZ4wTYZMnaRo5P5fXraBd/MZi6OYtzmB1oHSb6NeNe2 4FWb7tCxQHfMQ== From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Leif Lindholm , Alexander Graf Subject: [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> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220926082511.2110797-1-ardb@kernel.org> References: <20220926082511.2110797-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 | 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=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 FixedPcdGet32 (PcdMemoryTypeEfiACPIReclaimMemo= ry);=0D + Info[1].Type =3D EfiACPIMemoryNVS;=0D + Info[1].NumberOfPages =3D FixedPcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS);= =0D + Info[2].Type =3D EfiReservedMemoryType;=0D + Info[2].NumberOfPages =3D FixedPcdGet32 (PcdMemoryTypeEfiReservedMemoryT= ype);=0D + Info[3].Type =3D EfiRuntimeServicesData;=0D + Info[3].NumberOfPages =3D FixedPcdGet32 (PcdMemoryTypeEfiRuntimeServices= Data);=0D + Info[4].Type =3D EfiRuntimeServicesCode;=0D + Info[4].NumberOfPages =3D FixedPcdGet32 (PcdMemoryTypeEfiRuntimeServices= Code);=0D + Info[5].Type =3D EfiBootServicesCode;=0D + Info[5].NumberOfPages =3D FixedPcdGet32 (PcdMemoryTypeEfiBootServicesCod= e);=0D + Info[6].Type =3D EfiBootServicesData;=0D + Info[6].NumberOfPages =3D FixedPcdGet32 (PcdMemoryTypeEfiBootServicesDat= a);=0D + Info[7].Type =3D EfiLoaderCode;=0D + Info[7].NumberOfPages =3D FixedPcdGet32 (PcdMemoryTypeEfiLoaderCode);=0D + Info[8].Type =3D EfiLoaderData;=0D + Info[8].NumberOfPages =3D FixedPcdGet32 (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 (FixedPcdGet64 (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)FixedPcdGet64 (PcdSystemMemoryBase) + SIZE_128= MB=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..2039f71a0ebe --- /dev/null +++ b/ArmVirtPkg/MemoryInitPei/MemoryInitPeim.inf @@ -0,0 +1,59 @@ +## @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 +[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 + gArmTokenSpaceGuid.PcdSystemMemoryBase=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 +[Depex]=0D + TRUE=0D --=20 2.35.1