3 Copyright (c) 2004 - 2008, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Perform the platform memory test
26 // BDS Platform Functions
29 PlatformBdsShowProgress (
30 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleForeground
,
31 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleBackground
,
33 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL ProgressColor
,
35 IN UINTN PreviousValue
41 Show progress bar with title above it. It only works in Graphics mode.
45 TitleForeground - Foreground color for Title.
46 TitleBackground - Background color for Title.
47 Title - Title above progress bar.
48 ProgressColor - Progress bar color.
49 Progress - Progress (0-100)
53 EFI_STATUS - Success update the progress bar
58 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
59 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
64 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
73 return EFI_INVALID_PARAMETER
;
77 Status
= gBS
->HandleProtocol (
78 gST
->ConsoleOutHandle
,
79 &gEfiGraphicsOutputProtocolGuid
,
80 (VOID
**) &GraphicsOutput
82 if (EFI_ERROR (Status
) && FeaturePcdGet (PcdUgaConsumeSupport
)) {
83 GraphicsOutput
= NULL
;
85 Status
= gBS
->HandleProtocol (
86 gST
->ConsoleOutHandle
,
87 &gEfiUgaDrawProtocolGuid
,
91 if (EFI_ERROR (Status
)) {
92 return EFI_UNSUPPORTED
;
97 if (GraphicsOutput
!= NULL
) {
98 SizeOfX
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
99 SizeOfY
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
100 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
101 Status
= UgaDraw
->GetMode (
108 if (EFI_ERROR (Status
)) {
109 return EFI_UNSUPPORTED
;
112 return EFI_UNSUPPORTED
;
115 BlockWidth
= SizeOfX
/ 100;
116 BlockHeight
= SizeOfY
/ 50;
121 PosY
= SizeOfY
* 48 / 50;
125 // Clear progress area
127 SetMem (&Color
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
129 if (GraphicsOutput
!= NULL
) {
130 Status
= GraphicsOutput
->Blt (
137 PosY
- GLYPH_HEIGHT
- 1,
139 SizeOfY
- (PosY
- GLYPH_HEIGHT
- 1),
140 SizeOfX
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
142 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
143 Status
= UgaDraw
->Blt (
145 (EFI_UGA_PIXEL
*) &Color
,
150 PosY
- GLYPH_HEIGHT
- 1,
152 SizeOfY
- (PosY
- GLYPH_HEIGHT
- 1),
153 SizeOfX
* sizeof (EFI_UGA_PIXEL
)
156 return EFI_UNSUPPORTED
;
160 // Show progress by drawing blocks
162 for (Index
= PreviousValue
; Index
< BlockNum
; Index
++) {
163 PosX
= Index
* BlockWidth
;
164 if (GraphicsOutput
!= NULL
) {
165 Status
= GraphicsOutput
->Blt (
175 (BlockWidth
) * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
177 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
178 Status
= UgaDraw
->Blt (
180 (EFI_UGA_PIXEL
*) &ProgressColor
,
188 (BlockWidth
) * sizeof (EFI_UGA_PIXEL
)
191 return EFI_UNSUPPORTED
;
196 (SizeOfX
- StrLen (Title
) * GLYPH_WIDTH
) / 2,
197 PosY
- GLYPH_HEIGHT
- 1,
208 IN EXTENDMEM_COVERAGE_LEVEL Level
214 Perform the memory test base on the memory test intensive level,
215 and update the memory resource.
219 Level - The memory test intensive level.
223 EFI_STATUS - Success test all the system memory and update
229 EFI_STATUS KeyStatus
;
230 EFI_STATUS InitStatus
;
231 EFI_STATUS ReturnStatus
;
232 BOOLEAN RequireSoftECCInit
;
233 EFI_GENERIC_MEMORY_TEST_PROTOCOL
*GenMemoryTest
;
234 UINT64 TestedMemorySize
;
235 UINT64 TotalMemorySize
;
237 UINT64 PreviousValue
;
241 CHAR16 StrPercent
[16];
242 CHAR16
*StrTotalMemory
;
245 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
246 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
247 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
253 ReturnStatus
= EFI_SUCCESS
;
254 ZeroMem (&Key
, sizeof (EFI_INPUT_KEY
));
256 Pos
= AllocatePool (128);
262 StrTotalMemory
= Pos
;
264 TestedMemorySize
= 0;
270 SetMem (&Foreground
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
271 SetMem (&Background
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
272 SetMem (&Color
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
274 RequireSoftECCInit
= FALSE
;
276 gST
->ConOut
->ClearScreen (gST
->ConOut
);
277 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_YELLOW
| EFI_BRIGHT
);
278 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
280 Status
= gBS
->LocateProtocol (
281 &gEfiGenericMemTestProtocolGuid
,
283 (VOID
**) &GenMemoryTest
285 if (EFI_ERROR (Status
)) {
290 InitStatus
= GenMemoryTest
->MemoryTestInit (
295 if (InitStatus
== EFI_NO_MEDIA
) {
297 // The PEI codes also have the relevant memory test code to check the memory,
298 // it can select to test some range of the memory or all of them. If PEI code
299 // checks all the memory, this BDS memory test will has no not-test memory to
300 // do the test, and then the status of EFI_NO_MEDIA will be returned by
301 // "MemoryTestInit". So it does not need to test memory again, just return.
307 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, 2);
308 TmpStr
= GetStringById (STRING_TOKEN (STR_ESC_TO_SKIP_MEM_TEST
));
310 if (TmpStr
!= NULL
) {
311 gST
->ConOut
->OutputString (gST
->ConOut
, TmpStr
);
316 Status
= GenMemoryTest
->PerformMemoryTest (
323 if (ErrorOut
&& (Status
== EFI_DEVICE_ERROR
)) {
324 TmpStr
= GetStringById (STRING_TOKEN (STR_SYSTEM_MEM_ERROR
));
325 if (TmpStr
!= NULL
) {
326 PrintXY (10, 10, NULL
, NULL
, TmpStr
);
327 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, 4);
328 gST
->ConOut
->OutputString (gST
->ConOut
, TmpStr
);
335 TempData
= (UINT32
) DivU64x32 (TotalMemorySize
, 16);
336 TestPercent
= (UINTN
) DivU64x32 (
337 DivU64x32 (MultU64x32 (TestedMemorySize
, 100), 16),
340 if (TestPercent
!= PreviousValue
) {
341 UnicodeValueToString (StrPercent
, 0, TestPercent
, 0);
342 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, 0);
343 TmpStr
= GetStringById (STRING_TOKEN (STR_MEMORY_TEST_PERCENT
));
344 if (TmpStr
!= NULL
) {
345 BdsLibOutputStrings (gST
->ConOut
, StrPercent
, TmpStr
, NULL
);
349 TmpStr
= GetStringById (STRING_TOKEN (STR_PERFORM_MEM_TEST
));
350 if (TmpStr
!= NULL
) {
351 PlatformBdsShowProgress (
357 (UINTN
) PreviousValue
363 PreviousValue
= TestPercent
;
365 KeyStatus
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
366 if (!EFI_ERROR (KeyStatus
) && (Key
.ScanCode
== SCAN_ESC
)) {
367 if (!RequireSoftECCInit
) {
368 TmpStr
= GetStringById (STRING_TOKEN (STR_PERFORM_MEM_TEST
));
369 if (TmpStr
!= NULL
) {
370 PlatformBdsShowProgress (
376 (UINTN
) PreviousValue
381 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, 0);
382 gST
->ConOut
->OutputString (gST
->ConOut
, L
"100");
383 Status
= GenMemoryTest
->Finished (GenMemoryTest
);
389 } while (Status
!= EFI_NOT_FOUND
);
391 Status
= GenMemoryTest
->Finished (GenMemoryTest
);
394 UnicodeValueToString (StrTotalMemory
, COMMA_TYPE
, TotalMemorySize
, 0);
395 if (StrTotalMemory
[0] == L
',') {
399 TmpStr
= GetStringById (STRING_TOKEN (STR_MEM_TEST_COMPLETED
));
400 if (TmpStr
!= NULL
) {
401 StrCat (StrTotalMemory
, TmpStr
);
405 gST
->ConOut
->ClearScreen (gST
->ConOut
);
406 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_YELLOW
| EFI_BRIGHT
);
407 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
408 gST
->ConOut
->OutputString (gST
->ConOut
, StrTotalMemory
);
409 PlatformBdsShowProgress (
415 (UINTN
) PreviousValue
420 DataSize
= sizeof (Value
);
421 Status
= gRT
->GetVariable (
429 if (EFI_ERROR (Status
)) {
434 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,