]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/SmmCpuFeaturesLib: Cleanup library constructors
authorMichael Kubacki <michael.kubacki@microsoft.com>
Wed, 17 Feb 2021 21:32:25 +0000 (13:32 -0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 8 Mar 2021 18:07:32 +0000 (18:07 +0000)
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>
Message-Id: <20210217213227.1277-4-mikuback@linux.microsoft.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h
UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c [new file with mode: 0644]
UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c
UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c

index 106e070cb8e888aa796f23a26f3942cea60893b3..c18521fd9c4eda19bcb4f7c6955d376fb4f922d5 100644 (file)
@@ -9,6 +9,18 @@
 #ifndef CPU_FEATURES_LIB_H_\r
 #define CPU_FEATURES_LIB_H_\r
 \r
+/**\r
+  Performs library initialization.\r
+\r
+  This initialization function contains common functionality shared betwen all\r
+  library instance constructors.\r
+\r
+**/\r
+VOID\r
+CpuFeaturesLibInitialization (\r
+  VOID\r
+  );\r
+\r
 /**\r
   Internal worker function that is called to complete CPU initialization at the\r
   end of SmmCpuFeaturesInitializeProcessor().\r
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
new file mode 100644 (file)
index 0000000..00948a1
--- /dev/null
@@ -0,0 +1,31 @@
+/** @file\r
+Implementation specific to the SmmCpuFeatureLib library instance.\r
+\r
+Copyright (c) Microsoft Corporation.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <PiSmm.h>\r
+#include "CpuFeaturesLib.h"\r
+\r
+/**\r
+  The constructor function for the Traditional MM library instance without STM.\r
+\r
+  @param[in]  ImageHandle  The firmware allocated handle for the EFI image.\r
+  @param[in]  SystemTable  A pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS      The constructor always returns EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmCpuFeaturesLibConstructor (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  CpuFeaturesLibInitialization ();\r
+\r
+  return EFI_SUCCESS;\r
+}\r
index 7ebb0b0ef01193ffd0c2d4ff076cd1222c713030..ddd00eeceb846275bb080a306666174f672b5f4c 100644 (file)
@@ -18,6 +18,7 @@
 \r
 [Sources]\r
   CpuFeaturesLib.h\r
+  SmmCpuFeaturesLib.c\r
   SmmCpuFeaturesLibCommon.c\r
   SmmCpuFeaturesLibNoStm.c\r
 \r
index 36c48310c31ee3d6592aa9d5a8614d14281b25db..7a919c5ee70fdf9408d09b9bbd61ea4182b80e1e 100644 (file)
@@ -2,6 +2,7 @@
 Implementation shared across all library instances.\r
 \r
 Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) Microsoft Corporation.<BR>\r
 SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
@@ -63,19 +64,15 @@ BOOLEAN  mNeedConfigureMtrrs = TRUE;
 BOOLEAN  *mSmrrEnabled;\r
 \r
 /**\r
-  The constructor function\r
+  Performs library initialization.\r
 \r
-  @param[in]  ImageHandle  The firmware allocated handle for the EFI image.\r
-  @param[in]  SystemTable  A pointer to the EFI System Table.\r
-\r
-  @retval EFI_SUCCESS      The constructor always returns EFI_SUCCESS.\r
+  This initialization function contains common functionality shared betwen all\r
+  library instance constructors.\r
 \r
 **/\r
-EFI_STATUS\r
-EFIAPI\r
-SmmCpuFeaturesLibConstructor (\r
-  IN EFI_HANDLE        ImageHandle,\r
-  IN EFI_SYSTEM_TABLE  *SystemTable\r
+VOID\r
+CpuFeaturesLibInitialization (\r
+  VOID\r
   )\r
 {\r
   UINT32  RegEax;\r
@@ -162,8 +159,6 @@ SmmCpuFeaturesLibConstructor (
   //\r
   mSmrrEnabled = (BOOLEAN *)AllocatePool (sizeof (BOOLEAN) * PcdGet32 (PcdCpuMaxLogicalProcessorNumber));\r
   ASSERT (mSmrrEnabled != NULL);\r
-\r
-  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
index b5aad41fdb6474ab69f5e1b9b5133fb0de120a12..dcc2e9f9a09a3c11ed5a747f4caa01e62d8e8fa6 100644 (file)
 #define RDWR_ACCS             3\r
 #define FULL_ACCS             7\r
 \r
-/**\r
-  The constructor function\r
-\r
-  @param[in]  ImageHandle  The firmware allocated handle for the EFI image.\r
-  @param[in]  SystemTable  A pointer to the EFI System Table.\r
-\r
-  @retval EFI_SUCCESS      The constructor always returns EFI_SUCCESS.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SmmCpuFeaturesLibConstructor (\r
-  IN EFI_HANDLE        ImageHandle,\r
-  IN EFI_SYSTEM_TABLE  *SystemTable\r
-  );\r
-\r
 EFI_HANDLE  mStmSmmCpuHandle = NULL;\r
 \r
 BOOLEAN mLockLoadMonitor = FALSE;\r
@@ -112,7 +96,7 @@ UINTN  mMsegSize = 0;
 BOOLEAN  mStmConfigurationTableInitialized = FALSE;\r
 \r
 /**\r
-  The constructor function\r
+  The constructor function for the Traditional MM library instance with STM.\r
 \r
   @param[in]  ImageHandle  The firmware allocated handle for the EFI image.\r
   @param[in]  SystemTable  A pointer to the EFI System Table.\r
@@ -138,10 +122,9 @@ SmmCpuFeaturesLibStmConstructor (
   SmmCpuFeaturesLibStmSmiEntryFixupAddress ();\r
 \r
   //\r
-  // Call the common constructor function\r
+  // Perform library initialization common across all instances\r
   //\r
-  Status = SmmCpuFeaturesLibConstructor (ImageHandle, SystemTable);\r
-  ASSERT_EFI_ERROR (Status);\r
+  CpuFeaturesLibInitialization ();\r
 \r
   //\r
   // Lookup the MP Services Protocol\r