]>
Commit | Line | Data |
---|---|---|
703da8b4 RN |
1 | /** @file\r |
2 | Perform the platform memory test\r | |
3 | \r | |
de66e154 | 4 | Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>\r |
703da8b4 RN |
5 | This program and the accompanying materials\r |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "PlatformBootManager.h"\r | |
16 | \r | |
17 | EFI_HII_HANDLE gStringPackHandle = NULL;\r | |
18 | EFI_GUID mPlatformBootManagerStringPackGuid = {\r | |
19 | 0x154dd51, 0x9079, 0x4a10, { 0x89, 0x5c, 0x9c, 0x7, 0x72, 0x81, 0x57, 0x88 }\r | |
20 | };\r | |
21 | // extern UINT8 BdsDxeStrings[];\r | |
22 | \r | |
23 | //\r | |
24 | // BDS Platform Functions\r | |
25 | //\r | |
703da8b4 RN |
26 | \r |
27 | /**\r | |
28 | Perform the memory test base on the memory test intensive level,\r | |
29 | and update the memory resource.\r | |
30 | \r | |
31 | @param Level The memory test intensive level.\r | |
32 | \r | |
33 | @retval EFI_STATUS Success test all the system memory and update\r | |
34 | the memory resource\r | |
35 | \r | |
36 | **/\r | |
37 | EFI_STATUS\r | |
38 | PlatformBootManagerMemoryTest (\r | |
39 | IN EXTENDMEM_COVERAGE_LEVEL Level\r | |
40 | )\r | |
41 | {\r | |
42 | EFI_STATUS Status;\r | |
43 | EFI_STATUS KeyStatus;\r | |
44 | EFI_STATUS InitStatus;\r | |
45 | EFI_STATUS ReturnStatus;\r | |
46 | BOOLEAN RequireSoftECCInit;\r | |
47 | EFI_GENERIC_MEMORY_TEST_PROTOCOL *GenMemoryTest;\r | |
48 | UINT64 TestedMemorySize;\r | |
49 | UINT64 TotalMemorySize;\r | |
50 | UINTN TestPercent;\r | |
51 | UINT64 PreviousValue;\r | |
52 | BOOLEAN ErrorOut;\r | |
53 | BOOLEAN TestAbort;\r | |
54 | EFI_INPUT_KEY Key;\r | |
55 | CHAR16 StrPercent[80];\r | |
56 | CHAR16 *StrTotalMemory;\r | |
57 | CHAR16 *Pos;\r | |
58 | CHAR16 *TmpStr;\r | |
59 | EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;\r | |
60 | EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;\r | |
61 | EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color;\r | |
62 | UINT32 TempData;\r | |
63 | UINTN StrTotalMemorySize;\r | |
64 | \r | |
65 | ReturnStatus = EFI_SUCCESS;\r | |
66 | ZeroMem (&Key, sizeof (EFI_INPUT_KEY));\r | |
67 | \r | |
68 | StrTotalMemorySize = 128;\r | |
69 | Pos = AllocateZeroPool (StrTotalMemorySize);\r | |
70 | ASSERT (Pos != NULL);\r | |
71 | \r | |
72 | if (gStringPackHandle == NULL) { \r | |
73 | gStringPackHandle = HiiAddPackages (\r | |
74 | &mPlatformBootManagerStringPackGuid,\r | |
75 | gImageHandle,\r | |
76 | PlatformBootManagerLibStrings,\r | |
77 | NULL\r | |
78 | );\r | |
79 | ASSERT (gStringPackHandle != NULL);\r | |
80 | }\r | |
81 | \r | |
82 | StrTotalMemory = Pos;\r | |
83 | \r | |
84 | TestedMemorySize = 0;\r | |
85 | TotalMemorySize = 0;\r | |
86 | PreviousValue = 0;\r | |
87 | ErrorOut = FALSE;\r | |
88 | TestAbort = FALSE;\r | |
89 | \r | |
90 | SetMem (&Foreground, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0xff);\r | |
91 | SetMem (&Background, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0x0);\r | |
92 | SetMem (&Color, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0xff);\r | |
93 | \r | |
94 | RequireSoftECCInit = FALSE;\r | |
95 | \r | |
96 | Status = gBS->LocateProtocol (\r | |
97 | &gEfiGenericMemTestProtocolGuid,\r | |
98 | NULL,\r | |
99 | (VOID **) &GenMemoryTest\r | |
100 | );\r | |
101 | if (EFI_ERROR (Status)) {\r | |
102 | FreePool (Pos);\r | |
103 | return EFI_SUCCESS;\r | |
104 | }\r | |
105 | \r | |
106 | InitStatus = GenMemoryTest->MemoryTestInit (\r | |
107 | GenMemoryTest,\r | |
108 | Level,\r | |
109 | &RequireSoftECCInit\r | |
110 | );\r | |
111 | if (InitStatus == EFI_NO_MEDIA) {\r | |
112 | //\r | |
113 | // The PEI codes also have the relevant memory test code to check the memory,\r | |
114 | // it can select to test some range of the memory or all of them. If PEI code\r | |
115 | // checks all the memory, this BDS memory test will has no not-test memory to\r | |
116 | // do the test, and then the status of EFI_NO_MEDIA will be returned by\r | |
117 | // "MemoryTestInit". So it does not need to test memory again, just return.\r | |
118 | //\r | |
119 | FreePool (Pos);\r | |
120 | return EFI_SUCCESS;\r | |
121 | }\r | |
122 | \r | |
123 | if (!FeaturePcdGet(PcdBootlogoOnlyEnable)) {\r | |
124 | TmpStr = HiiGetString (gStringPackHandle, STRING_TOKEN (STR_ESC_TO_SKIP_MEM_TEST), NULL);\r | |
125 | \r | |
126 | if (TmpStr != NULL) {\r | |
127 | PrintXY (10, 10, NULL, NULL, TmpStr);\r | |
128 | FreePool (TmpStr);\r | |
129 | }\r | |
130 | } else {\r | |
131 | DEBUG ((EFI_D_INFO, "Enter memory test.\n"));\r | |
132 | }\r | |
133 | do {\r | |
134 | Status = GenMemoryTest->PerformMemoryTest (\r | |
135 | GenMemoryTest,\r | |
136 | &TestedMemorySize,\r | |
137 | &TotalMemorySize,\r | |
138 | &ErrorOut,\r | |
139 | TestAbort\r | |
140 | );\r | |
141 | if (ErrorOut && (Status == EFI_DEVICE_ERROR)) {\r | |
142 | TmpStr = HiiGetString (gStringPackHandle, STRING_TOKEN (STR_SYSTEM_MEM_ERROR), NULL);\r | |
143 | if (TmpStr != NULL) {\r | |
144 | PrintXY (10, 10, NULL, NULL, TmpStr);\r | |
145 | FreePool (TmpStr);\r | |
146 | }\r | |
147 | \r | |
148 | ASSERT (0);\r | |
149 | }\r | |
150 | \r | |
151 | if (!FeaturePcdGet(PcdBootlogoOnlyEnable)) {\r | |
152 | TempData = (UINT32) DivU64x32 (TotalMemorySize, 16);\r | |
153 | TestPercent = (UINTN) DivU64x32 (\r | |
154 | DivU64x32 (MultU64x32 (TestedMemorySize, 100), 16),\r | |
155 | TempData\r | |
156 | );\r | |
157 | if (TestPercent != PreviousValue) {\r | |
de66e154 | 158 | UnicodeValueToStringS (StrPercent, sizeof (StrPercent), 0, TestPercent, 0);\r |
703da8b4 RN |
159 | TmpStr = HiiGetString (gStringPackHandle, STRING_TOKEN (STR_MEMORY_TEST_PERCENT), NULL);\r |
160 | if (TmpStr != NULL) {\r | |
161 | //\r | |
162 | // TmpStr size is 64, StrPercent is reserved to 16.\r | |
163 | //\r | |
164 | StrnCatS (\r | |
165 | StrPercent,\r | |
166 | sizeof (StrPercent) / sizeof (CHAR16), \r | |
167 | TmpStr,\r | |
168 | sizeof (StrPercent) / sizeof (CHAR16) - StrLen (StrPercent) - 1\r | |
169 | );\r | |
170 | PrintXY (10, 10, NULL, NULL, StrPercent);\r | |
171 | FreePool (TmpStr);\r | |
172 | }\r | |
173 | \r | |
174 | TmpStr = HiiGetString (gStringPackHandle, STRING_TOKEN (STR_PERFORM_MEM_TEST), NULL);\r | |
175 | if (TmpStr != NULL) {\r | |
859e75c4 | 176 | BootLogoUpdateProgress (\r |
703da8b4 RN |
177 | Foreground,\r |
178 | Background,\r | |
179 | TmpStr,\r | |
180 | Color,\r | |
181 | TestPercent,\r | |
182 | (UINTN) PreviousValue\r | |
183 | );\r | |
184 | FreePool (TmpStr);\r | |
185 | }\r | |
186 | }\r | |
187 | \r | |
188 | PreviousValue = TestPercent;\r | |
189 | } else {\r | |
190 | DEBUG ((EFI_D_INFO, "Perform memory test (ESC to skip).\n"));\r | |
191 | }\r | |
192 | \r | |
193 | if (!PcdGetBool (PcdConInConnectOnDemand)) {\r | |
194 | KeyStatus = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r | |
195 | if (!EFI_ERROR (KeyStatus) && (Key.ScanCode == SCAN_ESC)) {\r | |
196 | if (!RequireSoftECCInit) {\r | |
197 | if (!FeaturePcdGet(PcdBootlogoOnlyEnable)) {\r | |
198 | TmpStr = HiiGetString (gStringPackHandle, STRING_TOKEN (STR_PERFORM_MEM_TEST), NULL);\r | |
199 | if (TmpStr != NULL) {\r | |
859e75c4 | 200 | BootLogoUpdateProgress (\r |
703da8b4 RN |
201 | Foreground,\r |
202 | Background,\r | |
203 | TmpStr,\r | |
204 | Color,\r | |
205 | 100,\r | |
206 | (UINTN) PreviousValue\r | |
207 | );\r | |
208 | FreePool (TmpStr);\r | |
209 | }\r | |
210 | \r | |
211 | PrintXY (10, 10, NULL, NULL, L"100");\r | |
212 | }\r | |
213 | Status = GenMemoryTest->Finished (GenMemoryTest);\r | |
214 | goto Done;\r | |
215 | }\r | |
216 | \r | |
217 | TestAbort = TRUE;\r | |
218 | }\r | |
219 | }\r | |
220 | } while (Status != EFI_NOT_FOUND);\r | |
221 | \r | |
222 | Status = GenMemoryTest->Finished (GenMemoryTest);\r | |
223 | \r | |
224 | Done:\r | |
225 | if (!FeaturePcdGet(PcdBootlogoOnlyEnable)) {\r | |
de66e154 | 226 | UnicodeValueToStringS (StrTotalMemory, StrTotalMemorySize, COMMA_TYPE, TotalMemorySize, 0);\r |
703da8b4 RN |
227 | if (StrTotalMemory[0] == L',') {\r |
228 | StrTotalMemory++;\r | |
229 | StrTotalMemorySize -= sizeof (CHAR16);\r | |
230 | }\r | |
231 | \r | |
232 | TmpStr = HiiGetString (gStringPackHandle, STRING_TOKEN (STR_MEM_TEST_COMPLETED), NULL);\r | |
233 | if (TmpStr != NULL) {\r | |
234 | StrnCatS (\r | |
235 | StrTotalMemory,\r | |
236 | StrTotalMemorySize / sizeof (CHAR16),\r | |
237 | TmpStr,\r | |
238 | StrTotalMemorySize / sizeof (CHAR16) - StrLen (StrTotalMemory) - 1\r | |
239 | );\r | |
240 | FreePool (TmpStr);\r | |
241 | }\r | |
242 | \r | |
243 | PrintXY (10, 10, NULL, NULL, StrTotalMemory);\r | |
859e75c4 | 244 | BootLogoUpdateProgress (\r |
703da8b4 RN |
245 | Foreground,\r |
246 | Background,\r | |
247 | StrTotalMemory,\r | |
248 | Color,\r | |
249 | 100,\r | |
250 | (UINTN) PreviousValue\r | |
251 | );\r | |
252 | \r | |
253 | } else {\r | |
254 | DEBUG ((EFI_D_INFO, "%d bytes of system memory tested OK\r\n", TotalMemorySize));\r | |
255 | }\r | |
256 | \r | |
257 | FreePool (Pos);\r | |
258 | return ReturnStatus;\r | |
259 | }\r |