2 Implementation of Generic Memory Test Protocol which does not perform real memory test.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "NullMemoryTest.h"
12 UINT64 mTestedSystemMemory
= 0;
13 UINT64 mTotalSystemMemory
= 0;
14 EFI_HANDLE mGenericMemoryTestHandle
;
16 EFI_GENERIC_MEMORY_TEST_PROTOCOL mGenericMemoryTest
= {
19 GenMemoryTestFinished
,
20 GenCompatibleRangeTest
24 Entry point of the NULL memory test driver.
26 This function is the entry point of the NULL memory test driver.
27 It simply installs the Generic Memory Test Protocol.
29 @param ImageHandle The firmware allocated handle for the EFI image.
30 @param SystemTable A pointer to the EFI System Table.
32 @retval EFI_SUCCESS Generic Memory Test Protocol is successfully installed.
37 GenericMemoryTestEntryPoint (
38 IN EFI_HANDLE ImageHandle
,
39 IN EFI_SYSTEM_TABLE
*SystemTable
44 Status
= gBS
->InstallProtocolInterface (
45 &mGenericMemoryTestHandle
,
46 &gEfiGenericMemTestProtocolGuid
,
50 ASSERT_EFI_ERROR (Status
);
56 Convert the memory range to tested.
58 @param BaseAddress Base address of the memory range.
59 @param Length Length of the memory range.
60 @param Capabilities Capabilities of the memory range.
62 @retval EFI_SUCCESS The memory range is converted to tested.
63 @retval others Error happens.
66 ConvertToTestedMemory (
67 IN UINT64 BaseAddress
,
69 IN UINT64 Capabilities
73 Status
= gDS
->RemoveMemorySpace (
77 if (!EFI_ERROR (Status
)) {
78 Status
= gDS
->AddMemorySpace (
79 ((Capabilities
& EFI_MEMORY_MORE_RELIABLE
) == EFI_MEMORY_MORE_RELIABLE
) ?
80 EfiGcdMemoryTypeMoreReliable
: EfiGcdMemoryTypeSystemMemory
,
84 (EFI_MEMORY_PRESENT
| EFI_MEMORY_INITIALIZED
| EFI_MEMORY_TESTED
| EFI_MEMORY_RUNTIME
)
91 Initialize the generic memory test.
93 This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.MemoryTestInit.
94 It simply promotes untested reserved memory to system memory without real test.
96 @param This Protocol instance pointer.
97 @param Level The coverage level of the memory test.
98 @param RequireSoftECCInit Indicate if the memory need software ECC init.
100 @retval EFI_SUCCESS The generic memory test initialized correctly.
101 @retval EFI_NO_MEDIA There is not any non-tested memory found, in this
102 function if not any non-tesed memory found means
103 that the memory test driver have not detect any
104 non-tested extended memory of current system.
109 InitializeMemoryTest (
110 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
,
111 IN EXTENDMEM_COVERAGE_LEVEL Level
,
112 OUT BOOLEAN
*RequireSoftECCInit
116 UINTN NumberOfDescriptors
;
117 EFI_GCD_MEMORY_SPACE_DESCRIPTOR
*MemorySpaceMap
;
120 gDS
->GetMemorySpaceMap (&NumberOfDescriptors
, &MemorySpaceMap
);
121 for (Index
= 0; Index
< NumberOfDescriptors
; Index
++) {
122 if (MemorySpaceMap
[Index
].GcdMemoryType
== EfiGcdMemoryTypeReserved
&&
123 (MemorySpaceMap
[Index
].Capabilities
& (EFI_MEMORY_PRESENT
| EFI_MEMORY_INITIALIZED
| EFI_MEMORY_TESTED
)) ==
124 (EFI_MEMORY_PRESENT
| EFI_MEMORY_INITIALIZED
)
127 // For those reserved memory that have not been tested, simply promote to system memory.
129 Status
= ConvertToTestedMemory (
130 MemorySpaceMap
[Index
].BaseAddress
,
131 MemorySpaceMap
[Index
].Length
,
132 MemorySpaceMap
[Index
].Capabilities
134 ASSERT_EFI_ERROR (Status
);
135 mTestedSystemMemory
+= MemorySpaceMap
[Index
].Length
;
136 mTotalSystemMemory
+= MemorySpaceMap
[Index
].Length
;
137 } else if ((MemorySpaceMap
[Index
].GcdMemoryType
== EfiGcdMemoryTypeSystemMemory
) ||
138 (MemorySpaceMap
[Index
].GcdMemoryType
== EfiGcdMemoryTypeMoreReliable
)) {
139 mTotalSystemMemory
+= MemorySpaceMap
[Index
].Length
;
143 FreePool (MemorySpaceMap
);
145 *RequireSoftECCInit
= FALSE
;
150 Perform the memory test.
152 This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.PerformMemoryTest.
153 It simply returns EFI_NOT_FOUND.
155 @param This Protocol instance pointer.
156 @param TestedMemorySize Return the tested extended memory size.
157 @param TotalMemorySize Return the whole system physical memory size, this
158 value may be changed if in some case some error
160 @param ErrorOut Any time the memory error occurs, this will be
162 @param IfTestAbort Indicate if the user press "ESC" to skip the memory
165 @retval EFI_SUCCESS One block of memory test ok, the block size is hide
167 @retval EFI_NOT_FOUND Indicate all the non-tested memory blocks have
169 @retval EFI_DEVICE_ERROR Mis-compare error, and no agent can handle it
174 GenPerformMemoryTest (
175 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
,
176 IN OUT UINT64
*TestedMemorySize
,
177 OUT UINT64
*TotalMemorySize
,
178 OUT BOOLEAN
*ErrorOut
,
183 *TestedMemorySize
= mTestedSystemMemory
;
184 *TotalMemorySize
= mTotalSystemMemory
;
186 return EFI_NOT_FOUND
;
191 The memory test finished.
193 This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.Finished.
194 It simply returns EFI_SUCCESS.
196 @param This Protocol instance pointer.
198 @retval EFI_SUCCESS Successful free all the generic memory test driver
199 allocated resource and notify to platform memory
200 test driver that memory test finished.
205 GenMemoryTestFinished (
206 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
213 Provide capability to test compatible range which used by some special
214 driver required using memory range before BDS perform memory test.
216 This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.CompatibleRangeTest.
217 It simply sets the memory range to system memory.
219 @param This Protocol instance pointer.
220 @param StartAddress The start address of the memory range.
221 @param Length The memory range's length.
223 @retval EFI_SUCCESS The compatible memory range pass the memory test.
224 @retval EFI_INVALID_PARAMETER The compatible memory range must be below 16M.
229 GenCompatibleRangeTest (
230 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
,
231 IN EFI_PHYSICAL_ADDRESS StartAddress
,
236 EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor
;
237 EFI_PHYSICAL_ADDRESS CurrentBase
;
238 UINT64 CurrentLength
;
241 // Check if the parameter is below 16MB
243 if (StartAddress
+ Length
> SIZE_16MB
) {
244 return EFI_INVALID_PARAMETER
;
246 CurrentBase
= StartAddress
;
249 // Check the required memory range status; if the required memory range span
250 // the different GCD memory descriptor, it may be cause different action.
252 Status
= gDS
->GetMemorySpaceDescriptor (
256 if (EFI_ERROR (Status
)) {
260 if (Descriptor
.GcdMemoryType
== EfiGcdMemoryTypeReserved
&&
261 (Descriptor
.Capabilities
& (EFI_MEMORY_PRESENT
| EFI_MEMORY_INITIALIZED
| EFI_MEMORY_TESTED
)) ==
262 (EFI_MEMORY_PRESENT
| EFI_MEMORY_INITIALIZED
)
264 CurrentLength
= Descriptor
.BaseAddress
+ Descriptor
.Length
- CurrentBase
;
265 if (CurrentBase
+ CurrentLength
> StartAddress
+ Length
) {
266 CurrentLength
= StartAddress
+ Length
- CurrentBase
;
268 Status
= ConvertToTestedMemory (
271 Descriptor
.Capabilities
273 if (EFI_ERROR (Status
)) {
277 CurrentBase
= Descriptor
.BaseAddress
+ Descriptor
.Length
;
278 } while (CurrentBase
< StartAddress
+ Length
);
280 // Here means the required range already be tested, so just return success.