]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTest.c
MdeModulePkg/NullMemoryTest: Change prototype of ConvertToTestedMemory
[mirror_edk2.git] / MdeModulePkg / Universal / MemoryTest / NullMemoryTestDxe / NullMemoryTest.c
CommitLineData
674dced3 1/** @file\r
b3764698 2 Implementation of Generic Memory Test Protocol which does not perform real memory test.\r
05177bef 3\r
1c06bd48 4Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
e5eed7d3 5This program and the accompanying materials\r
674dced3 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
05177bef 9\r
674dced3 10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
05177bef 12\r
674dced3 13**/\r
05177bef 14\r
15\r
16#include "NullMemoryTest.h"\r
17\r
05177bef 18UINT64 mTestedSystemMemory = 0;\r
19UINT64 mTotalSystemMemory = 0;\r
20EFI_HANDLE mGenericMemoryTestHandle;\r
21\r
05177bef 22EFI_GENERIC_MEMORY_TEST_PROTOCOL mGenericMemoryTest = {\r
23 InitializeMemoryTest,\r
24 GenPerformMemoryTest,\r
25 GenMemoryTestFinished,\r
26 GenCompatibleRangeTest\r
27};\r
28\r
b3764698 29/**\r
30 Entry point of the NULL memory test driver.\r
31 \r
32 This function is the entry point of the NULL memory test driver.\r
33 It simply installs the Generic Memory Test Protocol.\r
34\r
35 @param ImageHandle The firmware allocated handle for the EFI image.\r
36 @param SystemTable A pointer to the EFI System Table.\r
37\r
38 @retval EFI_SUCCESS Generic Memory Test Protocol is successfully installed.\r
39\r
40**/\r
05177bef 41EFI_STATUS\r
42EFIAPI\r
43GenericMemoryTestEntryPoint (\r
44 IN EFI_HANDLE ImageHandle,\r
45 IN EFI_SYSTEM_TABLE *SystemTable\r
46 )\r
05177bef 47{\r
48 EFI_STATUS Status;\r
49\r
05177bef 50 Status = gBS->InstallProtocolInterface (\r
51 &mGenericMemoryTestHandle,\r
52 &gEfiGenericMemTestProtocolGuid,\r
53 EFI_NATIVE_INTERFACE,\r
54 &mGenericMemoryTest\r
55 );\r
b3764698 56 ASSERT_EFI_ERROR (Status);\r
05177bef 57\r
b3764698 58 return EFI_SUCCESS;\r
05177bef 59}\r
b3764698 60\r
1c06bd48 61/**\r
ee37e964 62 Convert the memory range to tested.\r
1c06bd48 63\r
ee37e964
RN
64 @param BaseAddress Base address of the memory range.\r
65 @param Length Length of the memory range.\r
66 @param Capabilities Capabilities of the memory range.\r
1c06bd48 67\r
ee37e964 68 @retval EFI_SUCCESS The memory range is converted to tested.\r
1c06bd48
RN
69 @retval others Error happens.\r
70**/\r
71EFI_STATUS\r
72ConvertToTestedMemory (\r
ee37e964
RN
73 IN UINT64 BaseAddress,\r
74 IN UINT64 Length,\r
75 IN UINT64 Capabilities\r
1c06bd48
RN
76 )\r
77{\r
78 EFI_STATUS Status;\r
79 Status = gDS->RemoveMemorySpace (\r
ee37e964
RN
80 BaseAddress,\r
81 Length\r
1c06bd48
RN
82 );\r
83 if (!EFI_ERROR (Status)) {\r
84 Status = gDS->AddMemorySpace (\r
ee37e964 85 ((Capabilities & EFI_MEMORY_MORE_RELIABLE) == EFI_MEMORY_MORE_RELIABLE) ?\r
1c06bd48 86 EfiGcdMemoryTypeMoreReliable : EfiGcdMemoryTypeSystemMemory,\r
ee37e964
RN
87 BaseAddress,\r
88 Length,\r
89 Capabilities &~\r
1c06bd48
RN
90 (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)\r
91 );\r
92 }\r
93 return Status;\r
94}\r
95\r
b3764698 96/**\r
97 Initialize the generic memory test.\r
98\r
99 This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.MemoryTestInit.\r
100 It simply promotes untested reserved memory to system memory without real test.\r
101\r
102 @param This Protocol instance pointer. \r
103 @param Level The coverage level of the memory test. \r
104 @param RequireSoftECCInit Indicate if the memory need software ECC init. \r
105\r
106 @retval EFI_SUCCESS The generic memory test initialized correctly. \r
107 @retval EFI_NO_MEDIA There is not any non-tested memory found, in this \r
108 function if not any non-tesed memory found means \r
109 that the memory test driver have not detect any \r
110 non-tested extended memory of current system. \r
111\r
112**/\r
05177bef 113EFI_STATUS\r
114EFIAPI\r
115InitializeMemoryTest (\r
116 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,\r
117 IN EXTENDMEM_COVERAGE_LEVEL Level,\r
118 OUT BOOLEAN *RequireSoftECCInit\r
119 )\r
05177bef 120{\r
1c06bd48 121 EFI_STATUS Status;\r
05177bef 122 UINTN NumberOfDescriptors;\r
123 EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;\r
124 UINTN Index;\r
125\r
126 gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);\r
127 for (Index = 0; Index < NumberOfDescriptors; Index++) {\r
128 if (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeReserved &&\r
129 (MemorySpaceMap[Index].Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==\r
130 (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED)\r
131 ) {\r
b3764698 132 //\r
133 // For those reserved memory that have not been tested, simply promote to system memory.\r
134 //\r
ee37e964
RN
135 Status = ConvertToTestedMemory (\r
136 MemorySpaceMap[Index].BaseAddress,\r
137 MemorySpaceMap[Index].Length,\r
138 MemorySpaceMap[Index].Capabilities\r
139 );\r
1c06bd48 140 ASSERT_EFI_ERROR (Status);\r
05177bef 141 mTestedSystemMemory += MemorySpaceMap[Index].Length;\r
142 mTotalSystemMemory += MemorySpaceMap[Index].Length;\r
1c06bd48
RN
143 } else if ((MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeSystemMemory) ||\r
144 (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeMoreReliable)) {\r
05177bef 145 mTotalSystemMemory += MemorySpaceMap[Index].Length;\r
146 }\r
147 }\r
148\r
149 FreePool (MemorySpaceMap);\r
150\r
151 *RequireSoftECCInit = FALSE;\r
152 return EFI_SUCCESS;\r
153}\r
154\r
b3764698 155/**\r
156 Perform the memory test.\r
157\r
158 This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.PerformMemoryTest.\r
159 It simply returns EFI_NOT_FOUND.\r
160\r
161 @param This Protocol instance pointer. \r
162 @param TestedMemorySize Return the tested extended memory size. \r
163 @param TotalMemorySize Return the whole system physical memory size, this \r
164 value may be changed if in some case some error \r
165 DIMMs be disabled. \r
166 @param ErrorOut Any time the memory error occurs, this will be \r
167 TRUE. \r
168 @param IfTestAbort Indicate if the user press "ESC" to skip the memory \r
169 test. \r
170\r
171 @retval EFI_SUCCESS One block of memory test ok, the block size is hide \r
172 internally. \r
173 @retval EFI_NOT_FOUND Indicate all the non-tested memory blocks have \r
174 already go through. \r
175 @retval EFI_DEVICE_ERROR Mis-compare error, and no agent can handle it\r
176\r
177**/\r
05177bef 178EFI_STATUS\r
179EFIAPI\r
180GenPerformMemoryTest (\r
181 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,\r
182 IN OUT UINT64 *TestedMemorySize,\r
183 OUT UINT64 *TotalMemorySize,\r
184 OUT BOOLEAN *ErrorOut,\r
185 IN BOOLEAN TestAbort\r
186 )\r
05177bef 187{\r
188 *ErrorOut = FALSE;\r
189 *TestedMemorySize = mTestedSystemMemory;\r
190 *TotalMemorySize = mTotalSystemMemory;\r
191\r
192 return EFI_NOT_FOUND;\r
193\r
194}\r
195\r
b3764698 196/**\r
197 The memory test finished.\r
198\r
199 This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.Finished.\r
200 It simply returns EFI_SUCCESS.\r
201\r
202 @param This Protocol instance pointer. \r
203\r
204 @retval EFI_SUCCESS Successful free all the generic memory test driver \r
205 allocated resource and notify to platform memory \r
206 test driver that memory test finished. \r
207\r
208**/\r
05177bef 209EFI_STATUS\r
210EFIAPI\r
211GenMemoryTestFinished (\r
212 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This\r
213 )\r
05177bef 214{\r
215 return EFI_SUCCESS;\r
216}\r
217\r
b3764698 218/**\r
219 Provide capability to test compatible range which used by some special\r
220 driver required using memory range before BDS perform memory test.\r
221\r
222 This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.CompatibleRangeTest.\r
223 It simply sets the memory range to system memory.\r
224\r
225 @param This Protocol instance pointer. \r
226 @param StartAddress The start address of the memory range. \r
227 @param Length The memory range's length. \r
228 \r
229 @retval EFI_SUCCESS The compatible memory range pass the memory test. \r
230 @retval EFI_INVALID_PARAMETER The compatible memory range must be below 16M.\r
231\r
232**/\r
05177bef 233EFI_STATUS\r
234EFIAPI\r
235GenCompatibleRangeTest (\r
236 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,\r
1c06bd48
RN
237 IN EFI_PHYSICAL_ADDRESS StartAddress,\r
238 IN UINT64 Length\r
05177bef 239 )\r
05177bef 240{\r
1c06bd48 241 EFI_STATUS Status;\r
b3764698 242 EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;\r
05177bef 243\r
1c06bd48
RN
244 Status = gDS->GetMemorySpaceDescriptor (StartAddress, &Descriptor);\r
245 if (!EFI_ERROR (Status)) {\r
ee37e964
RN
246 Status = ConvertToTestedMemory (\r
247 Descriptor.BaseAddress,\r
248 Descriptor.Length,\r
249 Descriptor.Capabilities\r
250 );\r
1c06bd48
RN
251 }\r
252 return Status;\r
05177bef 253}\r