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
)
158 // Show progress by drawing blocks
160 for (Index
= PreviousValue
; Index
< BlockNum
; Index
++) {
161 PosX
= Index
* BlockWidth
;
162 if (GraphicsOutput
!= NULL
) {
163 Status
= GraphicsOutput
->Blt (
173 (BlockWidth
) * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
175 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
176 Status
= UgaDraw
->Blt (
178 (EFI_UGA_PIXEL
*) &ProgressColor
,
186 (BlockWidth
) * sizeof (EFI_UGA_PIXEL
)
192 (SizeOfX
- StrLen (Title
) * GLYPH_WIDTH
) / 2,
193 PosY
- GLYPH_HEIGHT
- 1,
204 IN EXTENDMEM_COVERAGE_LEVEL Level
210 Perform the memory test base on the memory test intensive level,
211 and update the memory resource.
215 Level - The memory test intensive level.
219 EFI_STATUS - Success test all the system memory and update
225 EFI_STATUS KeyStatus
;
226 EFI_STATUS InitStatus
;
227 EFI_STATUS ReturnStatus
;
228 BOOLEAN RequireSoftECCInit
;
229 EFI_GENERIC_MEMORY_TEST_PROTOCOL
*GenMemoryTest
;
230 UINT64 TestedMemorySize
;
231 UINT64 TotalMemorySize
;
233 UINT64 PreviousValue
;
237 CHAR16 StrPercent
[16];
238 CHAR16
*StrTotalMemory
;
241 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
242 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
243 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
249 ReturnStatus
= EFI_SUCCESS
;
250 ZeroMem (&Key
, sizeof (EFI_INPUT_KEY
));
252 Pos
= AllocatePool (128);
258 StrTotalMemory
= Pos
;
260 TestedMemorySize
= 0;
266 SetMem (&Foreground
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
267 SetMem (&Background
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
268 SetMem (&Color
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
270 RequireSoftECCInit
= FALSE
;
272 gST
->ConOut
->ClearScreen (gST
->ConOut
);
273 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_YELLOW
| EFI_BRIGHT
);
274 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
276 Status
= gBS
->LocateProtocol (
277 &gEfiGenericMemTestProtocolGuid
,
279 (VOID
**) &GenMemoryTest
281 if (EFI_ERROR (Status
)) {
286 InitStatus
= GenMemoryTest
->MemoryTestInit (
291 if (InitStatus
== EFI_NO_MEDIA
) {
293 // The PEI codes also have the relevant memory test code to check the memory,
294 // it can select to test some range of the memory or all of them. If PEI code
295 // checks all the memory, this BDS memory test will has no not-test memory to
296 // do the test, and then the status of EFI_NO_MEDIA will be returned by
297 // "MemoryTestInit". So it does not need to test memory again, just return.
303 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, 2);
304 TmpStr
= GetStringById (STRING_TOKEN (STR_ESC_TO_SKIP_MEM_TEST
));
306 if (TmpStr
!= NULL
) {
307 gST
->ConOut
->OutputString (gST
->ConOut
, TmpStr
);
312 Status
= GenMemoryTest
->PerformMemoryTest (
319 if (ErrorOut
&& (Status
== EFI_DEVICE_ERROR
)) {
320 TmpStr
= GetStringById (STRING_TOKEN (STR_SYSTEM_MEM_ERROR
));
321 if (TmpStr
!= NULL
) {
322 PrintXY (10, 10, NULL
, NULL
, TmpStr
);
323 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, 4);
324 gST
->ConOut
->OutputString (gST
->ConOut
, TmpStr
);
331 TempData
= (UINT32
) DivU64x32 (TotalMemorySize
, 16);
332 TestPercent
= (UINTN
) DivU64x32 (
333 DivU64x32 (MultU64x32 (TestedMemorySize
, 100), 16),
336 if (TestPercent
!= PreviousValue
) {
337 UnicodeValueToString (StrPercent
, 0, TestPercent
, 0);
338 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, 0);
339 TmpStr
= GetStringById (STRING_TOKEN (STR_MEMORY_TEST_PERCENT
));
340 if (TmpStr
!= NULL
) {
341 BdsLibOutputStrings (gST
->ConOut
, StrPercent
, TmpStr
, NULL
);
345 TmpStr
= GetStringById (STRING_TOKEN (STR_PERFORM_MEM_TEST
));
346 if (TmpStr
!= NULL
) {
347 PlatformBdsShowProgress (
353 (UINTN
) PreviousValue
359 PreviousValue
= TestPercent
;
361 KeyStatus
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
362 if (!EFI_ERROR (KeyStatus
) && (Key
.ScanCode
== SCAN_ESC
)) {
363 if (!RequireSoftECCInit
) {
364 TmpStr
= GetStringById (STRING_TOKEN (STR_PERFORM_MEM_TEST
));
365 if (TmpStr
!= NULL
) {
366 PlatformBdsShowProgress (
372 (UINTN
) PreviousValue
377 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, 0);
378 gST
->ConOut
->OutputString (gST
->ConOut
, L
"100");
379 Status
= GenMemoryTest
->Finished (GenMemoryTest
);
385 } while (Status
!= EFI_NOT_FOUND
);
387 Status
= GenMemoryTest
->Finished (GenMemoryTest
);
390 UnicodeValueToString (StrTotalMemory
, COMMA_TYPE
, TotalMemorySize
, 0);
391 if (StrTotalMemory
[0] == L
',') {
395 TmpStr
= GetStringById (STRING_TOKEN (STR_MEM_TEST_COMPLETED
));
396 if (TmpStr
!= NULL
) {
397 StrCat (StrTotalMemory
, TmpStr
);
401 gST
->ConOut
->ClearScreen (gST
->ConOut
);
402 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_YELLOW
| EFI_BRIGHT
);
403 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
404 gST
->ConOut
->OutputString (gST
->ConOut
, StrTotalMemory
);
405 PlatformBdsShowProgress (
411 (UINTN
) PreviousValue
416 DataSize
= sizeof (Value
);
417 Status
= gRT
->GetVariable (
425 if (EFI_ERROR (Status
)) {
430 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,