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')
80 // Cpu arch protocol's pointer
82 EFI_CPU_ARCH_PROTOCOL
*Cpu
;
85 // generic memory test driver's protocol
87 EFI_GENERIC_MEMORY_TEST_PROTOCOL GenericMemoryTest
;
90 // memory test covered spans
92 EXTENDMEM_COVERAGE_LEVEL CoverLevel
;
97 // the memory test pattern and size every time R/W/V memory
103 // base memory's size which tested in PEI phase
105 UINT64 BaseMemorySize
;
110 LIST_ENTRY NonTestedMemRanList
;
111 } GENERIC_MEMORY_TEST_PRIVATE
;
113 #define GENERIC_MEMORY_TEST_PRIVATE_FROM_THIS(a) \
116 GENERIC_MEMORY_TEST_PRIVATE, \
118 EFI_GENERIC_MEMORY_TEST_PRIVATE_SIGNATURE \
122 // Function Prototypes
126 Construct the system base memory range through GCD service.
128 @param[in] Private Point to generic memory test driver's private data.
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.
136 ConstructBaseMemoryRange (
137 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
141 Construct the system non-tested memory range through GCD service.
143 @param[in] Private Point to generic memory test driver's private data.
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.
151 ConstructNonTestedMemoryRange (
152 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
156 Perform the address line walking ones test.
158 @param[in] Private Point to generic memory test driver's private data.
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.
167 PerformAddressDataLineTest (
168 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
172 Destroy the link list base on the correspond link list type.
174 @param[in] Private Point to generic memory test driver's private data.
179 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
183 Add the extened memory to whole system memory map.
185 @param[in] Private Point to generic memory test driver's private data.
187 @retval EFI_SUCCESS Successful add all the extended memory to system memory map.
188 @retval Others Failed to add the tested extended memory.
193 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
197 Write the memory test pattern into a range of physical memory.
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.
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.
209 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
,
210 IN EFI_PHYSICAL_ADDRESS Start
,
215 Verify the range of physical memory which covered by memory test pattern.
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.
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.
224 @retval EFI_SUCCESS Successful verify the range of memory, no errors' location found.
225 @retval Others The range of memory have errors contained.
230 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
,
231 IN EFI_PHYSICAL_ADDRESS Start
,
236 Test a range of the memory directly .
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.
243 @retval EFI_SUCCESS Successful test the range of memory.
244 @retval Others Failed to test the range of memory.
249 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
,
250 IN EFI_PHYSICAL_ADDRESS StartAddress
,
252 IN UINT64 Capabilities
256 Initialize the generic memory test.
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.
262 @retval EFI_SUCCESS The generic memory test is initialized correctly.
263 @retval EFI_NO_MEDIA The system had no memory to be tested.
268 InitializeMemoryTest (
269 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
,
270 IN EXTENDMEM_COVERAGE_LEVEL Level
,
271 OUT BOOLEAN
*RequireSoftECCInit
275 Perform the memory test.
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.
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.
291 GenPerformMemoryTest (
292 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
,
293 OUT UINT64
*TestedMemorySize
,
294 OUT UINT64
*TotalMemorySize
,
295 OUT BOOLEAN
*ErrorOut
,
300 Finish the memory test.
302 @param[in] This The protocol instance pointer.
304 @retval EFI_SUCCESS Success. All resources used in the memory test are freed.
309 GenMemoryTestFinished (
310 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
314 Provides the capability to test the compatible range used by some special drivers.
316 @param[in] This The protocol instance pointer.
317 @param[in] StartAddress The start address of the compatible memory range that
319 @param[in] Length The compatible memory range's length.
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.
327 GenCompatibleRangeTest (
328 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
,
329 IN EFI_PHYSICAL_ADDRESS StartAddress
,