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