TianoCore EDK2 master
Loading...
Searching...
No Matches
NullMemoryTest.c
Go to the documentation of this file.
1
9#include "NullMemoryTest.h"
10
11UINT64 mTestedSystemMemory = 0;
12UINT64 mTotalSystemMemory = 0;
13EFI_HANDLE mGenericMemoryTestHandle;
14
15EFI_GENERIC_MEMORY_TEST_PROTOCOL mGenericMemoryTest = {
20};
21
35EFIAPI
37 IN EFI_HANDLE ImageHandle,
38 IN EFI_SYSTEM_TABLE *SystemTable
39 )
40{
41 EFI_STATUS Status;
42
43 Status = gBS->InstallProtocolInterface (
44 &mGenericMemoryTestHandle,
45 &gEfiGenericMemTestProtocolGuid,
47 &mGenericMemoryTest
48 );
49 ASSERT_EFI_ERROR (Status);
50
51 return EFI_SUCCESS;
52}
53
66 IN UINT64 BaseAddress,
67 IN UINT64 Length,
68 IN UINT64 Capabilities
69 )
70{
71 EFI_STATUS Status;
72
73 Status = gDS->RemoveMemorySpace (
74 BaseAddress,
75 Length
76 );
77 if (!EFI_ERROR (Status)) {
78 Status = gDS->AddMemorySpace (
79 ((Capabilities & EFI_MEMORY_MORE_RELIABLE) == EFI_MEMORY_MORE_RELIABLE) ?
81 BaseAddress,
82 Length,
83 Capabilities &~
84 (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)
85 );
86 }
87
88 return Status;
89}
90
109EFIAPI
113 OUT BOOLEAN *RequireSoftECCInit
114 )
115{
116 EFI_STATUS Status;
117 UINTN NumberOfDescriptors;
118 EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;
119 UINTN Index;
120
121 gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);
122 for (Index = 0; Index < NumberOfDescriptors; Index++) {
123 if ((MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeReserved) &&
124 ((MemorySpaceMap[Index].Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==
125 (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED))
126 )
127 {
128 //
129 // For those reserved memory that have not been tested, simply promote to system memory.
130 //
131 Status = ConvertToTestedMemory (
132 MemorySpaceMap[Index].BaseAddress,
133 MemorySpaceMap[Index].Length,
134 MemorySpaceMap[Index].Capabilities
135 );
136 ASSERT_EFI_ERROR (Status);
137 mTestedSystemMemory += MemorySpaceMap[Index].Length;
138 mTotalSystemMemory += MemorySpaceMap[Index].Length;
139 } else if ((MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeSystemMemory) ||
140 (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeMoreReliable))
141 {
142 mTotalSystemMemory += MemorySpaceMap[Index].Length;
143 }
144 }
145
146 FreePool (MemorySpaceMap);
147
148 *RequireSoftECCInit = FALSE;
149 return EFI_SUCCESS;
150}
151
176EFIAPI
179 IN OUT UINT64 *TestedMemorySize,
180 OUT UINT64 *TotalMemorySize,
181 OUT BOOLEAN *ErrorOut,
182 IN BOOLEAN TestAbort
183 )
184{
185 *ErrorOut = FALSE;
186 *TestedMemorySize = mTestedSystemMemory;
187 *TotalMemorySize = mTotalSystemMemory;
188
189 return EFI_NOT_FOUND;
190}
191
206EFIAPI
209 )
210{
211 return EFI_SUCCESS;
212}
213
230EFIAPI
233 IN EFI_PHYSICAL_ADDRESS StartAddress,
234 IN UINT64 Length
235 )
236{
237 EFI_STATUS Status;
239 EFI_PHYSICAL_ADDRESS CurrentBase;
240 UINT64 CurrentLength;
241
242 //
243 // Check if the parameter is below 16MB
244 //
245 if (StartAddress + Length > SIZE_16MB) {
246 return EFI_INVALID_PARAMETER;
247 }
248
249 CurrentBase = StartAddress;
250 do {
251 //
252 // Check the required memory range status; if the required memory range span
253 // the different GCD memory descriptor, it may be cause different action.
254 //
255 Status = gDS->GetMemorySpaceDescriptor (
256 CurrentBase,
257 &Descriptor
258 );
259 if (EFI_ERROR (Status)) {
260 return Status;
261 }
262
263 if ((Descriptor.GcdMemoryType == EfiGcdMemoryTypeReserved) &&
264 ((Descriptor.Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==
265 (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED))
266 )
267 {
268 CurrentLength = Descriptor.BaseAddress + Descriptor.Length - CurrentBase;
269 if (CurrentBase + CurrentLength > StartAddress + Length) {
270 CurrentLength = StartAddress + Length - CurrentBase;
271 }
272
273 Status = ConvertToTestedMemory (
274 CurrentBase,
275 CurrentLength,
276 Descriptor.Capabilities
277 );
278 if (EFI_ERROR (Status)) {
279 return Status;
280 }
281 }
282
283 CurrentBase = Descriptor.BaseAddress + Descriptor.Length;
284 } while (CurrentBase < StartAddress + Length);
285
286 //
287 // Here means the required range already be tested, so just return success.
288 //
289 return EFI_SUCCESS;
290}
UINT64 UINTN
EFI_DXE_SERVICES * gDS
VOID EFIAPI FreePool(IN VOID *Buffer)
EXTENDMEM_COVERAGE_LEVEL
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
EFI_STATUS EFIAPI GenPerformMemoryTest(IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This, IN OUT UINT64 *TestedMemorySize, OUT UINT64 *TotalMemorySize, OUT BOOLEAN *ErrorOut, IN BOOLEAN TestAbort)
EFI_STATUS EFIAPI InitializeMemoryTest(IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This, IN EXTENDMEM_COVERAGE_LEVEL Level, OUT BOOLEAN *RequireSoftECCInit)
EFI_STATUS ConvertToTestedMemory(IN UINT64 BaseAddress, IN UINT64 Length, IN UINT64 Capabilities)
EFI_STATUS EFIAPI GenericMemoryTestEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS EFIAPI GenMemoryTestFinished(IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This)
EFI_STATUS EFIAPI GenCompatibleRangeTest(IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This, IN EFI_PHYSICAL_ADDRESS StartAddress, IN UINT64 Length)
@ EfiGcdMemoryTypeReserved
Definition: PiDxeCis.h:32
@ EfiGcdMemoryTypeMoreReliable
Definition: PiDxeCis.h:58
@ EfiGcdMemoryTypeSystemMemory
Definition: PiDxeCis.h:38
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
@ EFI_NATIVE_INTERFACE
Definition: UefiSpec.h:1193
EFI_GCD_MEMORY_TYPE GcdMemoryType
Definition: PiDxeCis.h:152
EFI_PHYSICAL_ADDRESS BaseAddress
Definition: PiDxeCis.h:130