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.web11.1029.1613177912359399418 for ; Fri, 12 Feb 2021 16:58:32 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@linux.microsoft.com header.s=default header.b=XJRX7Wkb; 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 0AAEF20B6C40; Fri, 12 Feb 2021 16:58:32 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 0AAEF20B6C40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1613177912; bh=M2Cru3gQmC4s6dW3FgKzuFJSPXmWpMiN5zOcF4FKx4E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XJRX7WkbBhs3Mi+td38Dnp8Wwe8X63GIc4sVv9a5ty9L/CzJ4Mj/1vhvjZc+87iuC Gmg3DE0fXIjI70RoebFOf9c17MTKrl82925ga6KFw3LaUDfkylf/yQHKlAgdooB84+ x8NK5LFPaC0OczppzQaUwwOonF0imfrgcsz73rPA= From: "Michael Kubacki" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Laszlo Ersek , Rahul Kumar Subject: [PATCH v2 2/4] UefiCpuPkg/SmmCpuFeaturesLib: Cleanup library constructors Date: Fri, 12 Feb 2021 16:58:04 -0800 Message-Id: <20210213005806.2927-3-mikuback@linux.microsoft.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210213005806.2927-1-mikuback@linux.microsoft.com> References: <20210213005806.2927-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. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Cc: Rahul Kumar Signed-off-by: Michael Kubacki --- 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/U= efiCpuPkg/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. =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/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 wh= en STM support is not included. =20 Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -82,3 +83,24 @@ SmmCpuFeaturesInstallSmiHandler ( ) { } + +/** + The constructor function for the library instance without 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/SmmStm.c b/UefiCpuPkg/L= ibrary/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 =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; @@ -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(). --=20 2.28.0.windows.1