]>
Commit | Line | Data |
---|---|---|
479613bd MK |
1 | /** @file\r |
2 | Migrates SEC structures after permanent memory is installed.\r | |
3 | \r | |
4 | Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>\r | |
5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
6 | \r | |
7 | **/\r | |
8 | \r | |
9 | #include <Base.h>\r | |
10 | \r | |
11 | #include <Library/BaseLib.h>\r | |
12 | #include <Library/BaseMemoryLib.h>\r | |
13 | #include <Library/DebugLib.h>\r | |
14 | #include <Library/HobLib.h>\r | |
15 | #include <Library/MemoryAllocationLib.h>\r | |
16 | #include <Library/PeiServicesLib.h>\r | |
17 | #include <Library/PeiServicesTablePointerLib.h>\r | |
18 | \r | |
19 | #include "SecMigrationPei.h"\r | |
20 | \r | |
21 | STATIC REPUBLISH_SEC_PPI_PPI mEdkiiRepublishSecPpiPpi = {\r | |
22 | RepublishSecPpis\r | |
23 | };\r | |
24 | \r | |
25 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_SEC_PLATFORM_INFORMATION_PPI mSecPlatformInformationPostMemoryPpi = {\r | |
26 | SecPlatformInformationPostMemory\r | |
27 | };\r | |
28 | \r | |
29 | \r | |
30 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_TEMPORARY_RAM_DONE_PPI mSecTemporaryRamDonePostMemoryPpi = {\r | |
31 | SecTemporaryRamDonePostMemory\r | |
32 | };\r | |
33 | \r | |
34 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mSecTemporaryRamSupportPostMemoryPpi = {\r | |
35 | SecTemporaryRamSupportPostMemory\r | |
36 | };\r | |
37 | \r | |
38 | GLOBAL_REMOVE_IF_UNREFERENCED PEI_SEC_PERFORMANCE_PPI mSecPerformancePpi = {\r | |
39 | GetPerformancePostMemory\r | |
40 | };\r | |
41 | \r | |
42 | STATIC EFI_PEI_PPI_DESCRIPTOR mEdkiiRepublishSecPpiDescriptor = {\r | |
43 | (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r | |
44 | &gRepublishSecPpiPpiGuid,\r | |
45 | &mEdkiiRepublishSecPpiPpi\r | |
46 | };\r | |
47 | \r | |
48 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_PPI_DESCRIPTOR mSecPlatformInformationPostMemoryDescriptor = {\r | |
49 | (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r | |
50 | &gEfiSecPlatformInformationPpiGuid,\r | |
51 | &mSecPlatformInformationPostMemoryPpi\r | |
52 | };\r | |
53 | \r | |
54 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_PPI_DESCRIPTOR mSecTemporaryRamDonePostMemoryDescriptor = {\r | |
55 | (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r | |
56 | &gEfiTemporaryRamDonePpiGuid,\r | |
57 | &mSecTemporaryRamDonePostMemoryPpi\r | |
58 | };\r | |
59 | \r | |
60 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_PPI_DESCRIPTOR mSecTemporaryRamSupportPostMemoryDescriptor = {\r | |
61 | (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r | |
62 | &gEfiTemporaryRamSupportPpiGuid,\r | |
63 | &mSecTemporaryRamSupportPostMemoryPpi\r | |
64 | };\r | |
65 | \r | |
66 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_PPI_DESCRIPTOR mSecPerformancePpiDescriptor = {\r | |
67 | (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r | |
68 | &gPeiSecPerformancePpiGuid,\r | |
69 | &mSecPerformancePpi\r | |
70 | };\r | |
71 | \r | |
72 | /**\r | |
73 | Disables the use of Temporary RAM.\r | |
74 | \r | |
75 | If present, this service is invoked by the PEI Foundation after\r | |
76 | the EFI_PEI_PERMANANT_MEMORY_INSTALLED_PPI is installed.\r | |
77 | \r | |
78 | @retval EFI_SUCCESS Dummy function, alway return this value.\r | |
79 | \r | |
80 | **/\r | |
81 | EFI_STATUS\r | |
82 | EFIAPI\r | |
83 | SecTemporaryRamDonePostMemory (\r | |
84 | VOID\r | |
85 | )\r | |
86 | {\r | |
87 | //\r | |
88 | // Temporary RAM Done is already done in post-memory\r | |
89 | // install a stub function that is located in permanent memory\r | |
90 | //\r | |
91 | return EFI_SUCCESS;\r | |
92 | }\r | |
93 | \r | |
94 | /**\r | |
95 | This service of the EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI that migrates temporary RAM into\r | |
96 | permanent memory.\r | |
97 | \r | |
98 | @param PeiServices Pointer to the PEI Services Table.\r | |
99 | @param TemporaryMemoryBase Source Address in temporary memory from which the SEC or PEIM will copy the\r | |
100 | Temporary RAM contents.\r | |
101 | @param PermanentMemoryBase Destination Address in permanent memory into which the SEC or PEIM will copy the\r | |
102 | Temporary RAM contents.\r | |
103 | @param CopySize Amount of memory to migrate from temporary to permanent memory.\r | |
104 | \r | |
105 | @retval EFI_SUCCESS The data was successfully returned.\r | |
106 | @retval EFI_INVALID_PARAMETER PermanentMemoryBase + CopySize > TemporaryMemoryBase when\r | |
107 | TemporaryMemoryBase > PermanentMemoryBase.\r | |
108 | \r | |
109 | **/\r | |
110 | EFI_STATUS\r | |
111 | EFIAPI\r | |
112 | SecTemporaryRamSupportPostMemory (\r | |
113 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
114 | IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,\r | |
115 | IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,\r | |
116 | IN UINTN CopySize\r | |
117 | )\r | |
118 | {\r | |
119 | //\r | |
120 | // Temporary RAM Support is already done in post-memory\r | |
121 | // install a stub function that is located in permanent memory\r | |
122 | //\r | |
123 | return EFI_SUCCESS;\r | |
124 | }\r | |
125 | \r | |
126 | /**\r | |
127 | This interface conveys performance information out of the Security (SEC) phase into PEI.\r | |
128 | \r | |
129 | This service is published by the SEC phase. The SEC phase handoff has an optional\r | |
130 | EFI_PEI_PPI_DESCRIPTOR list as its final argument when control is passed from SEC into the\r | |
131 | PEI Foundation. As such, if the platform supports collecting performance data in SEC,\r | |
132 | this information is encapsulated into the data structure abstracted by this service.\r | |
133 | This information is collected for the boot-strap processor (BSP) on IA-32.\r | |
134 | \r | |
135 | @param[in] PeiServices The pointer to the PEI Services Table.\r | |
136 | @param[in] This The pointer to this instance of the PEI_SEC_PERFORMANCE_PPI.\r | |
137 | @param[out] Performance The pointer to performance data collected in SEC phase.\r | |
138 | \r | |
139 | @retval EFI_SUCCESS The performance data was successfully returned.\r | |
140 | @retval EFI_INVALID_PARAMETER The This or Performance is NULL.\r | |
141 | @retval EFI_NOT_FOUND Can't found the HOB created by the SecMigrationPei component.\r | |
142 | \r | |
143 | **/\r | |
144 | EFI_STATUS\r | |
145 | EFIAPI\r | |
146 | GetPerformancePostMemory (\r | |
147 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
148 | IN PEI_SEC_PERFORMANCE_PPI *This,\r | |
149 | OUT FIRMWARE_SEC_PERFORMANCE *Performance\r | |
150 | )\r | |
151 | {\r | |
152 | SEC_PLATFORM_INFORMATION_CONTEXT_HOB *SecPlatformInformationContexHob;\r | |
153 | \r | |
154 | if (This == NULL || Performance == NULL) {\r | |
155 | return EFI_INVALID_PARAMETER;\r | |
156 | }\r | |
157 | \r | |
158 | SecPlatformInformationContexHob = GetFirstGuidHob (&gEfiCallerIdGuid);\r | |
159 | if (SecPlatformInformationContexHob == NULL) {\r | |
160 | return EFI_NOT_FOUND;\r | |
161 | }\r | |
162 | \r | |
163 | Performance->ResetEnd = SecPlatformInformationContexHob->FirmwareSecPerformance.ResetEnd;\r | |
164 | \r | |
165 | return EFI_SUCCESS;\r | |
166 | }\r | |
167 | \r | |
168 | /**\r | |
169 | This interface conveys state information out of the Security (SEC) phase into PEI.\r | |
170 | \r | |
171 | @param[in] PeiServices Pointer to the PEI Services Table.\r | |
172 | @param[in,out] StructureSize Pointer to the variable describing size of the input buffer.\r | |
173 | @param[out] PlatformInformationRecord Pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD.\r | |
174 | \r | |
175 | @retval EFI_SUCCESS The data was successfully returned.\r | |
176 | @retval EFI_NOT_FOUND Can't found the HOB created by SecMigrationPei component.\r | |
177 | @retval EFI_BUFFER_TOO_SMALL The size of buffer pointed by StructureSize is too small and will return\r | |
178 | the minimal required size in the buffer pointed by StructureSize.\r | |
179 | @retval EFI_INVALID_PARAMETER The StructureSize is NULL or PlatformInformationRecord is NULL.\r | |
180 | \r | |
181 | **/\r | |
182 | EFI_STATUS\r | |
183 | EFIAPI\r | |
184 | SecPlatformInformationPostMemory (\r | |
185 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
186 | IN OUT UINT64 *StructureSize,\r | |
187 | OUT EFI_SEC_PLATFORM_INFORMATION_RECORD *PlatformInformationRecord\r | |
188 | )\r | |
189 | {\r | |
190 | SEC_PLATFORM_INFORMATION_CONTEXT_HOB *SecPlatformInformationContexHob;\r | |
191 | \r | |
192 | if (StructureSize == NULL) {\r | |
193 | return EFI_INVALID_PARAMETER;\r | |
194 | }\r | |
195 | \r | |
196 | SecPlatformInformationContexHob = GetFirstGuidHob (&gEfiCallerIdGuid);\r | |
197 | if (SecPlatformInformationContexHob == NULL) {\r | |
198 | return EFI_NOT_FOUND;\r | |
199 | }\r | |
200 | \r | |
201 | if (*StructureSize < SecPlatformInformationContexHob->Context.StructureSize) {\r | |
202 | *StructureSize = SecPlatformInformationContexHob->Context.StructureSize;\r | |
203 | return EFI_BUFFER_TOO_SMALL;\r | |
204 | }\r | |
205 | \r | |
206 | if (PlatformInformationRecord == NULL) {\r | |
207 | return EFI_INVALID_PARAMETER;\r | |
208 | }\r | |
209 | \r | |
210 | *StructureSize = SecPlatformInformationContexHob->Context.StructureSize;\r | |
211 | CopyMem (\r | |
212 | (VOID *) PlatformInformationRecord,\r | |
213 | (VOID *) SecPlatformInformationContexHob->Context.PlatformInformationRecord,\r | |
214 | (UINTN) SecPlatformInformationContexHob->Context.StructureSize\r | |
215 | );\r | |
216 | \r | |
217 | return EFI_SUCCESS;\r | |
218 | }\r | |
219 | \r | |
220 | /**\r | |
221 | This interface re-installs PPIs installed in SecCore from a post-memory PEIM.\r | |
222 | \r | |
223 | This is to allow a platform that may not support relocation of SecCore to update the PPI instance to a post-memory\r | |
224 | copy from a PEIM that has been shadowed to permanent memory.\r | |
225 | \r | |
226 | @retval EFI_SUCCESS The SecCore PPIs were re-installed successfully.\r | |
227 | @retval Others An error occurred re-installing the SecCore PPIs.\r | |
228 | \r | |
229 | **/\r | |
230 | EFI_STATUS\r | |
231 | EFIAPI\r | |
232 | RepublishSecPpis (\r | |
233 | VOID\r | |
234 | )\r | |
235 | {\r | |
236 | EFI_STATUS Status;\r | |
237 | EFI_PEI_PPI_DESCRIPTOR *PeiPpiDescriptor;\r | |
238 | VOID *PeiPpi;\r | |
239 | SEC_PLATFORM_INFORMATION_CONTEXT_HOB *SecPlatformInformationContextHob;\r | |
240 | EFI_SEC_PLATFORM_INFORMATION_RECORD *SecPlatformInformationPtr;\r | |
241 | UINT64 SecStructureSize;\r | |
242 | \r | |
243 | SecPlatformInformationPtr = NULL;\r | |
244 | SecStructureSize = 0;\r | |
245 | \r | |
246 | Status = PeiServicesLocatePpi (\r | |
247 | &gEfiTemporaryRamDonePpiGuid,\r | |
248 | 0,\r | |
249 | &PeiPpiDescriptor,\r | |
250 | (VOID **) &PeiPpi\r | |
251 | );\r | |
252 | if (!EFI_ERROR (Status)) {\r | |
253 | Status = PeiServicesReInstallPpi (\r | |
254 | PeiPpiDescriptor,\r | |
255 | &mSecTemporaryRamDonePostMemoryDescriptor\r | |
256 | );\r | |
257 | ASSERT_EFI_ERROR (Status);\r | |
258 | }\r | |
259 | \r | |
260 | Status = PeiServicesLocatePpi (\r | |
261 | &gEfiTemporaryRamSupportPpiGuid,\r | |
262 | 0,\r | |
263 | &PeiPpiDescriptor,\r | |
264 | (VOID **) &PeiPpi\r | |
265 | );\r | |
266 | if (!EFI_ERROR (Status)) {\r | |
267 | Status = PeiServicesReInstallPpi (\r | |
268 | PeiPpiDescriptor,\r | |
269 | &mSecTemporaryRamSupportPostMemoryDescriptor\r | |
270 | );\r | |
271 | ASSERT_EFI_ERROR (Status);\r | |
272 | }\r | |
273 | \r | |
274 | Status = PeiServicesCreateHob (\r | |
275 | EFI_HOB_TYPE_GUID_EXTENSION,\r | |
276 | sizeof (SEC_PLATFORM_INFORMATION_CONTEXT_HOB),\r | |
277 | (VOID **) &SecPlatformInformationContextHob\r | |
278 | );\r | |
279 | ASSERT_EFI_ERROR (Status);\r | |
280 | if (EFI_ERROR (Status)) {\r | |
281 | DEBUG ((DEBUG_ERROR, "SecPlatformInformation Context HOB could not be created.\n"));\r | |
282 | return Status;\r | |
283 | }\r | |
284 | \r | |
285 | SecPlatformInformationContextHob->Header.Name = gEfiCallerIdGuid;\r | |
286 | SecPlatformInformationContextHob->Revision = 1;\r | |
287 | \r | |
288 | Status = PeiServicesLocatePpi (\r | |
289 | &gPeiSecPerformancePpiGuid,\r | |
290 | 0,\r | |
291 | &PeiPpiDescriptor,\r | |
292 | (VOID **) &PeiPpi\r | |
293 | );\r | |
294 | if (!EFI_ERROR (Status)) {\r | |
295 | Status = ((PEI_SEC_PERFORMANCE_PPI *) PeiPpi)->GetPerformance (\r | |
296 | GetPeiServicesTablePointer (),\r | |
297 | (PEI_SEC_PERFORMANCE_PPI *) PeiPpi,\r | |
298 | &SecPlatformInformationContextHob->FirmwareSecPerformance\r | |
299 | );\r | |
300 | ASSERT_EFI_ERROR (Status);\r | |
301 | if (!EFI_ERROR (Status)) {\r | |
302 | Status = PeiServicesReInstallPpi (\r | |
303 | PeiPpiDescriptor,\r | |
304 | &mSecPerformancePpiDescriptor\r | |
305 | );\r | |
306 | ASSERT_EFI_ERROR (Status);\r | |
307 | }\r | |
308 | }\r | |
309 | \r | |
310 | Status = PeiServicesLocatePpi (\r | |
311 | &gEfiSecPlatformInformationPpiGuid,\r | |
312 | 0,\r | |
313 | &PeiPpiDescriptor,\r | |
314 | (VOID **) &PeiPpi\r | |
315 | );\r | |
316 | if (!EFI_ERROR (Status)) {\r | |
317 | Status = ((EFI_SEC_PLATFORM_INFORMATION_PPI *) PeiPpi)->PlatformInformation (\r | |
318 | GetPeiServicesTablePointer (),\r | |
319 | &SecStructureSize,\r | |
320 | SecPlatformInformationPtr\r | |
321 | );\r | |
322 | ASSERT (Status == EFI_BUFFER_TOO_SMALL);\r | |
323 | if (Status != EFI_BUFFER_TOO_SMALL) {\r | |
324 | return EFI_NOT_FOUND;\r | |
325 | }\r | |
326 | \r | |
327 | ZeroMem ((VOID *) &(SecPlatformInformationContextHob->Context), sizeof (SEC_PLATFORM_INFORMATION_CONTEXT));\r | |
328 | SecPlatformInformationContextHob->Context.PlatformInformationRecord = AllocatePool ((UINTN) SecStructureSize);\r | |
329 | ASSERT (SecPlatformInformationContextHob->Context.PlatformInformationRecord != NULL);\r | |
330 | if (SecPlatformInformationContextHob->Context.PlatformInformationRecord == NULL) {\r | |
331 | return EFI_OUT_OF_RESOURCES;\r | |
332 | }\r | |
333 | SecPlatformInformationContextHob->Context.StructureSize = SecStructureSize;\r | |
334 | \r | |
335 | Status = ((EFI_SEC_PLATFORM_INFORMATION_PPI *) PeiPpi)->PlatformInformation (\r | |
336 | GetPeiServicesTablePointer (),\r | |
337 | &(SecPlatformInformationContextHob->Context.StructureSize),\r | |
338 | SecPlatformInformationContextHob->Context.PlatformInformationRecord\r | |
339 | );\r | |
340 | ASSERT_EFI_ERROR (Status);\r | |
341 | if (!EFI_ERROR (Status)) {\r | |
342 | Status = PeiServicesReInstallPpi (\r | |
343 | PeiPpiDescriptor,\r | |
344 | &mSecPlatformInformationPostMemoryDescriptor\r | |
345 | );\r | |
346 | ASSERT_EFI_ERROR (Status);\r | |
347 | }\r | |
348 | }\r | |
349 | \r | |
350 | return EFI_SUCCESS;\r | |
351 | }\r | |
352 | \r | |
353 | /**\r | |
354 | This function is the entry point which installs an instance of REPUBLISH_SEC_PPI_PPI.\r | |
355 | \r | |
356 | It install the RepublishSecPpi depent on PcdMigrateTemporaryRamFirmwareVolumes, install\r | |
357 | the PPI when the PcdMigrateTemporaryRamFirmwareVolumes enabled.\r | |
358 | \r | |
359 | @param[in] FileHandle Pointer to image file handle.\r | |
360 | @param[in] PeiServices Pointer to PEI Services Table\r | |
361 | \r | |
362 | @retval EFI_ABORTED Disable evacuate temporary memory feature by disable\r | |
363 | PcdMigrateTemporaryRamFirmwareVolumes.\r | |
364 | @retval EFI_SUCCESS An instance of REPUBLISH_SEC_PPI_PPI was installed successfully.\r | |
365 | @retval Others An error occurred installing and instance of REPUBLISH_SEC_PPI_PPI.\r | |
366 | \r | |
367 | **/\r | |
368 | EFI_STATUS\r | |
369 | EFIAPI\r | |
370 | SecMigrationPeiInitialize (\r | |
371 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
372 | IN CONST EFI_PEI_SERVICES **PeiServices\r | |
373 | )\r | |
374 | {\r | |
375 | EFI_STATUS Status;\r | |
376 | \r | |
377 | Status = EFI_ABORTED;\r | |
378 | \r | |
379 | if (PcdGetBool (PcdMigrateTemporaryRamFirmwareVolumes)) {\r | |
380 | Status = PeiServicesInstallPpi (&mEdkiiRepublishSecPpiDescriptor);\r | |
381 | ASSERT_EFI_ERROR (Status);\r | |
382 | }\r | |
383 | \r | |
384 | return Status;\r | |
385 | }\r |