2 The PEI memory test support
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>
16 #include <Library/PeiServicesLib.h>
18 static PEI_BASE_MEMORY_TEST_PPI mPeiBaseMemoryTestPpi
= { BaseMemoryTest
};
20 static EFI_PEI_PPI_DESCRIPTOR PpiListPeiBaseMemoryTest
= {
21 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
22 &gPeiBaseMemoryTestPpiGuid
,
23 &mPeiBaseMemoryTestPpi
28 PeiBaseMemoryTestInit (
29 IN EFI_FFS_FILE_HEADER
*FfsHeader
,
30 IN EFI_PEI_SERVICES
**PeiServices
35 Entry point function of BaseMemoryTestInit Peim.
39 PeiServices - General purpose services available to every PEIM.
40 FfsHeader - Ffs header pointer
44 Status - Result of InstallPpi
49 return PeiServicesInstallPpi (&PpiListPeiBaseMemoryTest
);
56 IN EFI_PEI_SERVICES
**PeiServices
,
57 IN PEI_BASE_MEMORY_TEST_PPI
*This
,
58 IN EFI_PHYSICAL_ADDRESS BeginAddress
,
59 IN UINT64 MemoryLength
,
60 IN PEI_MEMORY_TEST_OP Operation
,
61 OUT EFI_PHYSICAL_ADDRESS
*ErrorAddress
70 PeiServices - General purpose services available to every PEIM.
71 This - Pei memory test PPI pointer.
72 BeginAddress - Beginning of the memory address to be checked.
73 MemoryLength - Bytes of memory range to be checked.
74 Operation - Type of memory check operation to be performed.
75 ErrorAddress - Return the address of the error memory address.
76 ErrorAddress - Address which has error when checked.
80 Status - Result of InstallPpi
85 EFI_PHYSICAL_ADDRESS TempAddress
;
88 REPORT_STATUS_CODE (EFI_PROGRESS_CODE
, PcdGet32 (PcdStatusCodeValueMemoryTestStarted
));
90 TestPattern
= TEST_PATTERN
;
94 // Make sure we don't try and test anything above the max physical address range
96 ASSERT (BeginAddress
+ MemoryLength
< EFI_MAX_ADDRESS
);
105 SpanSize
= COVER_SPAN
;
113 // Write the test pattern into memory range
115 TempAddress
= BeginAddress
;
116 while (TempAddress
< BeginAddress
+ MemoryLength
) {
117 (*(UINT32
*) (UINTN
) TempAddress
) = TestPattern
;
118 TempAddress
+= SpanSize
;
121 // Read pattern from memory and compare it
123 TempAddress
= BeginAddress
;
124 while (TempAddress
< BeginAddress
+ MemoryLength
) {
125 if ((*(UINT32
*) (UINTN
) TempAddress
) != TestPattern
) {
126 *ErrorAddress
= TempAddress
;
127 REPORT_STATUS_CODE (EFI_ERROR_CODE
| EFI_ERROR_UNRECOVERED
, PcdGet32 (PcdStatusCodeValueUncorrectableMemoryError
));
129 return EFI_DEVICE_ERROR
;
132 TempAddress
+= SpanSize
;