]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/Gcd/Gcd.c
MdeModulePkg/Gcd: Suppress incorrect compiler/analyzer warnings
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Gcd / Gcd.c
index 907245a3f512c2eeb5424cdf166744b57c1df2ce..e17e98230b79beb063c5a00cbe38c251e86e9fc3 100644 (file)
@@ -3,7 +3,7 @@
   The GCD services are used to manage the memory and I/O regions that\r
   are accessible to the CPU that is executing the DXE core.\r
 \r
-Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -48,8 +48,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #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
 // Module Variables\r
 //\r
@@ -868,12 +866,30 @@ CoreConvertSpace (
   }\r
   ASSERT (TopEntry != NULL && BottomEntry != NULL);\r
 \r
+  //\r
+  // Initialize CpuArchAttributes to suppress incorrect compiler/analyzer warnings.\r
+  //\r
+  CpuArchAttributes = 0;\r
   if (Operation == GCD_SET_ATTRIBUTES_MEMORY_OPERATION) {\r
     //\r
     // Call CPU Arch Protocol to attempt to set attributes on the range\r
     //\r
     CpuArchAttributes = ConverToCpuArchAttributes (Attributes);\r
-    if (CpuArchAttributes != INVALID_CPU_ARCH_ATTRIBUTES) {\r
+    //\r
+    // CPU arch attributes include page attributes and cache attributes. \r
+    // Only page attributes supports to be cleared, but not cache attributes.\r
+    // Caller is expected to use GetMemorySpaceDescriptor() to get the current\r
+    // attributes, AND/OR attributes, and then calls SetMemorySpaceAttributes()\r
+    // to set the new attributes.\r
+    // So 0 CPU arch attributes should not happen as memory should always have\r
+    // a cache attribute (no matter UC or WB, etc). \r
+    //\r
+    // Here, 0 CPU arch attributes will be filtered to be compatible with the\r
+    // case that caller just calls SetMemorySpaceAttributes() with none CPU\r
+    // arch attributes (for example, RUNTIME) as the purpose of the case is not\r
+    // to clear CPU arch attributes.\r
+    //\r
+    if (CpuArchAttributes != 0) {\r
       if (gCpu == NULL) {\r
         Status = EFI_NOT_AVAILABLE_YET;\r
       } else {\r
@@ -936,6 +952,13 @@ CoreConvertSpace (
     // Set attributes operation\r
     //\r
     case GCD_SET_ATTRIBUTES_MEMORY_OPERATION:\r
+      if (CpuArchAttributes == 0) {\r
+        //\r
+        // Keep original CPU arch attributes when caller just calls\r
+        // SetMemorySpaceAttributes() with none CPU arch attributes (for example, RUNTIME).\r
+        //\r
+        Attributes |= (Entry->Attributes & (EXCLUSIVE_MEMORY_ATTRIBUTES | NONEXCLUSIVE_MEMORY_ATTRIBUTES));\r
+      }\r
       Entry->Attributes = Attributes;\r
       break;\r
     //\r