On 02/13/21 01:58, [email protected] wrote:
> From: Michael Kubacki <[email protected]>
> 
> There's currently two library instances:
>   1. SmmCpuFeaturesLib
>   2. SmmCpuFeaturesLibStm
> 
> There's two constructor functions:
>   1. SmmCpuFeaturesLibConstructor()
>   2. SmmCpuFeaturesLibStmConstructor()
> 
> SmmCpuFeaturesLibConstructor() is called by
> SmmCpuFeaturesLibStmConstructor() since the functionality in that
> function is required by both library instances.
> 
> The declaration for SmmCpuFeaturesLibConstructor() is embedded in
> "SmmStm.c" instead of being declared in a header file. Further,
> that constructor function is called by the STM specific constructor.
> 
> This change moves the common code to a function called
> CpuFeaturesLibInitialization() which is declared in an internal
> library header file "CpuFeaturesLib.h". Each constructor simply
> calls this function to perform the common functionality.
> 
> Cc: Eric Dong <[email protected]>
> Cc: Ray Ni <[email protected]>
> Cc: Laszlo Ersek <[email protected]>
> Cc: Rahul Kumar <[email protected]>
> Signed-off-by: Michael Kubacki <[email protected]>
> ---
>  UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c      | 19 
> +++++++----------
>  UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibNoStm.c | 22 
> ++++++++++++++++++++
>  UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c                 | 21 
> ++-----------------
>  UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h         | 12 
> +++++++++++
>  4 files changed, 43 insertions(+), 31 deletions(-)
> 
> diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c 
> b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
> index 75bde752785a..e74f87f3f266 100644
> --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
> +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
> @@ -2,6 +2,7 @@
>  The CPU specific programming for PiSmmCpuDxeSmm module.
>  
>  Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) Microsoft Corporation.<BR>
>  SPDX-License-Identifier: BSD-2-Clause-Patent
>  
>  **/
> @@ -63,19 +64,15 @@ BOOLEAN  mNeedConfigureMtrrs = TRUE;
>  BOOLEAN  *mSmrrEnabled;
>  
>  /**
> -  The constructor function
> +  Performs library initialization.
>  
> -  @param[in]  ImageHandle  The firmware allocated handle for the EFI image.
> -  @param[in]  SystemTable  A pointer to the EFI System Table.
> -
> -  @retval EFI_SUCCESS      The constructor always returns EFI_SUCCESS.
> +  This initialization function contains common functionality shared betwen 
> all
> +  library instance constructors.
>  
>  **/
> -EFI_STATUS
> -EFIAPI
> -SmmCpuFeaturesLibConstructor (
> -  IN EFI_HANDLE        ImageHandle,
> -  IN EFI_SYSTEM_TABLE  *SystemTable
> +VOID
> +CpuFeaturesLibInitialization (
> +  VOID
>    )
>  {
>    UINT32  RegEax;
> @@ -162,8 +159,6 @@ SmmCpuFeaturesLibConstructor (
>    //
>    mSmrrEnabled = (BOOLEAN *)AllocatePool (sizeof (BOOLEAN) * PcdGet32 
> (PcdCpuMaxLogicalProcessorNumber));
>    ASSERT (mSmrrEnabled != NULL);
> -
> -  return EFI_SUCCESS;
>  }
>  
>  /**
> diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibNoStm.c 
> b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibNoStm.c
> index c562582ccee0..eebbbfd00a83 100644
> --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibNoStm.c
> +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibNoStm.c
> @@ -3,6 +3,7 @@ The CPU specific programming for PiSmmCpuDxeSmm module when 
> STM support
>  is not included.
>  
>  Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) Microsoft Corporation.<BR>
>  SPDX-License-Identifier: BSD-2-Clause-Patent
>  
>  **/
> @@ -82,3 +83,24 @@ SmmCpuFeaturesInstallSmiHandler (
>    )
>  {
>  }
> +
> +/**
> +  The constructor function for the library instance without STM.
> +
> +  @param[in]  ImageHandle  The firmware allocated handle for the EFI image.
> +  @param[in]  SystemTable  A pointer to the EFI System Table.
> +
> +  @retval EFI_SUCCESS      The constructor always returns EFI_SUCCESS.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +SmmCpuFeaturesLibConstructor (
> +  IN EFI_HANDLE        ImageHandle,
> +  IN EFI_SYSTEM_TABLE  *SystemTable
> +  )
> +{
> +  CpuFeaturesLibInitialization ();
> +
> +  return EFI_SUCCESS;
> +}
> diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c 
> b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
> index b5aad41fdb64..4b6bf958cedf 100644
> --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
> +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
> @@ -30,22 +30,6 @@
>  #define RDWR_ACCS             3
>  #define FULL_ACCS             7
>  
> -/**
> -  The constructor function
> -
> -  @param[in]  ImageHandle  The firmware allocated handle for the EFI image.
> -  @param[in]  SystemTable  A pointer to the EFI System Table.
> -
> -  @retval EFI_SUCCESS      The constructor always returns EFI_SUCCESS.
> -
> -**/
> -EFI_STATUS
> -EFIAPI
> -SmmCpuFeaturesLibConstructor (
> -  IN EFI_HANDLE        ImageHandle,
> -  IN EFI_SYSTEM_TABLE  *SystemTable
> -  );
> -
>  EFI_HANDLE  mStmSmmCpuHandle = NULL;
>  
>  BOOLEAN mLockLoadMonitor = FALSE;
> @@ -138,10 +122,9 @@ SmmCpuFeaturesLibStmConstructor (
>    SmmCpuFeaturesLibStmSmiEntryFixupAddress ();
>  
>    //
> -  // Call the common constructor function
> +  // Perform library initialization common across all instances
>    //
> -  Status = SmmCpuFeaturesLibConstructor (ImageHandle, SystemTable);
> -  ASSERT_EFI_ERROR (Status);
> +  CpuFeaturesLibInitialization ();
>  
>    //
>    // Lookup the MP Services Protocol
> diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h 
> b/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h
> index 4645bbb066c9..f9a758e82558 100644
> --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h
> +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h
> @@ -9,6 +9,18 @@
>  #ifndef _CPU_FEATURES_LIB_H_
>  #define _CPU_FEATURES_LIB_H_
>  
> +/**
> +  Performs library initialization.
> +
> +  This initialization function contains common functionality shared betwen 
> all
> +  library instance constructors.
> +
> +**/
> +VOID
> +CpuFeaturesLibInitialization (
> +  VOID
> +  );
> +
>  /**
>    Internal worker function that is called to complete CPU initialization at 
> the
>    end of SmmCpuFeaturesInitializeProcessor().
> 

Reviewed-by: Laszlo Ersek <[email protected]>



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#71682): https://edk2.groups.io/g/devel/message/71682
Mute This Topic: https://groups.io/mt/80599745/21656
Group Owner: [email protected]
Unsubscribe: https://edk2.groups.io/g/devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to