]> git.proxmox.com Git - mirror_edk2.git/blob - EmulatorPkg/Library/PlatformBmLib/PlatformBmMemoryTest.c
EmulatorPkg: Use MdeModulePkg/Bds module
[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 UINT64 PreviousValue;
45 BOOLEAN ErrorOut;
46 BOOLEAN TestAbort;
47 EFI_INPUT_KEY Key;
48 CHAR16 *StrTotalMemory;
49 CHAR16 *Pos;
50 UINTN StrTotalMemorySize;
51
52 ReturnStatus = EFI_SUCCESS;
53 ZeroMem (&Key, sizeof (EFI_INPUT_KEY));
54
55 StrTotalMemorySize = 128;
56 Pos = AllocateZeroPool (StrTotalMemorySize);
57 ASSERT (Pos != NULL);
58
59 StrTotalMemory = Pos;
60
61 TestedMemorySize = 0;
62 TotalMemorySize = 0;
63 PreviousValue = 0;
64 ErrorOut = FALSE;
65 TestAbort = FALSE;
66
67 RequireSoftECCInit = FALSE;
68
69 Status = gBS->LocateProtocol (
70 &gEfiGenericMemTestProtocolGuid,
71 NULL,
72 (VOID **) &GenMemoryTest
73 );
74 if (EFI_ERROR (Status)) {
75 FreePool (Pos);
76 return EFI_SUCCESS;
77 }
78
79 InitStatus = GenMemoryTest->MemoryTestInit (
80 GenMemoryTest,
81 Level,
82 &RequireSoftECCInit
83 );
84 if (InitStatus == EFI_NO_MEDIA) {
85 //
86 // The PEI codes also have the relevant memory test code to check the memory,
87 // it can select to test some range of the memory or all of them. If PEI code
88 // checks all the memory, this BDS memory test will has no not-test memory to
89 // do the test, and then the status of EFI_NO_MEDIA will be returned by
90 // "MemoryTestInit". So it does not need to test memory again, just return.
91 //
92 FreePool (Pos);
93 return EFI_SUCCESS;
94 }
95
96 DEBUG ((DEBUG_INFO, "Enter memory test.\n"));
97 do {
98 Status = GenMemoryTest->PerformMemoryTest (
99 GenMemoryTest,
100 &TestedMemorySize,
101 &TotalMemorySize,
102 &ErrorOut,
103 TestAbort
104 );
105 if (ErrorOut && (Status == EFI_DEVICE_ERROR)) {
106 PrintXY (10, 10, NULL, NULL, L"Memory Testing failed!");
107 ASSERT (0);
108 }
109
110
111 DEBUG ((DEBUG_INFO, "Perform memory test (ESC to skip).\n"));
112
113 if (!PcdGetBool (PcdConInConnectOnDemand)) {
114 KeyStatus = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
115 if (!EFI_ERROR (KeyStatus) && (Key.ScanCode == SCAN_ESC)) {
116 if (!RequireSoftECCInit) {
117 Status = GenMemoryTest->Finished (GenMemoryTest);
118 goto Done;
119 }
120
121 TestAbort = TRUE;
122 }
123 }
124 } while (Status != EFI_NOT_FOUND);
125
126 Status = GenMemoryTest->Finished (GenMemoryTest);
127
128 Done:
129 DEBUG ((DEBUG_INFO, "%d bytes of system memory tested OK\r\n", TotalMemorySize));
130
131 FreePool (Pos);
132 return ReturnStatus;
133 }