public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ard Biesheuvel" <ardb@kernel.org>
To: devel@edk2.groups.io
Cc: Ard Biesheuvel <ardb@kernel.org>,
	Michael Kinney <michael.d.kinney@intel.com>,
	Liming Gao <gaoliming@byosoft.com.cn>,
	Jiewen Yao <jiewen.yao@intel.com>,
	Michael Kubacki <michael.kubacki@microsoft.com>,
	Sean Brogan <sean.brogan@microsoft.com>,
	Rebecca Cran <quic_rcran@quicinc.com>,
	Leif Lindholm <quic_llindhol@quicinc.com>,
	Sami Mujawar <sami.mujawar@arm.com>,
	Taylor Beebe <t@taylorbeebe.com>
Subject: [PATCH v2 2/3] ArmPkg/CpuDxe: Unify PageAttributeToGcdAttribute helper
Date: Thu,  2 Feb 2023 12:27:21 +0100	[thread overview]
Message-ID: <20230202112722.2200755-3-ardb@kernel.org> (raw)
In-Reply-To: <20230202112722.2200755-1-ardb@kernel.org>

In preparation for introducing an implementation of the EFI memory
attributes protocol that is shared between ARM and AArch64, unify the
existing code that converts a page table descriptor into a
EFI_MEMORY_xxx bitfield, so it can be called from the generic code.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c |  5 +--
 ArmPkg/Drivers/CpuDxe/Arm/Mmu.c     | 46 +++++++++++---------
 ArmPkg/Drivers/CpuDxe/CpuDxe.h      |  5 +++
 3 files changed, 32 insertions(+), 24 deletions(-)

diff --git a/ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c b/ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c
index 8bb33046e707..4ec9fc0a582c 100644
--- a/ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c
+++ b/ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c
@@ -30,13 +30,12 @@ GetRootTranslationTableInfo (
   *RootTableEntryCount = TT_ENTRY_COUNT >> (T0SZ - MIN_T0SZ) % BITS_PER_LEVEL;
 }
 
