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/FspWrapperApiTestLib.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 ((UINT32
)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 ((UINT32
)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 ((UINT32
)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 FReturn 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 FReturn 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 This function is called after PEI core discover memory and finish migration.
189 @param[in] PeiServices Pointer to PEI Services Table.
190 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
191 caused this function to execute.
192 @param[in] Ppi Pointer to the PPI data associated with this function.
194 @retval EFI_STATUS Always return EFI_SUCCESS
198 PeiMemoryDiscoveredNotify (
199 IN EFI_PEI_SERVICES
**PeiServices
,
200 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
204 EFI_PEI_NOTIFY_DESCRIPTOR mPeiMemoryDiscoveredNotifyDesc
= {
205 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
206 &gEfiPeiMemoryDiscoveredPpiGuid
,
207 PeiMemoryDiscoveredNotify
211 This function is called after PEI core discover memory and finish migration.
213 @param[in] PeiServices Pointer to PEI Services Table.
214 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
215 caused this function to execute.
216 @param[in] Ppi Pointer to the PPI data associated with this function.
218 @retval EFI_STATUS Always return EFI_SUCCESS
222 PeiMemoryDiscoveredNotify (
223 IN EFI_PEI_SERVICES
**PeiServices
,
224 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
228 FSP_INFO_HEADER
*FspsHeaderPtr
;
229 UINT64 TimeStampCounterStart
;
232 EFI_HOB_GUID_TYPE
*GuidHob
;
233 FSPS_UPD_COMMON
*FspsUpdDataPtr
;
237 DEBUG ((DEBUG_INFO
, "PeiMemoryDiscoveredNotify enter\n"));
240 // Copy default FSP-S UPD data from Flash
242 FspsHeaderPtr
= (FSP_INFO_HEADER
*)FspFindFspHeader (PcdGet32 (PcdFspsBaseAddress
));
243 DEBUG ((DEBUG_INFO
, "FspsHeaderPtr - 0x%x\n", FspsHeaderPtr
));
244 if (FspsHeaderPtr
== NULL
) {
245 return EFI_DEVICE_ERROR
;
248 FspsUpdDataPtr
= (FSPS_UPD_COMMON
*)AllocateZeroPool ((UINTN
)FspsHeaderPtr
->CfgRegionSize
);
249 ASSERT (FspsUpdDataPtr
!= NULL
);
250 SourceData
= (UINTN
*)((UINTN
)FspsHeaderPtr
->ImageBase
+ (UINTN
)FspsHeaderPtr
->CfgRegionOffset
);
251 CopyMem (FspsUpdDataPtr
, SourceData
, (UINTN
)FspsHeaderPtr
->CfgRegionSize
);
253 UpdateFspsUpdData ((VOID
*)FspsUpdDataPtr
);
255 TimeStampCounterStart
= AsmReadTsc ();
256 PERF_START_EX(&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, 0x9000);
257 Status
= CallFspSiliconInit ((VOID
*)FspsUpdDataPtr
);
258 PERF_END_EX(&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, 0x907F);
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
345 DEBUG ((DEBUG_INFO
, "FspsWrapperPeimEntryPoint\n"));