2 Perform the platform memory test
4 Copyright (c) 2004 - 2008, Intel Corporation. <BR>
5 All rights reserved. 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.
19 // BDS Platform Functions
22 PlatformBdsShowProgress (
23 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleForeground
,
24 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleBackground
,
26 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL ProgressColor
,
28 IN UINTN PreviousValue
34 Show progress bar with title above it. It only works in Graphics mode.
38 TitleForeground - Foreground color for Title.
39 TitleBackground - Background color for Title.
40 Title - Title above progress bar.
41 ProgressColor - Progress bar color.
42 Progress - Progress (0-100)
46 EFI_STATUS - Success update the progress bar
51 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
52 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
57 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
66 return EFI_INVALID_PARAMETER
;
70 Status
= gBS
->HandleProtocol (
71 gST
->ConsoleOutHandle
,
72 &gEfiGraphicsOutputProtocolGuid
,
73 (VOID
**) &GraphicsOutput
75 if (EFI_ERROR (Status
) && FeaturePcdGet (PcdUgaConsumeSupport
)) {
76 GraphicsOutput
= NULL
;
78 Status
= gBS
->HandleProtocol (
79 gST
->ConsoleOutHandle
,
80 &gEfiUgaDrawProtocolGuid
,
84 if (EFI_ERROR (Status
)) {
85 return EFI_UNSUPPORTED
;
90 if (GraphicsOutput
!= NULL
) {
91 SizeOfX
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
92 SizeOfY
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
93 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
94 Status
= UgaDraw
->GetMode (
101 if (EFI_ERROR (Status
)) {
102 return EFI_UNSUPPORTED
;
105 return EFI_UNSUPPORTED
;
108 BlockWidth
= SizeOfX
/ 100;
109 BlockHeight
= SizeOfY
/ 50;
114 PosY
= SizeOfY
* 48 / 50;
118 // Clear progress area
120 SetMem (&Color
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
122 if (GraphicsOutput
!= NULL
) {
123 Status
= GraphicsOutput
->Blt (
130 PosY
- EFI_GLYPH_HEIGHT
- 1,
132 SizeOfY
- (PosY
- EFI_GLYPH_HEIGHT
- 1),
133 SizeOfX
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
135 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
136 Status
= UgaDraw
->Blt (
138 (EFI_UGA_PIXEL
*) &Color
,
143 PosY
- EFI_GLYPH_HEIGHT
- 1,
145 SizeOfY
- (PosY
- EFI_GLYPH_HEIGHT
- 1),
146 SizeOfX
* sizeof (EFI_UGA_PIXEL
)
149 return EFI_UNSUPPORTED
;
153 // Show progress by drawing blocks
155 for (Index
= PreviousValue
; Index
< BlockNum
; Index
++) {
156 PosX
= Index
* BlockWidth
;
157 if (GraphicsOutput
!= NULL
) {
158 Status
= GraphicsOutput
->Blt (
168 (BlockWidth
) * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
170 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
171 Status
= UgaDraw
->Blt (
173 (EFI_UGA_PIXEL
*) &ProgressColor
,
181 (BlockWidth
) * sizeof (EFI_UGA_PIXEL
)
184 return EFI_UNSUPPORTED
;
189 (SizeOfX
- StrLen (Title
) * EFI_GLYPH_WIDTH
) / 2,
190 PosY
- EFI_GLYPH_HEIGHT
- 1,
201 IN EXTENDMEM_COVERAGE_LEVEL Level
207 Perform the memory test base on the memory test intensive level,
208 and update the memory resource.
212 Level - The memory test intensive level.
216 EFI_STATUS - Success test all the system memory and update
222 EFI_STATUS KeyStatus
;
223 EFI_STATUS InitStatus
;
224 EFI_STATUS ReturnStatus
;
225 BOOLEAN RequireSoftECCInit
;
226 EFI_GENERIC_MEMORY_TEST_PROTOCOL
*GenMemoryTest
;
227 UINT64 TestedMemorySize
;
228 UINT64 TotalMemorySize
;
230 UINT64 PreviousValue
;
234 CHAR16 StrPercent
[16];
235 CHAR16
*StrTotalMemory
;
238 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
239 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
240 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
246 ReturnStatus
= EFI_SUCCESS
;
247 ZeroMem (&Key
, sizeof (EFI_INPUT_KEY
));
249 Pos
= AllocatePool (128);
255 StrTotalMemory
= Pos
;
257 TestedMemorySize
= 0;
263 SetMem (&Foreground
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
264 SetMem (&Background
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
265 SetMem (&Color
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
267 RequireSoftECCInit
= FALSE
;
269 gST
->ConOut
->ClearScreen (gST
->ConOut
);
270 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_YELLOW
| EFI_BRIGHT
);
271 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
273 Status
= gBS
->LocateProtocol (
274 &gEfiGenericMemTestProtocolGuid
,
276 (VOID
**) &GenMemoryTest
278 if (EFI_ERROR (Status
)) {
283 InitStatus
= GenMemoryTest
->MemoryTestInit (
288 if (InitStatus
== EFI_NO_MEDIA
) {
290 // The PEI codes also have the relevant memory test code to check the memory,
291 // it can select to test some range of the memory or all of them. If PEI code
292 // checks all the memory, this BDS memory test will has no not-test memory to
293 // do the test, and then the status of EFI_NO_MEDIA will be returned by
294 // "MemoryTestInit". So it does not need to test memory again, just return.
300 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, 2);
301 TmpStr
= GetStringById (STRING_TOKEN (STR_ESC_TO_SKIP_MEM_TEST
));
303 if (TmpStr
!= NULL
) {
304 gST
->ConOut
->OutputString (gST
->ConOut
, TmpStr
);
309 Status
= GenMemoryTest
->PerformMemoryTest (
316 if (ErrorOut
&& (Status
== EFI_DEVICE_ERROR
)) {
317 TmpStr
= GetStringById (STRING_TOKEN (STR_SYSTEM_MEM_ERROR
));
318 if (TmpStr
!= NULL
) {
319 PrintXY (10, 10, NULL
, NULL
, TmpStr
);
320 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, 4);
321 gST
->ConOut
->OutputString (gST
->ConOut
, TmpStr
);
328 TempData
= (UINT32
) DivU64x32 (TotalMemorySize
, 16);
329 TestPercent
= (UINTN
) DivU64x32 (
330 DivU64x32 (MultU64x32 (TestedMemorySize
, 100), 16),
333 if (TestPercent
!= PreviousValue
) {
334 UnicodeValueToString (StrPercent
, 0, TestPercent
, 0);
335 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, 0);
336 TmpStr
= GetStringById (STRING_TOKEN (STR_MEMORY_TEST_PERCENT
));
337 if (TmpStr
!= NULL
) {
338 BdsLibOutputStrings (gST
->ConOut
, StrPercent
, TmpStr
, NULL
);
342 TmpStr
= GetStringById (STRING_TOKEN (STR_PERFORM_MEM_TEST
));
343 if (TmpStr
!= NULL
) {
344 PlatformBdsShowProgress (
350 (UINTN
) PreviousValue
356 PreviousValue
= TestPercent
;
358 KeyStatus
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
359 if (!EFI_ERROR (KeyStatus
) && (Key
.ScanCode
== SCAN_ESC
)) {
360 if (!RequireSoftECCInit
) {
361 TmpStr
= GetStringById (STRING_TOKEN (STR_PERFORM_MEM_TEST
));
362 if (TmpStr
!= NULL
) {
363 PlatformBdsShowProgress (
369 (UINTN
) PreviousValue
374 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, 0);
375 gST
->ConOut
->OutputString (gST
->ConOut
, L
"100");
376 Status
= GenMemoryTest
->Finished (GenMemoryTest
);
382 } while (Status
!= EFI_NOT_FOUND
);
384 Status
= GenMemoryTest
->Finished (GenMemoryTest
);
387 UnicodeValueToString (StrTotalMemory
, COMMA_TYPE
, TotalMemorySize
, 0);
388 if (StrTotalMemory
[0] == L
',') {
392 TmpStr
= GetStringById (STRING_TOKEN (STR_MEM_TEST_COMPLETED
));
393 if (TmpStr
!= NULL
) {
394 StrCat (StrTotalMemory
, TmpStr
);
398 gST
->ConOut
->ClearScreen (gST
->ConOut
);
399 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_YELLOW
| EFI_BRIGHT
);
400 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
401 gST
->ConOut
->OutputString (gST
->ConOut
, StrTotalMemory
);
402 PlatformBdsShowProgress (
408 (UINTN
) PreviousValue
413 DataSize
= sizeof (Value
);
414 Status
= gRT
->GetVariable (
422 if (EFI_ERROR (Status
)) {
427 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,