19UINT64 mTestedSystemMemory;
20UINT64 mNonTestedSystemMemory;
22UINT32 GenericMemoryTestMonoPattern[GENERIC_CACHELINE_SIZE / 4] = {
63 IN CONST VOID *DestinationBuffer,
69 while ((--Length != 0) &&
70 (*(INT8 *)DestinationBuffer == *(INT8 *)SourceBuffer))
72 DestinationBuffer = (INT8 *)DestinationBuffer + 1;
73 SourceBuffer = (INT8 *)SourceBuffer + 1;
76 return (
INTN)*(UINT8 *)DestinationBuffer - (
INTN)*(UINT8 *)SourceBuffer;
94 UINTN NumberOfDescriptors;
101 gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);
103 for (Index = 0; Index < NumberOfDescriptors; Index++) {
107 Private->BaseMemorySize += MemorySpaceMap[Index].
Length;
128 Link = Private->NonTestedMemRanList.BackLink;
130 while (Link != &Private->NonTestedMemRanList) {
132 NontestedRange = NONTESTED_MEMORY_RANGE_FROM_LINK (Link);
133 gBS->FreePool (NontestedRange);
134 Link = Private->NonTestedMemRanList.BackLink;
150 IN UINT64 BaseAddress,
152 IN UINT64 Capabilities
157 Status =
gDS->RemoveMemorySpace (
161 if (!EFI_ERROR (Status)) {
162 Status =
gDS->AddMemorySpace (
163 ((Capabilities & EFI_MEMORY_MORE_RELIABLE) == EFI_MEMORY_MORE_RELIABLE) ?
168 (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)
192 Link = Private->NonTestedMemRanList.ForwardLink;
194 while (Link != &Private->NonTestedMemRanList) {
195 Range = NONTESTED_MEMORY_RANGE_FROM_LINK (Link);
200 Range->Capabilities &~
201 (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)
203 Link = Link->ForwardLink;
226 IN UINT64 Capabilities
240 if (EFI_ERROR (Status)) {
251 (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)
274 UINTN NumberOfDescriptors;
283 gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);
285 for (Index = 0; Index < NumberOfDescriptors; Index++) {
287 ((MemorySpaceMap[Index].Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==
288 (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED))
301 Range->Signature = EFI_NONTESTED_MEMORY_RANGE_SIGNATURE;
302 Range->StartAddress = MemorySpaceMap[Index].
BaseAddress;
303 Range->Length = MemorySpaceMap[Index].
Length;
304 Range->Capabilities = MemorySpaceMap[Index].
Capabilities;
306 mNonTestedSystemMemory += MemorySpaceMap[Index].
Length;
312 return EFI_NOT_FOUND;
348 while (Address < (Start + Size)) {
349 CopyMem ((VOID *)(
UINTN)Address, Private->MonoPattern, Private->MonoTestSize);
350 Address += Private->CoverageSpan;
357 if (Private->Cpu !=
NULL) {
358 Private->Cpu->FlushDataCache (Private->Cpu, Start, Size, EfiCpuFlushTypeWriteBackInvalidate);
390 ExtendedErrorData =
NULL;
405 while (Address < (Start + Size)) {
407 (VOID *)(
UINTN)(Address),
408 Private->MonoPattern,
409 Private->MonoTestSize
411 if (ErrorFound != 0) {
416 if (ExtendedErrorData ==
NULL) {
417 return EFI_OUT_OF_RESOURCES;
422 ExtendedErrorData->
Granularity = EFI_MEMORY_ERROR_DEVICE;
423 ExtendedErrorData->
Operation = EFI_MEMORY_OPERATION_READ;
425 ExtendedErrorData->
Address = Address;
430 EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_UNCORRECTABLE,
432 &gEfiGenericMemTestProtocolGuid,
438 return EFI_DEVICE_ERROR;
441 Address += Private->CoverageSpan;
463 OUT BOOLEAN *RequireSoftECCInit
470 Private = GENERIC_MEMORY_TEST_PRIVATE_FROM_THIS (This);
471 *RequireSoftECCInit =
FALSE;
477 Private->CoverLevel = Level;
478 Private->BdsBlockSize = TEST_BLOCK_SIZE;
479 Private->MonoPattern = GenericMemoryTestMonoPattern;
480 Private->MonoTestSize = GENERIC_CACHELINE_SIZE;
495 Status =
gBS->LocateProtocol (
496 &gEfiCpuArchProtocolGuid,
500 if (!EFI_ERROR (Status)) {
507 switch (Private->CoverLevel) {
509 Private->CoverageSpan = GENERIC_CACHELINE_SIZE;
513 Private->CoverageSpan = SPARSE_SPAN_SIZE;
521 Private->CoverageSpan = QUICK_SPAN_SIZE;
531 if (Status == EFI_NOT_FOUND) {
538 mTestedSystemMemory = Private->BaseMemorySize;
539 mCurrentLink = Private->NonTestedMemRanList.ForwardLink;
540 mCurrentRange = NONTESTED_MEMORY_RANGE_FROM_LINK (mCurrentLink);
541 mCurrentAddress = mCurrentRange->StartAddress;
565 OUT UINT64 *TestedMemorySize,
566 OUT UINT64 *TotalMemorySize,
567 OUT BOOLEAN *ErrorOut,
574 UINT64 BlockBoundary;
576 Private = GENERIC_MEMORY_TEST_PRIVATE_FROM_THIS (This);
586 if (mCurrentAddress < (mCurrentRange->StartAddress + mCurrentRange->Length)) {
587 if ((mCurrentAddress + Private->BdsBlockSize) <= (mCurrentRange->StartAddress + mCurrentRange->Length)) {
588 BlockBoundary = Private->BdsBlockSize;
590 BlockBoundary = mCurrentRange->StartAddress + mCurrentRange->Length - mCurrentAddress;
596 if (!TestAbort && (Private->CoverLevel != IGNORE)) {
601 if (RangeData ==
NULL) {
602 return EFI_OUT_OF_RESOURCES;
607 RangeData->
Start = mCurrentAddress;
608 RangeData->
Length = BlockBoundary;
612 EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_PC_TEST,
614 &gEfiGenericMemTestProtocolGuid,
624 WriteMemory (Private, mCurrentAddress, BlockBoundary);
626 Status =
VerifyMemory (Private, mCurrentAddress, BlockBoundary);
627 if (EFI_ERROR (Status)) {
633 return EFI_DEVICE_ERROR;
637 mTestedSystemMemory += BlockBoundary;
638 *TestedMemorySize = mTestedSystemMemory;
645 *TotalMemorySize = Private->BaseMemorySize + mNonTestedSystemMemory;
650 mCurrentAddress += Private->BdsBlockSize;
658 mCurrentLink = mCurrentLink->ForwardLink;
659 if (mCurrentLink != &Private->NonTestedMemRanList) {
660 mCurrentRange = NONTESTED_MEMORY_RANGE_FROM_LINK (mCurrentLink);
661 mCurrentAddress = mCurrentRange->StartAddress;
667 *TestedMemorySize = mTestedSystemMemory;
668 *TotalMemorySize = Private->BaseMemorySize + mNonTestedSystemMemory;
669 return EFI_NOT_FOUND;
690 Private = GENERIC_MEMORY_TEST_PRIVATE_FROM_THIS (This);
695 if (Private->CoverLevel != IGNORE) {
737 UINT64 CurrentLength;
739 Private = GENERIC_MEMORY_TEST_PRIVATE_FROM_THIS (This);
744 if (StartAddress + Length > 0x1000000) {
745 return EFI_INVALID_PARAMETER;
748 CurrentBase = StartAddress;
754 Status =
gDS->GetMemorySpaceDescriptor (
758 if (EFI_ERROR (Status)) {
763 ((Descriptor.
Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==
764 (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED))
768 if (CurrentBase + CurrentLength > StartAddress + Length) {
769 CurrentLength = StartAddress + Length - CurrentBase;
778 if (EFI_ERROR (Status)) {
784 }
while (CurrentBase < StartAddress + Length);
810 BOOLEAN InExtendedRange;
817 while (TestAddress < MAX_ADDRESS && TestAddress > 0) {
821 InExtendedRange =
FALSE;
822 ExtendedLink = Private->NonTestedMemRanList.BackLink;
823 while (ExtendedLink != &Private->NonTestedMemRanList) {
824 ExtendedRange = NONTESTED_MEMORY_RANGE_FROM_LINK (ExtendedLink);
825 if ((TestAddress >= ExtendedRange->StartAddress) &&
826 (TestAddress < (ExtendedRange->StartAddress + ExtendedRange->Length))
829 InExtendedRange =
TRUE;
832 ExtendedLink = ExtendedLink->BackLink;
835 if (InExtendedRange) {
837 Private->Cpu->FlushDataCache (Private->Cpu, TestAddress, 1, EfiCpuFlushTypeWriteBackInvalidate);
839 return EFI_ACCESS_DENIED;
843 TestAddress =
LShiftU64 (TestAddress, 1);
853 EFI_GENERIC_MEMORY_TEST_PRIVATE_SIGNATURE,
902 mGenericMemoryTestPrivate.MonoPattern = GenericMemoryTestMonoPattern;
903 mGenericMemoryTestPrivate.MonoTestSize = GENERIC_CACHELINE_SIZE;
911 if (Hob.Header->
HobType != EFI_HOB_TYPE_HANDOFF) {
912 return EFI_NOT_FOUND;
915 BootMode = Hob.HandoffInformationTable->
BootMode;
922 case BOOT_WITH_FULL_CONFIGURATION:
923 case BOOT_WITH_DEFAULT_SETTINGS:
924 mGenericMemoryTestPrivate.CoverageSpan = SPARSE_SPAN_SIZE;
927 case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS:
928 mGenericMemoryTestPrivate.CoverageSpan = GENERIC_CACHELINE_SIZE;
932 mGenericMemoryTestPrivate.CoverageSpan = QUICK_SPAN_SIZE;
939 Status =
gBS->InstallProtocolInterface (
940 &mGenericMemoryTestPrivate.Handle,
941 &gEfiGenericMemTestProtocolGuid,
943 &mGenericMemoryTestPrivate.GenericMemoryTest
VOID *EFIAPI GetHobList(VOID)
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
UINT64 EFIAPI LShiftU64(IN UINT64 Operand, IN UINTN Count)
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
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 ConstructNonTestedMemoryRange(IN GENERIC_MEMORY_TEST_PRIVATE *Private)
EFI_STATUS ConstructBaseMemoryRange(IN GENERIC_MEMORY_TEST_PRIVATE *Private)
EFI_STATUS EFIAPI InitializeMemoryTest(IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This, IN EXTENDMEM_COVERAGE_LEVEL Level, OUT BOOLEAN *RequireSoftECCInit)
EFI_STATUS ConvertToTestedMemory(IN UINT64 BaseAddress, IN UINT64 Length, IN UINT64 Capabilities)
EFI_STATUS EFIAPI GenericMemoryTestEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
INTN EFIAPI CompareMemWithoutCheckArgument(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
EFI_STATUS PerformAddressDataLineTest(IN GENERIC_MEMORY_TEST_PRIVATE *Private)
EFI_STATUS DirectRangeTest(IN GENERIC_MEMORY_TEST_PRIVATE *Private, IN EFI_PHYSICAL_ADDRESS StartAddress, IN UINT64 Length, IN UINT64 Capabilities)
EFI_STATUS EFIAPI GenMemoryTestFinished(IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This)
EFI_STATUS EFIAPI GenCompatibleRangeTest(IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This, IN EFI_PHYSICAL_ADDRESS StartAddress, IN UINT64 Length)
EFI_STATUS UpdateMemoryMap(IN GENERIC_MEMORY_TEST_PRIVATE *Private)
EFI_STATUS VerifyMemory(IN GENERIC_MEMORY_TEST_PRIVATE *Private, IN EFI_PHYSICAL_ADDRESS Start, IN UINT64 Size)
VOID DestroyLinkList(IN GENERIC_MEMORY_TEST_PRIVATE *Private)
EFI_STATUS WriteMemory(IN GENERIC_MEMORY_TEST_PRIVATE *Private, IN EFI_PHYSICAL_ADDRESS Start, IN UINT64 Size)
#define ASSERT_EFI_ERROR(StatusParameter)
#define REPORT_STATUS_CODE_EX(Type, Value, Instance, CallerId, ExtendedDataGuid, ExtendedData, ExtendedDataSize)
@ EfiGcdMemoryTypeReserved
@ EfiGcdMemoryTypeMoreReliable
@ EfiGcdMemoryTypeSystemMemory
#define EFI_PROGRESS_CODE
UINT64 EFI_PHYSICAL_ADDRESS
EFI_GCD_MEMORY_TYPE GcdMemoryType
EFI_PHYSICAL_ADDRESS BaseAddress
EFI_PHYSICAL_ADDRESS Address
EFI_MEMORY_ERROR_GRANULARITY Granularity
EFI_MEMORY_ERROR_OPERATION Operation
EFI_STATUS_CODE_DATA DataHeader
EFI_PHYSICAL_ADDRESS Length
EFI_STATUS_CODE_DATA DataHeader
EFI_PHYSICAL_ADDRESS Start