]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFsp2WrapperPkg/FspsWrapperPeim/FspsWrapperPeim.c
IntelFsp2WrapperPkg: Support FSP Dispatch mode
[mirror_edk2.git] / IntelFsp2WrapperPkg / FspsWrapperPeim / FspsWrapperPeim.c
index 9bc720fe2d406afa8ce4aab7a2c197b0e673ea64..69cf56838099cd555c9bc8b5e6178ce094860b57 100644 (file)
@@ -3,7 +3,7 @@
   register TemporaryRamDonePpi to call TempRamExit API, and register MemoryDiscoveredPpi\r
   notify to call FspSiliconInit API.\r
 \r
-  Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR>
   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
 #include <Ppi/MemoryDiscovered.h>\r
 #include <Ppi/TemporaryRamDone.h>\r
 #include <Ppi/SecPlatformInformation.h>\r
-#include <Library/PlatformSecLib.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
 \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
-caused this function to execute.\r
-@param[in] Ppi            Pointer to the PPI data associated with this function.\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
+  @retval EFI_STATUS        Always return EFI_SUCCESS\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -68,14 +68,14 @@ EFI_PEI_NOTIFY_DESCRIPTOR mS3EndOfPeiNotifyDesc = {
 };\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
-caused this function to execute.\r
-@param[in] Ppi            Pointer to the PPI data associated with this function.\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
+  @retval EFI_STATUS        Always return EFI_SUCCESS\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -94,25 +94,49 @@ S3EndOfPeiNotify(
   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
+  }\r
+\r
   NotifyPhaseParams.Phase = EnumInitPhaseReadyToBoot;\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
+  }\r
+\r
   NotifyPhaseParams.Phase = EnumInitPhaseEndOfFirmware;\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
+  }\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
-Return Hob list produced by FSP.\r
+  Return Hob list produced by FSP.\r
 \r
-@param[in]  PeiServices  The pointer to the PEI Services Table.\r
-@param[in]  This         The pointer to this instance of this PPI.\r
-@param[out] FspHobList   The pointer to Hob list produced by FSP.\r
+  @param[in]  PeiServices  The pointer to the PEI Services Table.\r
+  @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 FReturn Hob list produced by FSP successfully.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -133,13 +157,13 @@ EFI_PEI_PPI_DESCRIPTOR            mPeiFspSiliconInitDonePpi = {
 };\r
 \r
 /**\r
-Return Hob list produced by FSP.\r
+  Return Hob list produced by FSP.\r
 \r
-@param[in]  PeiServices  The pointer to the PEI Services Table.\r
-@param[in]  This         The pointer to this instance of this PPI.\r
-@param[out] FspHobList   The pointer to Hob list produced by FSP.\r
+  @param[in]  PeiServices  The pointer to the PEI Services Table.\r
+  @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 FReturn Hob list produced by FSP successfully.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -185,14 +209,14 @@ EFI_PEI_NOTIFY_DESCRIPTOR mPeiMemoryDiscoveredNotifyDesc = {
 };\r
 \r
 /**\r
-This function is called after PEI core discover memory and finish migration.\r
+  This function is called after PEI core discover memory and finish migration.\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
+  @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
+  @retval EFI_STATUS        Always return EFI_SUCCESS\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -210,25 +234,44 @@ PeiMemoryDiscoveredNotify (
   FSPS_UPD_COMMON           *FspsUpdDataPtr;\r
   UINTN                     *SourceData;\r
 \r
-  \r
   DEBUG ((DEBUG_INFO, "PeiMemoryDiscoveredNotify enter\n"));\r
-  \r
-  //\r
-  // Copy default FSP-S UPD data from Flash\r
-  //\r
+  FspsUpdDataPtr = NULL;\r
+\r
   FspsHeaderPtr = (FSP_INFO_HEADER *)FspFindFspHeader (PcdGet32 (PcdFspsBaseAddress));\r
-  FspsUpdDataPtr = (FSPS_UPD_COMMON *)AllocateZeroPool ((UINTN)FspsHeaderPtr->CfgRegionSize);\r
-  ASSERT (FspsUpdDataPtr != NULL);\r
-  SourceData = (UINTN *)((UINTN)FspsHeaderPtr->ImageBase + (UINTN)FspsHeaderPtr->CfgRegionOffset);\r
-  CopyMem (FspsUpdDataPtr, SourceData, (UINTN)FspsHeaderPtr->CfgRegionSize);\r
+  DEBUG ((DEBUG_INFO, "FspsHeaderPtr - 0x%x\n", FspsHeaderPtr));\r
+  if (FspsHeaderPtr == NULL) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  if (PcdGet32 (PcdFspsUpdDataAddress) == 0 && (FspsHeaderPtr->CfgRegionSize != 0) && (FspsHeaderPtr->CfgRegionOffset != 0)) {\r
+    //\r
+    // Copy default FSP-S UPD data from Flash\r
+    //\r
+    FspsUpdDataPtr = (FSPS_UPD_COMMON *)AllocateZeroPool ((UINTN)FspsHeaderPtr->CfgRegionSize);\r
+    ASSERT (FspsUpdDataPtr != NULL);\r
+    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
+    ASSERT (FspsUpdDataPtr != NULL);\r
+  }\r
 \r
   UpdateFspsUpdData ((VOID *)FspsUpdDataPtr);\r
 \r
   TimeStampCounterStart = AsmReadTsc ();\r
-  PERF_START_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, 0x9000);\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, 0x907F);\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
+  }\r
+\r
   if (EFI_ERROR(Status)) {\r
     DEBUG ((DEBUG_ERROR, "ERROR - Failed to execute FspSiliconInitApi(), Status = %r\n", Status));\r
   }\r
@@ -276,7 +319,7 @@ FspsWrapperInit (
   //\r
   Status = PeiServicesNotifyPpi (&mPeiMemoryDiscoveredNotifyDesc);\r
   ASSERT_EFI_ERROR (Status);\r
-      \r
+\r
   //\r
   // Register EndOfPei Notify for S3 to run FSP NotifyPhase\r
   //\r
@@ -304,10 +347,19 @@ FspsWrapperPeimEntryPoint (
   IN CONST EFI_PEI_SERVICES     **PeiServices\r
   )\r
 {\r
-\r
   DEBUG ((DEBUG_INFO, "FspsWrapperPeimEntryPoint\n"));\r
 \r
-  FspsWrapperInit ();\r
+  if (FixedPcdGet8 (PcdFspModeSelection) == 1) {
+    FspsWrapperInit ();
+  } else {
+    PeiServicesInstallFvInfoPpi (
+      NULL,
+      (VOID *)(UINTN) PcdGet32 (PcdFspsBaseAddress),
+      (UINT32)((EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) PcdGet32 (PcdFspsBaseAddress))->FvLength,
+      NULL,
+      NULL
+      );
+  }
 \r
   return EFI_SUCCESS;\r
 }\r