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 - 2016, Intel Corporation. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php.
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #include <Library/PeimEntryPoint.h>
20 #include <Library/PeiServicesLib.h>
21 #include <Library/PeiServicesTablePointerLib.h>
22 #include <Library/BaseLib.h>
23 #include <Library/DebugLib.h>
24 #include <Library/BaseMemoryLib.h>
25 #include <Library/HobLib.h>
26 #include <Library/PcdLib.h>
27 #include <Library/MemoryAllocationLib.h>
28 #include <Library/FspWrapperPlatformLib.h>
29 #include <Library/FspWrapperHobProcessLib.h>
30 #include <Library/TimerLib.h>
31 #include <Library/PerformanceLib.h>
32 #include <Library/FspWrapperApiLib.h>
34 #include <Ppi/FspSiliconInitDone.h>
35 #include <Ppi/EndOfPeiPhase.h>
36 #include <Ppi/MemoryDiscovered.h>
37 #include <Ppi/TemporaryRamDone.h>
38 #include <Ppi/SecPlatformInformation.h>
39 #include <Library/PlatformSecLib.h>
40 #include <Library/FspWrapperApiTestLib.h>
43 extern EFI_PEI_NOTIFY_DESCRIPTOR mS3EndOfPeiNotifyDesc
;
44 extern EFI_GUID gFspHobGuid
;
47 This function handles S3 resume task at the end of PEI
49 @param[in] PeiServices Pointer to PEI Services Table.
50 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
51 caused this function to execute.
52 @param[in] Ppi Pointer to the PPI data associated with this function.
54 @retval EFI_STATUS Always return EFI_SUCCESS
59 IN EFI_PEI_SERVICES
**PeiServices
,
60 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
64 EFI_PEI_NOTIFY_DESCRIPTOR mS3EndOfPeiNotifyDesc
= {
65 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
66 &gEfiEndOfPeiSignalPpiGuid
,
71 This function handles S3 resume task at the end of PEI
73 @param[in] PeiServices Pointer to PEI Services Table.
74 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
75 caused this function to execute.
76 @param[in] Ppi Pointer to the PPI data associated with this function.
78 @retval EFI_STATUS Always return EFI_SUCCESS
83 IN EFI_PEI_SERVICES
**PeiServices
,
84 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
88 NOTIFY_PHASE_PARAMS NotifyPhaseParams
;
91 DEBUG((DEBUG_INFO
, "S3EndOfPeiNotify enter\n"));
93 NotifyPhaseParams
.Phase
= EnumInitPhaseAfterPciEnumeration
;
94 Status
= CallFspNotifyPhase (&NotifyPhaseParams
);
95 DEBUG((DEBUG_INFO
, "FSP S3NotifyPhase AfterPciEnumeration status: 0x%x\n", Status
));
98 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
100 if ((Status
>= FSP_STATUS_RESET_REQUIRED_COLD
) && (Status
<= FSP_STATUS_RESET_REQUIRED_8
)) {
101 DEBUG((DEBUG_INFO
, "FSP S3NotifyPhase AfterPciEnumeration requested reset 0x%x\n", Status
));
102 CallFspWrapperResetSystem ((UINT32
)Status
);
105 NotifyPhaseParams
.Phase
= EnumInitPhaseReadyToBoot
;
106 Status
= CallFspNotifyPhase (&NotifyPhaseParams
);
107 DEBUG((DEBUG_INFO
, "FSP S3NotifyPhase ReadyToBoot status: 0x%x\n", Status
));
110 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
112 if ((Status
>= FSP_STATUS_RESET_REQUIRED_COLD
) && (Status
<= FSP_STATUS_RESET_REQUIRED_8
)) {
113 DEBUG((DEBUG_INFO
, "FSP S3NotifyPhase ReadyToBoot requested reset 0x%x\n", Status
));
114 CallFspWrapperResetSystem ((UINT32
)Status
);
117 NotifyPhaseParams
.Phase
= EnumInitPhaseEndOfFirmware
;
118 Status
= CallFspNotifyPhase (&NotifyPhaseParams
);
119 DEBUG((DEBUG_INFO
, "FSP S3NotifyPhase EndOfFirmware status: 0x%x\n", Status
));
122 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
124 if ((Status
>= FSP_STATUS_RESET_REQUIRED_COLD
) && (Status
<= FSP_STATUS_RESET_REQUIRED_8
)) {
125 DEBUG((DEBUG_INFO
, "FSP S3NotifyPhase EndOfFirmware requested reset 0x%x\n", Status
));
126 CallFspWrapperResetSystem ((UINT32
)Status
);
133 Return Hob list produced by FSP.
135 @param[in] PeiServices The pointer to the PEI Services Table.
136 @param[in] This The pointer to this instance of this PPI.
137 @param[out] FspHobList The pointer to Hob list produced by FSP.
139 @return EFI_SUCCESS FReturn Hob list produced by FSP successfully.
143 FspSiliconInitDoneGetFspHobList (
144 IN CONST EFI_PEI_SERVICES
**PeiServices
,
145 IN FSP_SILICON_INIT_DONE_PPI
*This
,
146 OUT VOID
**FspHobList
149 FSP_SILICON_INIT_DONE_PPI mFspSiliconInitDonePpi
= {
150 FspSiliconInitDoneGetFspHobList
153 EFI_PEI_PPI_DESCRIPTOR mPeiFspSiliconInitDonePpi
= {
154 EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
,
155 &gFspSiliconInitDonePpiGuid
,
156 &mFspSiliconInitDonePpi
160 Return Hob list produced by FSP.
162 @param[in] PeiServices The pointer to the PEI Services Table.
163 @param[in] This The pointer to this instance of this PPI.
164 @param[out] FspHobList The pointer to Hob list produced by FSP.
166 @return EFI_SUCCESS FReturn Hob list produced by FSP successfully.
170 FspSiliconInitDoneGetFspHobList (
171 IN CONST EFI_PEI_SERVICES
**PeiServices
,
172 IN FSP_SILICON_INIT_DONE_PPI
*This
,
173 OUT VOID
**FspHobList
176 EFI_HOB_GUID_TYPE
*GuidHob
;
178 GuidHob
= GetFirstGuidHob (&gFspHobGuid
);
179 if (GuidHob
!= NULL
) {
180 *FspHobList
= *(VOID
**)GET_GUID_HOB_DATA(GuidHob
);
183 return EFI_NOT_FOUND
;
188 This function is called after PEI core discover memory and finish migration.
190 @param[in] PeiServices Pointer to PEI Services Table.
191 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
192 caused this function to execute.
193 @param[in] Ppi Pointer to the PPI data associated with this function.
195 @retval EFI_STATUS Always return EFI_SUCCESS
199 PeiMemoryDiscoveredNotify (
200 IN EFI_PEI_SERVICES
**PeiServices
,
201 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
205 EFI_PEI_NOTIFY_DESCRIPTOR mPeiMemoryDiscoveredNotifyDesc
= {
206 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
207 &gEfiPeiMemoryDiscoveredPpiGuid
,
208 PeiMemoryDiscoveredNotify
212 This function is called after PEI core discover memory and finish migration.
214 @param[in] PeiServices Pointer to PEI Services Table.
215 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
216 caused this function to execute.
217 @param[in] Ppi Pointer to the PPI data associated with this function.
219 @retval EFI_STATUS Always return EFI_SUCCESS
223 PeiMemoryDiscoveredNotify (
224 IN EFI_PEI_SERVICES
**PeiServices
,
225 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
229 FSP_INFO_HEADER
*FspsHeaderPtr
;
230 UINT64 TimeStampCounterStart
;
233 EFI_HOB_GUID_TYPE
*GuidHob
;
234 FSPS_UPD_COMMON
*FspsUpdDataPtr
;
238 DEBUG ((DEBUG_INFO
, "PeiMemoryDiscoveredNotify enter\n"));
241 // Copy default FSP-S UPD data from Flash
243 FspsHeaderPtr
= (FSP_INFO_HEADER
*)FspFindFspHeader (PcdGet32 (PcdFspsBaseAddress
));
244 DEBUG ((DEBUG_INFO
, "FspsHeaderPtr - 0x%x\n", FspsHeaderPtr
));
245 if (FspsHeaderPtr
== NULL
) {
246 return EFI_DEVICE_ERROR
;
249 FspsUpdDataPtr
= (FSPS_UPD_COMMON
*)AllocateZeroPool ((UINTN
)FspsHeaderPtr
->CfgRegionSize
);
250 ASSERT (FspsUpdDataPtr
!= NULL
);
251 SourceData
= (UINTN
*)((UINTN
)FspsHeaderPtr
->ImageBase
+ (UINTN
)FspsHeaderPtr
->CfgRegionOffset
);
252 CopyMem (FspsUpdDataPtr
, SourceData
, (UINTN
)FspsHeaderPtr
->CfgRegionSize
);
254 UpdateFspsUpdData ((VOID
*)FspsUpdDataPtr
);
256 TimeStampCounterStart
= AsmReadTsc ();
257 PERF_START_EX(&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, 0x9000);
258 Status
= CallFspSiliconInit ((VOID
*)FspsUpdDataPtr
);
259 PERF_END_EX(&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, 0x907F);
260 DEBUG ((DEBUG_INFO
, "Total time spent executing FspSiliconInitApi: %d millisecond\n", DivU64x32 (GetTimeInNanoSecond (AsmReadTsc () - TimeStampCounterStart
), 1000000)));
263 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
265 if ((Status
>= FSP_STATUS_RESET_REQUIRED_COLD
) && (Status
<= FSP_STATUS_RESET_REQUIRED_8
)) {
266 DEBUG((DEBUG_INFO
, "FspSiliconInitApi requested reset 0x%x\n", Status
));
267 CallFspWrapperResetSystem ((UINT32
)Status
);
270 if (EFI_ERROR(Status
)) {
271 DEBUG ((DEBUG_ERROR
, "ERROR - Failed to execute FspSiliconInitApi(), Status = %r\n", Status
));
273 DEBUG((DEBUG_INFO
, "FspSiliconInit status: 0x%x\n", Status
));
274 ASSERT_EFI_ERROR (Status
);
276 Status
= TestFspSiliconInitApiOutput ((VOID
*)NULL
);
277 if (RETURN_ERROR (Status
)) {
278 DEBUG ((DEBUG_ERROR
, "ERROR - TestFspSiliconInitApiOutput () fail, Status = %r\n", Status
));
282 // Now FspHobList complete, process it
284 GuidHob
= GetFirstGuidHob (&gFspHobGuid
);
285 ASSERT (GuidHob
!= NULL
);
286 FspHobListPtr
= *(VOID
**)GET_GUID_HOB_DATA (GuidHob
);
287 DEBUG ((DEBUG_INFO
, "FspHobListPtr - 0x%x\n", FspHobListPtr
));
288 PostFspsHobProcess (FspHobListPtr
);
291 // Install FspSiliconInitDonePpi so that any other driver can consume this info.
293 Status
= PeiServicesInstallPpi (&mPeiFspSiliconInitDonePpi
);
294 ASSERT_EFI_ERROR(Status
);
300 Do FSP initialization.
302 @return FSP initialization status.
310 EFI_BOOT_MODE BootMode
;
313 // Register MemoryDiscovered Nofity to run FspSiliconInit
315 Status
= PeiServicesNotifyPpi (&mPeiMemoryDiscoveredNotifyDesc
);
316 ASSERT_EFI_ERROR (Status
);
319 // Register EndOfPei Notify for S3 to run FSP NotifyPhase
321 PeiServicesGetBootMode (&BootMode
);
322 if (BootMode
== BOOT_ON_S3_RESUME
) {
323 Status
= PeiServicesNotifyPpi (&mS3EndOfPeiNotifyDesc
);
324 ASSERT_EFI_ERROR (Status
);
331 This is the entrypoint of PEIM
333 @param[in] FileHandle Handle of the file being invoked.
334 @param[in] PeiServices Describes the list of possible PEI Services.
336 @retval EFI_SUCCESS if it completed successfully.
340 FspsWrapperPeimEntryPoint (
341 IN EFI_PEI_FILE_HANDLE FileHandle
,
342 IN CONST EFI_PEI_SERVICES
**PeiServices
346 DEBUG ((DEBUG_INFO
, "FspsWrapperPeimEntryPoint\n"));