]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/BaseMemoryTestPei/BaseMemoryTest.c
7b207b919d5c832cbb04cc1c872677e114e956cc
[mirror_edk2.git] / MdeModulePkg / Universal / BaseMemoryTestPei / BaseMemoryTest.c
1 /*++
2
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
8
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.
11
12 Module Name:
13
14 BaseMemoryTest.c
15
16 Abstract:
17
18 The PEI memory test support
19
20 --*/
21
22 //
23 // The package level header files this module uses
24 //
25 #include <PiPei.h>
26 #include <FrameworkPei.h>
27 //
28 // The protocols, PPI and GUID defintions for this module
29 //
30 #include <Ppi/BaseMemoryTest.h>
31 //
32 // The Library classes this module consumes
33 //
34 #include <Library/DebugLib.h>
35 #include <Library/PeimEntryPoint.h>
36 #include <Library/ReportStatusCodeLib.h>
37
38 #include <BaseMemoryTest.h>
39
40 static PEI_BASE_MEMORY_TEST_PPI mPeiBaseMemoryTestPpi = { BaseMemoryTest };
41
42 static EFI_PEI_PPI_DESCRIPTOR PpiListPeiBaseMemoryTest = {
43 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
44 &gPeiBaseMemoryTestPpiGuid,
45 &mPeiBaseMemoryTestPpi
46 };
47
48 EFI_STATUS
49 EFIAPI
50 PeiBaseMemoryTestInit (
51 IN EFI_FFS_FILE_HEADER *FfsHeader,
52 IN EFI_PEI_SERVICES **PeiServices
53 )
54 /*++
55 Description:
56
57 Entry point function of BaseMemoryTestInit Peim.
58
59 Arguments:
60
61 PeiServices - General purpose services available to every PEIM.
62 FfsHeader - Ffs header pointer
63
64 Returns:
65
66 Status - Result of InstallPpi
67
68 --*/
69 {
70 EFI_STATUS Status;
71
72 Status = (**PeiServices).InstallPpi (PeiServices, &PpiListPeiBaseMemoryTest);
73
74 return Status;
75 }
76
77 EFI_STATUS
78 EFIAPI
79 BaseMemoryTest (
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
86 )
87 /*++
88 Description:
89
90 Test base memory.
91
92 Arguments:
93
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.
101
102 Returns:
103
104 Status - Result of InstallPpi
105
106 --*/
107 {
108 UINT32 TestPattern;
109 EFI_PHYSICAL_ADDRESS TempAddress;
110 UINT32 SpanSize;
111
112 REPORT_STATUS_CODE (
113 EFI_PROGRESS_CODE,
114 EFI_COMPUTING_UNIT_MEMORY + EFI_CU_MEMORY_PC_TEST
115 );
116
117 TestPattern = TEST_PATTERN;
118 SpanSize = 0;
119
120 //
121 // Make sure we don't try and test anything above the max physical address range
122 //
123 ASSERT (BeginAddress + MemoryLength < EFI_MAX_ADDRESS);
124
125 switch (Operation) {
126 case Extensive:
127 SpanSize = 0x4;
128 break;
129
130 case Sparse:
131 case Quick:
132 SpanSize = COVER_SPAN;
133 break;
134
135 case Ignore:
136 goto Done;
137 break;
138 }
139 //
140 // Write the test pattern into memory range
141 //
142 TempAddress = BeginAddress;
143 while (TempAddress < BeginAddress + MemoryLength) {
144 (*(UINT32 *) (UINTN) TempAddress) = TestPattern;
145 TempAddress += SpanSize;
146 }
147 //
148 // Read pattern from memory and compare it
149 //
150 TempAddress = BeginAddress;
151 while (TempAddress < BeginAddress + MemoryLength) {
152 if ((*(UINT32 *) (UINTN) TempAddress) != TestPattern) {
153 *ErrorAddress = TempAddress;
154 REPORT_STATUS_CODE (
155 EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED,
156 EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_UNCORRECTABLE
157 );
158
159 return EFI_DEVICE_ERROR;
160 }
161
162 TempAddress += SpanSize;
163 }
164
165 Done:
166 return EFI_SUCCESS;
167 }