]>
Commit | Line | Data |
---|---|---|
bc11b829 | 1 | /*++\r |
2 | \r | |
3 | Copyright (c) 2006 - 2007, Intel Corporation\r | |
4 | All rights reserved. This program and the accompanying materials\r | |
5 | are licensed and made available under the terms and conditions of the BSD License\r | |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | \r | |
12 | Module Name:\r | |
13 | \r | |
14 | MemoryTest.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | Perform the platform memory test\r | |
19 | \r | |
20 | --*/\r | |
21 | \r | |
bc11b829 | 22 | #include "bds.h"\r |
23 | #include "BdsPlatform.h"\r | |
06335580 | 24 | #include "BdsString.h"\r |
bc11b829 | 25 | \r |
26 | //\r | |
27 | // BDS Platform Functions\r | |
28 | //\r | |
29 | EFI_STATUS\r | |
30 | PlatformBdsShowProgress (\r | |
31 | IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleForeground,\r | |
32 | IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleBackground,\r | |
33 | IN CHAR16 *Title,\r | |
34 | IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL ProgressColor,\r | |
35 | IN UINTN Progress,\r | |
36 | IN UINTN PreviousValue\r | |
37 | )\r | |
38 | /*++\r | |
39 | \r | |
40 | Routine Description:\r | |
41 | \r | |
42 | Show progress bar with title above it. It only works in UGA mode.\r | |
43 | \r | |
44 | Arguments:\r | |
45 | \r | |
46 | TitleForeground - Foreground color for Title.\r | |
47 | TitleBackground - Background color for Title.\r | |
48 | Title - Title above progress bar.\r | |
49 | ProgressColor - Progress bar color.\r | |
50 | Progress - Progress (0-100)\r | |
51 | \r | |
52 | Returns:\r | |
53 | \r | |
54 | EFI_STATUS - Success update the progress bar\r | |
55 | \r | |
56 | --*/\r | |
57 | {\r | |
454e9f65 | 58 | EFI_STATUS Status;\r |
bc11b829 | 59 | EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r |
454e9f65 | 60 | UINT32 SizeOfX;\r |
61 | UINT32 SizeOfY;\r | |
bc11b829 | 62 | EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color;\r |
454e9f65 | 63 | UINTN BlockHeight;\r |
64 | UINTN BlockWidth;\r | |
65 | UINTN BlockNum;\r | |
66 | UINTN PosX;\r | |
67 | UINTN PosY;\r | |
68 | UINTN Index;\r | |
bc11b829 | 69 | \r |
70 | if (Progress > 100) {\r | |
71 | return EFI_INVALID_PARAMETER;\r | |
72 | }\r | |
73 | \r | |
bc11b829 | 74 | Status = gBS->HandleProtocol (\r |
75 | gST->ConsoleOutHandle,\r | |
76 | &gEfiGraphicsOutputProtocolGuid,\r | |
77 | &GraphicsOutput\r | |
78 | );\r | |
79 | if (EFI_ERROR (Status)) {\r | |
454e9f65 | 80 | return EFI_UNSUPPORTED;\r |
bc11b829 | 81 | }\r |
82 | \r | |
454e9f65 | 83 | SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution;\r |
84 | SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution;\r | |
bc11b829 | 85 | \r |
86 | BlockWidth = SizeOfX / 100;\r | |
87 | BlockHeight = SizeOfY / 50;\r | |
88 | \r | |
89 | BlockNum = Progress;\r | |
90 | \r | |
91 | PosX = 0;\r | |
92 | PosY = SizeOfY * 48 / 50;\r | |
93 | \r | |
94 | if (BlockNum == 0) {\r | |
95 | //\r | |
96 | // Clear progress area\r | |
97 | //\r | |
98 | SetMem (&Color, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0x0);\r | |
99 | \r | |
454e9f65 | 100 | Status = GraphicsOutput->Blt (\r |
bc11b829 | 101 | GraphicsOutput,\r |
102 | &Color,\r | |
103 | EfiBltVideoFill,\r | |
104 | 0,\r | |
105 | 0,\r | |
106 | 0,\r | |
107 | PosY - GLYPH_HEIGHT - 1,\r | |
108 | SizeOfX,\r | |
109 | SizeOfY - (PosY - GLYPH_HEIGHT - 1),\r | |
110 | SizeOfX * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r | |
111 | );\r | |
bc11b829 | 112 | }\r |
113 | //\r | |
114 | // Show progress by drawing blocks\r | |
115 | //\r | |
116 | for (Index = PreviousValue; Index < BlockNum; Index++) {\r | |
117 | PosX = Index * BlockWidth;\r | |
454e9f65 | 118 | Status = GraphicsOutput->Blt (\r |
bc11b829 | 119 | GraphicsOutput,\r |
120 | &ProgressColor,\r | |
121 | EfiBltVideoFill,\r | |
122 | 0,\r | |
123 | 0,\r | |
124 | PosX,\r | |
125 | PosY,\r | |
126 | BlockWidth - 1,\r | |
127 | BlockHeight,\r | |
128 | (BlockWidth) * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r | |
129 | );\r | |
bc11b829 | 130 | }\r |
131 | \r | |
132 | PrintXY (\r | |
133 | (SizeOfX - StrLen (Title) * GLYPH_WIDTH) / 2,\r | |
134 | PosY - GLYPH_HEIGHT - 1,\r | |
135 | &TitleForeground,\r | |
136 | &TitleBackground,\r | |
137 | Title\r | |
138 | );\r | |
139 | \r | |
140 | return EFI_SUCCESS;\r | |
141 | }\r | |
142 | \r | |
143 | EFI_STATUS\r | |
144 | BdsMemoryTest (\r | |
145 | IN EXTENDMEM_COVERAGE_LEVEL Level\r | |
146 | )\r | |
147 | /*++\r | |
148 | \r | |
149 | Routine Description:\r | |
150 | \r | |
151 | Perform the memory test base on the memory test intensive level,\r | |
152 | and update the memory resource.\r | |
153 | \r | |
154 | Arguments:\r | |
155 | \r | |
156 | Level - The memory test intensive level.\r | |
157 | \r | |
158 | Returns:\r | |
159 | \r | |
160 | EFI_STATUS - Success test all the system memory and update\r | |
161 | the memory resource\r | |
162 | \r | |
163 | --*/\r | |
164 | {\r | |
165 | EFI_STATUS Status;\r | |
166 | EFI_STATUS InitStatus;\r | |
167 | EFI_STATUS KeyStatus;\r | |
168 | EFI_STATUS ReturnStatus;\r | |
169 | BOOLEAN RequireSoftECCInit;\r | |
170 | EFI_GENERIC_MEMORY_TEST_PROTOCOL *GenMemoryTest;\r | |
171 | UINT64 TestedMemorySize;\r | |
172 | UINT64 TotalMemorySize;\r | |
173 | UINTN TestPercent;\r | |
174 | UINT64 PreviousValue;\r | |
175 | BOOLEAN ErrorOut;\r | |
176 | BOOLEAN TestAbort;\r | |
177 | EFI_INPUT_KEY Key;\r | |
178 | CHAR16 StrPercent[16];\r | |
179 | CHAR16 *StrTotalMemory;\r | |
180 | CHAR16 *Pos;\r | |
181 | CHAR16 *TmpStr;\r | |
182 | EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;\r | |
183 | EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;\r | |
184 | EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color;\r | |
185 | UINT8 Value;\r | |
186 | UINTN DataSize;\r | |
187 | \r | |
188 | ReturnStatus = EFI_SUCCESS;\r | |
189 | ZeroMem (&Key, sizeof (EFI_INPUT_KEY));\r | |
190 | \r | |
191 | Pos = AllocatePool (128);\r | |
192 | \r | |
193 | if (Pos == NULL) {\r | |
194 | return ReturnStatus;\r | |
195 | }\r | |
196 | \r | |
197 | StrTotalMemory = Pos;\r | |
198 | \r | |
199 | TestedMemorySize = 0;\r | |
200 | TotalMemorySize = 0;\r | |
201 | PreviousValue = 0;\r | |
202 | ErrorOut = FALSE;\r | |
203 | TestAbort = FALSE;\r | |
204 | \r | |
205 | SetMem (&Foreground, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0xff);\r | |
206 | SetMem (&Background, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0x0);\r | |
207 | SetMem (&Color, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0xff);\r | |
208 | \r | |
209 | RequireSoftECCInit = FALSE;\r | |
210 | \r | |
211 | gST->ConOut->ClearScreen (gST->ConOut);\r | |
212 | gST->ConOut->SetAttribute (gST->ConOut, EFI_YELLOW | EFI_BRIGHT);\r | |
213 | gST->ConOut->EnableCursor (gST->ConOut, FALSE);\r | |
214 | \r | |
215 | Status = gBS->LocateProtocol (\r | |
216 | &gEfiGenericMemTestProtocolGuid,\r | |
217 | NULL,\r | |
218 | &GenMemoryTest\r | |
219 | );\r | |
220 | if (EFI_ERROR (Status)) {\r | |
221 | FreePool (Pos);\r | |
222 | return EFI_SUCCESS;\r | |
223 | }\r | |
224 | \r | |
225 | InitStatus = GenMemoryTest->MemoryTestInit (\r | |
226 | GenMemoryTest,\r | |
227 | Level,\r | |
228 | &RequireSoftECCInit\r | |
229 | );\r | |
230 | if (InitStatus == EFI_NO_MEDIA) {\r | |
231 | //\r | |
232 | // The PEI codes also have the relevant memory test code to check the memory,\r | |
233 | // it can select to test some range of the memory or all of them. If PEI code\r | |
234 | // checks all the memory, this BDS memory test will has no not-test memory to\r | |
235 | // do the test, and then the status of EFI_NO_MEDIA will be returned by\r | |
236 | // "MemoryTestInit". So it does not need to test memory again, just return.\r | |
237 | //\r | |
238 | FreePool (Pos);\r | |
239 | return EFI_SUCCESS;\r | |
240 | }\r | |
241 | \r | |
242 | gST->ConOut->SetCursorPosition (gST->ConOut, 0, 2);\r | |
243 | TmpStr = GetStringById (STRING_TOKEN (STR_ESC_TO_SKIP_MEM_TEST));\r | |
244 | \r | |
245 | if (TmpStr != NULL) {\r | |
246 | gST->ConOut->OutputString (gST->ConOut, TmpStr);\r | |
247 | FreePool (TmpStr);\r | |
248 | }\r | |
249 | \r | |
250 | do {\r | |
251 | Status = GenMemoryTest->PerformMemoryTest (\r | |
252 | GenMemoryTest,\r | |
253 | &TestedMemorySize,\r | |
254 | &TotalMemorySize,\r | |
255 | &ErrorOut,\r | |
256 | TestAbort\r | |
257 | );\r | |
258 | if (ErrorOut && (Status == EFI_DEVICE_ERROR)) {\r | |
259 | TmpStr = GetStringById (STRING_TOKEN (STR_SYSTEM_MEM_ERROR));\r | |
260 | if (TmpStr != NULL) {\r | |
261 | PrintXY (10, 10, NULL, NULL, TmpStr);\r | |
262 | gST->ConOut->SetCursorPosition (gST->ConOut, 0, 4);\r | |
263 | gST->ConOut->OutputString (gST->ConOut, TmpStr);\r | |
264 | FreePool (TmpStr);\r | |
265 | }\r | |
266 | \r | |
267 | ASSERT (0);\r | |
268 | }\r | |
269 | \r | |
270 | TestPercent = (UINTN) DivU64x32 (\r | |
271 | DivU64x32 (MultU64x32 (TestedMemorySize, 100), 16),\r | |
272 | (UINTN)DivU64x32 (TotalMemorySize, 16)\r | |
273 | );\r | |
274 | if (TestPercent != PreviousValue) {\r | |
275 | UnicodeValueToString (StrPercent, 0, TestPercent, 0);\r | |
276 | gST->ConOut->SetCursorPosition (gST->ConOut, 0, 0);\r | |
277 | TmpStr = GetStringById (STRING_TOKEN (STR_MEMORY_TEST_PERCENT));\r | |
278 | if (TmpStr != NULL) {\r | |
279 | BdsLibOutputStrings (gST->ConOut, StrPercent, TmpStr, NULL);\r | |
280 | FreePool (TmpStr);\r | |
281 | }\r | |
282 | \r | |
283 | TmpStr = GetStringById (STRING_TOKEN (STR_PERFORM_MEM_TEST));\r | |
284 | if (TmpStr != NULL) {\r | |
285 | PlatformBdsShowProgress (\r | |
286 | Foreground,\r | |
287 | Background,\r | |
288 | TmpStr,\r | |
289 | Color,\r | |
290 | TestPercent,\r | |
291 | (UINTN) PreviousValue\r | |
292 | );\r | |
293 | FreePool (TmpStr);\r | |
294 | }\r | |
295 | }\r | |
296 | \r | |
297 | PreviousValue = TestPercent;\r | |
298 | \r | |
299 | KeyStatus = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r | |
300 | if (Key.ScanCode == SCAN_ESC) {\r | |
301 | if (!RequireSoftECCInit) {\r | |
302 | TmpStr = GetStringById (STRING_TOKEN (STR_PERFORM_MEM_TEST));\r | |
303 | if (TmpStr != NULL) {\r | |
304 | PlatformBdsShowProgress (\r | |
305 | Foreground,\r | |
306 | Background,\r | |
307 | TmpStr,\r | |
308 | Color,\r | |
309 | 100,\r | |
310 | (UINTN) PreviousValue\r | |
311 | );\r | |
312 | FreePool (TmpStr);\r | |
313 | }\r | |
314 | \r | |
315 | gST->ConOut->SetCursorPosition (gST->ConOut, 0, 0);\r | |
316 | gST->ConOut->OutputString (gST->ConOut, L"100");\r | |
317 | Status = GenMemoryTest->Finished (GenMemoryTest);\r | |
318 | goto Done;\r | |
319 | }\r | |
320 | \r | |
321 | TestAbort = TRUE;\r | |
322 | }\r | |
323 | } while (Status != EFI_NOT_FOUND);\r | |
324 | \r | |
325 | Status = GenMemoryTest->Finished (GenMemoryTest);\r | |
326 | \r | |
327 | Done:\r | |
328 | UnicodeValueToString (StrTotalMemory, COMMA_TYPE, (UINTN) TotalMemorySize, 0);\r | |
329 | if (StrTotalMemory[0] == L',') {\r | |
330 | StrTotalMemory++;\r | |
331 | }\r | |
332 | \r | |
333 | TmpStr = GetStringById (STRING_TOKEN (STR_MEM_TEST_COMPLETED));\r | |
334 | if (TmpStr != NULL) {\r | |
335 | StrCat (StrTotalMemory, TmpStr);\r | |
336 | FreePool (TmpStr);\r | |
337 | }\r | |
338 | \r | |
339 | gST->ConOut->ClearScreen (gST->ConOut);\r | |
340 | gST->ConOut->SetAttribute (gST->ConOut, EFI_YELLOW | EFI_BRIGHT);\r | |
341 | gST->ConOut->EnableCursor (gST->ConOut, FALSE);\r | |
342 | gST->ConOut->OutputString (gST->ConOut, StrTotalMemory);\r | |
343 | PlatformBdsShowProgress (\r | |
344 | Foreground,\r | |
345 | Background,\r | |
346 | StrTotalMemory,\r | |
347 | Color,\r | |
348 | 100,\r | |
349 | (UINTN) PreviousValue\r | |
350 | );\r | |
351 | \r | |
352 | FreePool (Pos);\r | |
353 | \r | |
354 | DataSize = sizeof (Value);\r | |
355 | Status = gRT->GetVariable (\r | |
356 | L"BootState",\r | |
357 | &gEfiBootStateGuid,\r | |
358 | NULL,\r | |
359 | &DataSize,\r | |
360 | &Value\r | |
361 | );\r | |
362 | \r | |
363 | if (EFI_ERROR (Status)) {\r | |
364 | Value = 1;\r | |
365 | gRT->SetVariable (\r | |
366 | L"BootState",\r | |
367 | &gEfiBootStateGuid,\r | |
368 | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r | |
369 | sizeof (Value),\r | |
370 | &Value\r | |
371 | );\r | |
372 | }\r | |
373 | \r | |
374 | return ReturnStatus;\r | |
375 | }\r |