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