]> git.proxmox.com Git - mirror_edk2.git/blob - EmulatorPkg/Library/PlatformBmLib/PlatformBmMemoryTest.c
b07226ffbdc1dc0975d60fb9193d3303e09ec310
[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 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "PlatformBm.h"
16
17 //
18 // BDS Platform Functions
19 //
20
21 /**
22 Perform the memory test base on the memory test intensive level,
23 and update the memory resource.
24
25 @param Level The memory test intensive level.
26
27 @retval EFI_STATUS Success test all the system memory and update
28 the memory resource
29
30 **/
31 EFI_STATUS
32 PlatformBootManagerMemoryTest (
33 IN EXTENDMEM_COVERAGE_LEVEL Level
34 )
35 {
36 EFI_STATUS Status;
37 EFI_STATUS KeyStatus;
38 EFI_STATUS InitStatus;
39 EFI_STATUS ReturnStatus;
40 BOOLEAN RequireSoftECCInit;
41 EFI_GENERIC_MEMORY_TEST_PROTOCOL *GenMemoryTest;
42 UINT64 TestedMemorySize;
43 UINT64 TotalMemorySize;
44 BOOLEAN ErrorOut;
45 BOOLEAN TestAbort;
46 EFI_INPUT_KEY Key;
47
48 ReturnStatus = EFI_SUCCESS;
49 ZeroMem (&Key, sizeof (EFI_INPUT_KEY));
50
51 TestedMemorySize = 0;
52 TotalMemorySize = 0;
53 ErrorOut = FALSE;
54 TestAbort = FALSE;
55
56 RequireSoftECCInit = FALSE;
57
58 Status = gBS->LocateProtocol (
59 &gEfiGenericMemTestProtocolGuid,
60 NULL,
61 (VOID **) &GenMemoryTest
62 );
63 if (EFI_ERROR (Status)) {
64 return EFI_SUCCESS;
65 }
66
67 InitStatus = GenMemoryTest->MemoryTestInit (
68 GenMemoryTest,
69 Level,
70 &RequireSoftECCInit
71 );
72 if (InitStatus == EFI_NO_MEDIA) {
73 //
74 // The PEI codes also have the relevant memory test code to check the memory,
75 // it can select to test some range of the memory or all of them. If PEI code
76 // checks all the memory, this BDS memory test will has no not-test memory to
77 // do the test, and then the status of EFI_NO_MEDIA will be returned by
78 // "MemoryTestInit". So it does not need to test memory again, just return.
79 //
80 return EFI_SUCCESS;
81 }
82
83 DEBUG ((DEBUG_INFO, "Enter memory test.\n"));
84 do {
85 Status = GenMemoryTest->PerformMemoryTest (
86 GenMemoryTest,
87 &TestedMemorySize,
88 &TotalMemorySize,
89 &ErrorOut,
90 TestAbort
91 );
92 if (ErrorOut && (Status == EFI_DEVICE_ERROR)) {
93 PrintXY (10, 10, NULL, NULL, L"Memory Testing failed!");
94 ASSERT (0);
95 }
96
97
98 DEBUG ((DEBUG_INFO, "Perform memory test (ESC to skip).\n"));
99
100 if (!PcdGetBool (PcdConInConnectOnDemand)) {
101 KeyStatus = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
102 if (!EFI_ERROR (KeyStatus) && (Key.ScanCode == SCAN_ESC)) {
103 if (!RequireSoftECCInit) {
104 Status = GenMemoryTest->Finished (GenMemoryTest);
105 goto Done;
106 }
107
108 TestAbort = TRUE;
109 }
110 }
111 } while (Status != EFI_NOT_FOUND);
112
113 Status = GenMemoryTest->Finished (GenMemoryTest);
114
115 Done:
116 DEBUG ((DEBUG_INFO, "%d bytes of system memory tested OK\r\n", TotalMemorySize));
117
118 return ReturnStatus;
119 }