2 Perform the platform memory test
4 Copyright (c) 2004 - 2015, 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
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.
15 #include "PlatformBootManager.h"
17 EFI_HII_HANDLE gStringPackHandle
= NULL
;
18 EFI_GUID mPlatformBootManagerStringPackGuid
= {
19 0x154dd51, 0x9079, 0x4a10, { 0x89, 0x5c, 0x9c, 0x7, 0x72, 0x81, 0x57, 0x88 }
21 // extern UINT8 BdsDxeStrings[];
24 // BDS Platform Functions
28 Perform the memory test base on the memory test intensive level,
29 and update the memory resource.
31 @param Level The memory test intensive level.
33 @retval EFI_STATUS Success test all the system memory and update
38 PlatformBootManagerMemoryTest (
39 IN EXTENDMEM_COVERAGE_LEVEL Level
44 EFI_STATUS InitStatus
;
45 EFI_STATUS ReturnStatus
;
46 BOOLEAN RequireSoftECCInit
;
47 EFI_GENERIC_MEMORY_TEST_PROTOCOL
*GenMemoryTest
;
48 UINT64 TestedMemorySize
;
49 UINT64 TotalMemorySize
;
55 CHAR16 StrPercent
[80];
56 CHAR16
*StrTotalMemory
;
59 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
60 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
61 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
63 UINTN StrTotalMemorySize
;
65 ReturnStatus
= EFI_SUCCESS
;
66 ZeroMem (&Key
, sizeof (EFI_INPUT_KEY
));
68 StrTotalMemorySize
= 128;
69 Pos
= AllocateZeroPool (StrTotalMemorySize
);
72 if (gStringPackHandle
== NULL
) {
73 gStringPackHandle
= HiiAddPackages (
74 &mPlatformBootManagerStringPackGuid
,
76 PlatformBootManagerLibStrings
,
79 ASSERT (gStringPackHandle
!= NULL
);
90 SetMem (&Foreground
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
91 SetMem (&Background
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
92 SetMem (&Color
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
94 RequireSoftECCInit
= FALSE
;
96 Status
= gBS
->LocateProtocol (
97 &gEfiGenericMemTestProtocolGuid
,
99 (VOID
**) &GenMemoryTest
101 if (EFI_ERROR (Status
)) {
106 InitStatus
= GenMemoryTest
->MemoryTestInit (
111 if (InitStatus
== EFI_NO_MEDIA
) {
113 // The PEI codes also have the relevant memory test code to check the memory,
114 // it can select to test some range of the memory or all of them. If PEI code
115 // checks all the memory, this BDS memory test will has no not-test memory to
116 // do the test, and then the status of EFI_NO_MEDIA will be returned by
117 // "MemoryTestInit". So it does not need to test memory again, just return.
123 if (!FeaturePcdGet(PcdBootlogoOnlyEnable
)) {
124 TmpStr
= HiiGetString (gStringPackHandle
, STRING_TOKEN (STR_ESC_TO_SKIP_MEM_TEST
), NULL
);
126 if (TmpStr
!= NULL
) {
127 PrintXY (10, 10, NULL
, NULL
, TmpStr
);
131 DEBUG ((EFI_D_INFO
, "Enter memory test.\n"));
134 Status
= GenMemoryTest
->PerformMemoryTest (
141 if (ErrorOut
&& (Status
== EFI_DEVICE_ERROR
)) {
142 TmpStr
= HiiGetString (gStringPackHandle
, STRING_TOKEN (STR_SYSTEM_MEM_ERROR
), NULL
);
143 if (TmpStr
!= NULL
) {
144 PrintXY (10, 10, NULL
, NULL
, TmpStr
);
151 if (!FeaturePcdGet(PcdBootlogoOnlyEnable
)) {
152 TempData
= (UINT32
) DivU64x32 (TotalMemorySize
, 16);
153 TestPercent
= (UINTN
) DivU64x32 (
154 DivU64x32 (MultU64x32 (TestedMemorySize
, 100), 16),
157 if (TestPercent
!= PreviousValue
) {
158 UnicodeValueToString (StrPercent
, 0, TestPercent
, 0);
159 TmpStr
= HiiGetString (gStringPackHandle
, STRING_TOKEN (STR_MEMORY_TEST_PERCENT
), NULL
);
160 if (TmpStr
!= NULL
) {
162 // TmpStr size is 64, StrPercent is reserved to 16.
166 sizeof (StrPercent
) / sizeof (CHAR16
),
168 sizeof (StrPercent
) / sizeof (CHAR16
) - StrLen (StrPercent
) - 1
170 PrintXY (10, 10, NULL
, NULL
, StrPercent
);
174 TmpStr
= HiiGetString (gStringPackHandle
, STRING_TOKEN (STR_PERFORM_MEM_TEST
), NULL
);
175 if (TmpStr
!= NULL
) {
176 BootLogoUpdateProgress (
182 (UINTN
) PreviousValue
188 PreviousValue
= TestPercent
;
190 DEBUG ((EFI_D_INFO
, "Perform memory test (ESC to skip).\n"));
193 if (!PcdGetBool (PcdConInConnectOnDemand
)) {
194 KeyStatus
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
195 if (!EFI_ERROR (KeyStatus
) && (Key
.ScanCode
== SCAN_ESC
)) {
196 if (!RequireSoftECCInit
) {
197 if (!FeaturePcdGet(PcdBootlogoOnlyEnable
)) {
198 TmpStr
= HiiGetString (gStringPackHandle
, STRING_TOKEN (STR_PERFORM_MEM_TEST
), NULL
);
199 if (TmpStr
!= NULL
) {
200 BootLogoUpdateProgress (
206 (UINTN
) PreviousValue
211 PrintXY (10, 10, NULL
, NULL
, L
"100");
213 Status
= GenMemoryTest
->Finished (GenMemoryTest
);
220 } while (Status
!= EFI_NOT_FOUND
);
222 Status
= GenMemoryTest
->Finished (GenMemoryTest
);
225 if (!FeaturePcdGet(PcdBootlogoOnlyEnable
)) {
226 UnicodeValueToString (StrTotalMemory
, COMMA_TYPE
, TotalMemorySize
, 0);
227 if (StrTotalMemory
[0] == L
',') {
229 StrTotalMemorySize
-= sizeof (CHAR16
);
232 TmpStr
= HiiGetString (gStringPackHandle
, STRING_TOKEN (STR_MEM_TEST_COMPLETED
), NULL
);
233 if (TmpStr
!= NULL
) {
236 StrTotalMemorySize
/ sizeof (CHAR16
),
238 StrTotalMemorySize
/ sizeof (CHAR16
) - StrLen (StrTotalMemory
) - 1
243 PrintXY (10, 10, NULL
, NULL
, StrTotalMemory
);
244 BootLogoUpdateProgress (
250 (UINTN
) PreviousValue
254 DEBUG ((EFI_D_INFO
, "%d bytes of system memory tested OK\r\n", TotalMemorySize
));