summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Universal/MemoryTest
diff options
context:
space:
mode:
authorkx <kx@radix.pro>2024-06-04 06:43:08 +0300
committerkx <kx@radix.pro>2024-06-04 06:43:08 +0300
commit7e2ccccace24636f29ddc210b94606abd4c7e42b (patch)
tree545d43ea12671048956cafeb12303e84d601e571 /MdeModulePkg/Universal/MemoryTest
parent27b044605cd5f6b33a3d231576003850b3fe305b (diff)
downloadedk2-trunk.tar.xz
Renormalized end-of-lines from master@27b044605cd5f6b33a3d231576003850b3fe305btrunk
Diffstat (limited to 'MdeModulePkg/Universal/MemoryTest')
-rw-r--r--MdeModulePkg/Universal/MemoryTest/GenericMemoryTestDxe/GenericMemoryTestDxe.inf106
-rw-r--r--MdeModulePkg/Universal/MemoryTest/GenericMemoryTestDxe/GenericMemoryTestDxe.uni32
-rw-r--r--MdeModulePkg/Universal/MemoryTest/GenericMemoryTestDxe/GenericMemoryTestDxeExtra.uni28
-rw-r--r--MdeModulePkg/Universal/MemoryTest/GenericMemoryTestDxe/LightMemoryTest.c1894
-rw-r--r--MdeModulePkg/Universal/MemoryTest/GenericMemoryTestDxe/LightMemoryTest.h666
-rw-r--r--MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTest.c580
-rw-r--r--MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTest.h258
-rw-r--r--MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf92
-rw-r--r--MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.uni32
-rw-r--r--MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxeExtra.uni28
10 files changed, 1858 insertions, 1858 deletions
diff --git a/MdeModulePkg/Universal/MemoryTest/GenericMemoryTestDxe/GenericMemoryTestDxe.inf b/MdeModulePkg/Universal/MemoryTest/GenericMemoryTestDxe/GenericMemoryTestDxe.inf
index ae1b5909b4..f0c9a7051b 100644
--- a/MdeModulePkg/Universal/MemoryTest/GenericMemoryTestDxe/GenericMemoryTestDxe.inf
+++ b/MdeModulePkg/Universal/MemoryTest/GenericMemoryTestDxe/GenericMemoryTestDxe.inf
@@ -1,53 +1,53 @@
-## @file
-# This driver first constructs the non-tested memory range, then performs the R/W/V memory test.
-#
-# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
-#
-# SPDX-License-Identifier: BSD-2-Clause-Patent
-#
-##
-
-[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = GenericMemoryTestDxe
- MODULE_UNI_FILE = GenericMemoryTestDxe.uni
- FILE_GUID = 9C1080EE-D02E-487f-9432-F3BF086EC180
- MODULE_TYPE = DXE_DRIVER
- VERSION_STRING = 1.0
-
- ENTRY_POINT = GenericMemoryTestEntryPoint
-
-#
-# The following information is for reference only and not required by the build tools.
-#
-# VALID_ARCHITECTURES = IA32 X64 EBC
-#
-
-[Sources]
- LightMemoryTest.h
- LightMemoryTest.c
-
-[Packages]
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
-
-[LibraryClasses]
- UefiBootServicesTableLib
- MemoryAllocationLib
- BaseMemoryLib
- BaseLib
- ReportStatusCodeLib
- DxeServicesTableLib
- HobLib
- UefiDriverEntryPoint
- DebugLib
-
-[Protocols]
- gEfiCpuArchProtocolGuid ## CONSUMES
- gEfiGenericMemTestProtocolGuid ## PRODUCES
-
-[Depex]
- gEfiCpuArchProtocolGuid
-
-[UserExtensions.TianoCore."ExtraFiles"]
- GenericMemoryTestDxeExtra.uni
+## @file
+# This driver first constructs the non-tested memory range, then performs the R/W/V memory test.
+#
+# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = GenericMemoryTestDxe
+ MODULE_UNI_FILE = GenericMemoryTestDxe.uni
+ FILE_GUID = 9C1080EE-D02E-487f-9432-F3BF086EC180
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+
+ ENTRY_POINT = GenericMemoryTestEntryPoint
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 EBC
+#
+
+[Sources]
+ LightMemoryTest.h
+ LightMemoryTest.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+ UefiBootServicesTableLib
+ MemoryAllocationLib
+ BaseMemoryLib
+ BaseLib
+ ReportStatusCodeLib
+ DxeServicesTableLib
+ HobLib
+ UefiDriverEntryPoint
+ DebugLib
+
+[Protocols]
+ gEfiCpuArchProtocolGuid ## CONSUMES
+ gEfiGenericMemTestProtocolGuid ## PRODUCES
+
+[Depex]
+ gEfiCpuArchProtocolGuid
+
+[UserExtensions.TianoCore."ExtraFiles"]
+ GenericMemoryTestDxeExtra.uni
diff --git a/MdeModulePkg/Universal/MemoryTest/GenericMemoryTestDxe/GenericMemoryTestDxe.uni b/MdeModulePkg/Universal/MemoryTest/GenericMemoryTestDxe/GenericMemoryTestDxe.uni
index 3406f90f20..00853da796 100644
--- a/MdeModulePkg/Universal/MemoryTest/GenericMemoryTestDxe/GenericMemoryTestDxe.uni
+++ b/MdeModulePkg/Universal/MemoryTest/GenericMemoryTestDxe/GenericMemoryTestDxe.uni
@@ -1,16 +1,16 @@
-// /** @file
-// This driver first constructs the non-tested memory range, then performs the R/W/V memory test.
-//
-// This driver first constructs the non-tested memory range, then performs the R/W/V memory test.
-//
-// Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
-//
-// SPDX-License-Identifier: BSD-2-Clause-Patent
-//
-// **/
-
-
-#string STR_MODULE_ABSTRACT #language en-US "Constructs the non-tested memory range, then performs the R/W/V memory test"
-
-#string STR_MODULE_DESCRIPTION #language en-US "This driver first constructs the non-tested memory range, then performs the R/W/V memory test."
-
+// /** @file
+// This driver first constructs the non-tested memory range, then performs the R/W/V memory test.
+//
+// This driver first constructs the non-tested memory range, then performs the R/W/V memory test.
+//
+// Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+
+#string STR_MODULE_ABSTRACT #language en-US "Constructs the non-tested memory range, then performs the R/W/V memory test"
+
+#string STR_MODULE_DESCRIPTION #language en-US "This driver first constructs the non-tested memory range, then performs the R/W/V memory test."
+
diff --git a/MdeModulePkg/Universal/MemoryTest/GenericMemoryTestDxe/GenericMemoryTestDxeExtra.uni b/MdeModulePkg/Universal/MemoryTest/GenericMemoryTestDxe/GenericMemoryTestDxeExtra.uni
index f7818c961a..ff5c068b01 100644
--- a/MdeModulePkg/Universal/MemoryTest/GenericMemoryTestDxe/GenericMemoryTestDxeExtra.uni
+++ b/MdeModulePkg/Universal/MemoryTest/GenericMemoryTestDxe/GenericMemoryTestDxeExtra.uni
@@ -1,14 +1,14 @@
-// /** @file
-// GenericMemoryTestDxe Localized Strings and Content
-//
-// Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
-//
-// SPDX-License-Identifier: BSD-2-Clause-Patent
-//
-// **/
-
-#string STR_PROPERTIES_MODULE_NAME
-#language en-US
-"Generic Memory Test DXE Driver"
-
-
+// /** @file
+// GenericMemoryTestDxe Localized Strings and Content
+//
+// Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_PROPERTIES_MODULE_NAME
+#language en-US
+"Generic Memory Test DXE Driver"
+
+
diff --git a/MdeModulePkg/Universal/MemoryTest/GenericMemoryTestDxe/LightMemoryTest.c b/MdeModulePkg/Universal/MemoryTest/GenericMemoryTestDxe/LightMemoryTest.c
index 8b993a7889..dc4783bd99 100644
--- a/MdeModulePkg/Universal/MemoryTest/GenericMemoryTestDxe/LightMemoryTest.c
+++ b/MdeModulePkg/Universal/MemoryTest/GenericMemoryTestDxe/LightMemoryTest.c
@@ -1,947 +1,947 @@
-/** @file
-
- Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.<BR>
-
- SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include "LightMemoryTest.h"
-
-//
-// Global:
-// Since this driver will only ever produce one instance of the memory test
-// protocol, so we do not need to dynamically allocate the PrivateData.
-//
-EFI_PHYSICAL_ADDRESS mCurrentAddress;
-LIST_ENTRY *mCurrentLink;
-NONTESTED_MEMORY_RANGE *mCurrentRange;
-UINT64 mTestedSystemMemory;
-UINT64 mNonTestedSystemMemory;
-
-UINT32 GenericMemoryTestMonoPattern[GENERIC_CACHELINE_SIZE / 4] = {
- 0x5a5a5a5a,
- 0xa5a5a5a5,
- 0x5a5a5a5a,
- 0xa5a5a5a5,
- 0x5a5a5a5a,
- 0xa5a5a5a5,
- 0x5a5a5a5a,
- 0xa5a5a5a5,
- 0x5a5a5a5a,
- 0xa5a5a5a5,
- 0x5a5a5a5a,
- 0xa5a5a5a5,
- 0x5a5a5a5a,
- 0xa5a5a5a5,
- 0x5a5a5a5a,
- 0xa5a5a5a5
-};
-
-/**
- Compares the contents of two buffers.
-
- This function compares Length bytes of SourceBuffer to Length bytes of DestinationBuffer.
- If all Length bytes of the two buffers are identical, then 0 is returned. Otherwise, the
- value returned is the first mismatched byte in SourceBuffer subtracted from the first
- mismatched byte in DestinationBuffer.
-
- If Length = 0, then ASSERT().
-
- @param[in] DestinationBuffer The pointer to the destination buffer to compare.
- @param[in] SourceBuffer The pointer to the source buffer to compare.
- @param[in] Length The number of bytes to compare.
-
- @return 0 All Length bytes of the two buffers are identical.
- @retval Non-zero The first mismatched byte in SourceBuffer subtracted from the first
- mismatched byte in DestinationBuffer.
-
-**/
-INTN
-EFIAPI
-CompareMemWithoutCheckArgument (
- IN CONST VOID *DestinationBuffer,
- IN CONST VOID *SourceBuffer,
- IN UINTN Length
- )
-{
- ASSERT (Length > 0);
- while ((--Length != 0) &&
- (*(INT8 *)DestinationBuffer == *(INT8 *)SourceBuffer))
- {
- DestinationBuffer = (INT8 *)DestinationBuffer + 1;
- SourceBuffer = (INT8 *)SourceBuffer + 1;
- }
-
- return (INTN)*(UINT8 *)DestinationBuffer - (INTN)*(UINT8 *)SourceBuffer;
-}
-
-/**
- Construct the system base memory range through GCD service.
-
- @param[in] Private Point to generic memory test driver's private data.
-
- @retval EFI_SUCCESS Successful construct the base memory range through GCD service.
- @retval EFI_OUT_OF_RESOURCE Could not allocate needed resource from base memory.
- @retval Others Failed to construct base memory range through GCD service.
-
-**/
-EFI_STATUS
-ConstructBaseMemoryRange (
- IN GENERIC_MEMORY_TEST_PRIVATE *Private
- )
-{
- UINTN NumberOfDescriptors;
- EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;
- UINTN Index;
-
- //
- // Base memory will always below 4G
- //
- gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);
-
- for (Index = 0; Index < NumberOfDescriptors; Index++) {
- if ((MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeSystemMemory) ||
- (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeMoreReliable))
- {
- Private->BaseMemorySize += MemorySpaceMap[Index].Length;
- }
- }
-
- return EFI_SUCCESS;
-}
-
-/**
- Destroy the link list base on the correspond link list type.
-
- @param[in] Private Point to generic memory test driver's private data.
-
-**/
-VOID
-DestroyLinkList (
- IN GENERIC_MEMORY_TEST_PRIVATE *Private
- )
-{
- LIST_ENTRY *Link;
- NONTESTED_MEMORY_RANGE *NontestedRange;
-
- Link = Private->NonTestedMemRanList.BackLink;
-
- while (Link != &Private->NonTestedMemRanList) {
- RemoveEntryList (Link);
- NontestedRange = NONTESTED_MEMORY_RANGE_FROM_LINK (Link);
- gBS->FreePool (NontestedRange);
- Link = Private->NonTestedMemRanList.BackLink;
- }
-}
-
-/**
- Convert the memory range to tested.
-
- @param BaseAddress Base address of the memory range.
- @param Length Length of the memory range.
- @param Capabilities Capabilities of the memory range.
-
- @retval EFI_SUCCESS The memory range is converted to tested.
- @retval others Error happens.
-**/
-EFI_STATUS
-ConvertToTestedMemory (
- IN UINT64 BaseAddress,
- IN UINT64 Length,
- IN UINT64 Capabilities
- )
-{
- EFI_STATUS Status;
-
- Status = gDS->RemoveMemorySpace (
- BaseAddress,
- Length
- );
- if (!EFI_ERROR (Status)) {
- Status = gDS->AddMemorySpace (
- ((Capabilities & EFI_MEMORY_MORE_RELIABLE) == EFI_MEMORY_MORE_RELIABLE) ?
- EfiGcdMemoryTypeMoreReliable : EfiGcdMemoryTypeSystemMemory,
- BaseAddress,
- Length,
- Capabilities &~
- (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)
- );
- }
-
- return Status;
-}
-
-/**
- Add the extened memory to whole system memory map.
-
- @param[in] Private Point to generic memory test driver's private data.
-
- @retval EFI_SUCCESS Successful add all the extended memory to system memory map.
- @retval Others Failed to add the tested extended memory.
-
-**/
-EFI_STATUS
-UpdateMemoryMap (
- IN GENERIC_MEMORY_TEST_PRIVATE *Private
- )
-{
- LIST_ENTRY *Link;
- NONTESTED_MEMORY_RANGE *Range;
-
- Link = Private->NonTestedMemRanList.ForwardLink;
-
- while (Link != &Private->NonTestedMemRanList) {
- Range = NONTESTED_MEMORY_RANGE_FROM_LINK (Link);
-
- ConvertToTestedMemory (
- Range->StartAddress,
- Range->Length,
- Range->Capabilities &~
- (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)
- );
- Link = Link->ForwardLink;
- }
-
- return EFI_SUCCESS;
-}
-
-/**
- Test a range of the memory directly .
-
- @param[in] Private Point to generic memory test driver's private data.
- @param[in] StartAddress Starting address of the memory range to be tested.
- @param[in] Length Length in bytes of the memory range to be tested.
- @param[in] Capabilities The bit mask of attributes that the memory range supports.
-
- @retval EFI_SUCCESS Successful test the range of memory.
- @retval Others Failed to test the range of memory.
-
-**/
-EFI_STATUS
-DirectRangeTest (
- IN GENERIC_MEMORY_TEST_PRIVATE *Private,
- IN EFI_PHYSICAL_ADDRESS StartAddress,
- IN UINT64 Length,
- IN UINT64 Capabilities
- )
-{
- EFI_STATUS Status;
-
- //
- // Perform a dummy memory test, so directly write the pattern to all range
- //
- WriteMemory (Private, StartAddress, Length);
-
- //
- // Verify the memory range
- //
- Status = VerifyMemory (Private, StartAddress, Length);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- //
- // Add the tested compatible memory to system memory using GCD service
- //
- ConvertToTestedMemory (
- StartAddress,
- Length,
- Capabilities &~
- (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)
- );
-
- return EFI_SUCCESS;
-}
-
-/**
- Construct the system non-tested memory range through GCD service.
-
- @param[in] Private Point to generic memory test driver's private data.
-
- @retval EFI_SUCCESS Successful construct the non-tested memory range through GCD service.
- @retval EFI_OUT_OF_RESOURCE Could not allocate needed resource from base memory.
- @retval Others Failed to construct non-tested memory range through GCD service.
-
-**/
-EFI_STATUS
-ConstructNonTestedMemoryRange (
- IN GENERIC_MEMORY_TEST_PRIVATE *Private
- )
-{
- NONTESTED_MEMORY_RANGE *Range;
- BOOLEAN NoFound;
- UINTN NumberOfDescriptors;
- EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;
- UINTN Index;
-
- //
- // Non tested memory range may be span 4G here
- //
- NoFound = TRUE;
-
- gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);
-
- for (Index = 0; Index < NumberOfDescriptors; Index++) {
- if ((MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeReserved) &&
- ((MemorySpaceMap[Index].Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==
- (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED))
- )
- {
- NoFound = FALSE;
- //
- // Light version do not need to process >4G memory range
- //
- gBS->AllocatePool (
- EfiBootServicesData,
- sizeof (NONTESTED_MEMORY_RANGE),
- (VOID **)&Range
- );
-
- Range->Signature = EFI_NONTESTED_MEMORY_RANGE_SIGNATURE;
- Range->StartAddress = MemorySpaceMap[Index].BaseAddress;
- Range->Length = MemorySpaceMap[Index].Length;
- Range->Capabilities = MemorySpaceMap[Index].Capabilities;
-
- mNonTestedSystemMemory += MemorySpaceMap[Index].Length;
- InsertTailList (&Private->NonTestedMemRanList, &Range->Link);
- }
- }
-
- if (NoFound) {
- return EFI_NOT_FOUND;
- }
-
- return EFI_SUCCESS;
-}
-
-/**
- Write the memory test pattern into a range of physical memory.
-
- @param[in] Private Point to generic memory test driver's private data.
- @param[in] Start The memory range's start address.
- @param[in] Size The memory range's size.
-
- @retval EFI_SUCCESS Successful write the test pattern into the non-tested memory.
- @retval Others The test pattern may not really write into the physical memory.
-
-**/
-EFI_STATUS
-WriteMemory (
- IN GENERIC_MEMORY_TEST_PRIVATE *Private,
- IN EFI_PHYSICAL_ADDRESS Start,
- IN UINT64 Size
- )
-{
- EFI_PHYSICAL_ADDRESS Address;
-
- Address = Start;
-
- //
- // Add 4G memory address check for IA32 platform
- // NOTE: Without page table, there is no way to use memory above 4G.
- //
- if (Start + Size > MAX_ADDRESS) {
- return EFI_SUCCESS;
- }
-
- while (Address < (Start + Size)) {
- CopyMem ((VOID *)(UINTN)Address, Private->MonoPattern, Private->MonoTestSize);
- Address += Private->CoverageSpan;
- }
-
- //
- // bug bug: we may need GCD service to make the code cache and data uncache,
- // if GCD do not support it or return fail, then just flush the whole cache.
- //
- if (Private->Cpu != NULL) {
- Private->Cpu->FlushDataCache (Private->Cpu, Start, Size, EfiCpuFlushTypeWriteBackInvalidate);
- }
-
- return EFI_SUCCESS;
-}
-
-/**
- Verify the range of physical memory which covered by memory test pattern.
-
- This function will also do not return any informatin just cause system reset,
- because the handle error encount fatal error and disable the bad DIMMs.
-
- @param[in] Private Point to generic memory test driver's private data.
- @param[in] Start The memory range's start address.
- @param[in] Size The memory range's size.
-
- @retval EFI_SUCCESS Successful verify the range of memory, no errors' location found.
- @retval Others The range of memory have errors contained.
-
-**/
-EFI_STATUS
-VerifyMemory (
- IN GENERIC_MEMORY_TEST_PRIVATE *Private,
- IN EFI_PHYSICAL_ADDRESS Start,
- IN UINT64 Size
- )
-{
- EFI_PHYSICAL_ADDRESS Address;
- INTN ErrorFound;
- EFI_MEMORY_EXTENDED_ERROR_DATA *ExtendedErrorData;
-
- Address = Start;
- ExtendedErrorData = NULL;
-
- //
- // Add 4G memory address check for IA32 platform
- // NOTE: Without page table, there is no way to use memory above 4G.
- //
- if (Start + Size > MAX_ADDRESS) {
- return EFI_SUCCESS;
- }
-
- //
- // Use the software memory test to check whether have detected miscompare
- // error here. If there is miscompare error here then check if generic
- // memory test driver can disable the bad DIMM.
- //
- while (Address < (Start + Size)) {
- ErrorFound = CompareMemWithoutCheckArgument (
- (VOID *)(UINTN)(Address),
- Private->MonoPattern,
- Private->MonoTestSize
- );
- if (ErrorFound != 0) {
- //
- // Report uncorrectable errors
- //
- ExtendedErrorData = AllocateZeroPool (sizeof (EFI_MEMORY_EXTENDED_ERROR_DATA));
- if (ExtendedErrorData == NULL) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- ExtendedErrorData->DataHeader.HeaderSize = (UINT16)sizeof (EFI_STATUS_CODE_DATA);
- ExtendedErrorData->DataHeader.Size = (UINT16)(sizeof (EFI_MEMORY_EXTENDED_ERROR_DATA) - sizeof (EFI_STATUS_CODE_DATA));
- ExtendedErrorData->Granularity = EFI_MEMORY_ERROR_DEVICE;
- ExtendedErrorData->Operation = EFI_MEMORY_OPERATION_READ;
- ExtendedErrorData->Syndrome = 0x0;
- ExtendedErrorData->Address = Address;
- ExtendedErrorData->Resolution = 0x40;
-
- REPORT_STATUS_CODE_EX (
- EFI_ERROR_CODE,
- EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_UNCORRECTABLE,
- 0,
- &gEfiGenericMemTestProtocolGuid,
- NULL,
- (UINT8 *)ExtendedErrorData + sizeof (EFI_STATUS_CODE_DATA),
- ExtendedErrorData->DataHeader.Size
- );
-
- return EFI_DEVICE_ERROR;
- }
-
- Address += Private->CoverageSpan;
- }
-
- return EFI_SUCCESS;
-}
-
-/**
- Initialize the generic memory test.
-
- @param[in] This The protocol instance pointer.
- @param[in] Level The coverage level of the memory test.
- @param[out] RequireSoftECCInit Indicate if the memory need software ECC init.
-
- @retval EFI_SUCCESS The generic memory test is initialized correctly.
- @retval EFI_NO_MEDIA The system had no memory to be tested.
-
-**/
-EFI_STATUS
-EFIAPI
-InitializeMemoryTest (
- IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
- IN EXTENDMEM_COVERAGE_LEVEL Level,
- OUT BOOLEAN *RequireSoftECCInit
- )
-{
- EFI_STATUS Status;
- GENERIC_MEMORY_TEST_PRIVATE *Private;
- EFI_CPU_ARCH_PROTOCOL *Cpu;
-
- Private = GENERIC_MEMORY_TEST_PRIVATE_FROM_THIS (This);
- *RequireSoftECCInit = FALSE;
-
- //
- // This is initialize for default value, but some value may be reset base on
- // platform memory test driver.
- //
- Private->CoverLevel = Level;
- Private->BdsBlockSize = TEST_BLOCK_SIZE;
- Private->MonoPattern = GenericMemoryTestMonoPattern;
- Private->MonoTestSize = GENERIC_CACHELINE_SIZE;
-
- //
- // Initialize several internal link list
- //
- InitializeListHead (&Private->NonTestedMemRanList);
-
- //
- // Construct base memory range
- //
- ConstructBaseMemoryRange (Private);
-
- //
- // get the cpu arch protocol to support flash cache
- //
- Status = gBS->LocateProtocol (
- &gEfiCpuArchProtocolGuid,
- NULL,
- (VOID **)&Cpu
- );
- if (!EFI_ERROR (Status)) {
- Private->Cpu = Cpu;
- }
-
- //
- // Create the CoverageSpan of the memory test base on the coverage level
- //
- switch (Private->CoverLevel) {
- case EXTENSIVE:
- Private->CoverageSpan = GENERIC_CACHELINE_SIZE;
- break;
-
- case SPARSE:
- Private->CoverageSpan = SPARSE_SPAN_SIZE;
- break;
-
- //
- // Even the BDS do not need to test any memory, but in some case it
- // still need to init ECC memory.
- //
- default:
- Private->CoverageSpan = QUICK_SPAN_SIZE;
- break;
- }
-
- //
- // This is the first time we construct the non-tested memory range, if no
- // extended memory found, we know the system have not any extended memory
- // need to be test
- //
- Status = ConstructNonTestedMemoryRange (Private);
- if (Status == EFI_NOT_FOUND) {
- return EFI_NO_MEDIA;
- }
-
- //
- // ready to perform the R/W/V memory test
- //
- mTestedSystemMemory = Private->BaseMemorySize;
- mCurrentLink = Private->NonTestedMemRanList.ForwardLink;
- mCurrentRange = NONTESTED_MEMORY_RANGE_FROM_LINK (mCurrentLink);
- mCurrentAddress = mCurrentRange->StartAddress;
-
- return EFI_SUCCESS;
-}
-
-/**
- Perform the memory test.
-
- @param[in] This The protocol instance pointer.
- @param[out] TestedMemorySize Return the tested extended memory size.
- @param[out] TotalMemorySize Return the whole system physical memory size.
- The total memory size does not include memory in a slot with a disabled DIMM.
- @param[out] ErrorOut TRUE if the memory error occurred.
- @param[in] IfTestAbort Indicates that the user pressed "ESC" to skip the memory test.
-
- @retval EFI_SUCCESS One block of memory passed the test.
- @retval EFI_NOT_FOUND All memory blocks have already been tested.
- @retval EFI_DEVICE_ERROR Memory device error occurred, and no agent can handle it.
-
-**/
-EFI_STATUS
-EFIAPI
-GenPerformMemoryTest (
- IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
- OUT UINT64 *TestedMemorySize,
- OUT UINT64 *TotalMemorySize,
- OUT BOOLEAN *ErrorOut,
- IN BOOLEAN TestAbort
- )
-{
- EFI_STATUS Status;
- GENERIC_MEMORY_TEST_PRIVATE *Private;
- EFI_MEMORY_RANGE_EXTENDED_DATA *RangeData;
- UINT64 BlockBoundary;
-
- Private = GENERIC_MEMORY_TEST_PRIVATE_FROM_THIS (This);
- *ErrorOut = FALSE;
- RangeData = NULL;
- BlockBoundary = 0;
-
- //
- // In extensive mode the boundary of "mCurrentRange->Length" may will lost
- // some range that is not Private->BdsBlockSize size boundary, so need
- // the software mechanism to confirm all memory location be covered.
- //
- if (mCurrentAddress < (mCurrentRange->StartAddress + mCurrentRange->Length)) {
- if ((mCurrentAddress + Private->BdsBlockSize) <= (mCurrentRange->StartAddress + mCurrentRange->Length)) {
- BlockBoundary = Private->BdsBlockSize;
- } else {
- BlockBoundary = mCurrentRange->StartAddress + mCurrentRange->Length - mCurrentAddress;
- }
-
- //
- // If TestAbort is true, means user cancel the memory test
- //
- if (!TestAbort && (Private->CoverLevel != IGNORE)) {
- //
- // Report status code of every memory range
- //
- RangeData = AllocateZeroPool (sizeof (EFI_MEMORY_RANGE_EXTENDED_DATA));
- if (RangeData == NULL) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- RangeData->DataHeader.HeaderSize = (UINT16)sizeof (EFI_STATUS_CODE_DATA);
- RangeData->DataHeader.Size = (UINT16)(sizeof (EFI_MEMORY_RANGE_EXTENDED_DATA) - sizeof (EFI_STATUS_CODE_DATA));
- RangeData->Start = mCurrentAddress;
- RangeData->Length = BlockBoundary;
-
- REPORT_STATUS_CODE_EX (
- EFI_PROGRESS_CODE,
- EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_PC_TEST,
- 0,
- &gEfiGenericMemTestProtocolGuid,
- NULL,
- (UINT8 *)RangeData + sizeof (EFI_STATUS_CODE_DATA),
- RangeData->DataHeader.Size
- );
-
- //
- // The software memory test (R/W/V) perform here. It will detect the
- // memory mis-compare error.
- //
- WriteMemory (Private, mCurrentAddress, BlockBoundary);
-
- Status = VerifyMemory (Private, mCurrentAddress, BlockBoundary);
- if (EFI_ERROR (Status)) {
- //
- // If perform here, means there is mis-compare error, and no agent can
- // handle it, so we return to BDS EFI_DEVICE_ERROR.
- //
- *ErrorOut = TRUE;
- return EFI_DEVICE_ERROR;
- }
- }
-
- mTestedSystemMemory += BlockBoundary;
- *TestedMemorySize = mTestedSystemMemory;
-
- //
- // If the memory test restart after the platform driver disable dimms,
- // the NonTestSystemMemory may be changed, but the base memory size will
- // not changed, so we can get the current total memory size.
- //
- *TotalMemorySize = Private->BaseMemorySize + mNonTestedSystemMemory;
-
- //
- // Update the current test address pointing to next BDS BLOCK
- //
- mCurrentAddress += Private->BdsBlockSize;
-
- return EFI_SUCCESS;
- }
-
- //
- // Change to next non tested memory range
- //
- mCurrentLink = mCurrentLink->ForwardLink;
- if (mCurrentLink != &Private->NonTestedMemRanList) {
- mCurrentRange = NONTESTED_MEMORY_RANGE_FROM_LINK (mCurrentLink);
- mCurrentAddress = mCurrentRange->StartAddress;
- return EFI_SUCCESS;
- } else {
- //
- // Here means all the memory test have finished
- //
- *TestedMemorySize = mTestedSystemMemory;
- *TotalMemorySize = Private->BaseMemorySize + mNonTestedSystemMemory;
- return EFI_NOT_FOUND;
- }
-}
-
-/**
- Finish the memory test.
-
- @param[in] This The protocol instance pointer.
-
- @retval EFI_SUCCESS Success. All resources used in the memory test are freed.
-
-**/
-EFI_STATUS
-EFIAPI
-GenMemoryTestFinished (
- IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This
- )
-{
- EFI_STATUS Status;
- GENERIC_MEMORY_TEST_PRIVATE *Private;
-
- Private = GENERIC_MEMORY_TEST_PRIVATE_FROM_THIS (This);
-
- //
- // Perform Data and Address line test only if not ignore memory test
- //
- if (Private->CoverLevel != IGNORE) {
- Status = PerformAddressDataLineTest (Private);
- ASSERT_EFI_ERROR (Status);
- }
-
- //
- // Add the non tested memory range to system memory map through GCD service
- //
- UpdateMemoryMap (Private);
-
- //
- // we need to free all the memory allocate
- //
- DestroyLinkList (Private);
-
- return EFI_SUCCESS;
-}
-
-/**
- Provides the capability to test the compatible range used by some special drivers.
-
- @param[in] This The protocol instance pointer.
- @param[in] StartAddress The start address of the compatible memory range that
- must be below 16M.
- @param[in] Length The compatible memory range's length.
-
- @retval EFI_SUCCESS The compatible memory range pass the memory test.
- @retval EFI_INVALID_PARAMETER The compatible memory range are not below Low 16M.
-
-**/
-EFI_STATUS
-EFIAPI
-GenCompatibleRangeTest (
- IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
- IN EFI_PHYSICAL_ADDRESS StartAddress,
- IN UINT64 Length
- )
-{
- EFI_STATUS Status;
- GENERIC_MEMORY_TEST_PRIVATE *Private;
- EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
- EFI_PHYSICAL_ADDRESS CurrentBase;
- UINT64 CurrentLength;
-
- Private = GENERIC_MEMORY_TEST_PRIVATE_FROM_THIS (This);
-
- //
- // Check if the parameter is below 16MB
- //
- if (StartAddress + Length > 0x1000000) {
- return EFI_INVALID_PARAMETER;
- }
-
- CurrentBase = StartAddress;
- do {
- //
- // Check the required memory range status; if the required memory range span
- // the different GCD memory descriptor, it may be cause different action.
- //
- Status = gDS->GetMemorySpaceDescriptor (
- CurrentBase,
- &Descriptor
- );
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- if ((Descriptor.GcdMemoryType == EfiGcdMemoryTypeReserved) &&
- ((Descriptor.Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==
- (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED))
- )
- {
- CurrentLength = Descriptor.BaseAddress + Descriptor.Length - CurrentBase;
- if (CurrentBase + CurrentLength > StartAddress + Length) {
- CurrentLength = StartAddress + Length - CurrentBase;
- }
-
- Status = DirectRangeTest (
- Private,
- CurrentBase,
- CurrentLength,
- Descriptor.Capabilities
- );
- if (EFI_ERROR (Status)) {
- return Status;
- }
- }
-
- CurrentBase = Descriptor.BaseAddress + Descriptor.Length;
- } while (CurrentBase < StartAddress + Length);
-
- //
- // Here means the required range already be tested, so just return success.
- //
- return EFI_SUCCESS;
-}
-
-/**
- Perform the address line walking ones test.
-
- @param[in] Private Point to generic memory test driver's private data.
-
- @retval EFI_SUCCESS Successful finished walking ones test.
- @retval EFI_OUT_OF_RESOURCE Could not get resource in base memory.
- @retval EFI_ACCESS_DENIED Code may can not run here because if walking one test
- failed, system may be already halt.
-
-**/
-EFI_STATUS
-PerformAddressDataLineTest (
- IN GENERIC_MEMORY_TEST_PRIVATE *Private
- )
-{
- LIST_ENTRY *ExtendedLink;
- NONTESTED_MEMORY_RANGE *ExtendedRange;
- BOOLEAN InExtendedRange;
- EFI_PHYSICAL_ADDRESS TestAddress;
-
- //
- // Light version no data line test, only perform the address line test
- //
- TestAddress = (EFI_PHYSICAL_ADDRESS)0x1;
- while (TestAddress < MAX_ADDRESS && TestAddress > 0) {
- //
- // only test if the address falls in the enabled range
- //
- InExtendedRange = FALSE;
- ExtendedLink = Private->NonTestedMemRanList.BackLink;
- while (ExtendedLink != &Private->NonTestedMemRanList) {
- ExtendedRange = NONTESTED_MEMORY_RANGE_FROM_LINK (ExtendedLink);
- if ((TestAddress >= ExtendedRange->StartAddress) &&
- (TestAddress < (ExtendedRange->StartAddress + ExtendedRange->Length))
- )
- {
- InExtendedRange = TRUE;
- }
-
- ExtendedLink = ExtendedLink->BackLink;
- }
-
- if (InExtendedRange) {
- *(EFI_PHYSICAL_ADDRESS *)(UINTN)TestAddress = TestAddress;
- Private->Cpu->FlushDataCache (Private->Cpu, TestAddress, 1, EfiCpuFlushTypeWriteBackInvalidate);
- if (*(EFI_PHYSICAL_ADDRESS *)(UINTN)TestAddress != TestAddress) {
- return EFI_ACCESS_DENIED;
- }
- }
-
- TestAddress = LShiftU64 (TestAddress, 1);
- }
-
- return EFI_SUCCESS;
-}
-
-//
-// Driver entry here
-//
-GENERIC_MEMORY_TEST_PRIVATE mGenericMemoryTestPrivate = {
- EFI_GENERIC_MEMORY_TEST_PRIVATE_SIGNATURE,
- NULL,
- NULL,
- {
- InitializeMemoryTest,
- GenPerformMemoryTest,
- GenMemoryTestFinished,
- GenCompatibleRangeTest
- },
- (EXTENDMEM_COVERAGE_LEVEL)0,
- 0,
- 0,
- NULL,
- 0,
- 0,
- {
- NULL,
- NULL
- }
-};
-
-/**
- The generic memory test driver's entry point.
-
- It initializes private data to default value.
-
- @param[in] ImageHandle The firmware allocated handle for the EFI image.
- @param[in] SystemTable A pointer to the EFI System Table.
-
- @retval EFI_SUCCESS The entry point is executed successfully.
- @retval EFI_NOT_FOUND Can't find HandOff Hob in HobList.
- @retval other Some error occurs when executing this entry point.
-
-**/
-EFI_STATUS
-EFIAPI
-GenericMemoryTestEntryPoint (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
-{
- EFI_STATUS Status;
- VOID *HobList;
- EFI_BOOT_MODE BootMode;
- EFI_PEI_HOB_POINTERS Hob;
-
- //
- // Use the generic pattern to test compatible memory range
- //
- mGenericMemoryTestPrivate.MonoPattern = GenericMemoryTestMonoPattern;
- mGenericMemoryTestPrivate.MonoTestSize = GENERIC_CACHELINE_SIZE;
-
- //
- // Get the platform boot mode
- //
- HobList = GetHobList ();
-
- Hob.Raw = HobList;
- if (Hob.Header->HobType != EFI_HOB_TYPE_HANDOFF) {
- return EFI_NOT_FOUND;
- }
-
- BootMode = Hob.HandoffInformationTable->BootMode;
-
- //
- // Get the platform boot mode and create the default memory test coverage
- // level and span size for compatible memory test using
- //
- switch (BootMode) {
- case BOOT_WITH_FULL_CONFIGURATION:
- case BOOT_WITH_DEFAULT_SETTINGS:
- mGenericMemoryTestPrivate.CoverageSpan = SPARSE_SPAN_SIZE;
- break;
-
- case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS:
- mGenericMemoryTestPrivate.CoverageSpan = GENERIC_CACHELINE_SIZE;
- break;
-
- default:
- mGenericMemoryTestPrivate.CoverageSpan = QUICK_SPAN_SIZE;
- break;
- }
-
- //
- // Install the protocol
- //
- Status = gBS->InstallProtocolInterface (
- &mGenericMemoryTestPrivate.Handle,
- &gEfiGenericMemTestProtocolGuid,
- EFI_NATIVE_INTERFACE,
- &mGenericMemoryTestPrivate.GenericMemoryTest
- );
-
- return Status;
-}
+/** @file
+
+ Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "LightMemoryTest.h"
+
+//
+// Global:
+// Since this driver will only ever produce one instance of the memory test
+// protocol, so we do not need to dynamically allocate the PrivateData.
+//
+EFI_PHYSICAL_ADDRESS mCurrentAddress;
+LIST_ENTRY *mCurrentLink;
+NONTESTED_MEMORY_RANGE *mCurrentRange;
+UINT64 mTestedSystemMemory;
+UINT64 mNonTestedSystemMemory;
+
+UINT32 GenericMemoryTestMonoPattern[GENERIC_CACHELINE_SIZE / 4] = {
+ 0x5a5a5a5a,
+ 0xa5a5a5a5,
+ 0x5a5a5a5a,
+ 0xa5a5a5a5,
+ 0x5a5a5a5a,
+ 0xa5a5a5a5,
+ 0x5a5a5a5a,
+ 0xa5a5a5a5,
+ 0x5a5a5a5a,
+ 0xa5a5a5a5,
+ 0x5a5a5a5a,
+ 0xa5a5a5a5,
+ 0x5a5a5a5a,
+ 0xa5a5a5a5,
+ 0x5a5a5a5a,
+ 0xa5a5a5a5
+};
+
+/**
+ Compares the contents of two buffers.
+
+ This function compares Length bytes of SourceBuffer to Length bytes of DestinationBuffer.
+ If all Length bytes of the two buffers are identical, then 0 is returned. Otherwise, the
+ value returned is the first mismatched byte in SourceBuffer subtracted from the first
+ mismatched byte in DestinationBuffer.
+
+ If Length = 0, then ASSERT().
+
+ @param[in] DestinationBuffer The pointer to the destination buffer to compare.
+ @param[in] SourceBuffer The pointer to the source buffer to compare.
+ @param[in] Length The number of bytes to compare.
+
+ @return 0 All Length bytes of the two buffers are identical.
+ @retval Non-zero The first mismatched byte in SourceBuffer subtracted from the first
+ mismatched byte in DestinationBuffer.
+
+**/
+INTN
+EFIAPI
+CompareMemWithoutCheckArgument (
+ IN CONST VOID *DestinationBuffer,
+ IN CONST VOID *SourceBuffer,
+ IN UINTN Length
+ )
+{
+ ASSERT (Length > 0);
+ while ((--Length != 0) &&
+ (*(INT8 *)DestinationBuffer == *(INT8 *)SourceBuffer))
+ {
+ DestinationBuffer = (INT8 *)DestinationBuffer + 1;
+ SourceBuffer = (INT8 *)SourceBuffer + 1;
+ }
+
+ return (INTN)*(UINT8 *)DestinationBuffer - (INTN)*(UINT8 *)SourceBuffer;
+}
+
+/**
+ Construct the system base memory range through GCD service.
+
+ @param[in] Private Point to generic memory test driver's private data.
+
+ @retval EFI_SUCCESS Successful construct the base memory range through GCD service.
+ @retval EFI_OUT_OF_RESOURCE Could not allocate needed resource from base memory.
+ @retval Others Failed to construct base memory range through GCD service.
+
+**/
+EFI_STATUS
+ConstructBaseMemoryRange (
+ IN GENERIC_MEMORY_TEST_PRIVATE *Private
+ )
+{
+ UINTN NumberOfDescriptors;
+ EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;
+ UINTN Index;
+
+ //
+ // Base memory will always below 4G
+ //
+ gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);
+
+ for (Index = 0; Index < NumberOfDescriptors; Index++) {
+ if ((MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeSystemMemory) ||
+ (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeMoreReliable))
+ {
+ Private->BaseMemorySize += MemorySpaceMap[Index].Length;
+ }
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Destroy the link list base on the correspond link list type.
+
+ @param[in] Private Point to generic memory test driver's private data.
+
+**/
+VOID
+DestroyLinkList (
+ IN GENERIC_MEMORY_TEST_PRIVATE *Private
+ )
+{
+ LIST_ENTRY *Link;
+ NONTESTED_MEMORY_RANGE *NontestedRange;
+
+ Link = Private->NonTestedMemRanList.BackLink;
+
+ while (Link != &Private->NonTestedMemRanList) {
+ RemoveEntryList (Link);
+ NontestedRange = NONTESTED_MEMORY_RANGE_FROM_LINK (Link);
+ gBS->FreePool (NontestedRange);
+ Link = Private->NonTestedMemRanList.BackLink;
+ }
+}
+
+/**
+ Convert the memory range to tested.
+
+ @param BaseAddress Base address of the memory range.
+ @param Length Length of the memory range.
+ @param Capabilities Capabilities of the memory range.
+
+ @retval EFI_SUCCESS The memory range is converted to tested.
+ @retval others Error happens.
+**/
+EFI_STATUS
+ConvertToTestedMemory (
+ IN UINT64 BaseAddress,
+ IN UINT64 Length,
+ IN UINT64 Capabilities
+ )
+{
+ EFI_STATUS Status;
+
+ Status = gDS->RemoveMemorySpace (
+ BaseAddress,
+ Length
+ );
+ if (!EFI_ERROR (Status)) {
+ Status = gDS->AddMemorySpace (
+ ((Capabilities & EFI_MEMORY_MORE_RELIABLE) == EFI_MEMORY_MORE_RELIABLE) ?
+ EfiGcdMemoryTypeMoreReliable : EfiGcdMemoryTypeSystemMemory,
+ BaseAddress,
+ Length,
+ Capabilities &~
+ (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)
+ );
+ }
+
+ return Status;
+}
+
+/**
+ Add the extened memory to whole system memory map.
+
+ @param[in] Private Point to generic memory test driver's private data.
+
+ @retval EFI_SUCCESS Successful add all the extended memory to system memory map.
+ @retval Others Failed to add the tested extended memory.
+
+**/
+EFI_STATUS
+UpdateMemoryMap (
+ IN GENERIC_MEMORY_TEST_PRIVATE *Private
+ )
+{
+ LIST_ENTRY *Link;
+ NONTESTED_MEMORY_RANGE *Range;
+
+ Link = Private->NonTestedMemRanList.ForwardLink;
+
+ while (Link != &Private->NonTestedMemRanList) {
+ Range = NONTESTED_MEMORY_RANGE_FROM_LINK (Link);
+
+ ConvertToTestedMemory (
+ Range->StartAddress,
+ Range->Length,
+ Range->Capabilities &~
+ (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)
+ );
+ Link = Link->ForwardLink;
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Test a range of the memory directly .
+
+ @param[in] Private Point to generic memory test driver's private data.
+ @param[in] StartAddress Starting address of the memory range to be tested.
+ @param[in] Length Length in bytes of the memory range to be tested.
+ @param[in] Capabilities The bit mask of attributes that the memory range supports.
+
+ @retval EFI_SUCCESS Successful test the range of memory.
+ @retval Others Failed to test the range of memory.
+
+**/
+EFI_STATUS
+DirectRangeTest (
+ IN GENERIC_MEMORY_TEST_PRIVATE *Private,
+ IN EFI_PHYSICAL_ADDRESS StartAddress,
+ IN UINT64 Length,
+ IN UINT64 Capabilities
+ )
+{
+ EFI_STATUS Status;
+
+ //
+ // Perform a dummy memory test, so directly write the pattern to all range
+ //
+ WriteMemory (Private, StartAddress, Length);
+
+ //
+ // Verify the memory range
+ //
+ Status = VerifyMemory (Private, StartAddress, Length);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Add the tested compatible memory to system memory using GCD service
+ //
+ ConvertToTestedMemory (
+ StartAddress,
+ Length,
+ Capabilities &~
+ (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)
+ );
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Construct the system non-tested memory range through GCD service.
+
+ @param[in] Private Point to generic memory test driver's private data.
+
+ @retval EFI_SUCCESS Successful construct the non-tested memory range through GCD service.
+ @retval EFI_OUT_OF_RESOURCE Could not allocate needed resource from base memory.
+ @retval Others Failed to construct non-tested memory range through GCD service.
+
+**/
+EFI_STATUS
+ConstructNonTestedMemoryRange (
+ IN GENERIC_MEMORY_TEST_PRIVATE *Private
+ )
+{
+ NONTESTED_MEMORY_RANGE *Range;
+ BOOLEAN NoFound;
+ UINTN NumberOfDescriptors;
+ EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;
+ UINTN Index;
+
+ //
+ // Non tested memory range may be span 4G here
+ //
+ NoFound = TRUE;
+
+ gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);
+
+ for (Index = 0; Index < NumberOfDescriptors; Index++) {
+ if ((MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeReserved) &&
+ ((MemorySpaceMap[Index].Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==
+ (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED))
+ )
+ {
+ NoFound = FALSE;
+ //
+ // Light version do not need to process >4G memory range
+ //
+ gBS->AllocatePool (
+ EfiBootServicesData,
+ sizeof (NONTESTED_MEMORY_RANGE),
+ (VOID **)&Range
+ );
+
+ Range->Signature = EFI_NONTESTED_MEMORY_RANGE_SIGNATURE;
+ Range->StartAddress = MemorySpaceMap[Index].BaseAddress;
+ Range->Length = MemorySpaceMap[Index].Length;
+ Range->Capabilities = MemorySpaceMap[Index].Capabilities;
+
+ mNonTestedSystemMemory += MemorySpaceMap[Index].Length;
+ InsertTailList (&Private->NonTestedMemRanList, &Range->Link);
+ }
+ }
+
+ if (NoFound) {
+ return EFI_NOT_FOUND;
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Write the memory test pattern into a range of physical memory.
+
+ @param[in] Private Point to generic memory test driver's private data.
+ @param[in] Start The memory range's start address.
+ @param[in] Size The memory range's size.
+
+ @retval EFI_SUCCESS Successful write the test pattern into the non-tested memory.
+ @retval Others The test pattern may not really write into the physical memory.
+
+**/
+EFI_STATUS
+WriteMemory (
+ IN GENERIC_MEMORY_TEST_PRIVATE *Private,
+ IN EFI_PHYSICAL_ADDRESS Start,
+ IN UINT64 Size
+ )
+{
+ EFI_PHYSICAL_ADDRESS Address;
+
+ Address = Start;
+
+ //
+ // Add 4G memory address check for IA32 platform
+ // NOTE: Without page table, there is no way to use memory above 4G.
+ //
+ if (Start + Size > MAX_ADDRESS) {
+ return EFI_SUCCESS;
+ }
+
+ while (Address < (Start + Size)) {
+ CopyMem ((VOID *)(UINTN)Address, Private->MonoPattern, Private->MonoTestSize);
+ Address += Private->CoverageSpan;
+ }
+
+ //
+ // bug bug: we may need GCD service to make the code cache and data uncache,
+ // if GCD do not support it or return fail, then just flush the whole cache.
+ //
+ if (Private->Cpu != NULL) {
+ Private->Cpu->FlushDataCache (Private->Cpu, Start, Size, EfiCpuFlushTypeWriteBackInvalidate);
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Verify the range of physical memory which covered by memory test pattern.
+
+ This function will also do not return any informatin just cause system reset,
+ because the handle error encount fatal error and disable the bad DIMMs.
+
+ @param[in] Private Point to generic memory test driver's private data.
+ @param[in] Start The memory range's start address.
+ @param[in] Size The memory range's size.
+
+ @retval EFI_SUCCESS Successful verify the range of memory, no errors' location found.
+ @retval Others The range of memory have errors contained.
+
+**/
+EFI_STATUS
+VerifyMemory (
+ IN GENERIC_MEMORY_TEST_PRIVATE *Private,
+ IN EFI_PHYSICAL_ADDRESS Start,
+ IN UINT64 Size
+ )
+{
+ EFI_PHYSICAL_ADDRESS Address;
+ INTN ErrorFound;
+ EFI_MEMORY_EXTENDED_ERROR_DATA *ExtendedErrorData;
+
+ Address = Start;
+ ExtendedErrorData = NULL;
+
+ //
+ // Add 4G memory address check for IA32 platform
+ // NOTE: Without page table, there is no way to use memory above 4G.
+ //
+ if (Start + Size > MAX_ADDRESS) {
+ return EFI_SUCCESS;
+ }
+
+ //
+ // Use the software memory test to check whether have detected miscompare
+ // error here. If there is miscompare error here then check if generic
+ // memory test driver can disable the bad DIMM.
+ //
+ while (Address < (Start + Size)) {
+ ErrorFound = CompareMemWithoutCheckArgument (
+ (VOID *)(UINTN)(Address),
+ Private->MonoPattern,
+ Private->MonoTestSize
+ );
+ if (ErrorFound != 0) {
+ //
+ // Report uncorrectable errors
+ //
+ ExtendedErrorData = AllocateZeroPool (sizeof (EFI_MEMORY_EXTENDED_ERROR_DATA));
+ if (ExtendedErrorData == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ ExtendedErrorData->DataHeader.HeaderSize = (UINT16)sizeof (EFI_STATUS_CODE_DATA);
+ ExtendedErrorData->DataHeader.Size = (UINT16)(sizeof (EFI_MEMORY_EXTENDED_ERROR_DATA) - sizeof (EFI_STATUS_CODE_DATA));
+ ExtendedErrorData->Granularity = EFI_MEMORY_ERROR_DEVICE;
+ ExtendedErrorData->Operation = EFI_MEMORY_OPERATION_READ;
+ ExtendedErrorData->Syndrome = 0x0;
+ ExtendedErrorData->Address = Address;
+ ExtendedErrorData->Resolution = 0x40;
+
+ REPORT_STATUS_CODE_EX (
+ EFI_ERROR_CODE,
+ EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_UNCORRECTABLE,
+ 0,
+ &gEfiGenericMemTestProtocolGuid,
+ NULL,
+ (UINT8 *)ExtendedErrorData + sizeof (EFI_STATUS_CODE_DATA),
+ ExtendedErrorData->DataHeader.Size
+ );
+
+ return EFI_DEVICE_ERROR;
+ }
+
+ Address += Private->CoverageSpan;
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Initialize the generic memory test.
+
+ @param[in] This The protocol instance pointer.
+ @param[in] Level The coverage level of the memory test.
+ @param[out] RequireSoftECCInit Indicate if the memory need software ECC init.
+
+ @retval EFI_SUCCESS The generic memory test is initialized correctly.
+ @retval EFI_NO_MEDIA The system had no memory to be tested.
+
+**/
+EFI_STATUS
+EFIAPI
+InitializeMemoryTest (
+ IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
+ IN EXTENDMEM_COVERAGE_LEVEL Level,
+ OUT BOOLEAN *RequireSoftECCInit
+ )
+{
+ EFI_STATUS Status;
+ GENERIC_MEMORY_TEST_PRIVATE *Private;
+ EFI_CPU_ARCH_PROTOCOL *Cpu;
+
+ Private = GENERIC_MEMORY_TEST_PRIVATE_FROM_THIS (This);
+ *RequireSoftECCInit = FALSE;
+
+ //
+ // This is initialize for default value, but some value may be reset base on
+ // platform memory test driver.
+ //
+ Private->CoverLevel = Level;
+ Private->BdsBlockSize = TEST_BLOCK_SIZE;
+ Private->MonoPattern = GenericMemoryTestMonoPattern;
+ Private->MonoTestSize = GENERIC_CACHELINE_SIZE;
+
+ //
+ // Initialize several internal link list
+ //
+ InitializeListHead (&Private->NonTestedMemRanList);
+
+ //
+ // Construct base memory range
+ //
+ ConstructBaseMemoryRange (Private);
+
+ //
+ // get the cpu arch protocol to support flash cache
+ //
+ Status = gBS->LocateProtocol (
+ &gEfiCpuArchProtocolGuid,
+ NULL,
+ (VOID **)&Cpu
+ );
+ if (!EFI_ERROR (Status)) {
+ Private->Cpu = Cpu;
+ }
+
+ //
+ // Create the CoverageSpan of the memory test base on the coverage level
+ //
+ switch (Private->CoverLevel) {
+ case EXTENSIVE:
+ Private->CoverageSpan = GENERIC_CACHELINE_SIZE;
+ break;
+
+ case SPARSE:
+ Private->CoverageSpan = SPARSE_SPAN_SIZE;
+ break;
+
+ //
+ // Even the BDS do not need to test any memory, but in some case it
+ // still need to init ECC memory.
+ //
+ default:
+ Private->CoverageSpan = QUICK_SPAN_SIZE;
+ break;
+ }
+
+ //
+ // This is the first time we construct the non-tested memory range, if no
+ // extended memory found, we know the system have not any extended memory
+ // need to be test
+ //
+ Status = ConstructNonTestedMemoryRange (Private);
+ if (Status == EFI_NOT_FOUND) {
+ return EFI_NO_MEDIA;
+ }
+
+ //
+ // ready to perform the R/W/V memory test
+ //
+ mTestedSystemMemory = Private->BaseMemorySize;
+ mCurrentLink = Private->NonTestedMemRanList.ForwardLink;
+ mCurrentRange = NONTESTED_MEMORY_RANGE_FROM_LINK (mCurrentLink);
+ mCurrentAddress = mCurrentRange->StartAddress;
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Perform the memory test.
+
+ @param[in] This The protocol instance pointer.
+ @param[out] TestedMemorySize Return the tested extended memory size.
+ @param[out] TotalMemorySize Return the whole system physical memory size.
+ The total memory size does not include memory in a slot with a disabled DIMM.
+ @param[out] ErrorOut TRUE if the memory error occurred.
+ @param[in] IfTestAbort Indicates that the user pressed "ESC" to skip the memory test.
+
+ @retval EFI_SUCCESS One block of memory passed the test.
+ @retval EFI_NOT_FOUND All memory blocks have already been tested.
+ @retval EFI_DEVICE_ERROR Memory device error occurred, and no agent can handle it.
+
+**/
+EFI_STATUS
+EFIAPI
+GenPerformMemoryTest (
+ IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
+ OUT UINT64 *TestedMemorySize,
+ OUT UINT64 *TotalMemorySize,
+ OUT BOOLEAN *ErrorOut,
+ IN BOOLEAN TestAbort
+ )
+{
+ EFI_STATUS Status;
+ GENERIC_MEMORY_TEST_PRIVATE *Private;
+ EFI_MEMORY_RANGE_EXTENDED_DATA *RangeData;
+ UINT64 BlockBoundary;
+
+ Private = GENERIC_MEMORY_TEST_PRIVATE_FROM_THIS (This);
+ *ErrorOut = FALSE;
+ RangeData = NULL;
+ BlockBoundary = 0;
+
+ //
+ // In extensive mode the boundary of "mCurrentRange->Length" may will lost
+ // some range that is not Private->BdsBlockSize size boundary, so need
+ // the software mechanism to confirm all memory location be covered.
+ //
+ if (mCurrentAddress < (mCurrentRange->StartAddress + mCurrentRange->Length)) {
+ if ((mCurrentAddress + Private->BdsBlockSize) <= (mCurrentRange->StartAddress + mCurrentRange->Length)) {
+ BlockBoundary = Private->BdsBlockSize;
+ } else {
+ BlockBoundary = mCurrentRange->StartAddress + mCurrentRange->Length - mCurrentAddress;
+ }
+
+ //
+ // If TestAbort is true, means user cancel the memory test
+ //
+ if (!TestAbort && (Private->CoverLevel != IGNORE)) {
+ //
+ // Report status code of every memory range
+ //
+ RangeData = AllocateZeroPool (sizeof (EFI_MEMORY_RANGE_EXTENDED_DATA));
+ if (RangeData == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ RangeData->DataHeader.HeaderSize = (UINT16)sizeof (EFI_STATUS_CODE_DATA);
+ RangeData->DataHeader.Size = (UINT16)(sizeof (EFI_MEMORY_RANGE_EXTENDED_DATA) - sizeof (EFI_STATUS_CODE_DATA));
+ RangeData->Start = mCurrentAddress;
+ RangeData->Length = BlockBoundary;
+
+ REPORT_STATUS_CODE_EX (
+ EFI_PROGRESS_CODE,
+ EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_PC_TEST,
+ 0,
+ &gEfiGenericMemTestProtocolGuid,
+ NULL,
+ (UINT8 *)RangeData + sizeof (EFI_STATUS_CODE_DATA),
+ RangeData->DataHeader.Size
+ );
+
+ //
+ // The software memory test (R/W/V) perform here. It will detect the
+ // memory mis-compare error.
+ //
+ WriteMemory (Private, mCurrentAddress, BlockBoundary);
+
+ Status = VerifyMemory (Private, mCurrentAddress, BlockBoundary);
+ if (EFI_ERROR (Status)) {
+ //
+ // If perform here, means there is mis-compare error, and no agent can
+ // handle it, so we return to BDS EFI_DEVICE_ERROR.
+ //
+ *ErrorOut = TRUE;
+ return EFI_DEVICE_ERROR;
+ }
+ }
+
+ mTestedSystemMemory += BlockBoundary;
+ *TestedMemorySize = mTestedSystemMemory;
+
+ //
+ // If the memory test restart after the platform driver disable dimms,
+ // the NonTestSystemMemory may be changed, but the base memory size will
+ // not changed, so we can get the current total memory size.
+ //
+ *TotalMemorySize = Private->BaseMemorySize + mNonTestedSystemMemory;
+
+ //
+ // Update the current test address pointing to next BDS BLOCK
+ //
+ mCurrentAddress += Private->BdsBlockSize;
+
+ return EFI_SUCCESS;
+ }
+
+ //
+ // Change to next non tested memory range
+ //
+ mCurrentLink = mCurrentLink->ForwardLink;
+ if (mCurrentLink != &Private->NonTestedMemRanList) {
+ mCurrentRange = NONTESTED_MEMORY_RANGE_FROM_LINK (mCurrentLink);
+ mCurrentAddress = mCurrentRange->StartAddress;
+ return EFI_SUCCESS;
+ } else {
+ //
+ // Here means all the memory test have finished
+ //
+ *TestedMemorySize = mTestedSystemMemory;
+ *TotalMemorySize = Private->BaseMemorySize + mNonTestedSystemMemory;
+ return EFI_NOT_FOUND;
+ }
+}
+
+/**
+ Finish the memory test.
+
+ @param[in] This The protocol instance pointer.
+
+ @retval EFI_SUCCESS Success. All resources used in the memory test are freed.
+
+**/
+EFI_STATUS
+EFIAPI
+GenMemoryTestFinished (
+ IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This
+ )
+{
+ EFI_STATUS Status;
+ GENERIC_MEMORY_TEST_PRIVATE *Private;
+
+ Private = GENERIC_MEMORY_TEST_PRIVATE_FROM_THIS (This);
+
+ //
+ // Perform Data and Address line test only if not ignore memory test
+ //
+ if (Private->CoverLevel != IGNORE) {
+ Status = PerformAddressDataLineTest (Private);
+ ASSERT_EFI_ERROR (Status);
+ }
+
+ //
+ // Add the non tested memory range to system memory map through GCD service
+ //
+ UpdateMemoryMap (Private);
+
+ //
+ // we need to free all the memory allocate
+ //
+ DestroyLinkList (Private);
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Provides the capability to test the compatible range used by some special drivers.
+
+ @param[in] This The protocol instance pointer.
+ @param[in] StartAddress The start address of the compatible memory range that
+ must be below 16M.
+ @param[in] Length The compatible memory range's length.
+
+ @retval EFI_SUCCESS The compatible memory range pass the memory test.
+ @retval EFI_INVALID_PARAMETER The compatible memory range are not below Low 16M.
+
+**/
+EFI_STATUS
+EFIAPI
+GenCompatibleRangeTest (
+ IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
+ IN EFI_PHYSICAL_ADDRESS StartAddress,
+ IN UINT64 Length
+ )
+{
+ EFI_STATUS Status;
+ GENERIC_MEMORY_TEST_PRIVATE *Private;
+ EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
+ EFI_PHYSICAL_ADDRESS CurrentBase;
+ UINT64 CurrentLength;
+
+ Private = GENERIC_MEMORY_TEST_PRIVATE_FROM_THIS (This);
+
+ //
+ // Check if the parameter is below 16MB
+ //
+ if (StartAddress + Length > 0x1000000) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ CurrentBase = StartAddress;
+ do {
+ //
+ // Check the required memory range status; if the required memory range span
+ // the different GCD memory descriptor, it may be cause different action.
+ //
+ Status = gDS->GetMemorySpaceDescriptor (
+ CurrentBase,
+ &Descriptor
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ if ((Descriptor.GcdMemoryType == EfiGcdMemoryTypeReserved) &&
+ ((Descriptor.Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==
+ (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED))
+ )
+ {
+ CurrentLength = Descriptor.BaseAddress + Descriptor.Length - CurrentBase;
+ if (CurrentBase + CurrentLength > StartAddress + Length) {
+ CurrentLength = StartAddress + Length - CurrentBase;
+ }
+
+ Status = DirectRangeTest (
+ Private,
+ CurrentBase,
+ CurrentLength,
+ Descriptor.Capabilities
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ }
+
+ CurrentBase = Descriptor.BaseAddress + Descriptor.Length;
+ } while (CurrentBase < StartAddress + Length);
+
+ //
+ // Here means the required range already be tested, so just return success.
+ //
+ return EFI_SUCCESS;
+}
+
+/**
+ Perform the address line walking ones test.
+
+ @param[in] Private Point to generic memory test driver's private data.
+
+ @retval EFI_SUCCESS Successful finished walking ones test.
+ @retval EFI_OUT_OF_RESOURCE Could not get resource in base memory.
+ @retval EFI_ACCESS_DENIED Code may can not run here because if walking one test
+ failed, system may be already halt.
+
+**/
+EFI_STATUS
+PerformAddressDataLineTest (
+ IN GENERIC_MEMORY_TEST_PRIVATE *Private
+ )
+{
+ LIST_ENTRY *ExtendedLink;
+ NONTESTED_MEMORY_RANGE *ExtendedRange;
+ BOOLEAN InExtendedRange;
+ EFI_PHYSICAL_ADDRESS TestAddress;
+
+ //
+ // Light version no data line test, only perform the address line test
+ //
+ TestAddress = (EFI_PHYSICAL_ADDRESS)0x1;
+ while (TestAddress < MAX_ADDRESS && TestAddress > 0) {
+ //
+ // only test if the address falls in the enabled range
+ //
+ InExtendedRange = FALSE;
+ ExtendedLink = Private->NonTestedMemRanList.BackLink;
+ while (ExtendedLink != &Private->NonTestedMemRanList) {
+ ExtendedRange = NONTESTED_MEMORY_RANGE_FROM_LINK (ExtendedLink);
+ if ((TestAddress >= ExtendedRange->StartAddress) &&
+ (TestAddress < (ExtendedRange->StartAddress + ExtendedRange->Length))
+ )
+ {
+ InExtendedRange = TRUE;
+ }
+
+ ExtendedLink = ExtendedLink->BackLink;
+ }
+
+ if (InExtendedRange) {
+ *(EFI_PHYSICAL_ADDRESS *)(UINTN)TestAddress = TestAddress;
+ Private->Cpu->FlushDataCache (Private->Cpu, TestAddress, 1, EfiCpuFlushTypeWriteBackInvalidate);
+ if (*(EFI_PHYSICAL_ADDRESS *)(UINTN)TestAddress != TestAddress) {
+ return EFI_ACCESS_DENIED;
+ }
+ }
+
+ TestAddress = LShiftU64 (TestAddress, 1);
+ }
+
+ return EFI_SUCCESS;
+}
+
+//
+// Driver entry here
+//
+GENERIC_MEMORY_TEST_PRIVATE mGenericMemoryTestPrivate = {
+ EFI_GENERIC_MEMORY_TEST_PRIVATE_SIGNATURE,
+ NULL,
+ NULL,
+ {
+ InitializeMemoryTest,
+ GenPerformMemoryTest,
+ GenMemoryTestFinished,
+ GenCompatibleRangeTest
+ },
+ (EXTENDMEM_COVERAGE_LEVEL)0,
+ 0,
+ 0,
+ NULL,
+ 0,
+ 0,
+ {
+ NULL,
+ NULL
+ }
+};
+
+/**
+ The generic memory test driver's entry point.
+
+ It initializes private data to default value.
+
+ @param[in] ImageHandle The firmware allocated handle for the EFI image.
+ @param[in] SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS The entry point is executed successfully.
+ @retval EFI_NOT_FOUND Can't find HandOff Hob in HobList.
+ @retval other Some error occurs when executing this entry point.
+
+**/
+EFI_STATUS
+EFIAPI
+GenericMemoryTestEntryPoint (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+ VOID *HobList;
+ EFI_BOOT_MODE BootMode;
+ EFI_PEI_HOB_POINTERS Hob;
+
+ //
+ // Use the generic pattern to test compatible memory range
+ //
+ mGenericMemoryTestPrivate.MonoPattern = GenericMemoryTestMonoPattern;
+ mGenericMemoryTestPrivate.MonoTestSize = GENERIC_CACHELINE_SIZE;
+
+ //
+ // Get the platform boot mode
+ //
+ HobList = GetHobList ();
+
+ Hob.Raw = HobList;
+ if (Hob.Header->HobType != EFI_HOB_TYPE_HANDOFF) {
+ return EFI_NOT_FOUND;
+ }
+
+ BootMode = Hob.HandoffInformationTable->BootMode;
+
+ //
+ // Get the platform boot mode and create the default memory test coverage
+ // level and span size for compatible memory test using
+ //
+ switch (BootMode) {
+ case BOOT_WITH_FULL_CONFIGURATION:
+ case BOOT_WITH_DEFAULT_SETTINGS:
+ mGenericMemoryTestPrivate.CoverageSpan = SPARSE_SPAN_SIZE;
+ break;
+
+ case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS:
+ mGenericMemoryTestPrivate.CoverageSpan = GENERIC_CACHELINE_SIZE;
+ break;
+
+ default:
+ mGenericMemoryTestPrivate.CoverageSpan = QUICK_SPAN_SIZE;
+ break;
+ }
+
+ //
+ // Install the protocol
+ //
+ Status = gBS->InstallProtocolInterface (
+ &mGenericMemoryTestPrivate.Handle,
+ &gEfiGenericMemTestProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ &mGenericMemoryTestPrivate.GenericMemoryTest
+ );
+
+ return Status;
+}
diff --git a/MdeModulePkg/Universal/MemoryTest/GenericMemoryTestDxe/LightMemoryTest.h b/MdeModulePkg/Universal/MemoryTest/GenericMemoryTestDxe/LightMemoryTest.h
index 9806881f49..f11e4fd442 100644
--- a/MdeModulePkg/Universal/MemoryTest/GenericMemoryTestDxe/LightMemoryTest.h
+++ b/MdeModulePkg/Universal/MemoryTest/GenericMemoryTestDxe/LightMemoryTest.h
@@ -1,333 +1,333 @@
-/** @file
- The generic memory test driver definition
-
- Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
-
- SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#ifndef _GENERIC_MEMORY_TEST_H_
-#define _GENERIC_MEMORY_TEST_H_
-
-#include <Guid/StatusCodeDataTypeId.h>
-#include <Protocol/GenericMemoryTest.h>
-#include <Protocol/Cpu.h>
-
-#include <Library/DebugLib.h>
-#include <Library/UefiDriverEntryPoint.h>
-#include <Library/HobLib.h>
-#include <Library/DxeServicesTableLib.h>
-#include <Library/ReportStatusCodeLib.h>
-#include <Library/BaseLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-
-//
-// Some global define
-//
-#define GENERIC_CACHELINE_SIZE 0x40
-
-//
-// attributes for reserved memory before it is promoted to system memory
-//
-#define EFI_MEMORY_PRESENT 0x0100000000000000ULL
-#define EFI_MEMORY_INITIALIZED 0x0200000000000000ULL
-#define EFI_MEMORY_TESTED 0x0400000000000000ULL
-
-//
-// The SPARSE_SPAN_SIZE size can not small then the MonoTestSize
-//
-#define TEST_BLOCK_SIZE 0x2000000
-#define QUICK_SPAN_SIZE (TEST_BLOCK_SIZE >> 2)
-#define SPARSE_SPAN_SIZE (TEST_BLOCK_SIZE >> 4)
-
-//
-// This structure records every nontested memory range parsed through GCD
-// service.
-//
-#define EFI_NONTESTED_MEMORY_RANGE_SIGNATURE SIGNATURE_32 ('N', 'T', 'M', 'E')
-
-typedef struct {
- UINTN Signature;
- LIST_ENTRY Link;
- EFI_PHYSICAL_ADDRESS StartAddress;
- UINT64 Length;
- UINT64 Capabilities;
- BOOLEAN Above4G;
- BOOLEAN AlreadyMapped;
-} NONTESTED_MEMORY_RANGE;
-
-#define NONTESTED_MEMORY_RANGE_FROM_LINK(link) \
- CR ( \
- link, \
- NONTESTED_MEMORY_RANGE, \
- Link, \
- EFI_NONTESTED_MEMORY_RANGE_SIGNATURE \
- )
-
-//
-// This is the memory test driver's structure definition
-//
-#define EFI_GENERIC_MEMORY_TEST_PRIVATE_SIGNATURE SIGNATURE_32 ('G', 'E', 'M', 'T')
-
-typedef struct {
- UINTN Signature;
- EFI_HANDLE Handle;
-
- //
- // Cpu arch protocol's pointer
- //
- EFI_CPU_ARCH_PROTOCOL *Cpu;
-
- //
- // generic memory test driver's protocol
- //
- EFI_GENERIC_MEMORY_TEST_PROTOCOL GenericMemoryTest;
-
- //
- // memory test covered spans
- //
- EXTENDMEM_COVERAGE_LEVEL CoverLevel;
- UINTN CoverageSpan;
- UINT64 BdsBlockSize;
-
- //
- // the memory test pattern and size every time R/W/V memory
- //
- VOID *MonoPattern;
- UINTN MonoTestSize;
-
- //
- // base memory's size which tested in PEI phase
- //
- UINT64 BaseMemorySize;
-
- //
- // memory range list
- //
- LIST_ENTRY NonTestedMemRanList;
-} GENERIC_MEMORY_TEST_PRIVATE;
-
-#define GENERIC_MEMORY_TEST_PRIVATE_FROM_THIS(a) \
- CR ( \
- a, \
- GENERIC_MEMORY_TEST_PRIVATE, \
- GenericMemoryTest, \
- EFI_GENERIC_MEMORY_TEST_PRIVATE_SIGNATURE \
- )
-
-//
-// Function Prototypes
-//
-
-/**
- Construct the system base memory range through GCD service.
-
- @param[in] Private Point to generic memory test driver's private data.
-
- @retval EFI_SUCCESS Successful construct the base memory range through GCD service.
- @retval EFI_OUT_OF_RESOURCE Could not allocate needed resource from base memory.
- @retval Others Failed to construct base memory range through GCD service.
-
-**/
-EFI_STATUS
-ConstructBaseMemoryRange (
- IN GENERIC_MEMORY_TEST_PRIVATE *Private
- );
-
-/**
- Construct the system non-tested memory range through GCD service.
-
- @param[in] Private Point to generic memory test driver's private data.
-
- @retval EFI_SUCCESS Successful construct the non-tested memory range through GCD service.
- @retval EFI_OUT_OF_RESOURCE Could not allocate needed resource from base memory.
- @retval Others Failed to construct non-tested memory range through GCD service.
-
-**/
-EFI_STATUS
-ConstructNonTestedMemoryRange (
- IN GENERIC_MEMORY_TEST_PRIVATE *Private
- );
-
-/**
- Perform the address line walking ones test.
-
- @param[in] Private Point to generic memory test driver's private data.
-
- @retval EFI_SUCCESS Successful finished walking ones test.
- @retval EFI_OUT_OF_RESOURCE Could not get resource in base memory.
- @retval EFI_ACCESS_DENIED Code may can not run here because if walking one test
- failed, system may be already halt.
-
-**/
-EFI_STATUS
-PerformAddressDataLineTest (
- IN GENERIC_MEMORY_TEST_PRIVATE *Private
- );
-
-/**
- Destroy the link list base on the correspond link list type.
-
- @param[in] Private Point to generic memory test driver's private data.
-
-**/
-VOID
-DestroyLinkList (
- IN GENERIC_MEMORY_TEST_PRIVATE *Private
- );
-
-/**
- Add the extened memory to whole system memory map.
-
- @param[in] Private Point to generic memory test driver's private data.
-
- @retval EFI_SUCCESS Successful add all the extended memory to system memory map.
- @retval Others Failed to add the tested extended memory.
-
-**/
-EFI_STATUS
-UpdateMemoryMap (
- IN GENERIC_MEMORY_TEST_PRIVATE *Private
- );
-
-/**
- Write the memory test pattern into a range of physical memory.
-
- @param[in] Private Point to generic memory test driver's private data.
- @param[in] Start The memory range's start address.
- @param[in] Size The memory range's size.
-
- @retval EFI_SUCCESS Successful write the test pattern into the non-tested memory.
- @retval Others The test pattern may not really write into the physical memory.
-
-**/
-EFI_STATUS
-WriteMemory (
- IN GENERIC_MEMORY_TEST_PRIVATE *Private,
- IN EFI_PHYSICAL_ADDRESS Start,
- IN UINT64 Size
- );
-
-/**
- Verify the range of physical memory which covered by memory test pattern.
-
- This function will also do not return any informatin just cause system reset,
- because the handle error encount fatal error and disable the bad DIMMs.
-
- @param[in] Private Point to generic memory test driver's private data.
- @param[in] Start The memory range's start address.
- @param[in] Size The memory range's size.
-
- @retval EFI_SUCCESS Successful verify the range of memory, no errors' location found.
- @retval Others The range of memory have errors contained.
-
-**/
-EFI_STATUS
-VerifyMemory (
- IN GENERIC_MEMORY_TEST_PRIVATE *Private,
- IN EFI_PHYSICAL_ADDRESS Start,
- IN UINT64 Size
- );
-
-/**
- Test a range of the memory directly .
-
- @param[in] Private Point to generic memory test driver's private data.
- @param[in] StartAddress Starting address of the memory range to be tested.
- @param[in] Length Length in bytes of the memory range to be tested.
- @param[in] Capabilities The bit mask of attributes that the memory range supports.
-
- @retval EFI_SUCCESS Successful test the range of memory.
- @retval Others Failed to test the range of memory.
-
-**/
-EFI_STATUS
-DirectRangeTest (
- IN GENERIC_MEMORY_TEST_PRIVATE *Private,
- IN EFI_PHYSICAL_ADDRESS StartAddress,
- IN UINT64 Length,
- IN UINT64 Capabilities
- );
-
-/**
- Initialize the generic memory test.
-
- @param[in] This The protocol instance pointer.
- @param[in] Level The coverage level of the memory test.
- @param[out] RequireSoftECCInit Indicate if the memory need software ECC init.
-
- @retval EFI_SUCCESS The generic memory test is initialized correctly.
- @retval EFI_NO_MEDIA The system had no memory to be tested.
-
-**/
-EFI_STATUS
-EFIAPI
-InitializeMemoryTest (
- IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
- IN EXTENDMEM_COVERAGE_LEVEL Level,
- OUT BOOLEAN *RequireSoftECCInit
- );
-
-/**
- Perform the memory test.
-
- @param[in] This The protocol instance pointer.
- @param[out] TestedMemorySize Return the tested extended memory size.
- @param[out] TotalMemorySize Return the whole system physical memory size.
- The total memory size does not include memory in a slot with a disabled DIMM.
- @param[out] ErrorOut TRUE if the memory error occurred.
- @param[in] IfTestAbort Indicates that the user pressed "ESC" to skip the memory test.
-
- @retval EFI_SUCCESS One block of memory passed the test.
- @retval EFI_NOT_FOUND All memory blocks have already been tested.
- @retval EFI_DEVICE_ERROR Memory device error occurred, and no agent can handle it.
-
-**/
-EFI_STATUS
-EFIAPI
-GenPerformMemoryTest (
- IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
- OUT UINT64 *TestedMemorySize,
- OUT UINT64 *TotalMemorySize,
- OUT BOOLEAN *ErrorOut,
- IN BOOLEAN TestAbort
- );
-
-/**
- Finish the memory test.
-
- @param[in] This The protocol instance pointer.
-
- @retval EFI_SUCCESS Success. All resources used in the memory test are freed.
-
-**/
-EFI_STATUS
-EFIAPI
-GenMemoryTestFinished (
- IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This
- );
-
-/**
- Provides the capability to test the compatible range used by some special drivers.
-
- @param[in] This The protocol instance pointer.
- @param[in] StartAddress The start address of the compatible memory range that
- must be below 16M.
- @param[in] Length The compatible memory range's length.
-
- @retval EFI_SUCCESS The compatible memory range pass the memory test.
- @retval EFI_INVALID_PARAMETER The compatible memory range are not below Low 16M.
-
-**/
-EFI_STATUS
-EFIAPI
-GenCompatibleRangeTest (
- IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
- IN EFI_PHYSICAL_ADDRESS StartAddress,
- IN UINT64 Length
- );
-
-#endif
+/** @file
+ The generic memory test driver definition
+
+ Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef _GENERIC_MEMORY_TEST_H_
+#define _GENERIC_MEMORY_TEST_H_
+
+#include <Guid/StatusCodeDataTypeId.h>
+#include <Protocol/GenericMemoryTest.h>
+#include <Protocol/Cpu.h>
+
+#include <Library/DebugLib.h>
+#include <Library/UefiDriverEntryPoint.h>
+#include <Library/HobLib.h>
+#include <Library/DxeServicesTableLib.h>
+#include <Library/ReportStatusCodeLib.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+
+//
+// Some global define
+//
+#define GENERIC_CACHELINE_SIZE 0x40
+
+//
+// attributes for reserved memory before it is promoted to system memory
+//
+#define EFI_MEMORY_PRESENT 0x0100000000000000ULL
+#define EFI_MEMORY_INITIALIZED 0x0200000000000000ULL
+#define EFI_MEMORY_TESTED 0x0400000000000000ULL
+
+//
+// The SPARSE_SPAN_SIZE size can not small then the MonoTestSize
+//
+#define TEST_BLOCK_SIZE 0x2000000
+#define QUICK_SPAN_SIZE (TEST_BLOCK_SIZE >> 2)
+#define SPARSE_SPAN_SIZE (TEST_BLOCK_SIZE >> 4)
+
+//
+// This structure records every nontested memory range parsed through GCD
+// service.
+//
+#define EFI_NONTESTED_MEMORY_RANGE_SIGNATURE SIGNATURE_32 ('N', 'T', 'M', 'E')
+
+typedef struct {
+ UINTN Signature;
+ LIST_ENTRY Link;
+ EFI_PHYSICAL_ADDRESS StartAddress;
+ UINT64 Length;
+ UINT64 Capabilities;
+ BOOLEAN Above4G;
+ BOOLEAN AlreadyMapped;
+} NONTESTED_MEMORY_RANGE;
+
+#define NONTESTED_MEMORY_RANGE_FROM_LINK(link) \
+ CR ( \
+ link, \
+ NONTESTED_MEMORY_RANGE, \
+ Link, \
+ EFI_NONTESTED_MEMORY_RANGE_SIGNATURE \
+ )
+
+//
+// This is the memory test driver's structure definition
+//
+#define EFI_GENERIC_MEMORY_TEST_PRIVATE_SIGNATURE SIGNATURE_32 ('G', 'E', 'M', 'T')
+
+typedef struct {
+ UINTN Signature;
+ EFI_HANDLE Handle;
+
+ //
+ // Cpu arch protocol's pointer
+ //
+ EFI_CPU_ARCH_PROTOCOL *Cpu;
+
+ //
+ // generic memory test driver's protocol
+ //
+ EFI_GENERIC_MEMORY_TEST_PROTOCOL GenericMemoryTest;
+
+ //
+ // memory test covered spans
+ //
+ EXTENDMEM_COVERAGE_LEVEL CoverLevel;
+ UINTN CoverageSpan;
+ UINT64 BdsBlockSize;
+
+ //
+ // the memory test pattern and size every time R/W/V memory
+ //
+ VOID *MonoPattern;
+ UINTN MonoTestSize;
+
+ //
+ // base memory's size which tested in PEI phase
+ //
+ UINT64 BaseMemorySize;
+
+ //
+ // memory range list
+ //
+ LIST_ENTRY NonTestedMemRanList;
+} GENERIC_MEMORY_TEST_PRIVATE;
+
+#define GENERIC_MEMORY_TEST_PRIVATE_FROM_THIS(a) \
+ CR ( \
+ a, \
+ GENERIC_MEMORY_TEST_PRIVATE, \
+ GenericMemoryTest, \
+ EFI_GENERIC_MEMORY_TEST_PRIVATE_SIGNATURE \
+ )
+
+//
+// Function Prototypes
+//
+
+/**
+ Construct the system base memory range through GCD service.
+
+ @param[in] Private Point to generic memory test driver's private data.
+
+ @retval EFI_SUCCESS Successful construct the base memory range through GCD service.
+ @retval EFI_OUT_OF_RESOURCE Could not allocate needed resource from base memory.
+ @retval Others Failed to construct base memory range through GCD service.
+
+**/
+EFI_STATUS
+ConstructBaseMemoryRange (
+ IN GENERIC_MEMORY_TEST_PRIVATE *Private
+ );
+
+/**
+ Construct the system non-tested memory range through GCD service.
+
+ @param[in] Private Point to generic memory test driver's private data.
+
+ @retval EFI_SUCCESS Successful construct the non-tested memory range through GCD service.
+ @retval EFI_OUT_OF_RESOURCE Could not allocate needed resource from base memory.
+ @retval Others Failed to construct non-tested memory range through GCD service.
+
+**/
+EFI_STATUS
+ConstructNonTestedMemoryRange (
+ IN GENERIC_MEMORY_TEST_PRIVATE *Private
+ );
+
+/**
+ Perform the address line walking ones test.
+
+ @param[in] Private Point to generic memory test driver's private data.
+
+ @retval EFI_SUCCESS Successful finished walking ones test.
+ @retval EFI_OUT_OF_RESOURCE Could not get resource in base memory.
+ @retval EFI_ACCESS_DENIED Code may can not run here because if walking one test
+ failed, system may be already halt.
+
+**/
+EFI_STATUS
+PerformAddressDataLineTest (
+ IN GENERIC_MEMORY_TEST_PRIVATE *Private
+ );
+
+/**
+ Destroy the link list base on the correspond link list type.
+
+ @param[in] Private Point to generic memory test driver's private data.
+
+**/
+VOID
+DestroyLinkList (
+ IN GENERIC_MEMORY_TEST_PRIVATE *Private
+ );
+
+/**
+ Add the extened memory to whole system memory map.
+
+ @param[in] Private Point to generic memory test driver's private data.
+
+ @retval EFI_SUCCESS Successful add all the extended memory to system memory map.
+ @retval Others Failed to add the tested extended memory.
+
+**/
+EFI_STATUS
+UpdateMemoryMap (
+ IN GENERIC_MEMORY_TEST_PRIVATE *Private
+ );
+
+/**
+ Write the memory test pattern into a range of physical memory.
+
+ @param[in] Private Point to generic memory test driver's private data.
+ @param[in] Start The memory range's start address.
+ @param[in] Size The memory range's size.
+
+ @retval EFI_SUCCESS Successful write the test pattern into the non-tested memory.
+ @retval Others The test pattern may not really write into the physical memory.
+
+**/
+EFI_STATUS
+WriteMemory (
+ IN GENERIC_MEMORY_TEST_PRIVATE *Private,
+ IN EFI_PHYSICAL_ADDRESS Start,
+ IN UINT64 Size
+ );
+
+/**
+ Verify the range of physical memory which covered by memory test pattern.
+
+ This function will also do not return any informatin just cause system reset,
+ because the handle error encount fatal error and disable the bad DIMMs.
+
+ @param[in] Private Point to generic memory test driver's private data.
+ @param[in] Start The memory range's start address.
+ @param[in] Size The memory range's size.
+
+ @retval EFI_SUCCESS Successful verify the range of memory, no errors' location found.
+ @retval Others The range of memory have errors contained.
+
+**/
+EFI_STATUS
+VerifyMemory (
+ IN GENERIC_MEMORY_TEST_PRIVATE *Private,
+ IN EFI_PHYSICAL_ADDRESS Start,
+ IN UINT64 Size
+ );
+
+/**
+ Test a range of the memory directly .
+
+ @param[in] Private Point to generic memory test driver's private data.
+ @param[in] StartAddress Starting address of the memory range to be tested.
+ @param[in] Length Length in bytes of the memory range to be tested.
+ @param[in] Capabilities The bit mask of attributes that the memory range supports.
+
+ @retval EFI_SUCCESS Successful test the range of memory.
+ @retval Others Failed to test the range of memory.
+
+**/
+EFI_STATUS
+DirectRangeTest (
+ IN GENERIC_MEMORY_TEST_PRIVATE *Private,
+ IN EFI_PHYSICAL_ADDRESS StartAddress,
+ IN UINT64 Length,
+ IN UINT64 Capabilities
+ );
+
+/**
+ Initialize the generic memory test.
+
+ @param[in] This The protocol instance pointer.
+ @param[in] Level The coverage level of the memory test.
+ @param[out] RequireSoftECCInit Indicate if the memory need software ECC init.
+
+ @retval EFI_SUCCESS The generic memory test is initialized correctly.
+ @retval EFI_NO_MEDIA The system had no memory to be tested.
+
+**/
+EFI_STATUS
+EFIAPI
+InitializeMemoryTest (
+ IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
+ IN EXTENDMEM_COVERAGE_LEVEL Level,
+ OUT BOOLEAN *RequireSoftECCInit
+ );
+
+/**
+ Perform the memory test.
+
+ @param[in] This The protocol instance pointer.
+ @param[out] TestedMemorySize Return the tested extended memory size.
+ @param[out] TotalMemorySize Return the whole system physical memory size.
+ The total memory size does not include memory in a slot with a disabled DIMM.
+ @param[out] ErrorOut TRUE if the memory error occurred.
+ @param[in] IfTestAbort Indicates that the user pressed "ESC" to skip the memory test.
+
+ @retval EFI_SUCCESS One block of memory passed the test.
+ @retval EFI_NOT_FOUND All memory blocks have already been tested.
+ @retval EFI_DEVICE_ERROR Memory device error occurred, and no agent can handle it.
+
+**/
+EFI_STATUS
+EFIAPI
+GenPerformMemoryTest (
+ IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
+ OUT UINT64 *TestedMemorySize,
+ OUT UINT64 *TotalMemorySize,
+ OUT BOOLEAN *ErrorOut,
+ IN BOOLEAN TestAbort
+ );
+
+/**
+ Finish the memory test.
+
+ @param[in] This The protocol instance pointer.
+
+ @retval EFI_SUCCESS Success. All resources used in the memory test are freed.
+
+**/
+EFI_STATUS
+EFIAPI
+GenMemoryTestFinished (
+ IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This
+ );
+
+/**
+ Provides the capability to test the compatible range used by some special drivers.
+
+ @param[in] This The protocol instance pointer.
+ @param[in] StartAddress The start address of the compatible memory range that
+ must be below 16M.
+ @param[in] Length The compatible memory range's length.
+
+ @retval EFI_SUCCESS The compatible memory range pass the memory test.
+ @retval EFI_INVALID_PARAMETER The compatible memory range are not below Low 16M.
+
+**/
+EFI_STATUS
+EFIAPI
+GenCompatibleRangeTest (
+ IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
+ IN EFI_PHYSICAL_ADDRESS StartAddress,
+ IN UINT64 Length
+ );
+
+#endif
diff --git a/MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTest.c b/MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTest.c
index 846f9b8084..6cbcf548a4 100644
--- a/MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTest.c
+++ b/MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTest.c
@@ -1,290 +1,290 @@
-/** @file
- Implementation of Generic Memory Test Protocol which does not perform real memory test.
-
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
-SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include "NullMemoryTest.h"
-
-UINT64 mTestedSystemMemory = 0;
-UINT64 mTotalSystemMemory = 0;
-EFI_HANDLE mGenericMemoryTestHandle;
-
-EFI_GENERIC_MEMORY_TEST_PROTOCOL mGenericMemoryTest = {
- InitializeMemoryTest,
- GenPerformMemoryTest,
- GenMemoryTestFinished,
- GenCompatibleRangeTest
-};
-
-/**
- Entry point of the NULL memory test driver.
-
- This function is the entry point of the NULL memory test driver.
- It simply installs the Generic Memory Test Protocol.
-
- @param ImageHandle The firmware allocated handle for the EFI image.
- @param SystemTable A pointer to the EFI System Table.
-
- @retval EFI_SUCCESS Generic Memory Test Protocol is successfully installed.
-
-**/
-EFI_STATUS
-EFIAPI
-GenericMemoryTestEntryPoint (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
-{
- EFI_STATUS Status;
-
- Status = gBS->InstallProtocolInterface (
- &mGenericMemoryTestHandle,
- &gEfiGenericMemTestProtocolGuid,
- EFI_NATIVE_INTERFACE,
- &mGenericMemoryTest
- );
- ASSERT_EFI_ERROR (Status);
-
- return EFI_SUCCESS;
-}
-
-/**
- Convert the memory range to tested.
-
- @param BaseAddress Base address of the memory range.
- @param Length Length of the memory range.
- @param Capabilities Capabilities of the memory range.
-
- @retval EFI_SUCCESS The memory range is converted to tested.
- @retval others Error happens.
-**/
-EFI_STATUS
-ConvertToTestedMemory (
- IN UINT64 BaseAddress,
- IN UINT64 Length,
- IN UINT64 Capabilities
- )
-{
- EFI_STATUS Status;
-
- Status = gDS->RemoveMemorySpace (
- BaseAddress,
- Length
- );
- if (!EFI_ERROR (Status)) {
- Status = gDS->AddMemorySpace (
- ((Capabilities & EFI_MEMORY_MORE_RELIABLE) == EFI_MEMORY_MORE_RELIABLE) ?
- EfiGcdMemoryTypeMoreReliable : EfiGcdMemoryTypeSystemMemory,
- BaseAddress,
- Length,
- Capabilities &~
- (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)
- );
- }
-
- return Status;
-}
-
-/**
- Initialize the generic memory test.
-
- This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.MemoryTestInit.
- It simply promotes untested reserved memory to system memory without real test.
-
- @param This Protocol instance pointer.
- @param Level The coverage level of the memory test.
- @param RequireSoftECCInit Indicate if the memory need software ECC init.
-
- @retval EFI_SUCCESS The generic memory test initialized correctly.
- @retval EFI_NO_MEDIA There is not any non-tested memory found, in this
- function if not any non-tesed memory found means
- that the memory test driver have not detect any
- non-tested extended memory of current system.
-
-**/
-EFI_STATUS
-EFIAPI
-InitializeMemoryTest (
- IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
- IN EXTENDMEM_COVERAGE_LEVEL Level,
- OUT BOOLEAN *RequireSoftECCInit
- )
-{
- EFI_STATUS Status;
- UINTN NumberOfDescriptors;
- EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;
- UINTN Index;
-
- gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);
- for (Index = 0; Index < NumberOfDescriptors; Index++) {
- if ((MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeReserved) &&
- ((MemorySpaceMap[Index].Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==
- (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED))
- )
- {
- //
- // For those reserved memory that have not been tested, simply promote to system memory.
- //
- Status = ConvertToTestedMemory (
- MemorySpaceMap[Index].BaseAddress,
- MemorySpaceMap[Index].Length,
- MemorySpaceMap[Index].Capabilities
- );
- ASSERT_EFI_ERROR (Status);
- mTestedSystemMemory += MemorySpaceMap[Index].Length;
- mTotalSystemMemory += MemorySpaceMap[Index].Length;
- } else if ((MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeSystemMemory) ||
- (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeMoreReliable))
- {
- mTotalSystemMemory += MemorySpaceMap[Index].Length;
- }
- }
-
- FreePool (MemorySpaceMap);
-
- *RequireSoftECCInit = FALSE;
- return EFI_SUCCESS;
-}
-
-/**
- Perform the memory test.
-
- This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.PerformMemoryTest.
- It simply returns EFI_NOT_FOUND.
-
- @param This Protocol instance pointer.
- @param TestedMemorySize Return the tested extended memory size.
- @param TotalMemorySize Return the whole system physical memory size, this
- value may be changed if in some case some error
- DIMMs be disabled.
- @param ErrorOut Any time the memory error occurs, this will be
- TRUE.
- @param IfTestAbort Indicate if the user press "ESC" to skip the memory
- test.
-
- @retval EFI_SUCCESS One block of memory test ok, the block size is hide
- internally.
- @retval EFI_NOT_FOUND Indicate all the non-tested memory blocks have
- already go through.
- @retval EFI_DEVICE_ERROR Mis-compare error, and no agent can handle it
-
-**/
-EFI_STATUS
-EFIAPI
-GenPerformMemoryTest (
- IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
- IN OUT UINT64 *TestedMemorySize,
- OUT UINT64 *TotalMemorySize,
- OUT BOOLEAN *ErrorOut,
- IN BOOLEAN TestAbort
- )
-{
- *ErrorOut = FALSE;
- *TestedMemorySize = mTestedSystemMemory;
- *TotalMemorySize = mTotalSystemMemory;
-
- return EFI_NOT_FOUND;
-}
-
-/**
- The memory test finished.
-
- This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.Finished.
- It simply returns EFI_SUCCESS.
-
- @param This Protocol instance pointer.
-
- @retval EFI_SUCCESS Successful free all the generic memory test driver
- allocated resource and notify to platform memory
- test driver that memory test finished.
-
-**/
-EFI_STATUS
-EFIAPI
-GenMemoryTestFinished (
- IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This
- )
-{
- return EFI_SUCCESS;
-}
-
-/**
- Provide capability to test compatible range which used by some special
- driver required using memory range before BDS perform memory test.
-
- This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.CompatibleRangeTest.
- It simply sets the memory range to system memory.
-
- @param This Protocol instance pointer.
- @param StartAddress The start address of the memory range.
- @param Length The memory range's length.
-
- @retval EFI_SUCCESS The compatible memory range pass the memory test.
- @retval EFI_INVALID_PARAMETER The compatible memory range must be below 16M.
-
-**/
-EFI_STATUS
-EFIAPI
-GenCompatibleRangeTest (
- IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
- IN EFI_PHYSICAL_ADDRESS StartAddress,
- IN UINT64 Length
- )
-{
- EFI_STATUS Status;
- EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
- EFI_PHYSICAL_ADDRESS CurrentBase;
- UINT64 CurrentLength;
-
- //
- // Check if the parameter is below 16MB
- //
- if (StartAddress + Length > SIZE_16MB) {
- return EFI_INVALID_PARAMETER;
- }
-
- CurrentBase = StartAddress;
- do {
- //
- // Check the required memory range status; if the required memory range span
- // the different GCD memory descriptor, it may be cause different action.
- //
- Status = gDS->GetMemorySpaceDescriptor (
- CurrentBase,
- &Descriptor
- );
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- if ((Descriptor.GcdMemoryType == EfiGcdMemoryTypeReserved) &&
- ((Descriptor.Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==
- (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED))
- )
- {
- CurrentLength = Descriptor.BaseAddress + Descriptor.Length - CurrentBase;
- if (CurrentBase + CurrentLength > StartAddress + Length) {
- CurrentLength = StartAddress + Length - CurrentBase;
- }
-
- Status = ConvertToTestedMemory (
- CurrentBase,
- CurrentLength,
- Descriptor.Capabilities
- );
- if (EFI_ERROR (Status)) {
- return Status;
- }
- }
-
- CurrentBase = Descriptor.BaseAddress + Descriptor.Length;
- } while (CurrentBase < StartAddress + Length);
-
- //
- // Here means the required range already be tested, so just return success.
- //
- return EFI_SUCCESS;
-}
+/** @file
+ Implementation of Generic Memory Test Protocol which does not perform real memory test.
+
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "NullMemoryTest.h"
+
+UINT64 mTestedSystemMemory = 0;
+UINT64 mTotalSystemMemory = 0;
+EFI_HANDLE mGenericMemoryTestHandle;
+
+EFI_GENERIC_MEMORY_TEST_PROTOCOL mGenericMemoryTest = {
+ InitializeMemoryTest,
+ GenPerformMemoryTest,
+ GenMemoryTestFinished,
+ GenCompatibleRangeTest
+};
+
+/**
+ Entry point of the NULL memory test driver.
+
+ This function is the entry point of the NULL memory test driver.
+ It simply installs the Generic Memory Test Protocol.
+
+ @param ImageHandle The firmware allocated handle for the EFI image.
+ @param SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS Generic Memory Test Protocol is successfully installed.
+
+**/
+EFI_STATUS
+EFIAPI
+GenericMemoryTestEntryPoint (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+
+ Status = gBS->InstallProtocolInterface (
+ &mGenericMemoryTestHandle,
+ &gEfiGenericMemTestProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ &mGenericMemoryTest
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Convert the memory range to tested.
+
+ @param BaseAddress Base address of the memory range.
+ @param Length Length of the memory range.
+ @param Capabilities Capabilities of the memory range.
+
+ @retval EFI_SUCCESS The memory range is converted to tested.
+ @retval others Error happens.
+**/
+EFI_STATUS
+ConvertToTestedMemory (
+ IN UINT64 BaseAddress,
+ IN UINT64 Length,
+ IN UINT64 Capabilities
+ )
+{
+ EFI_STATUS Status;
+
+ Status = gDS->RemoveMemorySpace (
+ BaseAddress,
+ Length
+ );
+ if (!EFI_ERROR (Status)) {
+ Status = gDS->AddMemorySpace (
+ ((Capabilities & EFI_MEMORY_MORE_RELIABLE) == EFI_MEMORY_MORE_RELIABLE) ?
+ EfiGcdMemoryTypeMoreReliable : EfiGcdMemoryTypeSystemMemory,
+ BaseAddress,
+ Length,
+ Capabilities &~
+ (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)
+ );
+ }
+
+ return Status;
+}
+
+/**
+ Initialize the generic memory test.
+
+ This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.MemoryTestInit.
+ It simply promotes untested reserved memory to system memory without real test.
+
+ @param This Protocol instance pointer.
+ @param Level The coverage level of the memory test.
+ @param RequireSoftECCInit Indicate if the memory need software ECC init.
+
+ @retval EFI_SUCCESS The generic memory test initialized correctly.
+ @retval EFI_NO_MEDIA There is not any non-tested memory found, in this
+ function if not any non-tesed memory found means
+ that the memory test driver have not detect any
+ non-tested extended memory of current system.
+
+**/
+EFI_STATUS
+EFIAPI
+InitializeMemoryTest (
+ IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
+ IN EXTENDMEM_COVERAGE_LEVEL Level,
+ OUT BOOLEAN *RequireSoftECCInit
+ )
+{
+ EFI_STATUS Status;
+ UINTN NumberOfDescriptors;
+ EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;
+ UINTN Index;
+
+ gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);
+ for (Index = 0; Index < NumberOfDescriptors; Index++) {
+ if ((MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeReserved) &&
+ ((MemorySpaceMap[Index].Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==
+ (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED))
+ )
+ {
+ //
+ // For those reserved memory that have not been tested, simply promote to system memory.
+ //
+ Status = ConvertToTestedMemory (
+ MemorySpaceMap[Index].BaseAddress,
+ MemorySpaceMap[Index].Length,
+ MemorySpaceMap[Index].Capabilities
+ );
+ ASSERT_EFI_ERROR (Status);
+ mTestedSystemMemory += MemorySpaceMap[Index].Length;
+ mTotalSystemMemory += MemorySpaceMap[Index].Length;
+ } else if ((MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeSystemMemory) ||
+ (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeMoreReliable))
+ {
+ mTotalSystemMemory += MemorySpaceMap[Index].Length;
+ }
+ }
+
+ FreePool (MemorySpaceMap);
+
+ *RequireSoftECCInit = FALSE;
+ return EFI_SUCCESS;
+}
+
+/**
+ Perform the memory test.
+
+ This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.PerformMemoryTest.
+ It simply returns EFI_NOT_FOUND.
+
+ @param This Protocol instance pointer.
+ @param TestedMemorySize Return the tested extended memory size.
+ @param TotalMemorySize Return the whole system physical memory size, this
+ value may be changed if in some case some error
+ DIMMs be disabled.
+ @param ErrorOut Any time the memory error occurs, this will be
+ TRUE.
+ @param IfTestAbort Indicate if the user press "ESC" to skip the memory
+ test.
+
+ @retval EFI_SUCCESS One block of memory test ok, the block size is hide
+ internally.
+ @retval EFI_NOT_FOUND Indicate all the non-tested memory blocks have
+ already go through.
+ @retval EFI_DEVICE_ERROR Mis-compare error, and no agent can handle it
+
+**/
+EFI_STATUS
+EFIAPI
+GenPerformMemoryTest (
+ IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
+ IN OUT UINT64 *TestedMemorySize,
+ OUT UINT64 *TotalMemorySize,
+ OUT BOOLEAN *ErrorOut,
+ IN BOOLEAN TestAbort
+ )
+{
+ *ErrorOut = FALSE;
+ *TestedMemorySize = mTestedSystemMemory;
+ *TotalMemorySize = mTotalSystemMemory;
+
+ return EFI_NOT_FOUND;
+}
+
+/**
+ The memory test finished.
+
+ This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.Finished.
+ It simply returns EFI_SUCCESS.
+
+ @param This Protocol instance pointer.
+
+ @retval EFI_SUCCESS Successful free all the generic memory test driver
+ allocated resource and notify to platform memory
+ test driver that memory test finished.
+
+**/
+EFI_STATUS
+EFIAPI
+GenMemoryTestFinished (
+ IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This
+ )
+{
+ return EFI_SUCCESS;
+}
+
+/**
+ Provide capability to test compatible range which used by some special
+ driver required using memory range before BDS perform memory test.
+
+ This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.CompatibleRangeTest.
+ It simply sets the memory range to system memory.
+
+ @param This Protocol instance pointer.
+ @param StartAddress The start address of the memory range.
+ @param Length The memory range's length.
+
+ @retval EFI_SUCCESS The compatible memory range pass the memory test.
+ @retval EFI_INVALID_PARAMETER The compatible memory range must be below 16M.
+
+**/
+EFI_STATUS
+EFIAPI
+GenCompatibleRangeTest (
+ IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
+ IN EFI_PHYSICAL_ADDRESS StartAddress,
+ IN UINT64 Length
+ )
+{
+ EFI_STATUS Status;
+ EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
+ EFI_PHYSICAL_ADDRESS CurrentBase;
+ UINT64 CurrentLength;
+
+ //
+ // Check if the parameter is below 16MB
+ //
+ if (StartAddress + Length > SIZE_16MB) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ CurrentBase = StartAddress;
+ do {
+ //
+ // Check the required memory range status; if the required memory range span
+ // the different GCD memory descriptor, it may be cause different action.
+ //
+ Status = gDS->GetMemorySpaceDescriptor (
+ CurrentBase,
+ &Descriptor
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ if ((Descriptor.GcdMemoryType == EfiGcdMemoryTypeReserved) &&
+ ((Descriptor.Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==
+ (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED))
+ )
+ {
+ CurrentLength = Descriptor.BaseAddress + Descriptor.Length - CurrentBase;
+ if (CurrentBase + CurrentLength > StartAddress + Length) {
+ CurrentLength = StartAddress + Length - CurrentBase;
+ }
+
+ Status = ConvertToTestedMemory (
+ CurrentBase,
+ CurrentLength,
+ Descriptor.Capabilities
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ }
+
+ CurrentBase = Descriptor.BaseAddress + Descriptor.Length;
+ } while (CurrentBase < StartAddress + Length);
+
+ //
+ // Here means the required range already be tested, so just return success.
+ //
+ return EFI_SUCCESS;
+}
diff --git a/MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTest.h b/MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTest.h
index 5200600a43..d3f70c9d36 100644
--- a/MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTest.h
+++ b/MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTest.h
@@ -1,129 +1,129 @@
-/** @file
- Include file of the NULL memory test driver.
-
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
-SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#ifndef _NULL_MEMORY_TEST_H_
-#define _NULL_MEMORY_TEST_H_
-
-#include <PiDxe.h>
-
-#include <Protocol/GenericMemoryTest.h>
-
-#include <Library/DebugLib.h>
-#include <Library/UefiDriverEntryPoint.h>
-#include <Library/DxeServicesTableLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/MemoryAllocationLib.h>
-
-//
-// Definition of memory status.
-//
-#define EFI_MEMORY_PRESENT 0x0100000000000000ULL
-#define EFI_MEMORY_INITIALIZED 0x0200000000000000ULL
-#define EFI_MEMORY_TESTED 0x0400000000000000ULL
-
-/**
- Initialize the generic memory test.
-
- This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.MemoryTestInit.
- It simply promotes untested reserved memory to system memory without real test.
-
- @param This Protocol instance pointer.
- @param Level The coverage level of the memory test.
- @param RequireSoftECCInit Indicate if the memory need software ECC init.
-
- @retval EFI_SUCCESS The generic memory test initialized correctly.
- @retval EFI_NO_MEDIA There is not any non-tested memory found, in this
- function if not any non-tesed memory found means
- that the memory test driver have not detect any
- non-tested extended memory of current system.
-
-**/
-EFI_STATUS
-EFIAPI
-InitializeMemoryTest (
- IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
- IN EXTENDMEM_COVERAGE_LEVEL Level,
- OUT BOOLEAN *RequireSoftECCInit
- );
-
-/**
- Perform the memory test.
-
- This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.PerformMemoryTest.
- It simply returns EFI_NOT_FOUND.
-
- @param This Protocol instance pointer.
- @param TestedMemorySize Return the tested extended memory size.
- @param TotalMemorySize Return the whole system physical memory size, this
- value may be changed if in some case some error
- DIMMs be disabled.
- @param ErrorOut Any time the memory error occurs, this will be
- TRUE.
- @param IfTestAbort Indicate if the user press "ESC" to skip the memory
- test.
-
- @retval EFI_SUCCESS One block of memory test ok, the block size is hide
- internally.
- @retval EFI_NOT_FOUND Indicate all the non-tested memory blocks have
- already go through.
- @retval EFI_DEVICE_ERROR Mis-compare error, and no agent can handle it
-
-**/
-EFI_STATUS
-EFIAPI
-GenPerformMemoryTest (
- IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
- IN OUT UINT64 *TestedMemorySize,
- OUT UINT64 *TotalMemorySize,
- OUT BOOLEAN *ErrorOut,
- IN BOOLEAN TestAbort
- );
-
-/**
- The memory test finished.
-
- This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.Finished.
- It simply returns EFI_SUCCESS.
-
- @param This Protocol instance pointer.
-
- @retval EFI_SUCCESS Successful free all the generic memory test driver
- allocated resource and notify to platform memory
- test driver that memory test finished.
-
-**/
-EFI_STATUS
-EFIAPI
-GenMemoryTestFinished (
- IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This
- );
-
-/**
- Provide capability to test compatible range which used by some special
- driver required using memory range before BDS perform memory test.
-
- This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.CompatibleRangeTest.
- It simply set the memory range to system memory.
-
- @param This Protocol instance pointer.
- @param StartAddress The start address of the memory range.
- @param Length The memory range's length.
-
- @retval EFI_SUCCESS The compatible memory range pass the memory test.
- @retval EFI_INVALID_PARAMETER The compatible memory range must be below 16M.
-
-**/
-EFI_STATUS
-EFIAPI
-GenCompatibleRangeTest (
- IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
- IN EFI_PHYSICAL_ADDRESS StartAddress,
- IN UINT64 Length
- );
-
-#endif
+/** @file
+ Include file of the NULL memory test driver.
+
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef _NULL_MEMORY_TEST_H_
+#define _NULL_MEMORY_TEST_H_
+
+#include <PiDxe.h>
+
+#include <Protocol/GenericMemoryTest.h>
+
+#include <Library/DebugLib.h>
+#include <Library/UefiDriverEntryPoint.h>
+#include <Library/DxeServicesTableLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/MemoryAllocationLib.h>
+
+//
+// Definition of memory status.
+//
+#define EFI_MEMORY_PRESENT 0x0100000000000000ULL
+#define EFI_MEMORY_INITIALIZED 0x0200000000000000ULL
+#define EFI_MEMORY_TESTED 0x0400000000000000ULL
+
+/**
+ Initialize the generic memory test.
+
+ This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.MemoryTestInit.
+ It simply promotes untested reserved memory to system memory without real test.
+
+ @param This Protocol instance pointer.
+ @param Level The coverage level of the memory test.
+ @param RequireSoftECCInit Indicate if the memory need software ECC init.
+
+ @retval EFI_SUCCESS The generic memory test initialized correctly.
+ @retval EFI_NO_MEDIA There is not any non-tested memory found, in this
+ function if not any non-tesed memory found means
+ that the memory test driver have not detect any
+ non-tested extended memory of current system.
+
+**/
+EFI_STATUS
+EFIAPI
+InitializeMemoryTest (
+ IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
+ IN EXTENDMEM_COVERAGE_LEVEL Level,
+ OUT BOOLEAN *RequireSoftECCInit
+ );
+
+/**
+ Perform the memory test.
+
+ This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.PerformMemoryTest.
+ It simply returns EFI_NOT_FOUND.
+
+ @param This Protocol instance pointer.
+ @param TestedMemorySize Return the tested extended memory size.
+ @param TotalMemorySize Return the whole system physical memory size, this
+ value may be changed if in some case some error
+ DIMMs be disabled.
+ @param ErrorOut Any time the memory error occurs, this will be
+ TRUE.
+ @param IfTestAbort Indicate if the user press "ESC" to skip the memory
+ test.
+
+ @retval EFI_SUCCESS One block of memory test ok, the block size is hide
+ internally.
+ @retval EFI_NOT_FOUND Indicate all the non-tested memory blocks have
+ already go through.
+ @retval EFI_DEVICE_ERROR Mis-compare error, and no agent can handle it
+
+**/
+EFI_STATUS
+EFIAPI
+GenPerformMemoryTest (
+ IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
+ IN OUT UINT64 *TestedMemorySize,
+ OUT UINT64 *TotalMemorySize,
+ OUT BOOLEAN *ErrorOut,
+ IN BOOLEAN TestAbort
+ );
+
+/**
+ The memory test finished.
+
+ This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.Finished.
+ It simply returns EFI_SUCCESS.
+
+ @param This Protocol instance pointer.
+
+ @retval EFI_SUCCESS Successful free all the generic memory test driver
+ allocated resource and notify to platform memory
+ test driver that memory test finished.
+
+**/
+EFI_STATUS
+EFIAPI
+GenMemoryTestFinished (
+ IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This
+ );
+
+/**
+ Provide capability to test compatible range which used by some special
+ driver required using memory range before BDS perform memory test.
+
+ This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.CompatibleRangeTest.
+ It simply set the memory range to system memory.
+
+ @param This Protocol instance pointer.
+ @param StartAddress The start address of the memory range.
+ @param Length The memory range's length.
+
+ @retval EFI_SUCCESS The compatible memory range pass the memory test.
+ @retval EFI_INVALID_PARAMETER The compatible memory range must be below 16M.
+
+**/
+EFI_STATUS
+EFIAPI
+GenCompatibleRangeTest (
+ IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
+ IN EFI_PHYSICAL_ADDRESS StartAddress,
+ IN UINT64 Length
+ );
+
+#endif
diff --git a/MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf b/MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf
index eac7ae119c..4fdd60905c 100644
--- a/MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf
+++ b/MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf
@@ -1,46 +1,46 @@
-## @file
-# This driver installs Generic Memory Test Protocol which does not perform real memory test.
-#
-# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
-# SPDX-License-Identifier: BSD-2-Clause-Patent
-#
-##
-
-[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = NullMemoryTestDxe
- MODULE_UNI_FILE = NullMemoryTestDxe.uni
- FILE_GUID = 96B5C032-DF4C-4b6e-8232-438DCF448D0E
- MODULE_TYPE = DXE_DRIVER
- VERSION_STRING = 1.0
- ENTRY_POINT = GenericMemoryTestEntryPoint
-
-#
-# The following information is for reference only and not required by the build tools.
-#
-# VALID_ARCHITECTURES = IA32 X64 EBC
-#
-
-[Sources]
- NullMemoryTest.h
- NullMemoryTest.c
-
-[Packages]
- MdeModulePkg/MdeModulePkg.dec
- MdePkg/MdePkg.dec
-
-[LibraryClasses]
- MemoryAllocationLib
- UefiBootServicesTableLib
- DxeServicesTableLib
- UefiDriverEntryPoint
- DebugLib
-
-[Protocols]
- gEfiGenericMemTestProtocolGuid ## PRODUCES
-
-[Depex]
- TRUE
-
-[UserExtensions.TianoCore."ExtraFiles"]
- NullMemoryTestDxeExtra.uni
+## @file
+# This driver installs Generic Memory Test Protocol which does not perform real memory test.
+#
+# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = NullMemoryTestDxe
+ MODULE_UNI_FILE = NullMemoryTestDxe.uni
+ FILE_GUID = 96B5C032-DF4C-4b6e-8232-438DCF448D0E
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ ENTRY_POINT = GenericMemoryTestEntryPoint
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 EBC
+#
+
+[Sources]
+ NullMemoryTest.h
+ NullMemoryTest.c
+
+[Packages]
+ MdeModulePkg/MdeModulePkg.dec
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ MemoryAllocationLib
+ UefiBootServicesTableLib
+ DxeServicesTableLib
+ UefiDriverEntryPoint
+ DebugLib
+
+[Protocols]
+ gEfiGenericMemTestProtocolGuid ## PRODUCES
+
+[Depex]
+ TRUE
+
+[UserExtensions.TianoCore."ExtraFiles"]
+ NullMemoryTestDxeExtra.uni
diff --git a/MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.uni b/MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.uni
index 63c6698c72..2e0b1b8b60 100644
--- a/MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.uni
+++ b/MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.uni
@@ -1,16 +1,16 @@
-// /** @file
-// This driver installs Generic Memory Test Protocol which does not perform real memory test.
-//
-// This driver installs Generic Memory Test Protocol, which does not perform a real memory test.
-//
-// Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
-//
-// SPDX-License-Identifier: BSD-2-Clause-Patent
-//
-// **/
-
-
-#string STR_MODULE_ABSTRACT #language en-US "Installs Generic Memory Test Protocol, which does not perform real memory test"
-
-#string STR_MODULE_DESCRIPTION #language en-US "This driver installs Generic Memory Test Protocol, which does not perform a real memory test."
-
+// /** @file
+// This driver installs Generic Memory Test Protocol which does not perform real memory test.
+//
+// This driver installs Generic Memory Test Protocol, which does not perform a real memory test.
+//
+// Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+
+#string STR_MODULE_ABSTRACT #language en-US "Installs Generic Memory Test Protocol, which does not perform real memory test"
+
+#string STR_MODULE_DESCRIPTION #language en-US "This driver installs Generic Memory Test Protocol, which does not perform a real memory test."
+
diff --git a/MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxeExtra.uni b/MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxeExtra.uni
index e763f0685a..d30deb5b77 100644
--- a/MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxeExtra.uni
+++ b/MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxeExtra.uni
@@ -1,14 +1,14 @@
-// /** @file
-// NullMemoryTestDxe Localized Strings and Content
-//
-// Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
-//
-// SPDX-License-Identifier: BSD-2-Clause-Patent
-//
-// **/
-
-#string STR_PROPERTIES_MODULE_NAME
-#language en-US
-"NULL Memory Test DXE Driver"
-
-
+// /** @file
+// NullMemoryTestDxe Localized Strings and Content
+//
+// Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_PROPERTIES_MODULE_NAME
+#language en-US
+"NULL Memory Test DXE Driver"
+
+