]>
Commit | Line | Data |
---|---|---|
674dced3 | 1 | /** @file\r |
b3764698 | 2 | Implementation of Generic Memory Test Protocol which does not perform real memory test.\r |
05177bef | 3 | \r |
e5eed7d3 HT |
4 | Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r |
5 | This program and the accompanying materials\r | |
674dced3 | 6 | are licensed and made available under the terms and conditions of the BSD License\r |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
05177bef | 9 | \r |
674dced3 | 10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
11 | WITHOUT 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 | 18 | UINT64 mTestedSystemMemory = 0;\r |
19 | UINT64 mTotalSystemMemory = 0;\r | |
20 | EFI_HANDLE mGenericMemoryTestHandle;\r | |
21 | \r | |
05177bef | 22 | EFI_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 | 41 | EFI_STATUS\r |
42 | EFIAPI\r | |
43 | GenericMemoryTestEntryPoint (\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 |
61 | /**\r | |
62 | Initialize the generic memory test.\r | |
63 | \r | |
64 | This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.MemoryTestInit.\r | |
65 | It simply promotes untested reserved memory to system memory without real test.\r | |
66 | \r | |
67 | @param This Protocol instance pointer. \r | |
68 | @param Level The coverage level of the memory test. \r | |
69 | @param RequireSoftECCInit Indicate if the memory need software ECC init. \r | |
70 | \r | |
71 | @retval EFI_SUCCESS The generic memory test initialized correctly. \r | |
72 | @retval EFI_NO_MEDIA There is not any non-tested memory found, in this \r | |
73 | function if not any non-tesed memory found means \r | |
74 | that the memory test driver have not detect any \r | |
75 | non-tested extended memory of current system. \r | |
76 | \r | |
77 | **/\r | |
05177bef | 78 | EFI_STATUS\r |
79 | EFIAPI\r | |
80 | InitializeMemoryTest (\r | |
81 | IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,\r | |
82 | IN EXTENDMEM_COVERAGE_LEVEL Level,\r | |
83 | OUT BOOLEAN *RequireSoftECCInit\r | |
84 | )\r | |
05177bef | 85 | {\r |
86 | UINTN NumberOfDescriptors;\r | |
87 | EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;\r | |
88 | UINTN Index;\r | |
89 | \r | |
90 | gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);\r | |
91 | for (Index = 0; Index < NumberOfDescriptors; Index++) {\r | |
92 | if (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeReserved &&\r | |
93 | (MemorySpaceMap[Index].Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==\r | |
94 | (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED)\r | |
95 | ) {\r | |
b3764698 | 96 | //\r |
97 | // For those reserved memory that have not been tested, simply promote to system memory.\r | |
98 | //\r | |
05177bef | 99 | gDS->RemoveMemorySpace (\r |
100 | MemorySpaceMap[Index].BaseAddress,\r | |
101 | MemorySpaceMap[Index].Length\r | |
102 | );\r | |
103 | \r | |
104 | gDS->AddMemorySpace (\r | |
105 | EfiGcdMemoryTypeSystemMemory,\r | |
106 | MemorySpaceMap[Index].BaseAddress,\r | |
107 | MemorySpaceMap[Index].Length,\r | |
108 | MemorySpaceMap[Index].Capabilities &~\r | |
109 | (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)\r | |
110 | );\r | |
111 | \r | |
112 | mTestedSystemMemory += MemorySpaceMap[Index].Length;\r | |
113 | mTotalSystemMemory += MemorySpaceMap[Index].Length;\r | |
114 | } else if (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeSystemMemory) {\r | |
115 | mTotalSystemMemory += MemorySpaceMap[Index].Length;\r | |
116 | }\r | |
117 | }\r | |
118 | \r | |
119 | FreePool (MemorySpaceMap);\r | |
120 | \r | |
121 | *RequireSoftECCInit = FALSE;\r | |
122 | return EFI_SUCCESS;\r | |
123 | }\r | |
124 | \r | |
b3764698 | 125 | /**\r |
126 | Perform the memory test.\r | |
127 | \r | |
128 | This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.PerformMemoryTest.\r | |
129 | It simply returns EFI_NOT_FOUND.\r | |
130 | \r | |
131 | @param This Protocol instance pointer. \r | |
132 | @param TestedMemorySize Return the tested extended memory size. \r | |
133 | @param TotalMemorySize Return the whole system physical memory size, this \r | |
134 | value may be changed if in some case some error \r | |
135 | DIMMs be disabled. \r | |
136 | @param ErrorOut Any time the memory error occurs, this will be \r | |
137 | TRUE. \r | |
138 | @param IfTestAbort Indicate if the user press "ESC" to skip the memory \r | |
139 | test. \r | |
140 | \r | |
141 | @retval EFI_SUCCESS One block of memory test ok, the block size is hide \r | |
142 | internally. \r | |
143 | @retval EFI_NOT_FOUND Indicate all the non-tested memory blocks have \r | |
144 | already go through. \r | |
145 | @retval EFI_DEVICE_ERROR Mis-compare error, and no agent can handle it\r | |
146 | \r | |
147 | **/\r | |
05177bef | 148 | EFI_STATUS\r |
149 | EFIAPI\r | |
150 | GenPerformMemoryTest (\r | |
151 | IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,\r | |
152 | IN OUT UINT64 *TestedMemorySize,\r | |
153 | OUT UINT64 *TotalMemorySize,\r | |
154 | OUT BOOLEAN *ErrorOut,\r | |
155 | IN BOOLEAN TestAbort\r | |
156 | )\r | |
05177bef | 157 | {\r |
158 | *ErrorOut = FALSE;\r | |
159 | *TestedMemorySize = mTestedSystemMemory;\r | |
160 | *TotalMemorySize = mTotalSystemMemory;\r | |
161 | \r | |
162 | return EFI_NOT_FOUND;\r | |
163 | \r | |
164 | }\r | |
165 | \r | |
b3764698 | 166 | /**\r |
167 | The memory test finished.\r | |
168 | \r | |
169 | This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.Finished.\r | |
170 | It simply returns EFI_SUCCESS.\r | |
171 | \r | |
172 | @param This Protocol instance pointer. \r | |
173 | \r | |
174 | @retval EFI_SUCCESS Successful free all the generic memory test driver \r | |
175 | allocated resource and notify to platform memory \r | |
176 | test driver that memory test finished. \r | |
177 | \r | |
178 | **/\r | |
05177bef | 179 | EFI_STATUS\r |
180 | EFIAPI\r | |
181 | GenMemoryTestFinished (\r | |
182 | IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This\r | |
183 | )\r | |
05177bef | 184 | {\r |
185 | return EFI_SUCCESS;\r | |
186 | }\r | |
187 | \r | |
b3764698 | 188 | /**\r |
189 | Provide capability to test compatible range which used by some special\r | |
190 | driver required using memory range before BDS perform memory test.\r | |
191 | \r | |
192 | This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.CompatibleRangeTest.\r | |
193 | It simply sets the memory range to system memory.\r | |
194 | \r | |
195 | @param This Protocol instance pointer. \r | |
196 | @param StartAddress The start address of the memory range. \r | |
197 | @param Length The memory range's length. \r | |
198 | \r | |
199 | @retval EFI_SUCCESS The compatible memory range pass the memory test. \r | |
200 | @retval EFI_INVALID_PARAMETER The compatible memory range must be below 16M.\r | |
201 | \r | |
202 | **/\r | |
05177bef | 203 | EFI_STATUS\r |
204 | EFIAPI\r | |
205 | GenCompatibleRangeTest (\r | |
206 | IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,\r | |
207 | IN EFI_PHYSICAL_ADDRESS StartAddress,\r | |
208 | IN UINT64 Length\r | |
209 | )\r | |
05177bef | 210 | {\r |
b3764698 | 211 | EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;\r |
05177bef | 212 | \r |
b3764698 | 213 | gDS->GetMemorySpaceDescriptor (StartAddress, &Descriptor);\r |
05177bef | 214 | \r |
215 | gDS->RemoveMemorySpace (StartAddress, Length);\r | |
216 | \r | |
217 | gDS->AddMemorySpace (\r | |
218 | EfiGcdMemoryTypeSystemMemory,\r | |
219 | StartAddress,\r | |
220 | Length,\r | |
b3764698 | 221 | Descriptor.Capabilities &~(EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)\r |
05177bef | 222 | );\r |
223 | \r | |
224 | return EFI_SUCCESS;\r | |
225 | }\r |