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