]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFsp2WrapperPkg/FspsWrapperPeim/FspsWrapperPeim.c
Add IntelFsp2Pkg and IntelFsp2WrapperPkg.
[mirror_edk2.git] / IntelFsp2WrapperPkg / FspsWrapperPeim / FspsWrapperPeim.c
diff --git a/IntelFsp2WrapperPkg/FspsWrapperPeim/FspsWrapperPeim.c b/IntelFsp2WrapperPkg/FspsWrapperPeim/FspsWrapperPeim.c
new file mode 100644 (file)
index 0000000..9bc720f
--- /dev/null
@@ -0,0 +1,313 @@
+/** @file\r
+  This will be invoked only once. It will call FspMemoryInit API,\r
+  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
+  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
+\r
+**/\r
+\r
+#include <PiPei.h>\r
+\r
+#include <Library/PeimEntryPoint.h>\r
+#include <Library/PeiServicesLib.h>\r
+#include <Library/PeiServicesTablePointerLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/FspWrapperPlatformLib.h>\r
+#include <Library/FspWrapperHobProcessLib.h>\r
+#include <Library/TimerLib.h>\r
+#include <Library/PerformanceLib.h>\r
+#include <Library/FspWrapperApiLib.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 <Library/PlatformSecLib.h>\r
+#include <Library/FspWrapperApiTestLib.h>\r
+#include <FspEas.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
+\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
+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_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
+\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
+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
+\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
+\r
+  NotifyPhaseParams.Phase = EnumInitPhaseReadyToBoot;\r
+  Status = CallFspNotifyPhase (&NotifyPhaseParams);\r
+  DEBUG((DEBUG_INFO, "FSP S3NotifyPhase ReadyToBoot status: 0x%x\n", Status));\r
+\r
+  NotifyPhaseParams.Phase = EnumInitPhaseEndOfFirmware;\r
+  Status = CallFspNotifyPhase (&NotifyPhaseParams);\r
+  DEBUG((DEBUG_INFO, "FSP S3NotifyPhase EndOfFirmware status: 0x%x\n", Status));\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\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
+\r
+@return EFI_SUCCESS FReturn 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
+  );\r
+\r
+FSP_SILICON_INIT_DONE_PPI mFspSiliconInitDonePpi = {\r
+  FspSiliconInitDoneGetFspHobList\r
+};\r
+\r
+EFI_PEI_PPI_DESCRIPTOR            mPeiFspSiliconInitDonePpi = {\r
+  EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,\r
+  &gFspSiliconInitDonePpiGuid,\r
+  &mFspSiliconInitDonePpi\r
+};\r
+\r
+/**\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
+\r
+@return EFI_SUCCESS FReturn 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
+  )\r
+{\r
+  EFI_HOB_GUID_TYPE                  *GuidHob;\r
+\r
+  GuidHob = GetFirstGuidHob (&gFspHobGuid);\r
+  if (GuidHob != NULL) {\r
+    *FspHobList = *(VOID **)GET_GUID_HOB_DATA(GuidHob);\r
+    return EFI_SUCCESS;\r
+  } else {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+}\r
+\r
+/**\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
+\r
+  @retval EFI_STATUS        Always return EFI_SUCCESS\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PeiMemoryDiscoveredNotify (\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_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
+  &gEfiPeiMemoryDiscoveredPpiGuid,\r
+  PeiMemoryDiscoveredNotify\r
+};\r
+\r
+/**\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
+\r
+@retval EFI_STATUS        Always return EFI_SUCCESS\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PeiMemoryDiscoveredNotify (\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
+\r
+  \r
+  DEBUG ((DEBUG_INFO, "PeiMemoryDiscoveredNotify enter\n"));\r
+  \r
+  //\r
+  // Copy default FSP-S UPD data from Flash\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
+\r
+  UpdateFspsUpdData ((VOID *)FspsUpdDataPtr);\r
+\r
+  TimeStampCounterStart = AsmReadTsc ();\r
+  PERF_START_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, 0x9000);\r
+  Status = CallFspSiliconInit ((VOID *)FspsUpdDataPtr);\r
+  PERF_END_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, 0x907F);\r
+  DEBUG ((DEBUG_INFO, "Total time spent executing FspSiliconInitApi: %d millisecond\n", DivU64x32 (GetTimeInNanoSecond (AsmReadTsc () - TimeStampCounterStart), 1000000)));\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
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = TestFspSiliconInitApiOutput ((VOID *)NULL);\r
+  if (RETURN_ERROR (Status)) {\r
+    DEBUG ((DEBUG_ERROR, "ERROR - TestFspSiliconInitApiOutput () fail, Status = %r\n", Status));\r
+  }\r
+\r
+  //\r
+  // Now FspHobList complete, process it\r
+  //\r
+  GuidHob = GetFirstGuidHob (&gFspHobGuid);\r
+  ASSERT (GuidHob != NULL);\r
+  FspHobListPtr = *(VOID **)GET_GUID_HOB_DATA (GuidHob);\r
+  DEBUG ((DEBUG_INFO, "FspHobListPtr - 0x%x\n", FspHobListPtr));\r
+  PostFspsHobProcess (FspHobListPtr);\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
+/**\r
+  Do FSP initialization.\r
+\r
+  @return FSP initialization status.\r
+**/\r
+EFI_STATUS\r
+FspsWrapperInit (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS           Status;\r
+  EFI_BOOT_MODE        BootMode;\r
+\r
+  //\r
+  // Register MemoryDiscovered Nofity to run FspSiliconInit\r
+  //\r
+  Status = PeiServicesNotifyPpi (&mPeiMemoryDiscoveredNotifyDesc);\r
+  ASSERT_EFI_ERROR (Status);\r
+      \r
+  //\r
+  // Register EndOfPei Notify for S3 to run FSP NotifyPhase\r
+  //\r
+  PeiServicesGetBootMode (&BootMode);\r
+  if (BootMode == BOOT_ON_S3_RESUME) {\r
+    Status = PeiServicesNotifyPpi (&mS3EndOfPeiNotifyDesc);\r
+    ASSERT_EFI_ERROR (Status);\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
+\r
+  @retval EFI_SUCCESS if it completed successfully.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FspsWrapperPeimEntryPoint (\r
+  IN       EFI_PEI_FILE_HANDLE  FileHandle,\r
+  IN CONST EFI_PEI_SERVICES     **PeiServices\r
+  )\r
+{\r
+\r
+  DEBUG ((DEBUG_INFO, "FspsWrapperPeimEntryPoint\n"));\r
+\r
+  FspsWrapperInit ();\r
+\r
+  return EFI_SUCCESS;\r
+}\r