]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFsp2WrapperPkg/FspsWrapperPeim/FspsWrapperPeim.c
IntelFsp2WrapperPkg: Support 64bit FspResetType for X64 build.
[mirror_edk2.git] / IntelFsp2WrapperPkg / FspsWrapperPeim / FspsWrapperPeim.c
index 70dac7a4142dc62c1ba8b549599fe17b097d8eea..ee48dd69d36a6c61b18316d6b25a97dcbcae06b9 100644 (file)
@@ -3,14 +3,8 @@
   register TemporaryRamDonePpi to call TempRamExit API, and register MemoryDiscoveredPpi\r
   notify to call FspSiliconInit API.\r
 \r
-  Copyright (c) 2014 - 2017, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php.\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 #include <Library/TimerLib.h>\r
 #include <Library/PerformanceLib.h>\r
 #include <Library/FspWrapperApiLib.h>\r
+#include <Library/FspMeasurementLib.h>\r
 \r
 #include <Ppi/FspSiliconInitDone.h>\r
 #include <Ppi/EndOfPeiPhase.h>\r
 #include <Ppi/MemoryDiscovered.h>\r
 #include <Ppi/TemporaryRamDone.h>\r
 #include <Ppi/SecPlatformInformation.h>\r
+#include <Ppi/Tcg.h>\r
+#include <Ppi/FirmwareVolumeInfoMeasurementExcluded.h>\r
 #include <Library/FspWrapperApiTestLib.h>\r
 #include <FspEas.h>\r
 #include <FspStatusCode.h>\r
 \r
