From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by mx.groups.io with SMTP id smtpd.web11.3966.1636590336222896137 for ; Wed, 10 Nov 2021 16:25:36 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@corthon-com.20210112.gappssmtp.com header.s=20210112 header.b=Sy1rgDL9; spf=none, err=permanent DNS error (domain: corthon.com, ip: 209.85.210.182, mailfrom: bret@corthon.com) Received: by mail-pf1-f182.google.com with SMTP id o4so4038115pfp.13 for ; Wed, 10 Nov 2021 16:25:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corthon-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OIBsJk8XlKONrc/eBk/bty9E7xSAuMpAYjWqiOjMKM4=; b=Sy1rgDL95K9dydJK/aGHgje2jFniKa59w7BT3VEEt9fETU0asbI90kD5amlE5FhW3Y DKkej6filYjEbw1f4P9LMr2kCJCKV2xrJsttvedOCOmTJYDfEHQmSr08XrLG5RA9mHIe lu0B1S4NgS+6+IqLT7IveQIZhRBgrJToWZHa6jdpyO4IM5UM/fV5KCjrUs2eWxt2ZA9H sjdRwHLpv4MVNdBnjUM9FaZsk27bXtKqxKKFtAWfuQz4smWVg4bmt29uE6WHedamKGvj eFGI8C4l6kzIIYVP1teGDZqjbkyR3pQzWNtCT2EN+sJjy+DWGksBYwGxOxAUJXxN671F oDJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OIBsJk8XlKONrc/eBk/bty9E7xSAuMpAYjWqiOjMKM4=; b=A73g8AXm7QX4LNllom3/93LC7AuZvPZazbAH/GxryFO37m8wWeAoAuVgdUrCEwF/gN FBhPsaLZP5YrT36X+7+H76ucn/+W+bPSZH9nX4mNgJ+1xorUMIWIAZy7UOflGnYcv68C ShffRGGxWiAu3C7YT1IgCYNuMd6duIIUsXsx5/Im69P3XlHtJY8mtbXTX21qRonZ1roN 1uhfPjUQRzeV1stVRbWrPkYqNUIgu7W3b3jwHwlG0LTq8Wd0l0ADaqXte+lK/e9JK5WO 2ob8ymHsOICMpzP/LvATHR5c0+MI4CggAXO0YpOorzYnteTR8RmiCN/pedPqVNVIh4pD b0bg== X-Gm-Message-State: AOAM531/cRCd9y46JrkO9qGUERb6Haf2b5/IJs4MQzQtnSMM/VKdMUdu cvqLU84OJEf0oN8j6aiRfJyr+sS2gTFjqZBQ X-Google-Smtp-Source: ABdhPJy/OApGlpEzHKZUKc5lB946+sA5mRYFyP4jmrPPHCr+7vCqXBBaGS6TUCOQAKSDWDgj4vobPQ== X-Received: by 2002:a63:2b48:: with SMTP id r69mr1881668pgr.421.1636590335553; Wed, 10 Nov 2021 16:25:35 -0800 (PST) Return-Path: Received: from localhost.localdomain (174-21-94-94.tukw.qwest.net. [174.21.94.94]) by smtp.gmail.com with ESMTPSA id e14sm838890pfv.18.2021.11.10.16.25.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Nov 2021 16:25:35 -0800 (PST) From: "Bret Barkelew" X-Google-Original-From: "brbarkel@microsoft.com" To: devel@edk2.groups.io Cc: Leif Lindholm , Ard Biesheuvel , Sean Brogan Subject: [PATCH v3 09/14] ArmPkg: Add Basic MMU Lib for Arm silicon Date: Wed, 10 Nov 2021 16:24:11 -0800 Message-Id: <20211111002416.1770-10-brbarkel@microsoft.com> X-Mailer: git-send-email 2.31.1.windows.1 In-Reply-To: <20211111002416.1770-1-brbarkel@microsoft.com> References: <20211111002416.1770-1-brbarkel@microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Sean Brogan After adding the abstract MmuLib to MdePkg, add an implementation backed by the existing ArmMmuLib to ArmPkg. This implementation is currently just a shim to the old library, while enabling higher-level code to be more common. REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3651 Cc: Leif Lindholm Cc: Ard Biesheuvel Cc: Sean Brogan Signed-off-by: Bret Barkelew --- ArmPkg/Library/MmuLib/MmuLib.c | 120 ++++++++++++++++++++ ArmPkg/ArmPkg.dsc | 1 + ArmPkg/Library/MmuLib/BaseMmuLib.inf | 30 +++++ 3 files changed, 151 insertions(+) diff --git a/ArmPkg/Library/MmuLib/MmuLib.c b/ArmPkg/Library/MmuLib/MmuLib.c new file mode 100644 index 000000000000..6f3b664971da --- /dev/null +++ b/ArmPkg/Library/MmuLib/MmuLib.c @@ -0,0 +1,120 @@ +/** @file=0D +This library instance implements a very limited MMU Lib instance=0D +for the ARM/AARCH64 architectures. This library shims a common library=0D +interface to the ArmPkg defined ArmMmuLib.ib.=0D +=0D +Copyright (c) Microsoft Corporation.=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include =0D +#include =0D +#include =0D +=0D +/**=0D + Bitwise sets the memory attributes on a range of memory based on an attr= ibutes mask.=0D +=0D + @param BaseAddress The start of the range for which to set at= tributes.=0D + @param Length The length of the range.=0D + @param Attributes A bitmask of the attributes to set. See "P= hysical memory=0D + protection attributes" in UefiSpec.h=0D +=0D + @return EFI_SUCCESS=0D + @return Others=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +MmuSetAttributes (=0D + IN EFI_PHYSICAL_ADDRESS BaseAddress,=0D + IN UINT64 Length,=0D + IN UINT64 Attributes=0D + )=0D +{=0D + EFI_STATUS Status;=0D +=0D + Status =3D EFI_UNSUPPORTED;=0D +=0D + if ((Attributes & EFI_MEMORY_XP) =3D=3D EFI_MEMORY_XP) {=0D + Status =3D ArmSetMemoryRegionNoExec (BaseAddress, Length);=0D + if (EFI_ERROR(Status)) {=0D + DEBUG((DEBUG_ERROR, "%a - Failed to set NX. Status =3D %r\n", __F= UNCTION__, Status));=0D + }=0D + }=0D +=0D + ASSERT_EFI_ERROR(Status);=0D + return Status;=0D +}=0D +=0D +=0D +/**=0D + Bitwise clears the memory attributes on a range of memory based on an at= tributes mask.=0D +=0D + @param BaseAddress The start of the range for which to clear = attributes.=0D + @param Length The length of the range.=0D + @param Attributes A bitmask of the attributes to clear. See = "Physical memory=0D + protection attributes" in UefiSpec.h=0D +=0D + @return EFI_SUCCESS=0D + @return Others=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +MmuClearAttributes (=0D + IN EFI_PHYSICAL_ADDRESS BaseAddress,=0D + IN UINT64 Length,=0D + IN UINT64 Attributes=0D + )=0D +{=0D + EFI_STATUS Status;=0D +=0D + Status =3D EFI_UNSUPPORTED;=0D +=0D + if ((Attributes & EFI_MEMORY_XP) =3D=3D EFI_MEMORY_XP) {=0D + Status =3D ArmClearMemoryRegionNoExec (BaseAddress, Length);=0D + if (EFI_ERROR(Status)) {=0D + DEBUG((DEBUG_ERROR, "%a - Failed to clear NX. Status =3D %r\n", _= _FUNCTION__, Status));=0D + }=0D + }=0D +=0D + if ((Attributes & EFI_MEMORY_RO) =3D=3D EFI_MEMORY_RO) {=0D + Status =3D ArmClearMemoryRegionReadOnly(BaseAddress, Length);=0D + if (EFI_ERROR(Status)) {=0D + DEBUG((DEBUG_ERROR, "%a - Failed to clear RO. Status =3D %r\n", _= _FUNCTION__, Status));=0D + }=0D + }=0D +=0D + ASSERT_EFI_ERROR(Status);=0D + return Status;=0D +}=0D +=0D +=0D +/**=0D + Returns the memory attributes on a range of memory.=0D +=0D + @param BaseAddress The start of the range for which to set at= tributes.=0D + @param Attributes A return pointer for the attributes.=0D +=0D + @return EFI_SUCCESS=0D + @return EFI_INVALID_PARAMETER A return pointer is NULL.=0D + @return Others=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +MmuGetAttributes (=0D + IN EFI_PHYSICAL_ADDRESS BaseAddress,=0D + OUT UINT64 *Attributes=0D + )=0D +{=0D + EFI_STATUS Status;=0D +=0D + Status =3D EFI_UNSUPPORTED;=0D +=0D + DEBUG ((DEBUG_ERROR, "%a() API not implemented\n", __FUNCTION__));=0D +=0D + ASSERT_EFI_ERROR(Status);=0D + return Status;=0D +}=0D diff --git a/ArmPkg/ArmPkg.dsc b/ArmPkg/ArmPkg.dsc index f9268de8347e..197519a64718 100644 --- a/ArmPkg/ArmPkg.dsc +++ b/ArmPkg/ArmPkg.dsc @@ -165,3 +165,4 @@ [Components.AARCH64] =0D [Components.AARCH64, Components.ARM]=0D ArmPkg/Library/StandaloneMmMmuLib/ArmMmuStandaloneMmLib.inf=0D + ArmPkg/Library/MmuLib/BaseMmuLib.inf=0D diff --git a/ArmPkg/Library/MmuLib/BaseMmuLib.inf b/ArmPkg/Library/MmuLib/B= aseMmuLib.inf new file mode 100644 index 000000000000..15095abee9c3 --- /dev/null +++ b/ArmPkg/Library/MmuLib/BaseMmuLib.inf @@ -0,0 +1,30 @@ +## @file=0D +# This library instance implements a very limited MMU Lib instance=0D +# for the ARM/AARCH64 architectures. This library shims a common library= =0D +# interface to the ArmPkg defined ArmMmuLib.=0D +#=0D +# Copyright (c) Microsoft Corporation.=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D MmuLib=0D + FILE_GUID =3D 6f2ee9a4-79b3-4b77-9a47-e2bd4b917b75= =0D + MODULE_TYPE =3D BASE=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D MmuLib=0D +=0D +[Sources]=0D + MmuLib.c=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + MdeModulePkg/MdeModulePkg.dec=0D + ArmPkg/ArmPkg.dec=0D +=0D +[LibraryClasses]=0D + DebugLib=0D + ArmMmuLib=0D --=20 2.31.1.windows.1