]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFsp2WrapperPkg/FspsWrapperPeim/FspsWrapperPeim.c
Add IntelFsp2Pkg and IntelFsp2WrapperPkg.
[mirror_edk2.git] / IntelFsp2WrapperPkg / FspsWrapperPeim / FspsWrapperPeim.c
CommitLineData
cf1d4549
JY
1/** @file\r
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
5\r
6 Copyright (c) 2014 - 2016, 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
11\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
14\r
15**/\r
16\r
17#include <PiPei.h>\r
18\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
33\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/PlatformSecLib.h>\r
40#include <Library/FspWrapperApiTestLib.h>\r
41#include <FspEas.h>\r
42\r
43extern EFI_PEI_NOTIFY_DESCRIPTOR mS3EndOfPeiNotifyDesc;\r
44extern EFI_GUID gFspHobGuid;\r
45\r
46/**\r
47This function handles S3 resume task at the end of PEI\r
48\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
51caused this function to execute.\r
52@param[in] Ppi Pointer to the PPI data associated with this function.\r
53\r
54@retval EFI_STATUS Always return EFI_SUCCESS\r
55**/\r
56EFI_STATUS\r
57EFIAPI\r
58S3EndOfPeiNotify(\r
59 IN EFI_PEI_SERVICES **PeiServices,\r
60 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,\r
61 IN VOID *Ppi\r
62 );\r
63\r
64EFI_PEI_NOTIFY_DESCRIPTOR mS3EndOfPeiNotifyDesc = {\r
65 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
66 &gEfiEndOfPeiSignalPpiGuid,\r
67 S3EndOfPeiNotify\r
68};\r
69\r
70/**\r
71This function handles S3 resume task at the end of PEI\r
72\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
75caused this function to execute.\r
76@param[in] Ppi Pointer to the PPI data associated with this function.\r
77\r
78@retval EFI_STATUS Always return EFI_SUCCESS\r
79**/\r
80EFI_STATUS\r
81EFIAPI\r
82S3EndOfPeiNotify(\r
83 IN EFI_PEI_SERVICES **PeiServices,\r
84 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,\r
85 IN VOID *Ppi\r
86 )\r
87{\r
88 NOTIFY_PHASE_PARAMS NotifyPhaseParams;\r
89 EFI_STATUS Status;\r
90\r
91 DEBUG((DEBUG_INFO, "S3EndOfPeiNotify enter\n"));\r
92\r
93 NotifyPhaseParams.Phase = EnumInitPhaseAfterPciEnumeration;\r
94 Status = CallFspNotifyPhase (&NotifyPhaseParams);\r
95 DEBUG((DEBUG_INFO, "FSP S3NotifyPhase AfterPciEnumeration status: 0x%x\n", Status));\r
96\r
97 NotifyPhaseParams.Phase = EnumInitPhaseReadyToBoot;\r
98 Status = CallFspNotifyPhase (&NotifyPhaseParams);\r
99 DEBUG((DEBUG_INFO, "FSP S3NotifyPhase ReadyToBoot status: 0x%x\n", Status));\r
100\r
101 NotifyPhaseParams.Phase = EnumInitPhaseEndOfFirmware;\r
102 Status = CallFspNotifyPhase (&NotifyPhaseParams);\r
103 DEBUG((DEBUG_INFO, "FSP S3NotifyPhase EndOfFirmware status: 0x%x\n", Status));\r
104\r
105 return EFI_SUCCESS;\r
106}\r
107\r
108/**\r
109Return Hob list produced by FSP.\r
110\r
111@param[in] PeiServices The pointer to the PEI Services Table.\r
112@param[in] This The pointer to this instance of this PPI.\r
113@param[out] FspHobList The pointer to Hob list produced by FSP.\r
114\r
115@return EFI_SUCCESS FReturn Hob list produced by FSP successfully.\r
116**/\r
117EFI_STATUS\r
118EFIAPI\r
119FspSiliconInitDoneGetFspHobList (\r
120 IN CONST EFI_PEI_SERVICES **PeiServices,\r
121 IN FSP_SILICON_INIT_DONE_PPI *This,\r
122 OUT VOID **FspHobList\r
123 );\r
124\r
125FSP_SILICON_INIT_DONE_PPI mFspSiliconInitDonePpi = {\r
126 FspSiliconInitDoneGetFspHobList\r
127};\r
128\r
129EFI_PEI_PPI_DESCRIPTOR mPeiFspSiliconInitDonePpi = {\r
130 EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,\r
131 &gFspSiliconInitDonePpiGuid,\r
132 &mFspSiliconInitDonePpi\r
133};\r
134\r
135/**\r
136Return Hob list produced by FSP.\r
137\r
138@param[in] PeiServices The pointer to the PEI Services Table.\r
139@param[in] This The pointer to this instance of this PPI.\r
140@param[out] FspHobList The pointer to Hob list produced by FSP.\r
141\r
142@return EFI_SUCCESS FReturn Hob list produced by FSP successfully.\r
143**/\r
144EFI_STATUS\r
145EFIAPI\r
146FspSiliconInitDoneGetFspHobList (\r
147 IN CONST EFI_PEI_SERVICES **PeiServices,\r
148 IN FSP_SILICON_INIT_DONE_PPI *This,\r
149 OUT VOID **FspHobList\r
150 )\r
151{\r
152 EFI_HOB_GUID_TYPE *GuidHob;\r
153\r
154 GuidHob = GetFirstGuidHob (&gFspHobGuid);\r
155 if (GuidHob != NULL) {\r
156 *FspHobList = *(VOID **)GET_GUID_HOB_DATA(GuidHob);\r
157 return EFI_SUCCESS;\r
158 } else {\r
159 return EFI_NOT_FOUND;\r
160 }\r
161}\r
162\r
163/**\r
164 This function is called after PEI core discover memory and finish migration.\r
165\r
166 @param[in] PeiServices Pointer to PEI Services Table.\r
167 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that\r
168 caused this function to execute.\r
169 @param[in] Ppi Pointer to the PPI data associated with this function.\r
170\r
171 @retval EFI_STATUS Always return EFI_SUCCESS\r
172**/\r
173EFI_STATUS\r
174EFIAPI\r
175PeiMemoryDiscoveredNotify (\r
176 IN EFI_PEI_SERVICES **PeiServices,\r
177 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,\r
178 IN VOID *Ppi\r
179 );\r
180\r
181EFI_PEI_NOTIFY_DESCRIPTOR mPeiMemoryDiscoveredNotifyDesc = {\r
182 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
183 &gEfiPeiMemoryDiscoveredPpiGuid,\r
184 PeiMemoryDiscoveredNotify\r
185};\r
186\r
187/**\r
188This function is called after PEI core discover memory and finish migration.\r
189\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
192caused this function to execute.\r
193@param[in] Ppi Pointer to the PPI data associated with this function.\r
194\r
195@retval EFI_STATUS Always return EFI_SUCCESS\r
196**/\r
197EFI_STATUS\r
198EFIAPI\r
199PeiMemoryDiscoveredNotify (\r
200 IN EFI_PEI_SERVICES **PeiServices,\r
201 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,\r
202 IN VOID *Ppi\r
203 )\r
204{\r
205 FSP_INFO_HEADER *FspsHeaderPtr;\r
206 UINT64 TimeStampCounterStart;\r
207 EFI_STATUS Status;\r
208 VOID *FspHobListPtr;\r
209 EFI_HOB_GUID_TYPE *GuidHob;\r
210 FSPS_UPD_COMMON *FspsUpdDataPtr;\r
211 UINTN *SourceData;\r
212\r
213 \r
214 DEBUG ((DEBUG_INFO, "PeiMemoryDiscoveredNotify enter\n"));\r
215 \r
216 //\r
217 // Copy default FSP-S UPD data from Flash\r
218 //\r
219 FspsHeaderPtr = (FSP_INFO_HEADER *)FspFindFspHeader (PcdGet32 (PcdFspsBaseAddress));\r
220 FspsUpdDataPtr = (FSPS_UPD_COMMON *)AllocateZeroPool ((UINTN)FspsHeaderPtr->CfgRegionSize);\r
221 ASSERT (FspsUpdDataPtr != NULL);\r
222 SourceData = (UINTN *)((UINTN)FspsHeaderPtr->ImageBase + (UINTN)FspsHeaderPtr->CfgRegionOffset);\r
223 CopyMem (FspsUpdDataPtr, SourceData, (UINTN)FspsHeaderPtr->CfgRegionSize);\r
224\r
225 UpdateFspsUpdData ((VOID *)FspsUpdDataPtr);\r
226\r
227 TimeStampCounterStart = AsmReadTsc ();\r
228 PERF_START_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, 0x9000);\r
229 Status = CallFspSiliconInit ((VOID *)FspsUpdDataPtr);\r
230 PERF_END_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, 0x907F);\r
231 DEBUG ((DEBUG_INFO, "Total time spent executing FspSiliconInitApi: %d millisecond\n", DivU64x32 (GetTimeInNanoSecond (AsmReadTsc () - TimeStampCounterStart), 1000000)));\r
232 if (EFI_ERROR(Status)) {\r
233 DEBUG ((DEBUG_ERROR, "ERROR - Failed to execute FspSiliconInitApi(), Status = %r\n", Status));\r
234 }\r
235 DEBUG((DEBUG_INFO, "FspSiliconInit status: 0x%x\n", Status));\r
236 ASSERT_EFI_ERROR (Status);\r
237\r
238 Status = TestFspSiliconInitApiOutput ((VOID *)NULL);\r
239 if (RETURN_ERROR (Status)) {\r
240 DEBUG ((DEBUG_ERROR, "ERROR - TestFspSiliconInitApiOutput () fail, Status = %r\n", Status));\r
241 }\r
242\r
243 //\r
244 // Now FspHobList complete, process it\r
245 //\r
246 GuidHob = GetFirstGuidHob (&gFspHobGuid);\r
247 ASSERT (GuidHob != NULL);\r
248 FspHobListPtr = *(VOID **)GET_GUID_HOB_DATA (GuidHob);\r
249 DEBUG ((DEBUG_INFO, "FspHobListPtr - 0x%x\n", FspHobListPtr));\r
250 PostFspsHobProcess (FspHobListPtr);\r
251\r
252 //\r
253 // Install FspSiliconInitDonePpi so that any other driver can consume this info.\r
254 //\r
255 Status = PeiServicesInstallPpi (&mPeiFspSiliconInitDonePpi);\r
256 ASSERT_EFI_ERROR(Status);\r
257\r
258 return Status;\r
259}\r
260\r
261/**\r
262 Do FSP initialization.\r
263\r
264 @return FSP initialization status.\r
265**/\r
266EFI_STATUS\r
267FspsWrapperInit (\r
268 VOID\r
269 )\r
270{\r
271 EFI_STATUS Status;\r
272 EFI_BOOT_MODE BootMode;\r
273\r
274 //\r
275 // Register MemoryDiscovered Nofity to run FspSiliconInit\r
276 //\r
277 Status = PeiServicesNotifyPpi (&mPeiMemoryDiscoveredNotifyDesc);\r
278 ASSERT_EFI_ERROR (Status);\r
279 \r
280 //\r
281 // Register EndOfPei Notify for S3 to run FSP NotifyPhase\r
282 //\r
283 PeiServicesGetBootMode (&BootMode);\r
284 if (BootMode == BOOT_ON_S3_RESUME) {\r
285 Status = PeiServicesNotifyPpi (&mS3EndOfPeiNotifyDesc);\r
286 ASSERT_EFI_ERROR (Status);\r
287 }\r
288\r
289 return EFI_SUCCESS;\r
290}\r
291\r
292/**\r
293 This is the entrypoint of PEIM\r
294\r
295 @param[in] FileHandle Handle of the file being invoked.\r
296 @param[in] PeiServices Describes the list of possible PEI Services.\r
297\r
298 @retval EFI_SUCCESS if it completed successfully.\r
299**/\r
300EFI_STATUS\r
301EFIAPI\r
302FspsWrapperPeimEntryPoint (\r
303 IN EFI_PEI_FILE_HANDLE FileHandle,\r
304 IN CONST EFI_PEI_SERVICES **PeiServices\r
305 )\r
306{\r
307\r
308 DEBUG ((DEBUG_INFO, "FspsWrapperPeimEntryPoint\n"));\r
309\r
310 FspsWrapperInit ();\r
311\r
312 return EFI_SUCCESS;\r
313}\r