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
23 // The package level header files this module uses
26 #include <FrameworkPei.h>
28 // The protocols, PPI and GUID defintions for this module
30 #include <Ppi/BaseMemoryTest.h>
32 // The Library classes this module consumes
34 #include <Library/DebugLib.h>
35 #include <Library/PeimEntryPoint.h>
36 #include <Library/ReportStatusCodeLib.h>
38 #include <BaseMemoryTest.h>
40 static PEI_BASE_MEMORY_TEST_PPI mPeiBaseMemoryTestPpi
= { BaseMemoryTest
};
42 static EFI_PEI_PPI_DESCRIPTOR PpiListPeiBaseMemoryTest
= {
43 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
44 &gPeiBaseMemoryTestPpiGuid
,
45 &mPeiBaseMemoryTestPpi
50 PeiBaseMemoryTestInit (
51 IN EFI_FFS_FILE_HEADER
*FfsHeader
,
52 IN EFI_PEI_SERVICES
**PeiServices
57 Entry point function of BaseMemoryTestInit Peim.
61 PeiServices - General purpose services available to every PEIM.
62 FfsHeader - Ffs header pointer
66 Status - Result of InstallPpi
72 Status
= (**PeiServices
).InstallPpi (PeiServices
, &PpiListPeiBaseMemoryTest
);
80 IN EFI_PEI_SERVICES
**PeiServices
,
81 IN PEI_BASE_MEMORY_TEST_PPI
*This
,
82 IN EFI_PHYSICAL_ADDRESS BeginAddress
,
83 IN UINT64 MemoryLength
,
84 IN PEI_MEMORY_TEST_OP Operation
,
85 OUT EFI_PHYSICAL_ADDRESS
*ErrorAddress
94 PeiServices - General purpose services available to every PEIM.
95 This - Pei memory test PPI pointer.
96 BeginAddress - Beginning of the memory address to be checked.
97 MemoryLength - Bytes of memory range to be checked.
98 Operation - Type of memory check operation to be performed.
99 ErrorAddress - Return the address of the error memory address.
100 ErrorAddress - Address which has error when checked.
104 Status - Result of InstallPpi
109 EFI_PHYSICAL_ADDRESS TempAddress
;
114 EFI_COMPUTING_UNIT_MEMORY
+ EFI_CU_MEMORY_PC_TEST
117 TestPattern
= TEST_PATTERN
;
121 // Make sure we don't try and test anything above the max physical address range
123 ASSERT (BeginAddress
+ MemoryLength
< EFI_MAX_ADDRESS
);
132 SpanSize
= COVER_SPAN
;
140 // Write the test pattern into memory range
142 TempAddress
= BeginAddress
;
143 while (TempAddress
< BeginAddress
+ MemoryLength
) {
144 (*(UINT32
*) (UINTN
) TempAddress
) = TestPattern
;
145 TempAddress
+= SpanSize
;
148 // Read pattern from memory and compare it
150 TempAddress
= BeginAddress
;
151 while (TempAddress
< BeginAddress
+ MemoryLength
) {
152 if ((*(UINT32
*) (UINTN
) TempAddress
) != TestPattern
) {
153 *ErrorAddress
= TempAddress
;
155 EFI_ERROR_CODE
| EFI_ERROR_UNRECOVERED
,
156 EFI_COMPUTING_UNIT_MEMORY
| EFI_CU_MEMORY_EC_UNCORRECTABLE
159 return EFI_DEVICE_ERROR
;
162 TempAddress
+= SpanSize
;