From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web08.579.1613597602368339293 for ; Wed, 17 Feb 2021 13:33:22 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@linux.microsoft.com header.s=default header.b=S8E3eyVf; spf=pass (domain: linux.microsoft.com, ip: 13.77.154.182, mailfrom: mikuback@linux.microsoft.com) Received: from localhost.localdomain (unknown [131.107.174.202]) by linux.microsoft.com (Postfix) with ESMTPSA id 0152520B57A0; Wed, 17 Feb 2021 13:33:21 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 0152520B57A0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1613597602; bh=EGI7ewOjSnR+oggyLOiK5Ll4yb2JgbWTnNOzQk2kR4g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S8E3eyVftrVqPIZC3oNT/H9RJwfU1GZc7949XzKEUIwFsa5BUvZo7k7Xa9dL7Sv+z DQLOAseTJxhxwWvCtfAzQMg0xwhSQsgJj7pK9N4djkgeHRh5tsuXpmCepK5Vy+JE0p EUtqoRZc4E5cFY604IWki6iRVtkIXCmFcY88piGw= From: "Michael Kubacki" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Laszlo Ersek , Rahul Kumar Subject: [PATCH v3 3/5] UefiCpuPkg/SmmCpuFeaturesLib: Cleanup library constructors Date: Wed, 17 Feb 2021 13:32:25 -0800 Message-Id: <20210217213227.1277-4-mikuback@linux.microsoft.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210217213227.1277-1-mikuback@linux.microsoft.com> References: <20210217213227.1277-1-mikuback@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Kubacki 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 Cc: Ray Ni Cc: Laszlo Ersek Cc: Rahul Kumar Signed-off-by: Michael Kubacki Reviewed-by: Laszlo Ersek --- 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(-) diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c b/U= efiCpuPkg/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.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include "CpuFeaturesLib.h" + +/** + The constructor function for the Traditional MM library instance witho= ut STM. + + @param[in] ImageHandle The firmware allocated handle for the EFI ima= ge. + @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. =20 Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.
+Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -63,19 +64,15 @@ BOOLEAN mNeedConfigureMtrrs =3D TRUE; BOOLEAN *mSmrrEnabled; =20 /** - The constructor function + Performs library initialization. =20 - @param[in] ImageHandle The firmware allocated handle for the EFI ima= ge. - @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 betw= en all + library instance constructors. =20 **/ -EFI_STATUS -EFIAPI -SmmCpuFeaturesLibConstructor ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable +VOID +CpuFeaturesLibInitialization ( + VOID ) { UINT32 RegEax; @@ -162,8 +159,6 @@ SmmCpuFeaturesLibConstructor ( // mSmrrEnabled =3D (BOOLEAN *)AllocatePool (sizeof (BOOLEAN) * PcdGet32 = (PcdCpuMaxLogicalProcessorNumber)); ASSERT (mSmrrEnabled !=3D NULL); - - return EFI_SUCCESS; } =20 /** diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c b/UefiCpuPkg/L= ibrary/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 =20 -/** - The constructor function - - @param[in] ImageHandle The firmware allocated handle for the EFI ima= ge. - @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 =3D NULL; =20 BOOLEAN mLockLoadMonitor =3D FALSE; @@ -112,7 +96,7 @@ UINTN mMsegSize =3D 0; BOOLEAN mStmConfigurationTableInitialized =3D FALSE; =20 /** - The constructor function + The constructor function for the Traditional MM library instance with = STM. =20 @param[in] ImageHandle The firmware allocated handle for the EFI ima= ge. @param[in] SystemTable A pointer to the EFI System Table. @@ -138,10 +122,9 @@ SmmCpuFeaturesLibStmConstructor ( SmmCpuFeaturesLibStmSmiEntryFixupAddress (); =20 // - // Call the common constructor function + // Perform library initialization common across all instances // - Status =3D SmmCpuFeaturesLibConstructor (ImageHandle, SystemTable); - ASSERT_EFI_ERROR (Status); + CpuFeaturesLibInitialization (); =20 // // Lookup the MP Services Protocol diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h b/Uefi= CpuPkg/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_ =20 +/** + Performs library initialization. + + This initialization function contains common functionality shared betw= en 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] =20 [Sources] CpuFeaturesLib.h + SmmCpuFeaturesLib.c SmmCpuFeaturesLibCommon.c SmmCpuFeaturesLibNoStm.c =20 --=20 2.28.0.windows.1