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