From nobody Mon Feb 9 12:09:46 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+83041+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+83041+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1635796726; cv=none; d=zohomail.com; s=zohoarc; b=Q2ASzTwHkAast4B1zYCLg6qwWqResuu1oJN/pUQ7i4KvzkqOmHL5moEMV/XYne7jIoDDysh9T4AI5IauQDx5ZYF1CgX8gCImUc122J5e0Y+OwOneX2hmKEHSR3e7mXH13HZiaUqPFYQgvDmz7p2XsTaGcIXpjAnqAyCaYZkkWU4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635796726; 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=Vjd/y7ytCTyAksn80PF1yXVZttx+WIjyOdPPL+YCP8Y=; b=Pv+1TO+TcaHslXCx5rKt+/G2H9NY22lZUlsOonmTRqFZn4MGPJXjNlhgezI14jbunPbhugBBocro7pGuSx7V/3JLR7bbGEN8p5zlne8+SGjF/QJDBMm1ENLV8iGyAU3d8gkcNWVRK8KMAdeD//Sc0lMQoqIdVhB+cM04wyvOs2w= 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+83041+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1635796726455795.775725622964; Mon, 1 Nov 2021 12:58:46 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id cuo8YY1788612xrmP3OiND3s; Mon, 01 Nov 2021 12:58:46 -0700 X-Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by mx.groups.io with SMTP id smtpd.web12.1599.1635796725670660431 for ; Mon, 01 Nov 2021 12:58:45 -0700 X-Received: by mail-pf1-f172.google.com with SMTP id u33so5360645pfg.8 for ; Mon, 01 Nov 2021 12:58:45 -0700 (PDT) X-Gm-Message-State: Bj0azz242HdWhK9rf6rs1Y4mx1787277AA= X-Google-Smtp-Source: ABdhPJxF1/KDD3qLjAeLQyKQHMAxKK3+35vyXB3kC3e4o09WGMEsZHsKcKtNrCK45/zxUVodLdFYOg== X-Received: by 2002:a63:788d:: with SMTP id t135mr23436334pgc.2.1635796724962; Mon, 01 Nov 2021 12:58:44 -0700 (PDT) X-Received: from localhost.localdomain (174-21-94-94.tukw.qwest.net. [174.21.94.94]) by smtp.gmail.com with ESMTPSA id t2sm13759796pgf.35.2021.11.01.12.58.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 12:58:44 -0700 (PDT) From: "Bret Barkelew" X-Google-Original-From: "brbarkel@microsoft.com" To: devel@edk2.groups.io Cc: Leif Lindholm , Ard Biesheuvel , Sean Brogan Subject: [edk2-devel] [PATCH v1 11/16] ArmPkg: Add Basic MMU Lib for Arm silicon Date: Mon, 1 Nov 2021 12:56:43 -0700 Message-Id: <20211101195648.6420-12-brbarkel@microsoft.com> In-Reply-To: <20211101195648.6420-1-brbarkel@microsoft.com> References: <20211101195648.6420-1-brbarkel@microsoft.com> 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,bret@corthon.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1635796726; bh=62pMluTZvVzOYRiOms1O/x9U6XoafL/adKIt4ugG2xo=; h=Cc:Date:From:Reply-To:Subject:To; b=Te6EKDb0QMYpBBbWFHuNjy3EmW0R9ntqnki6BFEXxY0gjnwk6HHv+htF1inF/OqQ0ud 8Aib3PrQsxZYpcFnsZX65RxF0K5dgJ+IVGtFbV7/n5O6kd9TSwoRrQ5wceD1ztpL+0qe3 nWwmnhtjYpXwY4EIaThX9ehVPQcfs4DGPvM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1635796726753100016 Content-Type: text/plain; charset="utf-8" From: Sean Brogan 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..7a6ba1f81819 --- /dev/null +++ b/ArmPkg/Library/MmuLib/MmuLib.c @@ -0,0 +1,120 @@ +/** @file +This library instance implements a very limited MMU Lib instance +for the ARM/AARCH64 architectures. This library shims a common library +interface to the ArmPkg defined ArmMmuLib.ib. + +Copyright (c) Microsoft Corporation. +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include + +/** + Bitwise sets the memory attributes on a range of memory based on an attr= ibutes mask. + + @param BaseAddress The start of the range for which to set at= tributes. + @param Length The length of the range. + @param Attributes A bitmask of the attributes to set. See "P= hysical memory + protection attributes" in UefiSpec.h + + @return EFI_SUCCESS + @return Others + +**/ +EFI_STATUS +EFIAPI +MmuSetAttributes ( + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINT64 Length, + IN UINT64 Attributes + ) + { + EFI_STATUS Status; + + Status =3D EFI_UNSUPPORTED; + + if (Attributes & EFI_MEMORY_XP) { + Status =3D ArmSetMemoryRegionNoExec (BaseAddress, Length); + if (EFI_ERROR(Status)) { + DEBUG((DEBUG_ERROR, "%a - Failed to set NX. Status =3D %r\n", __F= UNCTION__, Status)); + } + } + + ASSERT_EFI_ERROR(Status); + return Status; + } + + +/** + Bitwise clears the memory attributes on a range of memory based on an at= tributes mask. + + @param BaseAddress The start of the range for which to clear = attributes. + @param Length The length of the range. + @param Attributes A bitmask of the attributes to clear. See = "Physical memory + protection attributes" in UefiSpec.h + + @return EFI_SUCCESS + @return Others + +**/ +EFI_STATUS +EFIAPI +MmuClearAttributes ( + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINT64 Length, + IN UINT64 Attributes + ) + { + EFI_STATUS Status; + + Status =3D EFI_UNSUPPORTED; + + if (Attributes & EFI_MEMORY_XP) { + Status =3D ArmClearMemoryRegionNoExec (BaseAddress, Length); + if (EFI_ERROR(Status)) { + DEBUG((DEBUG_ERROR, "%a - Failed to clear NX. Status =3D %r\n", _= _FUNCTION__, Status)); + } + } + + if (Attributes & EFI_MEMORY_RO) { + Status =3D ArmClearMemoryRegionReadOnly(BaseAddress, Length); + if (EFI_ERROR(Status)) { + DEBUG((DEBUG_ERROR, "%a - Failed to clear RO. Status =3D %r\n", _= _FUNCTION__, Status)); + } + } + + ASSERT_EFI_ERROR(Status); + return Status; + } + + +/** + Returns the memory attributes on a range of memory. + + @param BaseAddress The start of the range for which to set at= tributes. + @param Attributes A return pointer for the attributes. + + @return EFI_SUCCESS + @return EFI_INVALID_PARAMETER A return pointer is NULL. + @return Others + +**/ +EFI_STATUS +EFIAPI +MmuGetAttributes ( + IN EFI_PHYSICAL_ADDRESS BaseAddress, + OUT UINT64 *Attributes + ) + { + EFI_STATUS Status; + + Status =3D EFI_UNSUPPORTED; + + DEBUG ((DEBUG_ERROR, "%a() API not implemented\n", __FUNCTION__)); + + ASSERT_EFI_ERROR(Status); + return Status; + } diff --git a/ArmPkg/ArmPkg.dsc b/ArmPkg/ArmPkg.dsc index 06ede068f99d..cbc67daa7696 100644 --- a/ArmPkg/ArmPkg.dsc +++ b/ArmPkg/ArmPkg.dsc @@ -165,3 +165,4 @@ [Components.AARCH64] =20 [Components.AARCH64, Components.ARM] ArmPkg/Library/StandaloneMmMmuLib/ArmMmuStandaloneMmLib.inf + ArmPkg/Library/MmuLib/BaseMmuLib.inf 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 +# This library instance implements a very limited MMU Lib instance +# for the ARM/AARCH64 architectures. This library shims a common library +# interface to the ArmPkg defined ArmMmuLib. +# +# Copyright (c) Microsoft Corporation. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D MmuLib + FILE_GUID =3D 6f2ee9a4-79b3-4b77-9a47-e2bd4b917b75 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D MmuLib + +[Sources] + MmuLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + ArmPkg/ArmPkg.dec + +[LibraryClasses] + DebugLib + ArmMmuLib --=20 2.31.1.windows.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 (#83041): https://edk2.groups.io/g/devel/message/83041 Mute This Topic: https://groups.io/mt/86750658/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-