2 The generic memory test driver definition
4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions
8 of the BSD License which accompanies this distribution. The
9 full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #ifndef _GENERIC_MEMORY_TEST_H_
18 #define _GENERIC_MEMORY_TEST_H_
20 #include <Guid/StatusCodeDataTypeId.h>
21 #include <Protocol/GenericMemoryTest.h>
22 #include <Protocol/Cpu.h>
24 #include <Library/DebugLib.h>
25 #include <Library/UefiDriverEntryPoint.h>
26 #include <Library/HobLib.h>
27 #include <Library/DxeServicesTableLib.h>
28 #include <Library/ReportStatusCodeLib.h>
29 #include <Library/BaseLib.h>
30 #include <Library/BaseMemoryLib.h>
31 #include <Library/MemoryAllocationLib.h>
32 #include <Library/UefiBootServicesTableLib.h>
37 #define GENERIC_CACHELINE_SIZE 0x40
40 // attributes for reserved memory before it is promoted to system memory
42 #define EFI_MEMORY_PRESENT 0x0100000000000000ULL
43 #define EFI_MEMORY_INITIALIZED 0x0200000000000000ULL
44 #define EFI_MEMORY_TESTED 0x0400000000000000ULL
47 // The SPARSE_SPAN_SIZE size can not small then the MonoTestSize
49 #define TEST_BLOCK_SIZE 0x2000000
50 #define QUICK_SPAN_SIZE (TEST_BLOCK_SIZE >> 2)
51 #define SPARSE_SPAN_SIZE (TEST_BLOCK_SIZE >> 4)
54 // This structure records every nontested memory range parsed through GCD
57 #define EFI_NONTESTED_MEMORY_RANGE_SIGNATURE SIGNATURE_32 ('N', 'T', 'M', 'E')
62 EFI_PHYSICAL_ADDRESS StartAddress
;
66 BOOLEAN AlreadyMapped
;
67 } NONTESTED_MEMORY_RANGE
;
69 #define NONTESTED_MEMORY_RANGE_FROM_LINK(link) \
72 NONTESTED_MEMORY_RANGE, \
74 EFI_NONTESTED_MEMORY_RANGE_SIGNATURE \
78 // This is the memory test driver's structure definition
80 #define EFI_GENERIC_MEMORY_TEST_PRIVATE_SIGNATURE SIGNATURE_32 ('G', 'E', 'M', 'T')
88 // Cpu arch protocol's pointer
90 EFI_CPU_ARCH_PROTOCOL
*Cpu
;
93 // generic memory test driver's protocol
95 EFI_GENERIC_MEMORY_TEST_PROTOCOL GenericMemoryTest
;
98 // memory test covered spans
100 EXTENDMEM_COVERAGE_LEVEL CoverLevel
;
105 // the memory test pattern and size every time R/W/V memory
111 // base memory's size which tested in PEI phase
113 UINT64 BaseMemorySize
;
118 LIST_ENTRY NonTestedMemRanList
;
120 } GENERIC_MEMORY_TEST_PRIVATE
;
122 #define GENERIC_MEMORY_TEST_PRIVATE_FROM_THIS(a) \
125 GENERIC_MEMORY_TEST_PRIVATE, \
127 EFI_GENERIC_MEMORY_TEST_PRIVATE_SIGNATURE \
131 // Function Prototypes
135 Construct the system base memory range through GCD service.
137 @param[in] Private Point to generic memory test driver's private data.
139 @retval EFI_SUCCESS Successful construct the base memory range through GCD service.
140 @retval EFI_OUT_OF_RESOURCE Could not allocate needed resource from base memory.
141 @retval Others Failed to construct base memory range through GCD service.
145 ConstructBaseMemoryRange (
146 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
150 Construct the system non-tested memory range through GCD service.
152 @param[in] Private Point to generic memory test driver's private data.
154 @retval EFI_SUCCESS Successful construct the non-tested memory range through GCD service.
155 @retval EFI_OUT_OF_RESOURCE Could not allocate needed resource from base memory.
156 @retval Others Failed to construct non-tested memory range through GCD service.
160 ConstructNonTestedMemoryRange (
161 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
165 Perform the address line walking ones test.
167 @param[in] Private Point to generic memory test driver's private data.
169 @retval EFI_SUCCESS Successful finished walking ones test.
170 @retval EFI_OUT_OF_RESOURCE Could not get resource in base memory.
171 @retval EFI_ACCESS_DENIED Code may can not run here because if walking one test
172 failed, system may be already halt.
176 PerformAddressDataLineTest (
177 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
181 Destroy the link list base on the correspond link list type.
183 @param[in] Private Point to generic memory test driver's private data.
188 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
192 Add the extened memory to whole system memory map.
194 @param[in] Private Point to generic memory test driver's private data.
196 @retval EFI_SUCCESS Successful add all the extended memory to system memory map.
197 @retval Others Failed to add the tested extended memory.
202 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
206 Write the memory test pattern into a range of physical memory.
208 @param[in] Private Point to generic memory test driver's private data.
209 @param[in] Start The memory range's start address.
210 @param[in] Size The memory range's size.
212 @retval EFI_SUCCESS Successful write the test pattern into the non-tested memory.
213 @retval Others The test pattern may not really write into the physical memory.
218 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
,
219 IN EFI_PHYSICAL_ADDRESS Start
,
224 Verify the range of physical memory which covered by memory test pattern.
226 This function will also do not return any informatin just cause system reset,
227 because the handle error encount fatal error and disable the bad DIMMs.
229 @param[in] Private Point to generic memory test driver's private data.
230 @param[in] Start The memory range's start address.
231 @param[in] Size The memory range's size.
233 @retval EFI_SUCCESS Successful verify the range of memory, no errors' location found.
234 @retval Others The range of memory have errors contained.
239 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
,
240 IN EFI_PHYSICAL_ADDRESS Start
,
245 Test a range of the memory directly .
247 @param[in] Private Point to generic memory test driver's private data.
248 @param[in] StartAddress Starting address of the memory range to be tested.
249 @param[in] Length Length in bytes of the memory range to be tested.
250 @param[in] Capabilities The bit mask of attributes that the memory range supports.
252 @retval EFI_SUCCESS Successful test the range of memory.
253 @retval Others Failed to test the range of memory.
258 IN GENERIC_MEMORY_TEST_PRIVATE
*Private
,
259 IN EFI_PHYSICAL_ADDRESS StartAddress
,
261 IN UINT64 Capabilities
265 Initialize the generic memory test.
267 @param[in] This The protocol instance pointer.
268 @param[in] Level The coverage level of the memory test.
269 @param[out] RequireSoftECCInit Indicate if the memory need software ECC init.
271 @retval EFI_SUCCESS The generic memory test is initialized correctly.
272 @retval EFI_NO_MEDIA The system had no memory to be tested.
277 InitializeMemoryTest (
278 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
,
279 IN EXTENDMEM_COVERAGE_LEVEL Level
,
280 OUT BOOLEAN
*RequireSoftECCInit
284 Perform the memory test.
286 @param[in] This The protocol instance pointer.
287 @param[out] TestedMemorySize Return the tested extended memory size.
288 @param[out] TotalMemorySize Return the whole system physical memory size.
289 The total memory size does not include memory in a slot with a disabled DIMM.
290 @param[out] ErrorOut TRUE if the memory error occured.
291 @param[in] IfTestAbort Indicates that the user pressed "ESC" to skip the memory test.
293 @retval EFI_SUCCESS One block of memory passed the test.
294 @retval EFI_NOT_FOUND All memory blocks have already been tested.
295 @retval EFI_DEVICE_ERROR Memory device error occured, and no agent can handle it.
300 GenPerformMemoryTest (
301 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
,
302 OUT UINT64
*TestedMemorySize
,
303 OUT UINT64
*TotalMemorySize
,
304 OUT BOOLEAN
*ErrorOut
,
309 Finish the memory test.
311 @param[in] This The protocol instance pointer.
313 @retval EFI_SUCCESS Success. All resources used in the memory test are freed.
318 GenMemoryTestFinished (
319 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
323 Provides the capability to test the compatible range used by some special drivers.
325 @param[in] This The protocol instance pointer.
326 @param[in] StartAddress The start address of the compatible memory range that
328 @param[in] Length The compatible memory range's length.
330 @retval EFI_SUCCESS The compatible memory range pass the memory test.
331 @retval EFI_INVALID_PARAMETER The compatible memory range are not below Low 16M.
336 GenCompatibleRangeTest (
337 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
,
338 IN EFI_PHYSICAL_ADDRESS StartAddress
,