-extern EFI_PEI_NOTIFY_DESCRIPTOR mS3EndOfPeiNotifyDesc;\r
-extern EFI_GUID                  gFspHobGuid;\r
+extern EFI_PEI_NOTIFY_DESCRIPTOR  mS3EndOfPeiNotifyDesc;\r
+extern EFI_GUID                   gFspHobGuid;\r
 \r
 /**\r
-  This function handles S3 resume task at the end of PEI\r
+  This function handles S3 resume task at the end of PEI.\r
 \r
   @param[in] PeiServices    Pointer to PEI Services Table.\r
   @param[in] NotifyDesc     Pointer to the descriptor for the Notification event that\r
@@ -55,20 +52,20 @@ extern EFI_GUID                  gFspHobGuid;
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-S3EndOfPeiNotify(\r
-  IN EFI_PEI_SERVICES          **PeiServices,\r
-  IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,\r
-  IN VOID                      *Ppi\r
+S3EndOfPeiNotify (\r
+  IN EFI_PEI_SERVICES           **PeiServices,\r
+  IN EFI_PEI_NOTIFY_DESCRIPTOR  *NotifyDesc,\r
+  IN VOID                       *Ppi\r
   );\r
 \r
-EFI_PEI_NOTIFY_DESCRIPTOR mS3EndOfPeiNotifyDesc = {\r
+EFI_PEI_NOTIFY_DESCRIPTOR  mS3EndOfPeiNotifyDesc = {\r
   (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
   &gEfiEndOfPeiSignalPpiGuid,\r
   S3EndOfPeiNotify\r
 };\r
 \r
 /**\r
-  This function handles S3 resume task at the end of PEI\r
+  This function handles S3 resume task at the end of PEI.\r
 \r
   @param[in] PeiServices    Pointer to PEI Services Table.\r
   @param[in] NotifyDesc     Pointer to the descriptor for the Notification event that\r
@@ -79,51 +76,51 @@ EFI_PEI_NOTIFY_DESCRIPTOR mS3EndOfPeiNotifyDesc = {
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-S3EndOfPeiNotify(\r
-  IN EFI_PEI_SERVICES          **PeiServices,\r
-  IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,\r
-  IN VOID                      *Ppi\r
+S3EndOfPeiNotify (\r
+  IN EFI_PEI_SERVICES           **PeiServices,\r
+  IN EFI_PEI_NOTIFY_DESCRIPTOR  *NotifyDesc,\r
+  IN VOID                       *Ppi\r
   )\r
 {\r
-  NOTIFY_PHASE_PARAMS NotifyPhaseParams;\r
-  EFI_STATUS          Status;\r
+  NOTIFY_PHASE_PARAMS  NotifyPhaseParams;\r
+  EFI_STATUS           Status;\r
 \r
-  DEBUG((DEBUG_INFO, "S3EndOfPeiNotify enter\n"));\r
+  DEBUG ((DEBUG_INFO, "S3EndOfPeiNotify enter\n"));\r
 \r
   NotifyPhaseParams.Phase = EnumInitPhaseAfterPciEnumeration;\r
-  Status = CallFspNotifyPhase (&NotifyPhaseParams);\r
-  DEBUG((DEBUG_INFO, "FSP S3NotifyPhase AfterPciEnumeration status: 0x%x\n", Status));\r
+  Status                  = CallFspNotifyPhase (&NotifyPhaseParams);\r
+  DEBUG ((DEBUG_INFO, "FSP S3NotifyPhase AfterPciEnumeration status: 0x%x\n", Status));\r
 \r
   //\r
   // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status\r
   //\r
   if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {\r
-    DEBUG((DEBUG_INFO, "FSP S3NotifyPhase AfterPciEnumeration requested reset 0x%x\n", Status));\r
-    CallFspWrapperResetSystem ((UINT32)Status);\r
+    DEBUG ((DEBUG_INFO, "FSP S3NotifyPhase AfterPciEnumeration requested reset 0x%x\n", Status));\r
+    CallFspWrapperResetSystem (Status);\r
   }\r
 \r
   NotifyPhaseParams.Phase = EnumInitPhaseReadyToBoot;\r
-  Status = CallFspNotifyPhase (&NotifyPhaseParams);\r
-  DEBUG((DEBUG_INFO, "FSP S3NotifyPhase ReadyToBoot status: 0x%x\n", Status));\r
+  Status                  = CallFspNotifyPhase (&NotifyPhaseParams);\r
+  DEBUG ((DEBUG_INFO, "FSP S3NotifyPhase ReadyToBoot status: 0x%x\n", Status));\r
 \r
   //\r
   // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status\r
   //\r
   if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {\r
-    DEBUG((DEBUG_INFO, "FSP S3NotifyPhase ReadyToBoot requested reset 0x%x\n", Status));\r
-    CallFspWrapperResetSystem ((UINT32)Status);\r
+    DEBUG ((DEBUG_INFO, "FSP S3NotifyPhase ReadyToBoot requested reset 0x%x\n", Status));\r
+    CallFspWrapperResetSystem (Status);\r
   }\r
 \r
   NotifyPhaseParams.Phase = EnumInitPhaseEndOfFirmware;\r
-  Status = CallFspNotifyPhase (&NotifyPhaseParams);\r
-  DEBUG((DEBUG_INFO, "FSP S3NotifyPhase EndOfFirmware status: 0x%x\n", Status));\r
+  Status                  = CallFspNotifyPhase (&NotifyPhaseParams);\r
+  DEBUG ((DEBUG_INFO, "FSP S3NotifyPhase EndOfFirmware status: 0x%x\n", Status));\r
 \r
   //\r
   // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status\r
   //\r
   if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {\r
-    DEBUG((DEBUG_INFO, "FSP S3NotifyPhase EndOfFirmware requested reset 0x%x\n", Status));\r
-    CallFspWrapperResetSystem ((UINT32)Status);\r
+    DEBUG ((DEBUG_INFO, "FSP S3NotifyPhase EndOfFirmware requested reset 0x%x\n", Status));\r
+    CallFspWrapperResetSystem (Status);\r
   }\r
 \r
   return EFI_SUCCESS;\r
@@ -136,21 +133,21 @@ S3EndOfPeiNotify(
   @param[in]  This         The pointer to this instance of this PPI.\r
   @param[out] FspHobList   The pointer to Hob list produced by FSP.\r
 \r
-  @return EFI_SUCCESS FReturn Hob list produced by FSP successfully.\r
+  @return EFI_SUCCESS      Return Hob list produced by FSP successfully.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 FspSiliconInitDoneGetFspHobList (\r
-  IN  CONST EFI_PEI_SERVICES         **PeiServices,\r
-  IN  FSP_SILICON_INIT_DONE_PPI      *This,\r
-  OUT VOID                           **FspHobList\r
+  IN  CONST EFI_PEI_SERVICES     **PeiServices,\r
+  IN  FSP_SILICON_INIT_DONE_PPI  *This,\r
+  OUT VOID                       **FspHobList\r
   );\r
 \r
-FSP_SILICON_INIT_DONE_PPI mFspSiliconInitDonePpi = {\r
+FSP_SILICON_INIT_DONE_PPI  mFspSiliconInitDonePpi = {\r
   FspSiliconInitDoneGetFspHobList\r
 };\r
 \r
-EFI_PEI_PPI_DESCRIPTOR            mPeiFspSiliconInitDonePpi = {\r
+EFI_PEI_PPI_DESCRIPTOR  mPeiFspSiliconInitDonePpi = {\r
   EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,\r
   &gFspSiliconInitDonePpiGuid,\r
   &mFspSiliconInitDonePpi\r
@@ -163,27 +160,87 @@ EFI_PEI_PPI_DESCRIPTOR            mPeiFspSiliconInitDonePpi = {
   @param[in]  This         The pointer to this instance of this PPI.\r
   @param[out] FspHobList   The pointer to Hob list produced by FSP.\r
 \r
-  @return EFI_SUCCESS FReturn Hob list produced by FSP successfully.\r
+  @return EFI_SUCCESS      Return Hob list produced by FSP successfully.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 FspSiliconInitDoneGetFspHobList (\r
-  IN  CONST EFI_PEI_SERVICES         **PeiServices,\r
-  IN  FSP_SILICON_INIT_DONE_PPI      *This,\r
-  OUT VOID                           **FspHobList\r
+  IN  CONST EFI_PEI_SERVICES     **PeiServices,\r
+  IN  FSP_SILICON_INIT_DONE_PPI  *This,\r
+  OUT VOID                       **FspHobList\r
   )\r
 {\r
-  EFI_HOB_GUID_TYPE                  *GuidHob;\r
+  EFI_HOB_GUID_TYPE  *GuidHob;\r
 \r
   GuidHob = GetFirstGuidHob (&gFspHobGuid);\r
   if (GuidHob != NULL) {\r
-    *FspHobList = *(VOID **)GET_GUID_HOB_DATA(GuidHob);\r
+    *FspHobList = *(VOID **)GET_GUID_HOB_DATA (GuidHob);\r
     return EFI_SUCCESS;\r
   } else {\r
     return EFI_NOT_FOUND;\r
   }\r
 }\r
 \r
+/**\r
+  Get the FSP S UPD Data address\r
+\r
+  @return FSP-S UPD Data Address\r
+**/\r
+UINTN\r
+GetFspsUpdDataAddress (\r
+  VOID\r
+  )\r
+{\r
+  if (PcdGet64 (PcdFspsUpdDataAddress64) != 0) {\r
+    return (UINTN)PcdGet64 (PcdFspsUpdDataAddress64);\r
+  } else {\r
+    return (UINTN)PcdGet32 (PcdFspsUpdDataAddress);\r
+  }\r
+}\r
+\r
+/**\r
+  This function is for FSP dispatch mode to perform post FSP-S process.\r
+\r
+  @param[in] PeiServices    Pointer to PEI Services Table.\r
+  @param[in] NotifyDesc     Pointer to the descriptor for the Notification event that\r
+                            caused this function to execute.\r
+  @param[in] Ppi            Pointer to the PPI data associated with this function.\r
+\r
+  @retval EFI_STATUS        Status returned by PeiServicesInstallPpi ()\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FspsWrapperEndOfPeiNotify (\r
+  IN EFI_PEI_SERVICES           **PeiServices,\r
+  IN EFI_PEI_NOTIFY_DESCRIPTOR  *NotifyDesc,\r
+  IN VOID                       *Ppi\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // This step may include platform specific process in some boot loaders so\r
+  // aligning the same behavior between API and Dispatch modes.\r
+  // Note: In Dispatch mode no FspHobList so passing NULL to function and\r
+  //       expecting function will handle it.\r
+  //\r
+  PostFspsHobProcess (NULL);\r
+\r
+  //\r
+  // Install FspSiliconInitDonePpi so that any other driver can consume this info.\r
+  //\r
+  Status = PeiServicesInstallPpi (&mPeiFspSiliconInitDonePpi);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_PEI_NOTIFY_DESCRIPTOR  mFspsWrapperEndOfPeiNotifyDesc = {\r
+  (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
+  &gEfiEndOfPeiSignalPpiGuid,\r
+  FspsWrapperEndOfPeiNotify\r
+};\r
+\r
 /**\r
   This function is called after PEI core discover memory and finish migration.\r
 \r
@@ -197,12 +254,12 @@ FspSiliconInitDoneGetFspHobList (
 EFI_STATUS\r
 EFIAPI\r
 PeiMemoryDiscoveredNotify (\r
-  IN EFI_PEI_SERVICES          **PeiServices,\r
-  IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,\r
-  IN VOID                      *Ppi\r
+  IN EFI_PEI_SERVICES           **PeiServices,\r
+  IN EFI_PEI_NOTIFY_DESCRIPTOR  *NotifyDesc,\r
+  IN VOID                       *Ppi\r
   );\r
 \r
-EFI_PEI_NOTIFY_DESCRIPTOR mPeiMemoryDiscoveredNotifyDesc = {\r
+EFI_PEI_NOTIFY_DESCRIPTOR  mPeiMemoryDiscoveredNotifyDesc = {\r
   (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
   &gEfiPeiMemoryDiscoveredPpiGuid,\r
   PeiMemoryDiscoveredNotify\r
@@ -221,18 +278,18 @@ EFI_PEI_NOTIFY_DESCRIPTOR mPeiMemoryDiscoveredNotifyDesc = {
 EFI_STATUS\r
 EFIAPI\r
 PeiMemoryDiscoveredNotify (\r
-  IN EFI_PEI_SERVICES          **PeiServices,\r
-  IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,\r
-  IN VOID                      *Ppi\r
+  IN EFI_PEI_SERVICES           **PeiServices,\r
+  IN EFI_PEI_NOTIFY_DESCRIPTOR  *NotifyDesc,\r
+  IN VOID                       *Ppi\r
   )\r
 {\r
-  FSP_INFO_HEADER           *FspsHeaderPtr;\r
-  UINT64                    TimeStampCounterStart;\r
-  EFI_STATUS                Status;\r
-  VOID                      *FspHobListPtr;\r
-  EFI_HOB_GUID_TYPE         *GuidHob;\r
-  FSPS_UPD_COMMON           *FspsUpdDataPtr;\r
-  UINTN                     *SourceData;\r
+  FSP_INFO_HEADER    *FspsHeaderPtr;\r
+  UINT64             TimeStampCounterStart;\r
+  EFI_STATUS         Status;\r
+  VOID               *FspHobListPtr;\r
+  EFI_HOB_GUID_TYPE  *GuidHob;\r
+  FSPS_UPD_COMMON    *FspsUpdDataPtr;\r
+  UINTN              *SourceData;\r
 \r
   DEBUG ((DEBUG_INFO, "PeiMemoryDiscoveredNotify enter\n"));\r
   FspsUpdDataPtr = NULL;\r
@@ -243,7 +300,7 @@ PeiMemoryDiscoveredNotify (
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
-  if (PcdGet32 (PcdFspsUpdDataAddress) == 0 && (FspsHeaderPtr->CfgRegionSize != 0) && (FspsHeaderPtr->CfgRegionOffset != 0)) {\r
+  if ((GetFspsUpdDataAddress () == 0) && (FspsHeaderPtr->CfgRegionSize != 0) && (FspsHeaderPtr->CfgRegionOffset != 0)) {\r
     //\r
     // Copy default FSP-S UPD data from Flash\r
     //\r
@@ -252,30 +309,31 @@ PeiMemoryDiscoveredNotify (
     SourceData = (UINTN *)((UINTN)FspsHeaderPtr->ImageBase + (UINTN)FspsHeaderPtr->CfgRegionOffset);\r
     CopyMem (FspsUpdDataPtr, SourceData, (UINTN)FspsHeaderPtr->CfgRegionSize);\r
   } else {\r
-    FspsUpdDataPtr = (FSPS_UPD_COMMON *)PcdGet32 (PcdFspsUpdDataAddress);\r
+    FspsUpdDataPtr = (FSPS_UPD_COMMON *)GetFspsUpdDataAddress ();\r
     ASSERT (FspsUpdDataPtr != NULL);\r
   }\r
 \r
   UpdateFspsUpdData ((VOID *)FspsUpdDataPtr);\r
 \r
   TimeStampCounterStart = AsmReadTsc ();\r
-  PERF_START_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_SILICON_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);\r
+  PERF_START_EX (&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_SILICON_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);\r
   Status = CallFspSiliconInit ((VOID *)FspsUpdDataPtr);\r
-  PERF_END_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_SILICON_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);\r
+  PERF_END_EX (&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_SILICON_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);\r
   DEBUG ((DEBUG_INFO, "Total time spent executing FspSiliconInitApi: %d millisecond\n", DivU64x32 (GetTimeInNanoSecond (AsmReadTsc () - TimeStampCounterStart), 1000000)));\r
 \r
   //\r
   // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status\r
   //\r
   if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {\r
-    DEBUG((DEBUG_INFO, "FspSiliconInitApi requested reset 0x%x\n", Status));\r
-    CallFspWrapperResetSystem ((UINT32)Status);\r
+    DEBUG ((DEBUG_INFO, "FspSiliconInitApi requested reset 0x%x\n", Status));\r
+    CallFspWrapperResetSystem (Status);\r
   }\r
 \r
-  if (EFI_ERROR(Status)) {\r
+  if (EFI_ERROR (Status)) {\r
     DEBUG ((DEBUG_ERROR, "ERROR - Failed to execute FspSiliconInitApi(), Status = %r\n", Status));\r
   }\r
-  DEBUG((DEBUG_INFO, "FspSiliconInit status: 0x%x\n", Status));\r
+\r
+  DEBUG ((DEBUG_INFO, "FspSiliconInit status: 0x%x\n", Status));\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   Status = TestFspSiliconInitApiOutput ((VOID *)NULL);\r
@@ -296,26 +354,26 @@ PeiMemoryDiscoveredNotify (
   // Install FspSiliconInitDonePpi so that any other driver can consume this info.\r
   //\r
   Status = PeiServicesInstallPpi (&mPeiFspSiliconInitDonePpi);\r
-  ASSERT_EFI_ERROR(Status);\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
   return Status;\r
 }\r
 \r
 /**\r
-  Do FSP initialization.\r
+  Do FSP initialization in API mode.\r
 \r
-  @return FSP initialization status.\r
+  @retval EFI_STATUS        Always return EFI_SUCCESS\r
 **/\r
 EFI_STATUS\r
