--- /dev/null
+/** @file\r
+ This PEIM will be invoked twice by pei core. In 1st entry, it will call FspInit API.\r
+ In 2nd entry, it will parse the hoblist from fsp and report them into pei core.\r
+ This file contains the main entrypoint of the PEIM.\r
+\r
+ Copyright (c) 2014, 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 FSP_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 != FSP_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
+SecFspInit (\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
+ FSP_STATUS FspStatus;\r
+\r
+ DEBUG ((DEBUG_INFO, "SecFspInit 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
+ FspStatus = CallFspInit (FspHeader, &FspInitParams);\r
+ //\r
+ // Should never return\r
+ //\r
+ DEBUG((DEBUG_ERROR, "FSP Init failed, status: 0x%x\n", FspStatus));\r
+ CpuDeadLoop ();\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
+FspPeiEntryPoint (\r
+ IN EFI_PEI_FILE_HANDLE FileHandle,\r
+ IN CONST EFI_PEI_SERVICES **PeiServices\r
+ )\r
+{\r
+ FSP_INFO_HEADER *FspHeader;\r
+ EFI_STATUS Status;\r
+ FSP_INIT_DONE_PPI *FspInitDone;\r
+ VOID *FspHobList;\r
+ EFI_BOOT_MODE BootMode;\r
+\r
+ DEBUG ((DEBUG_INFO, "FspPeiEntryPoint\n"));\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
+ FspHeader = FspFindFspHeader (PcdGet32 (PcdFlashFvFspBase));\r
+ DEBUG ((DEBUG_INFO, "FspHeader - 0x%x\n", FspHeader));\r
+ if (FspHeader == NULL) {\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+\r
+ SecFspInit (FspHeader);\r
+\r
+ //\r
+ // Never return here\r
+ //\r
+ CpuDeadLoop ();\r
+ } else {\r
+ //\r
+ // 2nd entry\r
+ //\r
+ DEBUG ((DEBUG_INFO, "2nd entry\n"));\r
+ Status = FspInitDone->GetFspHobList (PeiServices, FspInitDone, &FspHobList);\r
+ DEBUG ((DEBUG_INFO, "FspHobList - 0x%x\n", FspHobList));\r
+ FspHobProcess (FspHobList);\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
+}\r