]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/GenericMemoryTest: Handle more reliable memory
authorRuiyu Ni <ruiyu.ni@intel.com>
Sat, 10 Feb 2018 14:22:15 +0000 (22:22 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Tue, 27 Feb 2018 05:56:00 +0000 (13:56 +0800)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=650
Today's implementation converts the untested more reliable memory
from reserved GCD type to system memory GCD type.
Though it doesn't impact the return result of gBS->GetMemoryMap().
But it impacts the return result of gDS->GetMemorySpaceDescriptor().
The patch fixes the bug to convert the untested more reliable memory
from reserved GCD type to more reliable memory GCD type.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
MdeModulePkg/Universal/MemoryTest/GenericMemoryTestDxe/LightMemoryTest.c

index 477c914059ce138a97e4be4d312509ee262c9499..a7ade955c34754759187675947c721208408dbca 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
 /** @file\r
 \r
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions\r
@@ -106,7 +106,8 @@ ConstructBaseMemoryRange (
   gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);\r
 \r
   for (Index = 0; Index < NumberOfDescriptors; Index++) {\r
   gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);\r
 \r
   for (Index = 0; Index < NumberOfDescriptors; Index++) {\r
-    if (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeSystemMemory) {\r
+    if ((MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeSystemMemory) ||\r
+        (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeMoreReliable)) {\r
       Private->BaseMemorySize += MemorySpaceMap[Index].Length;\r
     }\r
   }\r
       Private->BaseMemorySize += MemorySpaceMap[Index].Length;\r
     }\r
   }\r
@@ -138,6 +139,41 @@ DestroyLinkList (
   }\r
 }\r
 \r
   }\r
 }\r
 \r
+/**\r
+  Convert the memory range to tested.\r
+\r
+  @param BaseAddress  Base address of the memory range.\r
+  @param Length       Length of the memory range.\r
+  @param Capabilities Capabilities of the memory range.\r
+\r
+  @retval EFI_SUCCESS The memory range is converted to tested.\r
+  @retval others      Error happens.\r
+**/\r
+EFI_STATUS\r
+ConvertToTestedMemory (\r
+  IN UINT64           BaseAddress,\r
+  IN UINT64           Length,\r
+  IN UINT64           Capabilities\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  Status = gDS->RemoveMemorySpace (\r
+                  BaseAddress,\r
+                  Length\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = gDS->AddMemorySpace (\r
+                    ((Capabilities & EFI_MEMORY_MORE_RELIABLE) == EFI_MEMORY_MORE_RELIABLE) ?\r
+                    EfiGcdMemoryTypeMoreReliable : EfiGcdMemoryTypeSystemMemory,\r
+                    BaseAddress,\r
+                    Length,\r
+                    Capabilities &~\r
+                    (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)\r
+                    );\r
+  }\r
+  return Status;\r
+}\r
+\r
 /**\r
   Add the extened memory to whole system memory map.\r
 \r
 /**\r
   Add the extened memory to whole system memory map.\r
 \r
@@ -160,18 +196,12 @@ UpdateMemoryMap (
   while (Link != &Private->NonTestedMemRanList) {\r
     Range = NONTESTED_MEMORY_RANGE_FROM_LINK (Link);\r
 \r
   while (Link != &Private->NonTestedMemRanList) {\r
     Range = NONTESTED_MEMORY_RANGE_FROM_LINK (Link);\r
 \r
-    gDS->RemoveMemorySpace (\r
-          Range->StartAddress,\r
-          Range->Length\r
-          );\r
-\r
-    gDS->AddMemorySpace (\r
-          EfiGcdMemoryTypeSystemMemory,\r
-          Range->StartAddress,\r
-          Range->Length,\r
-          Range->Capabilities &~(EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)\r
-          );\r
-\r
+    ConvertToTestedMemory (\r
+      Range->StartAddress,\r
+      Range->Length,\r
+      Range->Capabilities &~\r
+      (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)\r
+      );\r
     Link = Link->ForwardLink;\r
   }\r
 \r
     Link = Link->ForwardLink;\r
   }\r
 \r
@@ -215,17 +245,12 @@ DirectRangeTest (
   //\r
   // Add the tested compatible memory to system memory using GCD service\r
   //\r
   //\r
   // Add the tested compatible memory to system memory using GCD service\r
   //\r
-  gDS->RemoveMemorySpace (\r
-        StartAddress,\r
-        Length\r
-        );\r
-\r
-  gDS->AddMemorySpace (\r
-        EfiGcdMemoryTypeSystemMemory,\r
-        StartAddress,\r
-        Length,\r
-        Capabilities &~(EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)\r
-        );\r
+  ConvertToTestedMemory (\r
+      StartAddress,\r
+      Length,\r
+      Capabilities &~\r
+      (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)\r
+      );\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
   return EFI_SUCCESS;\r
 }\r