3 Copyright (c) 2006 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 The PEI memory test support
22 #include <BaseMemoryTest.h>
24 static PEI_BASE_MEMORY_TEST_PPI mPeiBaseMemoryTestPpi
= { BaseMemoryTest
};
26 static EFI_PEI_PPI_DESCRIPTOR PpiListPeiBaseMemoryTest
= {
27 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
28 &gPeiBaseMemoryTestPpiGuid
,
29 &mPeiBaseMemoryTestPpi
34 PeiBaseMemoryTestInit (
35 IN EFI_FFS_FILE_HEADER
*FfsHeader
,
36 IN EFI_PEI_SERVICES
**PeiServices
41 Entry point function of BaseMemoryTestInit Peim.
45 PeiServices - General purpose services available to every PEIM.
46 FfsHeader - Ffs header pointer
50 Status - Result of InstallPpi
56 Status
= (**PeiServices
).InstallPpi (PeiServices
, &PpiListPeiBaseMemoryTest
);
64 IN EFI_PEI_SERVICES
**PeiServices
,
65 IN PEI_BASE_MEMORY_TEST_PPI
*This
,
66 IN EFI_PHYSICAL_ADDRESS BeginAddress
,
67 IN UINT64 MemoryLength
,
68 IN PEI_MEMORY_TEST_OP Operation
,
69 OUT EFI_PHYSICAL_ADDRESS
*ErrorAddress
78 PeiServices - General purpose services available to every PEIM.
79 This - Pei memory test PPI pointer.
80 BeginAddress - Beginning of the memory address to be checked.
81 MemoryLength - Bytes of memory range to be checked.
82 Operation - Type of memory check operation to be performed.
83 ErrorAddress - Return the address of the error memory address.
84 ErrorAddress - Address which has error when checked.
88 Status - Result of InstallPpi
93 EFI_PHYSICAL_ADDRESS TempAddress
;
96 REPORT_STATUS_CODE (EFI_PROGRESS_CODE
, PcdGet32 (PcdStatusCodeValueMemoryTestStarted
));
98 TestPattern
= TEST_PATTERN
;
102 // Make sure we don't try and test anything above the max physical address range
104 ASSERT (BeginAddress
+ MemoryLength
< EFI_MAX_ADDRESS
);
113 SpanSize
= COVER_SPAN
;
121 // Write the test pattern into memory range
123 TempAddress
= BeginAddress
;
124 while (TempAddress
< BeginAddress
+ MemoryLength
) {
125 (*(UINT32
*) (UINTN
) TempAddress
) = TestPattern
;
126 TempAddress
+= SpanSize
;
129 // Read pattern from memory and compare it
131 TempAddress
= BeginAddress
;
132 while (TempAddress
< BeginAddress
+ MemoryLength
) {
133 if ((*(UINT32
*) (UINTN
) TempAddress
) != TestPattern
) {
134 *ErrorAddress
= TempAddress
;
135 REPORT_STATUS_CODE (EFI_ERROR_CODE
| EFI_ERROR_UNRECOVERED
, PcdGet32 (PcdStatusCodeValueUncorrectableMemoryError
));
137 return EFI_DEVICE_ERROR
;
140 TempAddress
+= SpanSize
;