]> git.proxmox.com Git - mirror_edk2.git/blob - EmulatorPkg/Library/PlatformBmLib/PlatformBmMemoryTest.c
EmulatorPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / EmulatorPkg / Library / PlatformBmLib / PlatformBmMemoryTest.c
1 /** @file
2 Perform the platform memory test
3
4 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "PlatformBm.h"
10
11 //
12 // BDS Platform Functions
13 //
14
15 /**
16 Perform the memory test base on the memory test intensive level,
17 and update the memory resource.
18
19 @param Level The memory test intensive level.
20
21 @retval EFI_STATUS Success test all the system memory and update
22 the memory resource
23
24 **/
25 EFI_STATUS
26 PlatformBootManagerMemoryTest (
27 IN EXTENDMEM_COVERAGE_LEVEL Level
28 )
29 {
30 EFI_STATUS Status;
31 EFI_STATUS KeyStatus;
32 EFI_STATUS InitStatus;
33 EFI_STATUS ReturnStatus;
34 BOOLEAN RequireSoftECCInit;
35 EFI_GENERIC_MEMORY_TEST_PROTOCOL *GenMemoryTest;
36 UINT64 TestedMemorySize;
37 UINT64 TotalMemorySize;
38 BOOLEAN ErrorOut;
39 BOOLEAN TestAbort;
40 EFI_INPUT_KEY Key;
41
42 ReturnStatus = EFI_SUCCESS;
43 ZeroMem (&Key, sizeof (EFI_INPUT_KEY));
44
45 TestedMemorySize = 0;
46 TotalMemorySize = 0;
47 ErrorOut = FALSE;
48 TestAbort = FALSE;
49
50 RequireSoftECCInit = FALSE;
51
52 Status = gBS->LocateProtocol (
53 &gEfiGenericMemTestProtocolGuid,
54 NULL,
55 (VOID **) &GenMemoryTest
56 );
57 if (EFI_ERROR (Status)) {
58 return EFI_SUCCESS;
59 }
60
61 InitStatus = GenMemoryTest->MemoryTestInit (
62 GenMemoryTest,
63 Level,
64 &RequireSoftECCInit
65 );
66 if (InitStatus == EFI_NO_MEDIA) {
67 //
68 // The PEI codes also have the relevant memory test code to check the memory,
69 // it can select to test some range of the memory or all of them. If PEI code
70 // checks all the memory, this BDS memory test will has no not-test memory to
71 // do the test, and then the status of EFI_NO_MEDIA will be returned by
72 // "MemoryTestInit". So it does not need to test memory again, just return.
73 //
74 return EFI_SUCCESS;
75 }
76
77 DEBUG ((DEBUG_INFO, "Enter memory test.\n"));
78 do {
79 Status = GenMemoryTest->PerformMemoryTest (
80 GenMemoryTest,
81 &TestedMemorySize,
82 &TotalMemorySize,
83 &ErrorOut,
84 TestAbort
85 );
86 if (ErrorOut && (Status == EFI_DEVICE_ERROR)) {
87 PrintXY (10, 10, NULL, NULL, L"Memory Testing failed!");
88 ASSERT (0);
89 }
90
91
92 DEBUG ((DEBUG_INFO, "Perform memory test (ESC to skip).\n"));
93
94 if (!PcdGetBool (PcdConInConnectOnDemand)) {
95 KeyStatus = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
96 if (!EFI_ERROR (KeyStatus) && (Key.ScanCode == SCAN_ESC)) {
97 if (!RequireSoftECCInit) {
98 Status = GenMemoryTest->Finished (GenMemoryTest);
99 goto Done;
100 }
101
102 TestAbort = TRUE;
103 }
104 }
105 } while (Status != EFI_NOT_FOUND);
106
107 Status = GenMemoryTest->Finished (GenMemoryTest);
108
109 Done:
110 DEBUG ((DEBUG_INFO, "%d bytes of system memory tested OK\r\n", TotalMemorySize));
111
112 return ReturnStatus;
113 }