]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/MemoryTest/GenericMemoryTestDxe/LightMemoryTest.c
MdeModulePkg: Clean up source files
[mirror_edk2.git] / MdeModulePkg / Universal / MemoryTest / GenericMemoryTestDxe / LightMemoryTest.c
index 477c914059ce138a97e4be4d312509ee262c9499..86c2be13dcb1f17a9f13ef68f484b140bcdeb118 100644 (file)
@@ -1,6 +1,6 @@
 /** @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
@@ -52,7 +52,7 @@ UINT32                  GenericMemoryTestMonoPattern[GENERIC_CACHELINE_SIZE / 4]
   If all Length bytes of the two buffers are identical, then 0 is returned.  Otherwise, the\r
   value returned is the first mismatched byte in SourceBuffer subtracted from the first\r
   mismatched byte in DestinationBuffer.\r
-  \r
+\r
   If Length = 0, then ASSERT().\r
 \r
   @param[in] DestinationBuffer The pointer to the destination buffer to compare.\r
@@ -62,7 +62,7 @@ UINT32                  GenericMemoryTestMonoPattern[GENERIC_CACHELINE_SIZE / 4]
   @return 0                 All Length bytes of the two buffers are identical.\r
   @retval Non-zero          The first mismatched byte in SourceBuffer subtracted from the first\r
                             mismatched byte in DestinationBuffer.\r
-                            \r
+\r
 **/\r
 INTN\r
 EFIAPI\r
