]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/MemoryTest/GenericMemoryTestDxe/LightMemoryTest.h
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Universal / MemoryTest / GenericMemoryTestDxe / LightMemoryTest.h
CommitLineData
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
52typedef struct {\r
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
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
73#define EFI_GENERIC_MEMORY_TEST_PRIVATE_SIGNATURE SIGNATURE_32 ('G', 'E', 'M', 'T')\r
74\r
75typedef struct {\r
76\r
77 UINTN Signature;\r
78 EFI_HANDLE Handle;\r
79\r
80 //\r
81 // Cpu arch protocol's pointer\r
82 //\r
83 EFI_CPU_ARCH_PROTOCOL *Cpu;\r
84\r
85 //\r
86 // generic memory test driver's protocol\r
87 //\r
88 EFI_GENERIC_MEMORY_TEST_PROTOCOL GenericMemoryTest;\r
89\r
90 //\r
91 // memory test covered spans\r
92 //\r
93 EXTENDMEM_COVERAGE_LEVEL CoverLevel;\r
94 UINTN CoverageSpan;\r
95 UINT64 BdsBlockSize;\r
96\r
97 //\r
98 // the memory test pattern and size every time R/W/V memory\r
99 //\r
100 VOID *MonoPattern;\r
101 UINTN MonoTestSize;\r
102\r
103 //\r
104 // base memory's size which tested in PEI phase\r
105 //\r
106 UINT64 BaseMemorySize;\r
107\r
108 //\r
109 // memory range list\r
110 //\r
111 LIST_ENTRY NonTestedMemRanList;\r
112\r
113} GENERIC_MEMORY_TEST_PRIVATE;\r
114\r
115#define GENERIC_MEMORY_TEST_PRIVATE_FROM_THIS(a) \\r
116 CR ( \\r
117 a, \\r
118 GENERIC_MEMORY_TEST_PRIVATE, \\r
119 GenericMemoryTest, \\r
120 EFI_GENERIC_MEMORY_TEST_PRIVATE_SIGNATURE \\r
121 )\r
122\r
123//\r
124// Function Prototypes\r
125//\r
126\r
127/**\r
128 Construct the system base memory range through GCD service.\r
129\r
130 @param[in] Private Point to generic memory test driver's private data.\r
131\r
132 @retval EFI_SUCCESS Successful construct the base memory range through GCD service.\r
133 @retval EFI_OUT_OF_RESOURCE Could not allocate needed resource from base memory.\r
134 @retval Others Failed to construct base memory range through GCD service.\r
d1102dba 135\r
7c636bd0 136**/\r
137EFI_STATUS\r
138ConstructBaseMemoryRange (\r
139 IN GENERIC_MEMORY_TEST_PRIVATE *Private\r
140 );\r
141\r
142/**\r
143 Construct the system non-tested memory range through GCD service.\r
144\r
145 @param[in] Private Point to generic memory test driver's private data.\r
146\r
147 @retval EFI_SUCCESS Successful construct the non-tested memory range through GCD service.\r
148 @retval EFI_OUT_OF_RESOURCE Could not allocate needed resource from base memory.\r
149 @retval Others Failed to construct non-tested memory range through GCD service.\r
d1102dba 150\r
7c636bd0 151**/\r
152EFI_STATUS\r
153ConstructNonTestedMemoryRange (\r
154 IN GENERIC_MEMORY_TEST_PRIVATE *Private\r
155 );\r
156\r
157/**\r
158 Perform the address line walking ones test.\r
159\r
160 @param[in] Private Point to generic memory test driver's private data.\r
d1102dba
LG
161\r
162 @retval EFI_SUCCESS Successful finished walking ones test.\r
163 @retval EFI_OUT_OF_RESOURCE Could not get resource in base memory.\r
7c636bd0 164 @retval EFI_ACCESS_DENIED Code may can not run here because if walking one test\r
165 failed, system may be already halt.\r
166\r
167**/\r
168EFI_STATUS\r
169PerformAddressDataLineTest (\r
170 IN GENERIC_MEMORY_TEST_PRIVATE *Private\r
171 );\r
172\r
173/**\r
174 Destroy the link list base on the correspond link list type.\r
175\r
176 @param[in] Private Point to generic memory test driver's private data.\r
d1102dba 177\r
7c636bd0 178**/\r
179VOID\r
180DestroyLinkList (\r
181 IN GENERIC_MEMORY_TEST_PRIVATE *Private\r
182 );\r
183\r
184/**\r
185 Add the extened memory to whole system memory map.\r
186\r
187 @param[in] Private Point to generic memory test driver's private data.\r
188\r
189 @retval EFI_SUCCESS Successful add all the extended memory to system memory map.\r
190 @retval Others Failed to add the tested extended memory.\r
d1102dba 191\r
7c636bd0 192**/\r
193EFI_STATUS\r
194UpdateMemoryMap (\r
195 IN GENERIC_MEMORY_TEST_PRIVATE *Private\r
196 );\r
197\r
198/**\r
199 Write the memory test pattern into a range of physical memory.\r
200\r
201 @param[in] Private Point to generic memory test driver's private data.\r
202 @param[in] Start The memory range's start address.\r
203 @param[in] Size The memory range's size.\r
204\r
205 @retval EFI_SUCCESS Successful write the test pattern into the non-tested memory.\r
206 @retval Others The test pattern may not really write into the physical memory.\r
d1102dba 207\r
7c636bd0 208**/\r
209EFI_STATUS\r
210WriteMemory (\r
211 IN GENERIC_MEMORY_TEST_PRIVATE *Private,\r
212 IN EFI_PHYSICAL_ADDRESS Start,\r
213 IN UINT64 Size\r
214 );\r
215\r
216/**\r
217 Verify the range of physical memory which covered by memory test pattern.\r
218\r
219 This function will also do not return any informatin just cause system reset,\r
220 because the handle error encount fatal error and disable the bad DIMMs.\r
221\r
222 @param[in] Private Point to generic memory test driver's private data.\r
223 @param[in] Start The memory range's start address.\r
224 @param[in] Size The memory range's size.\r
225\r
226 @retval EFI_SUCCESS Successful verify the range of memory, no errors' location found.\r
227 @retval Others The range of memory have errors contained.\r
d1102dba 228\r
7c636bd0 229**/\r
230EFI_STATUS\r
231VerifyMemory (\r
232 IN GENERIC_MEMORY_TEST_PRIVATE *Private,\r
233 IN EFI_PHYSICAL_ADDRESS Start,\r
234 IN UINT64 Size\r
235 );\r
236\r
237/**\r
238 Test a range of the memory directly .\r
239\r
240 @param[in] Private Point to generic memory test driver's private data.\r
241 @param[in] StartAddress Starting address of the memory range to be tested.\r
242 @param[in] Length Length in bytes of the memory range to be tested.\r
243 @param[in] Capabilities The bit mask of attributes that the memory range supports.\r
244\r
245 @retval EFI_SUCCESS Successful test the range of memory.\r
246 @retval Others Failed to test the range of memory.\r
d1102dba 247\r
7c636bd0 248**/\r
249EFI_STATUS\r
250DirectRangeTest (\r
251 IN GENERIC_MEMORY_TEST_PRIVATE *Private,\r
252 IN EFI_PHYSICAL_ADDRESS StartAddress,\r
253 IN UINT64 Length,\r
254 IN UINT64 Capabilities\r
255 );\r
256\r
257/**\r
258 Initialize the generic memory test.\r
259\r
d1102dba
LG
260 @param[in] This The protocol instance pointer.\r
261 @param[in] Level The coverage level of the memory test.\r
262 @param[out] RequireSoftECCInit Indicate if the memory need software ECC init.\r
7c636bd0 263\r
d1102dba
LG
264 @retval EFI_SUCCESS The generic memory test is initialized correctly.\r
265 @retval EFI_NO_MEDIA The system had no memory to be tested.\r
7c636bd0 266\r
267**/\r
268EFI_STATUS\r
269EFIAPI\r
270InitializeMemoryTest (\r
271 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,\r
272 IN EXTENDMEM_COVERAGE_LEVEL Level,\r
273 OUT BOOLEAN *RequireSoftECCInit\r
274 );\r
275\r
276/**\r
277 Perform the memory test.\r
278\r
d1102dba
LG
279 @param[in] This The protocol instance pointer.\r
280 @param[out] TestedMemorySize Return the tested extended memory size.\r
281 @param[out] TotalMemorySize Return the whole system physical memory size.\r
282 The total memory size does not include memory in a slot with a disabled DIMM.\r
7c636bd0 283 @param[out] ErrorOut TRUE if the memory error occured.\r
d1102dba 284 @param[in] IfTestAbort Indicates that the user pressed "ESC" to skip the memory test.\r
7c636bd0 285\r
286 @retval EFI_SUCCESS One block of memory passed the test.\r
287 @retval EFI_NOT_FOUND All memory blocks have already been tested.\r
288 @retval EFI_DEVICE_ERROR Memory device error occured, and no agent can handle it.\r
289\r
290**/\r
291EFI_STATUS\r
292EFIAPI\r
293GenPerformMemoryTest (\r
294 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,\r
295 OUT UINT64 *TestedMemorySize,\r
296 OUT UINT64 *TotalMemorySize,\r
297 OUT BOOLEAN *ErrorOut,\r
298 IN BOOLEAN TestAbort\r
299 );\r
300\r
301/**\r
302 Finish the memory test.\r
303\r
d1102dba 304 @param[in] This The protocol instance pointer.\r
7c636bd0 305\r
306 @retval EFI_SUCCESS Success. All resources used in the memory test are freed.\r
307\r
308**/\r
309EFI_STATUS\r
310EFIAPI\r
311GenMemoryTestFinished (\r
312 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This\r
313 );\r
314\r
315/**\r
316 Provides the capability to test the compatible range used by some special drivers.\r
317\r
d1102dba 318 @param[in] This The protocol instance pointer.\r
7c636bd0 319 @param[in] StartAddress The start address of the compatible memory range that\r
320 must be below 16M.\r
d1102dba
LG
321 @param[in] Length The compatible memory range's length.\r
322\r
323 @retval EFI_SUCCESS The compatible memory range pass the memory test.\r
7c636bd0 324 @retval EFI_INVALID_PARAMETER The compatible memory range are not below Low 16M.\r
325\r
326**/\r
327EFI_STATUS\r
328EFIAPI\r
329GenCompatibleRangeTest (\r
330 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,\r
331 IN EFI_PHYSICAL_ADDRESS StartAddress,\r
332 IN UINT64 Length\r
333 );\r
334\r
335#endif\r