]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFsp2WrapperPkg/FspsWrapperPeim/FspsWrapperPeim.c
IntelFsp2WrapperPkg: Remove unused header files from Fspm and Fsps WrapperPeim
[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
cf1d4549
JY
39#include <Library/FspWrapperApiTestLib.h>\r
40#include <FspEas.h>\r
41\r
42extern EFI_PEI_NOTIFY_DESCRIPTOR mS3EndOfPeiNotifyDesc;\r
43extern EFI_GUID gFspHobGuid;\r
44\r
45/**\r
46This function handles S3 resume task at the end of PEI\r
47\r
48@param[in] PeiServices Pointer to PEI Services Table.\r
49@param[in] NotifyDesc Pointer to the descriptor for the Notification event that\r
50caused this function to execute.\r
51@param[in] Ppi Pointer to the PPI data associated with this function.\r
52\r
53@retval EFI_STATUS Always return EFI_SUCCESS\r
54**/\r
55EFI_STATUS\r
56EFIAPI\r
57S3EndOfPeiNotify(\r
58 IN EFI_PEI_SERVICES **PeiServices,\r
59 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,\r
60 IN VOID *Ppi\r
61 );\r
62\r
63EFI_PEI_NOTIFY_DESCRIPTOR mS3EndOfPeiNotifyDesc = {\r
64 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
65 &gEfiEndOfPeiSignalPpiGuid,\r
66 S3EndOfPeiNotify\r
67};\r
68\r
69/**\r
70This function handles S3 resume task at the end of PEI\r
71\r
72@param[in] PeiServices Pointer to PEI Services Table.\r
73@param[in] NotifyDesc Pointer to the descriptor for the Notification event that\r
74caused this function to execute.\r
75@param[in] Ppi Pointer to the PPI data associated with this function.\r
76\r
77@retval EFI_STATUS Always return EFI_SUCCESS\r
78**/\r
79EFI_STATUS\r
80EFIAPI\r
81S3EndOfPeiNotify(\r
82 IN EFI_PEI_SERVICES **PeiServices,\r
83 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,\r
84 IN VOID *Ppi\r
85 )\r
86{\r
87 NOTIFY_PHASE_PARAMS NotifyPhaseParams;\r
88 EFI_STATUS Status;\r
89\r
90 DEBUG((DEBUG_INFO, "S3EndOfPeiNotify enter\n"));\r
91\r
92 NotifyPhaseParams.Phase = EnumInitPhaseAfterPciEnumeration;\r
93 Status = CallFspNotifyPhase (&NotifyPhaseParams);\r
94 DEBUG((DEBUG_INFO, "FSP S3NotifyPhase AfterPciEnumeration status: 0x%x\n", Status));\r
95\r
f862a3b6
JY
96 //\r
97 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status\r
98 //\r
99 if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {\r
100 DEBUG((DEBUG_INFO, "FSP S3NotifyPhase AfterPciEnumeration requested reset 0x%x\n", Status));\r
101 CallFspWrapperResetSystem ((UINT32)Status);\r
102 }\r
103\r
cf1d4549
JY
104 NotifyPhaseParams.Phase = EnumInitPhaseReadyToBoot;\r
105 Status = CallFspNotifyPhase (&NotifyPhaseParams);\r
106 DEBUG((DEBUG_INFO, "FSP S3NotifyPhase ReadyToBoot status: 0x%x\n", Status));\r
107\r
f862a3b6
JY
108 //\r
109 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status\r
110 //\r
111 if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {\r
112 DEBUG((DEBUG_INFO, "FSP S3NotifyPhase ReadyToBoot requested reset 0x%x\n", Status));\r
113 CallFspWrapperResetSystem ((UINT32)Status);\r
114 }\r
115\r
cf1d4549
JY
116 NotifyPhaseParams.Phase = EnumInitPhaseEndOfFirmware;\r
117 Status = CallFspNotifyPhase (&NotifyPhaseParams);\r
118 DEBUG((DEBUG_INFO, "FSP S3NotifyPhase EndOfFirmware status: 0x%x\n", Status));\r
119\r
f862a3b6
JY
120 //\r
121 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status\r
122 //\r
123 if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {\r
124 DEBUG((DEBUG_INFO, "FSP S3NotifyPhase EndOfFirmware requested reset 0x%x\n", Status));\r
125 CallFspWrapperResetSystem ((UINT32)Status);\r
126 }\r
127\r
cf1d4549
JY
128 return EFI_SUCCESS;\r
129}\r
130\r
131/**\r
132Return Hob list produced by FSP.\r
133\r
134@param[in] PeiServices The pointer to the PEI Services Table.\r
135@param[in] This The pointer to this instance of this PPI.\r
136@param[out] FspHobList The pointer to Hob list produced by FSP.\r
137\r
138@return EFI_SUCCESS FReturn Hob list produced by FSP successfully.\r
139**/\r
140EFI_STATUS\r
141EFIAPI\r
142FspSiliconInitDoneGetFspHobList (\r
143 IN CONST EFI_PEI_SERVICES **PeiServices,\r
144 IN FSP_SILICON_INIT_DONE_PPI *This,\r
145 OUT VOID **FspHobList\r
146 );\r
147\r
148FSP_SILICON_INIT_DONE_PPI mFspSiliconInitDonePpi = {\r
149 FspSiliconInitDoneGetFspHobList\r
150};\r
151\r
152EFI_PEI_PPI_DESCRIPTOR mPeiFspSiliconInitDonePpi = {\r
153 EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,\r
154 &gFspSiliconInitDonePpiGuid,\r
155 &mFspSiliconInitDonePpi\r
156};\r
157\r
158/**\r
159Return Hob list produced by FSP.\r
160\r
161@param[in] PeiServices The pointer to the PEI Services Table.\r
162@param[in] This The pointer to this instance of this PPI.\r
163@param[out] FspHobList The pointer to Hob list produced by FSP.\r
164\r
165@return EFI_SUCCESS FReturn Hob list produced by FSP successfully.\r
166**/\r
167EFI_STATUS\r
168EFIAPI\r
169FspSiliconInitDoneGetFspHobList (\r
170 IN CONST EFI_PEI_SERVICES **PeiServices,\r
171 IN FSP_SILICON_INIT_DONE_PPI *This,\r
172 OUT VOID **FspHobList\r
173 )\r
174{\r
175 EFI_HOB_GUID_TYPE *GuidHob;\r
176\r
177 GuidHob = GetFirstGuidHob (&gFspHobGuid);\r
178 if (GuidHob != NULL) {\r
179 *FspHobList = *(VOID **)GET_GUID_HOB_DATA(GuidHob);\r
180 return EFI_SUCCESS;\r
181 } else {\r
182 return EFI_NOT_FOUND;\r
183 }\r
184}\r
185\r
186/**\r
187 This function is called after PEI core discover memory and finish migration.\r
188\r
189 @param[in] PeiServices Pointer to PEI Services Table.\r
190 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that\r
191 caused this function to execute.\r
192 @param[in] Ppi Pointer to the PPI data associated with this function.\r
193\r
194 @retval EFI_STATUS Always return EFI_SUCCESS\r
195**/\r
196EFI_STATUS\r
197EFIAPI\r
198PeiMemoryDiscoveredNotify (\r
199 IN EFI_PEI_SERVICES **PeiServices,\r
200 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,\r
201 IN VOID *Ppi\r
202 );\r
203\r
204EFI_PEI_NOTIFY_DESCRIPTOR mPeiMemoryDiscoveredNotifyDesc = {\r
205 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
206 &gEfiPeiMemoryDiscoveredPpiGuid,\r
207 PeiMemoryDiscoveredNotify\r
208};\r
209\r
210/**\r
211This function is called after PEI core discover memory and finish migration.\r
212\r
213@param[in] PeiServices Pointer to PEI Services Table.\r
214@param[in] NotifyDesc Pointer to the descriptor for the Notification event that\r
215caused this function to execute.\r
216@param[in] Ppi Pointer to the PPI data associated with this function.\r
217\r
218@retval EFI_STATUS Always return EFI_SUCCESS\r
219**/\r
220EFI_STATUS\r
221EFIAPI\r
222PeiMemoryDiscoveredNotify (\r
223 IN EFI_PEI_SERVICES **PeiServices,\r
224 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,\r
225 IN VOID *Ppi\r
226 )\r
227{\r
228 FSP_INFO_HEADER *FspsHeaderPtr;\r
229 UINT64 TimeStampCounterStart;\r
230 EFI_STATUS Status;\r
231 VOID *FspHobListPtr;\r
232 EFI_HOB_GUID_TYPE *GuidHob;\r
233 FSPS_UPD_COMMON *FspsUpdDataPtr;\r
234 UINTN *SourceData;\r
235\r
236 \r
237 DEBUG ((DEBUG_INFO, "PeiMemoryDiscoveredNotify enter\n"));\r
238 \r
239 //\r
240 // Copy default FSP-S UPD data from Flash\r
241 //\r
242 FspsHeaderPtr = (FSP_INFO_HEADER *)FspFindFspHeader (PcdGet32 (PcdFspsBaseAddress));\r
599c45ff
HW
243 DEBUG ((DEBUG_INFO, "FspsHeaderPtr - 0x%x\n", FspsHeaderPtr));\r
244 if (FspsHeaderPtr == NULL) {\r
245 return EFI_DEVICE_ERROR;\r
246 }\r
247\r
cf1d4549
JY
248 FspsUpdDataPtr = (FSPS_UPD_COMMON *)AllocateZeroPool ((UINTN)FspsHeaderPtr->CfgRegionSize);\r
249 ASSERT (FspsUpdDataPtr != NULL);\r
250 SourceData = (UINTN *)((UINTN)FspsHeaderPtr->ImageBase + (UINTN)FspsHeaderPtr->CfgRegionOffset);\r
251 CopyMem (FspsUpdDataPtr, SourceData, (UINTN)FspsHeaderPtr->CfgRegionSize);\r
252\r
253 UpdateFspsUpdData ((VOID *)FspsUpdDataPtr);\r
254\r
255 TimeStampCounterStart = AsmReadTsc ();\r
256 PERF_START_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, 0x9000);\r
257 Status = CallFspSiliconInit ((VOID *)FspsUpdDataPtr);\r
258 PERF_END_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, 0x907F);\r
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
316 \r
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
344\r
345 DEBUG ((DEBUG_INFO, "FspsWrapperPeimEntryPoint\n"));\r
346\r
347 FspsWrapperInit ();\r
348\r
349 return EFI_SUCCESS;\r
350}\r