From c15430ce469ebbf1429ddab7bafd342b17c702d5 Mon Sep 17 00:00:00 2001 From: Hongbin1 Zhang Date: Mon, 7 Oct 2024 21:15:08 +0800 Subject: [PATCH] IntelFsp2WrapperPkg/FspiWrapperPeim : Support API mode Add fspsmm init interface for API mode. Signed-off-by: Hongbin1 Zhang Cc: Chasel Chiu Cc: Nate DeSimone Cc: Duggapu Chinni B Cc: Chen Gang C Cc: Star Zeng Cc: Ted Kuo Cc: Ashraf Ali S Cc: Ray Ni --- .../FspiWrapperPeim/FspiWrapperPeim.c | 114 +++++++++++++++++- .../FspiWrapperPeim/FspiWrapperPeim.inf | 13 ++ .../Include/Library/FspWrapperApiLib.h | 13 ++ .../Include/Library/FspWrapperApiTestLib.h | 13 ++ .../Include/Library/FspWrapperHobProcessLib.h | 13 ++ .../Include/Library/FspWrapperPlatformLib.h | 12 ++ IntelFsp2WrapperPkg/IntelFsp2WrapperPkg.dec | 4 + .../BaseFspWrapperApiLib.inf | 1 + .../BaseFspWrapperApiLib/FspWrapperApiLib.c | 36 ++++++ .../FspWrapperApiTestNull.c | 16 +++ .../FspWrapperPlatformLibSample.c | 14 +++ .../FspWrapperApiTest.c | 16 +++ .../FspWrapperHobProcessLibSample.c | 16 +++ 13 files changed, 280 insertions(+), 1 deletion(-) diff --git a/IntelFsp2WrapperPkg/FspiWrapperPeim/FspiWrapperPeim.c b/IntelFsp2WrapperPkg/FspiWrapperPeim/FspiWrapperPeim.c index ea9ffe49a62ce..63a6c78a29300 100644 --- a/IntelFsp2WrapperPkg/FspiWrapperPeim/FspiWrapperPeim.c +++ b/IntelFsp2WrapperPkg/FspiWrapperPeim/FspiWrapperPeim.c @@ -14,8 +14,116 @@ #include #include #include +#include +#include #include +#include +#include +#include +#include +#include #include +#include +#include +#include +#include + +/** + Call FspSmmInit API. + + @return Status returned by FspSmmInit API. +**/ +EFI_STATUS +FspiWrapperInitApiMode ( + VOID + ) +{ + FSP_INFO_HEADER *FspiHeaderPtr; + EFI_STATUS Status; + UINT64 TimeStampCounterStart; + EFI_HOB_GUID_TYPE *GuidHob; + VOID *FspHobListPtr; + VOID *FspiUpdDataPtr; + UINTN *SourceData; + + DEBUG ((DEBUG_INFO, "PeiFspSmmInit enter\n")); + + FspHobListPtr = NULL; + FspiUpdDataPtr = NULL; + + FspiHeaderPtr = (FSP_INFO_HEADER *)FspFindFspHeader (PcdGet32 (PcdFspiBaseAddress)); + DEBUG ((DEBUG_INFO, "FspiHeaderPtr - 0x%x\n", FspiHeaderPtr)); + if (FspiHeaderPtr == NULL) { + return EFI_DEVICE_ERROR; + } + + if ((PcdGet64 (PcdFspiUpdDataAddress64) == 0) && (FspiHeaderPtr->CfgRegionSize != 0) && (FspiHeaderPtr->CfgRegionOffset != 0)) { + // + // Copy default FSP-I UPD data from Flash + // + FspiUpdDataPtr = AllocateZeroPool ((UINTN)FspiHeaderPtr->CfgRegionSize); + ASSERT (FspiUpdDataPtr != NULL); + SourceData = (UINTN *)((UINTN)FspiHeaderPtr->ImageBase + (UINTN)FspiHeaderPtr->CfgRegionOffset); + CopyMem (FspiUpdDataPtr, SourceData, (UINTN)FspiHeaderPtr->CfgRegionSize); + } else { + // + // External UPD is ready, get the buffer from PCD pointer. + // + FspiUpdDataPtr = (VOID *)(UINTN)PcdGet64 (PcdFspiUpdDataAddress64); + ASSERT (FspiUpdDataPtr != NULL); + } + + DEBUG ((DEBUG_INFO, "UpdateFspiUpdData enter\n")); + UpdateFspiUpdData (FspiUpdDataPtr); + DEBUG ((DEBUG_INFO, " BootloaderSmmFvBaseAddress - 0x%lx\n", ((FSPI_UPD_COMMON *)FspiUpdDataPtr)->FspiArchUpd.BootloaderSmmFvBaseAddress)); + DEBUG ((DEBUG_INFO, " BootloaderSmmFvLength - 0x%lx\n", ((FSPI_UPD_COMMON *)FspiUpdDataPtr)->FspiArchUpd.BootloaderSmmFvLength)); + DEBUG ((DEBUG_INFO, " BootloaderSmmFvContextData - 0x%lx\n", ((FSPI_UPD_COMMON *)FspiUpdDataPtr)->FspiArchUpd.BootloaderSmmFvContextData)); + DEBUG ((DEBUG_INFO, " BootloaderSmmFvContextDataLength - 0x%lx\n", ((FSPI_UPD_COMMON *)FspiUpdDataPtr)->FspiArchUpd.BootloaderSmmFvContextDataLength)); + + // + // Get FspHobList + // + GuidHob = GetFirstGuidHob (&gFspHobGuid); + ASSERT (GuidHob != NULL); + FspHobListPtr = *(VOID **)GET_GUID_HOB_DATA (GuidHob); + DEBUG ((DEBUG_INFO, " HobListPtr - 0x%x\n", &FspHobListPtr)); + + TimeStampCounterStart = AsmReadTsc (); + Status = CallFspSmmInit (FspiUpdDataPtr); + + // + // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status + // + if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) { + DEBUG ((DEBUG_INFO, "FspSmmInitApi requested reset %r\n", Status)); + CallFspWrapperResetSystem (Status); + } + + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "ERROR - Failed to execute FspSmmInitApi(), Status = %r\n", Status)); + ASSERT_EFI_ERROR (Status); + } + + DEBUG ((DEBUG_INFO, "FspSmmInit status: %r\n", Status)); + // + // Create hobs after FspSmmInit. Hence passing the recorded timestamp here + // + PERF_START_EX (&gFspApiPerformanceGuid, "EventRec", NULL, TimeStampCounterStart, FSP_STATUS_CODE_FSPSMM_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY); + PERF_END_EX (&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_FSPSMM_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT); + DEBUG ((DEBUG_INFO, "Total time spent executing FspSmmInitApi: %d millisecond\n", DivU64x32 (GetTimeInNanoSecond (AsmReadTsc () - TimeStampCounterStart), 1000000))); + + Status = TestFspSmmInitApiOutput (FspiUpdDataPtr); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "ERROR - TestFspSmmInitApiOutput () fail, Status = %r\n", Status)); + } + + DEBUG ((DEBUG_INFO, " FspHobListPtr (returned) - 0x%x\n", FspHobListPtr)); + ASSERT (FspHobListPtr != NULL); + + PostFspiHobProcess (FspHobListPtr); + + return Status; +} /** Do FSP SMM initialization in Dispatch mode. @@ -88,7 +196,11 @@ FspiWrapperPeimEntryPoint ( DEBUG ((DEBUG_INFO, "FspiWrapperPeimEntryPoint\n")); - Status = FspiWrapperInitDispatchMode (); + if (PcdGet8 (PcdFspModeSelection) == 1) { + Status = FspiWrapperInitApiMode (); + } else { + Status = FspiWrapperInitDispatchMode (); + } return Status; } diff --git a/IntelFsp2WrapperPkg/FspiWrapperPeim/FspiWrapperPeim.inf b/IntelFsp2WrapperPkg/FspiWrapperPeim/FspiWrapperPeim.inf index d5b497326131e..f0291b17adb00 100644 --- a/IntelFsp2WrapperPkg/FspiWrapperPeim/FspiWrapperPeim.inf +++ b/IntelFsp2WrapperPkg/FspiWrapperPeim/FspiWrapperPeim.inf @@ -30,13 +30,22 @@ PeimEntryPoint PeiServicesLib PeiServicesTablePointerLib + BaseMemoryLib + TimerLib DebugLib + HobLib MemoryAllocationLib + FspWrapperPlatformLib + FspWrapperHobProcessLib + PerformanceLib + FspWrapperApiLib + FspWrapperApiTestLib [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec SecurityPkg/SecurityPkg.dec + IntelFsp2Pkg/IntelFsp2Pkg.dec IntelFsp2WrapperPkg/IntelFsp2WrapperPkg.dec [Ppis] @@ -44,8 +53,12 @@ [Pcd] gIntelFsp2WrapperTokenSpaceGuid.PcdFspiBaseAddress ## CONSUMES + gIntelFsp2WrapperTokenSpaceGuid.PcdFspModeSelection ## CONSUMES + gIntelFsp2WrapperTokenSpaceGuid.PcdFspiUpdDataAddress64 ## CONSUMES [Guids] + gFspHobGuid ## CONSUMES ## HOB + gFspApiPerformanceGuid ## SOMETIMES_CONSUMES ## GUID [Sources] FspiWrapperPeim.c diff --git a/IntelFsp2WrapperPkg/Include/Library/FspWrapperApiLib.h b/IntelFsp2WrapperPkg/Include/Library/FspWrapperApiLib.h index d38582d3e5919..59df1d7cd7d72 100644 --- a/IntelFsp2WrapperPkg/Include/Library/FspWrapperApiLib.h +++ b/IntelFsp2WrapperPkg/Include/Library/FspWrapperApiLib.h @@ -78,4 +78,17 @@ CallFspSiliconInit ( IN VOID *FspsUpdDataPtr ); +/** + Call FSP API - FspSmmInit. + + @param[in] FspiUpdDataPtr Pointer to the FSPI_UPD data structure. + + @return EFI status returned by FspSmmInit API. +**/ +EFI_STATUS +EFIAPI +CallFspSmmInit ( + IN VOID *FspiUpdDataPtr + ); + #endif diff --git a/IntelFsp2WrapperPkg/Include/Library/FspWrapperApiTestLib.h b/IntelFsp2WrapperPkg/Include/Library/FspWrapperApiTestLib.h index 2ff2d0cbced3b..26ad8f0dbd5bf 100644 --- a/IntelFsp2WrapperPkg/Include/Library/FspWrapperApiTestLib.h +++ b/IntelFsp2WrapperPkg/Include/Library/FspWrapperApiTestLib.h @@ -52,4 +52,17 @@ TestFspSiliconInitApiOutput ( IN VOID *FspsUpdDataPtr ); +/** + Test the output of FSP API - FspSmmInit. + + @param[in] FspiUpdDataPtr Address pointer to the Smm Init parameters structure. + + @return test result on output of FspSmmInit API. +**/ +EFI_STATUS +EFIAPI +TestFspSmmInitApiOutput ( + IN VOID *FspiUpdDataPtr + ); + #endif diff --git a/IntelFsp2WrapperPkg/Include/Library/FspWrapperHobProcessLib.h b/IntelFsp2WrapperPkg/Include/Library/FspWrapperHobProcessLib.h index c91dbb5ea2091..9ae9d67960a98 100644 --- a/IntelFsp2WrapperPkg/Include/Library/FspWrapperHobProcessLib.h +++ b/IntelFsp2WrapperPkg/Include/Library/FspWrapperHobProcessLib.h @@ -35,4 +35,17 @@ PostFspsHobProcess ( IN VOID *FspHobList ); +/** + Post FSP-I HOB process. + + @param[in] FspHobList Pointer to the HOB data structure produced by FSP. + + @return If platform process the FSP hob list successfully. +**/ +EFI_STATUS +EFIAPI +PostFspiHobProcess ( + IN VOID *FspHobList + ); + #endif diff --git a/IntelFsp2WrapperPkg/Include/Library/FspWrapperPlatformLib.h b/IntelFsp2WrapperPkg/Include/Library/FspWrapperPlatformLib.h index fe9f0d7408cd7..8e3cd64307518 100644 --- a/IntelFsp2WrapperPkg/Include/Library/FspWrapperPlatformLib.h +++ b/IntelFsp2WrapperPkg/Include/Library/FspWrapperPlatformLib.h @@ -77,4 +77,16 @@ CallFspWrapperResetSystem ( IN EFI_STATUS FspStatusResetType ); +/** + This function overrides the default configurations in the FSP-I UPD data region. + + @param[in,out] FspUpdRgnPtr A pointer to the UPD data region data structure. + +**/ +VOID +EFIAPI +UpdateFspiUpdData ( + IN OUT VOID *FspUpdRgnPtr + ); + #endif diff --git a/IntelFsp2WrapperPkg/IntelFsp2WrapperPkg.dec b/IntelFsp2WrapperPkg/IntelFsp2WrapperPkg.dec index 7649da74e81c5..a2972370d01f1 100644 --- a/IntelFsp2WrapperPkg/IntelFsp2WrapperPkg.dec +++ b/IntelFsp2WrapperPkg/IntelFsp2WrapperPkg.dec @@ -138,3 +138,7 @@ #1: measure FSP UPD region in one record (PCR1), the FSP code without UPD in another record (PCR0). # gIntelFsp2WrapperTokenSpaceGuid.PcdFspMeasurementConfig|0x00000000|UINT32|0x50000004 + # + # Non-0 means PcdFspiUpdDataAddress64 will be ignored, otherwise PcdFspiUpdDataAddress64 will be used. + # + gIntelFsp2WrapperTokenSpaceGuid.PcdFspiUpdDataAddress64|0x00000000|UINT64|0x50000005 diff --git a/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/BaseFspWrapperApiLib.inf b/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/BaseFspWrapperApiLib.inf index 1e348b539fe74..14760df0014ad 100644 --- a/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/BaseFspWrapperApiLib.inf +++ b/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/BaseFspWrapperApiLib.inf @@ -63,3 +63,4 @@ [Pcd] gIntelFsp2WrapperTokenSpaceGuid.PcdFspmBaseAddress ## CONSUMES gIntelFsp2WrapperTokenSpaceGuid.PcdFspsBaseAddress ## CONSUMES + gIntelFsp2WrapperTokenSpaceGuid.PcdFspiBaseAddress ## CONSUMES diff --git a/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/FspWrapperApiLib.c b/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/FspWrapperApiLib.c index 2e82a0c1b59ab..4d4cc8b5be629 100644 --- a/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/FspWrapperApiLib.c +++ b/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/FspWrapperApiLib.c @@ -230,3 +230,39 @@ CallFspSiliconInit ( return Status; } + +/** + Call FSP API - FspSmmInit. + + @param[in] FspiUpdDataPtr Address pointer to the Smm Init parameters structure. + + @return EFI status returned by FspSmmInit API. +**/ +EFI_STATUS +EFIAPI +CallFspSmmInit ( + IN VOID *FspiUpdDataPtr + ) +{ + FSP_INFO_HEADER *FspHeader; + FSP_SMM_INIT FspSmmInitApi; + EFI_STATUS Status; + BOOLEAN InterruptState; + + FspHeader = (FSP_INFO_HEADER *)FspFindFspHeader (PcdGet32 (PcdFspiBaseAddress)); + if (FspHeader == NULL) { + return EFI_DEVICE_ERROR; + } + + FspSmmInitApi = (FSP_SMM_INIT)((UINTN)FspHeader->ImageBase + FspHeader->FspSmmInitEntryOffset); + InterruptState = SaveAndDisableInterrupts (); + if ((FspHeader->ImageAttribute & IMAGE_ATTRIBUTE_64BIT_MODE_SUPPORT) == FSP_IA32) { + Status = Execute32BitCode ((UINTN)FspSmmInitApi, (UINTN)FspiUpdDataPtr, (UINTN)NULL); + } else { + Status = Execute64BitCode ((UINTN)FspSmmInitApi, (UINTN)FspiUpdDataPtr, (UINTN)NULL); + } + + SetInterruptState (InterruptState); + + return Status; +} diff --git a/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiTestLibNull/FspWrapperApiTestNull.c b/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiTestLibNull/FspWrapperApiTestNull.c index 4ac5d3d738fae..beaf56bd09027 100644 --- a/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiTestLibNull/FspWrapperApiTestNull.c +++ b/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiTestLibNull/FspWrapperApiTestNull.c @@ -57,3 +57,19 @@ TestFspSiliconInitApiOutput ( { return RETURN_UNSUPPORTED; } + +/** + Test the output of FSP API - FspSmmInit. + + @param[in] FspiUpdDataPtr Address pointer to the Smm Init parameters structure. + + @return test result on output of FspSmmInit API. +**/ +EFI_STATUS +EFIAPI +TestFspSmmInitApiOutput ( + IN VOID *FspiUpdDataPtr + ) +{ + return RETURN_SUCCESS; +} diff --git a/IntelFsp2WrapperPkg/Library/BaseFspWrapperPlatformLibSample/FspWrapperPlatformLibSample.c b/IntelFsp2WrapperPkg/Library/BaseFspWrapperPlatformLibSample/FspWrapperPlatformLibSample.c index 00b4799fb4932..6e0e8942ef252 100644 --- a/IntelFsp2WrapperPkg/Library/BaseFspWrapperPlatformLibSample/FspWrapperPlatformLibSample.c +++ b/IntelFsp2WrapperPkg/Library/BaseFspWrapperPlatformLibSample/FspWrapperPlatformLibSample.c @@ -95,3 +95,17 @@ CallFspWrapperResetSystem ( CpuDeadLoop (); } + +/** + This function overrides the default configurations in the FSP-I UPD data region. + + @param[in,out] FspUpdRgnPtr A pointer to the UPD data region data structure. + +**/ +VOID +EFIAPI +UpdateFspiUpdData ( + IN OUT VOID *FspUpdRgnPtr + ) +{ +} diff --git a/IntelFsp2WrapperPkg/Library/PeiFspWrapperApiTestLib/FspWrapperApiTest.c b/IntelFsp2WrapperPkg/Library/PeiFspWrapperApiTestLib/FspWrapperApiTest.c index 0b48677b77a16..24722ea2875fa 100644 --- a/IntelFsp2WrapperPkg/Library/PeiFspWrapperApiTestLib/FspWrapperApiTest.c +++ b/IntelFsp2WrapperPkg/Library/PeiFspWrapperApiTestLib/FspWrapperApiTest.c @@ -83,3 +83,19 @@ TestFspSiliconInitApiOutput ( { return RETURN_SUCCESS; } + +/** + Test the output of FSP API - FspSmmInit. + + @param[in] FspiUpdDataPtr Address pointer to the Smm Init parameters structure. + + @return test result on output of FspSmmInit API. +**/ +EFI_STATUS +EFIAPI +TestFspSmmInitApiOutput ( + IN VOID *FspiUpdDataPtr + ) +{ + return RETURN_SUCCESS; +} diff --git a/IntelFsp2WrapperPkg/Library/PeiFspWrapperHobProcessLibSample/FspWrapperHobProcessLibSample.c b/IntelFsp2WrapperPkg/Library/PeiFspWrapperHobProcessLibSample/FspWrapperHobProcessLibSample.c index 84360ac6e3a95..c11df5894c02e 100644 --- a/IntelFsp2WrapperPkg/Library/PeiFspWrapperHobProcessLibSample/FspWrapperHobProcessLibSample.c +++ b/IntelFsp2WrapperPkg/Library/PeiFspWrapperHobProcessLibSample/FspWrapperHobProcessLibSample.c @@ -400,3 +400,19 @@ PostFspsHobProcess ( return EFI_SUCCESS; } + +/** + Post FSP-I HOB process. + + @param[in] FspHobList Pointer to the HOB data structure produced by FSP. + + @return If platform process the FSP hob list successfully. +**/ +EFI_STATUS +EFIAPI +PostFspiHobProcess ( + IN VOID *FspHobList + ) +{ + return EFI_SUCCESS; +}