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
));
97 NotifyPhaseParams
.Phase
= EnumInitPhaseReadyToBoot
;
98 Status
= CallFspNotifyPhase (&NotifyPhaseParams
);
99 DEBUG((DEBUG_INFO
, "FSP S3NotifyPhase ReadyToBoot status: 0x%x\n", Status
));
101 NotifyPhaseParams
.Phase
= EnumInitPhaseEndOfFirmware
;
102 Status
= CallFspNotifyPhase (&NotifyPhaseParams
);
103 DEBUG((DEBUG_INFO
, "FSP S3NotifyPhase EndOfFirmware status: 0x%x\n", Status
));
109 Return Hob list produced by FSP.
111 @param[in] PeiServices The pointer to the PEI Services Table.
112 @param[in] This The pointer to this instance of this PPI.
113 @param[out] FspHobList The pointer to Hob list produced by FSP.
115 @return EFI_SUCCESS FReturn Hob list produced by FSP successfully.
119 FspSiliconInitDoneGetFspHobList (
120 IN CONST EFI_PEI_SERVICES
**PeiServices
,
121 IN FSP_SILICON_INIT_DONE_PPI
*This
,
122 OUT VOID
**FspHobList
125 FSP_SILICON_INIT_DONE_PPI mFspSiliconInitDonePpi
= {
126 FspSiliconInitDoneGetFspHobList
129 EFI_PEI_PPI_DESCRIPTOR mPeiFspSiliconInitDonePpi
= {
130 EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
,
131 &gFspSiliconInitDonePpiGuid
,
132 &mFspSiliconInitDonePpi
136 Return Hob list produced by FSP.
138 @param[in] PeiServices The pointer to the PEI Services Table.
139 @param[in] This The pointer to this instance of this PPI.
140 @param[out] FspHobList The pointer to Hob list produced by FSP.
142 @return EFI_SUCCESS FReturn Hob list produced by FSP successfully.
146 FspSiliconInitDoneGetFspHobList (
147 IN CONST EFI_PEI_SERVICES
**PeiServices
,
148 IN FSP_SILICON_INIT_DONE_PPI
*This
,
149 OUT VOID
**FspHobList
152 EFI_HOB_GUID_TYPE
*GuidHob
;
154 GuidHob
= GetFirstGuidHob (&gFspHobGuid
);
155 if (GuidHob
!= NULL
) {
156 *FspHobList
= *(VOID
**)GET_GUID_HOB_DATA(GuidHob
);
159 return EFI_NOT_FOUND
;
164 This function is called after PEI core discover memory and finish migration.
166 @param[in] PeiServices Pointer to PEI Services Table.
167 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
168 caused this function to execute.
169 @param[in] Ppi Pointer to the PPI data associated with this function.
171 @retval EFI_STATUS Always return EFI_SUCCESS
175 PeiMemoryDiscoveredNotify (
176 IN EFI_PEI_SERVICES
**PeiServices
,
177 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
181 EFI_PEI_NOTIFY_DESCRIPTOR mPeiMemoryDiscoveredNotifyDesc
= {
182 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
183 &gEfiPeiMemoryDiscoveredPpiGuid
,
184 PeiMemoryDiscoveredNotify
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 FSP_INFO_HEADER
*FspsHeaderPtr
;
206 UINT64 TimeStampCounterStart
;
209 EFI_HOB_GUID_TYPE
*GuidHob
;
210 FSPS_UPD_COMMON
*FspsUpdDataPtr
;
214 DEBUG ((DEBUG_INFO
, "PeiMemoryDiscoveredNotify enter\n"));
217 // Copy default FSP-S UPD data from Flash
219 FspsHeaderPtr
= (FSP_INFO_HEADER
*)FspFindFspHeader (PcdGet32 (PcdFspsBaseAddress
));
220 FspsUpdDataPtr
= (FSPS_UPD_COMMON
*)AllocateZeroPool ((UINTN
)FspsHeaderPtr
->CfgRegionSize
);
221 ASSERT (FspsUpdDataPtr
!= NULL
);
222 SourceData
= (UINTN
*)((UINTN
)FspsHeaderPtr
->ImageBase
+ (UINTN
)FspsHeaderPtr
->CfgRegionOffset
);
223 CopyMem (FspsUpdDataPtr
, SourceData
, (UINTN
)FspsHeaderPtr
->CfgRegionSize
);
225 UpdateFspsUpdData ((VOID
*)FspsUpdDataPtr
);
227 TimeStampCounterStart
= AsmReadTsc ();
228 PERF_START_EX(&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, 0x9000);
229 Status
= CallFspSiliconInit ((VOID
*)FspsUpdDataPtr
);
230 PERF_END_EX(&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, 0x907F);
231 DEBUG ((DEBUG_INFO
, "Total time spent executing FspSiliconInitApi: %d millisecond\n", DivU64x32 (GetTimeInNanoSecond (AsmReadTsc () - TimeStampCounterStart
), 1000000)));
232 if (EFI_ERROR(Status
)) {
233 DEBUG ((DEBUG_ERROR
, "ERROR - Failed to execute FspSiliconInitApi(), Status = %r\n", Status
));
235 DEBUG((DEBUG_INFO
, "FspSiliconInit status: 0x%x\n", Status
));
236 ASSERT_EFI_ERROR (Status
);
238 Status
= TestFspSiliconInitApiOutput ((VOID
*)NULL
);
239 if (RETURN_ERROR (Status
)) {
240 DEBUG ((DEBUG_ERROR
, "ERROR - TestFspSiliconInitApiOutput () fail, Status = %r\n", Status
));
244 // Now FspHobList complete, process it
246 GuidHob
= GetFirstGuidHob (&gFspHobGuid
);
247 ASSERT (GuidHob
!= NULL
);
248 FspHobListPtr
= *(VOID
**)GET_GUID_HOB_DATA (GuidHob
);
249 DEBUG ((DEBUG_INFO
, "FspHobListPtr - 0x%x\n", FspHobListPtr
));
250 PostFspsHobProcess (FspHobListPtr
);
253 // Install FspSiliconInitDonePpi so that any other driver can consume this info.
255 Status
= PeiServicesInstallPpi (&mPeiFspSiliconInitDonePpi
);
256 ASSERT_EFI_ERROR(Status
);
262 Do FSP initialization.
264 @return FSP initialization status.
272 EFI_BOOT_MODE BootMode
;
275 // Register MemoryDiscovered Nofity to run FspSiliconInit
277 Status
= PeiServicesNotifyPpi (&mPeiMemoryDiscoveredNotifyDesc
);
278 ASSERT_EFI_ERROR (Status
);
281 // Register EndOfPei Notify for S3 to run FSP NotifyPhase
283 PeiServicesGetBootMode (&BootMode
);
284 if (BootMode
== BOOT_ON_S3_RESUME
) {
285 Status
= PeiServicesNotifyPpi (&mS3EndOfPeiNotifyDesc
);
286 ASSERT_EFI_ERROR (Status
);
293 This is the entrypoint of PEIM
295 @param[in] FileHandle Handle of the file being invoked.
296 @param[in] PeiServices Describes the list of possible PEI Services.
298 @retval EFI_SUCCESS if it completed successfully.
302 FspsWrapperPeimEntryPoint (
303 IN EFI_PEI_FILE_HANDLE FileHandle
,
304 IN CONST EFI_PEI_SERVICES
**PeiServices
308 DEBUG ((DEBUG_INFO
, "FspsWrapperPeimEntryPoint\n"));