]>
Commit | Line | Data |
---|---|---|
674dced3 | 1 | /** @file\r |
b3764698 | 2 | Implementation of Generic Memory Test Protocol which does not perform real memory test.\r |
05177bef | 3 | \r |
1c06bd48 | 4 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r |
e5eed7d3 | 5 | This program and the accompanying materials\r |
674dced3 | 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 | |
05177bef | 9 | \r |
674dced3 | 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 | |
05177bef | 12 | \r |
674dced3 | 13 | **/\r |
05177bef | 14 | \r |
15 | \r | |
16 | #include "NullMemoryTest.h"\r | |
17 | \r | |
05177bef | 18 | UINT64 mTestedSystemMemory = 0;\r |
19 | UINT64 mTotalSystemMemory = 0;\r | |
20 | EFI_HANDLE mGenericMemoryTestHandle;\r | |
21 | \r | |
05177bef | 22 | EFI_GENERIC_MEMORY_TEST_PROTOCOL mGenericMemoryTest = {\r |
23 | InitializeMemoryTest,\r | |
24 | GenPerformMemoryTest,\r | |
25 | GenMemoryTestFinished,\r | |
26 | GenCompatibleRangeTest\r | |
27 | };\r | |
28 | \r | |
b3764698 | 29 | /**\r |
30 | Entry point of the NULL memory test driver.\r | |
d1102dba | 31 | \r |
b3764698 | 32 | This function is the entry point of the NULL memory test driver.\r |
33 | It simply installs the Generic Memory Test Protocol.\r | |
34 | \r | |
35 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
36 | @param SystemTable A pointer to the EFI System Table.\r | |
37 | \r | |
38 | @retval EFI_SUCCESS Generic Memory Test Protocol is successfully installed.\r | |
39 | \r | |
40 | **/\r | |
05177bef | 41 | EFI_STATUS\r |
42 | EFIAPI\r | |
43 | GenericMemoryTestEntryPoint (\r | |
44 | IN EFI_HANDLE ImageHandle,\r | |
45 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
46 | )\r | |
05177bef | 47 | {\r |
48 | EFI_STATUS Status;\r | |
49 | \r | |
05177bef | 50 | Status = gBS->InstallProtocolInterface (\r |
51 | &mGenericMemoryTestHandle,\r | |
52 | &gEfiGenericMemTestProtocolGuid,\r | |
53 | EFI_NATIVE_INTERFACE,\r | |
54 | &mGenericMemoryTest\r | |
55 | );\r | |
b3764698 | 56 | ASSERT_EFI_ERROR (Status);\r |
05177bef | 57 | \r |
b3764698 | 58 | return EFI_SUCCESS;\r |
05177bef | 59 | }\r |
b3764698 | 60 | \r |
1c06bd48 | 61 | /**\r |
ee37e964 | 62 | Convert the memory range to tested.\r |
1c06bd48 | 63 | \r |
ee37e964 RN |
64 | @param BaseAddress Base address of the memory range.\r |
65 | @param Length Length of the memory range.\r | |
66 | @param Capabilities Capabilities of the memory range.\r | |
1c06bd48 | 67 | \r |
ee37e964 | 68 | @retval EFI_SUCCESS The memory range is converted to tested.\r |
1c06bd48 RN |
69 | @retval others Error happens.\r |
70 | **/\r | |
71 | EFI_STATUS\r | |
72 | ConvertToTestedMemory (\r | |
ee37e964 RN |
73 | IN UINT64 BaseAddress,\r |
74 | IN UINT64 Length,\r | |
75 | IN UINT64 Capabilities\r | |
1c06bd48 RN |
76 | )\r |
77 | {\r | |
78 | EFI_STATUS Status;\r | |
79 | Status = gDS->RemoveMemorySpace (\r | |
ee37e964 RN |
80 | BaseAddress,\r |
81 | Length\r | |
1c06bd48 RN |
82 | );\r |
83 | if (!EFI_ERROR (Status)) {\r | |
84 | Status = gDS->AddMemorySpace (\r | |
ee37e964 | 85 | ((Capabilities & EFI_MEMORY_MORE_RELIABLE) == EFI_MEMORY_MORE_RELIABLE) ?\r |
1c06bd48 | 86 | EfiGcdMemoryTypeMoreReliable : EfiGcdMemoryTypeSystemMemory,\r |
ee37e964 RN |
87 | BaseAddress,\r |
88 | Length,\r | |
89 | Capabilities &~\r | |
1c06bd48 RN |
90 | (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)\r |
91 | );\r | |
92 | }\r | |
93 | return Status;\r | |
94 | }\r | |
95 | \r | |
b3764698 | 96 | /**\r |
97 | Initialize the generic memory test.\r | |
98 | \r | |
99 | This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.MemoryTestInit.\r | |
100 | It simply promotes untested reserved memory to system memory without real test.\r | |
101 | \r | |
d1102dba LG |
102 | @param This Protocol instance pointer.\r |
103 | @param Level The coverage level of the memory test.\r | |
104 | @param RequireSoftECCInit Indicate if the memory need software ECC init.\r | |
b3764698 | 105 | \r |
d1102dba LG |
106 | @retval EFI_SUCCESS The generic memory test initialized correctly.\r |
107 | @retval EFI_NO_MEDIA There is not any non-tested memory found, in this\r | |
108 | function if not any non-tesed memory found means\r | |
109 | that the memory test driver have not detect any\r | |
110 | non-tested extended memory of current system.\r | |
b3764698 | 111 | \r |
112 | **/\r | |
05177bef | 113 | EFI_STATUS\r |
114 | EFIAPI\r | |
115 | InitializeMemoryTest (\r | |
116 | IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,\r | |
117 | IN EXTENDMEM_COVERAGE_LEVEL Level,\r | |
118 | OUT BOOLEAN *RequireSoftECCInit\r | |
119 | )\r | |
05177bef | 120 | {\r |
1c06bd48 | 121 | EFI_STATUS Status;\r |
05177bef | 122 | UINTN NumberOfDescriptors;\r |
123 | EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;\r | |
124 | UINTN Index;\r | |
125 | \r | |
126 | gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);\r | |
127 | for (Index = 0; Index < NumberOfDescriptors; Index++) {\r | |
128 | if (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeReserved &&\r | |
129 | (MemorySpaceMap[Index].Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==\r | |
130 | (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED)\r | |
131 | ) {\r | |
b3764698 | 132 | //\r |
133 | // For those reserved memory that have not been tested, simply promote to system memory.\r | |
134 | //\r | |
ee37e964 RN |
135 | Status = ConvertToTestedMemory (\r |
136 | MemorySpaceMap[Index].BaseAddress,\r | |
137 | MemorySpaceMap[Index].Length,\r | |
138 | MemorySpaceMap[Index].Capabilities\r | |
139 | );\r | |
1c06bd48 | 140 | ASSERT_EFI_ERROR (Status);\r |
05177bef | 141 | mTestedSystemMemory += MemorySpaceMap[Index].Length;\r |
142 | mTotalSystemMemory += MemorySpaceMap[Index].Length;\r | |
1c06bd48 RN |
143 | } else if ((MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeSystemMemory) ||\r |
144 | (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeMoreReliable)) {\r | |
05177bef | 145 | mTotalSystemMemory += MemorySpaceMap[Index].Length;\r |
146 | }\r | |
147 | }\r | |
148 | \r | |
149 | FreePool (MemorySpaceMap);\r | |
150 | \r | |
151 | *RequireSoftECCInit = FALSE;\r | |
152 | return EFI_SUCCESS;\r | |
153 | }\r | |
154 | \r | |
b3764698 | 155 | /**\r |
156 | Perform the memory test.\r | |
157 | \r | |
158 | This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.PerformMemoryTest.\r | |
159 | It simply returns EFI_NOT_FOUND.\r | |
160 | \r | |
d1102dba LG |
161 | @param This Protocol instance pointer.\r |
162 | @param TestedMemorySize Return the tested extended memory size.\r | |
163 | @param TotalMemorySize Return the whole system physical memory size, this\r | |
164 | value may be changed if in some case some error\r | |
165 | DIMMs be disabled.\r | |
166 | @param ErrorOut Any time the memory error occurs, this will be\r | |
167 | TRUE.\r | |
168 | @param IfTestAbort Indicate if the user press "ESC" to skip the memory\r | |
169 | test.\r | |
170 | \r | |
171 | @retval EFI_SUCCESS One block of memory test ok, the block size is hide\r | |
172 | internally.\r | |
173 | @retval EFI_NOT_FOUND Indicate all the non-tested memory blocks have\r | |
174 | already go through.\r | |
b3764698 | 175 | @retval EFI_DEVICE_ERROR Mis-compare error, and no agent can handle it\r |
176 | \r | |
177 | **/\r | |
05177bef | 178 | EFI_STATUS\r |
179 | EFIAPI\r | |
180 | GenPerformMemoryTest (\r | |
181 | IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,\r | |
182 | IN OUT UINT64 *TestedMemorySize,\r | |
183 | OUT UINT64 *TotalMemorySize,\r | |
184 | OUT BOOLEAN *ErrorOut,\r | |
185 | IN BOOLEAN TestAbort\r | |
186 | )\r | |
05177bef | 187 | {\r |
188 | *ErrorOut = FALSE;\r | |
189 | *TestedMemorySize = mTestedSystemMemory;\r | |
190 | *TotalMemorySize = mTotalSystemMemory;\r | |
191 | \r | |
192 | return EFI_NOT_FOUND;\r | |
193 | \r | |
194 | }\r | |
195 | \r | |
b3764698 | 196 | /**\r |
197 | The memory test finished.\r | |
198 | \r | |
199 | This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.Finished.\r | |
200 | It simply returns EFI_SUCCESS.\r | |
201 | \r | |
d1102dba | 202 | @param This Protocol instance pointer.\r |
b3764698 | 203 | \r |
d1102dba LG |
204 | @retval EFI_SUCCESS Successful free all the generic memory test driver\r |
205 | allocated resource and notify to platform memory\r | |
206 | test driver that memory test finished.\r | |
b3764698 | 207 | \r |
208 | **/\r | |
05177bef | 209 | EFI_STATUS\r |
210 | EFIAPI\r | |
211 | GenMemoryTestFinished (\r | |
212 | IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This\r | |
213 | )\r | |
05177bef | 214 | {\r |
215 | return EFI_SUCCESS;\r | |
216 | }\r | |
217 | \r | |
b3764698 | 218 | /**\r |
219 | Provide capability to test compatible range which used by some special\r | |
220 | driver required using memory range before BDS perform memory test.\r | |
221 | \r | |
222 | This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.CompatibleRangeTest.\r | |
223 | It simply sets the memory range to system memory.\r | |
224 | \r | |
d1102dba LG |
225 | @param This Protocol instance pointer.\r |
226 | @param StartAddress The start address of the memory range.\r | |
227 | @param Length The memory range's length.\r | |
228 | \r | |
229 | @retval EFI_SUCCESS The compatible memory range pass the memory test.\r | |
b3764698 | 230 | @retval EFI_INVALID_PARAMETER The compatible memory range must be below 16M.\r |
231 | \r | |
232 | **/\r | |
05177bef | 233 | EFI_STATUS\r |
234 | EFIAPI\r | |
235 | GenCompatibleRangeTest (\r | |
236 | IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,\r | |
1c06bd48 RN |
237 | IN EFI_PHYSICAL_ADDRESS StartAddress,\r |
238 | IN UINT64 Length\r | |
05177bef | 239 | )\r |
05177bef | 240 | {\r |
1c06bd48 | 241 | EFI_STATUS Status;\r |
b3764698 | 242 | EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;\r |
61c1742b RN |
243 | EFI_PHYSICAL_ADDRESS CurrentBase;\r |
244 | UINT64 CurrentLength;\r | |
245 | \r | |
246 | //\r | |
247 | // Check if the parameter is below 16MB\r | |
248 | //\r | |
249 | if (StartAddress + Length > SIZE_16MB) {\r | |
250 | return EFI_INVALID_PARAMETER;\r | |
1c06bd48 | 251 | }\r |
61c1742b RN |
252 | CurrentBase = StartAddress;\r |
253 | do {\r | |
254 | //\r | |
255 | // Check the required memory range status; if the required memory range span\r | |
256 | // the different GCD memory descriptor, it may be cause different action.\r | |
257 | //\r | |
258 | Status = gDS->GetMemorySpaceDescriptor (\r | |
259 | CurrentBase,\r | |
260 | &Descriptor\r | |
261 | );\r | |
262 | if (EFI_ERROR (Status)) {\r | |
263 | return Status;\r | |
264 | }\r | |
265 | \r | |
266 | if (Descriptor.GcdMemoryType == EfiGcdMemoryTypeReserved &&\r | |
267 | (Descriptor.Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==\r | |
268 | (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED)\r | |
269 | ) {\r | |
270 | CurrentLength = Descriptor.BaseAddress + Descriptor.Length - CurrentBase;\r | |
271 | if (CurrentBase + CurrentLength > StartAddress + Length) {\r | |
272 | CurrentLength = StartAddress + Length - CurrentBase;\r | |
273 | }\r | |
274 | Status = ConvertToTestedMemory (\r | |
275 | CurrentBase,\r | |
276 | CurrentLength,\r | |
277 | Descriptor.Capabilities\r | |
278 | );\r | |
279 | if (EFI_ERROR (Status)) {\r | |
280 | return Status;\r | |
281 | }\r | |
282 | }\r | |
283 | CurrentBase = Descriptor.BaseAddress + Descriptor.Length;\r | |
284 | } while (CurrentBase < StartAddress + Length);\r | |
285 | //\r | |
286 | // Here means the required range already be tested, so just return success.\r | |
287 | //\r | |
288 | return EFI_SUCCESS;\r | |
05177bef | 289 | }\r |
61c1742b | 290 | \r |