1 /** @file 2 The generic memory test driver definition 3 4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR> 5 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 11 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. 14 15 **/ 16 17 #ifndef _GENERIC_MEMORY_TEST_H_ 18 #define _GENERIC_MEMORY_TEST_H_ 19 20 #include <Guid/StatusCodeDataTypeId.h> 21 #include <Protocol/GenericMemoryTest.h> 22 #include <Protocol/Cpu.h> 23 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> 33 34 // 35 // Some global define 36 // 37 #define GENERIC_CACHELINE_SIZE 0x40 38 39 // 40 // attributes for reserved memory before it is promoted to system memory 41 // 42 #define EFI_MEMORY_PRESENT 0x0100000000000000ULL 43 #define EFI_MEMORY_INITIALIZED 0x0200000000000000ULL 44 #define EFI_MEMORY_TESTED 0x0400000000000000ULL 45 46 // 47 // The SPARSE_SPAN_SIZE size can not small then the MonoTestSize 48 // 49 #define TEST_BLOCK_SIZE 0x2000000 50 #define QUICK_SPAN_SIZE (TEST_BLOCK_SIZE >> 2) 51 #define SPARSE_SPAN_SIZE (TEST_BLOCK_SIZE >> 4) 52 53 // 54 // This structure records every nontested memory range parsed through GCD 55 // service. 56 // 57 #define EFI_NONTESTED_MEMORY_RANGE_SIGNATURE SIGNATURE_32 ('N', 'T', 'M', 'E') 58 59 typedef struct { 60 UINTN Signature; 61 LIST_ENTRY Link; 62 EFI_PHYSICAL_ADDRESS StartAddress; 63 UINT64 Length; 64 UINT64 Capabilities; 65 BOOLEAN Above4G; 66 BOOLEAN AlreadyMapped; 67 } NONTESTED_MEMORY_RANGE; 68 69 #define NONTESTED_MEMORY_RANGE_FROM_LINK(link) \ 70 CR ( \ 71 link, \ 72 NONTESTED_MEMORY_RANGE, \ 73 Link, \ 74 EFI_NONTESTED_MEMORY_RANGE_SIGNATURE \ 75 ) 76 77 // 78 // This is the memory test driver's structure definition 79 // 80 #define EFI_GENERIC_MEMORY_TEST_PRIVATE_SIGNATURE SIGNATURE_32 ('G', 'E', 'M', 'T') 81 82 typedef struct { 83 84 UINTN Signature; 85 EFI_HANDLE Handle; 86 87 // 88 // Cpu arch protocol's pointer 89 // 90 EFI_CPU_ARCH_PROTOCOL *Cpu; 91 92 // 93 // generic memory test driver's protocol 94 // 95 EFI_GENERIC_MEMORY_TEST_PROTOCOL GenericMemoryTest; 96 97 // 98 // memory test covered spans 99 // 100 EXTENDMEM_COVERAGE_LEVEL CoverLevel; 101 UINTN CoverageSpan; 102 UINT64 BdsBlockSize; 103 104 // 105 // the memory test pattern and size every time R/W/V memory 106 // 107 VOID *MonoPattern; 108 UINTN MonoTestSize; 109 110 // 111 // base memory's size which tested in PEI phase 112 // 113 UINT64 BaseMemorySize; 114 115 // 116 // memory range list 117 // 118 LIST_ENTRY NonTestedMemRanList; 119 120 } GENERIC_MEMORY_TEST_PRIVATE; 121 122 #define GENERIC_MEMORY_TEST_PRIVATE_FROM_THIS(a) \ 123 CR ( \ 124 a, \ 125 GENERIC_MEMORY_TEST_PRIVATE, \ 126 GenericMemoryTest, \ 127 EFI_GENERIC_MEMORY_TEST_PRIVATE_SIGNATURE \ 128 ) 129 130 // 131 // Function Prototypes 132 // 133 134 /** 135 Construct the system base memory range through GCD service. 136 137 @param[in] Private Point to generic memory test driver's private data. 138 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. 142 143 **/ 144 EFI_STATUS 145 ConstructBaseMemoryRange ( 146 IN GENERIC_MEMORY_TEST_PRIVATE *Private 147 ); 148 149 /** 150 Construct the system non-tested memory range through GCD service. 151 152 @param[in] Private Point to generic memory test driver's private data. 153 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. 157 158 **/ 159 EFI_STATUS 160 ConstructNonTestedMemoryRange ( 161 IN GENERIC_MEMORY_TEST_PRIVATE *Private 162 ); 163 164 /** 165 Perform the address line walking ones test. 166 167 @param[in] Private Point to generic memory test driver's private data. 168 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. 173 174 **/ 175 EFI_STATUS 176 PerformAddressDataLineTest ( 177 IN GENERIC_MEMORY_TEST_PRIVATE *Private 178 ); 179 180 /** 181 Destroy the link list base on the correspond link list type. 182 183 @param[in] Private Point to generic memory test driver's private data. 184 185 **/ 186 VOID 187 DestroyLinkList ( 188 IN GENERIC_MEMORY_TEST_PRIVATE *Private 189 ); 190 191 /** 192 Add the extened memory to whole system memory map. 193 194 @param[in] Private Point to generic memory test driver's private data. 195 196 @retval EFI_SUCCESS Successful add all the extended memory to system memory map. 197 @retval Others Failed to add the tested extended memory. 198 199 **/ 200 EFI_STATUS 201 UpdateMemoryMap ( 202 IN GENERIC_MEMORY_TEST_PRIVATE *Private 203 ); 204 205 /** 206 Write the memory test pattern into a range of physical memory. 207 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. 211 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. 214 215 **/ 216 EFI_STATUS 217 WriteMemory ( 218 IN GENERIC_MEMORY_TEST_PRIVATE *Private, 219 IN EFI_PHYSICAL_ADDRESS Start, 220 IN UINT64 Size 221 ); 222 223 /** 224 Verify the range of physical memory which covered by memory test pattern. 225 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. 228 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. 232 233 @retval EFI_SUCCESS Successful verify the range of memory, no errors' location found. 234 @retval Others The range of memory have errors contained. 235 236 **/ 237 EFI_STATUS 238 VerifyMemory ( 239 IN GENERIC_MEMORY_TEST_PRIVATE *Private, 240 IN EFI_PHYSICAL_ADDRESS Start, 241 IN UINT64 Size 242 ); 243 244 /** 245 Test a range of the memory directly . 246 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. 251 252 @retval EFI_SUCCESS Successful test the range of memory. 253 @retval Others Failed to test the range of memory. 254 255 **/ 256 EFI_STATUS 257 DirectRangeTest ( 258 IN GENERIC_MEMORY_TEST_PRIVATE *Private, 259 IN EFI_PHYSICAL_ADDRESS StartAddress, 260 IN UINT64 Length, 261 IN UINT64 Capabilities 262 ); 263 264 /** 265 Initialize the generic memory test. 266 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. 270 271 @retval EFI_SUCCESS The generic memory test is initialized correctly. 272 @retval EFI_NO_MEDIA The system had no memory to be tested. 273 274 **/ 275 EFI_STATUS 276 EFIAPI 277 InitializeMemoryTest ( 278 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This, 279 IN EXTENDMEM_COVERAGE_LEVEL Level, 280 OUT BOOLEAN *RequireSoftECCInit 281 ); 282 283 /** 284 Perform the memory test. 285 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. 292 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. 296 297 **/ 298 EFI_STATUS 299 EFIAPI 300 GenPerformMemoryTest ( 301 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This, 302 OUT UINT64 *TestedMemorySize, 303 OUT UINT64 *TotalMemorySize, 304 OUT BOOLEAN *ErrorOut, 305 IN BOOLEAN TestAbort 306 ); 307 308 /** 309 Finish the memory test. 310 311 @param[in] This The protocol instance pointer. 312 313 @retval EFI_SUCCESS Success. All resources used in the memory test are freed. 314 315 **/ 316 EFI_STATUS 317 EFIAPI 318 GenMemoryTestFinished ( 319 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This 320 ); 321 322 /** 323 Provides the capability to test the compatible range used by some special drivers. 324 325 @param[in] This The protocol instance pointer. 326 @param[in] StartAddress The start address of the compatible memory range that 327 must be below 16M. 328 @param[in] Length The compatible memory range's length. 329 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. 332 333 **/ 334 EFI_STATUS 335 EFIAPI 336 GenCompatibleRangeTest ( 337 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This, 338 IN EFI_PHYSICAL_ADDRESS StartAddress, 339 IN UINT64 Length 340 ); 341 342 #endif 343