]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFspWrapperPkg/FspInitPei/FspInitPeiV1.c
Update IntelFspWrapperPkg according to FSP1.1.
[mirror_edk2.git] / IntelFspWrapperPkg / FspInitPei / FspInitPeiV1.c
diff --git a/IntelFspWrapperPkg/FspInitPei/FspInitPeiV1.c b/IntelFspWrapperPkg/FspInitPei/FspInitPeiV1.c
new file mode 100644 (file)
index 0000000..f6ffecb
--- /dev/null
@@ -0,0 +1,181 @@
+/** @file\r
+  In FSP API V1 mode, it will be invoked twice by pei core. In 1st entry, it will\r
+  call FspInit API. In 2nd entry, it will parse the hoblist from fsp and report\r
+  them into pei core.\r
+\r
+  Copyright (c) 2015, 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 "FspInitPei.h"\r
+\r
+/**\r
+  FSP Init continuation function.\r
+  Control will be returned to this callback function after FspInit API call.\r
+\r
+  @param[in] Status      Status of the FSP INIT API\r
+  @param[in] HobListPtr  Pointer to the HOB data structure defined in the PI specification.\r
+\r
+**/\r
+VOID\r
+ContinuationFunc (\r
+  IN EFI_STATUS Status,\r
+  IN VOID       *HobListPtr\r
+  )\r
+{\r
+  EFI_BOOT_MODE             BootMode;\r
+  UINT64                    StackSize;\r
+  EFI_PHYSICAL_ADDRESS      StackBase;\r
+\r
+  DEBUG ((DEBUG_INFO, "ContinuationFunc - %r\n", Status));\r
+  DEBUG ((DEBUG_INFO, "HobListPtr - 0x%x\n", HobListPtr));\r
+\r
+  if (Status != EFI_SUCCESS) {\r
+    CpuDeadLoop ();\r
+  }\r
+\r
+  //\r
+  // Can not call any PeiServices\r
+  //\r
+  BootMode = GetBootMode ();\r
+\r
+  GetStackInfo (BootMode, TRUE, &StackBase, &StackSize);\r
+  DEBUG ((DEBUG_INFO, "StackBase - 0x%x\n", StackBase));\r
+  DEBUG ((DEBUG_INFO, "StackSize - 0x%x\n", StackSize));\r
+  CallPeiCoreEntryPoint (\r
+    HobListPtr,\r
+    (VOID *)(UINTN)StackBase,\r
+    (VOID *)(UINTN)(StackBase + StackSize)\r
+    );\r
+}\r
+\r
+/**\r
+  Call FspInit API.\r
+\r
+  @param[in] FspHeader FSP header pointer.\r
+**/\r
+VOID\r
+PeiFspInit (\r
+  IN FSP_INFO_HEADER *FspHeader\r
+  )\r
+{\r
+  FSP_INIT_PARAMS           FspInitParams;\r
+  FSP_INIT_RT_COMMON_BUFFER FspRtBuffer;\r
+  UINT8                     FspUpdRgn[FixedPcdGet32 (PcdMaxUpdRegionSize)];\r
+  UINT32                    UpdRegionSize;\r
+  EFI_BOOT_MODE             BootMode;\r
+  UINT64                    StackSize;\r
+  EFI_PHYSICAL_ADDRESS      StackBase;\r
+  EFI_STATUS                Status;\r
+\r
+  DEBUG ((DEBUG_INFO, "PeiFspInit enter\n"));\r
+\r
+  PeiServicesGetBootMode (&BootMode);\r
+  DEBUG ((DEBUG_INFO, "BootMode - 0x%x\n", BootMode));\r
+\r
+  GetStackInfo (BootMode, FALSE, &StackBase, &StackSize);\r
+  DEBUG ((DEBUG_INFO, "StackBase - 0x%x\n", StackBase));\r
+  DEBUG ((DEBUG_INFO, "StackSize - 0x%x\n", StackSize));\r
+\r
+  ZeroMem (&FspRtBuffer, sizeof(FspRtBuffer));\r
+  FspRtBuffer.StackTop = (UINT32 *)(UINTN)(StackBase + StackSize);\r
+\r
+  FspRtBuffer.BootMode = BootMode;\r
+\r
+  /* Platform override any UPD configs */\r
+  UpdRegionSize = GetUpdRegionSize();\r
+  DEBUG ((DEBUG_INFO, "UpdRegionSize - 0x%x\n", UpdRegionSize));\r
+  DEBUG ((DEBUG_INFO, "sizeof(FspUpdRgn) - 0x%x\n", sizeof(FspUpdRgn)));\r
+  ASSERT(sizeof(FspUpdRgn) >= UpdRegionSize);\r
+  ZeroMem (FspUpdRgn, UpdRegionSize);\r
+  FspRtBuffer.UpdDataRgnPtr = UpdateFspUpdConfigs (FspUpdRgn);\r
+\r
+  ZeroMem (&FspInitParams, sizeof(FspInitParams));\r
+  FspInitParams.NvsBufferPtr = GetNvsBuffer ();\r
+  DEBUG ((DEBUG_INFO, "NvsBufferPtr - 0x%x\n", FspInitParams.NvsBufferPtr));\r
+  FspInitParams.RtBufferPtr  = (VOID *)&FspRtBuffer;\r
+  FspInitParams.ContinuationFunc = (CONTINUATION_PROC)ContinuationFunc;\r
+\r
+  SaveSecContext (GetPeiServicesTablePointer ());\r
+\r
+  DEBUG ((DEBUG_INFO, "FspInitParams      - 0x%x\n", &FspInitParams));\r
+  DEBUG ((DEBUG_INFO, "  NvsBufferPtr     - 0x%x\n", FspInitParams.NvsBufferPtr));\r
+  DEBUG ((DEBUG_INFO, "  RtBufferPtr      - 0x%x\n", FspInitParams.RtBufferPtr));\r
+  DEBUG ((DEBUG_INFO, "    StackTop       - 0x%x\n", FspRtBuffer.StackTop));\r
+  DEBUG ((DEBUG_INFO, "    BootMode       - 0x%x\n", FspRtBuffer.BootMode));\r
+  DEBUG ((DEBUG_INFO, "    UpdDataRgnPtr  - 0x%x\n", FspRtBuffer.UpdDataRgnPtr));\r
+  DEBUG ((DEBUG_INFO, "  ContinuationFunc - 0x%x\n", FspInitParams.ContinuationFunc));\r
+\r
+  Status = CallFspInit (FspHeader, &FspInitParams);\r
+  //\r
+  // Should never return\r
+  //\r
+  DEBUG((DEBUG_ERROR, "FSP Init failed, status: 0x%x\n", Status));\r
+  CpuDeadLoop ();\r
+}\r
+\r
+/**\r
+  Do FSP initialization based on FspApi version 1.\r
+\r
+  @param[in] FspHeader FSP header pointer.\r
+\r
+  @return FSP initialization status.\r
+**/\r
+EFI_STATUS\r
+PeiFspInitV1 (\r
+  IN FSP_INFO_HEADER *FspHeader\r
+  )\r
+{\r
+  EFI_STATUS           Status;\r
+  FSP_INIT_DONE_PPI    *FspInitDone;\r
+  VOID                 *FspHobList;\r
+  EFI_BOOT_MODE        BootMode;\r
+  \r
+  Status = PeiServicesLocatePpi (\r
+             &gFspInitDonePpiGuid,\r
+             0,\r
+             NULL,\r
+             (VOID **) &FspInitDone\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // 1st entry\r
+    //\r
+    DEBUG ((DEBUG_INFO, "1st entry\n"));\r
+\r
+    PeiFspInit (FspHeader);\r
+    //\r
+    // Never return here, for FspApi version 1.\r
+    //\r
+    CpuDeadLoop ();\r
+  } else {\r
+    //\r
+    // 2nd entry for FspApi version 1 only.\r
+    //\r
+    DEBUG ((DEBUG_INFO, "2nd entry\n"));\r
+\r
+    Status = FspInitDone->GetFspHobList (GetPeiServicesTablePointer (), FspInitDone, &FspHobList);\r
+    ASSERT_EFI_ERROR (Status);\r
+    DEBUG ((DEBUG_INFO, "FspHobList - 0x%x\n", FspHobList));\r
+    FspHobProcess (FspHobList);\r
+    \r
+    //\r
+    // Register EndOfPei Notify for S3 to run FspNotifyPhase\r
+    //\r
+    PeiServicesGetBootMode (&BootMode);\r
+    if (BootMode == BOOT_ON_S3_RESUME) {\r
+      Status = PeiServicesNotifyPpi (&mS3EndOfPeiNotifyDesc);\r
+      ASSERT_EFI_ERROR (Status);\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}
\ No newline at end of file