From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (NAM04-DM6-obe.outbound.protection.outlook.com [40.107.102.77]) by mx.groups.io with SMTP id smtpd.web10.42255.1682753862404034920 for ; Sat, 29 Apr 2023 00:37:42 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=EJNHWChx; 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.102.77, mailfrom: abner.chang@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BA8YFoakUyCvv0qkFXtMXpLJ/g0th76LOjfx2kuTIfZ2bFkwHxd1gu0AjnoWPnyifyevexllyDmQJ3onDrOblEhgz9D0pGF5VfyJl3kTF75ooKMc4uMPg27Rs65P4c+Fw6bl1e6nCLeEcKlFtANEbCrgvTQ+5bzdFmEnWnBUi5v/jHLR84SBNsTf5jdlXidL1rw7b5Bhe4lHhWz2no9DbxwyCVUA752c4A+rqTxEFoZwN+Dlsg7jJzIZx7+2RX6fK9sWchlT8O8hvssWrFp4LUG8Mgb7JyfYynKCpggVWaBLXGG8IXkSNKEvzrrsBMlD3+SAhNNAKj1yh1hUkfnBmQ== 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=fKX3v04nhfrWPuOUbg3d0NGTy4MM8vOGoEtz0hkWGdA=; b=b0GgN3dLEPME3h8dt+Z/Aq6OMpaJA5scTF3HLbGeFpLmbF4SK+We3CRmbmtJJ2BAir4+jI95bokTK5JztpG54ND+RRHIrT4Fq/Vn1xX/DQxDiZXvaDHZWjFHJQwb6NtJR2e3/E70hjeNTfnc0kkMYO2EYPDinm7Ckx+w6u4CzbIWDM06yRUmfgJiXQ2znFAQXo/LikjOlfk6fdVeEdIcto0Ju40ic7mzD1c+soZqUKbD5tpZY3SzMSgKToy/1waXOutki8UGW07SeI35Mcp24aqnjJIIcV7IFSakkXs7frEzOmVqJPh263GDxtEVsq1YcFt6lr45cl4r/jU9CEfj1w== 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=fKX3v04nhfrWPuOUbg3d0NGTy4MM8vOGoEtz0hkWGdA=; b=EJNHWChx9uJNGtqCZHdKg1lMbXhkLza20uSLdUbAlHVnAKH4JoZfrmXd+esfTEk41BaRhepk/yZLQLqI1QQG0BMwrKSQh5TmLfKoXeDdSpEqZ7lihLBbMTRuk6MiBWbapJH1u0szGh34Vuw6JVEgvhSbO+zzYClHQ9m6xfQ1M08= 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:37:39 +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:37:39 +0000 From: "Chang, Abner" To: "devel@edk2.groups.io" , "Attar, AbdulLateef (Abdul Lateef)" CC: "Grimes, Paul" , Garrett Kirkendall , Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann , Ard Biesheuvel , Jiewen Yao , Jordan Justen Subject: Re: [edk2-devel] [PATCH v9 8/9] UefiCpuPkg: Removes SmmCpuFeaturesReadSaveStateRegister Thread-Topic: [edk2-devel] [PATCH v9 8/9] UefiCpuPkg: Removes SmmCpuFeaturesReadSaveStateRegister Thread-Index: AQHZeBAGJWpmq64gPUWYexT5Rv4he69B6r4A Date: Sat, 29 Apr 2023 07:37:39 +0000 Message-ID: References: <817b1c42603f83d6150e32a3c190c41f4a49adc0.1682493282.git.abdattar@amd.com> In-Reply-To: <817b1c42603f83d6150e32a3c190c41f4a49adc0.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:37:35Z; 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=bc517201-a075-4504-9381-80864800f5e9; 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: 2dd06724-7980-48b9-b516-08db48849bd9 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Mhfdefpnr/56UI6Xzy1VOXkXV0tqIYBD8IM0D18DjQMmw04Dy4djV73Z9H3h9nhReb+wnPAloSQf0yD2cVBH08u8dzK6HpVOngRsOjPIeZggFsWVxaLonKZKN3eowigvLT/QUnKDq6e+SIRx3ElqS6zR0OCsKYcdxGJ/zt5h1q1JXAShwlsSxk1W+Dwk4OQKSLENCSpfCN4vqcwkk6NkEFBpp/xqeMsI0+ZkAuj2u9i2qsEDjjbMiGPu12gL1pnNYyqRT2AAQDtDUFVLE+pQxZ3Q5QObTurDeRhMZBP6eCwk7t0x6MOZxFrEGyE+dQsAlUDx3ewZKAkBvWyXG0/qP9ayaTiG/riefS9DPsBO23IUVENwxyBprTkxGH2ZqcjEnehc5prQ59ud8Cy4OX2BI0BQ1K7Icq0yAmLZi0TGHcA4eJAVqDJf/W59bogKy3/UCAc1+hHHS+1Eqp7KfMTbdKn5Nu2HhUWRyS5c/S5piMXeECgk6/+IuM74fxwWPIm0ETaRrdRNJyT4PmKUzoat/xSzwwU9GZPHHXz5llPXaGOW/r208YIUmnifoEnscVZT03rSacqC9StrqOVbusLgnzRjz/tW1MFjrWqTdWAjgONTmOHgMdysyDvvbV7g5vEp 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)(54906003)(86362001)(478600001)(19627235002)(110136005)(83380400001)(8676002)(8936002)(52536014)(2906002)(66899021)(30864003)(33656002)(71200400001)(7696005)(66476007)(66556008)(66946007)(76116006)(316002)(6506007)(26005)(9686003)(53546011)(122000001)(66446008)(4326008)(64756008)(6636002)(41300700001)(186003)(38070700005)(966005)(55016003)(213903007)(559001)(579004);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?iQVb3N0Wve16i8tAhyxwDAqhTKXn3GHuWcioPmUDDF8zvVMJlYvwGoXOYnx9?= =?us-ascii?Q?u5cs7uheRL69hPHvkKruNjI+YmGOf3QR1BCU5AhSYIvYVrfWkWbMtU5c5a3g?= =?us-ascii?Q?FvhCJl9aWMx0l2vrnsPZsgxF2i4+orYjJoqHRb+c87wGwaGTa53U8RDEVbmi?= =?us-ascii?Q?LSf81zUH/ZWpsHJF0VTpG3/GzxaQ6VW2jAkPY2jnyd2oEB0Fo+xMeamRRV3I?= =?us-ascii?Q?wM96BuQkG9pDs2YMwJ0u0Ih9783tPmhc3vbHzk+ovivXj0Am1JlIcCItulGs?= =?us-ascii?Q?cTqgQYUD+XhcQsTwdh6Szozy3b52LpqjOsoqsW6DqOKUeAVVng0LWB4zyAi5?= =?us-ascii?Q?o+wdWvs8yZf5/TiS7vDtTaRg7ZyXsTC+BUG6HlMe4ANq1lebFNPTyqKNCpXT?= =?us-ascii?Q?If9qejW+UrnuPO3JIRs7P8fc3m8NqNObB8Lo6P4xlfjUEgLYgzbV0e+hJXEu?= =?us-ascii?Q?SwCb3K0eTFP0Y+luztLLaDvty66XqF07+NSV22fdcNDDGsjG1gklKBHdEtsG?= =?us-ascii?Q?WjoV0qsnB7gCXHxO4RMIeXFZPCXxuSFldi8LAq+kIntTqBPvNrwao/eOYwOz?= =?us-ascii?Q?b7smtHr6v4xxJmVj4HvQ3p2Yzm/lv/TtVuSsRZr63q2sK+mn/7w0ReSOKeqZ?= =?us-ascii?Q?M6EKHARR9FG1PBjVnrDuo1lkeqokC0GplfxREoibqsuqYdI2krU5RhK8/7k6?= =?us-ascii?Q?stRoPfSYIsTkGsO2Gl7hnCYwMH40mdDHL/D35hktbWKvwa8CtLIAheVfhoH4?= =?us-ascii?Q?lF3ztSk9nrMS/OwDH/jEEWv45I6GyF4vBki6ODcP60717FC8/jweP/oflUL5?= =?us-ascii?Q?fvRabZldSX5DueirpANwb0IlYfWoACxnCN7Y4VATWujoZzk2i6LTyfp01Bsk?= =?us-ascii?Q?roHxIL8rtvACpXxlGmzJmxNF3EyqxXdO7RvaJmKAUXtWH2Z93YrFNgADOPk/?= =?us-ascii?Q?bpao1wwHIL8mtRfw7Xj0h7yrf8cyPxqn30VWLZMyreFZN0tkibBk0DFSmEeE?= =?us-ascii?Q?pXS9Iz7VOrRgx8jidLZ4LvOKouhFqhJOEEJ7P1exr1C8dRck+cvENr192Q2R?= =?us-ascii?Q?5UO49sqJ5IP8sqEIlKhh/NooBk3udbWr3kwWdKVoNSc8kNcD/+Aar18XBhXC?= =?us-ascii?Q?UfbKF4ZNU8jnTLUGT3dNcZTeoOPOm7y7x1we6T64+E2qCLYvsbZvdexgZ04T?= =?us-ascii?Q?CMgDPrsnJDo/sNtHMTXzaGGTktDWlAv+LkvjzCPYA4svKTV3JFd6CPfvL7V6?= =?us-ascii?Q?FtfYwA8XyPLfOxc/DB4RpLOcdMk95Pk7K+IUuDw3KOxOo40lN2FsV9XwfaAX?= =?us-ascii?Q?c3xWAnCZWU0ViZhPHN+q2yaU2sG7Sz/uDbZ466eDw6Ltzb7VQrMTLsTe/R8U?= =?us-ascii?Q?OMHrj6qeftjhSYt9V3BOwweLiJMfjGigVF8FvSW9MYtqr86+vkKq7MGPeqkj?= =?us-ascii?Q?KkZc7szOArLlp73RKkWPQclNh0LRHDqjWxRpMM141KbUmHn54SgiujCDzwI5?= =?us-ascii?Q?2x7iwJ9KPJoetUh8VE46+522V5j2SFINHOi4EyDLsd8XUx+JGUBD9GZWV+m/?= =?us-ascii?Q?6/pTAOdwaOaiUpFBQcE=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: 2dd06724-7980-48b9-b516-08db48849bd9 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Apr 2023 07:37:39.0641 (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: P5Hs/ZU81wTL4lNH79JNWilJnnGFRITtAw9IJjgAIcXWoeJb/mlOBQkbYsBBbEGqziQwXQrA4iUoS74NWSTBPg== 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] Reviewed-by: Abner Chang > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Abdul > Lateef Attar via groups.io > 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 > ; Gerd Hoffmann ; Ard > Biesheuvel ; Jiewen Yao > ; Jordan Justen > Subject: [edk2-devel] [PATCH v9 8/9] UefiCpuPkg: Removes > SmmCpuFeaturesReadSaveStateRegister >=20 > Caution: This message originated from an External Source. Use proper > caution when opening attachments, clicking links, or responding. >=20 >=20 > BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4182 >=20 > Removes SmmCpuFeaturesReadSaveStateRegister and > SmmCpuFeaturesWirteSaveStateRegister > function from SmmCpuFeaturesLib library. >=20 > MmSaveStateLib library replaces the functionality of the above functions. > Platform old/new need to use MmSaveStateLib library to read/write save > state registers. > Current implementation supports Intel, AMD and Ovmf/Qemu. >=20 > Cc: Paul Grimes > Cc: Garrett Kirkendall > Cc: Abner Chang > Cc: Eric Dong > Cc: Ray Ni > Cc: Rahul Kumar > Cc: Gerd Hoffmann > Cc: Ard Biesheuvel > Cc: Jiewen Yao > Cc: Jordan Justen > Signed-off-by: Abdul Lateef Attar > --- > UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf | 2 + > .../Include/Library/SmmCpuFeaturesLib.h | 52 -- > UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 56 +- > .../SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.c | 58 -- > .../IntelSmmCpuFeaturesLib.c | 58 -- > UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 11 +- > UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c | 500 +----------------- > 7 files changed, 9 insertions(+), 728 deletions(-) >=20 > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf > b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf > index 158e05e2646c..bd83b4afab26 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf > @@ -6,6 +6,7 @@ > # > # Copyright (c) 2009 - 2023, Intel Corporation. All rights reserved.
= # > Copyright (c) 2017, AMD Incorporated. All rights reserved.
> +# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights > +reserved.
> # > # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -97,6 +98,7 @@ > [LibraryClasses] > ReportStatusCodeLib > SmmCpuFeaturesLib > PeCoffGetEntryPointLib > + MmSaveStateLib >=20 > [Protocols] > gEfiSmmAccess2ProtocolGuid ## CONSUMES > diff --git a/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h > b/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h > index 52160c7145ba..733f0d03ebaa 100644 > --- a/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h > +++ b/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h > @@ -324,58 +324,6 @@ SmmCpuFeaturesSetSmmRegister ( > IN UINT64 Value > ); >=20 > -/** > - Read an SMM Save State register on the target processor. If this func= tion > - returns EFI_UNSUPPORTED, then the caller is responsible for reading th= e > - 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 st= ate. > - @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_PARAMETER 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 > - ); > - > -/** > - Writes an SMM Save State register on the target processor. If this fu= nction > - returns EFI_UNSUPPORTED, then the caller is responsible for writing th= e > - 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_PARAMETER 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 > - ); > - > /** > This function is hook point called after the > gEfiSmmReadyToLockProtocolGuid > notification is completely processed. > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h > b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h > index a5c2bdd971ca..106808b08e17 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h > @@ -3,6 +3,7 @@ Agent Module to load other modules to deploy SMM > Entry Vector for X86 CPU. >=20 > Copyright (c) 2009 - 2023, Intel Corporation. All rights reserved.
> Copyright (c) 2017, AMD Incorporated. All rights reserved.
> +Copyright (C) 2023 Advanced Micro Devices, Inc. All rights > +reserved.
>=20 > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > @@ -50,6 +51,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include > #include > > #include > +#include >=20 > #include > #include > @@ -367,60 +369,6 @@ ExecuteFirstSmiInit ( > VOID > ); >=20 > -/** > -Read a CPU Save State register on the target processor. > - > -This function abstracts the differences that whether the CPU Save State > register is in the > -IA32 CPU Save State Map or X64 CPU Save State Map. > - > -This function supports reading a CPU Save State register in SMBase > relocation handler. > - > -@param[in] CpuIndex Specifies the zero-based index of the CPU sav= e > state. > -@param[in] RegisterIndex Index into mSmmCpuWidthOffset[] look up > table. > -@param[in] Width The number of bytes to read from the CPU save > state. > -@param[out] Buffer Upon return, this holds the CPU register valu= e read > from the save state. > - > -@retval EFI_SUCCESS The register was read from Save State. > -@retval EFI_NOT_FOUND The register is not defined for the Save S= tate > of Processor. > -@retval EFI_INVALID_PARAMETER Buffer is NULL, or Width does not meet > requirement per Register type. > - > -**/ > -EFI_STATUS > -EFIAPI > -ReadSaveStateRegister ( > - IN UINTN CpuIndex, > - IN EFI_SMM_SAVE_STATE_REGISTER Register, > - IN UINTN Width, > - OUT VOID *Buffer > - ); > - > -/** > -Write value to a CPU Save State register on the target processor. > - > -This function abstracts the differences that whether the CPU Save State > register is in the > -IA32 CPU Save State Map or X64 CPU Save State Map. > - > -This function supports writing a CPU Save State register in SMBase > relocation handler. > - > -@param[in] CpuIndex Specifies the zero-based index of the CPU save > state. > -@param[in] RegisterIndex Index into mSmmCpuWidthOffset[] look up > table. > -@param[in] Width The number of bytes to read from the CPU save > state. > -@param[in] Buffer Upon entry, this holds the new CPU register va= lue. > - > -@retval EFI_SUCCESS The register was written to Save State. > -@retval EFI_NOT_FOUND The register is not defined for the Save S= tate > of Processor. > -@retval EFI_INVALID_PARAMETER ProcessorIndex or Width is not correct. > - > -**/ > -EFI_STATUS > -EFIAPI > -WriteSaveStateRegister ( > - IN UINTN CpuIndex, > - IN EFI_SMM_SAVE_STATE_REGISTER Register, > - IN UINTN Width, > - IN CONST VOID *Buffer > - ); > - > extern BOOLEAN mSmmRelocated; > extern volatile BOOLEAN *mSmmInitialized; > extern UINT32 mBspApicId; > diff --git > a/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.c > b/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.c > index 1473f0a51fe2..e6d1b5010356 100644 > --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.c > +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.c > @@ -27,64 +27,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // The > mode of the CPU at the time an SMI occurs STATIC UINT8 > mSmmSaveStateRegisterLma; >=20 > -/** > - Read an SMM Save State register on the target processor. If this func= tion > - returns EFI_UNSUPPORTED, then the caller is responsible for reading th= e > - 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 st= ate. > - @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 fu= nction > - returns EFI_UNSUPPORTED, then the caller is responsible for writing th= e > - 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. >=20 > diff --git > a/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c > b/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c > index 8f382b60266c..950056a7143d 100644 > --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c > +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c > @@ -461,64 +461,6 @@ SmmCpuFeaturesHookReturnFromSmm ( > return 0; > } >=20 > -/** > - Read an SMM Save State register on the target processor. If this func= tion > - returns EFI_UNSUPPORTED, then the caller is responsible for reading th= e > - 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 st= ate. > - @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_PARAMETER 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 EFI_UNSUPPORTED; > -} > - > -/** > - Writes an SMM Save State register on the target processor. If this fu= nction > - returns EFI_UNSUPPORTED, then the caller is responsible for writing th= e > - 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_PARAMETER 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 EFI_UNSUPPORTED; > -} > - > /** > Check to see if an SMM register is supported by a specified CPU. >=20 > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c > b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c > index c0e368ea9475..ec191be858af 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c > @@ -3,6 +3,7 @@ Agent Module to load other modules to deploy SMM > Entry Vector for X86 CPU. >=20 > Copyright (c) 2009 - 2023, Intel Corporation. All rights reserved.
> Copyright (c) 2017, AMD Incorporated. All rights reserved.
> +Copyright (C) 2023 Advanced Micro Devices, Inc. All rights > +reserved.
>=20 > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > @@ -276,10 +277,7 @@ SmmReadSaveState ( > return EFI_INVALID_PARAMETER; > } >=20 > - Status =3D SmmCpuFeaturesReadSaveStateRegister (CpuIndex, Register, > Width, Buffer); > - if (Status =3D=3D EFI_UNSUPPORTED) { > - Status =3D ReadSaveStateRegister (CpuIndex, Register, Width, Buffer)= ; > - } > + Status =3D MmSaveStateReadRegister (CpuIndex, Register, Width, Buffer)= ; >=20 > return Status; > } > @@ -328,10 +326,7 @@ SmmWriteSaveState ( > return EFI_INVALID_PARAMETER; > } >=20 > - Status =3D SmmCpuFeaturesWriteSaveStateRegister (CpuIndex, Register, > Width, Buffer); > - if (Status =3D=3D EFI_UNSUPPORTED) { > - Status =3D WriteSaveStateRegister (CpuIndex, Register, Width, Buffer= ); > - } > + Status =3D MmSaveStateWriteRegister (CpuIndex, Register, Width, > + Buffer); >=20 > return Status; > } > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c > b/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c > index c8ddc6083df6..1e316ee0acdb 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c > @@ -2,6 +2,8 @@ > Provides services to access SMRAM Save State Map >=20 > Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.
> +Copyright (C) 2023 Advanced Micro Devices, Inc. All rights > +reserved.
> + > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > **/ > @@ -48,52 +50,6 @@ extern CONST PROCESSOR_SMM_DESCRIPTOR gcPsd; > // #define LMA BIT10 >=20 > -/// > -/// Macro used to simplify the lookup table entries of type > CPU_SMM_SAVE_STATE_LOOKUP_ENTRY -/// -#define > SMM_CPU_OFFSET(Field) OFFSET_OF (SMRAM_SAVE_STATE_MAP, Field) > - > -/// > -/// Macro used to simplify the lookup table entries of type > CPU_SMM_SAVE_STATE_REGISTER_RANGE -/// -#define > SMM_REGISTER_RANGE(Start, End) { Start, End, End - Start + 1 } > - > -/// > -/// Structure used to describe a range of registers -/// -typedef struct= { > - EFI_SMM_SAVE_STATE_REGISTER Start; > - EFI_SMM_SAVE_STATE_REGISTER End; > - UINTN Length; > -} CPU_SMM_SAVE_STATE_REGISTER_RANGE; > - > -/// > -/// Structure used to build a lookup table to retrieve the widths and of= fsets - > /// associated with each supported EFI_SMM_SAVE_STATE_REGISTER value > -/// > - > -#define SMM_SAVE_STATE_REGISTER_SMMREVID_INDEX 1 > -#define SMM_SAVE_STATE_REGISTER_IOMISC_INDEX 2 > -#define SMM_SAVE_STATE_REGISTER_IOMEMADDR_INDEX 3 > -#define SMM_SAVE_STATE_REGISTER_MAX_INDEX 4 > - > -typedef struct { > - UINT8 Width32; > - UINT8 Width64; > - UINT16 Offset32; > - UINT16 Offset64Lo; > - UINT16 Offset64Hi; > - BOOLEAN Writeable; > -} CPU_SMM_SAVE_STATE_LOOKUP_ENTRY; > - > -/// > -/// Structure used to build a lookup table for the IOMisc width informat= ion - > /// -typedef struct { > - UINT8 Width; > - EFI_SMM_SAVE_STATE_IO_WIDTH IoWidth; > -} CPU_SMM_SAVE_STATE_IO_WIDTH; > - > /// > /// Variables from SMI Handler > /// > @@ -108,463 +64,11 @@ extern CONST UINT16 gcSmiHandlerSize; > // > IA32_DESCRIPTOR gSmiHandlerIdtr; >=20 > -/// > -/// Table used by GetRegisterIndex() to convert an > EFI_SMM_SAVE_STATE_REGISTER -/// value to an index into a table of type > CPU_SMM_SAVE_STATE_LOOKUP_ENTRY -/// -CONST > CPU_SMM_SAVE_STATE_REGISTER_RANGE mSmmCpuRegisterRanges[] =3D { > - SMM_REGISTER_RANGE (EFI_SMM_SAVE_STATE_REGISTER_GDTBASE, > EFI_SMM_SAVE_STATE_REGISTER_LDTINFO), > - SMM_REGISTER_RANGE (EFI_SMM_SAVE_STATE_REGISTER_ES, > EFI_SMM_SAVE_STATE_REGISTER_RIP), > - SMM_REGISTER_RANGE (EFI_SMM_SAVE_STATE_REGISTER_RFLAGS, > EFI_SMM_SAVE_STATE_REGISTER_CR4), > - { (EFI_SMM_SAVE_STATE_REGISTER)0, > (EFI_SMM_SAVE_STATE_REGISTER)0, 0} > -}; > - > -/// > -/// Lookup table used to retrieve the widths and offsets associated with > each -/// supported EFI_SMM_SAVE_STATE_REGISTER value -/// -CONST > CPU_SMM_SAVE_STATE_LOOKUP_ENTRY mSmmCpuWidthOffset[] =3D { > - { 0, 0, 0, 0, = 0, FALSE }, // > Reserved > - > - // > - // Internally defined CPU Save State Registers. Not defined in PI SMM = CPU > Protocol. > - // > - { 4, 4, SMM_CPU_OFFSET (x86.SMMRevId), SMM_CPU_OFFSET > (x64.SMMRevId), 0, FALSE }, // > SMM_SAVE_STATE_REGISTER_SMMREVID_INDEX =3D 1 > - { 4, 4, SMM_CPU_OFFSET (x86.IOMisc), SMM_CPU_OFFSET (x64.IOMisc), > 0, FALSE }, // SMM_SAVE_STATE_REGISTER_= IOMISC_INDEX > =3D 2 > - { 4, 8, SMM_CPU_OFFSET (x86.IOMemAddr), SMM_CPU_OFFSET > (x64.IOMemAddr), SMM_CPU_OFFSET (x64.IOMemAddr) + 4, FALSE }, // > SMM_SAVE_STATE_REGISTER_IOMEMADDR_INDEX =3D 3 > - > - // > - // CPU Save State registers defined in PI SMM CPU Protocol. > - // > - { 0, 8, 0, SMM_CPU_OFFSET (x64.GdtBaseLoD= word), > SMM_CPU_OFFSET (x64.GdtBaseHiDword), FALSE }, // > EFI_SMM_SAVE_STATE_REGISTER_GDTBASE =3D 4 > - { 0, 8, 0, SMM_CPU_OFFSET (x64.IdtBaseLoD= word), > SMM_CPU_OFFSET (x64.IdtBaseHiDword), FALSE }, // > EFI_SMM_SAVE_STATE_REGISTER_IDTBASE =3D 5 > - { 0, 8, 0, SMM_CPU_OFFSET (x64.LdtBaseLoD= word), > SMM_CPU_OFFSET (x64.LdtBaseHiDword), FALSE }, // > EFI_SMM_SAVE_STATE_REGISTER_LDTBASE =3D 6 > - { 0, 0, 0, 0, = 0, FALSE }, // > EFI_SMM_SAVE_STATE_REGISTER_GDTLIMIT =3D 7 > - { 0, 0, 0, 0, = 0, FALSE }, // > EFI_SMM_SAVE_STATE_REGISTER_IDTLIMIT =3D 8 > - { 0, 0, 0, 0, = 0, FALSE }, // > EFI_SMM_SAVE_STATE_REGISTER_LDTLIMIT =3D 9 > - { 0, 0, 0, 0, = 0, FALSE }, // > EFI_SMM_SAVE_STATE_REGISTER_LDTINFO =3D 10 > - > - { 4, 4, SMM_CPU_OFFSET (x86._ES), SMM_CPU_OFFSET (x64._ES), > 0, FALSE }, // EFI_SMM_SAVE_STATE_REGI= STER_ES =3D 20 > - { 4, 4, SMM_CPU_OFFSET (x86._CS), SMM_CPU_OFFSET (x64._CS), > 0, FALSE }, // EFI_SMM_SAVE_STATE_REGI= STER_CS =3D 21 > - { 4, 4, SMM_CPU_OFFSET (x86._SS), SMM_CPU_OFFSET (x64._SS), > 0, FALSE }, // EFI_SMM_SAVE_STATE_REGI= STER_SS =3D 22 > - { 4, 4, SMM_CPU_OFFSET (x86._DS), SMM_CPU_OFFSET (x64._DS), > 0, FALSE }, // EFI_SMM_SAVE_STATE_REGI= STER_DS =3D 23 > - { 4, 4, SMM_CPU_OFFSET (x86._FS), SMM_CPU_OFFSET (x64._FS), > 0, FALSE }, // EFI_SMM_SAVE_STATE_REGI= STER_FS =3D 24 > - { 4, 4, SMM_CPU_OFFSET (x86._GS), SMM_CPU_OFFSET (x64._GS), > 0, FALSE }, // EFI_SMM_SAVE_STATE_REGI= STER_GS =3D 25 > - { 0, 4, 0, SMM_CPU_OFFSET (x64._LDTR), = 0, > FALSE }, // EFI_SMM_SAVE_STATE_REGISTER_LDTR_SEL =3D 26 > - { 4, 4, SMM_CPU_OFFSET (x86._TR), SMM_CPU_OFFSET (x64._TR), > 0, FALSE }, // EFI_SMM_SAVE_STATE_REGI= STER_TR_SEL =3D > 27 > - { 4, 8, SMM_CPU_OFFSET (x86._DR7), SMM_CPU_OFFSET (x64._DR7), > SMM_CPU_OFFSET (x64._DR7) + 4, FALSE }, // > EFI_SMM_SAVE_STATE_REGISTER_DR7 =3D 28 > - { 4, 8, SMM_CPU_OFFSET (x86._DR6), SMM_CPU_OFFSET (x64._DR6), > SMM_CPU_OFFSET (x64._DR6) + 4, FALSE }, // > EFI_SMM_SAVE_STATE_REGISTER_DR6 =3D 29 > - { 0, 8, 0, SMM_CPU_OFFSET (x64._R8), > SMM_CPU_OFFSET (x64._R8) + 4, TRUE }, // > EFI_SMM_SAVE_STATE_REGISTER_R8 =3D 30 > - { 0, 8, 0, SMM_CPU_OFFSET (x64._R9), > SMM_CPU_OFFSET (x64._R9) + 4, TRUE }, // > EFI_SMM_SAVE_STATE_REGISTER_R9 =3D 31 > - { 0, 8, 0, SMM_CPU_OFFSET (x64._R10), > SMM_CPU_OFFSET (x64._R10) + 4, TRUE }, // > EFI_SMM_SAVE_STATE_REGISTER_R10 =3D 32 > - { 0, 8, 0, SMM_CPU_OFFSET (x64._R11), > SMM_CPU_OFFSET (x64._R11) + 4, TRUE }, // > EFI_SMM_SAVE_STATE_REGISTER_R11 =3D 33 > - { 0, 8, 0, SMM_CPU_OFFSET (x64._R12), > SMM_CPU_OFFSET (x64._R12) + 4, TRUE }, // > EFI_SMM_SAVE_STATE_REGISTER_R12 =3D 34 > - { 0, 8, 0, SMM_CPU_OFFSET (x64._R13), > SMM_CPU_OFFSET (x64._R13) + 4, TRUE }, // > EFI_SMM_SAVE_STATE_REGISTER_R13 =3D 35 > - { 0, 8, 0, SMM_CPU_OFFSET (x64._R14), > SMM_CPU_OFFSET (x64._R14) + 4, TRUE }, // > EFI_SMM_SAVE_STATE_REGISTER_R14 =3D 36 > - { 0, 8, 0, SMM_CPU_OFFSET (x64._R15), > SMM_CPU_OFFSET (x64._R15) + 4, TRUE }, // > EFI_SMM_SAVE_STATE_REGISTER_R15 =3D 37 > - { 4, 8, SMM_CPU_OFFSET (x86._EAX), SMM_CPU_OFFSET (x64._RAX), > SMM_CPU_OFFSET (x64._RAX) + 4, TRUE }, // > EFI_SMM_SAVE_STATE_REGISTER_RAX =3D 38 > - { 4, 8, SMM_CPU_OFFSET (x86._EBX), SMM_CPU_OFFSET (x64._RBX), > SMM_CPU_OFFSET (x64._RBX) + 4, TRUE }, // > EFI_SMM_SAVE_STATE_REGISTER_RBX =3D 39 > - { 4, 8, SMM_CPU_OFFSET (x86._ECX), SMM_CPU_OFFSET (x64._RCX), > SMM_CPU_OFFSET (x64._RCX) + 4, TRUE }, // > EFI_SMM_SAVE_STATE_REGISTER_RCX =3D 40 > - { 4, 8, SMM_CPU_OFFSET (x86._EDX), SMM_CPU_OFFSET (x64._RDX), > SMM_CPU_OFFSET (x64._RDX) + 4, TRUE }, // > EFI_SMM_SAVE_STATE_REGISTER_RDX =3D 41 > - { 4, 8, SMM_CPU_OFFSET (x86._ESP), SMM_CPU_OFFSET (x64._RSP), > SMM_CPU_OFFSET (x64._RSP) + 4, TRUE }, // > EFI_SMM_SAVE_STATE_REGISTER_RSP =3D 42 > - { 4, 8, SMM_CPU_OFFSET (x86._EBP), SMM_CPU_OFFSET (x64._RBP), > SMM_CPU_OFFSET (x64._RBP) + 4, TRUE }, // > EFI_SMM_SAVE_STATE_REGISTER_RBP =3D 43 > - { 4, 8, SMM_CPU_OFFSET (x86._ESI), SMM_CPU_OFFSET (x64._RSI), > SMM_CPU_OFFSET (x64._RSI) + 4, TRUE }, // > EFI_SMM_SAVE_STATE_REGISTER_RSI =3D 44 > - { 4, 8, SMM_CPU_OFFSET (x86._EDI), SMM_CPU_OFFSET (x64._RDI), > SMM_CPU_OFFSET (x64._RDI) + 4, TRUE }, // > EFI_SMM_SAVE_STATE_REGISTER_RDI =3D 45 > - { 4, 8, SMM_CPU_OFFSET (x86._EIP), SMM_CPU_OFFSET (x64._RIP), > SMM_CPU_OFFSET (x64._RIP) + 4, TRUE }, // > EFI_SMM_SAVE_STATE_REGISTER_RIP =3D 46 > - > - { 4, 8, SMM_CPU_OFFSET (x86._EFLAGS), SMM_CPU_OFFSET > (x64._RFLAGS), SMM_CPU_OFFSET (x64._RFLAGS) + 4, TRUE }, // > EFI_SMM_SAVE_STATE_REGISTER_RFLAGS =3D 51 > - { 4, 8, SMM_CPU_OFFSET (x86._CR0), SMM_CPU_OFFSET (x64._CR0), > SMM_CPU_OFFSET (x64._CR0) + 4, FALSE }, // > EFI_SMM_SAVE_STATE_REGISTER_CR0 =3D 52 > - { 4, 8, SMM_CPU_OFFSET (x86._CR3), SMM_CPU_OFFSET (x64._CR3), > SMM_CPU_OFFSET (x64._CR3) + 4, FALSE }, // > EFI_SMM_SAVE_STATE_REGISTER_CR3 =3D 53 > - { 0, 4, 0, SMM_CPU_OFFSET (x64._CR4), = 0, > FALSE }, // EFI_SMM_SAVE_STATE_REGISTER_CR4 =3D 54 > -}; > - > -/// > -/// Lookup table for the IOMisc width information -/// -CONST > CPU_SMM_SAVE_STATE_IO_WIDTH mSmmCpuIoWidth[] =3D { > - { 0, EFI_SMM_SAVE_STATE_IO_WIDTH_UINT8 }, // Undefined =3D= 0 > - { 1, EFI_SMM_SAVE_STATE_IO_WIDTH_UINT8 }, // > SMM_IO_LENGTH_BYTE =3D 1 > - { 2, EFI_SMM_SAVE_STATE_IO_WIDTH_UINT16 }, // > SMM_IO_LENGTH_WORD =3D 2 > - { 0, EFI_SMM_SAVE_STATE_IO_WIDTH_UINT8 }, // Undefined =3D= 3 > - { 4, EFI_SMM_SAVE_STATE_IO_WIDTH_UINT32 }, // > SMM_IO_LENGTH_DWORD =3D 4 > - { 0, EFI_SMM_SAVE_STATE_IO_WIDTH_UINT8 }, // Undefined =3D= 5 > - { 0, EFI_SMM_SAVE_STATE_IO_WIDTH_UINT8 }, // Undefined =3D= 6 > - { 0, EFI_SMM_SAVE_STATE_IO_WIDTH_UINT8 } // Undefined =3D= 7 > -}; > - > -/// > -/// Lookup table for the IOMisc type information -/// -CONST > EFI_SMM_SAVE_STATE_IO_TYPE mSmmCpuIoType[] =3D { > - EFI_SMM_SAVE_STATE_IO_TYPE_OUTPUT, // SMM_IO_TYPE_OUT_DX > =3D 0 > - EFI_SMM_SAVE_STATE_IO_TYPE_INPUT, // SMM_IO_TYPE_IN_DX > =3D 1 > - EFI_SMM_SAVE_STATE_IO_TYPE_STRING, // SMM_IO_TYPE_OUTS > =3D 2 > - EFI_SMM_SAVE_STATE_IO_TYPE_STRING, // SMM_IO_TYPE_INS = =3D > 3 > - (EFI_SMM_SAVE_STATE_IO_TYPE)0, // Undefined = =3D 4 > - (EFI_SMM_SAVE_STATE_IO_TYPE)0, // Undefined = =3D 5 > - EFI_SMM_SAVE_STATE_IO_TYPE_REP_PREFIX, // > SMM_IO_TYPE_REP_OUTS =3D 6 > - EFI_SMM_SAVE_STATE_IO_TYPE_REP_PREFIX, // SMM_IO_TYPE_REP_INS > =3D 7 > - EFI_SMM_SAVE_STATE_IO_TYPE_OUTPUT, // > SMM_IO_TYPE_OUT_IMMEDIATE =3D 8 > - EFI_SMM_SAVE_STATE_IO_TYPE_INPUT, // > SMM_IO_TYPE_OUT_IMMEDIATE =3D 9 > - (EFI_SMM_SAVE_STATE_IO_TYPE)0, // Undefined = =3D 10 > - (EFI_SMM_SAVE_STATE_IO_TYPE)0, // Undefined = =3D 11 > - (EFI_SMM_SAVE_STATE_IO_TYPE)0, // Undefined = =3D 12 > - (EFI_SMM_SAVE_STATE_IO_TYPE)0, // Undefined = =3D 13 > - (EFI_SMM_SAVE_STATE_IO_TYPE)0, // Undefined = =3D 14 > - (EFI_SMM_SAVE_STATE_IO_TYPE)0 // Undefined = =3D 15 > -}; > - > /// > /// The mode of the CPU at the time an SMI occurs /// > UINT8 mSmmSaveStateRegisterLma; >=20 > -/** > - Read information from the CPU save state. > - > - @param Register Specifies the CPU register to read form the save sta= te. > - > - @retval 0 Register is not valid > - @retval >0 Index into mSmmCpuWidthOffset[] associated with Register > - > -**/ > -UINTN > -GetRegisterIndex ( > - IN EFI_SMM_SAVE_STATE_REGISTER Register > - ) > -{ > - UINTN Index; > - UINTN Offset; > - > - for (Index =3D 0, Offset =3D SMM_SAVE_STATE_REGISTER_MAX_INDEX; > mSmmCpuRegisterRanges[Index].Length !=3D 0; Index++) { > - if ((Register >=3D mSmmCpuRegisterRanges[Index].Start) && (Register = <=3D > mSmmCpuRegisterRanges[Index].End)) { > - return Register - mSmmCpuRegisterRanges[Index].Start + Offset; > - } > - > - Offset +=3D mSmmCpuRegisterRanges[Index].Length; > - } > - > - return 0; > -} > - > -/** > - Read a CPU Save State register on the target processor. > - > - This function abstracts the differences that whether the CPU Save Stat= e > register is in the > - IA32 CPU Save State Map or X64 CPU Save State Map. > - > - This function supports reading a CPU Save State register in SMBase > relocation handler. > - > - @param[in] CpuIndex Specifies the zero-based index of the CPU s= ave > state. > - @param[in] RegisterIndex Index into mSmmCpuWidthOffset[] look up > table. > - @param[in] Width The number of bytes to read from the CPU sa= ve > state. > - @param[out] Buffer Upon return, this holds the CPU register va= lue > read from the save state. > - > - @retval EFI_SUCCESS The register was read from Save State. > - @retval EFI_NOT_FOUND The register is not defined for the Save= State > of Processor. > - @retval EFI_INVALID_PARAMETER This or Buffer is NULL. > - > -**/ > -EFI_STATUS > -ReadSaveStateRegisterByIndex ( > - IN UINTN CpuIndex, > - IN UINTN RegisterIndex, > - IN UINTN Width, > - OUT VOID *Buffer > - ) > -{ > - SMRAM_SAVE_STATE_MAP *CpuSaveState; > - > - if (RegisterIndex =3D=3D 0) { > - return EFI_NOT_FOUND; > - } > - > - CpuSaveState =3D gSmst->CpuSaveState[CpuIndex]; > - > - if (mSmmSaveStateRegisterLma =3D=3D > EFI_SMM_SAVE_STATE_REGISTER_LMA_32BIT) { > - // > - // If 32-bit mode width is zero, then the specified register can not= be > accessed > - // > - if (mSmmCpuWidthOffset[RegisterIndex].Width32 =3D=3D 0) { > - return EFI_NOT_FOUND; > - } > - > - // > - // If Width is bigger than the 32-bit mode width, then the specified > register can not be accessed > - // > - if (Width > mSmmCpuWidthOffset[RegisterIndex].Width32) { > - return EFI_INVALID_PARAMETER; > - } > - > - // > - // Write return buffer > - // > - ASSERT (CpuSaveState !=3D NULL); > - CopyMem (Buffer, (UINT8 *)CpuSaveState + > mSmmCpuWidthOffset[RegisterIndex].Offset32, Width); > - } else { > - // > - // If 64-bit mode width is zero, then the specified register can not= be > accessed > - // > - if (mSmmCpuWidthOffset[RegisterIndex].Width64 =3D=3D 0) { > - return EFI_NOT_FOUND; > - } > - > - // > - // If Width is bigger than the 64-bit mode width, then the specified > register can not be accessed > - // > - if (Width > mSmmCpuWidthOffset[RegisterIndex].Width64) { > - return EFI_INVALID_PARAMETER; > - } > - > - // > - // Write at most 4 of the lower bytes of the return buffer > - // > - CopyMem (Buffer, (UINT8 *)CpuSaveState + > mSmmCpuWidthOffset[RegisterIndex].Offset64Lo, MIN (4, Width)); > - if (Width > 4) { > - // > - // Write at most 4 of the upper bytes of the return buffer > - // > - CopyMem ((UINT8 *)Buffer + 4, (UINT8 *)CpuSaveState + > mSmmCpuWidthOffset[RegisterIndex].Offset64Hi, Width - 4); > - } > - } > - > - return EFI_SUCCESS; > -} > - > -/** > - Read a CPU Save State register on the target processor. > - > - This function abstracts the differences that whether the CPU Save Stat= e > register is in the > - IA32 CPU Save State Map or X64 CPU Save State Map. > - > - This function supports reading a CPU Save State register in SMBase > relocation handler. > - > - @param[in] CpuIndex Specifies the zero-based index of the CPU s= ave > state. > - @param[in] RegisterIndex Index into mSmmCpuWidthOffset[] look up > table. > - @param[in] Width The number of bytes to read from the CPU sa= ve > state. > - @param[out] Buffer Upon return, this holds the CPU register va= lue > read from the save state. > - > - @retval EFI_SUCCESS The register was read from Save State. > - @retval EFI_NOT_FOUND The register is not defined for the Save= State > of Processor. > - @retval EFI_INVALID_PARAMETER Buffer is NULL, or Width does not meet > requirement per Register type. > - > -**/ > -EFI_STATUS > -EFIAPI > -ReadSaveStateRegister ( > - IN UINTN CpuIndex, > - IN EFI_SMM_SAVE_STATE_REGISTER Register, > - IN UINTN Width, > - OUT VOID *Buffer > - ) > -{ > - UINT32 SmmRevId; > - SMRAM_SAVE_STATE_IOMISC IoMisc; > - EFI_SMM_SAVE_STATE_IO_INFO *IoInfo; > - > - // > - // Check for special EFI_SMM_SAVE_STATE_REGISTER_LMA > - // > - if (Register =3D=3D EFI_SMM_SAVE_STATE_REGISTER_LMA) { > - // > - // Only byte access is supported for this register > - // > - if (Width !=3D 1) { > - return EFI_INVALID_PARAMETER; > - } > - > - *(UINT8 *)Buffer =3D mSmmSaveStateRegisterLma; > - > - return EFI_SUCCESS; > - } > - > - // > - // Check for special EFI_SMM_SAVE_STATE_REGISTER_IO > - // > - if (Register =3D=3D EFI_SMM_SAVE_STATE_REGISTER_IO) { > - // > - // Get SMM Revision ID > - // > - ReadSaveStateRegisterByIndex (CpuIndex, > SMM_SAVE_STATE_REGISTER_SMMREVID_INDEX, sizeof (SmmRevId), > &SmmRevId); > - > - // > - // See if the CPU supports the IOMisc register in the save state > - // > - if (SmmRevId < SMRAM_SAVE_STATE_MIN_REV_ID_IOMISC) { > - return EFI_NOT_FOUND; > - } > - > - // > - // Get the IOMisc register value > - // > - ReadSaveStateRegisterByIndex (CpuIndex, > SMM_SAVE_STATE_REGISTER_IOMISC_INDEX, sizeof (IoMisc.Uint32), > &IoMisc.Uint32); > - > - // > - // Check for the SMI_FLAG in IOMisc > - // > - if (IoMisc.Bits.SmiFlag =3D=3D 0) { > - return EFI_NOT_FOUND; > - } > - > - // > - // Only support IN/OUT, but not INS/OUTS/REP INS/REP OUTS. > - // > - if ((mSmmCpuIoType[IoMisc.Bits.Type] !=3D > EFI_SMM_SAVE_STATE_IO_TYPE_INPUT) && > - (mSmmCpuIoType[IoMisc.Bits.Type] !=3D > EFI_SMM_SAVE_STATE_IO_TYPE_OUTPUT)) > - { > - return EFI_NOT_FOUND; > - } > - > - // > - // Compute index for the I/O Length and I/O Type lookup tables > - // > - if ((mSmmCpuIoWidth[IoMisc.Bits.Length].Width =3D=3D 0) || > (mSmmCpuIoType[IoMisc.Bits.Type] =3D=3D 0)) { > - return EFI_NOT_FOUND; > - } > - > - // > - // Make sure the incoming buffer is large enough to hold IoInfo befo= re > accessing > - // > - if (Width < sizeof (EFI_SMM_SAVE_STATE_IO_INFO)) { > - return EFI_INVALID_PARAMETER; > - } > - > - // > - // Zero the IoInfo structure that will be returned in Buffer > - // > - IoInfo =3D (EFI_SMM_SAVE_STATE_IO_INFO *)Buffer; > - ZeroMem (IoInfo, sizeof (EFI_SMM_SAVE_STATE_IO_INFO)); > - > - // > - // Use lookup tables to help fill in all the fields of the IoInfo st= ructure > - // > - IoInfo->IoPort =3D (UINT16)IoMisc.Bits.Port; > - IoInfo->IoWidth =3D mSmmCpuIoWidth[IoMisc.Bits.Length].IoWidth; > - IoInfo->IoType =3D mSmmCpuIoType[IoMisc.Bits.Type]; > - ReadSaveStateRegister (CpuIndex, > EFI_SMM_SAVE_STATE_REGISTER_RAX, > mSmmCpuIoWidth[IoMisc.Bits.Length].Width, &IoInfo->IoData); > - return EFI_SUCCESS; > - } > - > - // > - // Convert Register to a register lookup table index > - // > - return ReadSaveStateRegisterByIndex (CpuIndex, GetRegisterIndex > (Register), Width, Buffer); -} > - > -/** > - Write value to a CPU Save State register on the target processor. > - > - This function abstracts the differences that whether the CPU Save Stat= e > register is in the > - IA32 CPU Save State Map or X64 CPU Save State Map. > - > - This function supports writing a CPU Save State register in SMBase > relocation handler. > - > - @param[in] CpuIndex Specifies the zero-based index of the CPU sa= ve > state. > - @param[in] RegisterIndex Index into mSmmCpuWidthOffset[] look up > table. > - @param[in] Width The number of bytes to read from the CPU sav= e > state. > - @param[in] Buffer Upon entry, this holds the new CPU register = value. > - > - @retval EFI_SUCCESS The register was written to Save State. > - @retval EFI_NOT_FOUND The register is not defined for the Save= State > of Processor. > - @retval EFI_INVALID_PARAMETER ProcessorIndex or Width is not correct. > - > -**/ > -EFI_STATUS > -EFIAPI > -WriteSaveStateRegister ( > - IN UINTN CpuIndex, > - IN EFI_SMM_SAVE_STATE_REGISTER Register, > - IN UINTN Width, > - IN CONST VOID *Buffer > - ) > -{ > - UINTN RegisterIndex; > - SMRAM_SAVE_STATE_MAP *CpuSaveState; > - > - // > - // Writes to EFI_SMM_SAVE_STATE_REGISTER_LMA are ignored > - // > - if (Register =3D=3D EFI_SMM_SAVE_STATE_REGISTER_LMA) { > - return EFI_SUCCESS; > - } > - > - // > - // Writes to EFI_SMM_SAVE_STATE_REGISTER_IO are not supported > - // > - if (Register =3D=3D EFI_SMM_SAVE_STATE_REGISTER_IO) { > - return EFI_NOT_FOUND; > - } > - > - // > - // Convert Register to a register lookup table index > - // > - RegisterIndex =3D GetRegisterIndex (Register); > - if (RegisterIndex =3D=3D 0) { > - return EFI_NOT_FOUND; > - } > - > - CpuSaveState =3D gSmst->CpuSaveState[CpuIndex]; > - > - // > - // Do not write non-writable SaveState, because it will cause exceptio= n. > - // > - if (!mSmmCpuWidthOffset[RegisterIndex].Writeable) { > - return EFI_UNSUPPORTED; > - } > - > - // > - // Check CPU mode > - // > - if (mSmmSaveStateRegisterLma =3D=3D > EFI_SMM_SAVE_STATE_REGISTER_LMA_32BIT) { > - // > - // If 32-bit mode width is zero, then the specified register can not= be > accessed > - // > - if (mSmmCpuWidthOffset[RegisterIndex].Width32 =3D=3D 0) { > - return EFI_NOT_FOUND; > - } > - > - // > - // If Width is bigger than the 32-bit mode width, then the specified > register can not be accessed > - // > - if (Width > mSmmCpuWidthOffset[RegisterIndex].Width32) { > - return EFI_INVALID_PARAMETER; > - } > - > - // > - // Write SMM State register > - // > - ASSERT (CpuSaveState !=3D NULL); > - CopyMem ((UINT8 *)CpuSaveState + > mSmmCpuWidthOffset[RegisterIndex].Offset32, Buffer, Width); > - } else { > - // > - // If 64-bit mode width is zero, then the specified register can not= be > accessed > - // > - if (mSmmCpuWidthOffset[RegisterIndex].Width64 =3D=3D 0) { > - return EFI_NOT_FOUND; > - } > - > - // > - // If Width is bigger than the 64-bit mode width, then the specified > register can not be accessed > - // > - if (Width > mSmmCpuWidthOffset[RegisterIndex].Width64) { > - return EFI_INVALID_PARAMETER; > - } > - > - // > - // Write at most 4 of the lower bytes of SMM State register > - // > - CopyMem ((UINT8 *)CpuSaveState + > mSmmCpuWidthOffset[RegisterIndex].Offset64Lo, Buffer, MIN (4, Width)); > - if (Width > 4) { > - // > - // Write at most 4 of the upper bytes of SMM State register > - // > - CopyMem ((UINT8 *)CpuSaveState + > mSmmCpuWidthOffset[RegisterIndex].Offset64Hi, (UINT8 *)Buffer + 4, > Width - 4); > - } > - } > - > - return EFI_SUCCESS; > -} > - > /** > Hook the code executed immediately after an RSM instruction on the > currently > executing CPU. The mode of code executed immediately after RSM must > be > -- > 2.25.1 >=20 >=20 >=20 >=20 >=20