public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Bret Barkelew" <bret@corthon.com>
To: devel@edk2.groups.io
Cc: Michael D Kinney <michael.d.kinney@intel.com>,
	Liming Gao <gaoliming@byosoft.com.cn>,
	Zhiguang Liu <zhiguang.liu@intel.com>,
	Sean Brogan <sean.brogan@microsoft.com>
Subject: [PATCH v2 08/16] MdePkg: Create the MMU access lib to abstract memory protection settings
Date: Tue,  2 Nov 2021 13:17:40 -0700	[thread overview]
Message-ID: <20211102201748.1963-9-brbarkel@microsoft.com> (raw)
In-Reply-To: <20211102201748.1963-1-brbarkel@microsoft.com>

From: Bret Barkelew <brbarkel@microsoft.com>

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=3651

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Signed-off-by: Bret Barkelew <bret.barkelew@microsoft.com>
---
 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/Library/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 <Uefi.h>
+#include <Library/DebugLib.h>
+
+/**
+  Bitwise sets the memory attributes on a range of memory based on an attributes mask.
+
+  @param  BaseAddress           The start of the range for which to set attributes.
+  @param  Length                The length of the range.
+  @param  Attributes            A bitmask of the attributes to set. See "Physical 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 attributes 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 attributes.
+  @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/MmuLib.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 <Uefi.h>
+
+/**
+  Bitwise sets the memory attributes on a range of memory based on an attributes mask.
+
+  @param  BaseAddress           The start of the range for which to set attributes.
+  @param  Length                The length of the range.
+  @param  Attributes            A bitmask of the attributes to set. See "Physical 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 attributes 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 attributes.
+  @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/Library/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 point.
+#
+# Copyright (c) Microsoft Corporation.
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+
+[Defines]
+  INF_VERSION         = 0x00010017
+  BASE_NAME           = BaseMmuLibNull
+  FILE_GUID           = 97196A48-00C0-4487-802A-CC5540583EEB
+  VERSION_STRING      = 1.0
+  MODULE_TYPE         = BASE
+  LIBRARY_CLASS       = 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
 
+  ##  @libraryclass 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.
+  #
+  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]
 
   MdePkg/Library/RegisterFilterLibNull/RegisterFilterLibNull.inf
 
+  MdePkg/Library/BaseMmuLibNull/BaseMmuLibNull.inf
+
 [Components.IA32, Components.X64, Components.ARM, Components.AARCH64]
   #
   # Add UEFI Target Based Unit Tests
-- 
2.31.1.windows.1


  parent reply	other threads:[~2021-11-02 20:18 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-02 20:17 [PATCH v2 00/16] Un-siloing Arm common code Bret Barkelew
2021-11-02 20:17 ` [PATCH v2 01/16] ArmPkg/ArmMmuBaseLib: Disallow STANDALONE_MM Bret Barkelew
2021-11-02 20:17 ` [PATCH v2 02/16] ArmPkg/ArmMmuStandaloneMmLib: Update to match ArmMmuLib Bret Barkelew
2021-11-04 12:14   ` Leif Lindholm
2021-11-02 20:17 ` [PATCH v2 03/16] ArmPkg/StandaloneMmCoreEntryPoint: Swap to ArmMmuLib Bret Barkelew
2021-11-02 20:17 ` [PATCH v2 04/16] ArmPkg: Disavow StandaloneMmMmuLib. It's just ArmMmuLib Bret Barkelew
2021-11-02 20:17 ` [PATCH v2 05/16] ArmPkg and MdePkg: Move the Arm CompilerIntrinsicsLib to MdePkg Bret Barkelew
2021-11-04 12:16   ` Leif Lindholm
2021-11-02 20:17 ` [PATCH v2 06/16] ArmPkg and BaseTools: Move the GccLto binaries from ArmPkg to BaseTools Bret Barkelew
2021-11-02 20:17 ` [PATCH v2 07/16] ArmPkg and MdePkg: Move the AsmMacroIoLib from ArmPkg to MdePkg Bret Barkelew
2021-11-04 12:17   ` Leif Lindholm
2021-11-05  5:12     ` 回复: [edk2-devel] " gaoliming
2021-11-02 20:17 ` Bret Barkelew [this message]
2021-11-02 20:17 ` [PATCH v2 09/16] MdeModulePkg: Swap to MmuLib instead of Arm-specific lib Bret Barkelew
2021-11-02 20:17 ` [PATCH v2 10/16] StandaloneMmPkg: Switch to the MmuLib abstraction Bret Barkelew
2021-11-02 20:17 ` [PATCH v2 11/16] ArmPkg: Add Basic MMU Lib for Arm silicon Bret Barkelew
2021-11-04 12:43   ` Leif Lindholm
2021-11-10 20:39     ` Bret Barkelew
2021-11-02 20:17 ` [PATCH v2 12/16] ArmPkg: Move the StandaloneMmCpu driver to ArmPkg Bret Barkelew
2021-11-02 20:17 ` [PATCH v2 13/16] ArmPkg: Move the StandaloneMmCoreEntryPoint lib " Bret Barkelew
2021-11-02 20:17 ` [PATCH v2 14/16] ArmPkg/Library: Convert StandaloneMmCoreEntryPoint to Arm-only Bret Barkelew
2021-11-02 20:17 ` [PATCH v2 15/16] ArmPkg/ArmPkg.dsc: Resolve build errors resulting from package moves Bret Barkelew
2021-11-02 20:17 ` [PATCH v2 16/16] ArmPlatformPkg: " Bret Barkelew
2021-11-06  9:50   ` [edk2-devel] " Marvin Häuser
2021-11-08 19:25     ` [EXTERNAL] " Bret Barkelew

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211102201748.1963-9-brbarkel@microsoft.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox