]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFsp2WrapperPkg/FspsWrapperPeim/FspsWrapperPeim.c
AppPkg: Replace BSD License with BSD+Patent License
[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
2098de62 6 Copyright (c) 2014 - 2018, 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
e69dcef5 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
e69dcef5 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
e69dcef5 133 @return EFI_SUCCESS FReturn 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
e69dcef5 160 @return EFI_SUCCESS FReturn 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
181/**\r
182 This function is called after PEI core discover memory and finish migration.\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 Always return EFI_SUCCESS\r
190**/\r
191EFI_STATUS\r
192EFIAPI\r
193PeiMemoryDiscoveredNotify (\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
199EFI_PEI_NOTIFY_DESCRIPTOR mPeiMemoryDiscoveredNotifyDesc = {\r
200 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
201 &gEfiPeiMemoryDiscoveredPpiGuid,\r
202 PeiMemoryDiscoveredNotify\r
203};\r
204\r
205/**\r
e69dcef5 206 This function is called after PEI core discover memory and finish migration.\r
cf1d4549 207\r
e69dcef5
CC
208 @param[in] PeiServices Pointer to PEI Services Table.\r
209 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that\r
210 caused this function to execute.\r
211 @param[in] Ppi Pointer to the PPI data associated with this function.\r
cf1d4549 212\r
e69dcef5 213 @retval EFI_STATUS Always return EFI_SUCCESS\r
cf1d4549
JY
214**/\r
215EFI_STATUS\r
216EFIAPI\r
217PeiMemoryDiscoveredNotify (\r
218 IN EFI_PEI_SERVICES **PeiServices,\r
219 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,\r
220 IN VOID *Ppi\r
221 )\r
222{\r
223 FSP_INFO_HEADER *FspsHeaderPtr;\r
224 UINT64 TimeStampCounterStart;\r
225 EFI_STATUS Status;\r
226 VOID *FspHobListPtr;\r
227 EFI_HOB_GUID_TYPE *GuidHob;\r
228 FSPS_UPD_COMMON *FspsUpdDataPtr;\r
229 UINTN *SourceData;\r
230\r
cf1d4549 231 DEBUG ((DEBUG_INFO, "PeiMemoryDiscoveredNotify enter\n"));\r
e69dcef5
CC
232 FspsUpdDataPtr = NULL;\r
233\r
cf1d4549 234 FspsHeaderPtr = (FSP_INFO_HEADER *)FspFindFspHeader (PcdGet32 (PcdFspsBaseAddress));\r
599c45ff
HW
235 DEBUG ((DEBUG_INFO, "FspsHeaderPtr - 0x%x\n", FspsHeaderPtr));\r
236 if (FspsHeaderPtr == NULL) {\r
237 return EFI_DEVICE_ERROR;\r
238 }\r
239\r
e69dcef5
CC
240 if (PcdGet32 (PcdFspsUpdDataAddress) == 0 && (FspsHeaderPtr->CfgRegionSize != 0) && (FspsHeaderPtr->CfgRegionOffset != 0)) {\r
241 //\r
242 // Copy default FSP-S UPD data from Flash\r
243 //\r
244 FspsUpdDataPtr = (FSPS_UPD_COMMON *)AllocateZeroPool ((UINTN)FspsHeaderPtr->CfgRegionSize);\r
245 ASSERT (FspsUpdDataPtr != NULL);\r
246 SourceData = (UINTN *)((UINTN)FspsHeaderPtr->ImageBase + (UINTN)FspsHeaderPtr->CfgRegionOffset);\r
247 CopyMem (FspsUpdDataPtr, SourceData, (UINTN)FspsHeaderPtr->CfgRegionSize);\r
248 } else {\r
249 FspsUpdDataPtr = (FSPS_UPD_COMMON *)PcdGet32 (PcdFspsUpdDataAddress);\r
250 ASSERT (FspsUpdDataPtr != NULL);\r
251 }\r
cf1d4549
JY
252\r
253 UpdateFspsUpdData ((VOID *)FspsUpdDataPtr);\r
254\r
255 TimeStampCounterStart = AsmReadTsc ();\r
19d29d35 256 PERF_START_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_SILICON_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);\r
cf1d4549 257 Status = CallFspSiliconInit ((VOID *)FspsUpdDataPtr);\r
19d29d35 258 PERF_END_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_SILICON_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);\r
cf1d4549 259 DEBUG ((DEBUG_INFO, "Total time spent executing FspSiliconInitApi: %d millisecond\n", DivU64x32 (GetTimeInNanoSecond (AsmReadTsc () - TimeStampCounterStart), 1000000)));\r
f862a3b6
JY
260\r
261 //\r
262 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status\r
263 //\r
264 if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {\r
265 DEBUG((DEBUG_INFO, "FspSiliconInitApi requested reset 0x%x\n", Status));\r
266 CallFspWrapperResetSystem ((UINT32)Status);\r
267 }\r
268\r
cf1d4549
JY
269 if (EFI_ERROR(Status)) {\r
270 DEBUG ((DEBUG_ERROR, "ERROR - Failed to execute FspSiliconInitApi(), Status = %r\n", Status));\r
271 }\r
272 DEBUG((DEBUG_INFO, "FspSiliconInit status: 0x%x\n", Status));\r
273 ASSERT_EFI_ERROR (Status);\r
274\r
275 Status = TestFspSiliconInitApiOutput ((VOID *)NULL);\r
276 if (RETURN_ERROR (Status)) {\r
277 DEBUG ((DEBUG_ERROR, "ERROR - TestFspSiliconInitApiOutput () fail, Status = %r\n", Status));\r
278 }\r
279\r
280 //\r
281 // Now FspHobList complete, process it\r
282 //\r
283 GuidHob = GetFirstGuidHob (&gFspHobGuid);\r
284 ASSERT (GuidHob != NULL);\r
285 FspHobListPtr = *(VOID **)GET_GUID_HOB_DATA (GuidHob);\r
286 DEBUG ((DEBUG_INFO, "FspHobListPtr - 0x%x\n", FspHobListPtr));\r
287 PostFspsHobProcess (FspHobListPtr);\r
288\r
289 //\r
290 // Install FspSiliconInitDonePpi so that any other driver can consume this info.\r
291 //\r
292 Status = PeiServicesInstallPpi (&mPeiFspSiliconInitDonePpi);\r
293 ASSERT_EFI_ERROR(Status);\r
294\r
295 return Status;\r
296}\r
297\r
298/**\r
299 Do FSP initialization.\r
300\r
301 @return FSP initialization status.\r
302**/\r
303EFI_STATUS\r
304FspsWrapperInit (\r
305 VOID\r
306 )\r
307{\r
308 EFI_STATUS Status;\r
309 EFI_BOOT_MODE BootMode;\r
310\r
311 //\r
312 // Register MemoryDiscovered Nofity to run FspSiliconInit\r
313 //\r
314 Status = PeiServicesNotifyPpi (&mPeiMemoryDiscoveredNotifyDesc);\r
315 ASSERT_EFI_ERROR (Status);\r
e69dcef5 316\r
cf1d4549
JY
317 //\r
318 // Register EndOfPei Notify for S3 to run FSP NotifyPhase\r
319 //\r
320 PeiServicesGetBootMode (&BootMode);\r
321 if (BootMode == BOOT_ON_S3_RESUME) {\r
322 Status = PeiServicesNotifyPpi (&mS3EndOfPeiNotifyDesc);\r
323 ASSERT_EFI_ERROR (Status);\r
324 }\r
325\r
326 return EFI_SUCCESS;\r
327}\r
328\r
329/**\r
330 This is the entrypoint of PEIM\r
331\r
332 @param[in] FileHandle Handle of the file being invoked.\r
333 @param[in] PeiServices Describes the list of possible PEI Services.\r
334\r
335 @retval EFI_SUCCESS if it completed successfully.\r
336**/\r
337EFI_STATUS\r
338EFIAPI\r
339FspsWrapperPeimEntryPoint (\r
340 IN EFI_PEI_FILE_HANDLE FileHandle,\r
341 IN CONST EFI_PEI_SERVICES **PeiServices\r
342 )\r
343{\r
cf1d4549
JY
344 DEBUG ((DEBUG_INFO, "FspsWrapperPeimEntryPoint\n"));\r
345\r
e8f40b77 346 if (PcdGet8 (PcdFspModeSelection) == 1) {\r
2098de62
CC
347 FspsWrapperInit ();\r
348 } else {\r
349 PeiServicesInstallFvInfoPpi (\r
350 NULL,\r
351 (VOID *)(UINTN) PcdGet32 (PcdFspsBaseAddress),\r
352 (UINT32)((EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) PcdGet32 (PcdFspsBaseAddress))->FvLength,\r
353 NULL,\r
354 NULL\r
355 );\r
356 }\r
cf1d4549
JY
357\r
358 return EFI_SUCCESS;\r
359}\r