2 Support of memory test in PEI Phase.
4 Copyright (c) 2006 - 2008, Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "BaseMemoryTest.h"
17 PEI_BASE_MEMORY_TEST_PPI mPeiBaseMemoryTestPpi
= {
21 EFI_PEI_PPI_DESCRIPTOR PpiListPeiBaseMemoryTest
= {
22 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
23 &gPeiBaseMemoryTestPpiGuid
,
24 &mPeiBaseMemoryTestPpi
28 Entry point of BaseMemoryTestPei PEIM.
30 This function is the entry point of BaseMemoryTestPei PEIM.
31 It installs the PEI_BASE_MEMORY_TEST_PPI.
33 @param FileHandle Handle of the file being invoked.
34 @param PeiServices Describes the list of possible PEI Services.
36 @retval EFI_SUCCESS PEI_BASE_MEMORY_TEST_PPI is successfully installed.
37 @retval Others PEI_BASE_MEMORY_TEST_PPI is not successfully installed.
42 PeiBaseMemoryTestInit (
43 IN EFI_PEI_FILE_HANDLE FileHandle
,
44 IN CONST EFI_PEI_SERVICES
**PeiServices
47 return PeiServicesInstallPpi (&PpiListPeiBaseMemoryTest
);
54 @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.
55 @param This Pointer to this PPI instance.
56 @param BeginAddress Beginning of the memory address to be checked.
57 @param MemoryLength Bytes of memory range to be checked.
58 @param Operation Type of memory check operation to be performed.
59 @param ErrorAddress Pointer to address of the error memory returned.
61 @retval EFI_SUCCESS Memory test passed.
62 @retval EFI_DEVICE_ERROR Memory test failed.
68 IN EFI_PEI_SERVICES
**PeiServices
,
69 IN PEI_BASE_MEMORY_TEST_PPI
*This
,
70 IN EFI_PHYSICAL_ADDRESS BeginAddress
,
71 IN UINT64 MemoryLength
,
72 IN PEI_MEMORY_TEST_OP Operation
,
73 OUT EFI_PHYSICAL_ADDRESS
*ErrorAddress
77 EFI_PHYSICAL_ADDRESS TempAddress
;
80 REPORT_STATUS_CODE (EFI_PROGRESS_CODE
, PcdGet32 (PcdStatusCodeValueMemoryTestStarted
));
82 TestPattern
= TEST_PATTERN
;
86 // Make sure we don't try and test anything above the max physical address range
88 ASSERT (BeginAddress
+ MemoryLength
< MAX_ADDRESS
);
93 // Extensive means full and detailed check,
94 // so use small span size to cover the entire test range.
102 // Sparse and Quick indicates quick test,
103 // so use large span size for sample test.
105 SpanSize
= COVER_SPAN
;
110 // Ignore means no test.
116 // Write the test pattern into memory range
118 TempAddress
= BeginAddress
;
119 while (TempAddress
< BeginAddress
+ MemoryLength
) {
120 (*(UINT32
*) (UINTN
) TempAddress
) = TestPattern
;
121 TempAddress
+= SpanSize
;
124 // Read pattern from memory and compare it
126 TempAddress
= BeginAddress
;
127 while (TempAddress
< BeginAddress
+ MemoryLength
) {
128 if ((*(UINT32
*) (UINTN
) TempAddress
) != TestPattern
) {
130 // Value read back does not equal to the value written, so error is detected.
132 *ErrorAddress
= TempAddress
;
133 REPORT_STATUS_CODE (EFI_ERROR_CODE
| EFI_ERROR_UNRECOVERED
, PcdGet32 (PcdStatusCodeValueUncorrectableMemoryError
));
135 return EFI_DEVICE_ERROR
;
138 TempAddress
+= SpanSize
;