2 Implementation of Generic Memory Test Protocol which does not perform real memory test.
4 Copyright (c) 2006 - 2008, 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 Initialize the generic memory test.
64 This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.MemoryTestInit.
65 It simply promotes untested reserved memory to system memory without real test.
67 @param This Protocol instance pointer.
68 @param Level The coverage level of the memory test.
69 @param RequireSoftECCInit Indicate if the memory need software ECC init.
71 @retval EFI_SUCCESS The generic memory test initialized correctly.
72 @retval EFI_NO_MEDIA There is not any non-tested memory found, in this
73 function if not any non-tesed memory found means
74 that the memory test driver have not detect any
75 non-tested extended memory of current system.
80 InitializeMemoryTest (
81 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
,
82 IN EXTENDMEM_COVERAGE_LEVEL Level
,
83 OUT BOOLEAN
*RequireSoftECCInit
86 UINTN NumberOfDescriptors
;
87 EFI_GCD_MEMORY_SPACE_DESCRIPTOR
*MemorySpaceMap
;
90 gDS
->GetMemorySpaceMap (&NumberOfDescriptors
, &MemorySpaceMap
);
91 for (Index
= 0; Index
< NumberOfDescriptors
; Index
++) {
92 if (MemorySpaceMap
[Index
].GcdMemoryType
== EfiGcdMemoryTypeReserved
&&
93 (MemorySpaceMap
[Index
].Capabilities
& (EFI_MEMORY_PRESENT
| EFI_MEMORY_INITIALIZED
| EFI_MEMORY_TESTED
)) ==
94 (EFI_MEMORY_PRESENT
| EFI_MEMORY_INITIALIZED
)
97 // For those reserved memory that have not been tested, simply promote to system memory.
99 gDS
->RemoveMemorySpace (
100 MemorySpaceMap
[Index
].BaseAddress
,
101 MemorySpaceMap
[Index
].Length
104 gDS
->AddMemorySpace (
105 EfiGcdMemoryTypeSystemMemory
,
106 MemorySpaceMap
[Index
].BaseAddress
,
107 MemorySpaceMap
[Index
].Length
,
108 MemorySpaceMap
[Index
].Capabilities
&~
109 (EFI_MEMORY_PRESENT
| EFI_MEMORY_INITIALIZED
| EFI_MEMORY_TESTED
| EFI_MEMORY_RUNTIME
)
112 mTestedSystemMemory
+= MemorySpaceMap
[Index
].Length
;
113 mTotalSystemMemory
+= MemorySpaceMap
[Index
].Length
;
114 } else if (MemorySpaceMap
[Index
].GcdMemoryType
== EfiGcdMemoryTypeSystemMemory
) {
115 mTotalSystemMemory
+= MemorySpaceMap
[Index
].Length
;
119 FreePool (MemorySpaceMap
);
121 *RequireSoftECCInit
= FALSE
;
126 Perform the memory test.
128 This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.PerformMemoryTest.
129 It simply returns EFI_NOT_FOUND.
131 @param This Protocol instance pointer.
132 @param TestedMemorySize Return the tested extended memory size.
133 @param TotalMemorySize Return the whole system physical memory size, this
134 value may be changed if in some case some error
136 @param ErrorOut Any time the memory error occurs, this will be
138 @param IfTestAbort Indicate if the user press "ESC" to skip the memory
141 @retval EFI_SUCCESS One block of memory test ok, the block size is hide
143 @retval EFI_NOT_FOUND Indicate all the non-tested memory blocks have
145 @retval EFI_DEVICE_ERROR Mis-compare error, and no agent can handle it
150 GenPerformMemoryTest (
151 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
,
152 IN OUT UINT64
*TestedMemorySize
,
153 OUT UINT64
*TotalMemorySize
,
154 OUT BOOLEAN
*ErrorOut
,
159 *TestedMemorySize
= mTestedSystemMemory
;
160 *TotalMemorySize
= mTotalSystemMemory
;
162 return EFI_NOT_FOUND
;
167 The memory test finished.
169 This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.Finished.
170 It simply returns EFI_SUCCESS.
172 @param This Protocol instance pointer.
174 @retval EFI_SUCCESS Successful free all the generic memory test driver
175 allocated resource and notify to platform memory
176 test driver that memory test finished.
181 GenMemoryTestFinished (
182 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
189 Provide capability to test compatible range which used by some special
190 driver required using memory range before BDS perform memory test.
192 This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.CompatibleRangeTest.
193 It simply sets the memory range to system memory.
195 @param This Protocol instance pointer.
196 @param StartAddress The start address of the memory range.
197 @param Length The memory range's length.
199 @retval EFI_SUCCESS The compatible memory range pass the memory test.
200 @retval EFI_INVALID_PARAMETER The compatible memory range must be below 16M.
205 GenCompatibleRangeTest (
206 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
,
207 IN EFI_PHYSICAL_ADDRESS StartAddress
,
211 EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor
;
213 gDS
->GetMemorySpaceDescriptor (StartAddress
, &Descriptor
);
215 gDS
->RemoveMemorySpace (StartAddress
, Length
);
217 gDS
->AddMemorySpace (
218 EfiGcdMemoryTypeSystemMemory
,
221 Descriptor
.Capabilities
&~(EFI_MEMORY_PRESENT
| EFI_MEMORY_INITIALIZED
| EFI_MEMORY_TESTED
| EFI_MEMORY_RUNTIME
)