Initial import.
[mirror_edk2.git] / EdkModulePkg / Universal / GenericMemoryTest / Dxe / NullMemoryTest.c
1 /*++
2
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
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 NullMemoryTest.c
15
16 Abstract:
17
18 --*/
19
20
21 #include "NullMemoryTest.h"
22
23 //
24 // Module global members
25 //
26 UINT64 mTestedSystemMemory = 0;
27 UINT64 mTotalSystemMemory = 0;
28 EFI_HANDLE mGenericMemoryTestHandle;
29
30 //
31 // Driver entry here
32 //
33 EFI_GENERIC_MEMORY_TEST_PROTOCOL mGenericMemoryTest = {
34 InitializeMemoryTest,
35 GenPerformMemoryTest,
36 GenMemoryTestFinished,
37 GenCompatibleRangeTest
38 };
39
40 EFI_STATUS
41 EFIAPI
42 GenericMemoryTestEntryPoint (
43 IN EFI_HANDLE ImageHandle,
44 IN EFI_SYSTEM_TABLE *SystemTable
45 )
46 /*++
47
48 Routine Description:
49
50 The generic memory test driver's entry point, it can initialize private data
51 to default value
52
53 Arguments:
54
55 ImageHandle of the loaded driver
56 Pointer to the System Table
57
58 Returns:
59
60 Status
61
62 EFI_SUCCESS - Protocol successfully installed
63 EFI_OUT_OF_RESOURCES - Can not allocate protocol data structure in base
64 memory
65
66 --*/
67 {
68 EFI_STATUS Status;
69
70 //
71 // Install the protocol
72 //
73 Status = gBS->InstallProtocolInterface (
74 &mGenericMemoryTestHandle,
75 &gEfiGenericMemTestProtocolGuid,
76 EFI_NATIVE_INTERFACE,
77 &mGenericMemoryTest
78 );
79
80 return Status;
81 }
82 //
83 // EFI_GENERIC_MEMORY_TEST_PROTOCOL implementation
84 //
85 EFI_STATUS
86 EFIAPI
87 InitializeMemoryTest (
88 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
89 IN EXTENDMEM_COVERAGE_LEVEL Level,
90 OUT BOOLEAN *RequireSoftECCInit
91 )
92 /*++
93
94 Routine Description:
95
96 Arguments:
97
98 Returns:
99
100 --*/
101 {
102 UINTN NumberOfDescriptors;
103 EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;
104 UINTN Index;
105
106 gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);
107 for (Index = 0; Index < NumberOfDescriptors; Index++) {
108 if (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeReserved &&
109 (MemorySpaceMap[Index].Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==
110 (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED)
111 ) {
112 gDS->RemoveMemorySpace (
113 MemorySpaceMap[Index].BaseAddress,
114 MemorySpaceMap[Index].Length
115 );
116
117 gDS->AddMemorySpace (
118 EfiGcdMemoryTypeSystemMemory,
119 MemorySpaceMap[Index].BaseAddress,
120 MemorySpaceMap[Index].Length,
121 MemorySpaceMap[Index].Capabilities &~
122 (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)
123 );
124
125 mTestedSystemMemory += MemorySpaceMap[Index].Length;
126 mTotalSystemMemory += MemorySpaceMap[Index].Length;
127 } else if (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeSystemMemory) {
128 mTotalSystemMemory += MemorySpaceMap[Index].Length;
129 }
130 }
131
132 gBS->FreePool (MemorySpaceMap);
133
134 *RequireSoftECCInit = FALSE;
135 return EFI_SUCCESS;
136 }
137
138 EFI_STATUS
139 EFIAPI
140 GenPerformMemoryTest (
141 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
142 IN OUT UINT64 *TestedMemorySize,
143 OUT UINT64 *TotalMemorySize,
144 OUT BOOLEAN *ErrorOut,
145 IN BOOLEAN TestAbort
146 )
147 /*++
148
149 Routine Description:
150
151 Arguments:
152
153 Returns:
154
155 --*/
156 {
157 *ErrorOut = FALSE;
158 *TestedMemorySize = mTestedSystemMemory;
159 *TotalMemorySize = mTotalSystemMemory;
160
161 return EFI_NOT_FOUND;
162
163 }
164
165 EFI_STATUS
166 EFIAPI
167 GenMemoryTestFinished (
168 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This
169 )
170 /*++
171
172 Routine Description:
173
174 Arguments:
175
176 Returns:
177
178 --*/
179 {
180 return EFI_SUCCESS;
181 }
182
183 EFI_STATUS
184 EFIAPI
185 GenCompatibleRangeTest (
186 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
187 IN EFI_PHYSICAL_ADDRESS StartAddress,
188 IN UINT64 Length
189 )
190 /*++
191
192 Routine Description:
193
194 Arguments:
195
196 Returns:
197
198 --*/
199 {
200 EFI_GCD_MEMORY_SPACE_DESCRIPTOR descriptor;
201
202 gDS->GetMemorySpaceDescriptor (StartAddress, &descriptor);
203
204 gDS->RemoveMemorySpace (StartAddress, Length);
205
206 gDS->AddMemorySpace (
207 EfiGcdMemoryTypeSystemMemory,
208 StartAddress,
209 Length,
210 descriptor.Capabilities &~(EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)
211 );
212
213 return EFI_SUCCESS;
214 }