3 Copyright (c) 2006, 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 UGA 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
)) {
83 GraphicsOutput
= NULL
;
85 Status
= gBS
->HandleProtocol (
86 gST
->ConsoleOutHandle
,
87 &gEfiUgaDrawProtocolGuid
,
90 if (EFI_ERROR (Status
)) {
91 return EFI_UNSUPPORTED
;
95 if (GraphicsOutput
!= NULL
) {
96 SizeOfX
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
97 SizeOfY
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
99 Status
= UgaDraw
->GetMode (
106 if (EFI_ERROR (Status
)) {
107 return EFI_UNSUPPORTED
;
111 BlockWidth
= SizeOfX
/ 100;
112 BlockHeight
= SizeOfY
/ 50;
117 PosY
= SizeOfY
* 48 / 50;
121 // Clear progress area
123 SetMem (&Color
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
125 if (GraphicsOutput
!= NULL
) {
126 Status
= GraphicsOutput
->Blt (
133 PosY
- GLYPH_HEIGHT
- 1,
135 SizeOfY
- (PosY
- GLYPH_HEIGHT
- 1),
136 SizeOfX
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
139 Status
= UgaDraw
->Blt (
141 (EFI_UGA_PIXEL
*) &Color
,
146 PosY
- GLYPH_HEIGHT
- 1,
148 SizeOfY
- (PosY
- GLYPH_HEIGHT
- 1),
149 SizeOfX
* sizeof (EFI_UGA_PIXEL
)
154 // Show progress by drawing blocks
156 for (Index
= PreviousValue
; Index
< BlockNum
; Index
++) {
157 PosX
= Index
* BlockWidth
;
158 if (GraphicsOutput
!= NULL
) {
159 Status
= GraphicsOutput
->Blt (
169 (BlockWidth
) * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
172 Status
= UgaDraw
->Blt (
174 (EFI_UGA_PIXEL
*) &ProgressColor
,
182 (BlockWidth
) * sizeof (EFI_UGA_PIXEL
)
188 (SizeOfX
- StrLen (Title
) * GLYPH_WIDTH
) / 2,
189 PosY
- GLYPH_HEIGHT
- 1,
200 IN EXTENDMEM_COVERAGE_LEVEL Level
206 Perform the memory test base on the memory test intensive level,
207 and update the memory resource.
211 Level - The memory test intensive level.
215 EFI_STATUS - Success test all the system memory and update
221 EFI_STATUS InitStatus
;
222 EFI_STATUS KeyStatus
;
223 EFI_STATUS ReturnStatus
;
224 BOOLEAN RequireSoftECCInit
;
225 EFI_GENERIC_MEMORY_TEST_PROTOCOL
*GenMemoryTest
;
226 UINT64 TestedMemorySize
;
227 UINT64 TotalMemorySize
;
229 UINT64 PreviousValue
;
233 CHAR16 StrPercent
[16];
234 CHAR16
*StrTotalMemory
;
237 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
238 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
239 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
243 ReturnStatus
= EFI_SUCCESS
;
244 ZeroMem (&Key
, sizeof (EFI_INPUT_KEY
));
246 Pos
= AllocatePool (128);
252 StrTotalMemory
= Pos
;
254 TestedMemorySize
= 0;
260 SetMem (&Foreground
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
261 SetMem (&Background
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
262 SetMem (&Color
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
264 RequireSoftECCInit
= FALSE
;
266 gST
->ConOut
->ClearScreen (gST
->ConOut
);
267 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_YELLOW
| EFI_BRIGHT
);
268 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
270 Status
= gBS
->LocateProtocol (
271 &gEfiGenericMemTestProtocolGuid
,
273 (VOID
**)&GenMemoryTest
275 if (EFI_ERROR (Status
)) {
280 InitStatus
= GenMemoryTest
->MemoryTestInit (
285 if (InitStatus
== EFI_NO_MEDIA
) {
287 // The PEI codes also have the relevant memory test code to check the memory,
288 // it can select to test some range of the memory or all of them. If PEI code
289 // checks all the memory, this BDS memory test will has no not-test memory to
290 // do the test, and then the status of EFI_NO_MEDIA will be returned by
291 // "MemoryTestInit". So it does not need to test memory again, just return.
297 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, 2);
298 TmpStr
= GetStringById (STRING_TOKEN (STR_ESC_TO_SKIP_MEM_TEST
));
300 if (TmpStr
!= NULL
) {
301 gST
->ConOut
->OutputString (gST
->ConOut
, TmpStr
);
302 gBS
->FreePool (TmpStr
);
306 Status
= GenMemoryTest
->PerformMemoryTest (
313 if (ErrorOut
&& (Status
== EFI_DEVICE_ERROR
)) {
314 TmpStr
= GetStringById (STRING_TOKEN (STR_SYSTEM_MEM_ERROR
));
315 if (TmpStr
!= NULL
) {
316 PrintXY (10, 10, NULL
, NULL
, TmpStr
);
317 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, 4);
318 gST
->ConOut
->OutputString (gST
->ConOut
, TmpStr
);
319 gBS
->FreePool (TmpStr
);
325 TestPercent
= (UINTN
) DivU64x32 (
326 DivU64x32 (MultU64x32 (TestedMemorySize
, 100), 16),
327 (UINTN
)DivU64x32 (TotalMemorySize
, 16)
329 if (TestPercent
!= PreviousValue
) {
330 UnicodeValueToString (StrPercent
, 0, TestPercent
, 0);
331 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, 0);
332 TmpStr
= GetStringById (STRING_TOKEN (STR_MEMORY_TEST_PERCENT
));
333 if (TmpStr
!= NULL
) {
334 BdsLibOutputStrings (gST
->ConOut
, StrPercent
, TmpStr
, NULL
);
335 gBS
->FreePool (TmpStr
);
338 TmpStr
= GetStringById (STRING_TOKEN (STR_PERFORM_MEM_TEST
));
339 if (TmpStr
!= NULL
) {
340 PlatformBdsShowProgress (
346 (UINTN
) PreviousValue
348 gBS
->FreePool (TmpStr
);
352 PreviousValue
= TestPercent
;
354 KeyStatus
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
355 if (Key
.ScanCode
== SCAN_ESC
) {
356 if (!RequireSoftECCInit
) {
357 TmpStr
= GetStringById (STRING_TOKEN (STR_PERFORM_MEM_TEST
));
358 if (TmpStr
!= NULL
) {
359 PlatformBdsShowProgress (
365 (UINTN
) PreviousValue
367 gBS
->FreePool (TmpStr
);
370 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, 0);
371 gST
->ConOut
->OutputString (gST
->ConOut
, L
"100");
372 Status
= GenMemoryTest
->Finished (GenMemoryTest
);
378 } while (Status
!= EFI_NOT_FOUND
);
380 Status
= GenMemoryTest
->Finished (GenMemoryTest
);
383 UnicodeValueToString (StrTotalMemory
, COMMA_TYPE
, (UINTN
) TotalMemorySize
, 0);
384 if (StrTotalMemory
[0] == L
',') {
388 TmpStr
= GetStringById (STRING_TOKEN (STR_MEM_TEST_COMPLETED
));
389 if (TmpStr
!= NULL
) {
390 StrCat (StrTotalMemory
, TmpStr
);
391 gBS
->FreePool (TmpStr
);
394 gST
->ConOut
->ClearScreen (gST
->ConOut
);
395 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_YELLOW
| EFI_BRIGHT
);
396 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
397 gST
->ConOut
->OutputString (gST
->ConOut
, StrTotalMemory
);
398 PlatformBdsShowProgress (
404 (UINTN
) PreviousValue
409 DataSize
= sizeof (Value
);
410 Status
= gRT
->GetVariable (
418 if (EFI_ERROR (Status
)) {
423 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,