From 99d8c3710a0fc2d15fcc28d8b9a1aedbb190b9b9 Mon Sep 17 00:00:00 2001
From: Richard Lyu <richard.lyu@suse.com>
Date: Tue, 14 Apr 2026 14:54:24 +0800
Subject: [PATCH 1/2] ArmPkg/CpuDxe: Drop GCD system memory check from
 MemoryAttribute protocol

The UEFI specification does not restrict the MemoryAttribute Protocol
to system memory only. The protocol should permit manipulating
permission attributes on any existing, valid mapping, consistent with
other architectures.

Remove RegionIsSystemMemory() and its use as a precondition in
GetMemoryAttributes(), SetMemoryAttributes() and
ClearMemoryAttributes().

Signed-off-by: Richard Lyu <richard.lyu@suse.com>
---
 ArmPkg/Drivers/CpuDxe/MemoryAttribute.c | 48 -------------------------
 1 file changed, 48 deletions(-)

diff --git a/ArmPkg/Drivers/CpuDxe/MemoryAttribute.c b/ArmPkg/Drivers/CpuDxe/MemoryAttribute.c
index c77feb848c45..65d232c71f81 100644
--- a/ArmPkg/Drivers/CpuDxe/MemoryAttribute.c
+++ b/ArmPkg/Drivers/CpuDxe/MemoryAttribute.c
@@ -8,42 +8,6 @@
 
 #include "CpuDxe.h"
 
-/**
-  Check whether the provided memory range is covered by a single entry of type
-  EfiGcdSystemMemory in the GCD memory map.
-
-  @param  BaseAddress       The physical address that is the start address of
-                            a memory region.
-  @param  Length            The size in bytes of the memory region.
-
-  @return Whether the region is system memory or not.
-**/
-STATIC
-BOOLEAN
-RegionIsSystemMemory (
-  IN  EFI_PHYSICAL_ADDRESS  BaseAddress,
-  IN  UINT64                Length
-  )
-{
-  EFI_GCD_MEMORY_SPACE_DESCRIPTOR  GcdDescriptor;
-  EFI_PHYSICAL_ADDRESS             GcdEndAddress;
-  EFI_STATUS                       Status;
-
-  Status = gDS->GetMemorySpaceDescriptor (BaseAddress, &GcdDescriptor);
-  if (EFI_ERROR (Status) ||
-      (GcdDescriptor.GcdMemoryType != EfiGcdMemoryTypeSystemMemory))
-  {
-    return FALSE;
-  }
-
-  GcdEndAddress = GcdDescriptor.BaseAddress + GcdDescriptor.Length;
-
-  //
-  // Return TRUE if the GCD descriptor covers the range entirely
-  //
-  return GcdEndAddress >= (BaseAddress + Length);
-}
-
 /**
   This function retrieves the attributes of the memory region specified by
   BaseAddress and Length. If different attributes are obtained from different
@@ -92,10 +56,6 @@ GetMemoryAttributes (
     return EFI_INVALID_PARAMETER;
   }
 
-  if (!RegionIsSystemMemory (BaseAddress, Length)) {
-    return EFI_UNSUPPORTED;
-  }
-
   DEBUG ((
     DEBUG_VERBOSE,
     "%a: BaseAddress == 0x%lx, Length == 0x%lx\n",
@@ -212,10 +172,6 @@ SetMemoryAttributes (
     return EFI_INVALID_PARAMETER;
   }
 
-  if (!RegionIsSystemMemory (BaseAddress, Length)) {
-    return EFI_UNSUPPORTED;
-  }
-
   return ArmSetMemoryAttributes (BaseAddress, Length, Attributes, Attributes);
 }
 
@@ -280,10 +236,6 @@ ClearMemoryAttributes (
     return EFI_INVALID_PARAMETER;
   }
 
-  if (!RegionIsSystemMemory (BaseAddress, Length)) {
-    return EFI_UNSUPPORTED;
-  }
-
   return ArmSetMemoryAttributes (BaseAddress, Length, 0, Attributes);
 }
 
-- 
2.51.0

