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 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
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.
16 #include "NullMemoryTest.h"
18 UINT64 mTestedSystemMemory
= 0;
19 UINT64 mTotalSystemMemory
= 0;
20 EFI_HANDLE mGenericMemoryTestHandle
;
22 EFI_GENERIC_MEMORY_TEST_PROTOCOL mGenericMemoryTest
= {
25 GenMemoryTestFinished
,
26 GenCompatibleRangeTest
30 Entry point of the NULL memory test driver.
32 This function is the entry point of the NULL memory test driver.
33 It simply installs the Generic Memory Test Protocol.
35 @param ImageHandle The firmware allocated handle for the EFI image.
36 @param SystemTable A pointer to the EFI System Table.
38 @retval EFI_SUCCESS Generic Memory Test Protocol is successfully installed.
43 GenericMemoryTestEntryPoint (
44 IN EFI_HANDLE ImageHandle
,
45 IN EFI_SYSTEM_TABLE
*SystemTable
50 Status
= gBS
->InstallProtocolInterface (
51 &mGenericMemoryTestHandle
,
52 &gEfiGenericMemTestProtocolGuid
,
56 ASSERT_EFI_ERROR (Status
);
62 Convert the memory range to tested.
64 @param BaseAddress Base address of the memory range.
65 @param Length Length of the memory range.
66 @param Capabilities Capabilities of the memory range.
68 @retval EFI_SUCCESS The memory range is converted to tested.
69 @retval others Error happens.
72 ConvertToTestedMemory (
73 IN UINT64 BaseAddress
,
75 IN UINT64 Capabilities
79 Status
= gDS
->RemoveMemorySpace (
83 if (!EFI_ERROR (Status
)) {
84 Status
= gDS
->AddMemorySpace (
85 ((Capabilities
& EFI_MEMORY_MORE_RELIABLE
) == EFI_MEMORY_MORE_RELIABLE
) ?
86 EfiGcdMemoryTypeMoreReliable
: EfiGcdMemoryTypeSystemMemory
,
90 (EFI_MEMORY_PRESENT
| EFI_MEMORY_INITIALIZED
| EFI_MEMORY_TESTED
| EFI_MEMORY_RUNTIME
)
97 Initialize the generic memory test.
99 This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.MemoryTestInit.
100 It simply promotes untested reserved memory to system memory without real test.
102 @param This Protocol instance pointer.
103 @param Level The coverage level of the memory test.
104 @param RequireSoftECCInit Indicate if the memory need software ECC init.
106 @retval EFI_SUCCESS The generic memory test initialized correctly.
107 @retval EFI_NO_MEDIA There is not any non-tested memory found, in this
108 function if not any non-tesed memory found means
109 that the memory test driver have not detect any
110 non-tested extended memory of current system.
115 InitializeMemoryTest (
116 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
,
117 IN EXTENDMEM_COVERAGE_LEVEL Level
,
118 OUT BOOLEAN
*RequireSoftECCInit
122 UINTN NumberOfDescriptors
;
123 EFI_GCD_MEMORY_SPACE_DESCRIPTOR
*MemorySpaceMap
;
126 gDS
->GetMemorySpaceMap (&NumberOfDescriptors
, &MemorySpaceMap
);
127 for (Index
= 0; Index
< NumberOfDescriptors
; Index
++) {
128 if (MemorySpaceMap
[Index
].GcdMemoryType
== EfiGcdMemoryTypeReserved
&&
129 (MemorySpaceMap
[Index
].Capabilities
& (EFI_MEMORY_PRESENT
| EFI_MEMORY_INITIALIZED
| EFI_MEMORY_TESTED
)) ==
130 (EFI_MEMORY_PRESENT
| EFI_MEMORY_INITIALIZED
)
133 // For those reserved memory that have not been tested, simply promote to system memory.
135 Status
= ConvertToTestedMemory (
136 MemorySpaceMap
[Index
].BaseAddress
,
137 MemorySpaceMap
[Index
].Length
,
138 MemorySpaceMap
[Index
].Capabilities
140 ASSERT_EFI_ERROR (Status
);
141 mTestedSystemMemory
+= MemorySpaceMap
[Index
].Length
;
142 mTotalSystemMemory
+= MemorySpaceMap
[Index
].Length
;
143 } else if ((MemorySpaceMap
[Index
].GcdMemoryType
== EfiGcdMemoryTypeSystemMemory
) ||
144 (MemorySpaceMap
[Index
].GcdMemoryType
== EfiGcdMemoryTypeMoreReliable
)) {
145 mTotalSystemMemory
+= MemorySpaceMap
[Index
].Length
;
149 FreePool (MemorySpaceMap
);
151 *RequireSoftECCInit
= FALSE
;
156 Perform the memory test.
158 This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.PerformMemoryTest.
159 It simply returns EFI_NOT_FOUND.
161 @param This Protocol instance pointer.
162 @param TestedMemorySize Return the tested extended memory size.
163 @param TotalMemorySize Return the whole system physical memory size, this
164 value may be changed if in some case some error
166 @param ErrorOut Any time the memory error occurs, this will be
168 @param IfTestAbort Indicate if the user press "ESC" to skip the memory
171 @retval EFI_SUCCESS One block of memory test ok, the block size is hide
173 @retval EFI_NOT_FOUND Indicate all the non-tested memory blocks have
175 @retval EFI_DEVICE_ERROR Mis-compare error, and no agent can handle it
180 GenPerformMemoryTest (
181 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
,
182 IN OUT UINT64
*TestedMemorySize
,
183 OUT UINT64
*TotalMemorySize
,
184 OUT BOOLEAN
*ErrorOut
,
189 *TestedMemorySize
= mTestedSystemMemory
;
190 *TotalMemorySize
= mTotalSystemMemory
;
192 return EFI_NOT_FOUND
;
197 The memory test finished.
199 This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.Finished.
200 It simply returns EFI_SUCCESS.
202 @param This Protocol instance pointer.
204 @retval EFI_SUCCESS Successful free all the generic memory test driver
205 allocated resource and notify to platform memory
206 test driver that memory test finished.
211 GenMemoryTestFinished (
212 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
219 Provide capability to test compatible range which used by some special
220 driver required using memory range before BDS perform memory test.
222 This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.CompatibleRangeTest.
223 It simply sets the memory range to system memory.
225 @param This Protocol instance pointer.
226 @param StartAddress The start address of the memory range.
227 @param Length The memory range's length.
229 @retval EFI_SUCCESS The compatible memory range pass the memory test.
230 @retval EFI_INVALID_PARAMETER The compatible memory range must be below 16M.
235 GenCompatibleRangeTest (
236 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
,
237 IN EFI_PHYSICAL_ADDRESS StartAddress
,
242 EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor
;
243 EFI_PHYSICAL_ADDRESS CurrentBase
;
244 UINT64 CurrentLength
;
247 // Check if the parameter is below 16MB
249 if (StartAddress
+ Length
> SIZE_16MB
) {
250 return EFI_INVALID_PARAMETER
;
252 CurrentBase
= StartAddress
;
255 // Check the required memory range status; if the required memory range span
256 // the different GCD memory descriptor, it may be cause different action.
258 Status
= gDS
->GetMemorySpaceDescriptor (
262 if (EFI_ERROR (Status
)) {
266 if (Descriptor
.GcdMemoryType
== EfiGcdMemoryTypeReserved
&&
267 (Descriptor
.Capabilities
& (EFI_MEMORY_PRESENT
| EFI_MEMORY_INITIALIZED
| EFI_MEMORY_TESTED
)) ==
268 (EFI_MEMORY_PRESENT
| EFI_MEMORY_INITIALIZED
)
270 CurrentLength
= Descriptor
.BaseAddress
+ Descriptor
.Length
- CurrentBase
;
271 if (CurrentBase
+ CurrentLength
> StartAddress
+ Length
) {
272 CurrentLength
= StartAddress
+ Length
- CurrentBase
;
274 Status
= ConvertToTestedMemory (
277 Descriptor
.Capabilities
279 if (EFI_ERROR (Status
)) {
283 CurrentBase
= Descriptor
.BaseAddress
+ Descriptor
.Length
;
284 } while (CurrentBase
< StartAddress
+ Length
);
286 // Here means the required range already be tested, so just return success.