TianoCore EDK2 master
Loading...
Searching...
No Matches
FspsWrapperPeim.c
Go to the documentation of this file.
1
11#include <PiPei.h>
12
16#include <Library/BaseLib.h>
17#include <Library/DebugLib.h>
19#include <Library/HobLib.h>
20#include <Library/PcdLib.h>
25#include <Library/TimerLib.h>
29
31#include <Ppi/EndOfPeiPhase.h>
35#include <Ppi/Tcg.h>
38#include <FspEas.h>
39#include <FspStatusCode.h>
40#include <FspGlobalData.h>
41
42extern EFI_PEI_NOTIFY_DESCRIPTOR mS3EndOfPeiNotifyDesc;
43extern EFI_GUID gFspHobGuid;
44
56EFIAPI
58 IN EFI_PEI_SERVICES **PeiServices,
59 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
60 IN VOID *Ppi
61 );
62
63EFI_PEI_NOTIFY_DESCRIPTOR mS3EndOfPeiNotifyDesc = {
64 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
65 &gEfiEndOfPeiSignalPpiGuid,
67};
68
80EFIAPI
82 IN EFI_PEI_SERVICES **PeiServices,
83 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
84 IN VOID *Ppi
85 )
86{
87 NOTIFY_PHASE_PARAMS NotifyPhaseParams;
88 EFI_STATUS Status;
89
90 DEBUG ((DEBUG_INFO, "S3EndOfPeiNotify enter\n"));
91
92 NotifyPhaseParams.Phase = EnumInitPhaseAfterPciEnumeration;
93 Status = CallFspNotifyPhase (&NotifyPhaseParams);
94 DEBUG ((DEBUG_INFO, "FSP S3NotifyPhase AfterPciEnumeration status: 0x%x\n", Status));
95
96 //
97 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
98 //
99 if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {
100 DEBUG ((DEBUG_INFO, "FSP S3NotifyPhase AfterPciEnumeration requested reset 0x%x\n", Status));
102 }
103
104 NotifyPhaseParams.Phase = EnumInitPhaseReadyToBoot;
105 Status = CallFspNotifyPhase (&NotifyPhaseParams);
106 DEBUG ((DEBUG_INFO, "FSP S3NotifyPhase ReadyToBoot status: 0x%x\n", Status));
107
108 //
109 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
110 //
111 if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {
112 DEBUG ((DEBUG_INFO, "FSP S3NotifyPhase ReadyToBoot requested reset 0x%x\n", Status));
114 }
115
116 NotifyPhaseParams.Phase = EnumInitPhaseEndOfFirmware;
117 Status = CallFspNotifyPhase (&NotifyPhaseParams);
118 DEBUG ((DEBUG_INFO, "FSP S3NotifyPhase EndOfFirmware status: 0x%x\n", Status));
119
120 //
121 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
122 //
123 if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {
124 DEBUG ((DEBUG_INFO, "FSP S3NotifyPhase EndOfFirmware requested reset 0x%x\n", Status));
126 }
127
128 return EFI_SUCCESS;
129}
130
141EFIAPI
143 IN CONST EFI_PEI_SERVICES **PeiServices,
145 OUT VOID **FspHobList
146 );
147
148FSP_SILICON_INIT_DONE_PPI mFspSiliconInitDonePpi = {
150};
151
152EFI_PEI_PPI_DESCRIPTOR mPeiFspSiliconInitDonePpi = {
153 EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
154 &gFspSiliconInitDonePpiGuid,
155 &mFspSiliconInitDonePpi
156};
157
168EFIAPI
170 IN CONST EFI_PEI_SERVICES **PeiServices,
172 OUT VOID **FspHobList
173 )
174{
175 EFI_HOB_GUID_TYPE *GuidHob;
176
177 GuidHob = GetFirstGuidHob (&gFspHobGuid);
178 if (GuidHob != NULL) {
179 *FspHobList = *(VOID **)GET_GUID_HOB_DATA (GuidHob);
180 return EFI_SUCCESS;
181 } else {
182 return EFI_NOT_FOUND;
183 }
184}
185
191UINTN
193 VOID
194 )
195{
196 if (PcdGet64 (PcdFspsUpdDataAddress64) != 0) {
197 return (UINTN)PcdGet64 (PcdFspsUpdDataAddress64);
198 } else {
199 return (UINTN)PcdGet32 (PcdFspsUpdDataAddress);
200 }
201}
202
214EFIAPI
216 IN EFI_PEI_SERVICES **PeiServices,
217 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
218 IN VOID *Ppi
219 )
220{
221 EFI_STATUS Status;
222
223 //
224 // This step may include platform specific process in some boot loaders so
225 // aligning the same behavior between API and Dispatch modes.
226 // Note: In Dispatch mode no FspHobList so passing NULL to function and
227 // expecting function will handle it.
228 //
230
231 //
232 // Install FspSiliconInitDonePpi so that any other driver can consume this info.
233 //
234 Status = PeiServicesInstallPpi (&mPeiFspSiliconInitDonePpi);
235 ASSERT_EFI_ERROR (Status);
236
237 return Status;
238}
239
240EFI_PEI_NOTIFY_DESCRIPTOR mFspsWrapperEndOfPeiNotifyDesc = {
241 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
242 &gEfiEndOfPeiSignalPpiGuid,
244};
245
257EFIAPI
259 IN EFI_PEI_SERVICES **PeiServices,
260 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
261 IN VOID *Ppi
262 );
263
264EFI_PEI_NOTIFY_DESCRIPTOR mPeiMemoryDiscoveredNotifyDesc = {
265 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
266 &gEfiPeiMemoryDiscoveredPpiGuid,
268};
269
281EFIAPI
283 IN EFI_PEI_SERVICES **PeiServices,
284 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
285 IN VOID *Ppi
286 )
287{
288 FSP_INFO_HEADER *FspsHeaderPtr;
289 UINT64 TimeStampCounterStart;
290 EFI_STATUS Status;
291 VOID *FspHobListPtr;
292 EFI_HOB_GUID_TYPE *GuidHob;
293 FSPS_UPD_COMMON *FspsUpdDataPtr;
294 UINTN *SourceData;
295
296 DEBUG ((DEBUG_INFO, "PeiMemoryDiscoveredNotify enter\n"));
297 FspsUpdDataPtr = NULL;
298
299 FspsHeaderPtr = (FSP_INFO_HEADER *)FspFindFspHeader (PcdGet32 (PcdFspsBaseAddress));
300 DEBUG ((DEBUG_INFO, "FspsHeaderPtr - 0x%x\n", FspsHeaderPtr));
301 if (FspsHeaderPtr == NULL) {
302 return EFI_DEVICE_ERROR;
303 }
304
305 if ((GetFspsUpdDataAddress () == 0) && (FspsHeaderPtr->CfgRegionSize != 0) && (FspsHeaderPtr->CfgRegionOffset != 0)) {
306 //
307 // Copy default FSP-S UPD data from Flash
308 //
309 FspsUpdDataPtr = (FSPS_UPD_COMMON *)AllocateZeroPool ((UINTN)FspsHeaderPtr->CfgRegionSize);
310 ASSERT (FspsUpdDataPtr != NULL);
311 SourceData = (UINTN *)((UINTN)FspsHeaderPtr->ImageBase + (UINTN)FspsHeaderPtr->CfgRegionOffset);
312 CopyMem (FspsUpdDataPtr, SourceData, (UINTN)FspsHeaderPtr->CfgRegionSize);
313 } else {
314 FspsUpdDataPtr = (FSPS_UPD_COMMON *)GetFspsUpdDataAddress ();
315 ASSERT (FspsUpdDataPtr != NULL);
316 }
317
318 UpdateFspsUpdData ((VOID *)FspsUpdDataPtr);
319
320 TimeStampCounterStart = AsmReadTsc ();
321 PERF_START_EX (&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_SILICON_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);
322 Status = CallFspSiliconInit ((VOID *)FspsUpdDataPtr);
323
324 //
325 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
326 //
327 if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {
328 DEBUG ((DEBUG_INFO, "FspSiliconInitApi requested reset %r\n", Status));
330 }
331
332 if ((Status != FSP_STATUS_VARIABLE_REQUEST) && EFI_ERROR (Status)) {
333 DEBUG ((DEBUG_ERROR, "ERROR - Failed to execute FspSiliconInitApi(), Status = %r\n", Status));
334 ASSERT_EFI_ERROR (Status);
335 }
336
337 DEBUG ((DEBUG_INFO, "FspSiliconInit status: %r\n", Status));
338
339 //
340 // Get FspHobList
341 //
342 GuidHob = GetFirstGuidHob (&gFspHobGuid);
343 ASSERT (GuidHob != NULL);
344 FspHobListPtr = *(VOID **)GET_GUID_HOB_DATA (GuidHob);
345 DEBUG ((DEBUG_INFO, "FspHobListPtr - 0x%x\n", FspHobListPtr));
346
347 if (Status == FSP_STATUS_VARIABLE_REQUEST) {
348 //
349 // call to Variable request handler
350 //
351 FspWrapperVariableRequestHandler (&FspHobListPtr, FspMultiPhaseSiInitApiIndex);
352 }
353
354 //
355 // See if MultiPhase process is required or not
356 //
357 FspWrapperMultiPhaseHandler (&FspHobListPtr, FspMultiPhaseSiInitApiIndex); // FspS MultiPhase
358
359 PERF_END_EX (&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_SILICON_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);
360 DEBUG ((DEBUG_INFO, "Total time spent executing FspSiliconInitApi: %d millisecond\n", DivU64x32 (GetTimeInNanoSecond (AsmReadTsc () - TimeStampCounterStart), 1000000)));
361
362 Status = TestFspSiliconInitApiOutput ((VOID *)NULL);
363 if (RETURN_ERROR (Status)) {
364 DEBUG ((DEBUG_ERROR, "ERROR - TestFspSiliconInitApiOutput () fail, Status = %r\n", Status));
365 }
366
367 PostFspsHobProcess (FspHobListPtr);
368
369 //
370 // Install FspSiliconInitDonePpi so that any other driver can consume this info.
371 //
372 Status = PeiServicesInstallPpi (&mPeiFspSiliconInitDonePpi);
373 ASSERT_EFI_ERROR (Status);
374
375 return Status;
376}
377
385 VOID
386 )
387{
388 EFI_STATUS Status;
389 EFI_BOOT_MODE BootMode;
390
391 //
392 // Register MemoryDiscovered Notify to run FspSiliconInit
393 //
394 Status = PeiServicesNotifyPpi (&mPeiMemoryDiscoveredNotifyDesc);
395 ASSERT_EFI_ERROR (Status);
396
397 //
398 // Register EndOfPei Notify for S3 to run FSP NotifyPhase
399 //
400 PeiServicesGetBootMode (&BootMode);
401 if (BootMode == BOOT_ON_S3_RESUME) {
402 Status = PeiServicesNotifyPpi (&mS3EndOfPeiNotifyDesc);
403 ASSERT_EFI_ERROR (Status);
404 }
405
406 return EFI_SUCCESS;
407}
408
416 VOID
417 )
418{
419 EFI_STATUS Status;
421 EFI_PEI_PPI_DESCRIPTOR *MeasurementExcludedPpiList;
422
423 MeasurementExcludedFvPpi = AllocatePool (sizeof (*MeasurementExcludedFvPpi));
424 if (MeasurementExcludedFvPpi == NULL) {
425 ASSERT (MeasurementExcludedFvPpi != NULL);
426 return EFI_OUT_OF_RESOURCES;
427 }
428
429 MeasurementExcludedFvPpi->Count = 1;
430 MeasurementExcludedFvPpi->Fv[0].FvBase = PcdGet32 (PcdFspsBaseAddress);
431 MeasurementExcludedFvPpi->Fv[0].FvLength = ((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdFspsBaseAddress))->FvLength;
432
433 MeasurementExcludedPpiList = AllocatePool (sizeof (*MeasurementExcludedPpiList));
434 if (MeasurementExcludedPpiList == NULL) {
435 ASSERT (MeasurementExcludedPpiList != NULL);
436 FreePool (MeasurementExcludedFvPpi);
437 return EFI_OUT_OF_RESOURCES;
438 }
439
440 MeasurementExcludedPpiList->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
441 MeasurementExcludedPpiList->Guid = &gEfiPeiFirmwareVolumeInfoMeasurementExcludedPpiGuid;
442 MeasurementExcludedPpiList->Ppi = MeasurementExcludedFvPpi;
443
444 Status = PeiServicesInstallPpi (MeasurementExcludedPpiList);
445 ASSERT_EFI_ERROR (Status);
446
447 //
448 // FSP-S Wrapper running in Dispatch mode and reports FSP-S FV to PEI dispatcher.
449 //
451 &((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdFspsBaseAddress))->FileSystemGuid,
452 (VOID *)(UINTN)PcdGet32 (PcdFspsBaseAddress),
453 (UINT32)((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdFspsBaseAddress))->FvLength,
454 NULL,
455 NULL
456 );
457 //
458 // Register EndOfPei Nofity to run post FSP-S process.
459 //
460 Status = PeiServicesNotifyPpi (&mFspsWrapperEndOfPeiNotifyDesc);
461 ASSERT_EFI_ERROR (Status);
462 return Status;
463}
464
476EFIAPI
478 IN EFI_PEI_SERVICES **PeiServices,
479 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
480 IN VOID *Ppi
481 );
482
483EFI_PEI_NOTIFY_DESCRIPTOR mTcgPpiNotifyDesc = {
484 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
485 &gEdkiiTcgPpiGuid,
487};
488
500EFIAPI
502 IN EFI_PEI_SERVICES **PeiServices,
503 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
504 IN VOID *Ppi
505 )
506{
507 UINT32 FspMeasureMask;
508
509 DEBUG ((DEBUG_INFO, "TcgPpiNotify FSPS\n"));
510
511 FspMeasureMask = PcdGet32 (PcdFspMeasurementConfig);
512
513 if ((FspMeasureMask & FSP_MEASURE_FSPS) != 0) {
515 0,
516 "FSPS",
517 PcdGet32 (PcdFspsBaseAddress),
518 (UINT32)((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdFspsBaseAddress))->FvLength
519 );
520 }
521
522 return EFI_SUCCESS;
523}
524
534EFIAPI
536 IN EFI_PEI_FILE_HANDLE FileHandle,
537 IN CONST EFI_PEI_SERVICES **PeiServices
538 )
539{
540 EFI_STATUS Status;
541
542 DEBUG ((DEBUG_INFO, "FspsWrapperPeimEntryPoint\n"));
543
544 Status = PeiServicesNotifyPpi (&mTcgPpiNotifyDesc);
545 ASSERT_EFI_ERROR (Status);
546
547 if (PcdGet8 (PcdFspModeSelection) == 1) {
549 } else {
551 }
552
553 return EFI_SUCCESS;
554}
UINT64 UINTN
UINT64 EFIAPI GetTimeInNanoSecond(IN UINT64 Ticks)
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
Definition: HobLib.c:215
UINT64 EFIAPI AsmReadTsc(VOID)
Definition: GccInline.c:555
UINT64 EFIAPI DivU64x32(IN UINT64 Dividend, IN UINT32 Divisor)
Definition: DivU64x32.c:29
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS EFIAPI PeiServicesGetBootMode(OUT EFI_BOOT_MODE *BootMode)
VOID EFIAPI PeiServicesInstallFvInfoPpi(IN CONST EFI_GUID *FvFormat OPTIONAL, IN CONST VOID *FvInfo, IN UINT32 FvInfoSize, IN CONST EFI_GUID *ParentFvName OPTIONAL, IN CONST EFI_GUID *ParentFileName OPTIONAL)
EFI_STATUS EFIAPI PeiServicesNotifyPpi(IN CONST EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList)
EFI_STATUS EFIAPI PeiServicesInstallPpi(IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList)
@ EnumInitPhaseAfterPciEnumeration
Definition: FspApi.h:470
@ EnumInitPhaseReadyToBoot
Definition: FspApi.h:475
@ EnumInitPhaseEndOfFirmware
Definition: FspApi.h:481
EFI_STATUS EFIAPI MeasureFspFirmwareBlob(IN UINT32 PcrIndex, IN CHAR8 *Description OPTIONAL, IN EFI_PHYSICAL_ADDRESS FirmwareBlobBase, IN UINT64 FirmwareBlobLength)
EFI_STATUS EFIAPI CallFspSiliconInit(IN VOID *FspsUpdDataPtr)
EFI_STATUS EFIAPI CallFspNotifyPhase(IN NOTIFY_PHASE_PARAMS *NotifyPhaseParams)
FSP_INFO_HEADER *EFIAPI FspFindFspHeader(IN EFI_PHYSICAL_ADDRESS FlashFvFspBase)
EFI_STATUS EFIAPI TestFspSiliconInitApiOutput(IN VOID *FspsUpdDataPtr)
EFI_STATUS EFIAPI PostFspsHobProcess(IN VOID *FspHobList)
EFI_STATUS EFIAPI FspWrapperVariableRequestHandler(IN OUT VOID **FspHobListPtr, IN UINT8 ComponentIndex)
EFI_STATUS EFIAPI FspWrapperMultiPhaseHandler(IN OUT VOID **FspHobListPtr, IN UINT8 ComponentIndex)
VOID EFIAPI UpdateFspsUpdData(IN OUT VOID *FspUpdRgnPtr)
VOID EFIAPI CallFspWrapperResetSystem(IN EFI_STATUS FspStatusResetType)
EFI_STATUS EFIAPI FspsWrapperPeimEntryPoint(IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices)
EFI_STATUS FspsWrapperInitDispatchMode(VOID)
EFI_STATUS EFIAPI TcgPpiNotify(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc, IN VOID *Ppi)
EFI_STATUS EFIAPI FspsWrapperEndOfPeiNotify(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc, IN VOID *Ppi)
UINTN GetFspsUpdDataAddress(VOID)
EFI_STATUS EFIAPI S3EndOfPeiNotify(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc, IN VOID *Ppi)
EFI_STATUS FspsWrapperInitApiMode(VOID)
EFI_STATUS EFIAPI PeiMemoryDiscoveredNotify(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc, IN VOID *Ppi)
EFI_STATUS EFIAPI FspSiliconInitDoneGetFspHobList(IN CONST EFI_PEI_SERVICES **PeiServices, IN FSP_SILICON_INIT_DONE_PPI *This, OUT VOID **FspHobList)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define RETURN_ERROR(StatusCode)
Definition: Base.h:1061
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define PcdGet64(TokenName)
Definition: PcdLib.h:375
#define PcdGet8(TokenName)
Definition: PcdLib.h:336
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
#define PERF_START_EX(Handle, Token, Module, TimeStamp, Identifier)
#define PERF_END_EX(Handle, Token, Module, TimeStamp, Identifier)
UINT32 EFI_BOOT_MODE
Definition: PiBootMode.h:18
VOID * EFI_PEI_FILE_HANDLE
Definition: PiPeiCis.h:26
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
UINT32 CfgRegionOffset
Definition: Base.h:213
FSP_INIT_PHASE Phase
Definition: FspApi.h:491