public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Laszlo Ersek" <lersek@redhat.com>
To: mikuback@linux.microsoft.com, devel@edk2.groups.io
Cc: Eric Dong <eric.dong@intel.com>, Ray Ni <ray.ni@intel.com>,
	Rahul Kumar <rahul1.kumar@intel.com>
Subject: Re: [PATCH v3 3/5] UefiCpuPkg/SmmCpuFeaturesLib: Cleanup library constructors
Date: Fri, 19 Feb 2021 21:39:21 +0100	[thread overview]
Message-ID: <7c653d91-5669-71f9-4899-598a19424567@redhat.com> (raw)
In-Reply-To: <20210217213227.1277-4-mikuback@linux.microsoft.com>

On 02/17/21 22:32, mikuback@linux.microsoft.com wrote:
> From: Michael Kubacki <michael.kubacki@microsoft.com>
> 
> 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.
> 
> Additionally, SmmCpuFeaturesLibConstructor() is moved from
> SmmCpuFeaturesLibNoStm.c into a instance-specific file allowing
> SmmCpuFeaturesLibNoStm.c to contain no STM implementation agnostic
> to a particular library instance.
> 
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Rahul Kumar <rahul1.kumar@intel.com>
> Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
> ---
>  UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c       | 31 ++++++++++++++++++++
>  UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c | 19 +++++-------
>  UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c                  | 23 ++-------------
>  UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h          | 12 ++++++++
>  UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf     |  1 +
>  5 files changed, 54 insertions(+), 32 deletions(-)

The update looks OK, thanks.
Laszlo

> 
> diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
> new file mode 100644
> index 000000000000..00948a191fad
> --- /dev/null
> +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
> @@ -0,0 +1,31 @@
> +/** @file
> +Implementation specific to the SmmCpuFeatureLib library instance.
> +
> +Copyright (c) Microsoft Corporation.<BR>
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiSmm.h>
> +#include "CpuFeaturesLib.h"
> +
> +/**
> +  The constructor function for the Traditional MM 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/SmmCpuFeaturesLibCommon.c b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c
> index 36c48310c31e..7a919c5ee70f 100644
> --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c
> +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c
> @@ -2,6 +2,7 @@
>  Implementation shared across all library instances.
>  
>  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/SmmStm.c b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
> index b5aad41fdb64..dcc2e9f9a09a 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;
> @@ -112,7 +96,7 @@ UINTN  mMsegSize = 0;
>  BOOLEAN  mStmConfigurationTableInitialized = FALSE;
>  
>  /**
> -  The constructor function
> +  The constructor function for the Traditional MM library instance with STM.
>  
>    @param[in]  ImageHandle  The firmware allocated handle for the EFI image.
>    @param[in]  SystemTable  A pointer to the EFI System Table.
> @@ -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().
> diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
> index 7ebb0b0ef011..ddd00eeceb84 100644
> --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
> +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
> @@ -18,6 +18,7 @@ [Defines]
>  
>  [Sources]
>    CpuFeaturesLib.h
> +  SmmCpuFeaturesLib.c
>    SmmCpuFeaturesLibCommon.c
>    SmmCpuFeaturesLibNoStm.c
>  
> 


  reply	other threads:[~2021-02-19 20:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-17 21:32 [PATCH v3 0/5] UefiCpuPkg/StandaloneMmCpuFeaturesLib: Add Standalone MM support Michael Kubacki
2021-02-17 21:32 ` [PATCH v3 1/5] UefiCpuPkg/SmmCpuFeaturesLib: Move multi-instance function decl to header Michael Kubacki
2021-02-17 21:32 ` [PATCH v3 2/5] UefiCpuPkg/SmmCpuFeaturesLib: Rename SmmCpuFeaturesLib.c Michael Kubacki
2021-02-19 20:31   ` Laszlo Ersek
2021-02-17 21:32 ` [PATCH v3 3/5] UefiCpuPkg/SmmCpuFeaturesLib: Cleanup library constructors Michael Kubacki
2021-02-19 20:39   ` Laszlo Ersek [this message]
2021-02-17 21:32 ` [PATCH v3 4/5] UefiCpuPkg/SmmCpuFeaturesLib: Abstract PcdCpuMaxLogicalProcessorNumber Michael Kubacki
2021-02-19 20:43   ` Laszlo Ersek
2021-02-17 21:32 ` [PATCH v3 5/5] UefiCpuPkg/SmmCpuFeaturesLib: Add Standalone MM support Michael Kubacki
2021-02-19 20:43   ` Laszlo Ersek
2021-03-05 14:39 ` [edk2-devel] [PATCH v3 0/5] UefiCpuPkg/StandaloneMmCpuFeaturesLib: " Laszlo Ersek
2021-03-08  1:45 ` Dong, Eric
2021-03-08 18:16 ` Laszlo Ersek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7c653d91-5669-71f9-4899-598a19424567@redhat.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox