--- /dev/null
+/** @file\r
+ The generic memory test driver definition\r
+\r
+ Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+\r
+ This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions\r
+ of the BSD License which accompanies this distribution. The\r
+ full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef _GENERIC_MEMORY_TEST_H_\r
+#define _GENERIC_MEMORY_TEST_H_\r
+\r
+#include <Guid/StatusCodeDataTypeId.h>\r
+#include <Protocol/GenericMemoryTest.h>\r
+#include <Protocol/Cpu.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/DxeServicesTableLib.h>\r
+#include <Library/ReportStatusCodeLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+//\r
+// Some global define\r
+//\r
+#define GENERIC_CACHELINE_SIZE 0x40\r
+\r
+//\r
+// attributes for reserved memory before it is promoted to system memory\r
+//\r
+#define EFI_MEMORY_PRESENT 0x0100000000000000ULL\r
+#define EFI_MEMORY_INITIALIZED 0x0200000000000000ULL\r
+#define EFI_MEMORY_TESTED 0x0400000000000000ULL\r
+\r
+//\r
+// The SPARSE_SPAN_SIZE size can not small then the MonoTestSize\r
+//\r
+#define TEST_BLOCK_SIZE 0x2000000\r
+#define QUICK_SPAN_SIZE (TEST_BLOCK_SIZE >> 2)\r
+#define SPARSE_SPAN_SIZE (TEST_BLOCK_SIZE >> 4)\r
+\r
+//\r
+// This structure records every nontested memory range parsed through GCD\r
+// service.\r
+//\r
+#define EFI_NONTESTED_MEMORY_RANGE_SIGNATURE SIGNATURE_32 ('N', 'T', 'M', 'E')\r
+\r
+typedef struct {\r
+ UINTN Signature;\r
+ LIST_ENTRY Link;\r
+ EFI_PHYSICAL_ADDRESS StartAddress;\r
+ UINT64 Length;\r
+ UINT64 Capabilities;\r
+ BOOLEAN Above4G;\r
+ BOOLEAN AlreadyMapped;\r
+} NONTESTED_MEMORY_RANGE;\r
+\r
+#define NONTESTED_MEMORY_RANGE_FROM_LINK(link) \\r
+ CR ( \\r
+ link, \\r
+ NONTESTED_MEMORY_RANGE, \\r
+ Link, \\r
+ EFI_NONTESTED_MEMORY_RANGE_SIGNATURE \\r
+ )\r
+\r
+//\r
+// This is the memory test driver's structure definition\r
+//\r
+#define EFI_GENERIC_MEMORY_TEST_PRIVATE_SIGNATURE SIGNATURE_32 ('G', 'E', 'M', 'T')\r
+\r
+typedef struct {\r
+\r
+ UINTN Signature;\r
+ EFI_HANDLE Handle;\r
+\r
+ //\r
+ // Cpu arch protocol's pointer\r
+ //\r
+ EFI_CPU_ARCH_PROTOCOL *Cpu;\r
+\r
+ //\r
+ // generic memory test driver's protocol\r
+ //\r
+ EFI_GENERIC_MEMORY_TEST_PROTOCOL GenericMemoryTest;\r
+\r
+ //\r
+ // memory test covered spans\r
+ //\r
+ EXTENDMEM_COVERAGE_LEVEL CoverLevel;\r
+ UINTN CoverageSpan;\r
+ UINT64 BdsBlockSize;\r
+\r
+ //\r
+ // the memory test pattern and size every time R/W/V memory\r
+ //\r
+ VOID *MonoPattern;\r
+ UINTN MonoTestSize;\r
+\r
+ //\r
+ // base memory's size which tested in PEI phase\r
+ //\r
+ UINT64 BaseMemorySize;\r
+\r
+ //\r
+ // memory range list\r
+ //\r
+ LIST_ENTRY NonTestedMemRanList;\r
+\r
+} GENERIC_MEMORY_TEST_PRIVATE;\r
+\r
+#define GENERIC_MEMORY_TEST_PRIVATE_FROM_THIS(a) \\r
+ CR ( \\r
+ a, \\r
+ GENERIC_MEMORY_TEST_PRIVATE, \\r
+ GenericMemoryTest, \\r
+ EFI_GENERIC_MEMORY_TEST_PRIVATE_SIGNATURE \\r
+ )\r
+\r
+//\r
+// Function Prototypes\r
+//\r
+\r
+/**\r
+ Construct the system base memory range through GCD service.\r
+\r
+ @param[in] Private Point to generic memory test driver's private data.\r
+\r
+ @retval EFI_SUCCESS Successful construct the base memory range through GCD service.\r
+ @retval EFI_OUT_OF_RESOURCE Could not allocate needed resource from base memory.\r
+ @retval Others Failed to construct base memory range through GCD service.\r
+ \r
+**/\r
+EFI_STATUS\r
+ConstructBaseMemoryRange (\r
+ IN GENERIC_MEMORY_TEST_PRIVATE *Private\r
+ );\r
+\r
+/**\r
+ Construct the system non-tested memory range through GCD service.\r
+\r
+ @param[in] Private Point to generic memory test driver's private data.\r
+\r
+ @retval EFI_SUCCESS Successful construct the non-tested memory range through GCD service.\r
+ @retval EFI_OUT_OF_RESOURCE Could not allocate needed resource from base memory.\r
+ @retval Others Failed to construct non-tested memory range through GCD service.\r
+ \r
+**/\r
+EFI_STATUS\r
+ConstructNonTestedMemoryRange (\r
+ IN GENERIC_MEMORY_TEST_PRIVATE *Private\r
+ );\r
+\r
+/**\r
+ Perform the address line walking ones test.\r
+\r
+ @param[in] Private Point to generic memory test driver's private data.\r
+ \r
+ @retval EFI_SUCCESS Successful finished walking ones test. \r
+ @retval EFI_OUT_OF_RESOURCE Could not get resource in base memory. \r
+ @retval EFI_ACCESS_DENIED Code may can not run here because if walking one test\r
+ failed, system may be already halt.\r
+\r
+**/\r
+EFI_STATUS\r
+PerformAddressDataLineTest (\r
+ IN GENERIC_MEMORY_TEST_PRIVATE *Private\r
+ );\r
+\r
+/**\r
+ Destroy the link list base on the correspond link list type.\r
+\r
+ @param[in] Private Point to generic memory test driver's private data.\r
+ \r
+**/\r
+VOID\r
+DestroyLinkList (\r
+ IN GENERIC_MEMORY_TEST_PRIVATE *Private\r
+ );\r
+\r
+/**\r
+ Add the extened memory to whole system memory map.\r
+\r
+ @param[in] Private Point to generic memory test driver's private data.\r
+\r
+ @retval EFI_SUCCESS Successful add all the extended memory to system memory map.\r
+ @retval Others Failed to add the tested extended memory.\r
+ \r
+**/\r
+EFI_STATUS\r
+UpdateMemoryMap (\r
+ IN GENERIC_MEMORY_TEST_PRIVATE *Private\r
+ );\r
+\r
+/**\r
+ Write the memory test pattern into a range of physical memory.\r
+\r
+ @param[in] Private Point to generic memory test driver's private data.\r
+ @param[in] Start The memory range's start address.\r
+ @param[in] Size The memory range's size.\r
+\r
+ @retval EFI_SUCCESS Successful write the test pattern into the non-tested memory.\r
+ @retval Others The test pattern may not really write into the physical memory.\r
+ \r
+**/\r
+EFI_STATUS\r
+WriteMemory (\r
+ IN GENERIC_MEMORY_TEST_PRIVATE *Private,\r
+ IN EFI_PHYSICAL_ADDRESS Start,\r
+ IN UINT64 Size\r
+ );\r
+\r
+/**\r
+ Verify the range of physical memory which covered by memory test pattern.\r
+\r
+ This function will also do not return any informatin just cause system reset,\r
+ because the handle error encount fatal error and disable the bad DIMMs.\r
+\r
+ @param[in] Private Point to generic memory test driver's private data.\r
+ @param[in] Start The memory range's start address.\r
+ @param[in] Size The memory range's size.\r
+\r
+ @retval EFI_SUCCESS Successful verify the range of memory, no errors' location found.\r
+ @retval Others The range of memory have errors contained.\r
+ \r
+**/\r
+EFI_STATUS\r
+VerifyMemory (\r
+ IN GENERIC_MEMORY_TEST_PRIVATE *Private,\r
+ IN EFI_PHYSICAL_ADDRESS Start,\r
+ IN UINT64 Size\r
+ );\r
+\r
+/**\r
+ Test a range of the memory directly .\r
+\r
+ @param[in] Private Point to generic memory test driver's private data.\r
+ @param[in] StartAddress Starting address of the memory range to be tested.\r
+ @param[in] Length Length in bytes of the memory range to be tested.\r
+ @param[in] Capabilities The bit mask of attributes that the memory range supports.\r
+\r
+ @retval EFI_SUCCESS Successful test the range of memory.\r
+ @retval Others Failed to test the range of memory.\r
+ \r
+**/\r
+EFI_STATUS\r
+DirectRangeTest (\r
+ IN GENERIC_MEMORY_TEST_PRIVATE *Private,\r
+ IN EFI_PHYSICAL_ADDRESS StartAddress,\r
+ IN UINT64 Length,\r
+ IN UINT64 Capabilities\r
+ );\r
+\r
+/**\r
+ Initialize the generic memory test.\r
+\r
+ @param[in] This The protocol instance pointer. \r
+ @param[in] Level The coverage level of the memory test. \r
+ @param[out] RequireSoftECCInit Indicate if the memory need software ECC init. \r
+\r
+ @retval EFI_SUCCESS The generic memory test is initialized correctly. \r
+ @retval EFI_NO_MEDIA The system had no memory to be tested. \r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeMemoryTest (\r
+ IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,\r
+ IN EXTENDMEM_COVERAGE_LEVEL Level,\r
+ OUT BOOLEAN *RequireSoftECCInit\r
+ );\r
+\r
+/**\r
+ Perform the memory test.\r
+\r
+ @param[in] This The protocol instance pointer. \r
+ @param[out] TestedMemorySize Return the tested extended memory size. \r
+ @param[out] TotalMemorySize Return the whole system physical memory size. \r
+ The total memory size does not include memory in a slot with a disabled DIMM. \r
+ @param[out] ErrorOut TRUE if the memory error occured.\r
+ @param[in] IfTestAbort Indicates that the user pressed "ESC" to skip the memory test. \r
+\r
+ @retval EFI_SUCCESS One block of memory passed the test.\r
+ @retval EFI_NOT_FOUND All memory blocks have already been tested.\r
+ @retval EFI_DEVICE_ERROR Memory device error occured, and no agent can handle it.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GenPerformMemoryTest (\r
+ IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,\r
+ OUT UINT64 *TestedMemorySize,\r
+ OUT UINT64 *TotalMemorySize,\r
+ OUT BOOLEAN *ErrorOut,\r
+ IN BOOLEAN TestAbort\r
+ );\r
+\r
+/**\r
+ Finish the memory test.\r
+\r
+ @param[in] This The protocol instance pointer. \r
+\r
+ @retval EFI_SUCCESS Success. All resources used in the memory test are freed.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GenMemoryTestFinished (\r
+ IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This\r
+ );\r
+\r
+/**\r
+ Provides the capability to test the compatible range used by some special drivers.\r
+\r
+ @param[in] This The protocol instance pointer. \r
+ @param[in] StartAddress The start address of the compatible memory range that\r
+ must be below 16M.\r
+ @param[in] Length The compatible memory range's length. \r
+ \r
+ @retval EFI_SUCCESS The compatible memory range pass the memory test. \r
+ @retval EFI_INVALID_PARAMETER The compatible memory range are not below Low 16M.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GenCompatibleRangeTest (\r
+ IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,\r
+ IN EFI_PHYSICAL_ADDRESS StartAddress,\r
+ IN UINT64 Length\r
+ );\r
+\r
+#endif\r