]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFsp2WrapperPkg/FspsWrapperPeim/FspsWrapperPeim.c
IntelFsp2WrapperPkg: Fix various typos
[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
68d47eea 6 Copyright (c) 2014 - 2019, Intel Corporation. All rights reserved.<BR>\r
512e23a3 7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
cf1d4549
JY
8\r
9**/\r
10\r
11#include <PiPei.h>\r
12\r
13#include <Library/PeimEntryPoint.h>\r
14#include <Library/PeiServicesLib.h>\r
15#include <Library/PeiServicesTablePointerLib.h>\r
16#include <Library/BaseLib.h>\r
17#include <Library/DebugLib.h>\r
18#include <Library/BaseMemoryLib.h>\r
19#include <Library/HobLib.h>\r
20#include <Library/PcdLib.h>\r
21#include <Library/MemoryAllocationLib.h>\r
22#include <Library/FspWrapperPlatformLib.h>\r
23#include <Library/FspWrapperHobProcessLib.h>\r
24#include <Library/TimerLib.h>\r
25#include <Library/PerformanceLib.h>\r
26#include <Library/FspWrapperApiLib.h>\r
27\r
28#include <Ppi/FspSiliconInitDone.h>\r
29#include <Ppi/EndOfPeiPhase.h>\r
30#include <Ppi/MemoryDiscovered.h>\r
31#include <Ppi/TemporaryRamDone.h>\r
32#include <Ppi/SecPlatformInformation.h>\r
cf1d4549
JY
33#include <Library/FspWrapperApiTestLib.h>\r
34#include <FspEas.h>\r
19d29d35 35#include <FspStatusCode.h>\r
cf1d4549
JY
36\r
37extern EFI_PEI_NOTIFY_DESCRIPTOR mS3EndOfPeiNotifyDesc;\r
38extern EFI_GUID gFspHobGuid;\r
39\r
40/**\r
00e3e480 41 This function handles S3 resume task at the end of PEI.\r
cf1d4549 42\r
e69dcef5
CC
43 @param[in] PeiServices Pointer to PEI Services Table.\r
44 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that\r
45 caused this function to execute.\r
46 @param[in] Ppi Pointer to the PPI data associated with this function.\r
cf1d4549 47\r
e69dcef5 48 @retval EFI_STATUS Always return EFI_SUCCESS\r
cf1d4549
JY
49**/\r
50EFI_STATUS\r
51EFIAPI\r
52S3EndOfPeiNotify(\r
53 IN EFI_PEI_SERVICES **PeiServices,\r
54 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,\r
55 IN VOID *Ppi\r
56 );\r
57\r
58EFI_PEI_NOTIFY_DESCRIPTOR mS3EndOfPeiNotifyDesc = {\r
59 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
60 &gEfiEndOfPeiSignalPpiGuid,\r
61 S3EndOfPeiNotify\r
62};\r
63\r
64/**\r
00e3e480 65 This function handles S3 resume task at the end of PEI.\r
cf1d4549 66\r
e69dcef5
CC
67 @param[in] PeiServices Pointer to PEI Services Table.\r
68 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that\r
69 caused this function to execute.\r
70 @param[in] Ppi Pointer to the PPI data associated with this function.\r
cf1d4549 71\r
e69dcef5 72 @retval EFI_STATUS Always return EFI_SUCCESS\r
cf1d4549
JY
73**/\r
74EFI_STATUS\r
75EFIAPI\r
76S3EndOfPeiNotify(\r
77 IN EFI_PEI_SERVICES **PeiServices,\r
78 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,\r
79 IN VOID *Ppi\r
80 )\r
81{\r
82 NOTIFY_PHASE_PARAMS NotifyPhaseParams;\r
83 EFI_STATUS Status;\r
84\r
85 DEBUG((DEBUG_INFO, "S3EndOfPeiNotify enter\n"));\r
86\r
87 NotifyPhaseParams.Phase = EnumInitPhaseAfterPciEnumeration;\r
88 Status = CallFspNotifyPhase (&NotifyPhaseParams);\r
89 DEBUG((DEBUG_INFO, "FSP S3NotifyPhase AfterPciEnumeration status: 0x%x\n", Status));\r
90\r
f862a3b6
JY
91 //\r
92 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status\r
93 //\r
94 if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {\r
95 DEBUG((DEBUG_INFO, "FSP S3NotifyPhase AfterPciEnumeration requested reset 0x%x\n", Status));\r
96 CallFspWrapperResetSystem ((UINT32)Status);\r
97 }\r
98\r
cf1d4549
JY
99 NotifyPhaseParams.Phase = EnumInitPhaseReadyToBoot;\r
100 Status = CallFspNotifyPhase (&NotifyPhaseParams);\r
101 DEBUG((DEBUG_INFO, "FSP S3NotifyPhase ReadyToBoot status: 0x%x\n", Status));\r
102\r
f862a3b6
JY
103 //\r
104 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status\r
105 //\r
106 if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {\r
107 DEBUG((DEBUG_INFO, "FSP S3NotifyPhase ReadyToBoot requested reset 0x%x\n", Status));\r
108 CallFspWrapperResetSystem ((UINT32)Status);\r
109 }\r
110\r
cf1d4549
JY
111 NotifyPhaseParams.Phase = EnumInitPhaseEndOfFirmware;\r
112 Status = CallFspNotifyPhase (&NotifyPhaseParams);\r
113 DEBUG((DEBUG_INFO, "FSP S3NotifyPhase EndOfFirmware status: 0x%x\n", Status));\r
114\r
f862a3b6
JY
115 //\r
116 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status\r
117 //\r
118 if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {\r
119 DEBUG((DEBUG_INFO, "FSP S3NotifyPhase EndOfFirmware requested reset 0x%x\n", Status));\r
120 CallFspWrapperResetSystem ((UINT32)Status);\r
121 }\r
122\r
cf1d4549
JY
123 return EFI_SUCCESS;\r
124}\r
125\r
126/**\r
e69dcef5 127 Return Hob list produced by FSP.\r
cf1d4549 128\r
e69dcef5
CC
129 @param[in] PeiServices The pointer to the PEI Services Table.\r
130 @param[in] This The pointer to this instance of this PPI.\r
131 @param[out] FspHobList The pointer to Hob list produced by FSP.\r
cf1d4549 132\r
68d47eea 133 @return EFI_SUCCESS Return Hob list produced by FSP successfully.\r
cf1d4549
JY
134**/\r
135EFI_STATUS\r
136EFIAPI\r
137FspSiliconInitDoneGetFspHobList (\r
138 IN CONST EFI_PEI_SERVICES **PeiServices,\r
139 IN FSP_SILICON_INIT_DONE_PPI *This,\r
140 OUT VOID **FspHobList\r
141 );\r
142\r
143FSP_SILICON_INIT_DONE_PPI mFspSiliconInitDonePpi = {\r
144 FspSiliconInitDoneGetFspHobList\r
145};\r
146\r
147EFI_PEI_PPI_DESCRIPTOR mPeiFspSiliconInitDonePpi = {\r
148 EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,\r
149 &gFspSiliconInitDonePpiGuid,\r
150 &mFspSiliconInitDonePpi\r
151};\r
152\r
153/**\r
e69dcef5 154 Return Hob list produced by FSP.\r
cf1d4549 155\r
e69dcef5
CC
156 @param[in] PeiServices The pointer to the PEI Services Table.\r
157 @param[in] This The pointer to this instance of this PPI.\r
158 @param[out] FspHobList The pointer to Hob list produced by FSP.\r
cf1d4549 159\r
68d47eea 160 @return EFI_SUCCESS Return Hob list produced by FSP successfully.\r
cf1d4549
JY
161**/\r
162EFI_STATUS\r
163EFIAPI\r
164FspSiliconInitDoneGetFspHobList (\r
165 IN CONST EFI_PEI_SERVICES **PeiServices,\r
166 IN FSP_SILICON_INIT_DONE_PPI *This,\r
167 OUT VOID **FspHobList\r
168 )\r
169{\r
170 EFI_HOB_GUID_TYPE *GuidHob;\r
171\r
172 GuidHob = GetFirstGuidHob (&gFspHobGuid);\r
173 if (GuidHob != NULL) {\r
174 *FspHobList = *(VOID **)GET_GUID_HOB_DATA(GuidHob);\r
175 return EFI_SUCCESS;\r
176 } else {\r
177 return EFI_NOT_FOUND;\r
178 }\r
179}\r
180\r
68d47eea
CC
181/**\r
182 This function is for FSP dispatch mode to perform post FSP-S process.\r
183\r
184 @param[in] PeiServices Pointer to PEI Services Table.\r
185 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that\r
186 caused this function to execute.\r
187 @param[in] Ppi Pointer to the PPI data associated with this function.\r
188\r
189 @retval EFI_STATUS Status returned by PeiServicesInstallPpi ()\r
190**/\r
191EFI_STATUS\r
192EFIAPI\r
193FspsWrapperEndOfPeiNotify (\r
194 IN EFI_PEI_SERVICES **PeiServices,\r
195 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,\r
196 IN VOID *Ppi\r
197 )\r
198{\r
199 EFI_STATUS Status;\r
200\r
201 //\r
202 // This step may include platform specific process in some boot loaders so\r
203 // aligning the same behavior between API and Dispatch modes.\r
204 // Note: In Dispatch mode no FspHobList so passing NULL to function and\r
205 // expecting function will handle it.\r
206 //\r
207 PostFspsHobProcess (NULL);\r
208\r
209 //\r
210 // Install FspSiliconInitDonePpi so that any other driver can consume this info.\r
211 //\r
212 Status = PeiServicesInstallPpi (&mPeiFspSiliconInitDonePpi);\r
213 ASSERT_EFI_ERROR(Status);\r
214\r
215 return Status;\r
216}\r
217\r
218EFI_PEI_NOTIFY_DESCRIPTOR mFspsWrapperEndOfPeiNotifyDesc = {\r
219 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
220 &gEfiEndOfPeiSignalPpiGuid,\r
221 FspsWrapperEndOfPeiNotify\r
222};\r
223\r
cf1d4549
JY
224/**\r
225 This function is called after PEI core discover memory and finish migration.\r
226\r
227 @param[in] PeiServices Pointer to PEI Services Table.\r
228 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that\r
229 caused this function to execute.\r
230 @param[in] Ppi Pointer to the PPI data associated with this function.\r
231\r
232 @retval EFI_STATUS Always return EFI_SUCCESS\r
233**/\r
234EFI_STATUS\r
235EFIAPI\r
236PeiMemoryDiscoveredNotify (\r
237 IN EFI_PEI_SERVICES **PeiServices,\r
238 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,\r
239 IN VOID *Ppi\r
240 );\r
241\r
242EFI_PEI_NOTIFY_DESCRIPTOR mPeiMemoryDiscoveredNotifyDesc = {\r
243 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
244 &gEfiPeiMemoryDiscoveredPpiGuid,\r
245 PeiMemoryDiscoveredNotify\r
246};\r
247\r
248/**\r
e69dcef5 249 This function is called after PEI core discover memory and finish migration.\r
cf1d4549 250\r
e69dcef5
CC
251 @param[in] PeiServices Pointer to PEI Services Table.\r
252 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that\r
253 caused this function to execute.\r
254 @param[in] Ppi Pointer to the PPI data associated with this function.\r
cf1d4549 255\r
e69dcef5 256 @retval EFI_STATUS Always return EFI_SUCCESS\r
cf1d4549
JY
257**/\r
258EFI_STATUS\r
259EFIAPI\r
260PeiMemoryDiscoveredNotify (\r
261 IN EFI_PEI_SERVICES **PeiServices,\r
262 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,\r
263 IN VOID *Ppi\r
264 )\r
265{\r
266 FSP_INFO_HEADER *FspsHeaderPtr;\r
267 UINT64 TimeStampCounterStart;\r
268 EFI_STATUS Status;\r
269 VOID *FspHobListPtr;\r
270 EFI_HOB_GUID_TYPE *GuidHob;\r
271 FSPS_UPD_COMMON *FspsUpdDataPtr;\r
272 UINTN *SourceData;\r
273\r
cf1d4549 274 DEBUG ((DEBUG_INFO, "PeiMemoryDiscoveredNotify enter\n"));\r
e69dcef5
CC
275 FspsUpdDataPtr = NULL;\r
276\r
cf1d4549 277 FspsHeaderPtr = (FSP_INFO_HEADER *)FspFindFspHeader (PcdGet32 (PcdFspsBaseAddress));\r
599c45ff
HW
278 DEBUG ((DEBUG_INFO, "FspsHeaderPtr - 0x%x\n", FspsHeaderPtr));\r
279 if (FspsHeaderPtr == NULL) {\r
280 return EFI_DEVICE_ERROR;\r
281 }\r
282\r
e69dcef5
CC
283 if (PcdGet32 (PcdFspsUpdDataAddress) == 0 && (FspsHeaderPtr->CfgRegionSize != 0) && (FspsHeaderPtr->CfgRegionOffset != 0)) {\r
284 //\r
285 // Copy default FSP-S UPD data from Flash\r
286 //\r
287 FspsUpdDataPtr = (FSPS_UPD_COMMON *)AllocateZeroPool ((UINTN)FspsHeaderPtr->CfgRegionSize);\r
288 ASSERT (FspsUpdDataPtr != NULL);\r
289 SourceData = (UINTN *)((UINTN)FspsHeaderPtr->ImageBase + (UINTN)FspsHeaderPtr->CfgRegionOffset);\r
290 CopyMem (FspsUpdDataPtr, SourceData, (UINTN)FspsHeaderPtr->CfgRegionSize);\r
291 } else {\r
292 FspsUpdDataPtr = (FSPS_UPD_COMMON *)PcdGet32 (PcdFspsUpdDataAddress);\r
293 ASSERT (FspsUpdDataPtr != NULL);\r
294 }\r
cf1d4549
JY
295\r
296 UpdateFspsUpdData ((VOID *)FspsUpdDataPtr);\r
297\r
298 TimeStampCounterStart = AsmReadTsc ();\r
19d29d35 299 PERF_START_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_SILICON_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);\r
cf1d4549 300 Status = CallFspSiliconInit ((VOID *)FspsUpdDataPtr);\r
19d29d35 301 PERF_END_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_SILICON_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);\r
cf1d4549 302 DEBUG ((DEBUG_INFO, "Total time spent executing FspSiliconInitApi: %d millisecond\n", DivU64x32 (GetTimeInNanoSecond (AsmReadTsc () - TimeStampCounterStart), 1000000)));\r
f862a3b6
JY
303\r
304 //\r
305 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status\r
306 //\r
307 if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {\r
308 DEBUG((DEBUG_INFO, "FspSiliconInitApi requested reset 0x%x\n", Status));\r
309 CallFspWrapperResetSystem ((UINT32)Status);\r
310 }\r
311\r
cf1d4549
JY
312 if (EFI_ERROR(Status)) {\r
313 DEBUG ((DEBUG_ERROR, "ERROR - Failed to execute FspSiliconInitApi(), Status = %r\n", Status));\r
314 }\r
315 DEBUG((DEBUG_INFO, "FspSiliconInit status: 0x%x\n", Status));\r
316 ASSERT_EFI_ERROR (Status);\r
317\r
318 Status = TestFspSiliconInitApiOutput ((VOID *)NULL);\r
319 if (RETURN_ERROR (Status)) {\r
320 DEBUG ((DEBUG_ERROR, "ERROR - TestFspSiliconInitApiOutput () fail, Status = %r\n", Status));\r
321 }\r
322\r
323 //\r
324 // Now FspHobList complete, process it\r
325 //\r
326 GuidHob = GetFirstGuidHob (&gFspHobGuid);\r
327 ASSERT (GuidHob != NULL);\r
328 FspHobListPtr = *(VOID **)GET_GUID_HOB_DATA (GuidHob);\r
329 DEBUG ((DEBUG_INFO, "FspHobListPtr - 0x%x\n", FspHobListPtr));\r
330 PostFspsHobProcess (FspHobListPtr);\r
331\r
332 //\r
333 // Install FspSiliconInitDonePpi so that any other driver can consume this info.\r
334 //\r
335 Status = PeiServicesInstallPpi (&mPeiFspSiliconInitDonePpi);\r
336 ASSERT_EFI_ERROR(Status);\r
337\r
338 return Status;\r
339}\r
340\r
341/**\r
00e3e480 342 Do FSP initialization in API mode.\r
cf1d4549 343\r
68d47eea 344 @retval EFI_STATUS Always return EFI_SUCCESS\r
cf1d4549
JY
345**/\r
346EFI_STATUS\r
68d47eea 347FspsWrapperInitApiMode (\r
cf1d4549
JY
348 VOID\r
349 )\r
350{\r
351 EFI_STATUS Status;\r
352 EFI_BOOT_MODE BootMode;\r
353\r
354 //\r
97eedf5d 355 // Register MemoryDiscovered Notify to run FspSiliconInit\r
cf1d4549
JY
356 //\r
357 Status = PeiServicesNotifyPpi (&mPeiMemoryDiscoveredNotifyDesc);\r
358 ASSERT_EFI_ERROR (Status);\r
e69dcef5 359\r
cf1d4549
JY
360 //\r
361 // Register EndOfPei Notify for S3 to run FSP NotifyPhase\r
362 //\r
363 PeiServicesGetBootMode (&BootMode);\r
364 if (BootMode == BOOT_ON_S3_RESUME) {\r
365 Status = PeiServicesNotifyPpi (&mS3EndOfPeiNotifyDesc);\r
366 ASSERT_EFI_ERROR (Status);\r
367 }\r
368\r
369 return EFI_SUCCESS;\r
370}\r
371\r
68d47eea 372/**\r
00e3e480 373 Do FSP initialization in Dispatch mode.\r
68d47eea
CC
374\r
375 @retval FSP initialization status.\r
376**/\r
377EFI_STATUS\r
378FspsWrapperInitDispatchMode (\r
379 VOID\r
380 )\r
381{\r
382 EFI_STATUS Status;\r
383 //\r
384 // FSP-S Wrapper running in Dispatch mode and reports FSP-S FV to PEI dispatcher.\r
385 //\r
386 PeiServicesInstallFvInfoPpi (\r
387 NULL,\r
388 (VOID *)(UINTN) PcdGet32 (PcdFspsBaseAddress),\r
389 (UINT32)((EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) PcdGet32 (PcdFspsBaseAddress))->FvLength,\r
390 NULL,\r
391 NULL\r
392 );\r
393 //\r
394 // Register EndOfPei Nofity to run post FSP-S process.\r
395 //\r
396 Status = PeiServicesNotifyPpi (&mFspsWrapperEndOfPeiNotifyDesc);\r
397 ASSERT_EFI_ERROR (Status);\r
398 return Status;\r
399}\r
400\r
cf1d4549 401/**\r
00e3e480 402 This is the entrypoint of PEIM.\r
cf1d4549
JY
403\r
404 @param[in] FileHandle Handle of the file being invoked.\r
405 @param[in] PeiServices Describes the list of possible PEI Services.\r
406\r
407 @retval EFI_SUCCESS if it completed successfully.\r
408**/\r
409EFI_STATUS\r
410EFIAPI\r
411FspsWrapperPeimEntryPoint (\r
412 IN EFI_PEI_FILE_HANDLE FileHandle,\r
413 IN CONST EFI_PEI_SERVICES **PeiServices\r
414 )\r
415{\r
cf1d4549
JY
416 DEBUG ((DEBUG_INFO, "FspsWrapperPeimEntryPoint\n"));\r
417\r
e8f40b77 418 if (PcdGet8 (PcdFspModeSelection) == 1) {\r
68d47eea 419 FspsWrapperInitApiMode ();\r
2098de62 420 } else {\r
68d47eea 421 FspsWrapperInitDispatchMode ();\r
2098de62 422 }\r
cf1d4549
JY
423\r
424 return EFI_SUCCESS;\r
425}\r