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
23 #include "BdsPlatform.h"
27 // BDS Platform Functions
30 PlatformBdsShowProgress (
31 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleForeground
,
32 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleBackground
,
34 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL ProgressColor
,
36 IN UINTN PreviousValue
42 Show progress bar with title above it. It only works in UGA mode.
46 TitleForeground - Foreground color for Title.
47 TitleBackground - Background color for Title.
48 Title - Title above progress bar.
49 ProgressColor - Progress bar color.
50 Progress - Progress (0-100)
54 EFI_STATUS - Success update the progress bar
59 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
60 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
65 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
74 return EFI_INVALID_PARAMETER
;
78 Status
= gBS
->HandleProtocol (
79 gST
->ConsoleOutHandle
,
80 &gEfiGraphicsOutputProtocolGuid
,
83 if (EFI_ERROR (Status
)) {
84 GraphicsOutput
= NULL
;
86 Status
= gBS
->HandleProtocol (
87 gST
->ConsoleOutHandle
,
88 &gEfiUgaDrawProtocolGuid
,
91 if (EFI_ERROR (Status
)) {
92 return EFI_UNSUPPORTED
;
96 if (GraphicsOutput
!= NULL
) {
97 SizeOfX
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
98 SizeOfY
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
100 Status
= UgaDraw
->GetMode (
107 if (EFI_ERROR (Status
)) {
108 return EFI_UNSUPPORTED
;
112 BlockWidth
= SizeOfX
/ 100;
113 BlockHeight
= SizeOfY
/ 50;
118 PosY
= SizeOfY
* 48 / 50;
122 // Clear progress area
124 SetMem (&Color
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
126 if (GraphicsOutput
!= NULL
) {
127 Status
= GraphicsOutput
->Blt (
134 PosY
- GLYPH_HEIGHT
- 1,
136 SizeOfY
- (PosY
- GLYPH_HEIGHT
- 1),
137 SizeOfX
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
140 Status
= UgaDraw
->Blt (
142 (EFI_UGA_PIXEL
*) &Color
,
147 PosY
- GLYPH_HEIGHT
- 1,
149 SizeOfY
- (PosY
- GLYPH_HEIGHT
- 1),
150 SizeOfX
* sizeof (EFI_UGA_PIXEL
)
155 // Show progress by drawing blocks
157 for (Index
= PreviousValue
; Index
< BlockNum
; Index
++) {
158 PosX
= Index
* BlockWidth
;
159 if (GraphicsOutput
!= NULL
) {
160 Status
= GraphicsOutput
->Blt (
170 (BlockWidth
) * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
173 Status
= UgaDraw
->Blt (
175 (EFI_UGA_PIXEL
*) &ProgressColor
,
183 (BlockWidth
) * sizeof (EFI_UGA_PIXEL
)
189 (SizeOfX
- StrLen (Title
) * GLYPH_WIDTH
) / 2,
190 PosY
- 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 InitStatus
;
223 EFI_STATUS KeyStatus
;
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
;
245 ReturnStatus
= EFI_SUCCESS
;
246 ZeroMem (&Key
, sizeof (EFI_INPUT_KEY
));
248 Pos
= AllocatePool (128);
254 StrTotalMemory
= Pos
;
256 TestedMemorySize
= 0;
262 SetMem (&Foreground
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
263 SetMem (&Background
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
264 SetMem (&Color
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
266 RequireSoftECCInit
= FALSE
;
268 gST
->ConOut
->ClearScreen (gST
->ConOut
);
269 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_YELLOW
| EFI_BRIGHT
);
270 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
272 Status
= gBS
->LocateProtocol (
273 &gEfiGenericMemTestProtocolGuid
,
277 if (EFI_ERROR (Status
)) {
282 InitStatus
= GenMemoryTest
->MemoryTestInit (
287 if (InitStatus
== EFI_NO_MEDIA
) {
289 // The PEI codes also have the relevant memory test code to check the memory,
290 // it can select to test some range of the memory or all of them. If PEI code
291 // checks all the memory, this BDS memory test will has no not-test memory to
292 // do the test, and then the status of EFI_NO_MEDIA will be returned by
293 // "MemoryTestInit". So it does not need to test memory again, just return.
299 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, 2);
300 TmpStr
= GetStringById (STRING_TOKEN (STR_ESC_TO_SKIP_MEM_TEST
));
302 if (TmpStr
!= NULL
) {
303 gST
->ConOut
->OutputString (gST
->ConOut
, TmpStr
);
304 gBS
->FreePool (TmpStr
);
308 Status
= GenMemoryTest
->PerformMemoryTest (
315 if (ErrorOut
&& (Status
== EFI_DEVICE_ERROR
)) {
316 TmpStr
= GetStringById (STRING_TOKEN (STR_SYSTEM_MEM_ERROR
));
317 if (TmpStr
!= NULL
) {
318 PrintXY (10, 10, NULL
, NULL
, TmpStr
);
319 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, 4);
320 gST
->ConOut
->OutputString (gST
->ConOut
, TmpStr
);
321 gBS
->FreePool (TmpStr
);
327 TestPercent
= (UINTN
) DivU64x32 (
328 DivU64x32 (MultU64x32 (TestedMemorySize
, 100), 16),
329 (UINTN
)DivU64x32 (TotalMemorySize
, 16)
331 if (TestPercent
!= PreviousValue
) {
332 UnicodeValueToString (StrPercent
, 0, TestPercent
, 0);
333 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, 0);
334 TmpStr
= GetStringById (STRING_TOKEN (STR_MEMORY_TEST_PERCENT
));
335 if (TmpStr
!= NULL
) {
336 BdsLibOutputStrings (gST
->ConOut
, StrPercent
, TmpStr
, NULL
);
337 gBS
->FreePool (TmpStr
);
340 TmpStr
= GetStringById (STRING_TOKEN (STR_PERFORM_MEM_TEST
));
341 if (TmpStr
!= NULL
) {
342 PlatformBdsShowProgress (
348 (UINTN
) PreviousValue
350 gBS
->FreePool (TmpStr
);
354 PreviousValue
= TestPercent
;
356 KeyStatus
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
357 if (Key
.ScanCode
== SCAN_ESC
) {
358 if (!RequireSoftECCInit
) {
359 TmpStr
= GetStringById (STRING_TOKEN (STR_PERFORM_MEM_TEST
));
360 if (TmpStr
!= NULL
) {
361 PlatformBdsShowProgress (
367 (UINTN
) PreviousValue
369 gBS
->FreePool (TmpStr
);
372 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, 0);
373 gST
->ConOut
->OutputString (gST
->ConOut
, L
"100");
374 Status
= GenMemoryTest
->Finished (GenMemoryTest
);
380 } while (Status
!= EFI_NOT_FOUND
);
382 Status
= GenMemoryTest
->Finished (GenMemoryTest
);
385 UnicodeValueToString (StrTotalMemory
, COMMA_TYPE
, (UINTN
) TotalMemorySize
, 0);
386 if (StrTotalMemory
[0] == L
',') {
390 TmpStr
= GetStringById (STRING_TOKEN (STR_MEM_TEST_COMPLETED
));
391 if (TmpStr
!= NULL
) {
392 StrCat (StrTotalMemory
, TmpStr
);
393 gBS
->FreePool (TmpStr
);
396 gST
->ConOut
->ClearScreen (gST
->ConOut
);
397 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_YELLOW
| EFI_BRIGHT
);
398 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
399 gST
->ConOut
->OutputString (gST
->ConOut
, StrTotalMemory
);
400 PlatformBdsShowProgress (
406 (UINTN
) PreviousValue
411 DataSize
= sizeof (Value
);
412 Status
= gRT
->GetVariable (
420 if (EFI_ERROR (Status
)) {
425 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,