From nobody Mon Feb 9 02:28:49 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+83620+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+83620+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1636590353; cv=none; d=zohomail.com; s=zohoarc; b=P+QTwOrTijROURApVlROUG8E6gLSrmOmGsI4EsmytpWnappnXCmRhcBrB/yBeKewnIsy+JRS10D1hqtCFshOWYxN3+gfBEI//QAc1/qxFmA1rpjpenmXtz8dWOYZ2hC+QEXjT/xgei5d8mrCCLIWInZCu6Y+cCeC+tp0dOIcs6I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1636590353; 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=gNHzkaVMLg7IripzUrEQCkPzSTcsbsYmQ7GruHovcJI=; b=DSGOwA/VTn9rLkqIRUhuklIzIrI96YsAhEusyVGCDrCbVMBOi2w7uqFn1zJs37c89q72e8UOefqdwUB/opI6iJ5ntCZWB87dIUhzJSKVSnonn3iOn6E49vUM5QnkEQHX2Py8gzs7GydKEa7WtmplCw89c08Ks+Ok/fRO4kMhjy0= 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+83620+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1636590353598600.773446754739; Wed, 10 Nov 2021 16:25:53 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id X47AYY1788612xT9ct4qodym; Wed, 10 Nov 2021 16:25:53 -0800 X-Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by mx.groups.io with SMTP id smtpd.web09.3958.1636590330511516611 for ; Wed, 10 Nov 2021 16:25:30 -0800 X-Received: by mail-pl1-f175.google.com with SMTP id u17so4342919plg.9 for ; Wed, 10 Nov 2021 16:25:30 -0800 (PST) X-Gm-Message-State: Of1JlOkoeTSwj8kuYhTK5hSkx1787277AA= X-Google-Smtp-Source: ABdhPJzqzuXm3tNBGBhIAdYf0Jb8hl+haW86QpnnjEygwZDE/QjvaGh267DYfYdgNGZplgXlzWB3fQ== X-Received: by 2002:a17:90a:f002:: with SMTP id bt2mr3424010pjb.221.1636590329822; Wed, 10 Nov 2021 16:25:29 -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.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Nov 2021 16:25:29 -0800 (PST) From: "Bret Barkelew" X-Google-Original-From: "brbarkel@microsoft.com" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Sean Brogan Subject: [edk2-devel] [PATCH v3 08/14] MdePkg: Create the MMU access lib to abstract memory protection settings Date: Wed, 10 Nov 2021 16:24:10 -0800 Message-Id: <20211111002416.1770-9-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=1636590353; bh=0YO2UqkdBT0+ZTcMAz85gP6RYR55PYC2uZIOjeOCj+U=; h=Cc:Date:From:Reply-To:Subject:To; b=JCOjdAhhFXRXMHSHF/05pH5aQICaXqz61s3Bkna3b5/lYSh8nJPTOaWPQ5zUXIv2H1x uwIuGGwMVBEBFZe8+7g9Iuzos9nVvasQbH/V1r0sUPYk0ccpYk2oebbMy55epRFb+6wcl /rs6e8BPrSV/896KQascN8rItP9dHDikiHo= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1636590354903100002 Content-Type: text/plain; charset="utf-8" From: Bret Barkelew There are a number of Arm-specific accesses that are abstracted behind this. It may need to be refactored to work better across architectures. REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3651 Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Cc: Sean Brogan Signed-off-by: Bret Barkelew --- MdePkg/Library/BaseMmuLibNull/BaseMmuLibNull.c | 86 ++++++++++++++++++++ MdePkg/Include/Library/MmuLib.h | 75 +++++++++++++++++ MdePkg/Library/BaseMmuLibNull/BaseMmuLibNull.inf | 28 +++++++ MdePkg/MdePkg.dec | 5 ++ MdePkg/MdePkg.dsc | 2 + 5 files changed, 196 insertions(+) diff --git a/MdePkg/Library/BaseMmuLibNull/BaseMmuLibNull.c b/MdePkg/Librar= y/BaseMmuLibNull/BaseMmuLibNull.c new file mode 100644 index 000000000000..0398bc03f8f7 --- /dev/null +++ b/MdePkg/Library/BaseMmuLibNull/BaseMmuLibNull.c @@ -0,0 +1,86 @@ +/** @file +This lib abstracts some of the MMU accesses currently hardcoded against +an Arm lib. It's likely that this will need to be refactored at some point. + +Copyright (c) Microsoft Corporation. +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#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 + ) +{ + DEBUG ((DEBUG_ERROR, "%a() NULL implementation used!\n", __FUNCTION__)); + ASSERT (FALSE); + return EFI_UNSUPPORTED; +} + + +/** + 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 + ) +{ + DEBUG ((DEBUG_ERROR, "%a() NULL implementation used!\n", __FUNCTION__)); + ASSERT (FALSE); + return EFI_UNSUPPORTED; +} + + +/** + 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 + ) +{ + DEBUG ((DEBUG_ERROR, "%a() NULL implementation used!\n", __FUNCTION__)); + ASSERT (FALSE); + return EFI_UNSUPPORTED; +} diff --git a/MdePkg/Include/Library/MmuLib.h b/MdePkg/Include/Library/MmuLi= b.h new file mode 100644 index 000000000000..34b363bf712f --- /dev/null +++ b/MdePkg/Include/Library/MmuLib.h @@ -0,0 +1,75 @@ +/** @file +This lib abstracts some of the MMU accesses currently hardcoded against +an Arm lib. It's likely that this will need to be refactored at some point. + +Copyright (c) Microsoft Corporation. +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef MMU_LIB_H_ +#define MMU_LIB_H_ + +#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 + ); + + +/** + 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 + ); + + +/** + 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 + ); + +#endif diff --git a/MdePkg/Library/BaseMmuLibNull/BaseMmuLibNull.inf b/MdePkg/Libr= ary/BaseMmuLibNull/BaseMmuLibNull.inf new file mode 100644 index 000000000000..9f1b4422cc04 --- /dev/null +++ b/MdePkg/Library/BaseMmuLibNull/BaseMmuLibNull.inf @@ -0,0 +1,28 @@ +## @file +# This lib abstracts some of the MMU accesses currently hardcoded against +# an Arm lib. It's likely that this will need to be refactored at some poi= nt. +# +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + + +[Defines] + INF_VERSION =3D 0x00010017 + BASE_NAME =3D BaseMmuLibNull + FILE_GUID =3D 97196A48-00C0-4487-802A-CC5540583EEB + VERSION_STRING =3D 1.0 + MODULE_TYPE =3D BASE + LIBRARY_CLASS =3D MmuLib + + +[Sources] + BaseMmuLibNull.c + + +[LibraryClasses] + DebugLib + + +[Packages] + MdePkg/MdePkg.dec diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 8b18415b107a..43ad9726bf7f 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -267,6 +267,11 @@ [LibraryClasses] # RegisterFilterLib|Include/Library/RegisterFilterLib.h =20 + ## @libraryclass This lib abstracts some of the MMU accesses currently = hardcoded against + # an Arm lib. It's likely that this will need to be refa= ctored at some point. + # + MmuLib|Include/Library/MmuLib.h + [LibraryClasses.IA32, LibraryClasses.X64, LibraryClasses.AARCH64] ## @libraryclass Provides services to generate random number. # diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index a04f0aec8c20..c0f9bac787f2 100644 --- a/MdePkg/MdePkg.dsc +++ b/MdePkg/MdePkg.dsc @@ -131,6 +131,8 @@ [Components] =20 MdePkg/Library/RegisterFilterLibNull/RegisterFilterLibNull.inf =20 + MdePkg/Library/BaseMmuLibNull/BaseMmuLibNull.inf + [Components.IA32, Components.X64, Components.ARM, Components.AARCH64] # # Add UEFI Target Based Unit Tests --=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 (#83620): https://edk2.groups.io/g/devel/message/83620 Mute This Topic: https://groups.io/mt/86971567/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-