]>
Commit | Line | Data |
---|---|---|
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 - 2019, Intel Corporation. All rights reserved.<BR>\r | |
7 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
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 | |
33 | #include <Library/FspWrapperApiTestLib.h>\r | |
34 | #include <FspEas.h>\r | |
35 | #include <FspStatusCode.h>\r | |
36 | \r | |
37 | extern EFI_PEI_NOTIFY_DESCRIPTOR mS3EndOfPeiNotifyDesc;\r | |
38 | extern EFI_GUID gFspHobGuid;\r | |
39 | \r | |
40 | /**\r | |
41 | This function handles S3 resume task at the end of PEI.\r | |
42 | \r | |
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 | |
47 | \r | |
48 | @retval EFI_STATUS Always return EFI_SUCCESS\r | |
49 | **/\r | |
50 | EFI_STATUS\r | |
51 | EFIAPI\r | |
52 | S3EndOfPeiNotify(\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 | |
58 | EFI_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 | |
65 | This function handles S3 resume task at the end of PEI.\r | |
66 | \r | |
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 | |
71 | \r | |
72 | @retval EFI_STATUS Always return EFI_SUCCESS\r | |
73 | **/\r | |
74 | EFI_STATUS\r | |
75 | EFIAPI\r | |
76 | S3EndOfPeiNotify(\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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
123 | return EFI_SUCCESS;\r | |
124 | }\r | |
125 | \r | |
126 | /**\r | |
127 | Return Hob list produced by FSP.\r | |
128 | \r | |
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 | |
132 | \r | |
133 | @return EFI_SUCCESS Return Hob list produced by FSP successfully.\r | |
134 | **/\r | |
135 | EFI_STATUS\r | |
136 | EFIAPI\r | |
137 | FspSiliconInitDoneGetFspHobList (\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 | |
143 | FSP_SILICON_INIT_DONE_PPI mFspSiliconInitDonePpi = {\r | |
144 | FspSiliconInitDoneGetFspHobList\r | |
145 | };\r | |
146 | \r | |
147 | EFI_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 | |
154 | Return Hob list produced by FSP.\r | |
155 | \r | |
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 | |
159 | \r | |
160 | @return EFI_SUCCESS Return Hob list produced by FSP successfully.\r | |
161 | **/\r | |
162 | EFI_STATUS\r | |
163 | EFIAPI\r | |
164 | FspSiliconInitDoneGetFspHobList (\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 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 | |
191 | EFI_STATUS\r | |
192 | EFIAPI\r | |
193 | FspsWrapperEndOfPeiNotify (\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 | |
218 | EFI_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 | |
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 | |
234 | EFI_STATUS\r | |
235 | EFIAPI\r | |
236 | PeiMemoryDiscoveredNotify (\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 | |
242 | EFI_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 | |
249 | This function is called after PEI core discover memory and finish migration.\r | |
250 | \r | |
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 | |
255 | \r | |
256 | @retval EFI_STATUS Always return EFI_SUCCESS\r | |
257 | **/\r | |
258 | EFI_STATUS\r | |
259 | EFIAPI\r | |
260 | PeiMemoryDiscoveredNotify (\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 | |
274 | DEBUG ((DEBUG_INFO, "PeiMemoryDiscoveredNotify enter\n"));\r | |
275 | FspsUpdDataPtr = NULL;\r | |
276 | \r | |
277 | FspsHeaderPtr = (FSP_INFO_HEADER *)FspFindFspHeader (PcdGet32 (PcdFspsBaseAddress));\r | |
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 | |
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 | |
295 | \r | |
296 | UpdateFspsUpdData ((VOID *)FspsUpdDataPtr);\r | |
297 | \r | |
298 | TimeStampCounterStart = AsmReadTsc ();\r | |
299 | PERF_START_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_SILICON_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);\r | |
300 | Status = CallFspSiliconInit ((VOID *)FspsUpdDataPtr);\r | |
301 | PERF_END_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_SILICON_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);\r | |
302 | DEBUG ((DEBUG_INFO, "Total time spent executing FspSiliconInitApi: %d millisecond\n", DivU64x32 (GetTimeInNanoSecond (AsmReadTsc () - TimeStampCounterStart), 1000000)));\r | |
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 | |
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 | |
342 | Do FSP initialization in API mode.\r | |
343 | \r | |
344 | @retval EFI_STATUS Always return EFI_SUCCESS\r | |
345 | **/\r | |
346 | EFI_STATUS\r | |
347 | FspsWrapperInitApiMode (\r | |
348 | VOID\r | |
349 | )\r | |
350 | {\r | |
351 | EFI_STATUS Status;\r | |
352 | EFI_BOOT_MODE BootMode;\r | |
353 | \r | |
354 | //\r | |
355 | // Register MemoryDiscovered Notify to run FspSiliconInit\r | |
356 | //\r | |
357 | Status = PeiServicesNotifyPpi (&mPeiMemoryDiscoveredNotifyDesc);\r | |
358 | ASSERT_EFI_ERROR (Status);\r | |
359 | \r | |
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 | |
372 | /**\r | |
373 | Do FSP initialization in Dispatch mode.\r | |
374 | \r | |
375 | @retval FSP initialization status.\r | |
376 | **/\r | |
377 | EFI_STATUS\r | |
378 | FspsWrapperInitDispatchMode (\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 | |
401 | /**\r | |
402 | This is the entrypoint of PEIM.\r | |
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 | |
409 | EFI_STATUS\r | |
410 | EFIAPI\r | |
411 | FspsWrapperPeimEntryPoint (\r | |
412 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
413 | IN CONST EFI_PEI_SERVICES **PeiServices\r | |
414 | )\r | |
415 | {\r | |
416 | DEBUG ((DEBUG_INFO, "FspsWrapperPeimEntryPoint\n"));\r | |
417 | \r | |
418 | if (PcdGet8 (PcdFspModeSelection) == 1) {\r | |
419 | FspsWrapperInitApiMode ();\r | |
420 | } else {\r | |
421 | FspsWrapperInitDispatchMode ();\r | |
422 | }\r | |
423 | \r | |
424 | return EFI_SUCCESS;\r | |
425 | }\r |