-FspsWrapperInit (\r
+FspsWrapperInitApiMode (\r
   VOID\r
   )\r
 {\r
-  EFI_STATUS           Status;\r
-  EFI_BOOT_MODE        BootMode;\r
+  EFI_STATUS     Status;\r
+  EFI_BOOT_MODE  BootMode;\r
 \r
   //\r
-  // Register MemoryDiscovered Nofity to run FspSiliconInit\r
+  // Register MemoryDiscovered Notify to run FspSiliconInit\r
   //\r
   Status = PeiServicesNotifyPpi (&mPeiMemoryDiscoveredNotifyDesc);\r
   ASSERT_EFI_ERROR (Status);\r
@@ -333,7 +391,114 @@ FspsWrapperInit (
 }\r
 \r
 /**\r
-  This is the entrypoint of PEIM\r
+  Do FSP initialization in Dispatch mode.\r
+\r
+  @retval FSP initialization status.\r
+**/\r
+EFI_STATUS\r
+FspsWrapperInitDispatchMode (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS                                             Status;\r
+  EFI_PEI_FIRMWARE_VOLUME_INFO_MEASUREMENT_EXCLUDED_PPI  *MeasurementExcludedFvPpi;\r
+  EFI_PEI_PPI_DESCRIPTOR                                 *MeasurementExcludedPpiList;\r
+\r
+  MeasurementExcludedFvPpi = AllocatePool (sizeof (*MeasurementExcludedFvPpi));\r
+  ASSERT (MeasurementExcludedFvPpi != NULL);\r
+  MeasurementExcludedFvPpi->Count          = 1;\r
+  MeasurementExcludedFvPpi->Fv[0].FvBase   = PcdGet32 (PcdFspsBaseAddress);\r
+  MeasurementExcludedFvPpi->Fv[0].FvLength = ((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdFspsBaseAddress))->FvLength;\r
+\r
+  MeasurementExcludedPpiList = AllocatePool (sizeof (*MeasurementExcludedPpiList));\r
+  ASSERT (MeasurementExcludedPpiList != NULL);\r
+  MeasurementExcludedPpiList->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;\r
+  MeasurementExcludedPpiList->Guid  = &gEfiPeiFirmwareVolumeInfoMeasurementExcludedPpiGuid;\r
+  MeasurementExcludedPpiList->Ppi   = MeasurementExcludedFvPpi;\r
+\r
+  Status = PeiServicesInstallPpi (MeasurementExcludedPpiList);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // FSP-S Wrapper running in Dispatch mode and reports FSP-S FV to PEI dispatcher.\r
+  //\r
+  PeiServicesInstallFvInfoPpi (\r
+    NULL,\r
+    (VOID *)(UINTN)PcdGet32 (PcdFspsBaseAddress),\r
+    (UINT32)((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdFspsBaseAddress))->FvLength,\r
+    NULL,\r
+    NULL\r
+    );\r
+  //\r
+  // Register EndOfPei Nofity to run post FSP-S process.\r
+  //\r
+  Status = PeiServicesNotifyPpi (&mFspsWrapperEndOfPeiNotifyDesc);\r
+  ASSERT_EFI_ERROR (Status);\r
+  return Status;\r
+}\r
+\r
+/**\r
+  This function is called after TCG installed PPI.\r
+\r
+  @param[in] PeiServices    Pointer to PEI Services Table.\r
+  @param[in] NotifyDesc     Pointer to the descriptor for the Notification event that\r
+                            caused this function to execute.\r
+  @param[in] Ppi            Pointer to the PPI data associated with this function.\r
+\r
+  @retval EFI_STATUS        Always return EFI_SUCCESS\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TcgPpiNotify (\r
+  IN EFI_PEI_SERVICES           **PeiServices,\r
+  IN EFI_PEI_NOTIFY_DESCRIPTOR  *NotifyDesc,\r
+  IN VOID                       *Ppi\r
+  );\r
+\r
+EFI_PEI_NOTIFY_DESCRIPTOR  mTcgPpiNotifyDesc = {\r
+  (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
+  &gEdkiiTcgPpiGuid,\r
+  TcgPpiNotify\r
+};\r
+\r
+/**\r
+  This function is called after TCG installed PPI.\r
+\r
+  @param[in] PeiServices    Pointer to PEI Services Table.\r
+  @param[in] NotifyDesc     Pointer to the descriptor for the Notification event that\r
+                            caused this function to execute.\r
+  @param[in] Ppi            Pointer to the PPI data associated with this function.\r
+\r
+  @retval EFI_STATUS        Always return EFI_SUCCESS\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TcgPpiNotify (\r
+  IN EFI_PEI_SERVICES           **PeiServices,\r
+  IN EFI_PEI_NOTIFY_DESCRIPTOR  *NotifyDesc,\r
+  IN VOID                       *Ppi\r
+  )\r
+{\r
+  UINT32  FspMeasureMask;\r
+\r
+  DEBUG ((DEBUG_INFO, "TcgPpiNotify FSPS\n"));\r
+\r
+  FspMeasureMask = PcdGet32 (PcdFspMeasurementConfig);\r
+\r
+  if ((FspMeasureMask & FSP_MEASURE_FSPS) != 0) {\r
+    MeasureFspFirmwareBlob (\r
+      0,\r
+      "FSPS",\r
+      PcdGet32 (PcdFspsBaseAddress),\r
+      (UINT32)((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdFspsBaseAddress))->FvLength\r
+      );\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  This is the entrypoint of PEIM.\r
 \r
   @param[in] FileHandle  Handle of the file being invoked.\r
   @param[in] PeiServices Describes the list of possible PEI Services.\r
@@ -347,9 +512,18 @@ FspsWrapperPeimEntryPoint (
   IN CONST EFI_PEI_SERVICES     **PeiServices\r
   )\r
 {\r
+  EFI_STATUS  Status;\r
+\r
   DEBUG ((DEBUG_INFO, "FspsWrapperPeimEntryPoint\n"));\r
 \r
-  FspsWrapperInit ();\r
+  Status = PeiServicesNotifyPpi (&mTcgPpiNotifyDesc);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  if (PcdGet8 (PcdFspModeSelection) == 1) {\r
+    FspsWrapperInitApiMode ();\r
+  } else {\r
+    FspsWrapperInitDispatchMode ();\r
+  }\r
 \r
   return EFI_SUCCESS;\r
 }\r