From nobody Mon Feb 9 03:13:13 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+83621+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+83621+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1636590357; cv=none; d=zohomail.com; s=zohoarc; b=CCPKYYj3JtwHspghz2VPIkhGw8VCtWbcXGijr4ZORhEZcHPdirbvyYLfE3KliyW7C13TZaAeAGfUT3n1P/pV/yfS7KRhcPP8qasCyD1SVUZ4sil2ts5pxjHqJrk1lHVvnojEKmzADryZap6N2qdaI5Df6HiutJ5sLWU2pQg+Yeg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1636590357; 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=80xMScUYS4o1XMZ+mVexeN63tVypYtGGeOm+brb45X4=; b=hD18D3686QPESoMlX792jVb63HHZLnt1e7Lo9Jna6dxtAzOhuWllImwzUayk8UtgExZjSdFHZco7q8mcO6ORY8Jndi055HvBQ+p23dNJHYMreHqoja36I0LudmVoMgxKr18fGsvBT4Hbl40954zVd3C2nZiGSqOuvaPDP2LMbLg= 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+83621+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1636590357394407.2968705612218; Wed, 10 Nov 2021 16:25:57 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id pXG6YY1788612xQJaDUzxXif; Wed, 10 Nov 2021 16:25:57 -0800 X-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 X-Received: by mail-pf1-f182.google.com with SMTP id o4so4038115pfp.13 for ; Wed, 10 Nov 2021 16:25:36 -0800 (PST) X-Gm-Message-State: 9SoeSQjiE2Npb1ahkABuWqQlx1787277AA= 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) X-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: [edk2-devel] [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> In-Reply-To: <20211111002416.1770-1-brbarkel@microsoft.com> References: <20211111002416.1770-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=1636590357; bh=PnxeRtInkNdvANSpG0kEWWa1Tv+C6QAAWhkH1sYjHWA=; h=Cc:Date:From:Reply-To:Subject:To; b=C01zHxdVRHYRMlDNfrQShrdaXf6ku8pxnOPQwsB9r79zMavTvvqWU69ogrqSKynV5Cn n+Amkoa0wSqqRsuuKhlnQ/3GPilajj8C/hdzeNnM/lTSmsFoABVZYab9Ly5uORv/Jmalc 41kVCQE1ONmhrsol358DTPJzjkha4QcMHQw= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1636590359034100010 Content-Type: text/plain; charset="utf-8" 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 +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) =3D=3D 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) =3D=3D 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) =3D=3D 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 f9268de8347e..197519a64718 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 (#83621): https://edk2.groups.io/g/devel/message/83621 Mute This Topic: https://groups.io/mt/86971568/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-