2 This will be invoked only once. It will call FspMemoryInit API,
3 register TemporaryRamDonePpi to call TempRamExit API, and register MemoryDiscoveredPpi
4 notify to call FspSiliconInit API.
6 Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
13 #include <Library/PeimEntryPoint.h>
14 #include <Library/PeiServicesLib.h>
15 #include <Library/PeiServicesTablePointerLib.h>
16 #include <Library/BaseLib.h>
17 #include <Library/DebugLib.h>
18 #include <Library/BaseMemoryLib.h>
19 #include <Library/HobLib.h>
20 #include <Library/PcdLib.h>
21 #include <Library/MemoryAllocationLib.h>
22 #include <Library/FspWrapperPlatformLib.h>
23 #include <Library/FspWrapperHobProcessLib.h>
24 #include <Library/TimerLib.h>
25 #include <Library/PerformanceLib.h>
26 #include <Library/FspWrapperApiLib.h>
27 #include <Library/FspMeasurementLib.h>
29 #include <Ppi/FspSiliconInitDone.h>
30 #include <Ppi/EndOfPeiPhase.h>
31 #include <Ppi/MemoryDiscovered.h>
32 #include <Ppi/TemporaryRamDone.h>
33 #include <Ppi/SecPlatformInformation.h>
35 #include <Ppi/FirmwareVolumeInfoMeasurementExcluded.h>
36 #include <Library/FspWrapperApiTestLib.h>
38 #include <FspStatusCode.h>
40 extern EFI_PEI_NOTIFY_DESCRIPTOR mS3EndOfPeiNotifyDesc
;
41 extern EFI_GUID gFspHobGuid
;
44 This function handles S3 resume task at the end of PEI.
46 @param[in] PeiServices Pointer to PEI Services Table.
47 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
48 caused this function to execute.
49 @param[in] Ppi Pointer to the PPI data associated with this function.
51 @retval EFI_STATUS Always return EFI_SUCCESS
56 IN EFI_PEI_SERVICES
**PeiServices
,
57 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
61 EFI_PEI_NOTIFY_DESCRIPTOR mS3EndOfPeiNotifyDesc
= {
62 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
63 &gEfiEndOfPeiSignalPpiGuid
,
68 This function handles S3 resume task at the end of PEI.
70 @param[in] PeiServices Pointer to PEI Services Table.
71 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
72 caused this function to execute.
73 @param[in] Ppi Pointer to the PPI data associated with this function.
75 @retval EFI_STATUS Always return EFI_SUCCESS
80 IN EFI_PEI_SERVICES
**PeiServices
,
81 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
85 NOTIFY_PHASE_PARAMS NotifyPhaseParams
;
88 DEBUG ((DEBUG_INFO
, "S3EndOfPeiNotify enter\n"));
90 NotifyPhaseParams
.Phase
= EnumInitPhaseAfterPciEnumeration
;
91 Status
= CallFspNotifyPhase (&NotifyPhaseParams
);
92 DEBUG ((DEBUG_INFO
, "FSP S3NotifyPhase AfterPciEnumeration status: 0x%x\n", Status
));
95 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
97 if ((Status
>= FSP_STATUS_RESET_REQUIRED_COLD
) && (Status
<= FSP_STATUS_RESET_REQUIRED_8
)) {
98 DEBUG ((DEBUG_INFO
, "FSP S3NotifyPhase AfterPciEnumeration requested reset 0x%x\n", Status
));
99 CallFspWrapperResetSystem (Status
);
102 NotifyPhaseParams
.Phase
= EnumInitPhaseReadyToBoot
;
103 Status
= CallFspNotifyPhase (&NotifyPhaseParams
);
104 DEBUG ((DEBUG_INFO
, "FSP S3NotifyPhase ReadyToBoot status: 0x%x\n", Status
));
107 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
109 if ((Status
>= FSP_STATUS_RESET_REQUIRED_COLD
) && (Status
<= FSP_STATUS_RESET_REQUIRED_8
)) {
110 DEBUG ((DEBUG_INFO
, "FSP S3NotifyPhase ReadyToBoot requested reset 0x%x\n", Status
));
111 CallFspWrapperResetSystem (Status
);
114 NotifyPhaseParams
.Phase
= EnumInitPhaseEndOfFirmware
;
115 Status
= CallFspNotifyPhase (&NotifyPhaseParams
);
116 DEBUG ((DEBUG_INFO
, "FSP S3NotifyPhase EndOfFirmware status: 0x%x\n", Status
));
119 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
121 if ((Status
>= FSP_STATUS_RESET_REQUIRED_COLD
) && (Status
<= FSP_STATUS_RESET_REQUIRED_8
)) {
122 DEBUG ((DEBUG_INFO
, "FSP S3NotifyPhase EndOfFirmware requested reset 0x%x\n", Status
));
123 CallFspWrapperResetSystem (Status
);
130 Return Hob list produced by FSP.
132 @param[in] PeiServices The pointer to the PEI Services Table.
133 @param[in] This The pointer to this instance of this PPI.
134 @param[out] FspHobList The pointer to Hob list produced by FSP.
136 @return EFI_SUCCESS Return Hob list produced by FSP successfully.
140 FspSiliconInitDoneGetFspHobList (
141 IN CONST EFI_PEI_SERVICES
**PeiServices
,
142 IN FSP_SILICON_INIT_DONE_PPI
*This
,
143 OUT VOID
**FspHobList
146 FSP_SILICON_INIT_DONE_PPI mFspSiliconInitDonePpi
= {
147 FspSiliconInitDoneGetFspHobList
150 EFI_PEI_PPI_DESCRIPTOR mPeiFspSiliconInitDonePpi
= {
151 EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
,
152 &gFspSiliconInitDonePpiGuid
,
153 &mFspSiliconInitDonePpi
157 Return Hob list produced by FSP.
159 @param[in] PeiServices The pointer to the PEI Services Table.
160 @param[in] This The pointer to this instance of this PPI.
161 @param[out] FspHobList The pointer to Hob list produced by FSP.
163 @return EFI_SUCCESS Return Hob list produced by FSP successfully.
167 FspSiliconInitDoneGetFspHobList (
168 IN CONST EFI_PEI_SERVICES
**PeiServices
,
169 IN FSP_SILICON_INIT_DONE_PPI
*This
,
170 OUT VOID
**FspHobList
173 EFI_HOB_GUID_TYPE
*GuidHob
;
175 GuidHob
= GetFirstGuidHob (&gFspHobGuid
);
176 if (GuidHob
!= NULL
) {
177 *FspHobList
= *(VOID
**)GET_GUID_HOB_DATA (GuidHob
);
180 return EFI_NOT_FOUND
;
185 Get the FSP S UPD Data address
187 @return FSP-S UPD Data Address
190 GetFspsUpdDataAddress (
194 if (PcdGet64 (PcdFspsUpdDataAddress64
) != 0) {
195 return (UINTN
)PcdGet64 (PcdFspsUpdDataAddress64
);
197 return (UINTN
)PcdGet32 (PcdFspsUpdDataAddress
);
202 This function is for FSP dispatch mode to perform post FSP-S process.
204 @param[in] PeiServices Pointer to PEI Services Table.
205 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
206 caused this function to execute.
207 @param[in] Ppi Pointer to the PPI data associated with this function.
209 @retval EFI_STATUS Status returned by PeiServicesInstallPpi ()
213 FspsWrapperEndOfPeiNotify (
214 IN EFI_PEI_SERVICES
**PeiServices
,
215 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
222 // This step may include platform specific process in some boot loaders so
223 // aligning the same behavior between API and Dispatch modes.
224 // Note: In Dispatch mode no FspHobList so passing NULL to function and
225 // expecting function will handle it.
227 PostFspsHobProcess (NULL
);
230 // Install FspSiliconInitDonePpi so that any other driver can consume this info.
232 Status
= PeiServicesInstallPpi (&mPeiFspSiliconInitDonePpi
);
233 ASSERT_EFI_ERROR (Status
);
238 EFI_PEI_NOTIFY_DESCRIPTOR mFspsWrapperEndOfPeiNotifyDesc
= {
239 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
240 &gEfiEndOfPeiSignalPpiGuid
,
241 FspsWrapperEndOfPeiNotify
245 This function is called after PEI core discover memory and finish migration.
247 @param[in] PeiServices Pointer to PEI Services Table.
248 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
249 caused this function to execute.
250 @param[in] Ppi Pointer to the PPI data associated with this function.
252 @retval EFI_STATUS Always return EFI_SUCCESS
256 PeiMemoryDiscoveredNotify (
257 IN EFI_PEI_SERVICES
**PeiServices
,
258 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
262 EFI_PEI_NOTIFY_DESCRIPTOR mPeiMemoryDiscoveredNotifyDesc
= {
263 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
264 &gEfiPeiMemoryDiscoveredPpiGuid
,
265 PeiMemoryDiscoveredNotify
269 This function is called after PEI core discover memory and finish migration.
271 @param[in] PeiServices Pointer to PEI Services Table.
272 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
273 caused this function to execute.
274 @param[in] Ppi Pointer to the PPI data associated with this function.
276 @retval EFI_STATUS Always return EFI_SUCCESS
280 PeiMemoryDiscoveredNotify (
281 IN EFI_PEI_SERVICES
**PeiServices
,
282 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
286 FSP_INFO_HEADER
*FspsHeaderPtr
;
287 UINT64 TimeStampCounterStart
;
290 EFI_HOB_GUID_TYPE
*GuidHob
;
291 FSPS_UPD_COMMON
*FspsUpdDataPtr
;
294 DEBUG ((DEBUG_INFO
, "PeiMemoryDiscoveredNotify enter\n"));
295 FspsUpdDataPtr
= NULL
;
297 FspsHeaderPtr
= (FSP_INFO_HEADER
*)FspFindFspHeader (PcdGet32 (PcdFspsBaseAddress
));
298 DEBUG ((DEBUG_INFO
, "FspsHeaderPtr - 0x%x\n", FspsHeaderPtr
));
299 if (FspsHeaderPtr
== NULL
) {
300 return EFI_DEVICE_ERROR
;
303 if ((GetFspsUpdDataAddress () == 0) && (FspsHeaderPtr
->CfgRegionSize
!= 0) && (FspsHeaderPtr
->CfgRegionOffset
!= 0)) {
305 // Copy default FSP-S UPD data from Flash
307 FspsUpdDataPtr
= (FSPS_UPD_COMMON
*)AllocateZeroPool ((UINTN
)FspsHeaderPtr
->CfgRegionSize
);
308 ASSERT (FspsUpdDataPtr
!= NULL
);
309 SourceData
= (UINTN
*)((UINTN
)FspsHeaderPtr
->ImageBase
+ (UINTN
)FspsHeaderPtr
->CfgRegionOffset
);
310 CopyMem (FspsUpdDataPtr
, SourceData
, (UINTN
)FspsHeaderPtr
->CfgRegionSize
);
312 FspsUpdDataPtr
= (FSPS_UPD_COMMON
*)GetFspsUpdDataAddress ();
313 ASSERT (FspsUpdDataPtr
!= NULL
);
316 UpdateFspsUpdData ((VOID
*)FspsUpdDataPtr
);
318 TimeStampCounterStart
= AsmReadTsc ();
319 PERF_START_EX (&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, FSP_STATUS_CODE_SILICON_INIT
| FSP_STATUS_CODE_COMMON_CODE
| FSP_STATUS_CODE_API_ENTRY
);
320 Status
= CallFspSiliconInit ((VOID
*)FspsUpdDataPtr
);
321 PERF_END_EX (&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, FSP_STATUS_CODE_SILICON_INIT
| FSP_STATUS_CODE_COMMON_CODE
| FSP_STATUS_CODE_API_EXIT
);
322 DEBUG ((DEBUG_INFO
, "Total time spent executing FspSiliconInitApi: %d millisecond\n", DivU64x32 (GetTimeInNanoSecond (AsmReadTsc () - TimeStampCounterStart
), 1000000)));
325 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
327 if ((Status
>= FSP_STATUS_RESET_REQUIRED_COLD
) && (Status
<= FSP_STATUS_RESET_REQUIRED_8
)) {
328 DEBUG ((DEBUG_INFO
, "FspSiliconInitApi requested reset 0x%x\n", Status
));
329 CallFspWrapperResetSystem (Status
);
332 if (EFI_ERROR (Status
)) {
333 DEBUG ((DEBUG_ERROR
, "ERROR - Failed to execute FspSiliconInitApi(), Status = %r\n", Status
));
336 DEBUG ((DEBUG_INFO
, "FspSiliconInit status: 0x%x\n", Status
));
337 ASSERT_EFI_ERROR (Status
);
339 Status
= TestFspSiliconInitApiOutput ((VOID
*)NULL
);
340 if (RETURN_ERROR (Status
)) {
341 DEBUG ((DEBUG_ERROR
, "ERROR - TestFspSiliconInitApiOutput () fail, Status = %r\n", Status
));
345 // Now FspHobList complete, process it
347 GuidHob
= GetFirstGuidHob (&gFspHobGuid
);
348 ASSERT (GuidHob
!= NULL
);
349 FspHobListPtr
= *(VOID
**)GET_GUID_HOB_DATA (GuidHob
);
350 DEBUG ((DEBUG_INFO
, "FspHobListPtr - 0x%x\n", FspHobListPtr
));
351 PostFspsHobProcess (FspHobListPtr
);
354 // Install FspSiliconInitDonePpi so that any other driver can consume this info.
356 Status
= PeiServicesInstallPpi (&mPeiFspSiliconInitDonePpi
);
357 ASSERT_EFI_ERROR (Status
);
363 Do FSP initialization in API mode.
365 @retval EFI_STATUS Always return EFI_SUCCESS
368 FspsWrapperInitApiMode (
373 EFI_BOOT_MODE BootMode
;
376 // Register MemoryDiscovered Notify to run FspSiliconInit
378 Status
= PeiServicesNotifyPpi (&mPeiMemoryDiscoveredNotifyDesc
);
379 ASSERT_EFI_ERROR (Status
);
382 // Register EndOfPei Notify for S3 to run FSP NotifyPhase
384 PeiServicesGetBootMode (&BootMode
);
385 if (BootMode
== BOOT_ON_S3_RESUME
) {
386 Status
= PeiServicesNotifyPpi (&mS3EndOfPeiNotifyDesc
);
387 ASSERT_EFI_ERROR (Status
);
394 Do FSP initialization in Dispatch mode.
396 @retval FSP initialization status.
399 FspsWrapperInitDispatchMode (
404 EFI_PEI_FIRMWARE_VOLUME_INFO_MEASUREMENT_EXCLUDED_PPI
*MeasurementExcludedFvPpi
;
405 EFI_PEI_PPI_DESCRIPTOR
*MeasurementExcludedPpiList
;
407 MeasurementExcludedFvPpi
= AllocatePool (sizeof (*MeasurementExcludedFvPpi
));
408 ASSERT (MeasurementExcludedFvPpi
!= NULL
);
409 MeasurementExcludedFvPpi
->Count
= 1;
410 MeasurementExcludedFvPpi
->Fv
[0].FvBase
= PcdGet32 (PcdFspsBaseAddress
);
411 MeasurementExcludedFvPpi
->Fv
[0].FvLength
= ((EFI_FIRMWARE_VOLUME_HEADER
*)(UINTN
)PcdGet32 (PcdFspsBaseAddress
))->FvLength
;
413 MeasurementExcludedPpiList
= AllocatePool (sizeof (*MeasurementExcludedPpiList
));
414 ASSERT (MeasurementExcludedPpiList
!= NULL
);
415 MeasurementExcludedPpiList
->Flags
= EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
;
416 MeasurementExcludedPpiList
->Guid
= &gEfiPeiFirmwareVolumeInfoMeasurementExcludedPpiGuid
;
417 MeasurementExcludedPpiList
->Ppi
= MeasurementExcludedFvPpi
;
419 Status
= PeiServicesInstallPpi (MeasurementExcludedPpiList
);
420 ASSERT_EFI_ERROR (Status
);
423 // FSP-S Wrapper running in Dispatch mode and reports FSP-S FV to PEI dispatcher.
425 PeiServicesInstallFvInfoPpi (
427 (VOID
*)(UINTN
)PcdGet32 (PcdFspsBaseAddress
),
428 (UINT32
)((EFI_FIRMWARE_VOLUME_HEADER
*)(UINTN
)PcdGet32 (PcdFspsBaseAddress
))->FvLength
,
433 // Register EndOfPei Nofity to run post FSP-S process.
435 Status
= PeiServicesNotifyPpi (&mFspsWrapperEndOfPeiNotifyDesc
);
436 ASSERT_EFI_ERROR (Status
);
441 This function is called after TCG installed PPI.
443 @param[in] PeiServices Pointer to PEI Services Table.
444 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
445 caused this function to execute.
446 @param[in] Ppi Pointer to the PPI data associated with this function.
448 @retval EFI_STATUS Always return EFI_SUCCESS
453 IN EFI_PEI_SERVICES
**PeiServices
,
454 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
458 EFI_PEI_NOTIFY_DESCRIPTOR mTcgPpiNotifyDesc
= {
459 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
465 This function is called after TCG installed PPI.
467 @param[in] PeiServices Pointer to PEI Services Table.
468 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
469 caused this function to execute.
470 @param[in] Ppi Pointer to the PPI data associated with this function.
472 @retval EFI_STATUS Always return EFI_SUCCESS
477 IN EFI_PEI_SERVICES
**PeiServices
,
478 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
482 UINT32 FspMeasureMask
;
484 DEBUG ((DEBUG_INFO
, "TcgPpiNotify FSPS\n"));
486 FspMeasureMask
= PcdGet32 (PcdFspMeasurementConfig
);
488 if ((FspMeasureMask
& FSP_MEASURE_FSPS
) != 0) {
489 MeasureFspFirmwareBlob (
492 PcdGet32 (PcdFspsBaseAddress
),
493 (UINT32
)((EFI_FIRMWARE_VOLUME_HEADER
*)(UINTN
)PcdGet32 (PcdFspsBaseAddress
))->FvLength
501 This is the entrypoint of PEIM.
503 @param[in] FileHandle Handle of the file being invoked.
504 @param[in] PeiServices Describes the list of possible PEI Services.
506 @retval EFI_SUCCESS if it completed successfully.
510 FspsWrapperPeimEntryPoint (
511 IN EFI_PEI_FILE_HANDLE FileHandle
,
512 IN CONST EFI_PEI_SERVICES
**PeiServices
517 DEBUG ((DEBUG_INFO
, "FspsWrapperPeimEntryPoint\n"));
519 Status
= PeiServicesNotifyPpi (&mTcgPpiNotifyDesc
);
520 ASSERT_EFI_ERROR (Status
);
522 if (PcdGet8 (PcdFspModeSelection
) == 1) {
523 FspsWrapperInitApiMode ();
525 FspsWrapperInitDispatchMode ();