-STATIC
 UINT64
 PageAttributeToGcdAttribute (
-  IN UINT64  PageAttributes
+  IN UINTN  PageAttributes
   )
 {
-  UINT64  GcdAttributes;
+  UINTN  GcdAttributes;
 
   switch (PageAttributes & TT_ATTR_INDX_MASK) {
     case TT_ATTR_INDX_DEVICE_MEMORY:
diff --git a/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c b/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c
index 2daf47ba6fe5..9545a1c1d2d3 100644
--- a/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c
+++ b/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c
@@ -77,39 +77,46 @@ SectionToGcdAttributes (
   return EFI_SUCCESS;
 }
 
-EFI_STATUS
-PageToGcdAttributes (
-  IN  UINT32  PageAttributes,
-  OUT UINT64  *GcdAttributes
+UINT64
+PageAttributeToGcdAttribute (
+  IN UINTN  PageAttributes
   )
 {
-  *GcdAttributes = 0;
+  UINT64 GcdAttributes;
 
   // determine cacheability attributes
   switch (PageAttributes & TT_DESCRIPTOR_PAGE_CACHE_POLICY_MASK) {
     case TT_DESCRIPTOR_PAGE_CACHE_POLICY_STRONGLY_ORDERED:
-      *GcdAttributes |= EFI_MEMORY_UC;
+      GcdAttributes = EFI_MEMORY_UC;
       break;
     case TT_DESCRIPTOR_PAGE_CACHE_POLICY_SHAREABLE_DEVICE:
-      *GcdAttributes |= EFI_MEMORY_UC;
+      GcdAttributes = EFI_MEMORY_UC;
       break;
     case TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC:
-      *GcdAttributes |= EFI_MEMORY_WT;
+      GcdAttributes = EFI_MEMORY_WT;
       break;
     case TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_BACK_NO_ALLOC:
-      *GcdAttributes |= EFI_MEMORY_WB;
+      GcdAttributes = EFI_MEMORY_WB;
       break;
     case TT_DESCRIPTOR_PAGE_CACHE_POLICY_NON_CACHEABLE:
-      *GcdAttributes |= EFI_MEMORY_WC;
+      GcdAttributes = EFI_MEMORY_WC;
       break;
     case TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_BACK_ALLOC:
-      *GcdAttributes |= EFI_MEMORY_WB;
+      GcdAttributes = EFI_MEMORY_WB;
       break;
     case TT_DESCRIPTOR_PAGE_CACHE_POLICY_NON_SHAREABLE_DEVICE:
-      *GcdAttributes |= EFI_MEMORY_UC;
+      GcdAttributes = EFI_MEMORY_UC;
       break;
     default:
-      return EFI_UNSUPPORTED;
+      DEBUG ((
+        DEBUG_ERROR,
+        "PageAttributeToGcdAttribute: PageAttributes:0x%X not supported.\n",
+        PageAttributes
+        ));
+      ASSERT (0);
+      // The Global Coherency Domain (GCD) value is defined as a bit set.
+      // Returning 0 means no attribute has been set.
+      GcdAttributes = 0;
   }
 
   // determine protection attributes
@@ -126,7 +133,7 @@ PageToGcdAttributes (
     // read only cases map to write-protect
     case TT_DESCRIPTOR_PAGE_AP_RO_NO:
     case TT_DESCRIPTOR_PAGE_AP_RO_RO:
-      *GcdAttributes |= EFI_MEMORY_RO;
+      GcdAttributes |= EFI_MEMORY_RO;
       break;
 
     default:
@@ -135,10 +142,10 @@ PageToGcdAttributes (
 
   // now process eXectue Never attribute
   if ((PageAttributes & TT_DESCRIPTOR_PAGE_XN_MASK) != 0 ) {
-    *GcdAttributes |= EFI_MEMORY_XP;
+    GcdAttributes |= EFI_MEMORY_XP;
   }
 
-  return EFI_SUCCESS;
+  return GcdAttributes;
 }
 
 EFI_STATUS
@@ -152,7 +159,6 @@ SyncCacheConfigPage (
   IN OUT UINT32                           *NextSectionAttributes
   )
 {
-  EFI_STATUS                     Status;
   UINT32                         i;
   volatile ARM_PAGE_TABLE_ENTRY  *SecondLevelTable;
   UINT32                         NextPageAttributes;
@@ -183,8 +189,7 @@ SyncCacheConfigPage (
         NextPageAttributes = PageAttributes;
       } else if (PageAttributes != NextPageAttributes) {
         // Convert Section Attributes into GCD Attributes
-        Status = PageToGcdAttributes (NextPageAttributes, &GcdAttributes);
-        ASSERT_EFI_ERROR (Status);
+        GcdAttributes = PageAttributeToGcdAttribute (NextPageAttributes);
 
         // update GCD with these changes (this will recurse into our own CpuSetMemoryAttributes below which is OK)
         SetGcdMemorySpaceAttributes (MemorySpaceMap, NumberOfDescriptors, *NextRegionBase, *NextRegionLength, GcdAttributes);
@@ -196,8 +201,7 @@ SyncCacheConfigPage (
       }
     } else if (NextPageAttributes != 0) {
       // Convert Page Attributes into GCD Attributes
-      Status = PageToGcdAttributes (NextPageAttributes, &GcdAttributes);
-      ASSERT_EFI_ERROR (Status);
+      GcdAttributes = PageAttributeToGcdAttribute (NextPageAttributes);
 
       // update GCD with these changes (this will recurse into our own CpuSetMemoryAttributes below which is OK)
       SetGcdMemorySpaceAttributes (MemorySpaceMap, NumberOfDescriptors, *NextRegionBase, *NextRegionLength, GcdAttributes);
diff --git a/ArmPkg/Drivers/CpuDxe/CpuDxe.h b/ArmPkg/Drivers/CpuDxe/CpuDxe.h
index ff672390ce51..8933fa90c4ed 100644
--- a/ArmPkg/Drivers/CpuDxe/CpuDxe.h
+++ b/ArmPkg/Drivers/CpuDxe/CpuDxe.h
@@ -126,4 +126,9 @@ SetGcdMemorySpaceAttributes (
   IN UINT64                           Attributes
   );
 
+UINT64
+PageAttributeToGcdAttribute (
+  IN UINTN  PageAttributes
+  );
+
 #endif // CPU_DXE_H_
-- 
2.39.0


  parent reply	other threads:[~2023-02-02 11:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-02 11:27 [PATCH v2 0/3] ArmPkg: implement EFI memory attributes protocol Ard Biesheuvel
2023-02-02 11:27 ` [PATCH v2 1/3] MdePkg: Add Memory Attribute Protocol definition Ard Biesheuvel
2023-02-03  5:28   ` 回复: [edk2-devel] " gaoliming
2023-02-02 11:27 ` Ard Biesheuvel [this message]
2023-02-02 11:27 ` [PATCH v2 3/3] ArmPkg/CpuDxe: Implement EFI memory attributes protocol Ard Biesheuvel

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=20230202112722.2200755-3-ardb@kernel.org \
    --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