-/** @file\r
- Support of memory test in PEI Phase.\r
-\r
-Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The 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
-#include "BaseMemoryTest.h"\r
-\r
-PEI_BASE_MEMORY_TEST_PPI mPeiBaseMemoryTestPpi = {\r
- BaseMemoryTest\r
-};\r
-\r
-EFI_PEI_PPI_DESCRIPTOR PpiListPeiBaseMemoryTest = {\r
- (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
- &gPeiBaseMemoryTestPpiGuid,\r
- &mPeiBaseMemoryTestPpi\r
-};\r
-\r
-/**\r
- Entry point of BaseMemoryTestPei PEIM.\r
-\r
- This function is the entry point of BaseMemoryTestPei PEIM.\r
- It installs the PEI_BASE_MEMORY_TEST_PPI.\r
-\r
- @param FileHandle Handle of the file being invoked.\r
- @param PeiServices Describes the list of possible PEI Services.\r
-\r
- @retval EFI_SUCCESS PEI_BASE_MEMORY_TEST_PPI is successfully installed.\r
- @retval Others PEI_BASE_MEMORY_TEST_PPI is not successfully installed.\r
-\r
-**/ \r
-EFI_STATUS\r
-EFIAPI\r
-PeiBaseMemoryTestInit (\r
- IN EFI_PEI_FILE_HANDLE FileHandle,\r
- IN CONST EFI_PEI_SERVICES **PeiServices\r
- )\r
-{\r
- return PeiServicesInstallPpi (&PpiListPeiBaseMemoryTest);\r
- \r
-}\r
-\r
-/**\r
- Test base memory.\r
-\r
- @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.\r
- @param This Pointer to this PPI instance.\r
- @param BeginAddress Beginning of the memory address to be checked.\r
- @param MemoryLength Bytes of memory range to be checked.\r
- @param Operation Type of memory check operation to be performed.\r
- @param ErrorAddress Pointer to address of the error memory returned.\r
-\r
- @retval EFI_SUCCESS Memory test passed.\r
- @retval EFI_DEVICE_ERROR Memory test failed.\r
-\r
-**/ \r
-EFI_STATUS\r
-EFIAPI\r
-BaseMemoryTest (\r
- IN EFI_PEI_SERVICES **PeiServices,\r
- IN PEI_BASE_MEMORY_TEST_PPI *This,\r
- IN EFI_PHYSICAL_ADDRESS BeginAddress,\r
- IN UINT64 MemoryLength,\r
- IN PEI_MEMORY_TEST_OP Operation,\r
- OUT EFI_PHYSICAL_ADDRESS *ErrorAddress\r
- )\r
-{\r
- UINT32 TestPattern;\r
- EFI_PHYSICAL_ADDRESS TempAddress;\r
- UINT32 SpanSize;\r
-\r
- REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdStatusCodeValueMemoryTestStarted));\r
-\r
- TestPattern = TEST_PATTERN;\r
- SpanSize = 0;\r
-\r
- //\r
- // Make sure we don't try and test anything above the max physical address range\r
- //\r
- ASSERT (BeginAddress + MemoryLength < MAX_ADDRESS);\r
-\r
- switch (Operation) {\r
- case Extensive:\r
- //\r
- // Extensive means full and detailed check,\r
- // so use small span size to cover the entire test range.\r
- //\r
- SpanSize = 0x4;\r
- break;\r
-\r
- case Sparse:\r
- case Quick:\r
- //\r
- // Sparse and Quick indicates quick test,\r
- // so use large span size for sample test.\r
- //\r
- SpanSize = COVER_SPAN;\r
- break;\r
-\r
- case Ignore:\r
- //\r
- // Ignore means no test.\r
- //\r
- goto Done;\r
- break;\r
- }\r
- //\r
- // Write the test pattern into memory range\r
- //\r
- TempAddress = BeginAddress;\r
- while (TempAddress < BeginAddress + MemoryLength) {\r
- (*(UINT32 *) (UINTN) TempAddress) = TestPattern;\r
- TempAddress += SpanSize;\r
- }\r
- //\r
- // Read pattern from memory and compare it\r
- //\r
- TempAddress = BeginAddress;\r
- while (TempAddress < BeginAddress + MemoryLength) {\r
- if ((*(UINT32 *) (UINTN) TempAddress) != TestPattern) {\r
- //\r
- // Value read back does not equal to the value written, so error is detected.\r
- //\r
- *ErrorAddress = TempAddress;\r
- REPORT_STATUS_CODE (EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED, PcdGet32 (PcdStatusCodeValueUncorrectableMemoryError));\r
-\r
- return EFI_DEVICE_ERROR;\r
- }\r
-\r
- TempAddress += SpanSize;\r
- }\r
-\r
-Done:\r
- return EFI_SUCCESS;\r
-}\r