]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTest.c
MdeModulePkg/NullMemoryTest: Fix bug in CompatibleRangeTest
[mirror_edk2.git] / MdeModulePkg / Universal / MemoryTest / NullMemoryTestDxe / NullMemoryTest.c
index c66f3fd2080ac6af8b04218fe9d33a18ab87bae9..a9bd1015013104d99e63d9f609452f6fe67e4bba 100644 (file)
@@ -240,14 +240,51 @@ GenCompatibleRangeTest (
 {\r
   EFI_STATUS                      Status;\r
   EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;\r
-\r
-  Status = gDS->GetMemorySpaceDescriptor (StartAddress, &Descriptor);\r
-  if (!EFI_ERROR (Status)) {\r
-    Status = ConvertToTestedMemory (\r
-               Descriptor.BaseAddress,\r
-               Descriptor.Length,\r
-               Descriptor.Capabilities\r
-               );\r
+  EFI_PHYSICAL_ADDRESS            CurrentBase;\r
+  UINT64                          CurrentLength;\r
+\r
+  //\r
+  // Check if the parameter is below 16MB\r
+  //\r
+  if (StartAddress + Length > SIZE_16MB) {\r
+    return EFI_INVALID_PARAMETER;\r
   }\r
-  return Status;\r
+  CurrentBase = StartAddress;\r
+  do {\r
+    //\r
+    // Check the required memory range status; if the required memory range span\r
+    // the different GCD memory descriptor, it may be cause different action.\r
+    //\r
+    Status = gDS->GetMemorySpaceDescriptor (\r
+                    CurrentBase,\r
+                    &Descriptor\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    if (Descriptor.GcdMemoryType == EfiGcdMemoryTypeReserved &&\r
+        (Descriptor.Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==\r
+          (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED)\r
+          ) {\r
+      CurrentLength = Descriptor.BaseAddress + Descriptor.Length - CurrentBase;\r
+      if (CurrentBase + CurrentLength > StartAddress + Length) {\r
+        CurrentLength = StartAddress + Length - CurrentBase;\r
+      }\r
+      Status = ConvertToTestedMemory (\r
+                 CurrentBase,\r
+                 CurrentLength,\r
+                 Descriptor.Capabilities\r
+                 );\r
+      if (EFI_ERROR (Status)) {\r
+        return Status;\r
+      }\r
+    }\r
+    CurrentBase = Descriptor.BaseAddress + Descriptor.Length;\r
+  } while (CurrentBase < StartAddress + Length);\r
+  //\r
+  // Here means the required range already be tested, so just return success.\r
+  //\r
+  return EFI_SUCCESS;\r
 }\r
+\r