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
30 GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_TEMPORARY_RAM_DONE_PPI mSecTemporaryRamDonePostMemoryPpi
= {
31 SecTemporaryRamDonePostMemory
34 GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mSecTemporaryRamSupportPostMemoryPpi
= {
35 SecTemporaryRamSupportPostMemory
38 GLOBAL_REMOVE_IF_UNREFERENCED PEI_SEC_PERFORMANCE_PPI mSecPerformancePpi
= {
39 GetPerformancePostMemory
42 STATIC EFI_PEI_PPI_DESCRIPTOR mEdkiiRepublishSecPpiDescriptor
= {
43 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
44 &gRepublishSecPpiPpiGuid
,
45 &mEdkiiRepublishSecPpiPpi
48 GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_PPI_DESCRIPTOR mSecPlatformInformationPostMemoryDescriptor
= {
49 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
50 &gEfiSecPlatformInformationPpiGuid
,
51 &mSecPlatformInformationPostMemoryPpi
54 GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_PPI_DESCRIPTOR mSecTemporaryRamDonePostMemoryDescriptor
= {
55 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
56 &gEfiTemporaryRamDonePpiGuid
,
57 &mSecTemporaryRamDonePostMemoryPpi
60 GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_PPI_DESCRIPTOR mSecTemporaryRamSupportPostMemoryDescriptor
= {
61 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
62 &gEfiTemporaryRamSupportPpiGuid
,
63 &mSecTemporaryRamSupportPostMemoryPpi
66 GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_PPI_DESCRIPTOR mSecPerformancePpiDescriptor
= {
67 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
68 &gPeiSecPerformancePpiGuid
,
73 Disables the use of Temporary RAM.
75 If present, this service is invoked by the PEI Foundation after
76 the EFI_PEI_PERMANANT_MEMORY_INSTALLED_PPI is installed.
78 @retval EFI_SUCCESS Dummy function, alway return this value.
83 SecTemporaryRamDonePostMemory (
88 // Temporary RAM Done is already done in post-memory
89 // install a stub function that is located in permanent memory
95 This service of the EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI that migrates temporary RAM into
98 @param PeiServices Pointer to the PEI Services Table.
99 @param TemporaryMemoryBase Source Address in temporary memory from which the SEC or PEIM will copy the
100 Temporary RAM contents.
101 @param PermanentMemoryBase Destination Address in permanent memory into which the SEC or PEIM will copy the
102 Temporary RAM contents.
103 @param CopySize Amount of memory to migrate from temporary to permanent memory.
105 @retval EFI_SUCCESS The data was successfully returned.
106 @retval EFI_INVALID_PARAMETER PermanentMemoryBase + CopySize > TemporaryMemoryBase when
107 TemporaryMemoryBase > PermanentMemoryBase.
112 SecTemporaryRamSupportPostMemory (
113 IN CONST EFI_PEI_SERVICES
**PeiServices
,
114 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
115 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
120 // Temporary RAM Support is already done in post-memory
121 // install a stub function that is located in permanent memory
127 This interface conveys performance information out of the Security (SEC) phase into PEI.
129 This service is published by the SEC phase. The SEC phase handoff has an optional
130 EFI_PEI_PPI_DESCRIPTOR list as its final argument when control is passed from SEC into the
131 PEI Foundation. As such, if the platform supports collecting performance data in SEC,
132 this information is encapsulated into the data structure abstracted by this service.
133 This information is collected for the boot-strap processor (BSP) on IA-32.
135 @param[in] PeiServices The pointer to the PEI Services Table.
136 @param[in] This The pointer to this instance of the PEI_SEC_PERFORMANCE_PPI.
137 @param[out] Performance The pointer to performance data collected in SEC phase.
139 @retval EFI_SUCCESS The performance data was successfully returned.
140 @retval EFI_INVALID_PARAMETER The This or Performance is NULL.
141 @retval EFI_NOT_FOUND Can't found the HOB created by the SecMigrationPei component.
146 GetPerformancePostMemory (
147 IN CONST EFI_PEI_SERVICES
**PeiServices
,
148 IN PEI_SEC_PERFORMANCE_PPI
*This
,
149 OUT FIRMWARE_SEC_PERFORMANCE
*Performance
152 SEC_PLATFORM_INFORMATION_CONTEXT_HOB
*SecPlatformInformationContexHob
;
154 if (This
== NULL
|| Performance
== NULL
) {
155 return EFI_INVALID_PARAMETER
;
158 SecPlatformInformationContexHob
= GetFirstGuidHob (&gEfiCallerIdGuid
);
159 if (SecPlatformInformationContexHob
== NULL
) {
160 return EFI_NOT_FOUND
;
163 Performance
->ResetEnd
= SecPlatformInformationContexHob
->FirmwareSecPerformance
.ResetEnd
;
169 This interface conveys state information out of the Security (SEC) phase into PEI.
171 @param[in] PeiServices Pointer to the PEI Services Table.
172 @param[in,out] StructureSize Pointer to the variable describing size of the input buffer.
173 @param[out] PlatformInformationRecord Pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD.
175 @retval EFI_SUCCESS The data was successfully returned.
176 @retval EFI_NOT_FOUND Can't found the HOB created by SecMigrationPei component.
177 @retval EFI_BUFFER_TOO_SMALL The size of buffer pointed by StructureSize is too small and will return
178 the minimal required size in the buffer pointed by StructureSize.
179 @retval EFI_INVALID_PARAMETER The StructureSize is NULL or PlatformInformationRecord is NULL.
184 SecPlatformInformationPostMemory (
185 IN CONST EFI_PEI_SERVICES
**PeiServices
,
186 IN OUT UINT64
*StructureSize
,
187 OUT EFI_SEC_PLATFORM_INFORMATION_RECORD
*PlatformInformationRecord
190 SEC_PLATFORM_INFORMATION_CONTEXT_HOB
*SecPlatformInformationContexHob
;
192 if (StructureSize
== NULL
) {
193 return EFI_INVALID_PARAMETER
;
196 SecPlatformInformationContexHob
= GetFirstGuidHob (&gEfiCallerIdGuid
);
197 if (SecPlatformInformationContexHob
== NULL
) {
198 return EFI_NOT_FOUND
;
201 if (*StructureSize
< SecPlatformInformationContexHob
->Context
.StructureSize
) {
202 *StructureSize
= SecPlatformInformationContexHob
->Context
.StructureSize
;
203 return EFI_BUFFER_TOO_SMALL
;
206 if (PlatformInformationRecord
== NULL
) {
207 return EFI_INVALID_PARAMETER
;
210 *StructureSize
= SecPlatformInformationContexHob
->Context
.StructureSize
;
212 (VOID
*) PlatformInformationRecord
,
213 (VOID
*) SecPlatformInformationContexHob
->Context
.PlatformInformationRecord
,
214 (UINTN
) SecPlatformInformationContexHob
->Context
.StructureSize
221 This interface re-installs PPIs installed in SecCore from a post-memory PEIM.
223 This is to allow a platform that may not support relocation of SecCore to update the PPI instance to a post-memory
224 copy from a PEIM that has been shadowed to permanent memory.
226 @retval EFI_SUCCESS The SecCore PPIs were re-installed successfully.
227 @retval Others An error occurred re-installing the SecCore PPIs.
237 EFI_PEI_PPI_DESCRIPTOR
*PeiPpiDescriptor
;
239 SEC_PLATFORM_INFORMATION_CONTEXT_HOB
*SecPlatformInformationContextHob
;
240 EFI_SEC_PLATFORM_INFORMATION_RECORD
*SecPlatformInformationPtr
;
241 UINT64 SecStructureSize
;
243 SecPlatformInformationPtr
= NULL
;
244 SecStructureSize
= 0;
246 Status
= PeiServicesLocatePpi (
247 &gEfiTemporaryRamDonePpiGuid
,
252 if (!EFI_ERROR (Status
)) {
253 Status
= PeiServicesReInstallPpi (
255 &mSecTemporaryRamDonePostMemoryDescriptor
257 ASSERT_EFI_ERROR (Status
);
260 Status
= PeiServicesLocatePpi (
261 &gEfiTemporaryRamSupportPpiGuid
,
266 if (!EFI_ERROR (Status
)) {
267 Status
= PeiServicesReInstallPpi (
269 &mSecTemporaryRamSupportPostMemoryDescriptor
271 ASSERT_EFI_ERROR (Status
);
274 Status
= PeiServicesCreateHob (
275 EFI_HOB_TYPE_GUID_EXTENSION
,
276 sizeof (SEC_PLATFORM_INFORMATION_CONTEXT_HOB
),
277 (VOID
**) &SecPlatformInformationContextHob
279 ASSERT_EFI_ERROR (Status
);
280 if (EFI_ERROR (Status
)) {
281 DEBUG ((DEBUG_ERROR
, "SecPlatformInformation Context HOB could not be created.\n"));
285 SecPlatformInformationContextHob
->Header
.Name
= gEfiCallerIdGuid
;
286 SecPlatformInformationContextHob
->Revision
= 1;
288 Status
= PeiServicesLocatePpi (
289 &gPeiSecPerformancePpiGuid
,
294 if (!EFI_ERROR (Status
)) {
295 Status
= ((PEI_SEC_PERFORMANCE_PPI
*) PeiPpi
)->GetPerformance (
296 GetPeiServicesTablePointer (),
297 (PEI_SEC_PERFORMANCE_PPI
*) PeiPpi
,
298 &SecPlatformInformationContextHob
->FirmwareSecPerformance
300 ASSERT_EFI_ERROR (Status
);
301 if (!EFI_ERROR (Status
)) {
302 Status
= PeiServicesReInstallPpi (
304 &mSecPerformancePpiDescriptor
306 ASSERT_EFI_ERROR (Status
);
310 Status
= PeiServicesLocatePpi (
311 &gEfiSecPlatformInformationPpiGuid
,
316 if (!EFI_ERROR (Status
)) {
317 Status
= ((EFI_SEC_PLATFORM_INFORMATION_PPI
*) PeiPpi
)->PlatformInformation (
318 GetPeiServicesTablePointer (),
320 SecPlatformInformationPtr
322 ASSERT (Status
== EFI_BUFFER_TOO_SMALL
);
323 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
324 return EFI_NOT_FOUND
;
327 ZeroMem ((VOID
*) &(SecPlatformInformationContextHob
->Context
), sizeof (SEC_PLATFORM_INFORMATION_CONTEXT
));
328 SecPlatformInformationContextHob
->Context
.PlatformInformationRecord
= AllocatePool ((UINTN
) SecStructureSize
);
329 ASSERT (SecPlatformInformationContextHob
->Context
.PlatformInformationRecord
!= NULL
);
330 if (SecPlatformInformationContextHob
->Context
.PlatformInformationRecord
== NULL
) {
331 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
);