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.web12.2149.1613103104208574214 for ; Thu, 11 Feb 2021 20:11:44 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@linux.microsoft.com header.s=default header.b=Z2fpQUYy; 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 965F220B6C40; Thu, 11 Feb 2021 20:11:43 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 965F220B6C40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1613103103; bh=5dACiWVnP4TCwLbj2PWM/LVQ1pQITcr+i+IQuxSfngs=; h=From:To:Cc:Subject:Date:From; b=Z2fpQUYyU21IL4kRxHDjyttDU6e+Nr6HN++MXp0QQu4us2sLp/UAOI+tJVD3PsfVn QJAyBznh9whYr2XAnpLEezyHEUG4sdq+1+eOadIRITS3BRcSn2qWe0J8Tyxym2dytj JwypagD1xXIhLTAOAcKjrPqya74vd6Y/9OWJGrp0= From: "Michael Kubacki" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Laszlo Ersek , Rahul Kumar Subject: [PATCH v1 1/1] UefiCpuPkg/SmmCpuFeaturesLib: Add Standalone MM support Date: Thu, 11 Feb 2021 20:11:24 -0800 Message-Id: <20210212041124.2029-1-mikuback@linux.microsoft.com> X-Mailer: git-send-email 2.28.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Kubacki REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3218 Adds an INF for StandaloneMmCpuFeaturesLib, which supports building the SmmCpuFeaturesLib code for Standalone MM. Minimal code changes are made to allow reuse of existing code for Standalone MM. The original INF file names are left intact (continue to use SMM terminology) to retain backward compatibility with platforms that use those INFs. Similarly, the C file names are unchanged to be consistent with the INF file names. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Cc: Rahul Kumar Signed-off-by: Michael Kubacki --- UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c = | 18 +++---- UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibNoStm.c = | 2 +- UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c = | 10 ++-- UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.c = | 50 +++++++++++++++++++ UefiCpuPkg/Library/SmmCpuFeaturesLib/TraditionalMmCpuFeaturesLib.c = | 51 ++++++++++++++++++++ UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h = | 39 +++++++++++++++ UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf = | 4 +- UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf = | 2 + UefiCpuPkg/Library/SmmCpuFeaturesLib/{SmmCpuFeaturesLib.inf =3D> Standal= oneMmCpuFeaturesLib.inf} | 16 +++--- UefiCpuPkg/UefiCpuPkg.dsc = | 1 + 10 files changed, 169 insertions(+), 24 deletions(-) diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c b/U= efiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c index 8fed18cf0e17..bb45188dbfe0 100644 --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c @@ -6,7 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ =20 -#include +#include #include #include #include @@ -15,6 +15,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include "CpuFeaturesLib.h" =20 // // Machine Specific Registers (MSRs) @@ -72,19 +73,14 @@ 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. + @retval EFI_SUCCESS This function always returns success. =20 **/ EFI_STATUS -EFIAPI -SmmCpuFeaturesLibConstructor ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable +CpuFeaturesLibInitialization ( + VOID ) { UINT32 RegEax; @@ -169,7 +165,7 @@ SmmCpuFeaturesLibConstructor ( // // Allocate array for state of SMRR enable on all CPUs // - mSmrrEnabled =3D (BOOLEAN *)AllocatePool (sizeof (BOOLEAN) * PcdGet32 = (PcdCpuMaxLogicalProcessorNumber)); + mSmrrEnabled =3D (BOOLEAN *)AllocatePool (sizeof (BOOLEAN) * GetCpuMax= LogicalProcessorNumber ()); ASSERT (mSmrrEnabled !=3D NULL); =20 return EFI_SUCCESS; diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibNoStm.= c b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibNoStm.c index 3e63c5e27f98..0bd9483e97cf 100644 --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibNoStm.c +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibNoStm.c @@ -7,7 +7,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ =20 -#include +#include #include =20 /** diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c b/UefiCpuPkg/L= ibrary/SmmCpuFeaturesLib/SmmStm.c index f7f8afacffb5..be394528bcaa 100644 --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c @@ -6,7 +6,7 @@ =20 **/ =20 -#include +#include #include #include #include @@ -30,17 +30,17 @@ #define FULL_ACCS 7 =20 /** - The constructor function + The Traditional MM library constructor. =20 @param[in] ImageHandle The firmware allocated handle for the EFI ima= ge. @param[in] SystemTable A pointer to the EFI System Table. =20 - @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. + @retval EFI_SUCCESS This constructor always returns success. =20 **/ EFI_STATUS EFIAPI -SmmCpuFeaturesLibConstructor ( +TraditionalMmCpuFeaturesLibConstructor ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ); @@ -139,7 +139,7 @@ SmmCpuFeaturesLibStmConstructor ( // // Call the common constructor function // - Status =3D SmmCpuFeaturesLibConstructor (ImageHandle, SystemTable); + Status =3D TraditionalMmCpuFeaturesLibConstructor (ImageHandle, System= Table); ASSERT_EFI_ERROR (Status); =20 // diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeatures= Lib.c b/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.c new file mode 100644 index 000000000000..ff27052a24b3 --- /dev/null +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.c @@ -0,0 +1,50 @@ +/** @file +Standalone MM CPU specific programming. + +Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.
+Copyright (c) Microsoft Corporation.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include "CpuFeaturesLib.h" + +/** + Gets the maximum number of logical processors from the PCD + PcdCpuMaxLogicalProcessorNumber. + + This access is abstracted from the PCD services to enforce + that the PCD be FixedAtBuild in the Standalone MM build of + this driver. + + @retval The value of PcdCpuMaxLogicalProcessorNumber. + +**/ +UINT32 +GetCpuMaxLogicalProcessorNumber ( + VOID + ) +{ + return FixedPcdGet32 (PcdCpuMaxLogicalProcessorNumber); +} + +/** + The Standalone MM library constructor. + + @param[in] ImageHandle Image handle of this driver. + @param[in] SystemTable A Pointer to the EFI System Table. + + @retval EFI_SUCCESS This constructor always returns success. + +**/ +EFI_STATUS +EFIAPI +StandaloneMmCpuFeaturesLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_MM_SYSTEM_TABLE *SystemTable + ) +{ + return CpuFeaturesLibInitialization (); +} diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/TraditionalMmCpuFeature= sLib.c b/UefiCpuPkg/Library/SmmCpuFeaturesLib/TraditionalMmCpuFeaturesLib= .c new file mode 100644 index 000000000000..842eed6d52b9 --- /dev/null +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/TraditionalMmCpuFeaturesLib.c @@ -0,0 +1,51 @@ +/** @file + Traditional MM CPU specific programming. + + Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) Microsoft Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include "CpuFeaturesLib.h" + +/** + Gets the maximum number of logical processors from the PCD + PcdCpuMaxLogicalProcessorNumber. + + This access is abstracted from the PCD services to enforce + that the PCD be FixedAtBuild in the Standalone MM build of + this driver. + + @retval The value of PcdCpuMaxLogicalProcessorNumber. + +**/ +UINT32 +GetCpuMaxLogicalProcessorNumber ( + VOID + ) +{ + return PcdGet32 (PcdCpuMaxLogicalProcessorNumber); +} + +/** + The Traditional MM library constructor. + + @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 This constructor always returns success. + +**/ +EFI_STATUS +EFIAPI +TraditionalMmCpuFeaturesLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + return CpuFeaturesLibInitialization (); +} + diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h b/Uefi= CpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h new file mode 100644 index 000000000000..143bd5ea3e72 --- /dev/null +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h @@ -0,0 +1,39 @@ +/** @file + Internal library function definitions. + + Copyright (c) Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef _CPU_FEATURES_LIB_H_ +#define _CPU_FEATURES_LIB_H_ + +/** + Performs library initialization. + + @retval EFI_SUCCESS This function always returns success. + +**/ +EFI_STATUS +CpuFeaturesLibInitialization ( + VOID + ); + +/** + Gets the maximum number of logical processors from the PCD + PcdCpuMaxLogicalProcessorNumber. + + This access is abstracted from the PCD services to enforce + that the PCD be FixedAtBuild in the Standalone MM build of + this driver. + + @retval The value of PcdCpuMaxLogicalProcessorNumber. + +**/ +UINT32 +GetCpuMaxLogicalProcessorNumber ( + VOID + ); + +#endif diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf b= /UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf index dd828baf69cb..6ad36f0c3c9b 100644 --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf @@ -14,9 +14,11 @@ [Defines] MODULE_TYPE =3D DXE_SMM_DRIVER VERSION_STRING =3D 1.0 LIBRARY_CLASS =3D SmmCpuFeaturesLib - CONSTRUCTOR =3D SmmCpuFeaturesLibConstructor + CONSTRUCTOR =3D TraditionalMmCpuFeaturesLibConstruc= tor =20 [Sources] + CpuFeaturesLib.h + TraditionalMmCpuFeaturesLib.c SmmCpuFeaturesLib.c SmmCpuFeaturesLibNoStm.c =20 diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.in= f b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf index 50b9cc871302..cf06751af235 100644 --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf @@ -18,6 +18,8 @@ [Defines] CONSTRUCTOR =3D SmmCpuFeaturesLibStmConstructor =20 [Sources] + CpuFeaturesLib.h + TraditionalMmCpuFeaturesLib.c SmmCpuFeaturesLib.c SmmStm.c SmmStm.h diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf b= /UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf similarity index 56% copy from UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf copy to UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.i= nf index dd828baf69cb..432db8e8fe1c 100644 --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf @@ -1,22 +1,26 @@ ## @file -# The CPU specific programming for PiSmmCpuDxeSmm module. +# Standalone MM CPU specific programming. # # Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent # ## =20 [Defines] INF_VERSION =3D 0x00010005 - BASE_NAME =3D SmmCpuFeaturesLib + BASE_NAME =3D StandaloneMmCpuFeaturesLib MODULE_UNI_FILE =3D SmmCpuFeaturesLib.uni - FILE_GUID =3D FC3DC10D-D271-422a-AFF3-CBCF7034443= 1 - MODULE_TYPE =3D DXE_SMM_DRIVER + FILE_GUID =3D BB554A2D-F5DF-41D3-8C62-46476A2B2B1= 8 + MODULE_TYPE =3D MM_STANDALONE VERSION_STRING =3D 1.0 + PI_SPECIFICATION_VERSION =3D 0x00010032 LIBRARY_CLASS =3D SmmCpuFeaturesLib - CONSTRUCTOR =3D SmmCpuFeaturesLibConstructor + CONSTRUCTOR =3D StandaloneMmCpuFeaturesLibConstruct= or =20 [Sources] + CpuFeaturesLib.h + StandaloneMmCpuFeaturesLib.c SmmCpuFeaturesLib.c SmmCpuFeaturesLibNoStm.c =20 @@ -30,5 +34,5 @@ [LibraryClasses] MemoryAllocationLib DebugLib =20 -[Pcd] +[FixedPcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber ## SO= METIMES_CONSUMES diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index 9128cef076dd..7db419471deb 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -154,6 +154,7 @@ [Components.IA32, Components.X64] UefiCpuPkg/Library/SmmCpuPlatformHookLibNull/SmmCpuPlatformHookLibNull= .inf UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf + UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.inf UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationSmm.inf --=20 2.28.0.windows.1