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