2 The generic memory test driver definition
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #ifndef _GENERIC_MEMORY_TEST_H_
11 #define _GENERIC_MEMORY_TEST_H_
13 #include <Guid/StatusCodeDataTypeId.h>
14 #include <Protocol/GenericMemoryTest.h>
15 #include <Protocol/Cpu.h>
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>
30 #define GENERIC_CACHELINE_SIZE 0x40
33 // attributes for reserved memory before it is promoted to system memory
35 #define EFI_MEMORY_PRESENT 0x0100000000000000ULL
36 #define EFI_MEMORY_INITIALIZED 0x0200000000000000ULL
37 #define EFI_MEMORY_TESTED 0x0400000000000000ULL
40 // The SPARSE_SPAN_SIZE size can not small then the MonoTestSize
42 #define TEST_BLOCK_SIZE 0x2000000
43 #define QUICK_SPAN_SIZE (TEST_BLOCK_SIZE >> 2)
44 #define SPARSE_SPAN_SIZE (TEST_BLOCK_SIZE >> 4)
47 // This structure records every nontested memory range parsed through GCD
50 #define EFI_NONTESTED_MEMORY_RANGE_SIGNATURE SIGNATURE_32 ('N', 'T', 'M', 'E')
55 EFI_PHYSICAL_ADDRESS StartAddress
;
59 BOOLEAN AlreadyMapped
;
60 } NONTESTED_MEMORY_RANGE
;
62 #define NONTESTED_MEMORY_RANGE_FROM_LINK(link) \
65 NONTESTED_MEMORY_RANGE, \
67 EFI_NONTESTED_MEMORY_RANGE_SIGNATURE \
71 // This is the memory test driver's structure definition
73 #define EFI_GENERIC_MEMORY_TEST_PRIVATE_SIGNATURE SIGNATURE_32 ('G', 'E', 'M', 'T')
81 // Cpu arch protocol's pointer
83 EFI_CPU_ARCH_PROTOCOL
*Cpu
;
86 // generic memory test driver's protocol
88 EFI_GENERIC_MEMORY_TEST_PROTOCOL GenericMemoryTest
;
91 // memory test covered spans
93 EXTENDMEM_COVERAGE_LEVEL CoverLevel
;
98 // the memory test pattern and size every time R/W/V memory
104 // base memory's size which tested in PEI phase
106 UINT64 BaseMemorySize
;
111 LIST_ENTRY NonTestedMemRanList
;
113 } GENERIC_MEMORY_TEST_PRIVATE
;
115 #define GENERIC_MEMORY_TEST_PRIVATE_FROM_THIS(a) \
118 GENERIC_MEMORY_TEST_PRIVATE, \
120 EFI_GENERIC_MEMORY_TEST_PRIVATE_SIGNATURE \
124 // Function Prototypes
128 Construct the system base memory range through GCD service.
130 @param[in] Private Point to generic memory test driver's private data.
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.
138 ConstructBaseMemoryRange (
139 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
143 Construct the system non-tested memory range through GCD service.
145 @param[in] Private Point to generic memory test driver's private data.
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.
153 ConstructNonTestedMemoryRange (
154 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
158 Perform the address line walking ones test.
160 @param[in] Private Point to generic memory test driver's private data.
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.
169 PerformAddressDataLineTest (
170 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
174 Destroy the link list base on the correspond link list type.
176 @param[in] Private Point to generic memory test driver's private data.
181 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
185 Add the extened memory to whole system memory map.
187 @param[in] Private Point to generic memory test driver's private data.
189 @retval EFI_SUCCESS Successful add all the extended memory to system memory map.
190 @retval Others Failed to add the tested extended memory.
195 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
199 Write the memory test pattern into a range of physical memory.
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.
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.
211 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
,
212 IN EFI_PHYSICAL_ADDRESS Start
,
217 Verify the range of physical memory which covered by memory test pattern.
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.
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.
226 @retval EFI_SUCCESS Successful verify the range of memory, no errors' location found.
227 @retval Others The range of memory have errors contained.
232 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
,
233 IN EFI_PHYSICAL_ADDRESS Start
,
238 Test a range of the memory directly .
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.
245 @retval EFI_SUCCESS Successful test the range of memory.
246 @retval Others Failed to test the range of memory.
251 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
,
252 IN EFI_PHYSICAL_ADDRESS StartAddress
,
254 IN UINT64 Capabilities
258 Initialize the generic memory test.
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.
264 @retval EFI_SUCCESS The generic memory test is initialized correctly.
265 @retval EFI_NO_MEDIA The system had no memory to be tested.
270 InitializeMemoryTest (
271 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
,
272 IN EXTENDMEM_COVERAGE_LEVEL Level
,
273 OUT BOOLEAN
*RequireSoftECCInit
277 Perform the memory test.
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.
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.
293 GenPerformMemoryTest (
294 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
,
295 OUT UINT64
*TestedMemorySize
,
296 OUT UINT64
*TotalMemorySize
,
297 OUT BOOLEAN
*ErrorOut
,
302 Finish the memory test.
304 @param[in] This The protocol instance pointer.
306 @retval EFI_SUCCESS Success. All resources used in the memory test are freed.
311 GenMemoryTestFinished (
312 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
316 Provides the capability to test the compatible range used by some special drivers.
318 @param[in] This The protocol instance pointer.
319 @param[in] StartAddress The start address of the compatible memory range that
321 @param[in] Length The compatible memory range's length.
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.
329 GenCompatibleRangeTest (
330 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
,
331 IN EFI_PHYSICAL_ADDRESS StartAddress
,