3 Copyright (c) 2006, 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>
23 #include <Library/ReportStatusCodeLib.h>
25 static PEI_BASE_MEMORY_TEST_PPI mPeiBaseMemoryTestPpi
= { BaseMemoryTest
};
27 static EFI_PEI_PPI_DESCRIPTOR PpiListPeiBaseMemoryTest
= {
28 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
29 &gPeiBaseMemoryTestPpiGuid
,
30 &mPeiBaseMemoryTestPpi
35 PeiBaseMemoryTestInit (
36 IN EFI_FFS_FILE_HEADER
*FfsHeader
,
37 IN EFI_PEI_SERVICES
**PeiServices
42 Entry point function of BaseMemoryTestInit Peim.
46 PeiServices - General purpose services available to every PEIM.
47 FfsHeader - Ffs header pointer
51 Status - Result of InstallPpi
57 Status
= (**PeiServices
).InstallPpi (PeiServices
, &PpiListPeiBaseMemoryTest
);
65 IN EFI_PEI_SERVICES
**PeiServices
,
66 IN PEI_BASE_MEMORY_TEST_PPI
*This
,
67 IN EFI_PHYSICAL_ADDRESS BeginAddress
,
68 IN UINT64 MemoryLength
,
69 IN PEI_MEMORY_TEST_OP Operation
,
70 OUT EFI_PHYSICAL_ADDRESS
*ErrorAddress
79 PeiServices - General purpose services available to every PEIM.
80 This - Pei memory test PPI pointer.
81 BeginAddress - Beginning of the memory address to be checked.
82 MemoryLength - Bytes of memory range to be checked.
83 Operation - Type of memory check operation to be performed.
84 ErrorAddress - Return the address of the error memory address.
85 ErrorAddress - Address which has error when checked.
89 Status - Result of InstallPpi
95 EFI_PHYSICAL_ADDRESS TempAddress
;
100 EFI_COMPUTING_UNIT_MEMORY
+ EFI_CU_MEMORY_PC_TEST
103 TestPattern
= TEST_PATTERN
;
108 // Make sure we don't try and test anything above the max physical address range
110 ASSERT_EFI_ERROR (BeginAddress
+ MemoryLength
< EFI_MAX_ADDRESS
);
119 SpanSize
= COVER_SPAN
;
127 // Write the test pattern into memory range
129 TempAddress
= BeginAddress
;
130 while (TempAddress
< BeginAddress
+ MemoryLength
) {
131 (*(UINT32
*) (UINTN
) TempAddress
) = TestPattern
;
132 TempAddress
+= SpanSize
;
135 // Read pattern from memory and compare it
137 TempAddress
= BeginAddress
;
138 while (TempAddress
< BeginAddress
+ MemoryLength
) {
139 if ((*(UINT32
*) (UINTN
) TempAddress
) != TestPattern
) {
140 *ErrorAddress
= TempAddress
;
142 EFI_ERROR_CODE
| EFI_ERROR_UNRECOVERED
,
143 EFI_COMPUTING_UNIT_MEMORY
| EFI_CU_MEMORY_EC_UNCORRECTABLE
146 return EFI_DEVICE_ERROR
;
149 TempAddress
+= SpanSize
;