]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTest.c
ArmPkg/TimerDxe: Always perform an EOI, even for spurious interrupts
[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
RN
61/**\r
62 Convert the memory descriptor to tested.\r
63\r
64 @param Descriptor Pointer to EFI_GCD_MEMORY_SPACE_DESCRIPTOR\r
65\r
66 @retval EFI_SUCCESS The memory descriptor is converted to tested.\r
67 @retval others Error happens.\r
68**/\r
69EFI_STATUS\r
70ConvertToTestedMemory (\r
71 IN CONST EFI_GCD_MEMORY_SPACE_DESCRIPTOR *Descriptor\r
72 )\r
73{\r
74 EFI_STATUS Status;\r
75 Status = gDS->RemoveMemorySpace (\r
76 Descriptor->BaseAddress,\r
77 Descriptor->Length\r
78 );\r
79 if (!EFI_ERROR (Status)) {\r
80 Status = gDS->AddMemorySpace (\r
81 ((Descriptor->Capabilities & EFI_MEMORY_MORE_RELIABLE) == EFI_MEMORY_MORE_RELIABLE) ?\r
82 EfiGcdMemoryTypeMoreReliable : EfiGcdMemoryTypeSystemMemory,\r
83 Descriptor->BaseAddress,\r
84 Descriptor->Length,\r
85 Descriptor->Capabilities &~\r
86 (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)\r
87 );\r
88 }\r
89 return Status;\r
90}\r
91\r
92\r
b3764698 93/**\r
94 Initialize the generic memory test.\r
95\r
96 This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.MemoryTestInit.\r
97 It simply promotes untested reserved memory to system memory without real test.\r
98\r
99 @param This Protocol instance pointer. \r
100 @param Level The coverage level of the memory test. \r
101 @param RequireSoftECCInit Indicate if the memory need software ECC init. \r
102\r
103 @retval EFI_SUCCESS The generic memory test initialized correctly. \r
104 @retval EFI_NO_MEDIA There is not any non-tested memory found, in this \r
105 function if not any non-tesed memory found means \r
106 that the memory test driver have not detect any \r
107 non-tested extended memory of current system. \r
108\r
109**/\r
05177bef 110EFI_STATUS\r
111EFIAPI\r
112InitializeMemoryTest (\r
113 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,\r
114 IN EXTENDMEM_COVERAGE_LEVEL Level,\r
115 OUT BOOLEAN *RequireSoftECCInit\r
116 )\r
05177bef 117{\r
1c06bd48 118 EFI_STATUS Status;\r
05177bef 119 UINTN NumberOfDescriptors;\r
120 EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;\r
121 UINTN Index;\r
122\r
123 gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);\r
124 for (Index = 0; Index < NumberOfDescriptors; Index++) {\r
125 if (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeReserved &&\r
126 (MemorySpaceMap[Index].Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==\r
127 (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED)\r
128 ) {\r
b3764698 129 //\r
130 // For those reserved memory that have not been tested, simply promote to system memory.\r
131 //\r
1c06bd48
RN
132 Status = ConvertToTestedMemory (&MemorySpaceMap[Index]);\r
133 ASSERT_EFI_ERROR (Status);\r
05177bef 134 mTestedSystemMemory += MemorySpaceMap[Index].Length;\r
135 mTotalSystemMemory += MemorySpaceMap[Index].Length;\r
1c06bd48
RN
136 } else if ((MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeSystemMemory) ||\r
137 (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeMoreReliable)) {\r
05177bef 138 mTotalSystemMemory += MemorySpaceMap[Index].Length;\r
139 }\r
140 }\r
141\r
142 FreePool (MemorySpaceMap);\r
143\r
144 *RequireSoftECCInit = FALSE;\r
145 return EFI_SUCCESS;\r
146}\r
147\r
b3764698 148/**\r
149 Perform the memory test.\r
150\r
151 This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.PerformMemoryTest.\r
152 It simply returns EFI_NOT_FOUND.\r
153\r
154 @param This Protocol instance pointer. \r
155 @param TestedMemorySize Return the tested extended memory size. \r
156 @param TotalMemorySize Return the whole system physical memory size, this \r
157 value may be changed if in some case some error \r
158 DIMMs be disabled. \r
159 @param ErrorOut Any time the memory error occurs, this will be \r
160 TRUE. \r
161 @param IfTestAbort Indicate if the user press "ESC" to skip the memory \r
162 test. \r
163\r
164 @retval EFI_SUCCESS One block of memory test ok, the block size is hide \r
165 internally. \r
166 @retval EFI_NOT_FOUND Indicate all the non-tested memory blocks have \r
167 already go through. \r
168 @retval EFI_DEVICE_ERROR Mis-compare error, and no agent can handle it\r
169\r
170**/\r
05177bef 171EFI_STATUS\r
172EFIAPI\r
173GenPerformMemoryTest (\r
174 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,\r
175 IN OUT UINT64 *TestedMemorySize,\r
176 OUT UINT64 *TotalMemorySize,\r
177 OUT BOOLEAN *ErrorOut,\r
178 IN BOOLEAN TestAbort\r
179 )\r
05177bef 180{\r
181 *ErrorOut = FALSE;\r
182 *TestedMemorySize = mTestedSystemMemory;\r
183 *TotalMemorySize = mTotalSystemMemory;\r
184\r
185 return EFI_NOT_FOUND;\r
186\r
187}\r
188\r
b3764698 189/**\r
190 The memory test finished.\r
191\r
192 This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.Finished.\r
193 It simply returns EFI_SUCCESS.\r
194\r
195 @param This Protocol instance pointer. \r
196\r
197 @retval EFI_SUCCESS Successful free all the generic memory test driver \r
198 allocated resource and notify to platform memory \r
199 test driver that memory test finished. \r
200\r
201**/\r
05177bef 202EFI_STATUS\r
203EFIAPI\r
204GenMemoryTestFinished (\r
205 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This\r
206 )\r
05177bef 207{\r
208 return EFI_SUCCESS;\r
209}\r
210\r
b3764698 211/**\r
212 Provide capability to test compatible range which used by some special\r
213 driver required using memory range before BDS perform memory test.\r
214\r
215 This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.CompatibleRangeTest.\r
216 It simply sets the memory range to system memory.\r
217\r
218 @param This Protocol instance pointer. \r
219 @param StartAddress The start address of the memory range. \r
220 @param Length The memory range's length. \r
221 \r
222 @retval EFI_SUCCESS The compatible memory range pass the memory test. \r
223 @retval EFI_INVALID_PARAMETER The compatible memory range must be below 16M.\r
224\r
225**/\r
05177bef 226EFI_STATUS\r
227EFIAPI\r
228GenCompatibleRangeTest (\r
229 IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,\r
1c06bd48
RN
230 IN EFI_PHYSICAL_ADDRESS StartAddress,\r
231 IN UINT64 Length\r
05177bef 232 )\r
05177bef 233{\r
1c06bd48 234 EFI_STATUS Status;\r
b3764698 235 EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;\r
05177bef 236\r
1c06bd48
RN
237 Status = gDS->GetMemorySpaceDescriptor (StartAddress, &Descriptor);\r
238 if (!EFI_ERROR (Status)) {\r
239 Status = ConvertToTestedMemory (&Descriptor);\r
240 }\r
241 return Status;\r
05177bef 242}\r