public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Bret Barkelew" <bret@corthon.com>
To: devel@edk2.groups.io
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>,
	Sami Mujawar <sami.mujawar@arm.com>,
	Jiewen Yao <jiewen.yao@intel.com>,
	Supreeth Venkatesh <supreeth.venkatesh@arm.com>,
	Sean Brogan <sean.brogan@microsoft.com>
Subject: [PATCH v3 11/14] StandaloneMmPkg: Switch to the MmuLib abstraction
Date: Wed, 10 Nov 2021 16:24:13 -0800	[thread overview]
Message-ID: <20211111002416.1770-12-brbarkel@microsoft.com> (raw)
In-Reply-To: <20211111002416.1770-1-brbarkel@microsoft.com>

From: Bret Barkelew <brbarkel@microsoft.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3651

Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Supreeth Venkatesh <supreeth.venkatesh@arm.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Signed-off-by: Bret Barkelew <bret.barkelew@microsoft.com>
---
 StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/AArch64/StandaloneMmPeCoffExtraActionLib.c | 82 ++++++++++++++++++--
 StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/StandaloneMmPeCoffExtraActionLib.inf       |  3 +-
 StandaloneMmPkg/StandaloneMmPkg.dsc                                                                 |  1 +
 3 files changed, 79 insertions(+), 7 deletions(-)

diff --git a/StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/AArch64/StandaloneMmPeCoffExtraActionLib.c b/StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/AArch64/StandaloneMmPeCoffExtraActionLib.c
index ca8b1244a313..986f6ade5f47 100644
--- a/StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/AArch64/StandaloneMmPeCoffExtraActionLib.c
+++ b/StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/AArch64/StandaloneMmPeCoffExtraActionLib.c
@@ -10,7 +10,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 
 #include <PiDxe.h>
 
-#include <Library/ArmMmuLib.h>
+#include <Library/MmuLib.h>
 #include <Library/BaseLib.h>
 #include <Library/BaseMemoryLib.h>
 #include <Library/DebugLib.h>
@@ -163,6 +163,78 @@ UpdatePeCoffPermissions (
   return RETURN_SUCCESS;
 }
 
