]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFsp2WrapperPkg/FspmWrapperPeim/FspmWrapperPeim.c
Add IntelFsp2Pkg and IntelFsp2WrapperPkg.
[mirror_edk2.git] / IntelFsp2WrapperPkg / FspmWrapperPeim / FspmWrapperPeim.c
diff --git a/IntelFsp2WrapperPkg/FspmWrapperPeim/FspmWrapperPeim.c b/IntelFsp2WrapperPkg/FspmWrapperPeim/FspmWrapperPeim.c
new file mode 100644 (file)
index 0000000..b1c605c
--- /dev/null
@@ -0,0 +1,161 @@
+/** @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
+\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/MemoryAllocationLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/TimerLib.h>\r
+#include <Library/PerformanceLib.h>\r
+#include <Library/FspWrapperPlatformLib.h>\r
+#include <Library/FspWrapperHobProcessLib.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/SecPlatformInformation.h>\r
+#include <Library/PlatformSecLib.h>\r
+#include <Library/FspWrapperApiTestLib.h>\r
+#include <FspEas.h>\r
+\r
+extern EFI_GUID gFspHobGuid;\r
+\r
+/**\r
+  Call FspMemoryInit API.\r
+\r
+  @return Status returned by FspMemoryInit API.\r
+**/\r
+EFI_STATUS\r
+PeiFspMemoryInit (\r
+  VOID\r
+  )\r
+{\r
+  FSP_INFO_HEADER           *FspmHeaderPtr;\r
+  EFI_STATUS                Status;\r
+  UINT64                    TimeStampCounterStart;\r
+  VOID                      *FspHobListPtr;\r
+  VOID                      *HobData;\r
+  FSPM_UPD_COMMON           *FspmUpdDataPtr;\r
+  UINTN                     *SourceData;\r
+\r
+  DEBUG ((DEBUG_INFO, "PeiFspMemoryInit enter\n"));\r
+\r
+  FspHobListPtr = NULL;\r
+\r
+  //\r
+  // Copy default FSP-M UPD data from Flash\r
+  //\r
+  FspmHeaderPtr = (FSP_INFO_HEADER *)FspFindFspHeader (PcdGet32 (PcdFspmBaseAddress));\r
+  FspmUpdDataPtr = (FSPM_UPD_COMMON *)AllocateZeroPool ((UINTN)FspmHeaderPtr->CfgRegionSize);\r
+  ASSERT (FspmUpdDataPtr != NULL);\r
+  SourceData = (UINTN *)((UINTN)FspmHeaderPtr->ImageBase + (UINTN)FspmHeaderPtr->CfgRegionOffset);\r
+  CopyMem (FspmUpdDataPtr, SourceData, (UINTN)FspmHeaderPtr->CfgRegionSize);\r
+\r
+  DEBUG ((DEBUG_INFO, "FspWrapperPlatformInitPreMem enter\n"));\r
+  UpdateFspmUpdData ((VOID *)FspmUpdDataPtr);\r
+  DEBUG ((DEBUG_INFO, "  NvsBufferPtr        - 0x%x\n", FspmUpdDataPtr->FspmArchUpd.NvsBufferPtr));\r
+  DEBUG ((DEBUG_INFO, "  StackBase           - 0x%x\n", FspmUpdDataPtr->FspmArchUpd.StackBase));\r
+  DEBUG ((DEBUG_INFO, "  StackSize           - 0x%x\n", FspmUpdDataPtr->FspmArchUpd.StackSize));\r
+  DEBUG ((DEBUG_INFO, "  BootLoaderTolumSize - 0x%x\n", FspmUpdDataPtr->FspmArchUpd.BootLoaderTolumSize));\r
+  DEBUG ((DEBUG_INFO, "  BootMode            - 0x%x\n", FspmUpdDataPtr->FspmArchUpd.BootMode));\r
+  DEBUG ((DEBUG_INFO, "  HobListPtr          - 0x%x\n", &FspHobListPtr));\r
+\r
+  TimeStampCounterStart = AsmReadTsc ();\r
+  Status = CallFspMemoryInit (FspmUpdDataPtr, &FspHobListPtr);\r
+  // Create hobs after memory initialization and not in temp RAM. Hence passing the recorded timestamp here\r
+  PERF_START_EX(&gFspApiPerformanceGuid, "EventRec", NULL, TimeStampCounterStart, 0xD000);\r
+  PERF_END_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, 0xD07F);\r
+  DEBUG ((DEBUG_INFO, "Total time spent executing FspMemoryInitApi: %d millisecond\n", DivU64x32 (GetTimeInNanoSecond (AsmReadTsc () - TimeStampCounterStart), 1000000)));\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG ((DEBUG_ERROR, "ERROR - Failed to execute FspMemoryInitApi(), Status = %r\n", Status));\r
+  }\r
+  DEBUG((DEBUG_INFO, "FspMemoryInit status: 0x%x\n", Status));\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+\r
+  Status = TestFspMemoryInitApiOutput (FspmUpdDataPtr, &FspHobListPtr);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((DEBUG_ERROR, "ERROR - TestFspMemoryInitApiOutput () fail, Status = %r\n", Status));\r
+  }\r
+\r
+  DEBUG ((DEBUG_INFO, "  FspHobListPtr (returned) - 0x%x\n", FspHobListPtr));\r
+  ASSERT (FspHobListPtr != NULL);\r
+\r
+  PostFspmHobProcess (FspHobListPtr);\r
+\r
+  //\r
+  // FspHobList is not complete at this moment.\r
+  // Save FspHobList pointer to hob, so that it can be got later\r
+  //\r
+  HobData = BuildGuidHob (\r
+             &gFspHobGuid,\r
+             sizeof (VOID *)\r
+             );\r
+  ASSERT (HobData != NULL);\r
+  CopyMem (HobData, &FspHobListPtr, sizeof (FspHobListPtr));\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Do FSP initialization.\r
+\r
+  @return FSP initialization status.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FspmWrapperInit (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS           Status;\r
+\r
+  Status = PeiFspMemoryInit ();\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Status;\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
+FspmWrapperPeimEntryPoint (\r
+  IN       EFI_PEI_FILE_HANDLE  FileHandle,\r
+  IN CONST EFI_PEI_SERVICES     **PeiServices\r
+  )\r
+{\r
+  DEBUG((DEBUG_INFO, "FspmWrapperPeimEntryPoint\n"));\r
+\r
+  FspmWrapperInit ();\r
+\r
+  return EFI_SUCCESS;\r
+}\r