@@ -89,7 +89,7 @@ CompareMemWithoutCheckArgument (
   @retval EFI_SUCCESS          Successful construct the base memory range through GCD service.\r
   @retval EFI_OUT_OF_RESOURCE  Could not allocate needed resource from base memory.\r
   @retval Others               Failed to construct base memory range through GCD service.\r
-                            \r
+\r
 **/\r
 EFI_STATUS\r
 ConstructBaseMemoryRange (\r
@@ -106,7 +106,8 @@ ConstructBaseMemoryRange (
   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
@@ -118,7 +119,7 @@ ConstructBaseMemoryRange (
   Destroy the link list base on the correspond link list type.\r
 \r
   @param[in] Private  Point to generic memory test driver's private data.\r
-                            \r
+\r
 **/\r
 VOID\r
 DestroyLinkList (\r
@@ -138,6 +139,41 @@ DestroyLinkList (
   }\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
@@ -145,7 +181,7 @@ DestroyLinkList (
 \r
   @retval EFI_SUCCESS Successful add all the extended memory to system memory map.\r
   @retval Others      Failed to add the tested extended memory.\r
-                            \r
+\r
 **/\r
 EFI_STATUS\r
 UpdateMemoryMap (\r
@@ -160,18 +196,12 @@ UpdateMemoryMap (
   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
@@ -188,7 +218,7 @@ UpdateMemoryMap (
 \r
   @retval EFI_SUCCESS      Successful test the range of memory.\r
   @retval Others           Failed to test the range of memory.\r
-                            \r
+\r
 **/\r
 EFI_STATUS\r
 DirectRangeTest (\r
@@ -215,17 +245,12 @@ DirectRangeTest (
   //\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
@@ -238,7 +263,7 @@ DirectRangeTest (
   @retval EFI_SUCCESS          Successful construct the non-tested memory range through GCD service.\r
   @retval EFI_OUT_OF_RESOURCE  Could not allocate needed resource from base memory.\r
   @retval Others               Failed to construct non-tested memory range through GCD service.\r
-                            \r
+\r
 **/\r
 EFI_STATUS\r
 ConstructNonTestedMemoryRange (\r
@@ -299,7 +324,7 @@ ConstructNonTestedMemoryRange (
 \r
   @retval EFI_SUCCESS Successful write the test pattern into the non-tested memory.\r
   @retval Others      The test pattern may not really write into the physical memory.\r
-                            \r
+\r
 **/\r
 EFI_STATUS\r
 WriteMemory (\r
@@ -347,7 +372,7 @@ WriteMemory (
 \r
   @retval EFI_SUCCESS Successful verify the range of memory, no errors' location found.\r
   @retval Others      The range of memory have errors contained.\r
-                            \r
+\r
 **/\r
 EFI_STATUS\r
 VerifyMemory (\r
@@ -407,7 +432,7 @@ VerifyMemory (
           NULL,\r
           (UINT8 *) ExtendedErrorData + sizeof (EFI_STATUS_CODE_DATA),\r
           ExtendedErrorData->DataHeader.Size\r
-          ); \r
+          );\r
 \r
       return EFI_DEVICE_ERROR;\r
     }\r
@@ -421,12 +446,12 @@ VerifyMemory (
 /**\r
   Initialize the generic memory test.\r
 \r
-  @param[in]  This                The protocol instance pointer. \r
-  @param[in]  Level               The coverage level of the memory test. \r
-  @param[out] RequireSoftECCInit  Indicate if the memory need software ECC init. \r
+  @param[in]  This                The protocol instance pointer.\r
+  @param[in]  Level               The coverage level of the memory test.\r
+  @param[out] RequireSoftECCInit  Indicate if the memory need software ECC init.\r
 \r
-  @retval EFI_SUCCESS         The generic memory test is initialized correctly. \r
-  @retval EFI_NO_MEDIA        The system had no memory to be tested. \r
+  @retval EFI_SUCCESS         The generic memory test is initialized correctly.\r
+  @retval EFI_NO_MEDIA        The system had no memory to be tested.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -517,12 +542,12 @@ InitializeMemoryTest (
 /**\r
   Perform the memory test.\r
 \r
-  @param[in]  This              The protocol instance pointer. \r
-  @param[out] TestedMemorySize  Return the tested extended memory size. \r
-  @param[out] TotalMemorySize   Return the whole system physical memory size. \r
-                                The total memory size does not include memory in a slot with a disabled DIMM.  \r
+  @param[in]  This              The protocol instance pointer.\r
+  @param[out] TestedMemorySize  Return the tested extended memory size.\r
+  @param[out] TotalMemorySize   Return the whole system physical memory size.\r
+                                The total memory size does not include memory in a slot with a disabled DIMM.\r
   @param[out] ErrorOut          TRUE if the memory error occured.\r
-  @param[in]  IfTestAbort       Indicates that the user pressed "ESC" to skip the memory test. \r
+  @param[in]  IfTestAbort       Indicates that the user pressed "ESC" to skip the memory test.\r
 \r
   @retval EFI_SUCCESS         One block of memory passed the test.\r
   @retval EFI_NOT_FOUND       All memory blocks have already been tested.\r
@@ -642,7 +667,7 @@ GenPerformMemoryTest (
 /**\r
   Finish the memory test.\r
 \r
-  @param[in] This             The protocol instance pointer. \r
+  @param[in] This             The protocol instance pointer.\r
 \r
   @retval EFI_SUCCESS         Success. All resources used in the memory test are freed.\r
 \r
@@ -680,12 +705,12 @@ GenMemoryTestFinished (
 /**\r
   Provides the capability to test the compatible range used by some special drivers.\r
 \r
-  @param[in]  This              The protocol instance pointer. \r
+  @param[in]  This              The protocol instance pointer.\r
   @param[in]  StartAddress      The start address of the compatible memory range that\r
                                 must be below 16M.\r
-  @param[in]  Length            The compatible memory range's length. \r
-  \r
-  @retval EFI_SUCCESS           The compatible memory range pass the memory test. \r
+  @param[in]  Length            The compatible memory range's length.\r
+\r
+  @retval EFI_SUCCESS           The compatible memory range pass the memory test.\r
   @retval EFI_INVALID_PARAMETER The compatible memory range are not below Low 16M.\r
 \r
 **/\r
@@ -755,9 +780,9 @@ GenCompatibleRangeTest (
   Perform the address line walking ones test.\r
 \r
   @param[in] Private  Point to generic memory test driver's private data.\r
-  \r
-  @retval EFI_SUCCESS          Successful finished walking ones test. \r
-  @retval EFI_OUT_OF_RESOURCE  Could not get resource in base memory. \r
+\r
+  @retval EFI_SUCCESS          Successful finished walking ones test.\r
+  @retval EFI_OUT_OF_RESOURCE  Could not get resource in base memory.\r
   @retval EFI_ACCESS_DENIED    Code may can not run here because if walking one test\r
                                failed, system may be already halt.\r
 \r
@@ -836,9 +861,9 @@ GENERIC_MEMORY_TEST_PRIVATE mGenericMemoryTestPrivate = {
 \r
   It initializes private data to default value.\r
 \r
-  @param[in] ImageHandle  The firmware allocated handle for the EFI image.  \r
+  @param[in] ImageHandle  The firmware allocated handle for the EFI image.\r
   @param[in] SystemTable  A pointer to the EFI System Table.\r
-  \r
+\r
   @retval EFI_SUCCESS     The entry point is executed successfully.\r
   @retval EFI_NOT_FOUND   Can't find HandOff Hob in HobList.\r
   @retval other           Some error occurs when executing this entry point.\r