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