3 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "LightMemoryTest.h"
13 // Since this driver will only ever produce one instance of the memory test
14 // protocol, so we do not need to dynamically allocate the PrivateData.
16 EFI_PHYSICAL_ADDRESS mCurrentAddress
;
17 LIST_ENTRY
*mCurrentLink
;
18 NONTESTED_MEMORY_RANGE
*mCurrentRange
;
19 UINT64 mTestedSystemMemory
;
20 UINT64 mNonTestedSystemMemory
;
22 UINT32 GenericMemoryTestMonoPattern
[GENERIC_CACHELINE_SIZE
/ 4] = {
42 Compares the contents of two buffers.
44 This function compares Length bytes of SourceBuffer to Length bytes of DestinationBuffer.
45 If all Length bytes of the two buffers are identical, then 0 is returned. Otherwise, the
46 value returned is the first mismatched byte in SourceBuffer subtracted from the first
47 mismatched byte in DestinationBuffer.
49 If Length = 0, then ASSERT().
51 @param[in] DestinationBuffer The pointer to the destination buffer to compare.
52 @param[in] SourceBuffer The pointer to the source buffer to compare.
53 @param[in] Length The number of bytes to compare.
55 @return 0 All Length bytes of the two buffers are identical.
56 @retval Non-zero The first mismatched byte in SourceBuffer subtracted from the first
57 mismatched byte in DestinationBuffer.
62 CompareMemWithoutCheckArgument (
63 IN CONST VOID
*DestinationBuffer
,
64 IN CONST VOID
*SourceBuffer
,
69 while ((--Length
!= 0) &&
70 (*(INT8
*)DestinationBuffer
== *(INT8
*)SourceBuffer
)) {
71 DestinationBuffer
= (INT8
*)DestinationBuffer
+ 1;
72 SourceBuffer
= (INT8
*)SourceBuffer
+ 1;
74 return (INTN
)*(UINT8
*)DestinationBuffer
- (INTN
)*(UINT8
*)SourceBuffer
;
78 Construct the system base memory range through GCD service.
80 @param[in] Private Point to generic memory test driver's private data.
82 @retval EFI_SUCCESS Successful construct the base memory range through GCD service.
83 @retval EFI_OUT_OF_RESOURCE Could not allocate needed resource from base memory.
84 @retval Others Failed to construct base memory range through GCD service.
88 ConstructBaseMemoryRange (
89 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
92 UINTN NumberOfDescriptors
;
93 EFI_GCD_MEMORY_SPACE_DESCRIPTOR
*MemorySpaceMap
;
97 // Base memory will always below 4G
99 gDS
->GetMemorySpaceMap (&NumberOfDescriptors
, &MemorySpaceMap
);
101 for (Index
= 0; Index
< NumberOfDescriptors
; Index
++) {
102 if ((MemorySpaceMap
[Index
].GcdMemoryType
== EfiGcdMemoryTypeSystemMemory
) ||
103 (MemorySpaceMap
[Index
].GcdMemoryType
== EfiGcdMemoryTypeMoreReliable
)) {
104 Private
->BaseMemorySize
+= MemorySpaceMap
[Index
].Length
;
112 Destroy the link list base on the correspond link list type.
114 @param[in] Private Point to generic memory test driver's private data.
119 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
123 NONTESTED_MEMORY_RANGE
*NontestedRange
;
125 Link
= Private
->NonTestedMemRanList
.BackLink
;
127 while (Link
!= &Private
->NonTestedMemRanList
) {
128 RemoveEntryList (Link
);
129 NontestedRange
= NONTESTED_MEMORY_RANGE_FROM_LINK (Link
);
130 gBS
->FreePool (NontestedRange
);
131 Link
= Private
->NonTestedMemRanList
.BackLink
;;
136 Convert the memory range to tested.
138 @param BaseAddress Base address of the memory range.
139 @param Length Length of the memory range.
140 @param Capabilities Capabilities of the memory range.
142 @retval EFI_SUCCESS The memory range is converted to tested.
143 @retval others Error happens.
146 ConvertToTestedMemory (
147 IN UINT64 BaseAddress
,
149 IN UINT64 Capabilities
153 Status
= gDS
->RemoveMemorySpace (
157 if (!EFI_ERROR (Status
)) {
158 Status
= gDS
->AddMemorySpace (
159 ((Capabilities
& EFI_MEMORY_MORE_RELIABLE
) == EFI_MEMORY_MORE_RELIABLE
) ?
160 EfiGcdMemoryTypeMoreReliable
: EfiGcdMemoryTypeSystemMemory
,
164 (EFI_MEMORY_PRESENT
| EFI_MEMORY_INITIALIZED
| EFI_MEMORY_TESTED
| EFI_MEMORY_RUNTIME
)
171 Add the extened memory to whole system memory map.
173 @param[in] Private Point to generic memory test driver's private data.
175 @retval EFI_SUCCESS Successful add all the extended memory to system memory map.
176 @retval Others Failed to add the tested extended memory.
181 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
185 NONTESTED_MEMORY_RANGE
*Range
;
187 Link
= Private
->NonTestedMemRanList
.ForwardLink
;
189 while (Link
!= &Private
->NonTestedMemRanList
) {
190 Range
= NONTESTED_MEMORY_RANGE_FROM_LINK (Link
);
192 ConvertToTestedMemory (
195 Range
->Capabilities
&~
196 (EFI_MEMORY_PRESENT
| EFI_MEMORY_INITIALIZED
| EFI_MEMORY_TESTED
| EFI_MEMORY_RUNTIME
)
198 Link
= Link
->ForwardLink
;
205 Test a range of the memory directly .
207 @param[in] Private Point to generic memory test driver's private data.
208 @param[in] StartAddress Starting address of the memory range to be tested.
209 @param[in] Length Length in bytes of the memory range to be tested.
210 @param[in] Capabilities The bit mask of attributes that the memory range supports.
212 @retval EFI_SUCCESS Successful test the range of memory.
213 @retval Others Failed to test the range of memory.
218 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
,
219 IN EFI_PHYSICAL_ADDRESS StartAddress
,
221 IN UINT64 Capabilities
227 // Perform a dummy memory test, so directly write the pattern to all range
229 WriteMemory (Private
, StartAddress
, Length
);
232 // Verify the memory range
234 Status
= VerifyMemory (Private
, StartAddress
, Length
);
235 if (EFI_ERROR (Status
)) {
239 // Add the tested compatible memory to system memory using GCD service
241 ConvertToTestedMemory (
245 (EFI_MEMORY_PRESENT
| EFI_MEMORY_INITIALIZED
| EFI_MEMORY_TESTED
| EFI_MEMORY_RUNTIME
)
252 Construct the system non-tested memory range through GCD service.
254 @param[in] Private Point to generic memory test driver's private data.
256 @retval EFI_SUCCESS Successful construct the non-tested memory range through GCD service.
257 @retval EFI_OUT_OF_RESOURCE Could not allocate needed resource from base memory.
258 @retval Others Failed to construct non-tested memory range through GCD service.
262 ConstructNonTestedMemoryRange (
263 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
266 NONTESTED_MEMORY_RANGE
*Range
;
268 UINTN NumberOfDescriptors
;
269 EFI_GCD_MEMORY_SPACE_DESCRIPTOR
*MemorySpaceMap
;
273 // Non tested memory range may be span 4G here
277 gDS
->GetMemorySpaceMap (&NumberOfDescriptors
, &MemorySpaceMap
);
279 for (Index
= 0; Index
< NumberOfDescriptors
; Index
++) {
280 if (MemorySpaceMap
[Index
].GcdMemoryType
== EfiGcdMemoryTypeReserved
&&
281 (MemorySpaceMap
[Index
].Capabilities
& (EFI_MEMORY_PRESENT
| EFI_MEMORY_INITIALIZED
| EFI_MEMORY_TESTED
)) ==
282 (EFI_MEMORY_PRESENT
| EFI_MEMORY_INITIALIZED
)
286 // Light version do not need to process >4G memory range
290 sizeof (NONTESTED_MEMORY_RANGE
),
294 Range
->Signature
= EFI_NONTESTED_MEMORY_RANGE_SIGNATURE
;
295 Range
->StartAddress
= MemorySpaceMap
[Index
].BaseAddress
;
296 Range
->Length
= MemorySpaceMap
[Index
].Length
;
297 Range
->Capabilities
= MemorySpaceMap
[Index
].Capabilities
;
299 mNonTestedSystemMemory
+= MemorySpaceMap
[Index
].Length
;
300 InsertTailList (&Private
->NonTestedMemRanList
, &Range
->Link
);
305 return EFI_NOT_FOUND
;
312 Write the memory test pattern into a range of physical memory.
314 @param[in] Private Point to generic memory test driver's private data.
315 @param[in] Start The memory range's start address.
316 @param[in] Size The memory range's size.
318 @retval EFI_SUCCESS Successful write the test pattern into the non-tested memory.
319 @retval Others The test pattern may not really write into the physical memory.
324 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
,
325 IN EFI_PHYSICAL_ADDRESS Start
,
329 EFI_PHYSICAL_ADDRESS Address
;
334 // Add 4G memory address check for IA32 platform
335 // NOTE: Without page table, there is no way to use memory above 4G.
337 if (Start
+ Size
> MAX_ADDRESS
) {
341 while (Address
< (Start
+ Size
)) {
342 CopyMem ((VOID
*) (UINTN
) Address
, Private
->MonoPattern
, Private
->MonoTestSize
);
343 Address
+= Private
->CoverageSpan
;
346 // bug bug: we may need GCD service to make the code cache and data uncache,
347 // if GCD do not support it or return fail, then just flush the whole cache.
349 if (Private
->Cpu
!= NULL
) {
350 Private
->Cpu
->FlushDataCache (Private
->Cpu
, Start
, Size
, EfiCpuFlushTypeWriteBackInvalidate
);
357 Verify the range of physical memory which covered by memory test pattern.
359 This function will also do not return any informatin just cause system reset,
360 because the handle error encount fatal error and disable the bad DIMMs.
362 @param[in] Private Point to generic memory test driver's private data.
363 @param[in] Start The memory range's start address.
364 @param[in] Size The memory range's size.
366 @retval EFI_SUCCESS Successful verify the range of memory, no errors' location found.
367 @retval Others The range of memory have errors contained.
372 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
,
373 IN EFI_PHYSICAL_ADDRESS Start
,
377 EFI_PHYSICAL_ADDRESS Address
;
379 EFI_MEMORY_EXTENDED_ERROR_DATA
*ExtendedErrorData
;
382 ExtendedErrorData
= NULL
;
385 // Add 4G memory address check for IA32 platform
386 // NOTE: Without page table, there is no way to use memory above 4G.
388 if (Start
+ Size
> MAX_ADDRESS
) {
393 // Use the software memory test to check whether have detected miscompare
394 // error here. If there is miscompare error here then check if generic
395 // memory test driver can disable the bad DIMM.
397 while (Address
< (Start
+ Size
)) {
398 ErrorFound
= CompareMemWithoutCheckArgument (
399 (VOID
*) (UINTN
) (Address
),
400 Private
->MonoPattern
,
401 Private
->MonoTestSize
403 if (ErrorFound
!= 0) {
405 // Report uncorrectable errors
407 ExtendedErrorData
= AllocateZeroPool (sizeof (EFI_MEMORY_EXTENDED_ERROR_DATA
));
408 if (ExtendedErrorData
== NULL
) {
409 return EFI_OUT_OF_RESOURCES
;
412 ExtendedErrorData
->DataHeader
.HeaderSize
= (UINT16
) sizeof (EFI_STATUS_CODE_DATA
);
413 ExtendedErrorData
->DataHeader
.Size
= (UINT16
) (sizeof (EFI_MEMORY_EXTENDED_ERROR_DATA
) - sizeof (EFI_STATUS_CODE_DATA
));
414 ExtendedErrorData
->Granularity
= EFI_MEMORY_ERROR_DEVICE
;
415 ExtendedErrorData
->Operation
= EFI_MEMORY_OPERATION_READ
;
416 ExtendedErrorData
->Syndrome
= 0x0;
417 ExtendedErrorData
->Address
= Address
;
418 ExtendedErrorData
->Resolution
= 0x40;
420 REPORT_STATUS_CODE_EX (
422 EFI_COMPUTING_UNIT_MEMORY
| EFI_CU_MEMORY_EC_UNCORRECTABLE
,
424 &gEfiGenericMemTestProtocolGuid
,
426 (UINT8
*) ExtendedErrorData
+ sizeof (EFI_STATUS_CODE_DATA
),
427 ExtendedErrorData
->DataHeader
.Size
430 return EFI_DEVICE_ERROR
;
433 Address
+= Private
->CoverageSpan
;
440 Initialize the generic memory test.
442 @param[in] This The protocol instance pointer.
443 @param[in] Level The coverage level of the memory test.
444 @param[out] RequireSoftECCInit Indicate if the memory need software ECC init.
446 @retval EFI_SUCCESS The generic memory test is initialized correctly.
447 @retval EFI_NO_MEDIA The system had no memory to be tested.
452 InitializeMemoryTest (
453 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
,
454 IN EXTENDMEM_COVERAGE_LEVEL Level
,
455 OUT BOOLEAN
*RequireSoftECCInit
459 GENERIC_MEMORY_TEST_PRIVATE
*Private
;
460 EFI_CPU_ARCH_PROTOCOL
*Cpu
;
462 Private
= GENERIC_MEMORY_TEST_PRIVATE_FROM_THIS (This
);
463 *RequireSoftECCInit
= FALSE
;
466 // This is initialize for default value, but some value may be reset base on
467 // platform memory test driver.
469 Private
->CoverLevel
= Level
;
470 Private
->BdsBlockSize
= TEST_BLOCK_SIZE
;
471 Private
->MonoPattern
= GenericMemoryTestMonoPattern
;
472 Private
->MonoTestSize
= GENERIC_CACHELINE_SIZE
;
475 // Initialize several internal link list
477 InitializeListHead (&Private
->NonTestedMemRanList
);
480 // Construct base memory range
482 ConstructBaseMemoryRange (Private
);
485 // get the cpu arch protocol to support flash cache
487 Status
= gBS
->LocateProtocol (
488 &gEfiCpuArchProtocolGuid
,
492 if (!EFI_ERROR (Status
)) {
496 // Create the CoverageSpan of the memory test base on the coverage level
498 switch (Private
->CoverLevel
) {
500 Private
->CoverageSpan
= GENERIC_CACHELINE_SIZE
;
504 Private
->CoverageSpan
= SPARSE_SPAN_SIZE
;
508 // Even the BDS do not need to test any memory, but in some case it
509 // still need to init ECC memory.
512 Private
->CoverageSpan
= QUICK_SPAN_SIZE
;
516 // This is the first time we construct the non-tested memory range, if no
517 // extended memory found, we know the system have not any extended memory
520 Status
= ConstructNonTestedMemoryRange (Private
);
521 if (Status
== EFI_NOT_FOUND
) {
525 // ready to perform the R/W/V memory test
527 mTestedSystemMemory
= Private
->BaseMemorySize
;
528 mCurrentLink
= Private
->NonTestedMemRanList
.ForwardLink
;
529 mCurrentRange
= NONTESTED_MEMORY_RANGE_FROM_LINK (mCurrentLink
);
530 mCurrentAddress
= mCurrentRange
->StartAddress
;
536 Perform the memory test.
538 @param[in] This The protocol instance pointer.
539 @param[out] TestedMemorySize Return the tested extended memory size.
540 @param[out] TotalMemorySize Return the whole system physical memory size.
541 The total memory size does not include memory in a slot with a disabled DIMM.
542 @param[out] ErrorOut TRUE if the memory error occured.
543 @param[in] IfTestAbort Indicates that the user pressed "ESC" to skip the memory test.
545 @retval EFI_SUCCESS One block of memory passed the test.
546 @retval EFI_NOT_FOUND All memory blocks have already been tested.
547 @retval EFI_DEVICE_ERROR Memory device error occured, and no agent can handle it.
552 GenPerformMemoryTest (
553 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
,
554 OUT UINT64
*TestedMemorySize
,
555 OUT UINT64
*TotalMemorySize
,
556 OUT BOOLEAN
*ErrorOut
,
561 GENERIC_MEMORY_TEST_PRIVATE
*Private
;
562 EFI_MEMORY_RANGE_EXTENDED_DATA
*RangeData
;
563 UINT64 BlockBoundary
;
565 Private
= GENERIC_MEMORY_TEST_PRIVATE_FROM_THIS (This
);
571 // In extensive mode the boundary of "mCurrentRange->Length" may will lost
572 // some range that is not Private->BdsBlockSize size boundary, so need
573 // the software mechanism to confirm all memory location be covered.
575 if (mCurrentAddress
< (mCurrentRange
->StartAddress
+ mCurrentRange
->Length
)) {
576 if ((mCurrentAddress
+ Private
->BdsBlockSize
) <= (mCurrentRange
->StartAddress
+ mCurrentRange
->Length
)) {
577 BlockBoundary
= Private
->BdsBlockSize
;
579 BlockBoundary
= mCurrentRange
->StartAddress
+ mCurrentRange
->Length
- mCurrentAddress
;
582 // If TestAbort is true, means user cancel the memory test
584 if (!TestAbort
&& Private
->CoverLevel
!= IGNORE
) {
586 // Report status code of every memory range
588 RangeData
= AllocateZeroPool (sizeof (EFI_MEMORY_RANGE_EXTENDED_DATA
));
589 if (RangeData
== NULL
) {
590 return EFI_OUT_OF_RESOURCES
;
592 RangeData
->DataHeader
.HeaderSize
= (UINT16
) sizeof (EFI_STATUS_CODE_DATA
);
593 RangeData
->DataHeader
.Size
= (UINT16
) (sizeof (EFI_MEMORY_RANGE_EXTENDED_DATA
) - sizeof (EFI_STATUS_CODE_DATA
));
594 RangeData
->Start
= mCurrentAddress
;
595 RangeData
->Length
= BlockBoundary
;
597 REPORT_STATUS_CODE_EX (
599 EFI_COMPUTING_UNIT_MEMORY
| EFI_CU_MEMORY_PC_TEST
,
601 &gEfiGenericMemTestProtocolGuid
,
603 (UINT8
*) RangeData
+ sizeof (EFI_STATUS_CODE_DATA
),
604 RangeData
->DataHeader
.Size
608 // The software memory test (R/W/V) perform here. It will detect the
609 // memory mis-compare error.
611 WriteMemory (Private
, mCurrentAddress
, BlockBoundary
);
613 Status
= VerifyMemory (Private
, mCurrentAddress
, BlockBoundary
);
614 if (EFI_ERROR (Status
)) {
616 // If perform here, means there is mis-compare error, and no agent can
617 // handle it, so we return to BDS EFI_DEVICE_ERROR.
620 return EFI_DEVICE_ERROR
;
624 mTestedSystemMemory
+= BlockBoundary
;
625 *TestedMemorySize
= mTestedSystemMemory
;
628 // If the memory test restart after the platform driver disable dimms,
629 // the NonTestSystemMemory may be changed, but the base memory size will
630 // not changed, so we can get the current total memory size.
632 *TotalMemorySize
= Private
->BaseMemorySize
+ mNonTestedSystemMemory
;
635 // Update the current test address pointing to next BDS BLOCK
637 mCurrentAddress
+= Private
->BdsBlockSize
;
642 // Change to next non tested memory range
644 mCurrentLink
= mCurrentLink
->ForwardLink
;
645 if (mCurrentLink
!= &Private
->NonTestedMemRanList
) {
646 mCurrentRange
= NONTESTED_MEMORY_RANGE_FROM_LINK (mCurrentLink
);
647 mCurrentAddress
= mCurrentRange
->StartAddress
;
651 // Here means all the memory test have finished
653 *TestedMemorySize
= mTestedSystemMemory
;
654 *TotalMemorySize
= Private
->BaseMemorySize
+ mNonTestedSystemMemory
;
655 return EFI_NOT_FOUND
;
661 Finish the memory test.
663 @param[in] This The protocol instance pointer.
665 @retval EFI_SUCCESS Success. All resources used in the memory test are freed.
670 GenMemoryTestFinished (
671 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
675 GENERIC_MEMORY_TEST_PRIVATE
*Private
;
677 Private
= GENERIC_MEMORY_TEST_PRIVATE_FROM_THIS (This
);
680 // Perform Data and Address line test
682 Status
= PerformAddressDataLineTest (Private
);
683 ASSERT_EFI_ERROR (Status
);
686 // Add the non tested memory range to system memory map through GCD service
688 UpdateMemoryMap (Private
);
691 // we need to free all the memory allocate
693 DestroyLinkList (Private
);
699 Provides the capability to test the compatible range used by some special drivers.
701 @param[in] This The protocol instance pointer.
702 @param[in] StartAddress The start address of the compatible memory range that
704 @param[in] Length The compatible memory range's length.
706 @retval EFI_SUCCESS The compatible memory range pass the memory test.
707 @retval EFI_INVALID_PARAMETER The compatible memory range are not below Low 16M.
712 GenCompatibleRangeTest (
713 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
,
714 IN EFI_PHYSICAL_ADDRESS StartAddress
,
719 GENERIC_MEMORY_TEST_PRIVATE
*Private
;
720 EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor
;
721 EFI_PHYSICAL_ADDRESS CurrentBase
;
722 UINT64 CurrentLength
;
724 Private
= GENERIC_MEMORY_TEST_PRIVATE_FROM_THIS (This
);
727 // Check if the parameter is below 16MB
729 if (StartAddress
+ Length
> 0x1000000) {
730 return EFI_INVALID_PARAMETER
;
732 CurrentBase
= StartAddress
;
735 // Check the required memory range status; if the required memory range span
736 // the different GCD memory descriptor, it may be cause different action.
738 Status
= gDS
->GetMemorySpaceDescriptor (
742 if (EFI_ERROR (Status
)) {
746 if (Descriptor
.GcdMemoryType
== EfiGcdMemoryTypeReserved
&&
747 (Descriptor
.Capabilities
& (EFI_MEMORY_PRESENT
| EFI_MEMORY_INITIALIZED
| EFI_MEMORY_TESTED
)) ==
748 (EFI_MEMORY_PRESENT
| EFI_MEMORY_INITIALIZED
)
750 CurrentLength
= Descriptor
.BaseAddress
+ Descriptor
.Length
- CurrentBase
;
751 if (CurrentBase
+ CurrentLength
> StartAddress
+ Length
) {
752 CurrentLength
= StartAddress
+ Length
- CurrentBase
;
754 Status
= DirectRangeTest (
758 Descriptor
.Capabilities
760 if (EFI_ERROR (Status
)) {
764 CurrentBase
= Descriptor
.BaseAddress
+ Descriptor
.Length
;
765 } while (CurrentBase
< StartAddress
+ Length
);
767 // Here means the required range already be tested, so just return success.
773 Perform the address line walking ones test.
775 @param[in] Private Point to generic memory test driver's private data.
777 @retval EFI_SUCCESS Successful finished walking ones test.
778 @retval EFI_OUT_OF_RESOURCE Could not get resource in base memory.
779 @retval EFI_ACCESS_DENIED Code may can not run here because if walking one test
780 failed, system may be already halt.
784 PerformAddressDataLineTest (
785 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
788 LIST_ENTRY
*ExtendedLink
;
789 NONTESTED_MEMORY_RANGE
*ExtendedRange
;
790 BOOLEAN InExtendedRange
;
791 EFI_PHYSICAL_ADDRESS TestAddress
;
794 // Light version no data line test, only perform the address line test
796 TestAddress
= (EFI_PHYSICAL_ADDRESS
) 0x1;
797 while (TestAddress
< MAX_ADDRESS
&& TestAddress
> 0) {
799 // only test if the address falls in the enabled range
801 InExtendedRange
= FALSE
;
802 ExtendedLink
= Private
->NonTestedMemRanList
.BackLink
;
803 while (ExtendedLink
!= &Private
->NonTestedMemRanList
) {
804 ExtendedRange
= NONTESTED_MEMORY_RANGE_FROM_LINK (ExtendedLink
);
805 if ((TestAddress
>= ExtendedRange
->StartAddress
) &&
806 (TestAddress
< (ExtendedRange
->StartAddress
+ ExtendedRange
->Length
))
808 InExtendedRange
= TRUE
;
811 ExtendedLink
= ExtendedLink
->BackLink
;
814 if (InExtendedRange
) {
815 *(EFI_PHYSICAL_ADDRESS
*) (UINTN
) TestAddress
= TestAddress
;
816 Private
->Cpu
->FlushDataCache (Private
->Cpu
, TestAddress
, 1, EfiCpuFlushTypeWriteBackInvalidate
);
817 if (*(EFI_PHYSICAL_ADDRESS
*) (UINTN
) TestAddress
!= TestAddress
) {
818 return EFI_ACCESS_DENIED
;
822 TestAddress
= LShiftU64 (TestAddress
, 1);
830 GENERIC_MEMORY_TEST_PRIVATE mGenericMemoryTestPrivate
= {
831 EFI_GENERIC_MEMORY_TEST_PRIVATE_SIGNATURE
,
835 InitializeMemoryTest
,
836 GenPerformMemoryTest
,
837 GenMemoryTestFinished
,
838 GenCompatibleRangeTest
840 (EXTENDMEM_COVERAGE_LEVEL
) 0,
853 The generic memory test driver's entry point.
855 It initializes private data to default value.
857 @param[in] ImageHandle The firmware allocated handle for the EFI image.
858 @param[in] SystemTable A pointer to the EFI System Table.
860 @retval EFI_SUCCESS The entry point is executed successfully.
861 @retval EFI_NOT_FOUND Can't find HandOff Hob in HobList.
862 @retval other Some error occurs when executing this entry point.
867 GenericMemoryTestEntryPoint (
868 IN EFI_HANDLE ImageHandle
,
869 IN EFI_SYSTEM_TABLE
*SystemTable
874 EFI_BOOT_MODE BootMode
;
875 EFI_PEI_HOB_POINTERS Hob
;
878 // Use the generic pattern to test compatible memory range
880 mGenericMemoryTestPrivate
.MonoPattern
= GenericMemoryTestMonoPattern
;
881 mGenericMemoryTestPrivate
.MonoTestSize
= GENERIC_CACHELINE_SIZE
;
884 // Get the platform boot mode
886 HobList
= GetHobList ();
889 if (Hob
.Header
->HobType
!= EFI_HOB_TYPE_HANDOFF
) {
890 return EFI_NOT_FOUND
;
893 BootMode
= Hob
.HandoffInformationTable
->BootMode
;
896 // Get the platform boot mode and create the default memory test coverage
897 // level and span size for compatible memory test using
900 case BOOT_WITH_FULL_CONFIGURATION
:
901 case BOOT_WITH_DEFAULT_SETTINGS
:
902 mGenericMemoryTestPrivate
.CoverageSpan
= SPARSE_SPAN_SIZE
;
905 case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS
:
906 mGenericMemoryTestPrivate
.CoverageSpan
= GENERIC_CACHELINE_SIZE
;
910 mGenericMemoryTestPrivate
.CoverageSpan
= QUICK_SPAN_SIZE
;
914 // Install the protocol
916 Status
= gBS
->InstallProtocolInterface (
917 &mGenericMemoryTestPrivate
.Handle
,
918 &gEfiGenericMemTestProtocolGuid
,
919 EFI_NATIVE_INTERFACE
,
920 &mGenericMemoryTestPrivate
.GenericMemoryTest