2 Intall memory test protocol and bypass the real memory test procedure.
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
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"
19 // Module global members
21 UINT64 mTestedSystemMemory
= 0;
22 UINT64 mTotalSystemMemory
= 0;
23 EFI_HANDLE mGenericMemoryTestHandle
;
28 EFI_GENERIC_MEMORY_TEST_PROTOCOL mGenericMemoryTest
= {
31 GenMemoryTestFinished
,
32 GenCompatibleRangeTest
37 GenericMemoryTestEntryPoint (
38 IN EFI_HANDLE ImageHandle
,
39 IN EFI_SYSTEM_TABLE
*SystemTable
45 The generic memory test driver's entry point, it can initialize private data
50 ImageHandle of the loaded driver
51 Pointer to the System Table
57 EFI_SUCCESS - Protocol successfully installed
58 EFI_OUT_OF_RESOURCES - Can not allocate protocol data structure in base
66 // Install the protocol
68 Status
= gBS
->InstallProtocolInterface (
69 &mGenericMemoryTestHandle
,
70 &gEfiGenericMemTestProtocolGuid
,
78 // EFI_GENERIC_MEMORY_TEST_PROTOCOL implementation
82 InitializeMemoryTest (
83 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
,
84 IN EXTENDMEM_COVERAGE_LEVEL Level
,
85 OUT BOOLEAN
*RequireSoftECCInit
97 UINTN NumberOfDescriptors
;
98 EFI_GCD_MEMORY_SPACE_DESCRIPTOR
*MemorySpaceMap
;
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
)
107 gDS
->RemoveMemorySpace (
108 MemorySpaceMap
[Index
].BaseAddress
,
109 MemorySpaceMap
[Index
].Length
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
)
120 mTestedSystemMemory
+= MemorySpaceMap
[Index
].Length
;
121 mTotalSystemMemory
+= MemorySpaceMap
[Index
].Length
;
122 } else if (MemorySpaceMap
[Index
].GcdMemoryType
== EfiGcdMemoryTypeSystemMemory
) {
123 mTotalSystemMemory
+= MemorySpaceMap
[Index
].Length
;
127 FreePool (MemorySpaceMap
);
129 *RequireSoftECCInit
= FALSE
;
135 GenPerformMemoryTest (
136 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
,
137 IN OUT UINT64
*TestedMemorySize
,
138 OUT UINT64
*TotalMemorySize
,
139 OUT BOOLEAN
*ErrorOut
,
153 *TestedMemorySize
= mTestedSystemMemory
;
154 *TotalMemorySize
= mTotalSystemMemory
;
156 return EFI_NOT_FOUND
;
162 GenMemoryTestFinished (
163 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
180 GenCompatibleRangeTest (
181 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
,
182 IN EFI_PHYSICAL_ADDRESS StartAddress
,
195 EFI_GCD_MEMORY_SPACE_DESCRIPTOR descriptor
;
197 gDS
->GetMemorySpaceDescriptor (StartAddress
, &descriptor
);
199 gDS
->RemoveMemorySpace (StartAddress
, Length
);
201 gDS
->AddMemorySpace (
202 EfiGcdMemoryTypeSystemMemory
,
205 descriptor
.Capabilities
&~(EFI_MEMORY_PRESENT
| EFI_MEMORY_INITIALIZED
| EFI_MEMORY_TESTED
| EFI_MEMORY_RUNTIME
)