]>
Commit | Line | Data |
---|---|---|
7c636bd0 | 1 | /** @file\r |
2 | The generic memory test driver definition\r | |
3 | \r | |
d1102dba | 4 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r |
7c636bd0 | 5 | \r |
9d510e61 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
7c636bd0 | 7 | \r |
8 | **/\r | |
9 | \r | |
10 | #ifndef _GENERIC_MEMORY_TEST_H_\r | |
11 | #define _GENERIC_MEMORY_TEST_H_\r | |
12 | \r | |
13 | #include <Guid/StatusCodeDataTypeId.h>\r | |
14 | #include <Protocol/GenericMemoryTest.h>\r | |
15 | #include <Protocol/Cpu.h>\r | |
16 | \r | |
17 | #include <Library/DebugLib.h>\r | |
18 | #include <Library/UefiDriverEntryPoint.h>\r | |
19 | #include <Library/HobLib.h>\r | |
20 | #include <Library/DxeServicesTableLib.h>\r | |
21 | #include <Library/ReportStatusCodeLib.h>\r | |
22 | #include <Library/BaseLib.h>\r | |
23 | #include <Library/BaseMemoryLib.h>\r | |
24 | #include <Library/MemoryAllocationLib.h>\r | |
25 | #include <Library/UefiBootServicesTableLib.h>\r | |
26 | \r | |
27 | //\r | |
28 | // Some global define\r | |
29 | //\r | |
30 | #define GENERIC_CACHELINE_SIZE 0x40\r | |
31 | \r | |
32 | //\r | |
33 | // attributes for reserved memory before it is promoted to system memory\r | |
34 | //\r | |
35 | #define EFI_MEMORY_PRESENT 0x0100000000000000ULL\r | |
36 | #define EFI_MEMORY_INITIALIZED 0x0200000000000000ULL\r | |
37 | #define EFI_MEMORY_TESTED 0x0400000000000000ULL\r | |
38 | \r | |
39 | //\r | |
40 | // The SPARSE_SPAN_SIZE size can not small then the MonoTestSize\r | |
41 | //\r | |
42 | #define TEST_BLOCK_SIZE 0x2000000\r | |
43 | #define QUICK_SPAN_SIZE (TEST_BLOCK_SIZE >> 2)\r | |
44 | #define SPARSE_SPAN_SIZE (TEST_BLOCK_SIZE >> 4)\r | |
45 | \r | |
46 | //\r | |
47 | // This structure records every nontested memory range parsed through GCD\r | |
48 | // service.\r | |
49 | //\r | |
50 | #define EFI_NONTESTED_MEMORY_RANGE_SIGNATURE SIGNATURE_32 ('N', 'T', 'M', 'E')\r | |
51 | \r | |
52 | typedef struct {\r | |
1436aea4 MK |
53 | UINTN Signature;\r |
54 | LIST_ENTRY Link;\r | |
55 | EFI_PHYSICAL_ADDRESS StartAddress;\r | |
56 | UINT64 Length;\r | |
57 | UINT64 Capabilities;\r | |
58 | BOOLEAN Above4G;\r | |
59 | BOOLEAN AlreadyMapped;\r | |
7c636bd0 | 60 | } NONTESTED_MEMORY_RANGE;\r |
61 | \r | |
62 | #define NONTESTED_MEMORY_RANGE_FROM_LINK(link) \\r | |
63 | CR ( \\r | |
64 | link, \\r | |
65 | NONTESTED_MEMORY_RANGE, \\r | |
66 | Link, \\r | |
67 | EFI_NONTESTED_MEMORY_RANGE_SIGNATURE \\r | |
68 | )\r | |
69 | \r | |
70 | //\r | |
71 | // This is the memory test driver's structure definition\r | |
72 | //\r | |
1436aea4 | 73 | #define EFI_GENERIC_MEMORY_TEST_PRIVATE_SIGNATURE SIGNATURE_32 ('G', 'E', 'M', 'T')\r |
7c636bd0 | 74 | \r |
75 | typedef struct {\r | |
1436aea4 MK |
76 | UINTN Signature;\r |
77 | EFI_HANDLE Handle;\r | |
7c636bd0 | 78 | \r |
79 | //\r | |
80 | // Cpu arch protocol's pointer\r | |
81 | //\r | |
1436aea4 | 82 | EFI_CPU_ARCH_PROTOCOL *Cpu;\r |
7c636bd0 | 83 | \r |
84 | //\r | |
85 | // generic memory test driver's protocol\r | |
86 | //\r | |
1436aea4 | 87 | EFI_GENERIC_MEMORY_TEST_PROTOCOL GenericMemoryTest;\r |
7c636bd0 | 88 | \r |
89 | //\r | |
90 | // memory test covered spans\r | |
91 | //\r | |
1436aea4 MK |
92 | EXTENDMEM_COVERAGE_LEVEL CoverLevel;\r |
93 | UINTN CoverageSpan;\r | |
94 | UINT64 BdsBlockSize;\r | |
7c636bd0 | 95 | \r |
96 | //\r | |
97 | // the memory test pattern and size every time R/W/V memory\r | |
98 | //\r | |
1436aea4 MK |
99 | VOID *MonoPattern;\r |
100 | UINTN MonoTestSize;\r | |
7c636bd0 | 101 | \r |
102 | //\r | |
103 | // base memory's size which tested in PEI phase\r | |
104 | //\r | |
1436aea4 | 105 | UINT64 BaseMemorySize;\r |
7c636bd0 | 106 | \r |
107 | //\r | |
108 | // memory range list\r | |
109 | //\r | |
1436aea4 | 110 | LIST_ENTRY NonTestedMemRanList;\r |
7c636bd0 | 111 | } GENERIC_MEMORY_TEST_PRIVATE;\r |
112 | \r | |
113 | #define GENERIC_MEMORY_TEST_PRIVATE_FROM_THIS(a) \\r | |
114 | CR ( \\r | |
115 | a, \\r | |
116 | GENERIC_MEMORY_TEST_PRIVATE, \\r | |
117 | GenericMemoryTest, \\r | |
118 | EFI_GENERIC_MEMORY_TEST_PRIVATE_SIGNATURE \\r | |
119 | )\r | |
120 | \r | |
121 | //\r | |
122 | // Function Prototypes\r | |
123 | //\r | |
124 | \r | |
125 | /**\r | |
126 | Construct the system base memory range through GCD service.\r | |
127 | \r | |
128 | @param[in] Private Point to generic memory test driver's private data.\r | |
129 | \r | |
130 | @retval EFI_SUCCESS Successful construct the base memory range through GCD service.\r | |
131 | @retval EFI_OUT_OF_RESOURCE Could not allocate needed resource from base memory.\r | |
132 | @retval Others Failed to construct base memory range through GCD service.\r | |
d1102dba | 133 | \r |
7c636bd0 | 134 | **/\r |
135 | EFI_STATUS\r | |
136 | ConstructBaseMemoryRange (\r | |
137 | IN GENERIC_MEMORY_TEST_PRIVATE *Private\r | |
138 | );\r | |
139 | \r | |
140 | /**\r | |
141 | Construct the system non-tested memory range through GCD service.\r | |
142 | \r | |
143 | @param[in] Private Point to generic memory test driver's private data.\r | |
144 | \r | |
145 | @retval EFI_SUCCESS Successful construct the non-tested memory range through GCD service.\r | |
146 | @retval EFI_OUT_OF_RESOURCE Could not allocate needed resource from base memory.\r | |
147 | @retval Others Failed to construct non-tested memory range through GCD service.\r | |
d1102dba | 148 | \r |
7c636bd0 | 149 | **/\r |
150 | EFI_STATUS\r | |
151 | ConstructNonTestedMemoryRange (\r | |
152 | IN GENERIC_MEMORY_TEST_PRIVATE *Private\r | |
153 | );\r | |
154 | \r | |
155 | /**\r | |
156 | Perform the address line walking ones test.\r | |
157 | \r | |
158 | @param[in] Private Point to generic memory test driver's private data.\r | |
d1102dba LG |
159 | \r |
160 | @retval EFI_SUCCESS Successful finished walking ones test.\r | |
161 | @retval EFI_OUT_OF_RESOURCE Could not get resource in base memory.\r | |
7c636bd0 | 162 | @retval EFI_ACCESS_DENIED Code may can not run here because if walking one test\r |
163 | failed, system may be already halt.\r | |
164 | \r | |
165 | **/\r | |
166 | EFI_STATUS\r | |
167 | PerformAddressDataLineTest (\r | |
1436aea4 | 168 | IN GENERIC_MEMORY_TEST_PRIVATE *Private\r |
7c636bd0 | 169 | );\r |
170 | \r | |
171 | /**\r | |
172 | Destroy the link list base on the correspond link list type.\r | |
173 | \r | |
174 | @param[in] Private Point to generic memory test driver's private data.\r | |
d1102dba | 175 | \r |
7c636bd0 | 176 | **/\r |
177 | VOID\r | |
178 | DestroyLinkList (\r | |
179 | IN GENERIC_MEMORY_TEST_PRIVATE *Private\r | |
180 | );\r | |
181 | \r | |
182 | /**\r | |
183 | Add the extened memory to whole system memory map.\r | |
184 | \r | |
185 | @param[in] Private Point to generic memory test driver's private data.\r | |
186 | \r | |
187 | @retval EFI_SUCCESS Successful add all the extended memory to system memory map.\r | |
188 | @retval Others Failed to add the tested extended memory.\r | |
d1102dba | 189 | \r |
7c636bd0 | 190 | **/\r |
191 | EFI_STATUS\r | |
192 | UpdateMemoryMap (\r | |
193 | IN GENERIC_MEMORY_TEST_PRIVATE *Private\r | |
194 | );\r | |
195 | \r | |
196 | /**\r | |
197 | Write the memory test pattern into a range of physical memory.\r | |
198 | \r | |
199 | @param[in] Private Point to generic memory test driver's private data.\r | |
200 | @param[in] Start The memory range's start address.\r | |
201 | @param[in] Size The memory range's size.\r | |
202 | \r | |
203 | @retval EFI_SUCCESS Successful write the test pattern into the non-tested memory.\r | |
204 | @retval Others The test pattern may not really write into the physical memory.\r | |
d1102dba | 205 | \r |
7c636bd0 | 206 | **/\r |
207 | EFI_STATUS\r | |
208 | WriteMemory (\r | |
209 | IN GENERIC_MEMORY_TEST_PRIVATE *Private,\r | |
210 | IN EFI_PHYSICAL_ADDRESS Start,\r | |
211 | IN UINT64 Size\r | |
212 | );\r | |
213 | \r | |
214 | /**\r | |
215 | Verify the range of physical memory which covered by memory test pattern.\r | |
216 | \r | |
217 | This function will also do not return any informatin just cause system reset,\r | |
218 | because the handle error encount fatal error and disable the bad DIMMs.\r | |
219 | \r | |
220 | @param[in] Private Point to generic memory test driver's private data.\r | |
221 | @param[in] Start The memory range's start address.\r | |
222 | @param[in] Size The memory range's size.\r | |
223 | \r | |
224 | @retval EFI_SUCCESS Successful verify the range of memory, no errors' location found.\r | |
225 | @retval Others The range of memory have errors contained.\r | |
d1102dba | 226 | \r |
7c636bd0 | 227 | **/\r |
228 | EFI_STATUS\r | |
229 | VerifyMemory (\r | |
230 | IN GENERIC_MEMORY_TEST_PRIVATE *Private,\r | |
231 | IN EFI_PHYSICAL_ADDRESS Start,\r | |
232 | IN UINT64 Size\r | |
233 | );\r | |
234 | \r | |
235 | /**\r | |
236 | Test a range of the memory directly .\r | |
237 | \r | |
238 | @param[in] Private Point to generic memory test driver's private data.\r | |
239 | @param[in] StartAddress Starting address of the memory range to be tested.\r | |
240 | @param[in] Length Length in bytes of the memory range to be tested.\r | |
241 | @param[in] Capabilities The bit mask of attributes that the memory range supports.\r | |
242 | \r | |
243 | @retval EFI_SUCCESS Successful test the range of memory.\r | |
244 | @retval Others Failed to test the range of memory.\r | |
d1102dba | 245 | \r |
7c636bd0 | 246 | **/\r |
247 | EFI_STATUS\r | |
248 | DirectRangeTest (\r | |
249 | IN GENERIC_MEMORY_TEST_PRIVATE *Private,\r | |
250 | IN EFI_PHYSICAL_ADDRESS StartAddress,\r | |
251 | IN UINT64 Length,\r | |
252 | IN UINT64 Capabilities\r | |
253 | );\r | |
254 | \r | |
255 | /**\r | |
256 | Initialize the generic memory test.\r | |
257 | \r | |
d1102dba LG |
258 | @param[in] This The protocol instance pointer.\r |
259 | @param[in] Level The coverage level of the memory test.\r | |
260 | @param[out] RequireSoftECCInit Indicate if the memory need software ECC init.\r | |
7c636bd0 | 261 | \r |
d1102dba LG |
262 | @retval EFI_SUCCESS The generic memory test is initialized correctly.\r |
263 | @retval EFI_NO_MEDIA The system had no memory to be tested.\r | |
7c636bd0 | 264 | \r |
265 | **/\r | |
266 | EFI_STATUS\r | |
267 | EFIAPI\r | |
268 | InitializeMemoryTest (\r | |
1436aea4 MK |
269 | IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,\r |
270 | IN EXTENDMEM_COVERAGE_LEVEL Level,\r | |
271 | OUT BOOLEAN *RequireSoftECCInit\r | |
7c636bd0 | 272 | );\r |
273 | \r | |
274 | /**\r | |
275 | Perform the memory test.\r | |
276 | \r | |
d1102dba LG |
277 | @param[in] This The protocol instance pointer.\r |
278 | @param[out] TestedMemorySize Return the tested extended memory size.\r | |
279 | @param[out] TotalMemorySize Return the whole system physical memory size.\r | |
280 | The total memory size does not include memory in a slot with a disabled DIMM.\r | |
d181539b | 281 | @param[out] ErrorOut TRUE if the memory error occurred.\r |
d1102dba | 282 | @param[in] IfTestAbort Indicates that the user pressed "ESC" to skip the memory test.\r |
7c636bd0 | 283 | \r |
284 | @retval EFI_SUCCESS One block of memory passed the test.\r | |
285 | @retval EFI_NOT_FOUND All memory blocks have already been tested.\r | |
d181539b | 286 | @retval EFI_DEVICE_ERROR Memory device error occurred, and no agent can handle it.\r |
7c636bd0 | 287 | \r |
288 | **/\r | |
289 | EFI_STATUS\r | |
290 | EFIAPI\r | |
291 | GenPerformMemoryTest (\r | |
1436aea4 MK |
292 | IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,\r |
293 | OUT UINT64 *TestedMemorySize,\r | |
294 | OUT UINT64 *TotalMemorySize,\r | |
295 | OUT BOOLEAN *ErrorOut,\r | |
296 | IN BOOLEAN TestAbort\r | |
7c636bd0 | 297 | );\r |
298 | \r | |
299 | /**\r | |
300 | Finish the memory test.\r | |
301 | \r | |
d1102dba | 302 | @param[in] This The protocol instance pointer.\r |
7c636bd0 | 303 | \r |
304 | @retval EFI_SUCCESS Success. All resources used in the memory test are freed.\r | |
305 | \r | |
306 | **/\r | |
307 | EFI_STATUS\r | |
308 | EFIAPI\r | |
309 | GenMemoryTestFinished (\r | |
1436aea4 | 310 | IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This\r |
7c636bd0 | 311 | );\r |
312 | \r | |
313 | /**\r | |
314 | Provides the capability to test the compatible range used by some special drivers.\r | |
315 | \r | |
d1102dba | 316 | @param[in] This The protocol instance pointer.\r |
7c636bd0 | 317 | @param[in] StartAddress The start address of the compatible memory range that\r |
318 | must be below 16M.\r | |
d1102dba LG |
319 | @param[in] Length The compatible memory range's length.\r |
320 | \r | |
321 | @retval EFI_SUCCESS The compatible memory range pass the memory test.\r | |
7c636bd0 | 322 | @retval EFI_INVALID_PARAMETER The compatible memory range are not below Low 16M.\r |
323 | \r | |
324 | **/\r | |
325 | EFI_STATUS\r | |
326 | EFIAPI\r | |
327 | GenCompatibleRangeTest (\r | |
1436aea4 MK |
328 | IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,\r |
329 | IN EFI_PHYSICAL_ADDRESS StartAddress,\r | |
330 | IN UINT64 Length\r | |
7c636bd0 | 331 | );\r |
332 | \r | |
333 | #endif\r |