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 - 2018, 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 FReturn 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 FReturn 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 called after PEI core discover memory and finish migration.
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 Always return EFI_SUCCESS
193 PeiMemoryDiscoveredNotify (
194 IN EFI_PEI_SERVICES
**PeiServices
,
195 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
199 EFI_PEI_NOTIFY_DESCRIPTOR mPeiMemoryDiscoveredNotifyDesc
= {
200 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
201 &gEfiPeiMemoryDiscoveredPpiGuid
,
202 PeiMemoryDiscoveredNotify
206 This function is called after PEI core discover memory and finish migration.
208 @param[in] PeiServices Pointer to PEI Services Table.
209 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
210 caused this function to execute.
211 @param[in] Ppi Pointer to the PPI data associated with this function.
213 @retval EFI_STATUS Always return EFI_SUCCESS
217 PeiMemoryDiscoveredNotify (
218 IN EFI_PEI_SERVICES
**PeiServices
,
219 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
223 FSP_INFO_HEADER
*FspsHeaderPtr
;
224 UINT64 TimeStampCounterStart
;
227 EFI_HOB_GUID_TYPE
*GuidHob
;
228 FSPS_UPD_COMMON
*FspsUpdDataPtr
;
231 DEBUG ((DEBUG_INFO
, "PeiMemoryDiscoveredNotify enter\n"));
232 FspsUpdDataPtr
= NULL
;
234 FspsHeaderPtr
= (FSP_INFO_HEADER
*)FspFindFspHeader (PcdGet32 (PcdFspsBaseAddress
));
235 DEBUG ((DEBUG_INFO
, "FspsHeaderPtr - 0x%x\n", FspsHeaderPtr
));
236 if (FspsHeaderPtr
== NULL
) {
237 return EFI_DEVICE_ERROR
;
240 if (PcdGet32 (PcdFspsUpdDataAddress
) == 0 && (FspsHeaderPtr
->CfgRegionSize
!= 0) && (FspsHeaderPtr
->CfgRegionOffset
!= 0)) {
242 // Copy default FSP-S UPD data from Flash
244 FspsUpdDataPtr
= (FSPS_UPD_COMMON
*)AllocateZeroPool ((UINTN
)FspsHeaderPtr
->CfgRegionSize
);
245 ASSERT (FspsUpdDataPtr
!= NULL
);
246 SourceData
= (UINTN
*)((UINTN
)FspsHeaderPtr
->ImageBase
+ (UINTN
)FspsHeaderPtr
->CfgRegionOffset
);
247 CopyMem (FspsUpdDataPtr
, SourceData
, (UINTN
)FspsHeaderPtr
->CfgRegionSize
);
249 FspsUpdDataPtr
= (FSPS_UPD_COMMON
*)PcdGet32 (PcdFspsUpdDataAddress
);
250 ASSERT (FspsUpdDataPtr
!= NULL
);
253 UpdateFspsUpdData ((VOID
*)FspsUpdDataPtr
);
255 TimeStampCounterStart
= AsmReadTsc ();
256 PERF_START_EX(&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, FSP_STATUS_CODE_SILICON_INIT
| FSP_STATUS_CODE_COMMON_CODE
| FSP_STATUS_CODE_API_ENTRY
);
257 Status
= CallFspSiliconInit ((VOID
*)FspsUpdDataPtr
);
258 PERF_END_EX(&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, FSP_STATUS_CODE_SILICON_INIT
| FSP_STATUS_CODE_COMMON_CODE
| FSP_STATUS_CODE_API_EXIT
);
259 DEBUG ((DEBUG_INFO
, "Total time spent executing FspSiliconInitApi: %d millisecond\n", DivU64x32 (GetTimeInNanoSecond (AsmReadTsc () - TimeStampCounterStart
), 1000000)));
262 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
264 if ((Status
>= FSP_STATUS_RESET_REQUIRED_COLD
) && (Status
<= FSP_STATUS_RESET_REQUIRED_8
)) {
265 DEBUG((DEBUG_INFO
, "FspSiliconInitApi requested reset 0x%x\n", Status
));
266 CallFspWrapperResetSystem ((UINT32
)Status
);
269 if (EFI_ERROR(Status
)) {
270 DEBUG ((DEBUG_ERROR
, "ERROR - Failed to execute FspSiliconInitApi(), Status = %r\n", Status
));
272 DEBUG((DEBUG_INFO
, "FspSiliconInit status: 0x%x\n", Status
));
273 ASSERT_EFI_ERROR (Status
);
275 Status
= TestFspSiliconInitApiOutput ((VOID
*)NULL
);
276 if (RETURN_ERROR (Status
)) {
277 DEBUG ((DEBUG_ERROR
, "ERROR - TestFspSiliconInitApiOutput () fail, Status = %r\n", Status
));
281 // Now FspHobList complete, process it
283 GuidHob
= GetFirstGuidHob (&gFspHobGuid
);
284 ASSERT (GuidHob
!= NULL
);
285 FspHobListPtr
= *(VOID
**)GET_GUID_HOB_DATA (GuidHob
);
286 DEBUG ((DEBUG_INFO
, "FspHobListPtr - 0x%x\n", FspHobListPtr
));
287 PostFspsHobProcess (FspHobListPtr
);
290 // Install FspSiliconInitDonePpi so that any other driver can consume this info.
292 Status
= PeiServicesInstallPpi (&mPeiFspSiliconInitDonePpi
);
293 ASSERT_EFI_ERROR(Status
);
299 Do FSP initialization.
301 @return FSP initialization status.
309 EFI_BOOT_MODE BootMode
;
312 // Register MemoryDiscovered Nofity to run FspSiliconInit
314 Status
= PeiServicesNotifyPpi (&mPeiMemoryDiscoveredNotifyDesc
);
315 ASSERT_EFI_ERROR (Status
);
318 // Register EndOfPei Notify for S3 to run FSP NotifyPhase
320 PeiServicesGetBootMode (&BootMode
);
321 if (BootMode
== BOOT_ON_S3_RESUME
) {
322 Status
= PeiServicesNotifyPpi (&mS3EndOfPeiNotifyDesc
);
323 ASSERT_EFI_ERROR (Status
);
330 This is the entrypoint of PEIM
332 @param[in] FileHandle Handle of the file being invoked.
333 @param[in] PeiServices Describes the list of possible PEI Services.
335 @retval EFI_SUCCESS if it completed successfully.
339 FspsWrapperPeimEntryPoint (
340 IN EFI_PEI_FILE_HANDLE FileHandle
,
341 IN CONST EFI_PEI_SERVICES
**PeiServices
344 DEBUG ((DEBUG_INFO
, "FspsWrapperPeimEntryPoint\n"));
346 if (PcdGet8 (PcdFspModeSelection
) == 1) {
349 PeiServicesInstallFvInfoPpi (
351 (VOID
*)(UINTN
) PcdGet32 (PcdFspsBaseAddress
),
352 (UINT32
)((EFI_FIRMWARE_VOLUME_HEADER
*) (UINTN
) PcdGet32 (PcdFspsBaseAddress
))->FvLength
,