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/FspWrapperMultiPhaseProcessLib.h>
25 #include <Library/TimerLib.h>
26 #include <Library/PerformanceLib.h>
27 #include <Library/FspWrapperApiLib.h>
28 #include <Library/FspMeasurementLib.h>
30 #include <Ppi/FspSiliconInitDone.h>
31 #include <Ppi/EndOfPeiPhase.h>
32 #include <Ppi/MemoryDiscovered.h>
33 #include <Ppi/TemporaryRamDone.h>
34 #include <Ppi/SecPlatformInformation.h>
36 #include <Ppi/FirmwareVolumeInfoMeasurementExcluded.h>
37 #include <Library/FspWrapperApiTestLib.h>
39 #include <FspStatusCode.h>
40 #include <FspGlobalData.h>
42 extern EFI_PEI_NOTIFY_DESCRIPTOR mS3EndOfPeiNotifyDesc
;
43 extern EFI_GUID gFspHobGuid
;
46 This function handles S3 resume task at the end of PEI.
48 @param[in] PeiServices Pointer to PEI Services Table.
49 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
50 caused this function to execute.
51 @param[in] Ppi Pointer to the PPI data associated with this function.
53 @retval EFI_STATUS Always return EFI_SUCCESS
58 IN EFI_PEI_SERVICES
**PeiServices
,
59 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
63 EFI_PEI_NOTIFY_DESCRIPTOR mS3EndOfPeiNotifyDesc
= {
64 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
65 &gEfiEndOfPeiSignalPpiGuid
,
70 This function handles S3 resume task at the end of PEI.
72 @param[in] PeiServices Pointer to PEI Services Table.
73 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
74 caused this function to execute.
75 @param[in] Ppi Pointer to the PPI data associated with this function.
77 @retval EFI_STATUS Always return EFI_SUCCESS
82 IN EFI_PEI_SERVICES
**PeiServices
,
83 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
87 NOTIFY_PHASE_PARAMS NotifyPhaseParams
;
90 DEBUG ((DEBUG_INFO
, "S3EndOfPeiNotify enter\n"));
92 NotifyPhaseParams
.Phase
= EnumInitPhaseAfterPciEnumeration
;
93 Status
= CallFspNotifyPhase (&NotifyPhaseParams
);
94 DEBUG ((DEBUG_INFO
, "FSP S3NotifyPhase AfterPciEnumeration status: 0x%x\n", Status
));
97 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
99 if ((Status
>= FSP_STATUS_RESET_REQUIRED_COLD
) && (Status
<= FSP_STATUS_RESET_REQUIRED_8
)) {
100 DEBUG ((DEBUG_INFO
, "FSP S3NotifyPhase AfterPciEnumeration requested reset 0x%x\n", Status
));
101 CallFspWrapperResetSystem (Status
);
104 NotifyPhaseParams
.Phase
= EnumInitPhaseReadyToBoot
;
105 Status
= CallFspNotifyPhase (&NotifyPhaseParams
);
106 DEBUG ((DEBUG_INFO
, "FSP S3NotifyPhase ReadyToBoot status: 0x%x\n", Status
));
109 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
111 if ((Status
>= FSP_STATUS_RESET_REQUIRED_COLD
) && (Status
<= FSP_STATUS_RESET_REQUIRED_8
)) {
112 DEBUG ((DEBUG_INFO
, "FSP S3NotifyPhase ReadyToBoot requested reset 0x%x\n", Status
));
113 CallFspWrapperResetSystem (Status
);
116 NotifyPhaseParams
.Phase
= EnumInitPhaseEndOfFirmware
;
117 Status
= CallFspNotifyPhase (&NotifyPhaseParams
);
118 DEBUG ((DEBUG_INFO
, "FSP S3NotifyPhase EndOfFirmware status: 0x%x\n", Status
));
121 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
123 if ((Status
>= FSP_STATUS_RESET_REQUIRED_COLD
) && (Status
<= FSP_STATUS_RESET_REQUIRED_8
)) {
124 DEBUG ((DEBUG_INFO
, "FSP S3NotifyPhase EndOfFirmware requested reset 0x%x\n", Status
));
125 CallFspWrapperResetSystem (Status
);
132 Return Hob list produced by FSP.
134 @param[in] PeiServices The pointer to the PEI Services Table.
135 @param[in] This The pointer to this instance of this PPI.
136 @param[out] FspHobList The pointer to Hob list produced by FSP.
138 @return EFI_SUCCESS Return Hob list produced by FSP successfully.
142 FspSiliconInitDoneGetFspHobList (
143 IN CONST EFI_PEI_SERVICES
**PeiServices
,
144 IN FSP_SILICON_INIT_DONE_PPI
*This
,
145 OUT VOID
**FspHobList
148 FSP_SILICON_INIT_DONE_PPI mFspSiliconInitDonePpi
= {
149 FspSiliconInitDoneGetFspHobList
152 EFI_PEI_PPI_DESCRIPTOR mPeiFspSiliconInitDonePpi
= {
153 EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
,
154 &gFspSiliconInitDonePpiGuid
,
155 &mFspSiliconInitDonePpi
159 Return Hob list produced by FSP.
161 @param[in] PeiServices The pointer to the PEI Services Table.
162 @param[in] This The pointer to this instance of this PPI.
163 @param[out] FspHobList The pointer to Hob list produced by FSP.
165 @return EFI_SUCCESS Return Hob list produced by FSP successfully.
169 FspSiliconInitDoneGetFspHobList (
170 IN CONST EFI_PEI_SERVICES
**PeiServices
,
171 IN FSP_SILICON_INIT_DONE_PPI
*This
,
172 OUT VOID
**FspHobList
175 EFI_HOB_GUID_TYPE
*GuidHob
;
177 GuidHob
= GetFirstGuidHob (&gFspHobGuid
);
178 if (GuidHob
!= NULL
) {
179 *FspHobList
= *(VOID
**)GET_GUID_HOB_DATA (GuidHob
);
182 return EFI_NOT_FOUND
;
187 Get the FSP S UPD Data address
189 @return FSP-S UPD Data Address
192 GetFspsUpdDataAddress (
196 if (PcdGet64 (PcdFspsUpdDataAddress64
) != 0) {
197 return (UINTN
)PcdGet64 (PcdFspsUpdDataAddress64
);
199 return (UINTN
)PcdGet32 (PcdFspsUpdDataAddress
);
204 This function is for FSP dispatch mode to perform post FSP-S process.
206 @param[in] PeiServices Pointer to PEI Services Table.
207 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
208 caused this function to execute.
209 @param[in] Ppi Pointer to the PPI data associated with this function.
211 @retval EFI_STATUS Status returned by PeiServicesInstallPpi ()
215 FspsWrapperEndOfPeiNotify (
216 IN EFI_PEI_SERVICES
**PeiServices
,
217 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
224 // This step may include platform specific process in some boot loaders so
225 // aligning the same behavior between API and Dispatch modes.
226 // Note: In Dispatch mode no FspHobList so passing NULL to function and
227 // expecting function will handle it.
229 PostFspsHobProcess (NULL
);
232 // Install FspSiliconInitDonePpi so that any other driver can consume this info.
234 Status
= PeiServicesInstallPpi (&mPeiFspSiliconInitDonePpi
);
235 ASSERT_EFI_ERROR (Status
);
240 EFI_PEI_NOTIFY_DESCRIPTOR mFspsWrapperEndOfPeiNotifyDesc
= {
241 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
242 &gEfiEndOfPeiSignalPpiGuid
,
243 FspsWrapperEndOfPeiNotify
247 This function is called after PEI core discover memory and finish migration.
249 @param[in] PeiServices Pointer to PEI Services Table.
250 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
251 caused this function to execute.
252 @param[in] Ppi Pointer to the PPI data associated with this function.
254 @retval EFI_STATUS Always return EFI_SUCCESS
258 PeiMemoryDiscoveredNotify (
259 IN EFI_PEI_SERVICES
**PeiServices
,
260 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
264 EFI_PEI_NOTIFY_DESCRIPTOR mPeiMemoryDiscoveredNotifyDesc
= {
265 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
266 &gEfiPeiMemoryDiscoveredPpiGuid
,
267 PeiMemoryDiscoveredNotify
271 This function is called after PEI core discover memory and finish migration.
273 @param[in] PeiServices Pointer to PEI Services Table.
274 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
275 caused this function to execute.
276 @param[in] Ppi Pointer to the PPI data associated with this function.
278 @retval EFI_STATUS Always return EFI_SUCCESS
282 PeiMemoryDiscoveredNotify (
283 IN EFI_PEI_SERVICES
**PeiServices
,
284 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
288 FSP_INFO_HEADER
*FspsHeaderPtr
;
289 UINT64 TimeStampCounterStart
;
292 EFI_HOB_GUID_TYPE
*GuidHob
;
293 FSPS_UPD_COMMON
*FspsUpdDataPtr
;
296 DEBUG ((DEBUG_INFO
, "PeiMemoryDiscoveredNotify enter\n"));
297 FspsUpdDataPtr
= NULL
;
299 FspsHeaderPtr
= (FSP_INFO_HEADER
*)FspFindFspHeader (PcdGet32 (PcdFspsBaseAddress
));
300 DEBUG ((DEBUG_INFO
, "FspsHeaderPtr - 0x%x\n", FspsHeaderPtr
));
301 if (FspsHeaderPtr
== NULL
) {
302 return EFI_DEVICE_ERROR
;
305 if ((GetFspsUpdDataAddress () == 0) && (FspsHeaderPtr
->CfgRegionSize
!= 0) && (FspsHeaderPtr
->CfgRegionOffset
!= 0)) {
307 // Copy default FSP-S UPD data from Flash
309 FspsUpdDataPtr
= (FSPS_UPD_COMMON
*)AllocateZeroPool ((UINTN
)FspsHeaderPtr
->CfgRegionSize
);
310 ASSERT (FspsUpdDataPtr
!= NULL
);
311 SourceData
= (UINTN
*)((UINTN
)FspsHeaderPtr
->ImageBase
+ (UINTN
)FspsHeaderPtr
->CfgRegionOffset
);
312 CopyMem (FspsUpdDataPtr
, SourceData
, (UINTN
)FspsHeaderPtr
->CfgRegionSize
);
314 FspsUpdDataPtr
= (FSPS_UPD_COMMON
*)GetFspsUpdDataAddress ();
315 ASSERT (FspsUpdDataPtr
!= NULL
);
318 UpdateFspsUpdData ((VOID
*)FspsUpdDataPtr
);
320 TimeStampCounterStart
= AsmReadTsc ();
321 PERF_START_EX (&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, FSP_STATUS_CODE_SILICON_INIT
| FSP_STATUS_CODE_COMMON_CODE
| FSP_STATUS_CODE_API_ENTRY
);
322 Status
= CallFspSiliconInit ((VOID
*)FspsUpdDataPtr
);
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 %r\n", Status
));
329 CallFspWrapperResetSystem (Status
);
332 if ((Status
!= FSP_STATUS_VARIABLE_REQUEST
) && EFI_ERROR (Status
)) {
333 DEBUG ((DEBUG_ERROR
, "ERROR - Failed to execute FspSiliconInitApi(), Status = %r\n", Status
));
334 ASSERT_EFI_ERROR (Status
);
337 DEBUG ((DEBUG_INFO
, "FspSiliconInit status: %r\n", Status
));
339 if (Status
== FSP_STATUS_VARIABLE_REQUEST
) {
341 // call to Variable request handler
343 FspWrapperVariableRequestHandler (&FspHobListPtr
, FspMultiPhaseSiInitApiIndex
);
347 // See if MultiPhase process is required or not
349 FspWrapperMultiPhaseHandler (&FspHobListPtr
, FspMultiPhaseSiInitApiIndex
); // FspS MultiPhase
351 PERF_END_EX (&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, FSP_STATUS_CODE_SILICON_INIT
| FSP_STATUS_CODE_COMMON_CODE
| FSP_STATUS_CODE_API_EXIT
);
352 DEBUG ((DEBUG_INFO
, "Total time spent executing FspSiliconInitApi: %d millisecond\n", DivU64x32 (GetTimeInNanoSecond (AsmReadTsc () - TimeStampCounterStart
), 1000000)));
354 Status
= TestFspSiliconInitApiOutput ((VOID
*)NULL
);
355 if (RETURN_ERROR (Status
)) {
356 DEBUG ((DEBUG_ERROR
, "ERROR - TestFspSiliconInitApiOutput () fail, Status = %r\n", Status
));
360 // Now FspHobList complete, process it
362 GuidHob
= GetFirstGuidHob (&gFspHobGuid
);
363 ASSERT (GuidHob
!= NULL
);
364 FspHobListPtr
= *(VOID
**)GET_GUID_HOB_DATA (GuidHob
);
365 DEBUG ((DEBUG_INFO
, "FspHobListPtr - 0x%x\n", FspHobListPtr
));
366 PostFspsHobProcess (FspHobListPtr
);
369 // Install FspSiliconInitDonePpi so that any other driver can consume this info.
371 Status
= PeiServicesInstallPpi (&mPeiFspSiliconInitDonePpi
);
372 ASSERT_EFI_ERROR (Status
);
378 Do FSP initialization in API mode.
380 @retval EFI_STATUS Always return EFI_SUCCESS
383 FspsWrapperInitApiMode (
388 EFI_BOOT_MODE BootMode
;
391 // Register MemoryDiscovered Notify to run FspSiliconInit
393 Status
= PeiServicesNotifyPpi (&mPeiMemoryDiscoveredNotifyDesc
);
394 ASSERT_EFI_ERROR (Status
);
397 // Register EndOfPei Notify for S3 to run FSP NotifyPhase
399 PeiServicesGetBootMode (&BootMode
);
400 if (BootMode
== BOOT_ON_S3_RESUME
) {
401 Status
= PeiServicesNotifyPpi (&mS3EndOfPeiNotifyDesc
);
402 ASSERT_EFI_ERROR (Status
);
409 Do FSP initialization in Dispatch mode.
411 @retval FSP initialization status.
414 FspsWrapperInitDispatchMode (
419 EFI_PEI_FIRMWARE_VOLUME_INFO_MEASUREMENT_EXCLUDED_PPI
*MeasurementExcludedFvPpi
;
420 EFI_PEI_PPI_DESCRIPTOR
*MeasurementExcludedPpiList
;
422 MeasurementExcludedFvPpi
= AllocatePool (sizeof (*MeasurementExcludedFvPpi
));
423 ASSERT (MeasurementExcludedFvPpi
!= NULL
);
424 MeasurementExcludedFvPpi
->Count
= 1;
425 MeasurementExcludedFvPpi
->Fv
[0].FvBase
= PcdGet32 (PcdFspsBaseAddress
);
426 MeasurementExcludedFvPpi
->Fv
[0].FvLength
= ((EFI_FIRMWARE_VOLUME_HEADER
*)(UINTN
)PcdGet32 (PcdFspsBaseAddress
))->FvLength
;
428 MeasurementExcludedPpiList
= AllocatePool (sizeof (*MeasurementExcludedPpiList
));
429 ASSERT (MeasurementExcludedPpiList
!= NULL
);
430 MeasurementExcludedPpiList
->Flags
= EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
;
431 MeasurementExcludedPpiList
->Guid
= &gEfiPeiFirmwareVolumeInfoMeasurementExcludedPpiGuid
;
432 MeasurementExcludedPpiList
->Ppi
= MeasurementExcludedFvPpi
;
434 Status
= PeiServicesInstallPpi (MeasurementExcludedPpiList
);
435 ASSERT_EFI_ERROR (Status
);
438 // FSP-S Wrapper running in Dispatch mode and reports FSP-S FV to PEI dispatcher.
440 PeiServicesInstallFvInfoPpi (
442 (VOID
*)(UINTN
)PcdGet32 (PcdFspsBaseAddress
),
443 (UINT32
)((EFI_FIRMWARE_VOLUME_HEADER
*)(UINTN
)PcdGet32 (PcdFspsBaseAddress
))->FvLength
,
448 // Register EndOfPei Nofity to run post FSP-S process.
450 Status
= PeiServicesNotifyPpi (&mFspsWrapperEndOfPeiNotifyDesc
);
451 ASSERT_EFI_ERROR (Status
);
456 This function is called after TCG installed PPI.
458 @param[in] PeiServices Pointer to PEI Services Table.
459 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
460 caused this function to execute.
461 @param[in] Ppi Pointer to the PPI data associated with this function.
463 @retval EFI_STATUS Always return EFI_SUCCESS
468 IN EFI_PEI_SERVICES
**PeiServices
,
469 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
473 EFI_PEI_NOTIFY_DESCRIPTOR mTcgPpiNotifyDesc
= {
474 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
480 This function is called after TCG installed PPI.
482 @param[in] PeiServices Pointer to PEI Services Table.
483 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
484 caused this function to execute.
485 @param[in] Ppi Pointer to the PPI data associated with this function.
487 @retval EFI_STATUS Always return EFI_SUCCESS
492 IN EFI_PEI_SERVICES
**PeiServices
,
493 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
497 UINT32 FspMeasureMask
;
499 DEBUG ((DEBUG_INFO
, "TcgPpiNotify FSPS\n"));
501 FspMeasureMask
= PcdGet32 (PcdFspMeasurementConfig
);
503 if ((FspMeasureMask
& FSP_MEASURE_FSPS
) != 0) {
504 MeasureFspFirmwareBlob (
507 PcdGet32 (PcdFspsBaseAddress
),
508 (UINT32
)((EFI_FIRMWARE_VOLUME_HEADER
*)(UINTN
)PcdGet32 (PcdFspsBaseAddress
))->FvLength
516 This is the entrypoint of PEIM.
518 @param[in] FileHandle Handle of the file being invoked.
519 @param[in] PeiServices Describes the list of possible PEI Services.
521 @retval EFI_SUCCESS if it completed successfully.
525 FspsWrapperPeimEntryPoint (
526 IN EFI_PEI_FILE_HANDLE FileHandle
,
527 IN CONST EFI_PEI_SERVICES
**PeiServices
532 DEBUG ((DEBUG_INFO
, "FspsWrapperPeimEntryPoint\n"));
534 Status
= PeiServicesNotifyPpi (&mTcgPpiNotifyDesc
);
535 ASSERT_EFI_ERROR (Status
);
537 if (PcdGet8 (PcdFspModeSelection
) == 1) {
538 FspsWrapperInitApiMode ();
540 FspsWrapperInitDispatchMode ();