]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/NullMemoryTest: Handle more reliable memory
authorRuiyu Ni <ruiyu.ni@intel.com>
Sat, 10 Feb 2018 14:23:18 +0000 (22:23 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Tue, 27 Feb 2018 05:56:03 +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/NullMemoryTestDxe/NullMemoryTest.c

index 9c9849c776b799448e9fe93b8db4e92dff9debf8..11af8ea77fd00f155eb7252acb0b3d652701d206 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implementation of Generic Memory Test Protocol which does not perform real memory test.\r
 \r
-Copyright (c) 2006 - 2008, 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
@@ -58,6 +58,38 @@ GenericMemoryTestEntryPoint (
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Convert the memory descriptor to tested.\r
+\r
+  @param Descriptor  Pointer to EFI_GCD_MEMORY_SPACE_DESCRIPTOR\r
+\r
+  @retval EFI_SUCCESS The memory descriptor is converted to tested.\r
+  @retval others      Error happens.\r
+**/\r
+EFI_STATUS\r
+ConvertToTestedMemory (\r
+  IN CONST EFI_GCD_MEMORY_SPACE_DESCRIPTOR *Descriptor\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  Status = gDS->RemoveMemorySpace (\r
+                  Descriptor->BaseAddress,\r
+                  Descriptor->Length\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = gDS->AddMemorySpace (\r
+                    ((Descriptor->Capabilities & EFI_MEMORY_MORE_RELIABLE) == EFI_MEMORY_MORE_RELIABLE) ?\r
+                    EfiGcdMemoryTypeMoreReliable : EfiGcdMemoryTypeSystemMemory,\r
+                    Descriptor->BaseAddress,\r
+                    Descriptor->Length,\r
+                    Descriptor->Capabilities &~\r
+                    (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)\r
+                    );\r
+  }\r
+  return Status;\r
+}\r
+\r
+\r
 /**\r
   Initialize the generic memory test.\r
 \r
@@ -83,6 +115,7 @@ InitializeMemoryTest (
   OUT BOOLEAN                                  *RequireSoftECCInit\r
   )\r
 {\r
+  EFI_STATUS                      Status;\r
   UINTN                           NumberOfDescriptors;\r
   EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;\r
   UINTN                           Index;\r
@@ -96,22 +129,12 @@ InitializeMemoryTest (
       //\r
       // For those reserved memory that have not been tested, simply promote to system memory.\r
       //\r
-      gDS->RemoveMemorySpace (\r
-            MemorySpaceMap[Index].BaseAddress,\r
-            MemorySpaceMap[Index].Length\r
-            );\r
-\r
-      gDS->AddMemorySpace (\r
-            EfiGcdMemoryTypeSystemMemory,\r
-            MemorySpaceMap[Index].BaseAddress,\r
-            MemorySpaceMap[Index].Length,\r
-            MemorySpaceMap[Index].Capabilities &~\r
-            (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)\r
-            );\r
-\r
+      Status = ConvertToTestedMemory (&MemorySpaceMap[Index]);\r
+      ASSERT_EFI_ERROR (Status);\r
       mTestedSystemMemory += MemorySpaceMap[Index].Length;\r
       mTotalSystemMemory += MemorySpaceMap[Index].Length;\r
-    } else if (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeSystemMemory) {\r
+    } else if ((MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeSystemMemory) ||\r
+               (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeMoreReliable)) {\r
       mTotalSystemMemory += MemorySpaceMap[Index].Length;\r
     }\r
   }\r
@@ -204,22 +227,16 @@ EFI_STATUS
 EFIAPI\r
 GenCompatibleRangeTest (\r
   IN EFI_GENERIC_MEMORY_TEST_PROTOCOL          *This,\r
-  IN  EFI_PHYSICAL_ADDRESS                     StartAddress,\r
-  IN  UINT64                                   Length\r
+  IN EFI_PHYSICAL_ADDRESS                      StartAddress,\r
+  IN UINT64                                    Length\r
   )\r
 {\r
+  EFI_STATUS                      Status;\r
   EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;\r
 \r
-  gDS->GetMemorySpaceDescriptor (StartAddress, &Descriptor);\r
-\r
-  gDS->RemoveMemorySpace (StartAddress, Length);\r
-\r
-  gDS->AddMemorySpace (\r
-        EfiGcdMemoryTypeSystemMemory,\r
-        StartAddress,\r
-        Length,\r
-        Descriptor.Capabilities &~(EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)\r
-        );\r
-\r
-  return EFI_SUCCESS;\r
+  Status = gDS->GetMemorySpaceDescriptor (StartAddress, &Descriptor);\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = ConvertToTestedMemory (&Descriptor);\r
+  }\r
+  return Status;\r
 }\r