From 41a8bba3b198c7a11692e4d9404a86f5684efebd Mon Sep 17 00:00:00 2001 From: "Chasel, Chiu" Date: Thu, 30 Nov 2017 22:37:57 +0800 Subject: edk2-platforms: Pre-allocate UPD buffer before FspWrapper Customers request to initialize/update UPD buffer outside IntelFsp2Wrapper for better code sharing and maintenance. Use MinPlatform SiliconPolicPei to initialize UPD buffer and pass to FspWrapper by PCD. A new library instance introduced to add dependency to FspWrapper to ensure dispatching ordering. Cc: Jiewen Yao Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Chasel Chiu Reviewed-by: Jiewen Yao Reviewed-by: Michael A Kubacki Reviewed-by: Amy Chan --- .../KabylakeRvp3/OpenBoardPkg.dsc | 13 +++- .../KabylakeRvp3/OpenBoardPkg.fdf | 2 + .../KabylakeRvp3/OpenBoardPkgPcd.dsc | 4 ++ .../PeiPostMemSiliconPolicyInitLibDependency.inf | 37 +++++++++++ .../PeiPreMemSiliconPolicyInitLibDependency.inf | 37 +++++++++++ .../PeiSiliconPolicyInitLibDependency.c | 48 +++++++++++++++ .../PeiFspPolicyInitLib.c | 72 +++++++++++++++++++--- .../PeiSiliconPolicyInitLibFsp.inf | 8 ++- 8 files changed, 208 insertions(+), 13 deletions(-) create mode 100644 Silicon/Intel/KabylakeSiliconPkg/Library/PeiSiliconPolicyInitLibDependency/PeiPostMemSiliconPolicyInitLibDependency.inf create mode 100644 Silicon/Intel/KabylakeSiliconPkg/Library/PeiSiliconPolicyInitLibDependency/PeiPreMemSiliconPolicyInitLibDependency.inf create mode 100644 Silicon/Intel/KabylakeSiliconPkg/Library/PeiSiliconPolicyInitLibDependency/PeiSiliconPolicyInitLibDependency.c diff --git a/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/OpenBoardPkg.dsc b/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/OpenBoardPkg.dsc index 33bcdbb251..c9411d7099 100644 --- a/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/OpenBoardPkg.dsc +++ b/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/OpenBoardPkg.dsc @@ -192,8 +192,11 @@ NULL|$(PROJECT)/Library/BoardInitLib/PeiMultiBoardInitPreMemLib.inf !endif } - IntelFsp2WrapperPkg/FspmWrapperPeim/FspmWrapperPeim.inf - + IntelFsp2WrapperPkg/FspmWrapperPeim/FspmWrapperPeim.inf { + + SiliconPolicyInitLib|$(PLATFORM_SI_PACKAGE)/Library/PeiSiliconPolicyInitLibDependency/PeiPreMemSiliconPolicyInitLibDependency.inf + } + $(PLATFORM_PACKAGE)/PlatformInit/SiliconPolicyPei/SiliconPolicyPeiPreMem.inf $(PLATFORM_PACKAGE)/PlatformInit/PlatformInitPei/PlatformInitPostMem.inf { !if gBoardModuleTokenSpaceGuid.PcdMultiBoardSupport == FALSE @@ -203,7 +206,11 @@ !endif } - IntelFsp2WrapperPkg/FspsWrapperPeim/FspsWrapperPeim.inf + IntelFsp2WrapperPkg/FspsWrapperPeim/FspsWrapperPeim.inf { + + SiliconPolicyInitLib|$(PLATFORM_SI_PACKAGE)/Library/PeiSiliconPolicyInitLibDependency/PeiPostMemSiliconPolicyInitLibDependency.inf + } + $(PLATFORM_PACKAGE)/PlatformInit/SiliconPolicyPei/SiliconPolicyPeiPostMem.inf # # Security diff --git a/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/OpenBoardPkg.fdf b/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/OpenBoardPkg.fdf index aa57e9f550..21926c746b 100644 --- a/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/OpenBoardPkg.fdf +++ b/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/OpenBoardPkg.fdf @@ -237,6 +237,7 @@ FvNameGuid = FC8FE6B5-CD9B-411E-BD8F-31824D0CDE3D INF $(PLATFORM_PACKAGE)/PlatformInit/PlatformInitPei/PlatformInitPreMem.inf INF IntelFsp2WrapperPkg/FspmWrapperPeim/FspmWrapperPeim.inf +INF $(PLATFORM_PACKAGE)/PlatformInit/SiliconPolicyPei/SiliconPolicyPeiPreMem.inf [FV.FvPostMemoryUncompact] BlockSize = $(FLASH_BLOCK_SIZE) @@ -263,6 +264,7 @@ FvNameGuid = 7C4DCFC6-AECA-4707-85B9-FD4B2EEA49E7 # Init Board Config PCD INF $(PLATFORM_PACKAGE)/PlatformInit/PlatformInitPei/PlatformInitPostMem.inf INF IntelFsp2WrapperPkg/FspsWrapperPeim/FspsWrapperPeim.inf +INF $(PLATFORM_PACKAGE)/PlatformInit/SiliconPolicyPei/SiliconPolicyPeiPostMem.inf !if gSiPkgTokenSpaceGuid.PcdPeiDisplayEnable == TRUE FILE FREEFORM = 4ad46122-ffeb-4a52-bfb0-518cfca02db0 { diff --git a/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/OpenBoardPkgPcd.dsc b/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/OpenBoardPkgPcd.dsc index cb9d288476..8040ca16be 100644 --- a/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/OpenBoardPkgPcd.dsc +++ b/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/OpenBoardPkgPcd.dsc @@ -219,6 +219,10 @@ gSiPkgTokenSpaceGuid.PcdTsegSize|0x800000 [PcdsDynamicDefault] gIntelFsp2WrapperTokenSpaceGuid.PcdFspsBaseAddress|0xFFDA0000 + # Platform will pre-allocate UPD buffer and pass it to FspWrapper + # Those dummy address will be patched before FspWrapper executing + gIntelFsp2WrapperTokenSpaceGuid.PcdFspmUpdDataAddress|0xFFFFFFFF + gIntelFsp2WrapperTokenSpaceGuid.PcdFspsUpdDataAddress|0xFFFFFFFF [PcdsDynamicDefault.common.DEFAULT] gEfiMdeModulePkgTokenSpaceGuid.PcdConOutColumn|0x0 diff --git a/Silicon/Intel/KabylakeSiliconPkg/Library/PeiSiliconPolicyInitLibDependency/PeiPostMemSiliconPolicyInitLibDependency.inf b/Silicon/Intel/KabylakeSiliconPkg/Library/PeiSiliconPolicyInitLibDependency/PeiPostMemSiliconPolicyInitLibDependency.inf new file mode 100644 index 0000000000..243a70f30d --- /dev/null +++ b/Silicon/Intel/KabylakeSiliconPkg/Library/PeiSiliconPolicyInitLibDependency/PeiPostMemSiliconPolicyInitLibDependency.inf @@ -0,0 +1,37 @@ +## @file +# Component information file for Silicon Policy Init Library +# This library implements NULL functions and the purpose is to add Silicon Policy PPI +# dependency to the PEIM. +# +# Copyright (c) 2017, Intel Corporation. All rights reserved.
+# +# This program and the accompanying materials are licensed and made available under +# the terms and conditions of the BSD License which accompanies this distribution. +# The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = PeiPostMemSiliconPolicyInitLibDependency + FILE_GUID = 22D1F7FB-9299-4BB3-A11F-D63A92DF715A + MODULE_TYPE = PEIM + VERSION_STRING = 1.0 + LIBRARY_CLASS = SiliconPolicyInitLib + +[LibraryClasses] + BaseLib + +[Packages] + MdePkg/MdePkg.dec + KabylakeSiliconPkg/SiPkg.dec + +[Sources] + PeiSiliconPolicyInitLibDependency.c + +[Depex] + gSiPolicyPpiGuid diff --git a/Silicon/Intel/KabylakeSiliconPkg/Library/PeiSiliconPolicyInitLibDependency/PeiPreMemSiliconPolicyInitLibDependency.inf b/Silicon/Intel/KabylakeSiliconPkg/Library/PeiSiliconPolicyInitLibDependency/PeiPreMemSiliconPolicyInitLibDependency.inf new file mode 100644 index 0000000000..fd54b0bf7d --- /dev/null +++ b/Silicon/Intel/KabylakeSiliconPkg/Library/PeiSiliconPolicyInitLibDependency/PeiPreMemSiliconPolicyInitLibDependency.inf @@ -0,0 +1,37 @@ +## @file +# Component information file for Silicon Policy Init Library +# This library implements NULL functions and the purpose is to add Silicon Policy PPI +# dependency to the PEIM. +# +# Copyright (c) 2017, Intel Corporation. All rights reserved.
+# +# This program and the accompanying materials are licensed and made available under +# the terms and conditions of the BSD License which accompanies this distribution. +# The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = PeiPreMemSiliconPolicyInitLibDependency + FILE_GUID = EE6573D8-2F04-4F03-A997-DC962FE770C1 + MODULE_TYPE = PEIM + VERSION_STRING = 1.0 + LIBRARY_CLASS = SiliconPolicyInitLib + +[LibraryClasses] + BaseLib + +[Packages] + MdePkg/MdePkg.dec + KabylakeSiliconPkg/SiPkg.dec + +[Sources] + PeiSiliconPolicyInitLibDependency.c + +[Depex] + gSiPreMemPolicyPpiGuid diff --git a/Silicon/Intel/KabylakeSiliconPkg/Library/PeiSiliconPolicyInitLibDependency/PeiSiliconPolicyInitLibDependency.c b/Silicon/Intel/KabylakeSiliconPkg/Library/PeiSiliconPolicyInitLibDependency/PeiSiliconPolicyInitLibDependency.c new file mode 100644 index 0000000000..1db1582ff2 --- /dev/null +++ b/Silicon/Intel/KabylakeSiliconPkg/Library/PeiSiliconPolicyInitLibDependency/PeiSiliconPolicyInitLibDependency.c @@ -0,0 +1,48 @@ +/** @file + +Copyright (c) 2017, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under +the terms and conditions of the BSD License that accompanies this distribution. +The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php. + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +VOID * +EFIAPI +SiliconPolicyInitPreMem ( + IN VOID *Policy + ) +{ + return Policy; +} + +RETURN_STATUS +EFIAPI +SiliconPolicyDonePreMem ( + IN VOID *Policy + ) +{ + return RETURN_SUCCESS; +} + +VOID * +EFIAPI +SiliconPolicyInitPostMem ( + IN VOID *Policy + ) +{ + return Policy; +} + +RETURN_STATUS +EFIAPI +SiliconPolicyDonePostMem ( + IN VOID *Policy + ) +{ + return RETURN_SUCCESS; +} \ No newline at end of file diff --git a/Silicon/Intel/KabylakeSiliconPkg/Library/PeiSiliconPolicyInitLibFsp/PeiFspPolicyInitLib.c b/Silicon/Intel/KabylakeSiliconPkg/Library/PeiSiliconPolicyInitLibFsp/PeiFspPolicyInitLib.c index d15e3f9083..4e82a0cc31 100644 --- a/Silicon/Intel/KabylakeSiliconPkg/Library/PeiSiliconPolicyInitLibFsp/PeiFspPolicyInitLib.c +++ b/Silicon/Intel/KabylakeSiliconPkg/Library/PeiSiliconPolicyInitLibFsp/PeiFspPolicyInitLib.c @@ -13,7 +13,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ #include - +#include +#include +#include /** Performs silicon pre-mem policy initialization. @@ -43,9 +45,35 @@ SiliconPolicyInitPreMem ( { FSPM_UPD *FspmUpdDataPtr; EFI_STATUS Status; - - FspmUpdDataPtr = FspmUpd; - + UINTN *SourceData; + FSP_INFO_HEADER *FspmHeaderPtr; + + if (FspmUpd == NULL) { + // + // Allocate and initialize UPD buffer, copy default FSP-M UPD data + // + FspmHeaderPtr = (FSP_INFO_HEADER *) FspFindFspHeader (PcdGet32 (PcdFspmBaseAddress)); + ASSERT (FspmHeaderPtr != NULL); + if (FspmHeaderPtr != NULL) { + DEBUG ((DEBUG_INFO, "FspmHeaderPtr - 0x%x\n", FspmHeaderPtr)); + FspmUpdDataPtr = (FSPM_UPD *) AllocateZeroPool ((UINTN) FspmHeaderPtr->CfgRegionSize); + ASSERT (FspmUpdDataPtr != NULL); + if (FspmUpdDataPtr != NULL) { + SourceData = (UINTN *) ((UINTN) FspmHeaderPtr->ImageBase + (UINTN) FspmHeaderPtr->CfgRegionOffset); + CopyMem (FspmUpdDataPtr, SourceData, (UINTN) FspmHeaderPtr->CfgRegionSize); + PcdSet32S (PcdFspmUpdDataAddress, (UINT32) FspmUpdDataPtr); + } + } + } else { + FspmUpdDataPtr = FspmUpd; + } + // + // Return NULL pointer as error occurried and do not continue rest of the steps. + // + if (FspmUpdDataPtr == NULL) { + return NULL; + } + DEBUG ((DEBUG_INFO, "FspmUpdDataPtr - 0x%x\n", FspmUpdDataPtr)); // // Initialize Intel PEI Platform Policy // @@ -97,7 +125,7 @@ SiliconPolicyInitPreMem ( // Status = PeiFspMiscUpdInitPreMem (FspmUpdDataPtr); - return FspmUpd; + return FspmUpdDataPtr; } /* @@ -148,9 +176,35 @@ SiliconPolicyInitPostMem ( { FSPS_UPD *FspsUpdDataPtr; EFI_STATUS Status; - - FspsUpdDataPtr = FspsUpd; - + FSP_INFO_HEADER *FspsHeaderPtr; + UINTN *SourceData; + + if (FspsUpd == NULL) { + // + // Allocate and initialize UPD buffer, copy default FSP-S UPD data + // + FspsHeaderPtr = (FSP_INFO_HEADER *) FspFindFspHeader (PcdGet32 (PcdFspsBaseAddress)); + ASSERT (FspsHeaderPtr != NULL); + if (FspsHeaderPtr != NULL) { + DEBUG ((DEBUG_INFO, "FspsHeaderPtr - 0x%x\n", FspsHeaderPtr)); + FspsUpdDataPtr = (FSPS_UPD *) AllocateZeroPool ((UINTN) FspsHeaderPtr->CfgRegionSize); + ASSERT (FspsUpdDataPtr != NULL); + if (FspsUpdDataPtr != NULL) { + SourceData = (UINTN *) ((UINTN) FspsHeaderPtr->ImageBase + (UINTN) FspsHeaderPtr->CfgRegionOffset); + CopyMem (FspsUpdDataPtr, SourceData, (UINTN) FspsHeaderPtr->CfgRegionSize); + PcdSet32S (PcdFspsUpdDataAddress, (UINT32) FspsUpdDataPtr); + } + } + } else { + FspsUpdDataPtr = FspsUpd; + } + // + // Return NULL pointer as error occurried and do not continue rest of the steps. + // + if (FspsUpdDataPtr == NULL) { + return NULL; + } + DEBUG ((DEBUG_INFO, "FspsUpdDataPtr - 0x%x\n", FspsUpdDataPtr)); // // Initialize Intel PEI Platform Policy // @@ -189,7 +243,7 @@ SiliconPolicyInitPostMem ( DEBUG ((DEBUG_WARN, "ERROR - CPU Pei Fsp Policy Initialization fail, Status = %r\n", Status)); } - return FspsUpd; + return FspsUpdDataPtr; } /* diff --git a/Silicon/Intel/KabylakeSiliconPkg/Library/PeiSiliconPolicyInitLibFsp/PeiSiliconPolicyInitLibFsp.inf b/Silicon/Intel/KabylakeSiliconPkg/Library/PeiSiliconPolicyInitLibFsp/PeiSiliconPolicyInitLibFsp.inf index 7b91ac3fab..7f0d7a5dec 100644 --- a/Silicon/Intel/KabylakeSiliconPkg/Library/PeiSiliconPolicyInitLibFsp/PeiSiliconPolicyInitLibFsp.inf +++ b/Silicon/Intel/KabylakeSiliconPkg/Library/PeiSiliconPolicyInitLibFsp/PeiSiliconPolicyInitLibFsp.inf @@ -62,6 +62,7 @@ MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec IntelFsp2Pkg/IntelFsp2Pkg.dec + IntelFsp2WrapperPkg/IntelFsp2WrapperPkg.dec KabylakeSiliconPkg/SiPkg.dec KabylakeFspBinPkg/KabylakeFspBinPkg.dec @@ -76,6 +77,7 @@ ConfigBlockLib MemoryAllocationLib DebugPrintErrorLevelLib + FspWrapperApiLib [Pcd] gSiPkgTokenSpaceGuid.PcdTsegSize ## CONSUMES @@ -84,7 +86,11 @@ gIntelFsp2PkgTokenSpaceGuid.PcdTemporaryRamSize ## CONSUMES gIntelFsp2PkgTokenSpaceGuid.PcdFspTemporaryRamSize ## CONSUMES gIntelFsp2PkgTokenSpaceGuid.PcdFspReservedBufferSize ## CONSUMES - + gIntelFsp2WrapperTokenSpaceGuid.PcdFspmUpdDataAddress ## CONSUMES + gIntelFsp2WrapperTokenSpaceGuid.PcdFspmBaseAddress ## CONSUMES + gIntelFsp2WrapperTokenSpaceGuid.PcdFspsUpdDataAddress ## CONSUMES + gIntelFsp2WrapperTokenSpaceGuid.PcdFspsBaseAddress ## CONSUMES + [Ppis] gSiPolicyPpiGuid ## CONSUMES gSiPreMemPolicyPpiGuid ## CONSUMES -- cgit v1.2.3