From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com [40.107.237.76]) by mx.groups.io with SMTP id smtpd.web10.42222.1682753612856472691 for ; Sat, 29 Apr 2023 00:33:33 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=r0zYgNm6; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: 40.107.237.76, mailfrom: abner.chang@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f1u1+K6wNkN2En9sSAe14kEHoSrpLs6mcU+vN0l9INaunp5dQinqCmCP41LQoR0fEUNGsGqLdDOEh+Z09MVpQCbMY8yXOujWrT49FrRbB1qNueDd4HlHF3OGucGDQ/EndTHVTIK3iI3h2VuIBbNYbHRAxa/nWgcOUHW9F/Z0MPC/ZOuMOSg2Gd57CsIJSlD49ODg+LV70sugvMnueKayVvYJWrFYzcy1zNdxuHIdhCxngwq4YhpNe4D3wHCLdwlDhuI+YEOrwrridyR1ZMTvhyi90gEsX0nXHT3szbIlcaaRk3bEt2v0x37QQ0Fi93YBNeo7a3NQutJHBYFzIaI71g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=l+DrZG4SvTpLn1yE1WlLESxW1uujf71a32c4bIlfBpA=; b=ibf5qP/lukExzyHaa4r80KNWLdmY32rSrwhT391n+e94TiBuof4KpfhI1feHhBOFoCOC70GuJ6G2fh9Jx3mc7wKIO2gWU5bKEgsamydqPnzddEJvrKGg+G3mZCt/s5iW5gQopkZnLZl64A7umyA/7dSwNvl5/Xu3oC40cfey+VV3wuMNbm9Nqs934wXz+01MoWPKK5IbzmBJvYOFUDvb4df+FbZC56CDgwsa2RE5F7Nz0Dpaas6v1TDdasj+wv8yt2V9bDgHJiSoFMgB6MrsxmMEy5IZEGbxZReIT6juN1cRqgd+W+PdfYWYySi3+iQ0mQBJagDBLRtmE5f93+A+xg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=l+DrZG4SvTpLn1yE1WlLESxW1uujf71a32c4bIlfBpA=; b=r0zYgNm65/xevdNcnUMGUvufVO3vdvUdNm1v2c+4A5BsXvQ4TFvrGJEd+vF2SrWlBooV1DoEgHwKoAyG1KuezMgNLP+h5QxVMjZcCpl5chzoGSQD9MnKQXYRdcWYjLh6DsJw2XYC3rtTag9/A8Bh3nFIIKCis57kWqOlBHh0mAQ= Received: from MN2PR12MB3966.namprd12.prod.outlook.com (2603:10b6:208:165::18) by DS7PR12MB5957.namprd12.prod.outlook.com (2603:10b6:8:7c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.24; Sat, 29 Apr 2023 07:33:28 +0000 Received: from MN2PR12MB3966.namprd12.prod.outlook.com ([fe80::46f1:bdce:a4bc:29e3]) by MN2PR12MB3966.namprd12.prod.outlook.com ([fe80::46f1:bdce:a4bc:29e3%3]) with mapi id 15.20.6340.022; Sat, 29 Apr 2023 07:33:28 +0000 From: "Chang, Abner" To: "Attar, AbdulLateef (Abdul Lateef)" , "devel@edk2.groups.io" CC: "Attar, AbdulLateef (Abdul Lateef)" , "Grimes, Paul" , Garrett Kirkendall , Eric Dong , Ray Ni , Rahul Kumar , "Attar, AbdulLateef (Abdul Lateef)" Subject: Re: [PATCH v9 5/9] UefiCpuPkg: Implements SmmCpuFeaturesLib for AMD Family Thread-Topic: [PATCH v9 5/9] UefiCpuPkg: Implements SmmCpuFeaturesLib for AMD Family Thread-Index: AQHZeA/wtZ2QV0VZl0ScHnJVpRSPNK9B6TAg Date: Sat, 29 Apr 2023 07:33:28 +0000 Message-ID: References: <27c7939014dac7d22d0909d3b9cff61b23d87373.1682493282.git.abdattar@amd.com> In-Reply-To: <27c7939014dac7d22d0909d3b9cff61b23d87373.1682493282.git.abdattar@amd.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_Enabled=true; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_SetDate=2023-04-29T07:33:25Z; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_Method=Standard; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_Name=General; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_SiteId=3dd8961f-e488-4e60-8e11-a82d994e183d; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_ActionId=4e754946-8071-4fed-9765-a4e37dbad03a; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_ContentBits=1 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MN2PR12MB3966:EE_|DS7PR12MB5957:EE_ x-ms-office365-filtering-correlation-id: cd8ba9b8-98dd-4f49-c72c-08db48840691 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: meVTze4TqtpMgGjnPSUdwkGXKA9B2IWJyjqrp0e7dcC9UTHwaP4ME7bChll9HFDD7iUm0YnwqVhwwQFA9rBTiouf2iLEaGBfAvnlJ2wHE/zhtsnYczY/PVoQsE4piAGpPdxWGXC2HnRiVnw10x+xHzeyggmtpttYqgBVG8PGXd7XdY1+ElJIQoIUDKSaeST+yDUKE6J3rR95d2DkEYywB7uUFYdQzCQTwz0RhzYbn+sI1dL9Vmia+z69SqRDtXCrbl+i5uUElhJZ2DQ6TRHcHdctP3/uEHXeYNtGcERHUVWN1gFEUGA+/VAduO2GlGgtaqK89oEpEl7xdVxIawrnscHcqbeRHvNjdhJuTrHGsdsFF7qlTy/nyflzwZL+J03ij6149uaYfhmrd2mBH8/Ky5xv5GDduRFrOqfHqYZlRR4u+mRcQ0n9E+8b4giSENXr72buoLt4L9UgvNok+NDzLzOoxIVyqiPoyv7av5EahndsDptcfmhDvMBQFIOwH6Rs6UctJOcfKzZt0NEM70IuDc6dRd4Jy9uqEi68Xm88q8ztdO+8+NWJreN0iGJo9JuMbeuQ12/Xqa4mx6zUCT0z+sYyaS/7hxzOTW8ChlZpNzE= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR12MB3966.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(136003)(376002)(346002)(366004)(39860400002)(396003)(451199021)(5660300002)(38100700002)(45080400002)(54906003)(86362001)(478600001)(19627235002)(110136005)(83380400001)(8676002)(8936002)(52536014)(2906002)(30864003)(33656002)(71200400001)(7696005)(66476007)(66556008)(66946007)(76116006)(316002)(6506007)(26005)(9686003)(53546011)(122000001)(66446008)(4326008)(64756008)(41300700001)(186003)(38070700005)(966005)(55016003)(579004);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?spoBVjwJJMq0OU6x6YN9Skyv9Kb/X/frNxe/FGoZr3BwxPJmqN0Ol3Bg9T1H?= =?us-ascii?Q?PxbSTuymQN0zUwP0TngUmTXf8kQKfkJUL7KisIiNJfr+c81XWCsm/IZyWLyw?= =?us-ascii?Q?ZROnPXv1gaEo7Y08MmqKgwYt7+fRtqMiDzytaGXbTVveDvb8LIFmvHoBIHq/?= =?us-ascii?Q?4uAye/7TCYeqch6jYqn76P5MkVrh5RGjlltTb5LsTi63xv6ELpT+TZ6BErrA?= =?us-ascii?Q?ZNJyJ6SZgSiXw18WLmCiGRWcMGGdWgNlcYbV2+IpNgaLg6ukiKZ0BYA9FUeQ?= =?us-ascii?Q?nn460wT9XLFlgQL/394MQWL3QfyYSzBg530tfljC1jYxMjY5+litQXlJwAYf?= =?us-ascii?Q?yYblqW9Urm2NfWu9m+UQKOOEBxEQPkSnrAlyvM7t/jQhY4oZQeN1rfRjOShX?= =?us-ascii?Q?BMnw677vZiaOelQ2Gm8iAjJ5S0FZl5i90anEhNAHWJYrd4wX/JVxO+LmQh57?= =?us-ascii?Q?Koz6otqUcHUC25AwTlPVmAfHyDdol4+pERyXejfsle7M5z2zW3g3PV6ajfwz?= =?us-ascii?Q?7Van6iFVcU4syPaYcgv4evBpghol5/ax58M6iYOvbR70gVGa0AvM0NLZbDAX?= =?us-ascii?Q?C/lWTy68vkq6PToyPuX8jtJS2v0bAk99APvUqSnx/bq1prg1iu7MYqqM+k/X?= =?us-ascii?Q?a6YQ8jyeJOx9G/EBpePfr8r25baVUHnjnq/MZtRw/wLyBBJ++hwPE/XEdf4U?= =?us-ascii?Q?JupTwDMI4n5xIsZ9vQi8arrP+3y63FXMl1Ordk17LuFLxYDSnMUnnkDjBPIB?= =?us-ascii?Q?yRF5LvnGyrCAVc6VNQ6pXYft39Q2Mlqtb6Pv0bMHCV3jdF52spl3vbbniuEw?= =?us-ascii?Q?gncnTWXo0EtxG0/0uN4NsTgMdV9+4FJUgtWoOHIbojvcNe5spt8/Ua34eU4C?= =?us-ascii?Q?AR+O/BkTgODhjCn+8K2GrwwIwFgGhqxsJha6kJBnr3BWqCBkzK9hiaiOY0KV?= =?us-ascii?Q?w5K/kDcq62e30CAjfLYXCE2Guua3KyY7nb+VrOVTIOMeXxv5lEjCCxVxASLn?= =?us-ascii?Q?I3uozn85hfe4eF2NGiss70o2QuHkf69zbg7lKFaP7mbIDS72ssex0LpzmnbX?= =?us-ascii?Q?hdZayltbxFYPtN54MkBpCKUQEc4Usa0cZ/qrmElihb1/l8YN/dZBQVIRRilC?= =?us-ascii?Q?n1+DcwKvlt45ZG9cH4hWRG1BWPUsudo3I/F4tUu9uQ66+RfcRw29b5akqcKj?= =?us-ascii?Q?mxllSIz9Eje0VGtFqUQugBSoyiNg0gNdy2P/40f2Sv+3bNUuslcFF8+BIKui?= =?us-ascii?Q?y4tHQJo49HL8z+trPn4GRGJA8KHg2wmXFQ9cb2Cst4A1/OxpNADZQSlAqQrX?= =?us-ascii?Q?Jv3571DIYCSPosh/8ZEnermev3E5ICu3TZ2dA5TITouTUxVkErbK3eHquVQL?= =?us-ascii?Q?WYciAWxC1h6VrFVXBN5Tc8z8S5jHN+kW9qKNbh/x2o3+DQZYFREe6p9f9+8k?= =?us-ascii?Q?9VgfFhF7qDV/CzCcB+MLDwVoW1HORXeZAA282xdkrD6fna7NQ3lkvKoZ49Of?= =?us-ascii?Q?oeZMhPlFx071Ti+ptyfSwm74ljRQfQgBJbCu6I62M6of5mWQ0R7nrNoDlKY4?= =?us-ascii?Q?Fe/+/6l2Q2M8uht0OuY=3D?= MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB3966.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: cd8ba9b8-98dd-4f49-c72c-08db48840691 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Apr 2023 07:33:28.5594 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: IrvGCyBg1Nkp2m5KYaU3ud1IciAW2aVHlxevTx6DkVpOx9qvyxVPeJTfCh7aV5fAeiLN2EBvg8LsZbr+eb89+A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5957 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable [AMD Official Use Only - General] Hi Abdul, > -----Original Message----- > From: Abdul Lateef Attar > Sent: Wednesday, April 26, 2023 3:22 PM > To: devel@edk2.groups.io > Cc: Attar, AbdulLateef (Abdul Lateef) ; > Grimes, Paul ; Garrett Kirkendall > ; Chang, Abner ; > Eric Dong ; Ray Ni ; Rahul Kumar > ; Attar, AbdulLateef (Abdul Lateef) > > Subject: [PATCH v9 5/9] UefiCpuPkg: Implements SmmCpuFeaturesLib for > AMD Family >=20 > From: Abdul Lateef Attar >=20 > BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4182 >=20 > Implements interfaces to read and write save state registers of AMD's > processor family. > Initializes processor SMMADDR and MASK depends on PcdSmrrEnable flag. > Program or corrects the IP once control returns from SMM. >=20 > Cc: Paul Grimes > Cc: Garrett Kirkendall > Cc: Abner Chang > Cc: Eric Dong > Cc: Ray Ni > Cc: Rahul Kumar > Signed-off-by: Abdul Lateef Attar > --- > UefiCpuPkg/UefiCpuPkg.dsc | 8 + > .../AmdSmmCpuFeaturesLib.inf | 38 ++ > .../SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.c | 445 > ++++++++++++++++++ > 3 files changed, 491 insertions(+) > create mode 100644 > UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf > create mode 100644 > UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.c >=20 > diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index > 8b0cb02a80e8..61c4a0221d42 100644 > --- a/UefiCpuPkg/UefiCpuPkg.dsc > +++ b/UefiCpuPkg/UefiCpuPkg.dsc > @@ -169,6 +169,13 @@ [Components.IA32, Components.X64] > >=20 > SmmCpuFeaturesLib|UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFea > turesLibStm.inf > } > + UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf { > + > + FILE_GUID =3D B7242C74-BD21-49EE-84B4-07162E8C080D > + > + > SmmCpuFeaturesLib|UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCp > uFeaturesLib.inf > + > + > SmmCpuPlatformHookLib|UefiCpuPkg/Library/SmmCpuPlatformHookLibNull Why do we need SmmCpuPlatformHookLib? I don't see any invokes to the functi= ons in SmmCpuPlatformHookLib. Did I miss something? If we do need SmmCpuPlatformHookLib, could we have this instance in AmdSmmC= puFeaturesLib.inf? Thanks Abner > /Smm > + CpuPlatformHookLibNull.inf > + } > UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf > UefiCpuPkg/ResetVector/Vtf0/Bin/ResetVector.inf > UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf > @@ -185,6 +192,7 @@ [Components.IA32, Components.X64] >=20 > UnitTestResultReportLib|UnitTestFrameworkPkg/Library/UnitTestResultRep > ortLib/UnitTestResultReportLibConOut.inf > } > UefiCpuPkg/Library/MmSaveStateLib/AmdMmSaveStateLib.inf > + UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf >=20 > [Components.X64] >=20 > UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHan > dlerLibUnitTest.inf > diff --git > a/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf > b/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf > new file mode 100644 > index 000000000000..fcf6514443d1 > --- /dev/null > +++ > b/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf > @@ -0,0 +1,38 @@ > +## @file > +# The CPU specific programming for PiSmmCpuDxeSmm module. > +# > +# Copyright (c) 2009 - 2016, Intel Corporation. All rights > +reserved.
# Copyright (C) 2023 Advanced Micro Devices, Inc. All > +rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # > +## > + > +[Defines] > + INF_VERSION =3D 0x00010005 > + BASE_NAME =3D SmmCpuFeaturesLib > + MODULE_UNI_FILE =3D SmmCpuFeaturesLib.uni > + FILE_GUID =3D 5849E964-78EC-428E-8CBD-848A7E35913= 4 > + MODULE_TYPE =3D DXE_SMM_DRIVER > + VERSION_STRING =3D 1.0 > + LIBRARY_CLASS =3D SmmCpuFeaturesLib > + CONSTRUCTOR =3D SmmCpuFeaturesLibConstructor > + > +[Sources] > + SmmCpuFeaturesLib.c > + SmmCpuFeaturesLibCommon.c > + AmdSmmCpuFeaturesLib.c > + > +[Packages] > + MdePkg/MdePkg.dec > + UefiCpuPkg/UefiCpuPkg.dec > + > +[LibraryClasses] > + BaseLib > + PcdLib > + MemoryAllocationLib > + DebugLib > + MmSaveStateLib > + > +[FeaturePcd] > + gUefiCpuPkgTokenSpaceGuid.PcdSmrrEnable ## CONSUMES > + gUefiCpuPkgTokenSpaceGuid.PcdSmmFeatureControlEnable ## > CONSUMES > diff --git > a/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.c > b/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.c > new file mode 100644 > index 000000000000..1473f0a51fe2 > --- /dev/null > +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.c > @@ -0,0 +1,445 @@ > +/** @file > +Implementation specific to the SmmCpuFeatureLib library instance for > +AMD based platforms. > + > +Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.
> +Copyright (c) Microsoft Corporation.
Copyright (C) 2023 Advanced > +Micro Devices, Inc. All rights reserved.
> +SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +// EFER register LMA bit > +#define LMA BIT10 > + > +// Machine Specific Registers (MSRs) > +#define SMMADDR_ADDRESS 0xC0010112ul > +#define SMMMASK_ADDRESS 0xC0010113ul > +#define EFER_ADDRESS 0XC0000080ul > + > +// The mode of the CPU at the time an SMI occurs STATIC UINT8 > +mSmmSaveStateRegisterLma; > + > +/** > + Read an SMM Save State register on the target processor. If this > +function > + returns EFI_UNSUPPORTED, then the caller is responsible for reading > +the > + SMM Save Sate register. > + > + @param[in] CpuIndex The index of the CPU to read the SMM Save State. > The > + value must be between 0 and the NumberOfCpus fie= ld in > + the System Management System Table (SMST). > + @param[in] Register The SMM Save State register to read. > + @param[in] Width The number of bytes to read from the CPU save > state. > + @param[out] Buffer Upon return, this holds the CPU register value r= ead > + from the save state. > + > + @retval EFI_SUCCESS The register was read from Save State. > + @retval EFI_INVALID_PARAMTER Buffer is NULL. > + @retval EFI_UNSUPPORTED This function does not support reading > Register. > + > +**/ > +EFI_STATUS > +EFIAPI > +SmmCpuFeaturesReadSaveStateRegister ( > + IN UINTN CpuIndex, > + IN EFI_SMM_SAVE_STATE_REGISTER Register, > + IN UINTN Width, > + OUT VOID *Buffer > + ) > +{ > + return MmSaveStateReadRegister (CpuIndex, Register, Width, Buffer); } > + > +/** > + Writes an SMM Save State register on the target processor. If this > +function > + returns EFI_UNSUPPORTED, then the caller is responsible for writing > +the > + SMM Save Sate register. > + > + @param[in] CpuIndex The index of the CPU to write the SMM Save State. > The > + value must be between 0 and the NumberOfCpus fiel= d in > + the System Management System Table (SMST). > + @param[in] Register The SMM Save State register to write. > + @param[in] Width The number of bytes to write to the CPU save stat= e. > + @param[in] Buffer Upon entry, this holds the new CPU register value= . > + > + @retval EFI_SUCCESS The register was written to Save State. > + @retval EFI_INVALID_PARAMTER Buffer is NULL. > + @retval EFI_UNSUPPORTED This function does not support writing > Register. > +**/ > +EFI_STATUS > +EFIAPI > +SmmCpuFeaturesWriteSaveStateRegister ( > + IN UINTN CpuIndex, > + IN EFI_SMM_SAVE_STATE_REGISTER Register, > + IN UINTN Width, > + IN CONST VOID *Buffer > + ) > +{ > + return MmSaveStateWriteRegister (CpuIndex, Register, Width, Buffer); > +} > + > +/** > + Performs library initialization. > + > + This initialization function contains common functionality shared > + betwen all library instance constructors. > + > +**/ > +VOID > +CpuFeaturesLibInitialization ( > + VOID > + ) > +{ > + UINT32 LMAValue; > + > + LMAValue =3D (UINT32)AsmReadMsr64 (EFER_ADDRESS) & LMA= ; > + mSmmSaveStateRegisterLma =3D > EFI_SMM_SAVE_STATE_REGISTER_LMA_32BIT; > + if (LMAValue) { > + mSmmSaveStateRegisterLma =3D > EFI_SMM_SAVE_STATE_REGISTER_LMA_64BIT; > + } > +} > + > +/** > + Called during the very first SMI into System Management Mode to > +initialize > + CPU features, including SMBASE, for the currently executing CPU. > +Since this > + is the first SMI, the SMRAM Save State Map is at the default address > +of > + AMD_SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET. > The currently > +executing > + CPU is specified by CpuIndex and CpuIndex can be used to access > +information > + about the currently executing CPU in the ProcessorInfo array and the > + HotPlugCpuData data structure. > + > + @param[in] CpuIndex The index of the CPU to initialize. The va= lue > + must be between 0 and the NumberOfCpus fiel= d in > + the System Management System Table (SMST). > + @param[in] IsMonarch TRUE if the CpuIndex is the index of the CP= U > that > + was elected as monarch during System Manage= ment > + Mode initialization. > + FALSE if the CpuIndex is not the index of t= he CPU > + that was elected as monarch during System > + Management Mode initialization. > + @param[in] ProcessorInfo Pointer to an array of > EFI_PROCESSOR_INFORMATION > + structures. ProcessorInfo[CpuIndex] contai= ns the > + information for the currently executing CPU= . > + @param[in] CpuHotPlugData Pointer to the CPU_HOT_PLUG_DATA > structure that > + contains the ApidId and SmBase arrays. > +**/ > +VOID > +EFIAPI > +SmmCpuFeaturesInitializeProcessor ( > + IN UINTN CpuIndex, > + IN BOOLEAN IsMonarch, > + IN EFI_PROCESSOR_INFORMATION *ProcessorInfo, > + IN CPU_HOT_PLUG_DATA *CpuHotPlugData > + ) > +{ > + AMD_SMRAM_SAVE_STATE_MAP *CpuState; > + UINT32 LMAValue; > + > + // > + // Configure SMBASE. > + // > + CpuState =3D (AMD_SMRAM_SAVE_STATE_MAP > *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET); > + CpuState->x64.SMBASE =3D (UINT32)CpuHotPlugData->SmBase[CpuIndex]; > + > + // Re-initialize the value of mSmmSaveStateRegisterLma flag which > + might have been changed in PiCpuSmmDxeSmm Driver // Entry point, to > make sure correct value on AMD platform is assigned to be used by > SmmCpuFeaturesLib. > + LMAValue =3D (UINT32)AsmReadMsr64 (EFER_ADDRESS) & LMA= ; > + mSmmSaveStateRegisterLma =3D > EFI_SMM_SAVE_STATE_REGISTER_LMA_32BIT; > + if (LMAValue) { > + mSmmSaveStateRegisterLma =3D > EFI_SMM_SAVE_STATE_REGISTER_LMA_64BIT; > + } > + > + // > + // If SMRR is supported, then program SMRR base/mask MSRs. > + // The EFI_MSR_SMRR_PHYS_MASK_VALID bit is not set until the first > normal SMI. > + // The code that initializes SMM environment is running in normal > +mode > + // from SMRAM region. If SMRR is enabled here, then the SMRAM region > + // is protected and the normal mode code execution will fail. > + // > + if (FeaturePcdGet (PcdSmrrEnable)) { > + // > + // SMRR size cannot be less than 4-KBytes > + // SMRR size must be of length 2^n > + // SMRR base alignment cannot be less than SMRR length > + // > + if ((CpuHotPlugData->SmrrSize < SIZE_4KB) || > + (CpuHotPlugData->SmrrSize !=3D GetPowerOfTwo32 (CpuHotPlugData- > >SmrrSize)) || > + ((CpuHotPlugData->SmrrBase & ~(CpuHotPlugData->SmrrSize - 1)) != =3D > CpuHotPlugData->SmrrBase)) > + { > + // > + // Print message and halt if CPU is Monarch > + // > + if (IsMonarch) { > + DEBUG ((DEBUG_ERROR, "SMM Base/Size does not meet > alignment/size requirement!\n")); > + CpuDeadLoop (); > + } > + } else { > + AsmWriteMsr64 (SMMADDR_ADDRESS, CpuHotPlugData->SmrrBase); > + AsmWriteMsr64 (SMMMASK_ADDRESS, ((~(UINT64)(CpuHotPlugData- > >SmrrSize - 1)) | 0x6600)); > + } > + } > +} > + > +/** > + This function updates the SMRAM save state on the currently executing > +CPU > + to resume execution at a specific address after an RSM instruction. > +This > + function must evaluate the SMRAM save state to determine the > +execution mode > + the RSM instruction resumes and update the resume execution address > +with > + either NewInstructionPointer32 or NewInstructionPoint. The auto HALT > +restart > + flag in the SMRAM save state must always be cleared. This function > +returns > + the value of the instruction pointer from the SMRAM save state that > +was > + replaced. If this function returns 0, then the SMRAM save state was > +not > + modified. > + > + This function is called during the very first SMI on each CPU after > + SmmCpuFeaturesInitializeProcessor() to set a flag in normal execution > + mode to signal that the SMBASE of each CPU has been updated before > + the default SMBASE address is used for the first SMI to the next CPU. > + > + @param[in] CpuIndex The index of the CPU to hook. The= value > + must be between 0 and the NumberOf= Cpus > + field in the System Management Sys= tem Table > + (SMST). > + @param[in] CpuState Pointer to SMRAM Save State Map fo= r the > + currently executing CPU. > + @param[in] NewInstructionPointer32 Instruction pointer to use if > resuming to > + 32-bit execution mode from 64-bit = SMM. > + @param[in] NewInstructionPointer Instruction pointer to use if resu= ming > to > + same execution mode as SMM. > + > + @retval 0 This function did modify the SMRAM save state. > + @retval > 0 The original instruction pointer value from the SMRAM sav= e > state > + before it was replaced. > +**/ > +UINT64 > +EFIAPI > +SmmCpuFeaturesHookReturnFromSmm ( > + IN UINTN CpuIndex, > + IN SMRAM_SAVE_STATE_MAP *CpuState, > + IN UINT64 NewInstructionPointer32, > + IN UINT64 NewInstructionPointer > + ) > +{ > + UINT64 OriginalInstructionPointer; > + AMD_SMRAM_SAVE_STATE_MAP *AmdCpuState; > + > + AmdCpuState =3D (AMD_SMRAM_SAVE_STATE_MAP *)CpuState; > + > + if (mSmmSaveStateRegisterLma =3D=3D > EFI_SMM_SAVE_STATE_REGISTER_LMA_32BIT) { > + OriginalInstructionPointer =3D (UINT64)AmdCpuState->x86._EIP; > + AmdCpuState->x86._EIP =3D (UINT32)NewInstructionPointer; > + // > + // Clear the auto HALT restart flag so the RSM instruction returns > + // program control to the instruction following the HLT instruction. > + // > + if ((AmdCpuState->x86.AutoHALTRestart & BIT0) !=3D 0) { > + AmdCpuState->x86.AutoHALTRestart &=3D ~BIT0; > + } > + } else { > + OriginalInstructionPointer =3D AmdCpuState->x64._RIP; > + if ((AmdCpuState->x64.EFER & LMA) =3D=3D 0) { > + AmdCpuState->x64._RIP =3D (UINT32)NewInstructionPointer32; > + } else { > + AmdCpuState->x64._RIP =3D (UINT32)NewInstructionPointer; > + } > + > + // > + // Clear the auto HALT restart flag so the RSM instruction returns > + // program control to the instruction following the HLT instruction. > + // > + if ((AmdCpuState->x64.AutoHALTRestart & BIT0) !=3D 0) { > + AmdCpuState->x64.AutoHALTRestart &=3D ~BIT0; > + } > + } > + > + return OriginalInstructionPointer; > +} > + > +/** > + Return the size, in bytes, of a custom SMI Handler in bytes. If 0 is > + returned, then a custom SMI handler is not provided by this library, > + and the default SMI handler must be used. > + > + @retval 0 Use the default SMI handler. > + @retval > 0 Use the SMI handler installed by > SmmCpuFeaturesInstallSmiHandler() > + The caller is required to allocate enough SMRAM for each = CPU to > + support the size of the custom SMI handler. > +**/ > +UINTN > +EFIAPI > +SmmCpuFeaturesGetSmiHandlerSize ( > + VOID > + ) > +{ > + return 0; > +} > + > +/** > + Install a custom SMI handler for the CPU specified by CpuIndex. This > +function > + is only called if SmmCpuFeaturesGetSmiHandlerSize() returns a size is > +greater > + than zero and is called by the CPU that was elected as monarch during > +System > + Management Mode initialization. > + > + @param[in] CpuIndex The index of the CPU to install the custom SMI > handler. > + The value must be between 0 and the NumberOfCpus= field > + in the System Management System Table (SMST). > + @param[in] SmBase The SMBASE address for the CPU specified by > CpuIndex. > + @param[in] SmiStack The stack to use when an SMI is processed by the > + the CPU specified by CpuIndex. > + @param[in] StackSize The size, in bytes, if the stack used when an SM= I is > + processed by the CPU specified by CpuIndex. > + @param[in] GdtBase The base address of the GDT to use when an SMI i= s > + processed by the CPU specified by CpuIndex. > + @param[in] GdtSize The size, in bytes, of the GDT used when an SMI = is > + processed by the CPU specified by CpuIndex. > + @param[in] IdtBase The base address of the IDT to use when an SMI i= s > + processed by the CPU specified by CpuIndex. > + @param[in] IdtSize The size, in bytes, of the IDT used when an SMI = is > + processed by the CPU specified by CpuIndex. > + @param[in] Cr3 The base address of the page tables to use when = an > SMI > + is processed by the CPU specified by CpuIndex. > +**/ > +VOID > +EFIAPI > +SmmCpuFeaturesInstallSmiHandler ( > + IN UINTN CpuIndex, > + IN UINT32 SmBase, > + IN VOID *SmiStack, > + IN UINTN StackSize, > + IN UINTN GdtBase, > + IN UINTN GdtSize, > + IN UINTN IdtBase, > + IN UINTN IdtSize, > + IN UINT32 Cr3 > + ) > +{ > +} > + > +/** > + Determines if MTRR registers must be configured to set SMRAM > +cache-ability > + when executing in System Management Mode. > + > + @retval TRUE MTRR registers must be configured to set SMRAM cache- > ability. > + @retval FALSE MTRR registers do not need to be configured to set > SMRAM > + cache-ability. > +**/ > +BOOLEAN > +EFIAPI > +SmmCpuFeaturesNeedConfigureMtrrs ( > + VOID > + ) > +{ > + return FALSE; > +} > + > +/** > + Disable SMRR register if SMRR is supported and > +SmmCpuFeaturesNeedConfigureMtrrs() > + returns TRUE. > +**/ > +VOID > +EFIAPI > +SmmCpuFeaturesDisableSmrr ( > + VOID > + ) > +{ > +} > + > +/** > + Enable SMRR register if SMRR is supported and > +SmmCpuFeaturesNeedConfigureMtrrs() > + returns TRUE. > +**/ > +VOID > +EFIAPI > +SmmCpuFeaturesReenableSmrr ( > + VOID > + ) > +{ > +} > + > +/** > + Processor specific hook point each time a CPU enters System Management > Mode. > + > + @param[in] CpuIndex The index of the CPU that has entered SMM. The > value > + must be between 0 and the NumberOfCpus field in t= he > + System Management System Table (SMST). > +**/ > +VOID > +EFIAPI > +SmmCpuFeaturesRendezvousEntry ( > + IN UINTN CpuIndex > + ) > +{ > +} > + > +/** > + Returns the current value of the SMM register for the specified CPU. > + If the SMM register is not supported, then 0 is returned. > + > + @param[in] CpuIndex The index of the CPU to read the SMM register. > The > + value must be between 0 and the NumberOfCpus fiel= d in > + the System Management System Table (SMST). > + @param[in] RegName Identifies the SMM register to read. > + > + @return The value of the SMM register specified by RegName from the > CPU > + specified by CpuIndex. > +**/ > +UINT64 > +EFIAPI > +SmmCpuFeaturesGetSmmRegister ( > + IN UINTN CpuIndex, > + IN SMM_REG_NAME RegName > + ) > +{ > + return 0; > +} > + > +/** > + Sets the value of an SMM register on a specified CPU. > + If the SMM register is not supported, then no action is performed. > + > + @param[in] CpuIndex The index of the CPU to write the SMM register. > The > + value must be between 0 and the NumberOfCpus fiel= d in > + the System Management System Table (SMST). > + @param[in] RegName Identifies the SMM register to write. > + registers are read-only. > + @param[in] Value The value to write to the SMM register. > +**/ > +VOID > +EFIAPI > +SmmCpuFeaturesSetSmmRegister ( > + IN UINTN CpuIndex, > + IN SMM_REG_NAME RegName, > + IN UINT64 Value > + ) > +{ > +} > + > +/** > + Check to see if an SMM register is supported by a specified CPU. > + > + @param[in] CpuIndex The index of the CPU to check for SMM register > support. > + The value must be between 0 and the NumberOfCpus = field > + in the System Management System Table (SMST). > + @param[in] RegName Identifies the SMM register to check for support. > + > + @retval TRUE The SMM register specified by RegName is supported by > the CPU > + specified by CpuIndex. > + @retval FALSE The SMM register specified by RegName is not supported > by the > + CPU specified by CpuIndex. > +**/ > +BOOLEAN > +EFIAPI > +SmmCpuFeaturesIsSmmRegisterSupported ( > + IN UINTN CpuIndex, > + IN SMM_REG_NAME RegName > + ) > +{ > + return FALSE; > +} > -- > 2.25.1