From nobody Mon Feb 9 03:13:41 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+83038+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+83038+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1635796722; cv=none; d=zohomail.com; s=zohoarc; b=bBwPrTLXWx85crxwaWLKa7MMYsE0pObC/z/cXCHsjfv8zziOFEzM/saJcx+YLQr1NepCT+ylR/t1JvaxzIVYbbBJc6uGyTmxwbhgXM+cmXQwhBYobgD9oxK6iT0/1pubCQbT+JrFY+2Qf17W12FHXJAtGkRfvkYZpOv/O+tpbxs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635796722; 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=SnF+1O9wogaA0lk50Mz+qe0rsuXIGbg2BcpMkTxHEoI=; b=YhcxSoXdyfDeHEJh722erQ+qVavjQQn7sWrvs1h/jOz3IMCYLKnfCVgtGM2DUJrW/Yv6YTsB0KnrY+xc5AijfR066m0qF5FWNGeKraGxYuxmKC8bzNkvOsINUM3mTQoD4zMlgJEq7Yo4f7N1ZYWTgDF57RD/X2/t1hbE8k7w7yw= 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+83038+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1635796722666262.1511113175443; Mon, 1 Nov 2021 12:58:42 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id IKMlYY1788612xhyMDLGVeHb; Mon, 01 Nov 2021 12:58:42 -0700 X-Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by mx.groups.io with SMTP id smtpd.web12.1596.1635796721822573420 for ; Mon, 01 Nov 2021 12:58:41 -0700 X-Received: by mail-pl1-f172.google.com with SMTP id s24so12417211plp.0 for ; Mon, 01 Nov 2021 12:58:41 -0700 (PDT) X-Gm-Message-State: WMh9dDN1tPDAsJfHIW2vDW6px1787277AA= X-Google-Smtp-Source: ABdhPJzedCaMFAlcfYuYJjDh8MbY/vTL+gXI0afpZikhW/fqO3X4qAWmNjlNotuHYLi2HxcJDu7AGQ== X-Received: by 2002:a17:90a:9906:: with SMTP id b6mr1167574pjp.180.1635796721191; Mon, 01 Nov 2021 12:58:41 -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.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 12:58:40 -0700 (PDT) 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 v1 08/16] MdePkg: Create the MMU access lib to abstract memory protection settings Date: Mon, 1 Nov 2021 12:56:40 -0700 Message-Id: <20211101195648.6420-9-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=1635796722; bh=7AECEk5zbF8UkEcUzjZTeMxOC/deITj8jw76bB5q1zM=; h=Cc:Date:From:Reply-To:Subject:To; b=hkR+prP+OPXeW1AZqYMa7tWBAftEZ2PsMNUjAOcaATHUcgBJrID9fG6ZqZ1epbEbX89 Mo2dnRBa816OmT7cNQIcn9h273gwy91/AeHqYcWe/dLZwXAi5nayFb7/m4c/9pRvZ4Rs5 DOX4mq4UxkAEm4wVhMyiSrb9xX0j3rCjIIA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1635796724323100006 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..170670f7d52a --- /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 // _MMU_LIB_H_ 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 cb3907c88b4e..a9c67b72e4e0 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 (#83038): https://edk2.groups.io/g/devel/message/83038 Mute This Topic: https://groups.io/mt/86750654/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-