3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 #include "NullMemoryTest.h"
24 // Module global members
26 UINT64 mTestedSystemMemory
= 0;
27 UINT64 mTotalSystemMemory
= 0;
28 EFI_HANDLE mGenericMemoryTestHandle
;
33 EFI_GENERIC_MEMORY_TEST_PROTOCOL mGenericMemoryTest
= {
36 GenMemoryTestFinished
,
37 GenCompatibleRangeTest
42 GenericMemoryTestEntryPoint (
43 IN EFI_HANDLE ImageHandle
,
44 IN EFI_SYSTEM_TABLE
*SystemTable
50 The generic memory test driver's entry point, it can initialize private data
55 ImageHandle of the loaded driver
56 Pointer to the System Table
62 EFI_SUCCESS - Protocol successfully installed
63 EFI_OUT_OF_RESOURCES - Can not allocate protocol data structure in base
71 // Install the protocol
73 Status
= gBS
->InstallProtocolInterface (
74 &mGenericMemoryTestHandle
,
75 &gEfiGenericMemTestProtocolGuid
,
83 // EFI_GENERIC_MEMORY_TEST_PROTOCOL implementation
87 InitializeMemoryTest (
88 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
,
89 IN EXTENDMEM_COVERAGE_LEVEL Level
,
90 OUT BOOLEAN
*RequireSoftECCInit
102 UINTN NumberOfDescriptors
;
103 EFI_GCD_MEMORY_SPACE_DESCRIPTOR
*MemorySpaceMap
;
106 gDS
->GetMemorySpaceMap (&NumberOfDescriptors
, &MemorySpaceMap
);
107 for (Index
= 0; Index
< NumberOfDescriptors
; Index
++) {
108 if (MemorySpaceMap
[Index
].GcdMemoryType
== EfiGcdMemoryTypeReserved
&&
109 (MemorySpaceMap
[Index
].Capabilities
& (EFI_MEMORY_PRESENT
| EFI_MEMORY_INITIALIZED
| EFI_MEMORY_TESTED
)) ==
110 (EFI_MEMORY_PRESENT
| EFI_MEMORY_INITIALIZED
)
112 gDS
->RemoveMemorySpace (
113 MemorySpaceMap
[Index
].BaseAddress
,
114 MemorySpaceMap
[Index
].Length
117 gDS
->AddMemorySpace (
118 EfiGcdMemoryTypeSystemMemory
,
119 MemorySpaceMap
[Index
].BaseAddress
,
120 MemorySpaceMap
[Index
].Length
,
121 MemorySpaceMap
[Index
].Capabilities
&~
122 (EFI_MEMORY_PRESENT
| EFI_MEMORY_INITIALIZED
| EFI_MEMORY_TESTED
| EFI_MEMORY_RUNTIME
)
125 mTestedSystemMemory
+= MemorySpaceMap
[Index
].Length
;
126 mTotalSystemMemory
+= MemorySpaceMap
[Index
].Length
;
127 } else if (MemorySpaceMap
[Index
].GcdMemoryType
== EfiGcdMemoryTypeSystemMemory
) {
128 mTotalSystemMemory
+= MemorySpaceMap
[Index
].Length
;
132 gBS
->FreePool (MemorySpaceMap
);
134 *RequireSoftECCInit
= FALSE
;
140 GenPerformMemoryTest (
141 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
,
142 IN OUT UINT64
*TestedMemorySize
,
143 OUT UINT64
*TotalMemorySize
,
144 OUT BOOLEAN
*ErrorOut
,
158 *TestedMemorySize
= mTestedSystemMemory
;
159 *TotalMemorySize
= mTotalSystemMemory
;
161 return EFI_NOT_FOUND
;
167 GenMemoryTestFinished (
168 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
185 GenCompatibleRangeTest (
186 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL
*This
,
187 IN EFI_PHYSICAL_ADDRESS StartAddress
,
200 EFI_GCD_MEMORY_SPACE_DESCRIPTOR descriptor
;
202 gDS
->GetMemorySpaceDescriptor (StartAddress
, &descriptor
);
204 gDS
->RemoveMemorySpace (StartAddress
, Length
);
206 gDS
->AddMemorySpace (
207 EfiGcdMemoryTypeSystemMemory
,
210 descriptor
.Capabilities
&~(EFI_MEMORY_PRESENT
| EFI_MEMORY_INITIALIZED
| EFI_MEMORY_TESTED
| EFI_MEMORY_RUNTIME
)