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 - 2019, 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>
28 #include <Ppi/FspSiliconInitDone.h>
29 #include <Ppi/EndOfPeiPhase.h>
30 #include <Ppi/MemoryDiscovered.h>
31 #include <Ppi/TemporaryRamDone.h>
32 #include <Ppi/SecPlatformInformation.h>
33 #include <Library/FspWrapperApiTestLib.h>
35 #include <FspStatusCode.h>
37 extern EFI_PEI_NOTIFY_DESCRIPTOR mS3EndOfPeiNotifyDesc
;
38 extern EFI_GUID gFspHobGuid
;
41 This function handles S3 resume task at the end of PEI
43 @param[in] PeiServices Pointer to PEI Services Table.
44 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
45 caused this function to execute.
46 @param[in] Ppi Pointer to the PPI data associated with this function.
48 @retval EFI_STATUS Always return EFI_SUCCESS
53 IN EFI_PEI_SERVICES
**PeiServices
,
54 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
58 EFI_PEI_NOTIFY_DESCRIPTOR mS3EndOfPeiNotifyDesc
= {
59 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
60 &gEfiEndOfPeiSignalPpiGuid
,
65 This function handles S3 resume task at the end of PEI
67 @param[in] PeiServices Pointer to PEI Services Table.
68 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
69 caused this function to execute.
70 @param[in] Ppi Pointer to the PPI data associated with this function.
72 @retval EFI_STATUS Always return EFI_SUCCESS
77 IN EFI_PEI_SERVICES
**PeiServices
,
78 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
82 NOTIFY_PHASE_PARAMS NotifyPhaseParams
;
85 DEBUG((DEBUG_INFO
, "S3EndOfPeiNotify enter\n"));
87 NotifyPhaseParams
.Phase
= EnumInitPhaseAfterPciEnumeration
;
88 Status
= CallFspNotifyPhase (&NotifyPhaseParams
);
89 DEBUG((DEBUG_INFO
, "FSP S3NotifyPhase AfterPciEnumeration status: 0x%x\n", Status
));
92 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
94 if ((Status
>= FSP_STATUS_RESET_REQUIRED_COLD
) && (Status
<= FSP_STATUS_RESET_REQUIRED_8
)) {
95 DEBUG((DEBUG_INFO
, "FSP S3NotifyPhase AfterPciEnumeration requested reset 0x%x\n", Status
));
96 CallFspWrapperResetSystem ((UINT32
)Status
);
99 NotifyPhaseParams
.Phase
= EnumInitPhaseReadyToBoot
;
100 Status
= CallFspNotifyPhase (&NotifyPhaseParams
);
101 DEBUG((DEBUG_INFO
, "FSP S3NotifyPhase ReadyToBoot status: 0x%x\n", Status
));
104 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
106 if ((Status
>= FSP_STATUS_RESET_REQUIRED_COLD
) && (Status
<= FSP_STATUS_RESET_REQUIRED_8
)) {
107 DEBUG((DEBUG_INFO
, "FSP S3NotifyPhase ReadyToBoot requested reset 0x%x\n", Status
));
108 CallFspWrapperResetSystem ((UINT32
)Status
);
111 NotifyPhaseParams
.Phase
= EnumInitPhaseEndOfFirmware
;
112 Status
= CallFspNotifyPhase (&NotifyPhaseParams
);
113 DEBUG((DEBUG_INFO
, "FSP S3NotifyPhase EndOfFirmware status: 0x%x\n", Status
));
116 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
118 if ((Status
>= FSP_STATUS_RESET_REQUIRED_COLD
) && (Status
<= FSP_STATUS_RESET_REQUIRED_8
)) {
119 DEBUG((DEBUG_INFO
, "FSP S3NotifyPhase EndOfFirmware requested reset 0x%x\n", Status
));
120 CallFspWrapperResetSystem ((UINT32
)Status
);
127 Return Hob list produced by FSP.
129 @param[in] PeiServices The pointer to the PEI Services Table.
130 @param[in] This The pointer to this instance of this PPI.
131 @param[out] FspHobList The pointer to Hob list produced by FSP.
133 @return EFI_SUCCESS Return Hob list produced by FSP successfully.
137 FspSiliconInitDoneGetFspHobList (
138 IN CONST EFI_PEI_SERVICES
**PeiServices
,
139 IN FSP_SILICON_INIT_DONE_PPI
*This
,
140 OUT VOID
**FspHobList
143 FSP_SILICON_INIT_DONE_PPI mFspSiliconInitDonePpi
= {
144 FspSiliconInitDoneGetFspHobList
147 EFI_PEI_PPI_DESCRIPTOR mPeiFspSiliconInitDonePpi
= {
148 EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
,
149 &gFspSiliconInitDonePpiGuid
,
150 &mFspSiliconInitDonePpi
154 Return Hob list produced by FSP.
156 @param[in] PeiServices The pointer to the PEI Services Table.
157 @param[in] This The pointer to this instance of this PPI.
158 @param[out] FspHobList The pointer to Hob list produced by FSP.
160 @return EFI_SUCCESS Return Hob list produced by FSP successfully.
164 FspSiliconInitDoneGetFspHobList (
165 IN CONST EFI_PEI_SERVICES
**PeiServices
,
166 IN FSP_SILICON_INIT_DONE_PPI
*This
,
167 OUT VOID
**FspHobList
170 EFI_HOB_GUID_TYPE
*GuidHob
;
172 GuidHob
= GetFirstGuidHob (&gFspHobGuid
);
173 if (GuidHob
!= NULL
) {
174 *FspHobList
= *(VOID
**)GET_GUID_HOB_DATA(GuidHob
);
177 return EFI_NOT_FOUND
;
182 This function is for FSP dispatch mode to perform post FSP-S process.
184 @param[in] PeiServices Pointer to PEI Services Table.
185 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
186 caused this function to execute.
187 @param[in] Ppi Pointer to the PPI data associated with this function.
189 @retval EFI_STATUS Status returned by PeiServicesInstallPpi ()
193 FspsWrapperEndOfPeiNotify (
194 IN EFI_PEI_SERVICES
**PeiServices
,
195 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
202 // This step may include platform specific process in some boot loaders so
203 // aligning the same behavior between API and Dispatch modes.
204 // Note: In Dispatch mode no FspHobList so passing NULL to function and
205 // expecting function will handle it.
207 PostFspsHobProcess (NULL
);
210 // Install FspSiliconInitDonePpi so that any other driver can consume this info.
212 Status
= PeiServicesInstallPpi (&mPeiFspSiliconInitDonePpi
);
213 ASSERT_EFI_ERROR(Status
);
218 EFI_PEI_NOTIFY_DESCRIPTOR mFspsWrapperEndOfPeiNotifyDesc
= {
219 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
220 &gEfiEndOfPeiSignalPpiGuid
,
221 FspsWrapperEndOfPeiNotify
225 This function is called after PEI core discover memory and finish migration.
227 @param[in] PeiServices Pointer to PEI Services Table.
228 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
229 caused this function to execute.
230 @param[in] Ppi Pointer to the PPI data associated with this function.
232 @retval EFI_STATUS Always return EFI_SUCCESS
236 PeiMemoryDiscoveredNotify (
237 IN EFI_PEI_SERVICES
**PeiServices
,
238 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
242 EFI_PEI_NOTIFY_DESCRIPTOR mPeiMemoryDiscoveredNotifyDesc
= {
243 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
244 &gEfiPeiMemoryDiscoveredPpiGuid
,
245 PeiMemoryDiscoveredNotify
249 This function is called after PEI core discover memory and finish migration.
251 @param[in] PeiServices Pointer to PEI Services Table.
252 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
253 caused this function to execute.
254 @param[in] Ppi Pointer to the PPI data associated with this function.
256 @retval EFI_STATUS Always return EFI_SUCCESS
260 PeiMemoryDiscoveredNotify (
261 IN EFI_PEI_SERVICES
**PeiServices
,
262 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
266 FSP_INFO_HEADER
*FspsHeaderPtr
;
267 UINT64 TimeStampCounterStart
;
270 EFI_HOB_GUID_TYPE
*GuidHob
;
271 FSPS_UPD_COMMON
*FspsUpdDataPtr
;
274 DEBUG ((DEBUG_INFO
, "PeiMemoryDiscoveredNotify enter\n"));
275 FspsUpdDataPtr
= NULL
;
277 FspsHeaderPtr
= (FSP_INFO_HEADER
*)FspFindFspHeader (PcdGet32 (PcdFspsBaseAddress
));
278 DEBUG ((DEBUG_INFO
, "FspsHeaderPtr - 0x%x\n", FspsHeaderPtr
));
279 if (FspsHeaderPtr
== NULL
) {
280 return EFI_DEVICE_ERROR
;
283 if (PcdGet32 (PcdFspsUpdDataAddress
) == 0 && (FspsHeaderPtr
->CfgRegionSize
!= 0) && (FspsHeaderPtr
->CfgRegionOffset
!= 0)) {
285 // Copy default FSP-S UPD data from Flash
287 FspsUpdDataPtr
= (FSPS_UPD_COMMON
*)AllocateZeroPool ((UINTN
)FspsHeaderPtr
->CfgRegionSize
);
288 ASSERT (FspsUpdDataPtr
!= NULL
);
289 SourceData
= (UINTN
*)((UINTN
)FspsHeaderPtr
->ImageBase
+ (UINTN
)FspsHeaderPtr
->CfgRegionOffset
);
290 CopyMem (FspsUpdDataPtr
, SourceData
, (UINTN
)FspsHeaderPtr
->CfgRegionSize
);
292 FspsUpdDataPtr
= (FSPS_UPD_COMMON
*)PcdGet32 (PcdFspsUpdDataAddress
);
293 ASSERT (FspsUpdDataPtr
!= NULL
);
296 UpdateFspsUpdData ((VOID
*)FspsUpdDataPtr
);
298 TimeStampCounterStart
= AsmReadTsc ();
299 PERF_START_EX(&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, FSP_STATUS_CODE_SILICON_INIT
| FSP_STATUS_CODE_COMMON_CODE
| FSP_STATUS_CODE_API_ENTRY
);
300 Status
= CallFspSiliconInit ((VOID
*)FspsUpdDataPtr
);
301 PERF_END_EX(&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, FSP_STATUS_CODE_SILICON_INIT
| FSP_STATUS_CODE_COMMON_CODE
| FSP_STATUS_CODE_API_EXIT
);
302 DEBUG ((DEBUG_INFO
, "Total time spent executing FspSiliconInitApi: %d millisecond\n", DivU64x32 (GetTimeInNanoSecond (AsmReadTsc () - TimeStampCounterStart
), 1000000)));
305 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
307 if ((Status
>= FSP_STATUS_RESET_REQUIRED_COLD
) && (Status
<= FSP_STATUS_RESET_REQUIRED_8
)) {
308 DEBUG((DEBUG_INFO
, "FspSiliconInitApi requested reset 0x%x\n", Status
));
309 CallFspWrapperResetSystem ((UINT32
)Status
);
312 if (EFI_ERROR(Status
)) {
313 DEBUG ((DEBUG_ERROR
, "ERROR - Failed to execute FspSiliconInitApi(), Status = %r\n", Status
));
315 DEBUG((DEBUG_INFO
, "FspSiliconInit status: 0x%x\n", Status
));
316 ASSERT_EFI_ERROR (Status
);
318 Status
= TestFspSiliconInitApiOutput ((VOID
*)NULL
);
319 if (RETURN_ERROR (Status
)) {
320 DEBUG ((DEBUG_ERROR
, "ERROR - TestFspSiliconInitApiOutput () fail, Status = %r\n", Status
));
324 // Now FspHobList complete, process it
326 GuidHob
= GetFirstGuidHob (&gFspHobGuid
);
327 ASSERT (GuidHob
!= NULL
);
328 FspHobListPtr
= *(VOID
**)GET_GUID_HOB_DATA (GuidHob
);
329 DEBUG ((DEBUG_INFO
, "FspHobListPtr - 0x%x\n", FspHobListPtr
));
330 PostFspsHobProcess (FspHobListPtr
);
333 // Install FspSiliconInitDonePpi so that any other driver can consume this info.
335 Status
= PeiServicesInstallPpi (&mPeiFspSiliconInitDonePpi
);
336 ASSERT_EFI_ERROR(Status
);
342 Do FSP initialization in API mode
344 @retval EFI_STATUS Always return EFI_SUCCESS
347 FspsWrapperInitApiMode (
352 EFI_BOOT_MODE BootMode
;
355 // Register MemoryDiscovered Nofity to run FspSiliconInit
357 Status
= PeiServicesNotifyPpi (&mPeiMemoryDiscoveredNotifyDesc
);
358 ASSERT_EFI_ERROR (Status
);
361 // Register EndOfPei Notify for S3 to run FSP NotifyPhase
363 PeiServicesGetBootMode (&BootMode
);
364 if (BootMode
== BOOT_ON_S3_RESUME
) {
365 Status
= PeiServicesNotifyPpi (&mS3EndOfPeiNotifyDesc
);
366 ASSERT_EFI_ERROR (Status
);
373 Do FSP initialization in Dispatch mode
375 @retval FSP initialization status.
378 FspsWrapperInitDispatchMode (
384 // FSP-S Wrapper running in Dispatch mode and reports FSP-S FV to PEI dispatcher.
386 PeiServicesInstallFvInfoPpi (
388 (VOID
*)(UINTN
) PcdGet32 (PcdFspsBaseAddress
),
389 (UINT32
)((EFI_FIRMWARE_VOLUME_HEADER
*) (UINTN
) PcdGet32 (PcdFspsBaseAddress
))->FvLength
,
394 // Register EndOfPei Nofity to run post FSP-S process.
396 Status
= PeiServicesNotifyPpi (&mFspsWrapperEndOfPeiNotifyDesc
);
397 ASSERT_EFI_ERROR (Status
);
402 This is the entrypoint of PEIM
404 @param[in] FileHandle Handle of the file being invoked.
405 @param[in] PeiServices Describes the list of possible PEI Services.
407 @retval EFI_SUCCESS if it completed successfully.
411 FspsWrapperPeimEntryPoint (
412 IN EFI_PEI_FILE_HANDLE FileHandle
,
413 IN CONST EFI_PEI_SERVICES
**PeiServices
416 DEBUG ((DEBUG_INFO
, "FspsWrapperPeimEntryPoint\n"));
418 if (PcdGet8 (PcdFspModeSelection
) == 1) {
419 FspsWrapperInitApiMode ();
421 FspsWrapperInitDispatchMode ();