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