3 Copyright (c) 2006 - 2007, 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"
24 #include "BdsString.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
;
62 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
71 return EFI_INVALID_PARAMETER
;
74 Status
= gBS
->HandleProtocol (
75 gST
->ConsoleOutHandle
,
76 &gEfiGraphicsOutputProtocolGuid
,
79 if (EFI_ERROR (Status
)) {
80 return EFI_UNSUPPORTED
;
83 SizeOfX
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
84 SizeOfY
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
86 BlockWidth
= SizeOfX
/ 100;
87 BlockHeight
= SizeOfY
/ 50;
92 PosY
= SizeOfY
* 48 / 50;
96 // Clear progress area
98 SetMem (&Color
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
100 Status
= GraphicsOutput
->Blt (
107 PosY
- GLYPH_HEIGHT
- 1,
109 SizeOfY
- (PosY
- GLYPH_HEIGHT
- 1),
110 SizeOfX
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
114 // Show progress by drawing blocks
116 for (Index
= PreviousValue
; Index
< BlockNum
; Index
++) {
117 PosX
= Index
* BlockWidth
;
118 Status
= GraphicsOutput
->Blt (
128 (BlockWidth
) * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
133 (SizeOfX
- StrLen (Title
) * GLYPH_WIDTH
) / 2,
134 PosY
- GLYPH_HEIGHT
- 1,
145 IN EXTENDMEM_COVERAGE_LEVEL Level
151 Perform the memory test base on the memory test intensive level,
152 and update the memory resource.
156 Level - The memory test intensive level.
160 EFI_STATUS - Success test all the system memory and update
166 EFI_STATUS InitStatus
;
167 EFI_STATUS KeyStatus
;
168 EFI_STATUS ReturnStatus
;
169 BOOLEAN RequireSoftECCInit
;
170 EFI_GENERIC_MEMORY_TEST_PROTOCOL
*GenMemoryTest
;
171 UINT64 TestedMemorySize
;
172 UINT64 TotalMemorySize
;
174 UINT64 PreviousValue
;
178 CHAR16 StrPercent
[16];
179 CHAR16
*StrTotalMemory
;
182 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
183 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
184 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
188 ReturnStatus
= EFI_SUCCESS
;
189 ZeroMem (&Key
, sizeof (EFI_INPUT_KEY
));
191 Pos
= AllocatePool (128);
197 StrTotalMemory
= Pos
;
199 TestedMemorySize
= 0;
205 SetMem (&Foreground
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
206 SetMem (&Background
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
207 SetMem (&Color
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
209 RequireSoftECCInit
= FALSE
;
211 gST
->ConOut
->ClearScreen (gST
->ConOut
);
212 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_YELLOW
| EFI_BRIGHT
);
213 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
215 Status
= gBS
->LocateProtocol (
216 &gEfiGenericMemTestProtocolGuid
,
220 if (EFI_ERROR (Status
)) {
225 InitStatus
= GenMemoryTest
->MemoryTestInit (
230 if (InitStatus
== EFI_NO_MEDIA
) {
232 // The PEI codes also have the relevant memory test code to check the memory,
233 // it can select to test some range of the memory or all of them. If PEI code
234 // checks all the memory, this BDS memory test will has no not-test memory to
235 // do the test, and then the status of EFI_NO_MEDIA will be returned by
236 // "MemoryTestInit". So it does not need to test memory again, just return.
242 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, 2);
243 TmpStr
= GetStringById (STRING_TOKEN (STR_ESC_TO_SKIP_MEM_TEST
));
245 if (TmpStr
!= NULL
) {
246 gST
->ConOut
->OutputString (gST
->ConOut
, TmpStr
);
251 Status
= GenMemoryTest
->PerformMemoryTest (
258 if (ErrorOut
&& (Status
== EFI_DEVICE_ERROR
)) {
259 TmpStr
= GetStringById (STRING_TOKEN (STR_SYSTEM_MEM_ERROR
));
260 if (TmpStr
!= NULL
) {
261 PrintXY (10, 10, NULL
, NULL
, TmpStr
);
262 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, 4);
263 gST
->ConOut
->OutputString (gST
->ConOut
, TmpStr
);
270 TestPercent
= (UINTN
) DivU64x32 (
271 DivU64x32 (MultU64x32 (TestedMemorySize
, 100), 16),
272 (UINTN
)DivU64x32 (TotalMemorySize
, 16)
274 if (TestPercent
!= PreviousValue
) {
275 UnicodeValueToString (StrPercent
, 0, TestPercent
, 0);
276 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, 0);
277 TmpStr
= GetStringById (STRING_TOKEN (STR_MEMORY_TEST_PERCENT
));
278 if (TmpStr
!= NULL
) {
279 BdsLibOutputStrings (gST
->ConOut
, StrPercent
, TmpStr
, NULL
);
283 TmpStr
= GetStringById (STRING_TOKEN (STR_PERFORM_MEM_TEST
));
284 if (TmpStr
!= NULL
) {
285 PlatformBdsShowProgress (
291 (UINTN
) PreviousValue
297 PreviousValue
= TestPercent
;
299 KeyStatus
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
300 if (Key
.ScanCode
== SCAN_ESC
) {
301 if (!RequireSoftECCInit
) {
302 TmpStr
= GetStringById (STRING_TOKEN (STR_PERFORM_MEM_TEST
));
303 if (TmpStr
!= NULL
) {
304 PlatformBdsShowProgress (
310 (UINTN
) PreviousValue
315 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, 0);
316 gST
->ConOut
->OutputString (gST
->ConOut
, L
"100");
317 Status
= GenMemoryTest
->Finished (GenMemoryTest
);
323 } while (Status
!= EFI_NOT_FOUND
);
325 Status
= GenMemoryTest
->Finished (GenMemoryTest
);
328 UnicodeValueToString (StrTotalMemory
, COMMA_TYPE
, (UINTN
) TotalMemorySize
, 0);
329 if (StrTotalMemory
[0] == L
',') {
333 TmpStr
= GetStringById (STRING_TOKEN (STR_MEM_TEST_COMPLETED
));
334 if (TmpStr
!= NULL
) {
335 StrCat (StrTotalMemory
, TmpStr
);
339 gST
->ConOut
->ClearScreen (gST
->ConOut
);
340 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_YELLOW
| EFI_BRIGHT
);
341 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
342 gST
->ConOut
->OutputString (gST
->ConOut
, StrTotalMemory
);
343 PlatformBdsShowProgress (
349 (UINTN
) PreviousValue
354 DataSize
= sizeof (Value
);
355 Status
= gRT
->GetVariable (
363 if (EFI_ERROR (Status
)) {
368 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,