2 Migrates SEC structures after permanent memory is installed.
4 Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/BaseLib.h>
12 #include <Library/BaseMemoryLib.h>
13 #include <Library/DebugLib.h>
14 #include <Library/HobLib.h>
15 #include <Library/MemoryAllocationLib.h>
16 #include <Library/PeiServicesLib.h>
17 #include <Library/PeiServicesTablePointerLib.h>
19 #include "SecMigrationPei.h"
21 STATIC REPUBLISH_SEC_PPI_PPI mEdkiiRepublishSecPpiPpi
= {
25 GLOBAL_REMOVE_IF_UNREFERENCED EFI_SEC_PLATFORM_INFORMATION_PPI mSecPlatformInformationPostMemoryPpi
= {
26 SecPlatformInformationPostMemory
29 GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_TEMPORARY_RAM_DONE_PPI mSecTemporaryRamDonePostMemoryPpi
= {
30 SecTemporaryRamDonePostMemory
33 GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mSecTemporaryRamSupportPostMemoryPpi
= {
34 SecTemporaryRamSupportPostMemory
37 GLOBAL_REMOVE_IF_UNREFERENCED PEI_SEC_PERFORMANCE_PPI mSecPerformancePpi
= {
38 GetPerformancePostMemory
41 STATIC EFI_PEI_PPI_DESCRIPTOR mEdkiiRepublishSecPpiDescriptor
= {
42 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
43 &gRepublishSecPpiPpiGuid
,
44 &mEdkiiRepublishSecPpiPpi
47 GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_PPI_DESCRIPTOR mSecPlatformInformationPostMemoryDescriptor
= {
48 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
49 &gEfiSecPlatformInformationPpiGuid
,
50 &mSecPlatformInformationPostMemoryPpi
53 GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_PPI_DESCRIPTOR mSecTemporaryRamDonePostMemoryDescriptor
= {
54 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
55 &gEfiTemporaryRamDonePpiGuid
,
56 &mSecTemporaryRamDonePostMemoryPpi
59 GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_PPI_DESCRIPTOR mSecTemporaryRamSupportPostMemoryDescriptor
= {
60 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
61 &gEfiTemporaryRamSupportPpiGuid
,
62 &mSecTemporaryRamSupportPostMemoryPpi
65 GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_PPI_DESCRIPTOR mSecPerformancePpiDescriptor
= {
66 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
67 &gPeiSecPerformancePpiGuid
,
72 Disables the use of Temporary RAM.
74 If present, this service is invoked by the PEI Foundation after
75 the EFI_PEI_PERMANANT_MEMORY_INSTALLED_PPI is installed.
77 @retval EFI_SUCCESS Dummy function, alway return this value.
82 SecTemporaryRamDonePostMemory (
87 // Temporary RAM Done is already done in post-memory
88 // install a stub function that is located in permanent memory
94 This service of the EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI that migrates temporary RAM into
97 @param PeiServices Pointer to the PEI Services Table.
98 @param TemporaryMemoryBase Source Address in temporary memory from which the SEC or PEIM will copy the
99 Temporary RAM contents.
100 @param PermanentMemoryBase Destination Address in permanent memory into which the SEC or PEIM will copy the
101 Temporary RAM contents.
102 @param CopySize Amount of memory to migrate from temporary to permanent memory.
104 @retval EFI_SUCCESS The data was successfully returned.
105 @retval EFI_INVALID_PARAMETER PermanentMemoryBase + CopySize > TemporaryMemoryBase when
106 TemporaryMemoryBase > PermanentMemoryBase.
111 SecTemporaryRamSupportPostMemory (
112 IN CONST EFI_PEI_SERVICES
**PeiServices
,
113 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
114 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
119 // Temporary RAM Support is already done in post-memory
120 // install a stub function that is located in permanent memory
126 This interface conveys performance information out of the Security (SEC) phase into PEI.
128 This service is published by the SEC phase. The SEC phase handoff has an optional
129 EFI_PEI_PPI_DESCRIPTOR list as its final argument when control is passed from SEC into the
130 PEI Foundation. As such, if the platform supports collecting performance data in SEC,
131 this information is encapsulated into the data structure abstracted by this service.
132 This information is collected for the boot-strap processor (BSP) on IA-32.
134 @param[in] PeiServices The pointer to the PEI Services Table.
135 @param[in] This The pointer to this instance of the PEI_SEC_PERFORMANCE_PPI.
136 @param[out] Performance The pointer to performance data collected in SEC phase.
138 @retval EFI_SUCCESS The performance data was successfully returned.
139 @retval EFI_INVALID_PARAMETER The This or Performance is NULL.
140 @retval EFI_NOT_FOUND Can't found the HOB created by the SecMigrationPei component.
145 GetPerformancePostMemory (
146 IN CONST EFI_PEI_SERVICES
**PeiServices
,
147 IN PEI_SEC_PERFORMANCE_PPI
*This
,
148 OUT FIRMWARE_SEC_PERFORMANCE
*Performance
151 SEC_PLATFORM_INFORMATION_CONTEXT_HOB
*SecPlatformInformationContexHob
;
153 if ((This
== NULL
) || (Performance
== NULL
)) {
154 return EFI_INVALID_PARAMETER
;
157 SecPlatformInformationContexHob
= GetFirstGuidHob (&gEfiCallerIdGuid
);
158 if (SecPlatformInformationContexHob
== NULL
) {
159 return EFI_NOT_FOUND
;
162 Performance
->ResetEnd
= SecPlatformInformationContexHob
->FirmwareSecPerformance
.ResetEnd
;
168 This interface conveys state information out of the Security (SEC) phase into PEI.
170 @param[in] PeiServices Pointer to the PEI Services Table.
171 @param[in,out] StructureSize Pointer to the variable describing size of the input buffer.
172 @param[out] PlatformInformationRecord Pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD.
174 @retval EFI_SUCCESS The data was successfully returned.
175 @retval EFI_NOT_FOUND Can't found the HOB created by SecMigrationPei component.
176 @retval EFI_BUFFER_TOO_SMALL The size of buffer pointed by StructureSize is too small and will return
177 the minimal required size in the buffer pointed by StructureSize.
178 @retval EFI_INVALID_PARAMETER The StructureSize is NULL or PlatformInformationRecord is NULL.
183 SecPlatformInformationPostMemory (
184 IN CONST EFI_PEI_SERVICES
**PeiServices
,
185 IN OUT UINT64
*StructureSize
,
186 OUT EFI_SEC_PLATFORM_INFORMATION_RECORD
*PlatformInformationRecord
189 SEC_PLATFORM_INFORMATION_CONTEXT_HOB
*SecPlatformInformationContexHob
;
191 if (StructureSize
== NULL
) {
192 return EFI_INVALID_PARAMETER
;
195 SecPlatformInformationContexHob
= GetFirstGuidHob (&gEfiCallerIdGuid
);
196 if (SecPlatformInformationContexHob
== NULL
) {
197 return EFI_NOT_FOUND
;
200 if (*StructureSize
< SecPlatformInformationContexHob
->Context
.StructureSize
) {
201 *StructureSize
= SecPlatformInformationContexHob
->Context
.StructureSize
;
202 return EFI_BUFFER_TOO_SMALL
;
205 if (PlatformInformationRecord
== NULL
) {
206 return EFI_INVALID_PARAMETER
;
209 *StructureSize
= SecPlatformInformationContexHob
->Context
.StructureSize
;
211 (VOID
*)PlatformInformationRecord
,
212 (VOID
*)SecPlatformInformationContexHob
->Context
.PlatformInformationRecord
,
213 (UINTN
)SecPlatformInformationContexHob
->Context
.StructureSize
220 This interface re-installs PPIs installed in SecCore from a post-memory PEIM.
222 This is to allow a platform that may not support relocation of SecCore to update the PPI instance to a post-memory
223 copy from a PEIM that has been shadowed to permanent memory.
225 @retval EFI_SUCCESS The SecCore PPIs were re-installed successfully.
226 @retval Others An error occurred re-installing the SecCore PPIs.
236 EFI_PEI_PPI_DESCRIPTOR
*PeiPpiDescriptor
;
238 SEC_PLATFORM_INFORMATION_CONTEXT_HOB
*SecPlatformInformationContextHob
;
239 EFI_SEC_PLATFORM_INFORMATION_RECORD
*SecPlatformInformationPtr
;
240 UINT64 SecStructureSize
;
242 SecPlatformInformationPtr
= NULL
;
243 SecStructureSize
= 0;
245 Status
= PeiServicesLocatePpi (
246 &gEfiTemporaryRamDonePpiGuid
,
251 if (!EFI_ERROR (Status
)) {
252 Status
= PeiServicesReInstallPpi (
254 &mSecTemporaryRamDonePostMemoryDescriptor
256 ASSERT_EFI_ERROR (Status
);
259 Status
= PeiServicesLocatePpi (
260 &gEfiTemporaryRamSupportPpiGuid
,
265 if (!EFI_ERROR (Status
)) {
266 Status
= PeiServicesReInstallPpi (
268 &mSecTemporaryRamSupportPostMemoryDescriptor
270 ASSERT_EFI_ERROR (Status
);
273 Status
= PeiServicesCreateHob (
274 EFI_HOB_TYPE_GUID_EXTENSION
,
275 sizeof (SEC_PLATFORM_INFORMATION_CONTEXT_HOB
),
276 (VOID
**)&SecPlatformInformationContextHob
278 ASSERT_EFI_ERROR (Status
);
279 if (EFI_ERROR (Status
)) {
280 DEBUG ((DEBUG_ERROR
, "SecPlatformInformation Context HOB could not be created.\n"));
284 SecPlatformInformationContextHob
->Header
.Name
= gEfiCallerIdGuid
;
285 SecPlatformInformationContextHob
->Revision
= 1;
287 Status
= PeiServicesLocatePpi (
288 &gPeiSecPerformancePpiGuid
,
293 if (!EFI_ERROR (Status
)) {
294 Status
= ((PEI_SEC_PERFORMANCE_PPI
*)PeiPpi
)->GetPerformance (
295 GetPeiServicesTablePointer (),
296 (PEI_SEC_PERFORMANCE_PPI
*)PeiPpi
,
297 &SecPlatformInformationContextHob
->FirmwareSecPerformance
299 ASSERT_EFI_ERROR (Status
);
300 if (!EFI_ERROR (Status
)) {
301 Status
= PeiServicesReInstallPpi (
303 &mSecPerformancePpiDescriptor
305 ASSERT_EFI_ERROR (Status
);
309 Status
= PeiServicesLocatePpi (
310 &gEfiSecPlatformInformationPpiGuid
,
315 if (!EFI_ERROR (Status
)) {
316 Status
= ((EFI_SEC_PLATFORM_INFORMATION_PPI
*)PeiPpi
)->PlatformInformation (
317 GetPeiServicesTablePointer (),
319 SecPlatformInformationPtr
321 ASSERT (Status
== EFI_BUFFER_TOO_SMALL
);
322 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
323 return EFI_NOT_FOUND
;
326 ZeroMem ((VOID
*)&(SecPlatformInformationContextHob
->Context
), sizeof (SEC_PLATFORM_INFORMATION_CONTEXT
));
327 SecPlatformInformationContextHob
->Context
.PlatformInformationRecord
= AllocatePool ((UINTN
)SecStructureSize
);
328 ASSERT (SecPlatformInformationContextHob
->Context
.PlatformInformationRecord
!= NULL
);
329 if (SecPlatformInformationContextHob
->Context
.PlatformInformationRecord
== NULL
) {
330 return EFI_OUT_OF_RESOURCES
;
333 SecPlatformInformationContextHob
->Context
.StructureSize
= SecStructureSize
;
335 Status
= ((EFI_SEC_PLATFORM_INFORMATION_PPI
*)PeiPpi
)->PlatformInformation (
336 GetPeiServicesTablePointer (),
337 &(SecPlatformInformationContextHob
->Context
.StructureSize
),
338 SecPlatformInformationContextHob
->Context
.PlatformInformationRecord
340 ASSERT_EFI_ERROR (Status
);
341 if (!EFI_ERROR (Status
)) {
342 Status
= PeiServicesReInstallPpi (
344 &mSecPlatformInformationPostMemoryDescriptor
346 ASSERT_EFI_ERROR (Status
);
354 This function is the entry point which installs an instance of REPUBLISH_SEC_PPI_PPI.
356 It install the RepublishSecPpi depent on PcdMigrateTemporaryRamFirmwareVolumes, install
357 the PPI when the PcdMigrateTemporaryRamFirmwareVolumes enabled.
359 @param[in] FileHandle Pointer to image file handle.
360 @param[in] PeiServices Pointer to PEI Services Table
362 @retval EFI_ABORTED Disable evacuate temporary memory feature by disable
363 PcdMigrateTemporaryRamFirmwareVolumes.
364 @retval EFI_SUCCESS An instance of REPUBLISH_SEC_PPI_PPI was installed successfully.
365 @retval Others An error occurred installing and instance of REPUBLISH_SEC_PPI_PPI.
370 SecMigrationPeiInitialize (
371 IN EFI_PEI_FILE_HANDLE FileHandle
,
372 IN CONST EFI_PEI_SERVICES
**PeiServices
377 Status
= EFI_ABORTED
;
379 if (PcdGetBool (PcdMigrateTemporaryRamFirmwareVolumes
)) {
380 Status
= PeiServicesInstallPpi (&mEdkiiRepublishSecPpiDescriptor
);
381 ASSERT_EFI_ERROR (Status
);