+/**
+  Internal function to parameterize the call int MmuSetAttributes.
+
+  @param [in] BaseAddress
+  @param [in] Length
+
+  @retval   EFI_STATUS    Returned by MmuSetAttributes
+**/
+STATIC
+EFI_STATUS
+ArmPeSetMemoryRegionNoExec (
+  IN  EFI_PHYSICAL_ADDRESS      BaseAddress,
+  IN  UINT64                    Length
+  )
+{
+  return MmuSetAttributes (BaseAddress, Length, EFI_MEMORY_XP);
+}
+
+/**
+  Internal function to parameterize the call int MmuSetAttributes.
+
+  @param [in] BaseAddress
+  @param [in] Length
+
+  @retval   EFI_STATUS    Returned by MmuSetAttributes
+**/
+STATIC
+EFI_STATUS
+ArmPeClearMemoryRegionNoExec (
+  IN  EFI_PHYSICAL_ADDRESS      BaseAddress,
+  IN  UINT64                    Length
+  )
+{
+  return MmuClearAttributes (BaseAddress, Length, EFI_MEMORY_XP);
+}
+
+/**
+  Internal function to parameterize the call int MmuSetAttributes.
+
+  @param [in] BaseAddress
+  @param [in] Length
+
+  @retval   EFI_STATUS    Returned by MmuSetAttributes
+**/
+STATIC
+EFI_STATUS
+ArmPeSetMemoryRegionReadOnly (
+  IN  EFI_PHYSICAL_ADDRESS      BaseAddress,
+  IN  UINT64                    Length
+  )
+{
+  return MmuSetAttributes (BaseAddress, Length, EFI_MEMORY_RO);
+}
+
+/**
+  Internal function to parameterize the call int MmuSetAttributes.
+
+  @param [in] BaseAddress
+  @param [in] Length
+
+  @retval   EFI_STATUS    Returned by MmuSetAttributes
+**/
+STATIC
+EFI_STATUS
+ArmPeClearMemoryRegionReadOnly (
+  IN  EFI_PHYSICAL_ADDRESS      BaseAddress,
+  IN  UINT64                    Length
+  )
+{
+  return MmuClearAttributes (BaseAddress, Length, EFI_MEMORY_RO);
+}
+
 /**
   Performs additional actions after a PE/COFF image has been loaded and relocated.
 
@@ -180,8 +252,8 @@ PeCoffLoaderRelocateImageExtraAction (
 {
   UpdatePeCoffPermissions (
     ImageContext,
-    ArmClearMemoryRegionNoExec,
-    ArmSetMemoryRegionReadOnly
+    ArmPeClearMemoryRegionNoExec,
+    ArmPeSetMemoryRegionReadOnly
     );
 }
 
@@ -205,7 +277,7 @@ PeCoffLoaderUnloadImageExtraAction (
 {
   UpdatePeCoffPermissions (
     ImageContext,
-    ArmSetMemoryRegionNoExec,
-    ArmClearMemoryRegionReadOnly
+    ArmPeSetMemoryRegionNoExec,
+    ArmPeClearMemoryRegionReadOnly
     );
 }
diff --git a/StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/StandaloneMmPeCoffExtraActionLib.inf b/StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/StandaloneMmPeCoffExtraActionLib.inf
index 89083df679a1..25306dd3e707 100644
--- a/StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/StandaloneMmPeCoffExtraActionLib.inf
+++ b/StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/StandaloneMmPeCoffExtraActionLib.inf
@@ -27,10 +27,9 @@ [Sources.common]
   AArch64/StandaloneMmPeCoffExtraActionLib.c
 
 [Packages]
-  ArmPkg/ArmPkg.dec
   MdePkg/MdePkg.dec
   StandaloneMmPkg/StandaloneMmPkg.dec
 
 [LibraryClasses]
-  StandaloneMmMmuLib
+  MmuLib
   PcdLib
diff --git a/StandaloneMmPkg/StandaloneMmPkg.dsc b/StandaloneMmPkg/StandaloneMmPkg.dsc
index e9488538cb21..da3488e0d3fe 100644
--- a/StandaloneMmPkg/StandaloneMmPkg.dsc
+++ b/StandaloneMmPkg/StandaloneMmPkg.dsc
@@ -59,6 +59,7 @@ [LibraryClasses]
   StandaloneMmCoreEntryPoint|StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf
   StandaloneMmDriverEntryPoint|MdePkg/Library/StandaloneMmDriverEntryPoint/StandaloneMmDriverEntryPoint.inf
   VariableMmDependency|StandaloneMmPkg/Library/VariableMmDependency/VariableMmDependency.inf
+  MmuLib|MdePkg/Library/BaseMmuLibNull/BaseMmuLibNull.inf
 
 [LibraryClasses.AARCH64, LibraryClasses.ARM]
   ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf
-- 
2.31.1.windows.1


  parent reply	other threads:[~2021-11-11  0:25 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-11  0:24 [PATCH v3 00/14] Un-siloing Arm common code Bret Barkelew
2021-11-11  0:24 ` [PATCH v3 01/14] ArmPkg/ArmMmuBaseLib: Disallow STANDALONE_MM Bret Barkelew
2021-11-11  0:24 ` [PATCH v3 02/14] ArmPkg/ArmMmuStandaloneMmLib: Update to match ArmMmuLib Bret Barkelew
2021-11-11  0:24 ` [PATCH v3 03/14] ArmPkg/StandaloneMmCoreEntryPoint: Swap to ArmMmuLib Bret Barkelew
2021-11-11  0:24 ` [PATCH v3 04/14] ArmPkg: Disavow StandaloneMmMmuLib. It's just ArmMmuLib Bret Barkelew
2021-11-11  0:24 ` [PATCH v3 05/14] ArmPkg and MdePkg: Move the Arm CompilerIntrinsicsLib to MdePkg Bret Barkelew
2021-11-11  0:24 ` [PATCH v3 06/14] ArmPkg and BaseTools: Move the GccLto binaries from ArmPkg to BaseTools Bret Barkelew
2021-11-11  0:24 ` [PATCH v3 07/14] ArmPkg and MdePkg: Move the AsmMacroIoLib from ArmPkg to MdePkg Bret Barkelew
2021-11-11  0:24 ` [PATCH v3 08/14] MdePkg: Create the MMU access lib to abstract memory protection settings Bret Barkelew
2021-11-11  0:24 ` [PATCH v3 09/14] ArmPkg: Add Basic MMU Lib for Arm silicon Bret Barkelew
2021-11-11  0:24 ` [PATCH v3 10/14] MdeModulePkg: Swap to MmuLib instead of Arm-specific lib Bret Barkelew
2021-11-11  0:24 ` Bret Barkelew [this message]
2021-11-11  0:24 ` [PATCH v3 12/14] ArmPkg: Move the StandaloneMmCpu driver to ArmPkg Bret Barkelew
2021-11-11  0:24 ` [PATCH v3 13/14] StandaloneMmPkg: Add StandaloneMmCoreEntryNull to satisfy CI on all archs Bret Barkelew
2021-11-11  0:24 ` [PATCH v3 14/14] ArmPkg: Create an Arm-specific version of StandaloneMmCoreEntryPoint 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=20211111002416.1770-12-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