From: Eric Dong Date: Thu, 26 Oct 2017 02:28:23 +0000 (+0800) Subject: UefiCpuPkg/CpuFeatures: Export HOB if CPU initialized in PEI X-Git-Tag: edk2-stable201903~3171 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=bf5a306ab5e0b1829b1d59180bc010648f09a32e UefiCpuPkg/CpuFeatures: Export HOB if CPU initialized in PEI In current implementation, CPU initialized can be done in PEI or DXE phase. PEI uses CpuFeaturesPei and Dxe uses CpuFeaturesDxe. If CPU initialized in PEI phase, CpuFeaturesDxe driver will not be used. This driver will install gEdkiiCpuFeaturesInitDoneGuid protocol after it initializes the CPU. Some drivers depend on this protocol to dispatch themselves. If CpuFeaturesDxe not been used, these drivers will not be dispatched. This patch fix the above issue. If Cpu initialized in PEI phase, it also report a guid HOB for CpuFeaturesDxe. CpuFeaturesDxe will check this HOB first. If it found this HOB, it just install gEdkiiCpuFeaturesInitDoneGuid protocol, else it will also do the CPU initialization. Cc: Ruiyu Ni Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Eric Dong Reviewed-by: Ruiyu Ni Reviewed-by: Laszlo Ersek --- diff --git a/UefiCpuPkg/CpuFeatures/CpuFeaturesDxe.c b/UefiCpuPkg/CpuFeatures/CpuFeaturesDxe.c index b0b186d36d..16c8f37fd0 100644 --- a/UefiCpuPkg/CpuFeatures/CpuFeaturesDxe.c +++ b/UefiCpuPkg/CpuFeatures/CpuFeaturesDxe.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -101,6 +102,25 @@ CpuFeaturesDxeInitialize ( ) { VOID *Registration; + EFI_STATUS Status; + EFI_HANDLE Handle; + + if (GetFirstGuidHob (&gEdkiiCpuFeaturesInitDoneGuid) != NULL) { + // + // Try to find HOB first. This HOB exist means CPU features have + // been initialized by CpuFeaturesPei driver, just install + // gEdkiiCpuFeaturesInitDoneGuid. + // + Handle = NULL; + Status = gBS->InstallProtocolInterface ( + &Handle, + &gEdkiiCpuFeaturesInitDoneGuid, + EFI_NATIVE_INTERFACE, + NULL + ); + ASSERT_EFI_ERROR (Status); + return Status; + } if (PcdGetBool (PcdCpuFeaturesInitAfterSmmRelocation)) { // diff --git a/UefiCpuPkg/CpuFeatures/CpuFeaturesDxe.inf b/UefiCpuPkg/CpuFeatures/CpuFeaturesDxe.inf index 175e8a9797..b1733bee20 100644 --- a/UefiCpuPkg/CpuFeatures/CpuFeaturesDxe.inf +++ b/UefiCpuPkg/CpuFeatures/CpuFeaturesDxe.inf @@ -33,6 +33,7 @@ UefiDriverEntryPoint UefiBootServicesTableLib RegisterCpuFeaturesLib + HobLib [Sources] CpuFeaturesDxe.c diff --git a/UefiCpuPkg/CpuFeatures/CpuFeaturesPei.c b/UefiCpuPkg/CpuFeatures/CpuFeaturesPei.c index b052d554a9..72ee19b450 100644 --- a/UefiCpuPkg/CpuFeatures/CpuFeaturesPei.c +++ b/UefiCpuPkg/CpuFeatures/CpuFeaturesPei.c @@ -18,6 +18,7 @@ #include #include #include +#include #include @@ -70,6 +71,11 @@ CpuFeaturesPeimInitialize ( Status = PeiServicesInstallPpi(&mPeiCpuFeaturesInitDonePpiDesc); ASSERT_EFI_ERROR (Status); + // + // Build HOB to let CpuFeatureDxe driver skip the initialization process. + // + BuildGuidHob (&gEdkiiCpuFeaturesInitDoneGuid, 0); + return EFI_SUCCESS; } diff --git a/UefiCpuPkg/CpuFeatures/CpuFeaturesPei.inf b/UefiCpuPkg/CpuFeatures/CpuFeaturesPei.inf index dd4b388c9a..e617c5bd5f 100644 --- a/UefiCpuPkg/CpuFeatures/CpuFeaturesPei.inf +++ b/UefiCpuPkg/CpuFeatures/CpuFeaturesPei.inf @@ -32,6 +32,7 @@ PeimEntryPoint PeiServicesLib RegisterCpuFeaturesLib + HobLib [Sources] CpuFeaturesPei.c