]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/Core: Fix out-of-sync issue in GCD
authorJian J Wang <jian.j.wang@intel.com>
Tue, 19 Sep 2017 05:52:11 +0000 (13:52 +0800)
committerStar Zeng <star.zeng@intel.com>
Thu, 21 Sep 2017 01:38:27 +0000 (09:38 +0800)
From GCD perspective, its SetMemorySpaceAttributes() method doesn't accept page
related attributes. That means users cannot use it to change page attributes,
and have to turn to CPU arch protocol to do it, which is not be allowed by PI
spec.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Michael Kinney <michael.d.kinney@intel.com>
Suggested-by: Jiewen Yao <jiewen.yao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
MdeModulePkg/Core/Dxe/Gcd/Gcd.c

index a06f8bb77cb01666a48100dd3790c7aa5e0ec621..e9d1d5b612a6d94abd40a8b181805084b15b882c 100644 (file)
@@ -40,6 +40,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #define PRESENT_MEMORY_ATTRIBUTES     (EFI_RESOURCE_ATTRIBUTE_PRESENT)\r
 \r
+#define EXCLUSIVE_MEMORY_ATTRIBUTES   (EFI_MEMORY_UC | EFI_MEMORY_WC | \\r
+                                       EFI_MEMORY_WT | EFI_MEMORY_WB | \\r
+                                       EFI_MEMORY_WP | EFI_MEMORY_UCE)\r
+\r
+#define NONEXCLUSIVE_MEMORY_ATTRIBUTES (EFI_MEMORY_XP | EFI_MEMORY_RP | \\r
+                                        EFI_MEMORY_RO)\r
+\r
 #define INVALID_CPU_ARCH_ATTRIBUTES   0xffffffff\r
 \r
 //\r
@@ -654,28 +661,30 @@ ConverToCpuArchAttributes (
   UINT64 Attributes\r
   )\r
 {\r
-  if ( (Attributes & EFI_MEMORY_UC) == EFI_MEMORY_UC) {\r
-    return EFI_MEMORY_UC;\r
-  }\r
+  UINT64      CpuArchAttributes;\r
 \r
-  if ( (Attributes & EFI_MEMORY_WC ) == EFI_MEMORY_WC) {\r
-    return EFI_MEMORY_WC;\r
+  if ((Attributes & ~(EXCLUSIVE_MEMORY_ATTRIBUTES |\r
+                      NONEXCLUSIVE_MEMORY_ATTRIBUTES)) != 0) {\r
+    return INVALID_CPU_ARCH_ATTRIBUTES;\r
   }\r
 \r
-  if ( (Attributes & EFI_MEMORY_WT ) == EFI_MEMORY_WT) {\r
-    return EFI_MEMORY_WT;\r
-  }\r
-\r
-  if ( (Attributes & EFI_MEMORY_WB) == EFI_MEMORY_WB) {\r
-    return EFI_MEMORY_WB;\r
-  }\r
-\r
-  if ( (Attributes & EFI_MEMORY_WP) == EFI_MEMORY_WP) {\r
-    return EFI_MEMORY_WP;\r
-  }\r
-\r
-  return INVALID_CPU_ARCH_ATTRIBUTES;\r
+  CpuArchAttributes = Attributes & NONEXCLUSIVE_MEMORY_ATTRIBUTES;\r
 \r
+  if ( (Attributes & EFI_MEMORY_UC) == EFI_MEMORY_UC) {\r
+    CpuArchAttributes |= EFI_MEMORY_UC;\r
+  } else if ( (Attributes & EFI_MEMORY_WC ) == EFI_MEMORY_WC) {\r
+    CpuArchAttributes |= EFI_MEMORY_WC;\r
+  } else if ( (Attributes & EFI_MEMORY_WT ) == EFI_MEMORY_WT) {\r
+    CpuArchAttributes |= EFI_MEMORY_WT;\r
+  } else if ( (Attributes & EFI_MEMORY_WB) == EFI_MEMORY_WB) {\r
+    CpuArchAttributes |= EFI_MEMORY_WB;\r
+  } else if ( (Attributes & EFI_MEMORY_UCE) == EFI_MEMORY_UCE) {\r
+    CpuArchAttributes |= EFI_MEMORY_UCE;\r
+  } else if ( (Attributes & EFI_MEMORY_WP) == EFI_MEMORY_WP) {\r
+    CpuArchAttributes |= EFI_MEMORY_WP;\r
+  }\r
+\r
+  return CpuArchAttributes;\r
 }\r
 \r
 \r