From nobody Fri Apr 19 02:57:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+104791+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1683894757500903.2857210589325; Fri, 12 May 2023 05:32:37 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id r3AYYY1788612xg91IAEUEM4; Fri, 12 May 2023 05:32:37 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.62]) by mx.groups.io with SMTP id smtpd.web10.23674.1683894756154042912 for ; Fri, 12 May 2023 05:32:36 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SgURxBkGknB4fm2y+oYNB6XzDxSmUUtEPwh0+rLLuY+kCyVhvhYwgR3xgH2q0UT5CTxNJx0Ye5awdDIHtgRUu2Aspn6ODMDTEK1S0U69seRZga0YSWFOYBufAN6sGQQef+A/+SU+dXjnhFtlhUTjIHxFuzyfr7qUFdnXUphSJbY9eLXLKt8qBnFj6QCh3jTk6Vv3H4bdcQtKtknUAj9WVmrEnEJeMz2nWZrw2DQ0W+aZQ8bcnt0kWkItZAGJLD3cKXdFEphZRWc6bHChT2uRejY2gCrVSH8YFbfWDWkDmOgMsDclceBAnzM6yka+XwnWs77zC1MJPz6CkchCSTRQMg== 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=FTwyvOn/+HPGKUKHzOjqnv7CQ5gc+6NhOMfay/Xw3dQ=; b=iAuQu/hXJiHQWfm7z3r/6zYrUYHjIk3Tc+S+IJIeQ6QRHp+BSD4dYrMwKO+j+/0RkZGf2I6sLhhq2MG1ZPnY8IxW5rc2GrSzjWxRt6t7rerm7v+4guW1Rgf9pLgEszChBz3K9b5VgEbmEYQlxr+Qm+VNqYJ4vGJ2Z0l8B0YdABiYrcsA7e5C+jYiTiWPeJXjLeKGaD14I+BbzZrYIc96B8t6UElhh2MzDcynoxxMOtN/xY6r8YXniM7T8K28d2ZNEx20VdKSqbfXdfhKq/22DNKfjWEN8osffMWay904EvtUr1V7duhmGuG2VN/wC/gmxxLgpFzDSWJXspqjjJUKHg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none X-Received: from MW4PR03CA0220.namprd03.prod.outlook.com (2603:10b6:303:b9::15) by PH7PR12MB6859.namprd12.prod.outlook.com (2603:10b6:510:1b5::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.18; Fri, 12 May 2023 12:32:33 +0000 X-Received: from CO1NAM11FT026.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b9:cafe::a8) by MW4PR03CA0220.outlook.office365.com (2603:10b6:303:b9::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.22 via Frontend Transport; Fri, 12 May 2023 12:32:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+104791+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT026.mail.protection.outlook.com (10.13.175.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6387.23 via Frontend Transport; Fri, 12 May 2023 12:32:33 +0000 X-Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Fri, 12 May 2023 07:32:32 -0500 X-Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Fri, 12 May 2023 05:32:31 -0700 X-Received: from BLR-LAB-SFW01.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Fri, 12 May 2023 07:32:29 -0500 From: "Abdul Lateef Attar via groups.io" To: CC: Abdul Lateef Attar , Paul Grimes , Abner Chang , Michael D Kinney , Liming Gao , Zhiguang Liu Subject: [edk2-devel] [PATCH v13 1/8] MdePkg: Adds AMD SMRAM save state map Date: Fri, 12 May 2023 18:02:17 +0530 Message-ID: <473338120870fd04d0c8dbcda86c124a42bf1bc9.1683894329.git.abdattar@amd.com> In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT026:EE_|PH7PR12MB6859:EE_ X-MS-Office365-Filtering-Correlation-Id: f4364e14-6b58-4af2-b196-08db52e4f5c4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: NH3G90fmtXF9xaYriwxsJFkzDFQFEJPI8G4sUJO5IikEuwOdrTIpDa6scUkIGDasfjBRrH91uGAto9e6RfS8RJ71b/y3JeLOe9OXSFL1Bb8t5t5qUrquMkxWlF+Lptzjamu7Z6uU1shoY9WbJdCHs5dNs4MJgqw3FxNhmevjuw28fRdPH33DJ/TZNj0GStFTn36r0JYD0xVVqCw/VWbC8Bvvv2r9H3e8avu/Ew4DTFYDd9mVwhNBm2+Azn4M7odEUFTAsSm/md4ZWgi9yx6WTMzn1hW6DjApk+dK+i1ZY8xeLZcGLVwxLJaquBQVaCuiscrrZHFcWZRFowqR/3uENHC4Mi332OWCySXdMYxz6ShhI78t2esXrWdcPuRmsQyZvhTqg2qMr2X2X8KVsU4bldVSOwOjr1z1fjcGBwTaPNfIcWgmb9azrwB60Bb8snFkkS1IMUmLx+iH46Odj6FxIZJy3/nnVGPE+EOvKERVLOYEDZHFURNs8fE1fONqLpTQTRjzNWANHNH+qOBEBHCGYwl0TKdQ6ZGB3O4gG3+DUqVr2t4kDvxb6AQn2NJWdKd1W8wDYFB4IJ+UPO9WG0SvpQJ4kuReAdFqWH1kJh0zwujbp7tLxaDd+EVEvGdJdwFGJoEDJMpnggu+Es8abNVbv6pycaYD6c5SddWrYnd65EAXgO68BvAvztgWmr3mxL7ywZ/US+vmgB+Hp6ZZI9qNxPcjSMYfQ2niVBMFcrPcCQ+gzh5P8dA3KnlBq7XNUo0Z X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 May 2023 12:32:33.0668 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f4364e14-6b58-4af2-b196-08db52e4f5c4 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT026.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6859 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,abdattar@amd.com X-Gm-Message-State: p5pwcGaiVnbHNmNVBscgmq36x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1683894757; bh=cDt5oQj84uzVlM8l65ON0I3mPzUXkwHD2R1iiFURcZ8=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=VOG8zILkgWH9yr9zSZZUvCKw4g+jw4NX5jALxtFkNVF82mVPLUrT8XT6zGwGooZP5M4 rpQe7S97hET8Ra6F05rjRfv9P3b9BzpYnOuxjqFF16xmCy033YoHGntcdNA4E1HWyu+OX KRw/ZIQ4BcaHl/quobSFzCs4Tc/iyXL0NmA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1683894758047100005 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4182 Adds an SMM SMRAM save-state map for AMD processors. SMRAM save state maps for the AMD processor family are now supported. Save state map structure is added based on AMD64 Architecture Programmer's Manual, Volume 2, Section 10.2. The AMD legacy save state map for 32-bit architecture is defined. The AMD64 save state map for 64-bit architecture is defined.=C2=A0 Also added Amd/SmramSaveStateMap.h to IgnoreFiles of EccCheck, because structures defined in this file are derived from Intel/SmramSaveStateMap.h. Cc: Paul Grimes Cc: Abner Chang Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Signed-off-by: Abdul Lateef Attar Reviewed-by: Abner Chang Reviewed-by: Michael D Kinney --- .../Include/Register/Amd/SmramSaveStateMap.h | 194 ++++++++++++++++++ MdePkg/MdePkg.ci.yaml | 4 +- 2 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 MdePkg/Include/Register/Amd/SmramSaveStateMap.h diff --git a/MdePkg/Include/Register/Amd/SmramSaveStateMap.h b/MdePkg/Inclu= de/Register/Amd/SmramSaveStateMap.h new file mode 100644 index 000000000000..0607d2a19145 --- /dev/null +++ b/MdePkg/Include/Register/Amd/SmramSaveStateMap.h @@ -0,0 +1,194 @@ +/** @file + AMD SMRAM Save State Map Definitions. + + SMRAM Save State Map definitions based on contents of the + AMD64 Architecture Programmer Manual: + Volume 2, System Programming, Section 10.2 SMM Resources + + Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.
+ Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved .
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef AMD_SMRAM_SAVE_STATE_MAP_H_ +#define AMD_SMRAM_SAVE_STATE_MAP_H_ + +/// +/// Default SMBASE address +/// +#define SMM_DEFAULT_SMBASE 0x30000 + +/// +/// Offset of SMM handler from SMBASE +/// +#define SMM_HANDLER_OFFSET 0x8000 + +// SMM-Revision Identifier for AMD64 Architecture. +#define AMD_SMM_MIN_REV_ID_X64 0x30064 + +#pragma pack (1) + +/// +/// 32-bit SMRAM Save State Map +/// +typedef struct { + // Padded an extra 0x200 bytes to match Intel/EDK2 + UINT8 Reserved[0x200]; // fc00h + // AMD Save State area starts @ 0xfe00 + UINT8 Reserved1[0xf8]; // fe00h + UINT32 SMBASE; // fef8h + UINT32 SMMRevId; // fefch + UINT16 IORestart; // ff00h + UINT16 AutoHALTRestart; // ff02h + UINT8 Reserved2[0x84]; // ff04h + UINT32 GDTBase; // ff88h + UINT64 Reserved3; // ff8ch + UINT32 IDTBase; // ff94h + UINT8 Reserved4[0x10]; // ff98h + UINT32 _ES; // ffa8h + UINT32 _CS; // ffach + UINT32 _SS; // ffb0h + UINT32 _DS; // ffb4h + UINT32 _FS; // ffb8h + UINT32 _GS; // ffbch + UINT32 LDTBase; // ffc0h + UINT32 _TR; // ffc4h + UINT32 _DR7; // ffc8h + UINT32 _DR6; // ffcch + UINT32 _EAX; // ffd0h + UINT32 _ECX; // ffd4h + UINT32 _EDX; // ffd8h + UINT32 _EBX; // ffdch + UINT32 _ESP; // ffe0h + UINT32 _EBP; // ffe4h + UINT32 _ESI; // ffe8h + UINT32 _EDI; // ffech + UINT32 _EIP; // fff0h + UINT32 _EFLAGS; // fff4h + UINT32 _CR3; // fff8h + UINT32 _CR0; // fffch +} AMD_SMRAM_SAVE_STATE_MAP32; + +/// +/// 64-bit SMRAM Save State Map +/// +typedef struct { + // Padded an extra 0x200 bytes to match Intel/EDK2 + UINT8 Reserved[0x200]; // fc00h + // AMD Save State area starts @ 0xfe00 + UINT16 _ES; // fe00h + UINT16 _ESAttributes; // fe02h + UINT32 _ESLimit; // fe04h + UINT64 _ESBase; // fe08h + + UINT16 _CS; // fe10h + UINT16 _CSAttributes; // fe12h + UINT32 _CSLimit; // fe14h + UINT64 _CSBase; // fe18h + + UINT16 _SS; // fe20h + UINT16 _SSAttributes; // fe22h + UINT32 _SSLimit; // fe24h + UINT64 _SSBase; // fe28h + + UINT16 _DS; // fe30h + UINT16 _DSAttributes; // fe32h + UINT32 _DSLimit; // fe34h + UINT64 _DSBase; // fe38h + + UINT16 _FS; // fe40h + UINT16 _FSAttributes; // fe42h + UINT32 _FSLimit; // fe44h + UINT64 _FSBase; // fe48h + + UINT16 _GS; // fe50h + UINT16 _GSAttributes; // fe52h + UINT32 _GSLimit; // fe54h + UINT64 _GSBase; // fe58h + + UINT32 _GDTRReserved1; // fe60h + UINT16 _GDTRLimit; // fe64h + UINT16 _GDTRReserved2; // fe66h + // UINT64 _GDTRBase; // fe68h + UINT32 _GDTRBaseLoDword; + UINT32 _GDTRBaseHiDword; + + UINT16 _LDTR; // fe70h + UINT16 _LDTRAttributes; // fe72h + UINT32 _LDTRLimit; // fe74h + // UINT64 _LDTRBase; // fe78h + UINT32 _LDTRBaseLoDword; + UINT32 _LDTRBaseHiDword; + + UINT32 _IDTRReserved1; // fe80h + UINT16 _IDTRLimit; // fe84h + UINT16 _IDTRReserved2; // fe86h + // UINT64 _IDTRBase; // fe88h + UINT32 _IDTRBaseLoDword; + UINT32 _IDTRBaseHiDword; + + UINT16 _TR; // fe90h + UINT16 _TRAttributes; // fe92h + UINT32 _TRLimit; // fe94h + UINT64 _TRBase; // fe98h + + UINT64 IO_RIP; // fea0h + UINT64 IO_RCX; // fea8h + UINT64 IO_RSI; // feb0h + UINT64 IO_RDI; // feb8h + UINT32 IO_DWord; // fec0h + UINT8 Reserved1[0x04]; // fec4h + UINT8 IORestart; // fec8h + UINT8 AutoHALTRestart; // fec9h + UINT8 Reserved2[0x06]; // fecah + UINT64 EFER; // fed0h + UINT64 SVM_Guest; // fed8h + UINT64 SVM_GuestVMCB; // fee0h + UINT64 SVM_GuestVIntr; // fee8h + UINT8 Reserved3[0x0c]; // fef0h + UINT32 SMMRevId; // fefch + UINT32 SMBASE; // ff00h + UINT8 Reserved4[0x14]; // ff04h + UINT64 SSP; // ff18h + UINT64 SVM_GuestPAT; // ff20h + UINT64 SVM_HostEFER; // ff28h + UINT64 SVM_HostCR4; // ff30h + UINT64 SVM_HostCR3; // ff38h + UINT64 SVM_HostCR0; // ff40h + UINT64 _CR4; // ff48h + UINT64 _CR3; // ff50h + UINT64 _CR0; // ff58h + UINT64 _DR7; // ff60h + UINT64 _DR6; // ff68h + UINT64 _RFLAGS; // ff70h + UINT64 _RIP; // ff78h + UINT64 _R15; // ff80h + UINT64 _R14; // ff88h + UINT64 _R13; // ff90h + UINT64 _R12; // ff98h + UINT64 _R11; // ffa0h + UINT64 _R10; // ffa8h + UINT64 _R9; // ffb0h + UINT64 _R8; // ffb8h + UINT64 _RDI; // ffc0h + UINT64 _RSI; // ffc8h + UINT64 _RBP; // ffd0h + UINT64 _RSP; // ffd8h + UINT64 _RBX; // ffe0h + UINT64 _RDX; // ffe8h + UINT64 _RCX; // fff0h + UINT64 _RAX; // fff8h +} AMD_SMRAM_SAVE_STATE_MAP64; + +/// +/// Union of 32-bit and 64-bit SMRAM Save State Maps +/// +typedef union { + AMD_SMRAM_SAVE_STATE_MAP32 x86; + AMD_SMRAM_SAVE_STATE_MAP64 x64; +} AMD_SMRAM_SAVE_STATE_MAP; + +#pragma pack () + +#endif diff --git a/MdePkg/MdePkg.ci.yaml b/MdePkg/MdePkg.ci.yaml index f024b48685ef..c3faf4913d75 100644 --- a/MdePkg/MdePkg.ci.yaml +++ b/MdePkg/MdePkg.ci.yaml @@ -5,6 +5,7 @@ # Copyright (c) 2020, Intel Corporation. All rights reserved.
# Copyright (c) 2021, Arm Limited. All rights reserved.
# Copyright (c) 2023, Loongson Technology Corporation Limited. All rights = reserved.
+# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent ## { @@ -72,7 +73,8 @@ "Include/Protocol/DebugSupport.h", "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c", "Library/BaseFdtLib", - "Library/MipiSysTLib/mipi_syst.h" + "Library/MipiSysTLib/mipi_syst.h", + "Include/Register/Amd/SmramSaveStateMap.h" ] }, ## options defined ci/Plugin/CompilerPlugin --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#104791): https://edk2.groups.io/g/devel/message/104791 Mute This Topic: https://groups.io/mt/98848073/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri Apr 19 02:57:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+104792+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1683894760326990.6864026532008; Fri, 12 May 2023 05:32:40 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id N2UHYY1788612xtdxWvQf7S4; Fri, 12 May 2023 05:32:40 -0700 X-Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.107.243.86]) by mx.groups.io with SMTP id smtpd.web10.23678.1683894759363238784 for ; Fri, 12 May 2023 05:32:39 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e24KrTx5lCBosqGvRLx16y6ummWFj7OspdbqVY0V6+0o4GXJeczCiOnObZvYK/elqYv0bNwpILleTZbCpvapkhBo5UZ94NkCbPBdjY5BmTyV8SdkS7t3uQjHlfP5jQeWiR1JNZ1eWNtb0H7aiypqdUYYK5hPYNsAePdo/LJn+WkE7Jau8pkXCfyoHKKCSlDIgyAA29Zjvuqp6iGMh/4oOIUjx0nJDeEpXpgMGcK14b3sCEqagQLDrSKXvnaEXzpCYpmaLMDvRcWj7nVJ1H1CAVP9Tx/msk+D5uunoiD54MyyFwI9CeRPQVMetHMu7mnJyydAYfVJVB4n3+m+OxmTjA== 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=DU3VZz8VPjQ11F3Hm1Y4TJpKbLPd5rDxldr2wEBzjlc=; b=ZhtBnZC7LXLOg0BamNF38uYnT1C2+scLGc6GvP5fovgsLw2C/zgTi6vB9X9raTillufOm3B5bgdAAfGorXwAowZlvYNWTnWUTVD4NkgR/ExW830ZUxH+MhV6Zai5XByHEtoA+pimk1ZvR2Uj8lYZLJ1/G9x67jqu2mm7Ex0kMvqCS0zOxOBUPU5Lhmvp81eNqY9JZnR2eHuNs4RJxkn5zzn86elEY4T4NZsQXrFNKaEMxVov/KS4U8BB4GUyFgNdNjNq1pSbxnwsVf1DITO2gX38EkYpkGyc8AUADxwDyu5ZAtI9u4rYLyIk/FxjKTHowj11+mOr03Kx2FfulMQ3yg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none X-Received: from MW4PR03CA0238.namprd03.prod.outlook.com (2603:10b6:303:b9::33) by SJ0PR12MB5456.namprd12.prod.outlook.com (2603:10b6:a03:3ae::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.24; Fri, 12 May 2023 12:32:36 +0000 X-Received: from CO1NAM11FT003.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b9:cafe::e3) by MW4PR03CA0238.outlook.office365.com (2603:10b6:303:b9::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.24 via Frontend Transport; Fri, 12 May 2023 12:32:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+104792+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C X-Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT003.mail.protection.outlook.com (10.13.175.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6387.24 via Frontend Transport; Fri, 12 May 2023 12:32:35 +0000 X-Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Fri, 12 May 2023 07:32:34 -0500 X-Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Fri, 12 May 2023 05:32:34 -0700 X-Received: from BLR-LAB-SFW01.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Fri, 12 May 2023 07:32:32 -0500 From: "Abdul Lateef Attar via groups.io" To: CC: Abdul Lateef Attar , Paul Grimes , Abner Chang , Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH v13 2/8] UefiCpuPkg: Adds MmSaveStateLib library class Date: Fri, 12 May 2023 18:02:18 +0530 Message-ID: <4f182847f78b0bd999bf3b1a2ab5da7659303ed2.1683894329.git.abdattar@amd.com> In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT003:EE_|SJ0PR12MB5456:EE_ X-MS-Office365-Filtering-Correlation-Id: 5120caa6-6a25-4b4c-af8a-08db52e4f74c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: Luj1fsiZ0g2SW7CbeLk7GJGRDIJODBASxJMIHfyePImw1rIlsLYckps4BZb7EUAW6jkE8Vj3msuP8jnlbKLxfhTd3yMmgmvi0dJyjzISb/8LShtdIAtOXKtW73z+2FYkp7vn5cWq5m6YjFvojTyXszNEC1y/8OuTXSHrW/YRoiNEcQjUdB/PlLYGoxQsvK53q+HxMv9Fb4G2Pciyc1EpKSpOQfm/70dhng+0mHNbYEaypOyJHo3XBw3EyJHSU8Gea/qNaMAb/awX6JSqgk0WaUT3S/2Oj67a6nBLZTxGhFGDJnykwAXJuAjESubBVXDM45WBlKF2auSYzdsUphvXtbj5kbWTpo99/PZSsd401Wp1HJMdRCYmIkSbDB8reEYlWBf6xGzlmuZIRZfdhYC9lelSuTCiMzhs6VxY31Rus5/aEINmpvKT9dUJp80Vav3GMOt1uw5cT238F1A5eOtqMCVtwOFFZL/m/h5GqyDxSdi1TfYggubNhmUXY2gW4qqbLqrxd+yQTOxFya2YE4XJRH8dzyNxTPEEnhIygzvd7w9yQknoYRWXSmV/S6O6pCKP7wfR34TlgseIkqaeh3ztCFnlai982do8fiL7iymQD9++u2lTddAn4W5XlQMaZliXYyrzmB7QQ05dG3XK6xDk+mjRSOdL6kAtqVTYKk7nCWlfhWM0W7RZLS5O5aAbSzx/dp/L3Jsy0sDU5e35MCErmZ+KtJ0gLGaPTpguIWA74kOWM/Szbz9U55BzNqK4CP96 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 May 2023 12:32:35.6357 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5120caa6-6a25-4b4c-af8a-08db52e4f74c X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT003.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB5456 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,abdattar@amd.com X-Gm-Message-State: Dimkw04sHJlfazuRASQjGiz7x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1683894760; bh=sRF/OMlZSabI5y9v6qNU8GtWvLRV85vZMm9FMcwZSSg=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=GJz4jEarj/xXwfWrmWwVFYFikGz/6RlfmDWlJ8avFvRs29msm84M6keue+zFLlB9gPY 6Gr/W3TiGT3t0K+lciIHrJuADb7K8r2sau04WsWQ9SUAwLV8q+r4TDUQOHSE4qXmC8qJ1 hOgTNbu6Z8tj41jSkpuuD3l8S/TXc58HN18= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1683894760961100001 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4182 Adds MmSaveStateLib Library class in UefiCpuPkg.dec. Adds function declaration header file. Cc: Paul Grimes Cc: Abner Chang Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann Signed-off-by: Abdul Lateef Attar Reviewed-by: Abner Chang Reviewed-by: Ray Ni --- UefiCpuPkg/UefiCpuPkg.dec | 4 ++ UefiCpuPkg/Include/Library/MmSaveStateLib.h | 70 +++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 UefiCpuPkg/Include/Library/MmSaveStateLib.h diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index d31c3b127c0b..1f1b10e702bf 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -2,6 +2,7 @@ # This Package provides UEFI compatible CPU modules and libraries. # # Copyright (c) 2007 - 2023, Intel Corporation. All rights reserved.
+# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -60,6 +61,9 @@ [LibraryClasses.IA32, LibraryClasses.X64] ## @libraryclass Provides function for manipulating x86 paging structu= res. CpuPageTableLib|Include/Library/CpuPageTableLib.h =20 + ## @libraryclass Provides functions for manipulating smram savestate r= egisters. + MmSaveStateLib|Include/Library/MmSaveStateLib.h + [Guids] gUefiCpuPkgTokenSpaceGuid =3D { 0xac05bf33, 0x995a, 0x4ed4, { 0xaa,= 0xb8, 0xef, 0x7a, 0xe8, 0xf, 0x5c, 0xb0 }} gMsegSmramGuid =3D { 0x5802bce4, 0xeeee, 0x4e33, { 0xa1,= 0x30, 0xeb, 0xad, 0x27, 0xf0, 0xe4, 0x39 }} diff --git a/UefiCpuPkg/Include/Library/MmSaveStateLib.h b/UefiCpuPkg/Inclu= de/Library/MmSaveStateLib.h new file mode 100644 index 000000000000..6817fb3b9786 --- /dev/null +++ b/UefiCpuPkg/Include/Library/MmSaveStateLib.h @@ -0,0 +1,70 @@ +/** @file +Library that provides service to read/write CPU specific smram save state = registers. + +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 + +**/ + +#ifndef MM_SAVE_STATE_LIB_H_ +#define MM_SAVE_STATE_LIB_H_ + +#include +#include + +/** + Read a save state register on the target processor. If this function + returns EFI_UNSUPPORTED, then the caller is responsible for reading the + MM Save State register. + + @param[in] CpuIndex The index of the CPU to read the Save State regist= er. + The value must be between 0 and the NumberOfCpus f= ield in + the System Management System Table (SMST). + @param[in] Register The MM Save State register to read. + @param[in] Width The number of bytes to read from the CPU save stat= e. + @param[out] Buffer Upon return, this holds the CPU register value read + 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 Reg= ister. + @retval EFI_NOT_FOUND If desired Register not found. +**/ +EFI_STATUS +EFIAPI +MmSaveStateReadRegister ( + IN UINTN CpuIndex, + IN EFI_MM_SAVE_STATE_REGISTER Register, + IN UINTN Width, + OUT VOID *Buffer + ); + +/** + Writes a save state register on the target processor. If this function + returns EFI_UNSUPPORTED, then the caller is responsible for writing the + MM save state register. + + @param[in] CpuIndex The index of the CPU to write the MM Save State. T= he + value must be between 0 and the NumberOfCpus field = in + the System Management System Table (SMST). + @param[in] Register The MM Save State register to write. + @param[in] Width The number of bytes to write to the CPU save 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_INVALID_PARAMTER Buffer is NULL. + @retval EFI_UNSUPPORTED This function does not support writing Reg= ister. + @retval EFI_NOT_FOUND If desired Register not found. +**/ +EFI_STATUS +EFIAPI +MmSaveStateWriteRegister ( + IN UINTN CpuIndex, + IN EFI_MM_SAVE_STATE_REGISTER Register, + IN UINTN Width, + IN CONST VOID *Buffer + ); + +#endif --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#104792): https://edk2.groups.io/g/devel/message/104792 Mute This Topic: https://groups.io/mt/98848075/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri Apr 19 02:57:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+104793+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 16838947654839.587689921825472; Fri, 12 May 2023 05:32:45 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id BDOtYY1788612xbxxEoUHFm0; Fri, 12 May 2023 05:32:45 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.72]) by mx.groups.io with SMTP id smtpd.web10.23680.1683894764477896632 for ; Fri, 12 May 2023 05:32:44 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nzKzvT+V72CXyoxtTbLUzddiFZlGFAV+J9Xho0vEKJMRlkCXi3EskxXQxS3z7fybBXlzHpH6YROAbwqwpwXGqiQR1BaLaO9ESy7XW3Hx/UY/L77AEV0dU37yI5yi7mzQVYYsy8dJ/bl368XOxO9Y63hSrpT604PK2HXM8DMYWpRh78zj57AYMw86sXlvnWJWPqHMXPmSOSEaeQRhmxXvkNv5EsU+JEZGjzpuim81o2FM5fMw84pqqPn40O3TuJVntGny/bYxDge3M7eC6EaDd9Zff8avP+El/RY4A5SAvwLl2eqxY7w0VEjexwN5OOfkt+IBvysAljlUtilzdgROMg== 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=pD36JWBG6F5bOw73XD+w8ez6BvHrcJP9jY2lNLQ8314=; b=Az3HEQolWha+nES21ZJtcyK7v1Zw/983YXTURIBQYroT2GjlFfVh2iy8yOwBCjAPS6yI+LmRAJqpf26tv1vNSPr4RFKsbq2pgcdSt9IIh/aTtPFut0iJCdKyCYBTu6VYKNCEm3yBtZjtyjM+jPwuDnOMQkZJixucNyONe3qF78MvfsaNUVGDRoORBB/PXswH23RFYuttkiguRIg+IbntNTf9pYKu/Gqk4cYYrfRl637ohX76DaQoMPlAhIrZQsyIiilq4QlAbdKFSeofRaXrkI8ykHY/P29m+kGpLkyvAmk4GiQeuot/sKKdFuKxCd0TrSpfSGvXQX/jH/QpzYUsig== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none X-Received: from MW4PR03CA0240.namprd03.prod.outlook.com (2603:10b6:303:b9::35) by PH7PR12MB5829.namprd12.prod.outlook.com (2603:10b6:510:1d4::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.32; Fri, 12 May 2023 12:32:39 +0000 X-Received: from CO1NAM11FT026.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b9:cafe::35) by MW4PR03CA0240.outlook.office365.com (2603:10b6:303:b9::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.24 via Frontend Transport; Fri, 12 May 2023 12:32:39 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+104793+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT026.mail.protection.outlook.com (10.13.175.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6387.23 via Frontend Transport; Fri, 12 May 2023 12:32:39 +0000 X-Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Fri, 12 May 2023 07:32:37 -0500 X-Received: from BLR-LAB-SFW01.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Fri, 12 May 2023 07:32:34 -0500 From: "Abdul Lateef Attar via groups.io" To: CC: Abdul Lateef Attar , Paul Grimes , Abner Chang , Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann , "Abdul Lateef Attar" Subject: [edk2-devel] [PATCH v13 3/8] UefiCpuPkg: Implements MmSaveStateLib library instance Date: Fri, 12 May 2023 18:02:19 +0530 Message-ID: <92841c687411ba82c9ec07b11098e994fd41b3f2.1683894329.git.abdattar@amd.com> In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT026:EE_|PH7PR12MB5829:EE_ X-MS-Office365-Filtering-Correlation-Id: 0a7c7329-20b2-45ac-d7ef-08db52e4f968 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: lOiu9W6+3F69yK4NHYLTn+2a+4vCQPTc4bu+G6UWjsoi9ir6P7yYCTCRT8rom1vWfU4sa7Zis6LYjTkrTHBJIC8IH/d2ql40zTbaloPMN+N4zGkUCYfagbyKiqWunZrOKG2QuSgDV6X1N2k/9LYveYWofuwpmNk9hzBnZk/KVHwZhm4k/BZpfVDVRCNxTTn+gIObYvzBZ2W99f3zt/h8jFruo2JSMhSCZLjkF2ziQJInLSUhCAXPbdovmETMXlDrPHxewfRR/2ICiTKTDYS87Xt52ItRqmgXkBdNlHpjiszFg9PAMssFfiKes2xCXIceysteOr/BS9/72eJe7MlBuMgSHSssnC/Z7kqACLw04gxHB5Ph2zSxcLUlLr2cBeh5tFmvSO3v2BU00mo6jVlDbMjz5BxRWyQ1/e/s/I746E/mT2sJXGecm1qWoSb90+VP+/PKwxkIFMflfOnCNptH9MMKf7aT6ngGfzWQrMe6n5HhweviJ96IfTGTkuUxATJ8nVcDF4FsJR58o1uq8VtRHhqdJEBf3Z+2JIS5EZHi/Adc5E4yZaSHa9KB1rAK2is6shFIv1Sy4Dv1GVorVIzCJ/fOP69Rw6wSPjZScBflHdb2jHuqEfrFPDK2X6HUcoXSAMA6nhmffAzz5YqPV8VAN/I0NrXjr2/Izgh9vbuZ3R3ovgPBVBm7N8giyTLNz0hDWL9DQgcGyV/RmaUdz5Ktw7SizFa1oFqmT2SgxRUpwaI= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 May 2023 12:32:39.1757 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0a7c7329-20b2-45ac-d7ef-08db52e4f968 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT026.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5829 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,abdattar@amd.com X-Gm-Message-State: PjAGRZpivbeniCVYQ2PyRIjqx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1683894765; bh=49im0+CKQLkzS575l9XohBg4GJv9AXdoRarxtBpRCbw=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=P829R54x+PIccub7JDqprtjrNcZ8se1PXwNkVoKG00hD+iSP2weRutNUoWh5fQmPNDf l57IJq5J/lODpVDkMtepOmylmNnRDkdAqYg1yCIo/Hp+Vryd4QelFL+fNHJzw5J58GF0R Q9oKnjo6W0N6EuW4OdNch5/LvQobfhIkHD8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1683894766127100001 Content-Type: text/plain; charset="utf-8" From: Abdul Lateef Attar BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4182 Implements MmSaveStateLib Library class for AMD cpu family. Cc: Paul Grimes Cc: Abner Chang Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann Signed-off-by: Abdul Lateef Attar Reviewed-by: Abner Chang --- UefiCpuPkg/UefiCpuPkg.dsc | 3 + .../MmSaveStateLib/AmdMmSaveStateLib.inf | 34 ++ .../Library/MmSaveStateLib/MmSaveState.h | 94 ++++++ .../Library/MmSaveStateLib/AmdMmSaveState.c | 309 ++++++++++++++++++ .../MmSaveStateLib/MmSaveStateCommon.c | 132 ++++++++ 5 files changed, 572 insertions(+) create mode 100644 UefiCpuPkg/Library/MmSaveStateLib/AmdMmSaveStateLib.inf create mode 100644 UefiCpuPkg/Library/MmSaveStateLib/MmSaveState.h create mode 100644 UefiCpuPkg/Library/MmSaveStateLib/AmdMmSaveState.c create mode 100644 UefiCpuPkg/Library/MmSaveStateLib/MmSaveStateCommon.c diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index 593c11cc7482..8b0cb02a80e8 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -2,6 +2,7 @@ # UefiCpuPkg Package # # Copyright (c) 2007 - 2022, Intel Corporation. All rights reserved.
+# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -99,6 +100,7 @@ [LibraryClasses.common.DXE_SMM_DRIVER] MemoryAllocationLib|MdePkg/Library/SmmMemoryAllocationLib/SmmMemoryAlloc= ationLib.inf HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuE= xceptionHandlerLib.inf + MmSaveStateLib|UefiCpuPkg/Library/MmSaveStateLib/AmdMmSaveStateLib.inf =20 [LibraryClasses.common.MM_STANDALONE] MmServicesTableLib|MdePkg/Library/StandaloneMmServicesTableLib/Standalon= eMmServicesTableLib.inf @@ -182,6 +184,7 @@ [Components.IA32, Components.X64] UnitTestResultReportLib|UnitTestFrameworkPkg/Library/UnitTestResultR= eportLib/UnitTestResultReportLibConOut.inf } + UefiCpuPkg/Library/MmSaveStateLib/AmdMmSaveStateLib.inf =20 [Components.X64] UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandle= rLibUnitTest.inf diff --git a/UefiCpuPkg/Library/MmSaveStateLib/AmdMmSaveStateLib.inf b/Uefi= CpuPkg/Library/MmSaveStateLib/AmdMmSaveStateLib.inf new file mode 100644 index 000000000000..5c0685f283d3 --- /dev/null +++ b/UefiCpuPkg/Library/MmSaveStateLib/AmdMmSaveStateLib.inf @@ -0,0 +1,34 @@ +## @file +# MM Smram save state service lib. +# +# This is MM Smram save state service lib that provide service to read and +# save savestate area registers. +# +# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D AmdMmSaveStateLib + FILE_GUID =3D FB7D0A60-E8D4-4EFA-90AA-B357BC569879 + MODULE_TYPE =3D DXE_SMM_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D MmSaveStateLib + +[Sources] + MmSaveState.h + MmSaveStateCommon.c + AmdMmSaveState.c + +[Packages] + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + SmmServicesTableLib diff --git a/UefiCpuPkg/Library/MmSaveStateLib/MmSaveState.h b/UefiCpuPkg/L= ibrary/MmSaveStateLib/MmSaveState.h new file mode 100644 index 000000000000..c3499cbb3b17 --- /dev/null +++ b/UefiCpuPkg/Library/MmSaveStateLib/MmSaveState.h @@ -0,0 +1,94 @@ +/** @file + SMRAM Save State Map header file. + + 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 + +**/ + +#ifndef MM_SAVESTATE_H_ +#define MM_SAVESTATE_H_ + +#include +#include +#include +#include +#include +#include + +// Macro used to simplify the lookup table entries of type CPU_MM_SAVE_STA= TE_REGISTER_RANGE +#define MM_REGISTER_RANGE(Start, End) { Start, End, End - Start + 1 } + +// Structure used to describe a range of registers +typedef struct { + EFI_MM_SAVE_STATE_REGISTER Start; + EFI_MM_SAVE_STATE_REGISTER End; + UINTN Length; +} CPU_MM_SAVE_STATE_REGISTER_RANGE; + +// Structure used to build a lookup table to retrieve the widths and offse= ts +// associated with each supported EFI_MM_SAVE_STATE_REGISTER value + +typedef struct { + UINT8 Width32; + UINT8 Width64; + UINT16 Offset32; + UINT16 Offset64Lo; + UINT16 Offset64Hi; + BOOLEAN Writeable; +} CPU_MM_SAVE_STATE_LOOKUP_ENTRY; + +/** + Returns LMA value of the Processor. + + @retval UINT8 returns LMA bit value. +**/ +UINT8 +MmSaveStateGetRegisterLma ( + VOID + ); + +/** + Read information from the CPU save state. + + @param Register Specifies the CPU register to read form the save state. + @param RegOffset Offset for the next register index. + + @retval 0 Register is not valid + @retval >0 Index into mCpuWidthOffset[] associated with Register + +**/ +UINTN +MmSaveStateGetRegisterIndex ( + IN EFI_MM_SAVE_STATE_REGISTER Register, + IN UINTN RegOffset + ); + +/** + 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 reloc= ation handler. + + @param[in] CpuIndex Specifies the zero-based index of the CPU sav= e state. + @param[in] RegisterIndex Index into mCpuWidthOffset[] 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_PARAMTER This or Buffer is NULL. + +**/ +EFI_STATUS +MmSaveStateReadRegisterByIndex ( + IN UINTN CpuIndex, + IN UINTN RegisterIndex, + IN UINTN Width, + OUT VOID *Buffer + ); + +#endif diff --git a/UefiCpuPkg/Library/MmSaveStateLib/AmdMmSaveState.c b/UefiCpuPk= g/Library/MmSaveStateLib/AmdMmSaveState.c new file mode 100644 index 000000000000..9fed52896f5c --- /dev/null +++ b/UefiCpuPkg/Library/MmSaveStateLib/AmdMmSaveState.c @@ -0,0 +1,309 @@ +/** @file +Provides services to access SMRAM Save State Map + +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 + +**/ + +#include "MmSaveState.h" +#include +#include + +// EFER register LMA bit +#define LMA BIT10 +#define EFER_ADDRESS 0xC0000080ul +#define AMD_MM_SAVE_STATE_REGISTER_SMMREVID_INDEX 1 +#define AMD_MM_SAVE_STATE_REGISTER_MAX_INDEX 2 + +// Macro used to simplify the lookup table entries of type CPU_MM_SAVE_STA= TE_LOOKUP_ENTRY +#define MM_CPU_OFFSET(Field) OFFSET_OF (AMD_SMRAM_SAVE_STATE_MAP, Field) + +// Lookup table used to retrieve the widths and offsets associated with ea= ch +// supported EFI_MM_SAVE_STATE_REGISTER value +CONST CPU_MM_SAVE_STATE_LOOKUP_ENTRY mCpuWidthOffset[] =3D { + { 0, 0, 0, 0, = FALSE }, // Reserved + + // + // Internally defined CPU Save State Registers. Not defined in PI SMM CP= U Protocol. + // + { 4, 4, MM_CPU_OFFSET (x86.SMMRevId), MM_CPU_OFFSET (x64.SMMRevId), = 0, FALSE}, // AMD_MM_SAVE_STATE_RE= GISTER_SMMREVID_INDEX =3D 1 + + // + // CPU Save State registers defined in PI SMM CPU Protocol. + // + { 4, 8, MM_CPU_OFFSET (x86.GDTBase), MM_CPU_OFFSET (x64._GDTRBaseLoDwor= d), MM_CPU_OFFSET (x64._GDTRBaseHiDword), FALSE}, // EFI_MM_SAVE_STATE_R= EGISTER_GDTBASE =3D 4 + { 0, 8, 0, MM_CPU_OFFSET (x64._IDTRBaseLoDwor= d), MM_CPU_OFFSET (x64._IDTRBaseLoDword), FALSE}, // EFI_MM_SAVE_STATE_R= EGISTER_IDTBASE =3D 5 + { 0, 8, 0, MM_CPU_OFFSET (x64._LDTRBaseLoDwor= d), MM_CPU_OFFSET (x64._LDTRBaseLoDword), FALSE}, // EFI_MM_SAVE_STATE_R= EGISTER_LDTBASE =3D 6 + { 0, 2, 0, MM_CPU_OFFSET (x64._GDTRLimit), = 0, FALSE}, // EFI_MM_SAVE_STATE_R= EGISTER_GDTLIMIT =3D 7 + { 0, 2, 0, MM_CPU_OFFSET (x64._IDTRLimit), = 0, FALSE}, // EFI_MM_SAVE_STATE_R= EGISTER_IDTLIMIT =3D 8 + { 0, 4, 0, MM_CPU_OFFSET (x64._LDTRLimit), = 0, FALSE}, // EFI_MM_SAVE_STATE_R= EGISTER_LDTLIMIT =3D 9 + { 0, 0, 0, 0, = 0, FALSE}, // EFI_MM_SAVE_STATE_R= EGISTER_LDTINFO =3D 10 + { 4, 2, MM_CPU_OFFSET (x86._ES), MM_CPU_OFFSET (x64._ES), = 0, FALSE}, // EFI_MM_SAVE_STATE_R= EGISTER_ES =3D 20 + { 4, 2, MM_CPU_OFFSET (x86._CS), MM_CPU_OFFSET (x64._CS), = 0, FALSE}, // EFI_MM_SAVE_STATE_R= EGISTER_CS =3D 21 + { 4, 2, MM_CPU_OFFSET (x86._SS), MM_CPU_OFFSET (x64._SS), = 0, FALSE}, // EFI_MM_SAVE_STATE_R= EGISTER_SS =3D 22 + { 4, 2, MM_CPU_OFFSET (x86._DS), MM_CPU_OFFSET (x64._DS), = 0, FALSE}, // EFI_MM_SAVE_STATE_R= EGISTER_DS =3D 23 + { 4, 2, MM_CPU_OFFSET (x86._FS), MM_CPU_OFFSET (x64._FS), = 0, FALSE}, // EFI_MM_SAVE_STATE_R= EGISTER_FS =3D 24 + { 4, 2, MM_CPU_OFFSET (x86._GS), MM_CPU_OFFSET (x64._GS), = 0, FALSE}, // EFI_MM_SAVE_STATE_R= EGISTER_GS =3D 25 + { 0, 2, 0, MM_CPU_OFFSET (x64._LDTR), = 0, FALSE}, // EFI_MM_SAVE_STATE_R= EGISTER_LDTR_SEL =3D 26 + { 0, 2, 0, MM_CPU_OFFSET (x64._TR), = 0, FALSE}, // EFI_MM_SAVE_STATE_R= EGISTER_TR_SEL =3D 27 + { 4, 8, MM_CPU_OFFSET (x86._DR7), MM_CPU_OFFSET (x64._DR7), = MM_CPU_OFFSET (x64._DR7) + 4, FALSE}, // EFI_MM_SAVE_STATE_R= EGISTER_DR7 =3D 28 + { 4, 8, MM_CPU_OFFSET (x86._DR6), MM_CPU_OFFSET (x64._DR6), = MM_CPU_OFFSET (x64._DR6) + 4, FALSE}, // EFI_MM_SAVE_STATE_R= EGISTER_DR6 =3D 29 + { 0, 8, 0, MM_CPU_OFFSET (x64._R8), = MM_CPU_OFFSET (x64._R8) + 4, TRUE}, // EFI_MM_SAVE_STATE_R= EGISTER_R8 =3D 30 + { 0, 8, 0, MM_CPU_OFFSET (x64._R9), = MM_CPU_OFFSET (x64._R9) + 4, TRUE}, // EFI_MM_SAVE_STATE_R= EGISTER_R9 =3D 31 + { 0, 8, 0, MM_CPU_OFFSET (x64._R10), = MM_CPU_OFFSET (x64._R10) + 4, TRUE}, // EFI_MM_SAVE_STATE_R= EGISTER_R10 =3D 32 + { 0, 8, 0, MM_CPU_OFFSET (x64._R11), = MM_CPU_OFFSET (x64._R11) + 4, TRUE}, // EFI_MM_SAVE_STATE_R= EGISTER_R11 =3D 33 + { 0, 8, 0, MM_CPU_OFFSET (x64._R12), = MM_CPU_OFFSET (x64._R12) + 4, TRUE}, // EFI_MM_SAVE_STATE_R= EGISTER_R12 =3D 34 + { 0, 8, 0, MM_CPU_OFFSET (x64._R13), = MM_CPU_OFFSET (x64._R13) + 4, TRUE}, // EFI_MM_SAVE_STATE_R= EGISTER_R13 =3D 35 + { 0, 8, 0, MM_CPU_OFFSET (x64._R14), = MM_CPU_OFFSET (x64._R14) + 4, TRUE}, // EFI_MM_SAVE_STATE_R= EGISTER_R14 =3D 36 + { 0, 8, 0, MM_CPU_OFFSET (x64._R15), = MM_CPU_OFFSET (x64._R15) + 4, TRUE}, // EFI_MM_SAVE_STATE_R= EGISTER_R15 =3D 37 + { 4, 8, MM_CPU_OFFSET (x86._EAX), MM_CPU_OFFSET (x64._RAX), = MM_CPU_OFFSET (x64._RAX) + 4, TRUE}, // EFI_MM_SAVE_STATE_R= EGISTER_RAX =3D 38 + { 4, 8, MM_CPU_OFFSET (x86._EBX), MM_CPU_OFFSET (x64._RBX), = MM_CPU_OFFSET (x64._RBX) + 4, TRUE}, // EFI_MM_SAVE_STATE_R= EGISTER_RBX =3D 39 + { 4, 8, MM_CPU_OFFSET (x86._ECX), MM_CPU_OFFSET (x64._RCX), = MM_CPU_OFFSET (x64._RCX) + 4, TRUE}, // EFI_MM_SAVE_STATE_R= EGISTER_RBX =3D 39 + { 4, 8, MM_CPU_OFFSET (x86._EDX), MM_CPU_OFFSET (x64._RDX), = MM_CPU_OFFSET (x64._RDX) + 4, TRUE}, // EFI_MM_SAVE_STATE_R= EGISTER_RDX =3D 41 + { 4, 8, MM_CPU_OFFSET (x86._ESP), MM_CPU_OFFSET (x64._RSP), = MM_CPU_OFFSET (x64._RSP) + 4, TRUE}, // EFI_MM_SAVE_STATE_R= EGISTER_RSP =3D 42 + { 4, 8, MM_CPU_OFFSET (x86._EBP), MM_CPU_OFFSET (x64._RBP), = MM_CPU_OFFSET (x64._RBP) + 4, TRUE}, // EFI_MM_SAVE_STATE_R= EGISTER_RBP =3D 43 + { 4, 8, MM_CPU_OFFSET (x86._ESI), MM_CPU_OFFSET (x64._RSI), = MM_CPU_OFFSET (x64._RSI) + 4, TRUE}, // EFI_MM_SAVE_STATE_R= EGISTER_RSI =3D 44 + { 4, 8, MM_CPU_OFFSET (x86._EDI), MM_CPU_OFFSET (x64._RDI), = MM_CPU_OFFSET (x64._RDI) + 4, TRUE}, // EFI_MM_SAVE_STATE_R= EGISTER_RDI =3D 45 + { 4, 8, MM_CPU_OFFSET (x86._EIP), MM_CPU_OFFSET (x64._RIP), = MM_CPU_OFFSET (x64._RIP) + 4, TRUE}, // EFI_MM_SAVE_STATE_R= EGISTER_RIP =3D 46 + + { 4, 8, MM_CPU_OFFSET (x86._EFLAGS), MM_CPU_OFFSET (x64._RFLAGS), = MM_CPU_OFFSET (x64._RFLAGS) + 4, TRUE}, // EFI_MM_SAVE_STATE_R= EGISTER_RFLAGS =3D 51 + { 4, 8, MM_CPU_OFFSET (x86._CR0), MM_CPU_OFFSET (x64._CR0), = MM_CPU_OFFSET (x64._CR0) + 4, FALSE}, // EFI_MM_SAVE_STATE_R= EGISTER_CR0 =3D 52 + { 4, 8, MM_CPU_OFFSET (x86._CR3), MM_CPU_OFFSET (x64._CR3), = MM_CPU_OFFSET (x64._CR3) + 4, FALSE}, // EFI_MM_SAVE_STATE_R= EGISTER_CR3 =3D 53 + { 0, 8, 0, MM_CPU_OFFSET (x64._CR4), = MM_CPU_OFFSET (x64._CR4) + 4, FALSE}, // EFI_MM_SAVE_STATE_R= EGISTER_CR4 =3D 54 + { 0, 0, 0, 0, = 0 } +}; + +/** + Read a save state register on the target processor. If this function + returns EFI_UNSUPPORTED, then the caller is responsible for reading the + MM Save State register. + + @param[in] CpuIndex The index of the CPU to read the Save State regist= er. + The value must be between 0 and the NumberOfCpus f= ield in + the System Management System Table (SMST). + @param[in] Register The MM Save State register to read. + @param[in] Width The number of bytes to read from the CPU save stat= e. + @param[out] Buffer Upon return, this holds the CPU register value read + 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 Reg= ister. + @retval EFI_NOT_FOUND If desired Register not found. +**/ +EFI_STATUS +EFIAPI +MmSaveStateReadRegister ( + IN UINTN CpuIndex, + IN EFI_MM_SAVE_STATE_REGISTER Register, + IN UINTN Width, + OUT VOID *Buffer + ) +{ + UINT32 SmmRevId; + EFI_MM_SAVE_STATE_IO_INFO *IoInfo; + AMD_SMRAM_SAVE_STATE_MAP *CpuSaveState; + UINT8 DataWidth; + + // Read CPU State + CpuSaveState =3D (AMD_SMRAM_SAVE_STATE_MAP *)gSmst->CpuSaveState[CpuInde= x]; + + // Check for special EFI_MM_SAVE_STATE_REGISTER_LMA + if (Register =3D=3D EFI_MM_SAVE_STATE_REGISTER_LMA) { + // Only byte access is supported for this register + if (Width !=3D 1) { + return EFI_INVALID_PARAMETER; + } + + *(UINT8 *)Buffer =3D MmSaveStateGetRegisterLma (); + + return EFI_SUCCESS; + } + + // Check for special EFI_MM_SAVE_STATE_REGISTER_IO + if (Register =3D=3D EFI_MM_SAVE_STATE_REGISTER_IO) { + // + // Get SMM Revision ID + // + MmSaveStateReadRegisterByIndex (CpuIndex, AMD_MM_SAVE_STATE_REGISTER_S= MMREVID_INDEX, sizeof (SmmRevId), &SmmRevId); + + // + // See if the CPU supports the IOMisc register in the save state + // + if (SmmRevId < AMD_SMM_MIN_REV_ID_X64) { + return EFI_NOT_FOUND; + } + + // Check if IO Restart Dword [IO Trap] is valid or not using bit 1. + if (!(CpuSaveState->x64.IO_DWord & 0x02u)) { + return EFI_NOT_FOUND; + } + + // Zero the IoInfo structure that will be returned in Buffer + IoInfo =3D (EFI_MM_SAVE_STATE_IO_INFO *)Buffer; + ZeroMem (IoInfo, sizeof (EFI_MM_SAVE_STATE_IO_INFO)); + + IoInfo->IoPort =3D (UINT16)(CpuSaveState->x64.IO_DWord >> 16u); + + if (CpuSaveState->x64.IO_DWord & 0x10u) { + IoInfo->IoWidth =3D EFI_MM_SAVE_STATE_IO_WIDTH_UINT8; + DataWidth =3D 0x01u; + } else if (CpuSaveState->x64.IO_DWord & 0x20u) { + IoInfo->IoWidth =3D EFI_MM_SAVE_STATE_IO_WIDTH_UINT16; + DataWidth =3D 0x02u; + } else { + IoInfo->IoWidth =3D EFI_MM_SAVE_STATE_IO_WIDTH_UINT32; + DataWidth =3D 0x04u; + } + + if (CpuSaveState->x64.IO_DWord & 0x01u) { + IoInfo->IoType =3D EFI_MM_SAVE_STATE_IO_TYPE_INPUT; + } else { + IoInfo->IoType =3D EFI_MM_SAVE_STATE_IO_TYPE_OUTPUT; + } + + if ((IoInfo->IoType =3D=3D EFI_MM_SAVE_STATE_IO_TYPE_INPUT) || (IoInfo= ->IoType =3D=3D EFI_MM_SAVE_STATE_IO_TYPE_OUTPUT)) { + MmSaveStateReadRegister (CpuIndex, EFI_MM_SAVE_STATE_REGISTER_RAX, D= ataWidth, &IoInfo->IoData); + } + + return EFI_SUCCESS; + } + + // Convert Register to a register lookup table index + return MmSaveStateReadRegisterByIndex (CpuIndex, MmSaveStateGetRegisterI= ndex (Register, AMD_MM_SAVE_STATE_REGISTER_MAX_INDEX), Width, Buffer); +} + +/** + Writes a save state register on the target processor. If this function + returns EFI_UNSUPPORTED, then the caller is responsible for writing the + MM save state register. + + @param[in] CpuIndex The index of the CPU to write the MM Save State. T= he + value must be between 0 and the NumberOfCpus field = in + the System Management System Table (SMST). + @param[in] Register The MM Save State register to write. + @param[in] Width The number of bytes to write to the CPU save 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_INVALID_PARAMTER Buffer is NULL. + @retval EFI_UNSUPPORTED This function does not support writing Reg= ister. + @retval EFI_NOT_FOUND If desired Register not found. +**/ +EFI_STATUS +EFIAPI +MmSaveStateWriteRegister ( + IN UINTN CpuIndex, + IN EFI_MM_SAVE_STATE_REGISTER Register, + IN UINTN Width, + IN CONST VOID *Buffer + ) +{ + UINTN RegisterIndex; + AMD_SMRAM_SAVE_STATE_MAP *CpuSaveState; + + // + // Writes to EFI_MM_SAVE_STATE_REGISTER_LMA are ignored + // + if (Register =3D=3D EFI_MM_SAVE_STATE_REGISTER_LMA) { + return EFI_SUCCESS; + } + + // + // Writes to EFI_MM_SAVE_STATE_REGISTER_IO are not supported + // + if (Register =3D=3D EFI_MM_SAVE_STATE_REGISTER_IO) { + return EFI_NOT_FOUND; + } + + // + // Convert Register to a register lookup table index + // + RegisterIndex =3D MmSaveStateGetRegisterIndex (Register, AMD_MM_SAVE_STA= TE_REGISTER_MAX_INDEX); + if (RegisterIndex =3D=3D 0) { + return EFI_NOT_FOUND; + } + + CpuSaveState =3D gSmst->CpuSaveState[CpuIndex]; + + // + // Do not write non-writable SaveState, because it will cause exception. + // + if (!mCpuWidthOffset[RegisterIndex].Writeable) { + return EFI_UNSUPPORTED; + } + + // + // Check CPU mode + // + if (MmSaveStateGetRegisterLma () =3D=3D EFI_MM_SAVE_STATE_REGISTER_LMA_3= 2BIT) { + // + // If 32-bit mode width is zero, then the specified register can not b= e accessed + // + if (mCpuWidthOffset[RegisterIndex].Width32 =3D=3D 0) { + return EFI_NOT_FOUND; + } + + // + // If Width is bigger than the 32-bit mode width, then the specified r= egister can not be accessed + // + if (Width > mCpuWidthOffset[RegisterIndex].Width32) { + return EFI_INVALID_PARAMETER; + } + + // + // Write SMM State register + // + ASSERT (CpuSaveState !=3D NULL); + CopyMem ((UINT8 *)CpuSaveState + mCpuWidthOffset[RegisterIndex].Offset= 32, Buffer, Width); + } else { + // + // If 64-bit mode width is zero, then the specified register can not b= e accessed + // + if (mCpuWidthOffset[RegisterIndex].Width64 =3D=3D 0) { + return EFI_NOT_FOUND; + } + + // + // If Width is bigger than the 64-bit mode width, then the specified r= egister can not be accessed + // + if (Width > mCpuWidthOffset[RegisterIndex].Width64) { + return EFI_INVALID_PARAMETER; + } + + // + // Write lower 32-bits of SMM State register + // + CopyMem ((UINT8 *)CpuSaveState + mCpuWidthOffset[RegisterIndex].Offset= 64Lo, Buffer, MIN (4, Width)); + if (Width >=3D 4) { + // + // Write upper 32-bits of SMM State register + // + CopyMem ((UINT8 *)CpuSaveState + mCpuWidthOffset[RegisterIndex].Offs= et64Hi, (UINT8 *)Buffer + 4, Width - 4); + } + } + + return EFI_SUCCESS; +} + +/** + Returns LMA value of the Processor. + + @retval UINT8 returns LMA bit value. +**/ +UINT8 +MmSaveStateGetRegisterLma ( + VOID + ) +{ + UINT32 LMAValue; + + LMAValue =3D (UINT32)AsmReadMsr64 (EFER_ADDRESS) & LMA; + if (LMAValue) { + return EFI_MM_SAVE_STATE_REGISTER_LMA_64BIT; + } + + return EFI_MM_SAVE_STATE_REGISTER_LMA_32BIT; +} diff --git a/UefiCpuPkg/Library/MmSaveStateLib/MmSaveStateCommon.c b/UefiCp= uPkg/Library/MmSaveStateLib/MmSaveStateCommon.c new file mode 100644 index 000000000000..09c6c3f96fed --- /dev/null +++ b/UefiCpuPkg/Library/MmSaveStateLib/MmSaveStateCommon.c @@ -0,0 +1,132 @@ +/** @file + Provides common supporting function to access SMRAM Save State Map + + 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 + +**/ + +#include "MmSaveState.h" + +// Table used by MmSaveStateGetRegisterIndex() to convert an EFI_MM_SAVE_S= TATE_REGISTER +// value to an index into a table of type CPU_MM_SAVE_STATE_LOOKUP_ENTRY +CONST CPU_MM_SAVE_STATE_REGISTER_RANGE mCpuRegisterRanges[] =3D { + MM_REGISTER_RANGE (EFI_MM_SAVE_STATE_REGISTER_GDTBASE, EFI_MM_SAVE_STATE= _REGISTER_LDTINFO), + MM_REGISTER_RANGE (EFI_MM_SAVE_STATE_REGISTER_ES, EFI_MM_SAVE_STATE= _REGISTER_RIP), + MM_REGISTER_RANGE (EFI_MM_SAVE_STATE_REGISTER_RFLAGS, EFI_MM_SAVE_STATE= _REGISTER_CR4), + { (EFI_MM_SAVE_STATE_REGISTER)0, (EFI_MM_SAVE_STAT= E_REGISTER)0, 0} +}; + +extern CONST CPU_MM_SAVE_STATE_LOOKUP_ENTRY mCpuWidthOffset[]; + +/** + Read information from the CPU save state. + + @param Register Specifies the CPU register to read form the save state. + @param RegOffset Offset for the next register index. + + @retval 0 Register is not valid + @retval >0 Index into mCpuWidthOffset[] associated with Register + +**/ +UINTN +MmSaveStateGetRegisterIndex ( + IN EFI_MM_SAVE_STATE_REGISTER Register, + IN UINTN RegOffset + ) +{ + UINTN Index; + UINTN Offset; + + for (Index =3D 0, Offset =3D RegOffset; mCpuRegisterRanges[Index].Length= !=3D 0; Index++) { + if ((Register >=3D mCpuRegisterRanges[Index].Start) && (Register <=3D = mCpuRegisterRanges[Index].End)) { + return Register - mCpuRegisterRanges[Index].Start + Offset; + } + + Offset +=3D mCpuRegisterRanges[Index].Length; + } + + return 0; +} + +/** + 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 reloc= ation handler. + + @param[in] CpuIndex Specifies the zero-based index of the CPU sav= e state. + @param[in] RegisterIndex Index into mCpuWidthOffset[] 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_PARAMTER This or Buffer is NULL. + +**/ +EFI_STATUS +MmSaveStateReadRegisterByIndex ( + IN UINTN CpuIndex, + IN UINTN RegisterIndex, + IN UINTN Width, + OUT VOID *Buffer + ) +{ + if (RegisterIndex =3D=3D 0) { + return EFI_NOT_FOUND; + } + + if (MmSaveStateGetRegisterLma () =3D=3D EFI_MM_SAVE_STATE_REGISTER_LMA_3= 2BIT) { + // + // If 32-bit mode width is zero, then the specified register can not b= e accessed + // + if (mCpuWidthOffset[RegisterIndex].Width32 =3D=3D 0) { + return EFI_NOT_FOUND; + } + + // + // If Width is bigger than the 32-bit mode width, then the specified r= egister can not be accessed + // + if (Width > mCpuWidthOffset[RegisterIndex].Width32) { + return EFI_INVALID_PARAMETER; + } + + // + // Write return buffer + // + ASSERT (gSmst->CpuSaveState[CpuIndex] !=3D NULL); + CopyMem (Buffer, (UINT8 *)gSmst->CpuSaveState[CpuIndex] + mCpuWidthOff= set[RegisterIndex].Offset32, Width); + } else { + // + // If 64-bit mode width is zero, then the specified register can not b= e accessed + // + if (mCpuWidthOffset[RegisterIndex].Width64 =3D=3D 0) { + return EFI_NOT_FOUND; + } + + // + // If Width is bigger than the 64-bit mode width, then the specified r= egister can not be accessed + // + if (Width > mCpuWidthOffset[RegisterIndex].Width64) { + return EFI_INVALID_PARAMETER; + } + + // + // Write lower 32-bits of return buffer + // + CopyMem (Buffer, (UINT8 *)gSmst->CpuSaveState[CpuIndex] + mCpuWidthOff= set[RegisterIndex].Offset64Lo, MIN (4, Width)); + if (Width > 4) { + // + // Write upper 32-bits of return buffer + // + CopyMem ((UINT8 *)Buffer + 4, (UINT8 *)gSmst->CpuSaveState[CpuIndex]= + mCpuWidthOffset[RegisterIndex].Offset64Hi, Width - 4); + } + } + + return EFI_SUCCESS; +} --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#104793): https://edk2.groups.io/g/devel/message/104793 Mute This Topic: https://groups.io/mt/98848078/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri Apr 19 02:57:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+104794+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1683894768876883.088816289383; Fri, 12 May 2023 05:32:48 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id LOL5YY1788612xOxGAV999GX; Fri, 12 May 2023 05:32:48 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.62]) by mx.groups.io with SMTP id smtpd.web10.23681.1683894767848871465 for ; Fri, 12 May 2023 05:32:47 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EOSTOoTDNfb4iafNC3qxUbMCMIAOP2jbEgtx2WEUJ33W9drbWPRShKG7U8+waGHqt6QBamQpTi+EI6BrfKbH2FDYIjvlkRsBBf9D+E+np09gVkPEQNqrtmosvnGJsh4LmpErx0gi/MRZu8ymYeaGIGgd/dlMoDpYLN4C1nmd2pruMMOy5++YVNfJmKAxprwl8ncEijqr7WQ1Sbj9R5FSuMsWNJz/eKX7p5Cve6Q7APlIjyruuHXKZQaByx3xx8t6s2Gxo6dH7do4a1Mo9L8BxoiHAGCLJnF4d6ZQEnW0Q/GBjB/t2xxS7DxFM5Wnj2/+B0VibGPM7lv8miigHJ3P2w== 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=0elUXQJX2AiUWnIxbtGgurgEcBYpsaeR4BzyXKzPTAc=; b=QpXc8otJm5gEY5pzvDLyDFzhqJHPITQk6N1LqnX7Lr8kp8IbCZUTXyULUgtVk8YdsjqcQjGYKRPvze6ay2rGKJySYJoH8z146OkQo7eHX1m1MYcF1yWZzq+rnqusJkj7kiOyTuVFhjbz1cYD8cfXKkDeqUObCoRBS6pHGXySAL9IjVpSNT+xqSiX9du/+x1prVWBESEmebOMQEF7EdFtkN0RZxl7EZxvXK8qPNT8ahVr8FnlUYJNVPY5avbsrR3vl+1eJeDVnDRChRYpoTQV39KURD6Jd9oYNphfmZAQfTRQYFtvXv9DzTB+uvPBQ8sYTcXsshjjGe/quiQhjHeLeA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none X-Received: from MW4PR03CA0143.namprd03.prod.outlook.com (2603:10b6:303:8c::28) by MW4PR12MB7240.namprd12.prod.outlook.com (2603:10b6:303:226::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.20; Fri, 12 May 2023 12:32:45 +0000 X-Received: from CO1NAM11FT104.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8c:cafe::70) by MW4PR03CA0143.outlook.office365.com (2603:10b6:303:8c::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.24 via Frontend Transport; Fri, 12 May 2023 12:32:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+104794+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT104.mail.protection.outlook.com (10.13.174.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6387.24 via Frontend Transport; Fri, 12 May 2023 12:32:43 +0000 X-Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Fri, 12 May 2023 07:32:39 -0500 X-Received: from BLR-LAB-SFW01.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Fri, 12 May 2023 07:32:37 -0500 From: "Abdul Lateef Attar via groups.io" To: CC: Abdul Lateef Attar , Abner Chang , Paul Grimes , Eric Dong , Ray Ni , Rahul Kumar Subject: [edk2-devel] [PATCH v13 4/8] UefiCpuPkg/SmmCpuFeaturesLib: Restructure arch-dependent code Date: Fri, 12 May 2023 18:02:20 +0530 Message-ID: <2c876eca0102b58105af4cd2f4264b4376a73165.1683894329.git.abdattar@amd.com> In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT104:EE_|MW4PR12MB7240:EE_ X-MS-Office365-Filtering-Correlation-Id: b4d99fc5-a89f-4c0a-c24d-08db52e4fbff X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: 9Nw+8TBYJhuoGP1HTXdCue0okMvCkD4ub0s1M4E1Ys1ew9ChFTjW1lHzfB9Vf9sUyRw3QwoR9ZeRgY+9NvLFAltZi91JYBS3GZ+m3Pmk5wtyaOKRyK8GeqCivWvwkbvV84pe3auI9p7BuVHpxWP7AIbhTd9OMDHpxAzuTMiV2f/kcb1zxr6eGBcnIykreBzbD3tFeN3Gj+FCxQYEXoDI9qHTnJjNX7HfHjTcM8HJpc5AGKbaxQvlSwqlBwTFwcIx5ABXBn661qWcRUk8qK2jPCWdmdrBZlfe8I1pjWwJW+b7wedPPpMXED0tZrHqmDRrwDSHAClnonj4Avf2Cm10WdsEXowtz0OTLpZdhsg/gVNFTNQBYk+4MA7rVWPF0XyYiTg+LrmkN2lpAdMpXCx9YyIvpSxIOal4vqoVk1xyM4VJL4Kv+3Okq9EqHRMZQyJyWcHepk+WTnaR+FIkpJQWBo5H84uNlz8NjTwoEr5wAMTMb6mb8kQ4oYNvOjpT6aEA11d4Nh7w7MyRAsLJ2msRRf66KJhnuVDokXfphDDlcRKiXr7tAxAcEATPkicFr0HtW4rAhFey5PNrnFZvsw2ig9QXH8HiNvOelzkp8RTTlN4tmd6yjPcaHFqXzi6RUfMKlIYTivd8rnorRRzyIx2bxO6w2XtJwPyjLz5eZu3dZvkqnbR4qeNe9bvwK2X5amRfrbR5uH92Lh09+/VM7gF46/YpYyN408L9dM6YqY1qqNtGwUVMXUJA4YHbmuzrAOII X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 May 2023 12:32:43.5358 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b4d99fc5-a89f-4c0a-c24d-08db52e4fbff X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT104.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7240 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,abdattar@amd.com X-Gm-Message-State: YblejqGMVSMOXY0ZhVDR5zkXx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1683894768; bh=twSqeGX4xnmxpJus9lSwfvUZlrRan/ByTI9a1Fc7e5E=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=FF+DP/Y0aW3nUq2dceeQtsYVFIYbIzfNe7ZnMfWlmrozuIBi28MYsJfClTJMtm3wn4D tPT+DCaVIh+uHBt1ca5C9Cws8Rbog94ljAr823lXvl9U2VLQUaQac8k056hdtCWJ/CLM2 URMBWoZaNS0ik9UL4d4hKLEtSsm3vzU4XfA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1683894770132100003 Content-Type: text/plain; charset="utf-8" From: Abdul Lateef Attar BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4182 moves Intel-specific code to the arch-dependent file. Other processor families might have different implementation of these functions. Hence, moving out of the common file. Cc: Abner Chang Cc: Paul Grimes Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Signed-off-by: Abdul Lateef Attar Reviewed-by: Abner Chang Reviewed-by: Ray Ni --- .../IntelSmmCpuFeaturesLib.c | 128 ++++++++++++++++++ .../SmmCpuFeaturesLibCommon.c | 128 ------------------ 2 files changed, 128 insertions(+), 128 deletions(-) diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c = b/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c index 1a2c706fa1f1..8f382b60266c 100644 --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c @@ -417,3 +417,131 @@ SmmCpuFeaturesSetSmmRegister ( AsmWriteMsr64 (SMM_FEATURES_LIB_SMM_FEATURE_CONTROL, Value); } } + +/** + 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 m= ode + the RSM instruction resumes and update the resume execution address with + either NewInstructionPointer32 or NewInstructionPoint. The auto HALT re= start + flag in the SMRAM save state must always be cleared. This function retu= rns + 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 mo= de + 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 v= alue + must be between 0 and the NumberOfCp= us + field in the System Management Syste= m Table + (SMST). + @param[in] CpuState Pointer to SMRAM Save State Map for = the + currently executing CPU. + @param[in] NewInstructionPointer32 Instruction pointer to use if resumi= ng to + 32-bit execution mode from 64-bit SM= M. + @param[in] NewInstructionPointer Instruction pointer to use if resumi= ng 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 save = state + before it was replaced. +**/ +UINT64 +EFIAPI +SmmCpuFeaturesHookReturnFromSmm ( + IN UINTN CpuIndex, + IN SMRAM_SAVE_STATE_MAP *CpuState, + IN UINT64 NewInstructionPointer32, + IN UINT64 NewInstructionPointer + ) +{ + return 0; +} + +/** + Read an SMM Save State register on the target processor. If this functi= on + 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 field= 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 stat= e. + @param[out] Buffer Upon return, this holds the CPU register value read + 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 Reg= ister. + +**/ +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 func= tion + 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 field = 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 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_INVALID_PARAMETER Buffer is NULL. + @retval EFI_UNSUPPORTED This function does not support writing Reg= ister. +**/ +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. + + @param[in] CpuIndex The index of the CPU to check for SMM register supp= ort. + The value must be between 0 and the NumberOfCpus fi= eld + 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 + ) +{ + if (FeaturePcdGet (PcdSmmFeatureControlEnable) && (RegName =3D=3D SmmReg= FeatureControl)) { + return TRUE; + } + + return FALSE; +} diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c= b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c index 5498fda38da4..cbf4b495185b 100644 --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c @@ -17,49 +17,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include "CpuFeaturesLib.h" =20 -/** - 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 m= ode - the RSM instruction resumes and update the resume execution address with - either NewInstructionPointer32 or NewInstructionPoint. The auto HALT re= start - flag in the SMRAM save state must always be cleared. This function retu= rns - 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 mo= de - 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 v= alue - must be between 0 and the NumberOfCp= us - field in the System Management Syste= m Table - (SMST). - @param[in] CpuState Pointer to SMRAM Save State Map for = the - currently executing CPU. - @param[in] NewInstructionPointer32 Instruction pointer to use if resumi= ng to - 32-bit execution mode from 64-bit SM= M. - @param[in] NewInstructionPointer Instruction pointer to use if resumi= ng 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 save = state - before it was replaced. -**/ -UINT64 -EFIAPI -SmmCpuFeaturesHookReturnFromSmm ( - IN UINTN CpuIndex, - IN SMRAM_SAVE_STATE_MAP *CpuState, - IN UINT64 NewInstructionPointer32, - IN UINT64 NewInstructionPointer - ) -{ - return 0; -} - /** Hook point in normal execution mode that allows the one CPU that was ele= cted as monarch during System Management Mode initialization to perform addit= ional @@ -90,91 +47,6 @@ SmmCpuFeaturesRendezvousExit ( { } =20 -/** - 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 supp= ort. - The value must be between 0 and the NumberOfCpus fi= eld - 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 - ) -{ - if (FeaturePcdGet (PcdSmmFeatureControlEnable) && (RegName =3D=3D SmmReg= FeatureControl)) { - return TRUE; - } - - return FALSE; -} - -/** - Read an SMM Save State register on the target processor. If this functi= on - 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 field= 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 stat= e. - @param[out] Buffer Upon return, this holds the CPU register value read - 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 Reg= ister. - -**/ -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 func= tion - 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 field = 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 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_INVALID_PARAMETER Buffer is NULL. - @retval EFI_UNSUPPORTED This function does not support writing Reg= ister. -**/ -EFI_STATUS -EFIAPI -SmmCpuFeaturesWriteSaveStateRegister ( - IN UINTN CpuIndex, - IN EFI_SMM_SAVE_STATE_REGISTER Register, - IN UINTN Width, - IN CONST VOID *Buffer - ) -{ - return EFI_UNSUPPORTED; -} - /** This function is hook point called after the gEfiSmmReadyToLockProtocolG= uid notification is completely processed. --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#104794): https://edk2.groups.io/g/devel/message/104794 Mute This Topic: https://groups.io/mt/98848079/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri Apr 19 02:57:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+104796+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1683894775435263.1941152588448; Fri, 12 May 2023 05:32:55 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id lZOmYY1788612xWhjhPfzI8Z; Fri, 12 May 2023 05:32:55 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.50]) by mx.groups.io with SMTP id smtpd.web10.23685.1683894774314534489 for ; Fri, 12 May 2023 05:32:54 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oQ31Xwc0arGUN9xzIyGsFfHOy5fwllSrg2sERGsHLusKrJqxrzeOvgihfpFeBkpifO2r8cMNvuveUXtpM/IoniCuw8+fSmvPSGzWZYseZ3vvjs7zEinOlw7YIHOf+TJo89JWXbKB2aTpWYznmhDzYmX0+7xry7zcJFl/j1mjkTyjVpuKU4Hd/HjyHja8FVDDQY+sKeldZcqUTmOq37I2WvNjNkP1LRS9D9mn2CnK6vpqSNTVYIk7DtB8GRspiInCzPdcjIjr2sSV6y8xWkQ5RwL8Ch5iZDyfWu4jDWu6ECeaTJnSETMnvRc6NvQDiJIKVfVio8rhof1OkyGkbmAzfA== 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=5cAGWfAcUyIC8wuWDVEGtpCwvl00dV3syZvlEYGpt7g=; b=oYMFpzIMb8WBzeRU84TcCj24RDU7Nqs5zssIyYMBE1tQbBqmDuxxra0d/rTmOM+6AGjQIoZYNQBSRSa8cmHDQNGSm/x9GCbjJnpNoqi65LcLLlGp8hGLQZIY85kZT9vySVhbiRlOO1ySgunj/EaGWk+lEio1Yu61jzFFm5qAOoi1KEPF4eNg5La0jYcaI2bOgDqys3BVKJtY9SzdEXPR2xVNtAauVWYhxtEQj1FpVZXuT8GH+zA6WWKzPCxlLiVZIfa59PGgyhRPG6OyceCDbAlKxNL7ymkw+pBmI0AXvmm2XiFojhR5NH/ozzGk1MLye3Sft6e0rqBBWL7QOnwZnw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none X-Received: from MW4PR03CA0137.namprd03.prod.outlook.com (2603:10b6:303:8c::22) by IA0PR12MB8278.namprd12.prod.outlook.com (2603:10b6:208:3dc::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.21; Fri, 12 May 2023 12:32:48 +0000 X-Received: from CO1NAM11FT104.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8c:cafe::66) by MW4PR03CA0137.outlook.office365.com (2603:10b6:303:8c::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.24 via Frontend Transport; Fri, 12 May 2023 12:32:48 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+104796+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT104.mail.protection.outlook.com (10.13.174.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6387.24 via Frontend Transport; Fri, 12 May 2023 12:32:48 +0000 X-Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Fri, 12 May 2023 07:32:42 -0500 X-Received: from BLR-LAB-SFW01.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Fri, 12 May 2023 07:32:40 -0500 From: "Abdul Lateef Attar via groups.io" To: CC: Abdul Lateef Attar , Paul Grimes , Abner Chang , Eric Dong , Ray Ni , Rahul Kumar , Abdul Lateef Attar Subject: [edk2-devel] [PATCH v13 5/8] UefiCpuPkg: Implements SmmCpuFeaturesLib for AMD Family Date: Fri, 12 May 2023 18:02:21 +0530 Message-ID: <761f29836a8eddb3a6d0af0ad5e92201c569887e.1683894329.git.abdattar@amd.com> In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT104:EE_|IA0PR12MB8278:EE_ X-MS-Office365-Filtering-Correlation-Id: f225c7dd-e013-45c5-ba84-08db52e4feb0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: pcBQnofAPpWNPiSJGcEyt055BT3A+3gV5hqP917lO6QBR8l3IymRqHzVWNh9Tmo6Vz8qUMxrVT9WClF/6BUJXpOI5zrKGoeDwpWJAibLnTtHfUjC8PsRtXaqZxZYSYISVWbg17n1d5iab7xLE7NPg2nhNWR+zWwF4MqVwN8Tj8wHTZJPRYQuMlRFQM517w1Bk07xiNdfQFGRAkEpVW+SnLWb49txYFCyvoXKGVzh9aLc/+si78DTPoahOxxkAzuaRU4gie3BkzkT6tDxpFu1koTeBDRiFt90Oaqhr8GZzJnPU1mjwNPA9H5ZEXAwy2aEY57p0AbhpX7i1fgK5xd1Aq6D/i8D/rWYeC3pfrKz3/eZXobElkUlEhQgLCFpAjCbuicQ/zhKg8xd6GDMjduOaG07lCdY64xKaryZeHHo3FjYIu56jXA84M+fylC2MekgoO4DcDpMewpKQaYZYx2f/5wpU0iF+JO0JMmxNQY6b0ey1ykxv5oK2psBe7NTeoIfLQzDGPecjCK2EGST9U9WhIMXz/y1LbDRzlx0kCJ4euUxLWpQFfoJrQk5gNB/ZkvD6NRZyanSy2CrzpuSsTfmuJ5W15fPIszWWUBI3Lc0225KKtrSPrs+GCSWgvYrqZ7UqcYbazBdUSRrXW3g/8BvyXI4b3S3oywi/WKLHm75DDJkBB4iQ2NMs+XUnNpjDnxzWnhYtjzvf9YoWDdqt2/FkNnEVpWPbVqBLCrO27YlHYCeWCDT1vqGHcY6wZrhyaa7 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 May 2023 12:32:48.0510 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f225c7dd-e013-45c5-ba84-08db52e4feb0 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT104.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8278 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,abdattar@amd.com X-Gm-Message-State: jaaLVE2EpZLRHKVWXj5iB74Yx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1683894775; bh=8JZbDYeTvvFjjPRiipR4Hez9Mq+Una3cWqkoO5qAGps=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=PWvP8voB3LFr0ESPVTm3CBRL4MrQG2YwdAbRyy3KQMbJFKGxQBQoM0+cmLwdT2DZp3C SFFmKtIfuakdWM0hqgYoxBprxyJzOPC3aaI+rP7dpBUwGgo5NgDbZIwCjAheCtM9fMnLW ijIjMdWavSQgMOq++D54qUYRBqwYymc0T1s= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1683894776186100002 Content-Type: text/plain; charset="utf-8" From: Abdul Lateef Attar BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4182 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. Cc: Paul Grimes Cc: Abner Chang Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Signed-off-by: Abdul Lateef Attar Reviewed-by: Abner Chang --- UefiCpuPkg/UefiCpuPkg.dsc | 7 + .../AmdSmmCpuFeaturesLib.inf | 38 ++ .../SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.c | 445 ++++++++++++++++++ 3 files changed, 490 insertions(+) create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesL= ib.inf create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesL= ib.c diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index 8b0cb02a80e8..6e29850bed17 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -169,6 +169,12 @@ [Components.IA32, Components.X64] SmmCpuFeaturesLib|UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeature= sLibStm.inf } + UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf { + + FILE_GUID =3D B7242C74-BD21-49EE-84B4-07162E8C080D + + SmmCpuFeaturesLib|UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeat= uresLib.inf + } UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf UefiCpuPkg/ResetVector/Vtf0/Bin/ResetVector.inf UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf @@ -185,6 +191,7 @@ [Components.IA32, Components.X64] UnitTestResultReportLib|UnitTestFrameworkPkg/Library/UnitTestResultR= eportLib/UnitTestResultReportLibConOut.inf } UefiCpuPkg/Library/MmSaveStateLib/AmdMmSaveStateLib.inf + UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf =20 [Components.X64] UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandle= rLibUnitTest.inf diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf = b/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf new file mode 100644 index 000000000000..5ee8a2e720c9 --- /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 AmdSmmCpuFeaturesLib + MODULE_UNI_FILE =3D SmmCpuFeaturesLib.uni + FILE_GUID =3D 5849E964-78EC-428E-8CBD-848A7E359134 + 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 functi= on + 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 field= 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 stat= e. + @param[out] Buffer Upon return, this holds the CPU register value read + 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 Reg= ister. + +**/ +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 func= tion + 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 field = 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 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_INVALID_PARAMTER Buffer is NULL. + @retval EFI_UNSUPPORTED This function does not support writing Reg= ister. +**/ +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 initiali= ze + 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 exe= cuting + CPU is specified by CpuIndex and CpuIndex can be used to access informat= ion + 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 value + must be between 0 and the NumberOfCpus field = in + the System Management System Table (SMST). + @param[in] IsMonarch TRUE if the CpuIndex is the index of the CPU = that + was elected as monarch during System Manageme= nt + Mode initialization. + FALSE if the CpuIndex is not the index of the= CPU + that was elected as monarch during System + Management Mode initialization. + @param[in] ProcessorInfo Pointer to an array of EFI_PROCESSOR_INFORMAT= ION + structures. ProcessorInfo[CpuIndex] contains= the + information for the currently executing CPU. + @param[in] CpuHotPlugData Pointer to the CPU_HOT_PLUG_DATA structure th= at + 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 t= o 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 norma= l 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->Sm= rrSize)) || + ((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 r= equirement!\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 m= ode + the RSM instruction resumes and update the resume execution address with + either NewInstructionPointer32 or NewInstructionPoint. The auto HALT re= start + flag in the SMRAM save state must always be cleared. This function retu= rns + 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 mo= de + 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 v= alue + must be between 0 and the NumberOfCp= us + field in the System Management Syste= m Table + (SMST). + @param[in] CpuState Pointer to SMRAM Save State Map for = the + currently executing CPU. + @param[in] NewInstructionPointer32 Instruction pointer to use if resumi= ng to + 32-bit execution mode from 64-bit SM= M. + @param[in] NewInstructionPointer Instruction pointer to use if resumi= ng 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 save = 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_32BI= T) { + 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 SmmCpuFeaturesInstallSmiHa= ndler() + The caller is required to allocate enough SMRAM for each CP= U 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 fu= nction + is only called if SmmCpuFeaturesGetSmiHandlerSize() returns a size is gr= eater + than zero and is called by the CPU that was elected as monarch during Sy= stem + Management Mode initialization. + + @param[in] CpuIndex The index of the CPU to install the custom SMI han= dler. + The value must be between 0 and the NumberOfCpus f= ield + in the System Management System Table (SMST). + @param[in] SmBase The SMBASE address for the CPU specified by CpuInd= ex. + @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 SMI = is + processed by the CPU specified by CpuIndex. + @param[in] GdtBase The base address of the GDT to use when an SMI is + 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 is + 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-abili= ty + when executing in System Management Mode. + + @retval TRUE MTRR registers must be configured to set SMRAM cache-abil= ity. + @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 SmmCpuFeaturesNeedConfigu= reMtrrs() + returns TRUE. +**/ +VOID +EFIAPI +SmmCpuFeaturesDisableSmrr ( + VOID + ) +{ +} + +/** + Enable SMRR register if SMRR is supported and SmmCpuFeaturesNeedConfigur= eMtrrs() + returns TRUE. +**/ +VOID +EFIAPI +SmmCpuFeaturesReenableSmrr ( + VOID + ) +{ +} + +/** + Processor specific hook point each time a CPU enters System Management M= ode. + + @param[in] CpuIndex The index of the CPU that has entered SMM. The val= ue + must be between 0 and the NumberOfCpus field in the + 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 field = 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 field = 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 supp= ort. + The value must be between 0 and the NumberOfCpus fi= eld + 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; +} --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#104796): https://edk2.groups.io/g/devel/message/104796 Mute This Topic: https://groups.io/mt/98848082/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri Apr 19 02:57:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+104795+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1683894774997551.4360922331581; Fri, 12 May 2023 05:32:54 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id TOwPYY1788612xEeZuI2cLgp; Fri, 12 May 2023 05:32:54 -0700 X-Received: from NAM02-BN1-obe.outbound.protection.outlook.com (NAM02-BN1-obe.outbound.protection.outlook.com [40.107.212.85]) by mx.groups.io with SMTP id smtpd.web10.23684.1683894773947156221 for ; Fri, 12 May 2023 05:32:54 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UA3MLga3twFLU0KIBNbjSz8xe+tJD/IVM1THq/mZKatOqYB0YIzdQ5V/QJMtha3P942MV4WKE3kQZyhbYwC8lepLNay2U++j0uwguMYLy3jlWamRCM/CDskg7iIMkgJuLFkmTuuq9KabWUBp7LMKXkpLKgqpEbmXkukyf71geFACAMIFYbptFssJ9crcA1wZq+salYAHjrY6poHhIMIONZxHyP+rkDop7mfHsmHgb7Yv5vswBo5MdUB2+0W73RvRqNA7PquCnY/ieor+QqC3cT2vO05Z8TcA0nUObMADPNW+edBRoXYCLEW257DuMdTJEYmI7uKsHVXpisqzWsiWdQ== 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=e9GbSvqlU9MSjdDXME3gVrdqzrJ4c+7AdxeuZx0pBCI=; b=aFwqFiQlcORJJ9G9E7zH6qPl+mdun7lobH3VdzH+QEcD0AH2PG322Y8IrBTJ2D8cbNlFjokDyQHqHQfWYS/l7XOyomDCr2GVq/O4o0oBaxefaytUPTYt1wQI2oVMqVm3gLACOiOz1iPj8eoyte8Ryrc4bN14H5CyTJ0y4skcUiUej0vN8AekWW9G7z0HtZpMXbwWxEWnSDKU5a2ElQkI0SX0Uh5rNpbgbpSTbm6lDh/3G4Ql5/+YBxdoCbx4ufUDX0v9bqduYLPyOKdahcrg4M+wHupixzOsA6mOjjDGq9voJGB+HZQO2kqBlbrXgyoFLMo3r9wp0RSkEs567ySmjw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none X-Received: from MW4PR03CA0137.namprd03.prod.outlook.com (2603:10b6:303:8c::22) by SN7PR12MB8060.namprd12.prod.outlook.com (2603:10b6:806:343::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.32; Fri, 12 May 2023 12:32:51 +0000 X-Received: from CO1NAM11FT104.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8c:cafe::c3) by MW4PR03CA0137.outlook.office365.com (2603:10b6:303:8c::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.24 via Frontend Transport; Fri, 12 May 2023 12:32:51 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+104795+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT104.mail.protection.outlook.com (10.13.174.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6387.24 via Frontend Transport; Fri, 12 May 2023 12:32:50 +0000 X-Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Fri, 12 May 2023 07:32:45 -0500 X-Received: from BLR-LAB-SFW01.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Fri, 12 May 2023 07:32:42 -0500 From: "Abdul Lateef Attar via groups.io" To: CC: Abdul Lateef Attar , Paul Grimes , Abner Chang , Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH v13 6/8] UefiCpuPkg: Implements MmSaveStateLib for Intel Date: Fri, 12 May 2023 18:02:22 +0530 Message-ID: <2a07f4bf6991f95021550912a7afbc47e0f97fe7.1683894329.git.abdattar@amd.com> In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT104:EE_|SN7PR12MB8060:EE_ X-MS-Office365-Filtering-Correlation-Id: 643fe6dc-3a40-43fc-c3b6-08db52e50069 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: wpWaF6IiMf1HgfGgrANNAj1UppgeV4Ls3YQ6XBz0CPz/qwMHv4kMxaYkXi2K+4nvlx7CKxI/1OWQ2Idfxwxij9PQbH+6crPtTUljdAETe2Fx6JiA6zH9zW6F6ff6pFJBFU2vlgw90OZBjrwJonWzYWjaTiOa7WHiuSYQZ6EbIUq/yOGk0MKXy3UqvSn/CHbsnFJyuexC0ks0kA/APWEK67l1+3ovuzD1yRjwIp9gW1+8ZHauX+Q//2Xt2/9SolsN/PbH6hKMptjrRN0zNk9KAYhvg4OhOyxCCOpL0szgzUlwWKer56zKePSA9N3JbGRq5S7R3Va+SsSmS+rZAAfWOnsvZYJmie83fYn/sDxfElImIoAVqM4UTt1QQW/L0WnZtVvBuQZQY7crViaJziYiOVP+rHDo+UNoz5SkEkSw0WX5CV84WpyRoXdQL6918GsKARqQXHqero6M+bgGHbjBf4acJJ3vN/ncSr+HiilksPOfDX+BqlX8m4h+tq3KocOq0ExX+DodqBNr3L9uKSl7VlYorfXRFlha5jFCvzxy4ud3NnYi3cpxEU43Q0oW/squJCvkWLFIG9YEQ15L37DZ37ho+SbIDfkdh4oEW3oofn/l5tYCM1upokj9sClTFPEoTwNlwu/yYNpe3p36RNgDjuP+qCwj6mJb9s6Cvry32m9F9HmREGBoVtEeY3BHCzYhqrbnbyHNiHpJxFVo+FFUbTsXu694tQOKEMfvF+Zi7Bs= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 May 2023 12:32:50.9414 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 643fe6dc-3a40-43fc-c3b6-08db52e50069 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT104.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB8060 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,abdattar@amd.com X-Gm-Message-State: raudmunkJGM4yMSxt4OgPd4Px1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1683894774; bh=i8JosO36KrHqE2zDbllWokRUOwgqM5CvAVvUbWZvwC4=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=q4c+Izliz+0Uo875BJkV9rP5RUhNczXlsRHs5hlvafU0nJQXJ3O4rSmlRNUmHEip8KE f7Uhe/epKccRqSxwMjwbUQXE2K36lyJvSJP7X/FzkS7/ldLIdHNfVdYyeyvQENPO9Q3br A9FH0/Gcx8foxNGZJuwFVWI3oBbO1PHHsN4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1683894776165100001 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4182 Implements MmSaveStateLib library interfaces to read and write save state registers for Intel processor family. Moves Intel and AMD common functionality to common area. Cc: Paul Grimes Cc: Abner Chang Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann Signed-off-by: Abdul Lateef Attar Reviewed-by: Abner Chang --- UefiCpuPkg/UefiCpuPkg.dsc | 3 + .../MmSaveStateLib/IntelMmSaveStateLib.inf | 34 ++ .../Library/MmSaveStateLib/IntelMmSaveState.c | 410 ++++++++++++++++++ 3 files changed, 447 insertions(+) create mode 100644 UefiCpuPkg/Library/MmSaveStateLib/IntelMmSaveStateLib.i= nf create mode 100644 UefiCpuPkg/Library/MmSaveStateLib/IntelMmSaveState.c diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index 6e29850bed17..eb6bdc5bef63 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -101,6 +101,7 @@ [LibraryClasses.common.DXE_SMM_DRIVER] HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuE= xceptionHandlerLib.inf MmSaveStateLib|UefiCpuPkg/Library/MmSaveStateLib/AmdMmSaveStateLib.inf + MmSaveStateLib|UefiCpuPkg/Library/MmSaveStateLib/IntelMmSaveStateLib.inf =20 [LibraryClasses.common.MM_STANDALONE] MmServicesTableLib|MdePkg/Library/StandaloneMmServicesTableLib/Standalon= eMmServicesTableLib.inf @@ -174,6 +175,7 @@ [Components.IA32, Components.X64] FILE_GUID =3D B7242C74-BD21-49EE-84B4-07162E8C080D SmmCpuFeaturesLib|UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeat= uresLib.inf + MmSaveStateLib|UefiCpuPkg/Library/MmSaveStateLib/AmdMmSaveStateLib.i= nf } UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf UefiCpuPkg/ResetVector/Vtf0/Bin/ResetVector.inf @@ -191,6 +193,7 @@ [Components.IA32, Components.X64] UnitTestResultReportLib|UnitTestFrameworkPkg/Library/UnitTestResultR= eportLib/UnitTestResultReportLibConOut.inf } UefiCpuPkg/Library/MmSaveStateLib/AmdMmSaveStateLib.inf + UefiCpuPkg/Library/MmSaveStateLib/IntelMmSaveStateLib.inf UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf =20 [Components.X64] diff --git a/UefiCpuPkg/Library/MmSaveStateLib/IntelMmSaveStateLib.inf b/Ue= fiCpuPkg/Library/MmSaveStateLib/IntelMmSaveStateLib.inf new file mode 100644 index 000000000000..b92dfa643203 --- /dev/null +++ b/UefiCpuPkg/Library/MmSaveStateLib/IntelMmSaveStateLib.inf @@ -0,0 +1,34 @@ +## @file +# SMM Smram save state service lib. +# +# This is SMM Smram save state service lib that provide service to read and +# save savestate area registers. +# +# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D IntelMmSaveStateLib + FILE_GUID =3D 37E8137B-9F74-4250-8951-7A970A3C39C0 + MODULE_TYPE =3D DXE_SMM_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D MmSaveStateLib + +[Sources] + MmSaveState.h + MmSaveStateCommon.c + IntelMmSaveState.c + +[Packages] + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + SmmServicesTableLib diff --git a/UefiCpuPkg/Library/MmSaveStateLib/IntelMmSaveState.c b/UefiCpu= Pkg/Library/MmSaveStateLib/IntelMmSaveState.c new file mode 100644 index 000000000000..fd321bb571d5 --- /dev/null +++ b/UefiCpuPkg/Library/MmSaveStateLib/IntelMmSaveState.c @@ -0,0 +1,410 @@ +/** @file +Provides services to access SMRAM Save State Map + +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 + +**/ + +#include "MmSaveState.h" +#include +#include +#include + +#define INTEL_MM_SAVE_STATE_REGISTER_SMMREVID_INDEX 1 +#define INTEL_MM_SAVE_STATE_REGISTER_IOMISC_INDEX 2 +#define INTEL_MM_SAVE_STATE_REGISTER_IOMEMADDR_INDEX 3 +#define INTEL_MM_SAVE_STATE_REGISTER_MAX_INDEX 4 + +/// +/// Macro used to simplify the lookup table entries of type CPU_MM_SAVE_ST= ATE_LOOKUP_ENTRY +/// +#define MM_CPU_OFFSET(Field) OFFSET_OF (SMRAM_SAVE_STATE_MAP, Field) + +/// +/// Lookup table used to retrieve the widths and offsets associated with e= ach +/// supported EFI_MM_SAVE_STATE_REGISTER value +/// +CONST CPU_MM_SAVE_STATE_LOOKUP_ENTRY mCpuWidthOffset[] =3D { + { 0, 0, 0, 0, = 0, FALSE }, // Reserved + + // + // Internally defined CPU Save State Registers. Not defined in PI SMM CP= U Protocol. + // + { 4, 4, MM_CPU_OFFSET (x86.SMMRevId), MM_CPU_OFFSET (x64.SMMRevId), = 0, FALSE }, // INTEL_MM_SAVE_STATE_REGI= STER_SMMREVID_INDEX =3D 1 + { 4, 4, MM_CPU_OFFSET (x86.IOMisc), MM_CPU_OFFSET (x64.IOMisc), = 0, FALSE }, // INTEL_MM_SAVE_STATE_REGI= STER_IOMISC_INDEX =3D 2 + { 4, 8, MM_CPU_OFFSET (x86.IOMemAddr), MM_CPU_OFFSET (x64.IOMemAddr), = MM_CPU_OFFSET (x64.IOMemAddr) + 4, FALSE }, // INTEL_MM_SAVE_STATE_REGI= STER_IOMEMADDR_INDEX =3D 3 + + // + // CPU Save State registers defined in PI SMM CPU Protocol. + // + { 0, 8, 0, MM_CPU_OFFSET (x64.GdtBaseLoDword= ), MM_CPU_OFFSET (x64.GdtBaseHiDword), FALSE }, // EFI_MM_SAVE_STATE_REGIS= TER_GDTBASE =3D 4 + { 0, 8, 0, MM_CPU_OFFSET (x64.IdtBaseLoDword= ), MM_CPU_OFFSET (x64.IdtBaseHiDword), FALSE }, // EFI_MM_SAVE_STATE_REGIS= TER_IDTBASE =3D 5 + { 0, 8, 0, MM_CPU_OFFSET (x64.LdtBaseLoDword= ), MM_CPU_OFFSET (x64.LdtBaseHiDword), FALSE }, // EFI_MM_SAVE_STATE_REGIS= TER_LDTBASE =3D 6 + { 0, 0, 0, 0, = 0, FALSE }, // EFI_MM_SAVE_STATE_REGIS= TER_GDTLIMIT =3D 7 + { 0, 0, 0, 0, = 0, FALSE }, // EFI_MM_SAVE_STATE_REGIS= TER_IDTLIMIT =3D 8 + { 0, 0, 0, 0, = 0, FALSE }, // EFI_MM_SAVE_STATE_REGIS= TER_LDTLIMIT =3D 9 + { 0, 0, 0, 0, = 0, FALSE }, // EFI_MM_SAVE_STATE_REGIS= TER_LDTINFO =3D 10 + + { 4, 4, MM_CPU_OFFSET (x86._ES), MM_CPU_OFFSET (x64._ES), = 0, FALSE }, // EFI_MM_SAVE_STATE_REGIS= TER_ES =3D 20 + { 4, 4, MM_CPU_OFFSET (x86._CS), MM_CPU_OFFSET (x64._CS), = 0, FALSE }, // EFI_MM_SAVE_STATE_REGIS= TER_CS =3D 21 + { 4, 4, MM_CPU_OFFSET (x86._SS), MM_CPU_OFFSET (x64._SS), = 0, FALSE }, // EFI_MM_SAVE_STATE_REGIS= TER_SS =3D 22 + { 4, 4, MM_CPU_OFFSET (x86._DS), MM_CPU_OFFSET (x64._DS), = 0, FALSE }, // EFI_MM_SAVE_STATE_REGIS= TER_DS =3D 23 + { 4, 4, MM_CPU_OFFSET (x86._FS), MM_CPU_OFFSET (x64._FS), = 0, FALSE }, // EFI_MM_SAVE_STATE_REGIS= TER_FS =3D 24 + { 4, 4, MM_CPU_OFFSET (x86._GS), MM_CPU_OFFSET (x64._GS), = 0, FALSE }, // EFI_MM_SAVE_STATE_REGIS= TER_GS =3D 25 + { 0, 4, 0, MM_CPU_OFFSET (x64._LDTR), = 0, FALSE }, // EFI_MM_SAVE_STATE_REGIS= TER_LDTR_SEL =3D 26 + { 4, 4, MM_CPU_OFFSET (x86._TR), MM_CPU_OFFSET (x64._TR), = 0, FALSE }, // EFI_MM_SAVE_STATE_REGIS= TER_TR_SEL =3D 27 + { 4, 8, MM_CPU_OFFSET (x86._DR7), MM_CPU_OFFSET (x64._DR7), = MM_CPU_OFFSET (x64._DR7) + 4, FALSE }, // EFI_MM_SAVE_STATE_REGIS= TER_DR7 =3D 28 + { 4, 8, MM_CPU_OFFSET (x86._DR6), MM_CPU_OFFSET (x64._DR6), = MM_CPU_OFFSET (x64._DR6) + 4, FALSE }, // EFI_MM_SAVE_STATE_REGIS= TER_DR6 =3D 29 + { 0, 8, 0, MM_CPU_OFFSET (x64._R8), = MM_CPU_OFFSET (x64._R8) + 4, TRUE }, // EFI_MM_SAVE_STATE_REGIS= TER_R8 =3D 30 + { 0, 8, 0, MM_CPU_OFFSET (x64._R9), = MM_CPU_OFFSET (x64._R9) + 4, TRUE }, // EFI_MM_SAVE_STATE_REGIS= TER_R9 =3D 31 + { 0, 8, 0, MM_CPU_OFFSET (x64._R10), = MM_CPU_OFFSET (x64._R10) + 4, TRUE }, // EFI_MM_SAVE_STATE_REGIS= TER_R10 =3D 32 + { 0, 8, 0, MM_CPU_OFFSET (x64._R11), = MM_CPU_OFFSET (x64._R11) + 4, TRUE }, // EFI_MM_SAVE_STATE_REGIS= TER_R11 =3D 33 + { 0, 8, 0, MM_CPU_OFFSET (x64._R12), = MM_CPU_OFFSET (x64._R12) + 4, TRUE }, // EFI_MM_SAVE_STATE_REGIS= TER_R12 =3D 34 + { 0, 8, 0, MM_CPU_OFFSET (x64._R13), = MM_CPU_OFFSET (x64._R13) + 4, TRUE }, // EFI_MM_SAVE_STATE_REGIS= TER_R13 =3D 35 + { 0, 8, 0, MM_CPU_OFFSET (x64._R14), = MM_CPU_OFFSET (x64._R14) + 4, TRUE }, // EFI_MM_SAVE_STATE_REGIS= TER_R14 =3D 36 + { 0, 8, 0, MM_CPU_OFFSET (x64._R15), = MM_CPU_OFFSET (x64._R15) + 4, TRUE }, // EFI_MM_SAVE_STATE_REGIS= TER_R15 =3D 37 + { 4, 8, MM_CPU_OFFSET (x86._EAX), MM_CPU_OFFSET (x64._RAX), = MM_CPU_OFFSET (x64._RAX) + 4, TRUE }, // EFI_MM_SAVE_STATE_REGIS= TER_RAX =3D 38 + { 4, 8, MM_CPU_OFFSET (x86._EBX), MM_CPU_OFFSET (x64._RBX), = MM_CPU_OFFSET (x64._RBX) + 4, TRUE }, // EFI_MM_SAVE_STATE_REGIS= TER_RBX =3D 39 + { 4, 8, MM_CPU_OFFSET (x86._ECX), MM_CPU_OFFSET (x64._RCX), = MM_CPU_OFFSET (x64._RCX) + 4, TRUE }, // EFI_MM_SAVE_STATE_REGIS= TER_RCX =3D 40 + { 4, 8, MM_CPU_OFFSET (x86._EDX), MM_CPU_OFFSET (x64._RDX), = MM_CPU_OFFSET (x64._RDX) + 4, TRUE }, // EFI_MM_SAVE_STATE_REGIS= TER_RDX =3D 41 + { 4, 8, MM_CPU_OFFSET (x86._ESP), MM_CPU_OFFSET (x64._RSP), = MM_CPU_OFFSET (x64._RSP) + 4, TRUE }, // EFI_MM_SAVE_STATE_REGIS= TER_RSP =3D 42 + { 4, 8, MM_CPU_OFFSET (x86._EBP), MM_CPU_OFFSET (x64._RBP), = MM_CPU_OFFSET (x64._RBP) + 4, TRUE }, // EFI_MM_SAVE_STATE_REGIS= TER_RBP =3D 43 + { 4, 8, MM_CPU_OFFSET (x86._ESI), MM_CPU_OFFSET (x64._RSI), = MM_CPU_OFFSET (x64._RSI) + 4, TRUE }, // EFI_MM_SAVE_STATE_REGIS= TER_RSI =3D 44 + { 4, 8, MM_CPU_OFFSET (x86._EDI), MM_CPU_OFFSET (x64._RDI), = MM_CPU_OFFSET (x64._RDI) + 4, TRUE }, // EFI_MM_SAVE_STATE_REGIS= TER_RDI =3D 45 + { 4, 8, MM_CPU_OFFSET (x86._EIP), MM_CPU_OFFSET (x64._RIP), = MM_CPU_OFFSET (x64._RIP) + 4, TRUE }, // EFI_MM_SAVE_STATE_REGIS= TER_RIP =3D 46 + + { 4, 8, MM_CPU_OFFSET (x86._EFLAGS), MM_CPU_OFFSET (x64._RFLAGS), = MM_CPU_OFFSET (x64._RFLAGS) + 4, TRUE }, // EFI_MM_SAVE_STATE_REGIS= TER_RFLAGS =3D 51 + { 4, 8, MM_CPU_OFFSET (x86._CR0), MM_CPU_OFFSET (x64._CR0), = MM_CPU_OFFSET (x64._CR0) + 4, FALSE }, // EFI_MM_SAVE_STATE_REGIS= TER_CR0 =3D 52 + { 4, 8, MM_CPU_OFFSET (x86._CR3), MM_CPU_OFFSET (x64._CR3), = MM_CPU_OFFSET (x64._CR3) + 4, FALSE }, // EFI_MM_SAVE_STATE_REGIS= TER_CR3 =3D 53 + { 0, 4, 0, MM_CPU_OFFSET (x64._CR4), = 0, FALSE }, // EFI_MM_SAVE_STATE_REGIS= TER_CR4 =3D 54 +}; + +/// +/// Structure used to build a lookup table for the IOMisc width information +/// +typedef struct { + UINT8 Width; + EFI_MM_SAVE_STATE_IO_WIDTH IoWidth; +} CPU_MM_SAVE_STATE_IO_WIDTH; + +/// +/// Lookup table for the IOMisc width information +/// +STATIC CONST CPU_MM_SAVE_STATE_IO_WIDTH mSmmCpuIoWidth[] =3D { + { 0, EFI_MM_SAVE_STATE_IO_WIDTH_UINT8 }, // Undefined =3D 0 + { 1, EFI_MM_SAVE_STATE_IO_WIDTH_UINT8 }, // SMM_IO_LENGTH_BYTE =3D 1 + { 2, EFI_MM_SAVE_STATE_IO_WIDTH_UINT16 }, // SMM_IO_LENGTH_WORD =3D 2 + { 0, EFI_MM_SAVE_STATE_IO_WIDTH_UINT8 }, // Undefined =3D 3 + { 4, EFI_MM_SAVE_STATE_IO_WIDTH_UINT32 }, // SMM_IO_LENGTH_DWORD =3D 4 + { 0, EFI_MM_SAVE_STATE_IO_WIDTH_UINT8 }, // Undefined =3D 5 + { 0, EFI_MM_SAVE_STATE_IO_WIDTH_UINT8 }, // Undefined =3D 6 + { 0, EFI_MM_SAVE_STATE_IO_WIDTH_UINT8 } // Undefined =3D 7 +}; + +/// +/// Lookup table for the IOMisc type information +/// +STATIC CONST EFI_MM_SAVE_STATE_IO_TYPE mSmmCpuIoType[] =3D { + EFI_MM_SAVE_STATE_IO_TYPE_OUTPUT, // SMM_IO_TYPE_OUT_DX =3D 0 + EFI_MM_SAVE_STATE_IO_TYPE_INPUT, // SMM_IO_TYPE_IN_DX =3D 1 + EFI_MM_SAVE_STATE_IO_TYPE_STRING, // SMM_IO_TYPE_OUTS =3D 2 + EFI_MM_SAVE_STATE_IO_TYPE_STRING, // SMM_IO_TYPE_INS =3D 3 + (EFI_MM_SAVE_STATE_IO_TYPE)0, // Undefined =3D 4 + (EFI_MM_SAVE_STATE_IO_TYPE)0, // Undefined =3D 5 + EFI_MM_SAVE_STATE_IO_TYPE_REP_PREFIX, // SMM_IO_TYPE_REP_OUTS =3D 6 + EFI_MM_SAVE_STATE_IO_TYPE_REP_PREFIX, // SMM_IO_TYPE_REP_INS =3D 7 + EFI_MM_SAVE_STATE_IO_TYPE_OUTPUT, // SMM_IO_TYPE_OUT_IMMEDIATE =3D 8 + EFI_MM_SAVE_STATE_IO_TYPE_INPUT, // SMM_IO_TYPE_OUT_IMMEDIATE =3D 9 + (EFI_MM_SAVE_STATE_IO_TYPE)0, // Undefined =3D 10 + (EFI_MM_SAVE_STATE_IO_TYPE)0, // Undefined =3D 11 + (EFI_MM_SAVE_STATE_IO_TYPE)0, // Undefined =3D 12 + (EFI_MM_SAVE_STATE_IO_TYPE)0, // Undefined =3D 13 + (EFI_MM_SAVE_STATE_IO_TYPE)0, // Undefined =3D 14 + (EFI_MM_SAVE_STATE_IO_TYPE)0 // Undefined =3D 15 +}; + +/** + Read an SMM Save State register on the target processor. If this functi= on + 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 field= 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 stat= e. + @param[out] Buffer Upon return, this holds the CPU register value read + 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 Reg= ister. + @retval EFI_NOT_FOUND If desired Register not found. +**/ +EFI_STATUS +EFIAPI +MmSaveStateReadRegister ( + IN UINTN CpuIndex, + IN EFI_MM_SAVE_STATE_REGISTER Register, + IN UINTN Width, + OUT VOID *Buffer + ) +{ + UINT32 SmmRevId; + SMRAM_SAVE_STATE_IOMISC IoMisc; + EFI_MM_SAVE_STATE_IO_INFO *IoInfo; + + // + // Check for special EFI_MM_SAVE_STATE_REGISTER_LMA + // + if (Register =3D=3D EFI_MM_SAVE_STATE_REGISTER_LMA) { + // + // Only byte access is supported for this register + // + if (Width !=3D 1) { + return EFI_INVALID_PARAMETER; + } + + *(UINT8 *)Buffer =3D MmSaveStateGetRegisterLma (); + + return EFI_SUCCESS; + } + + // + // Check for special EFI_MM_SAVE_STATE_REGISTER_IO + // + if (Register =3D=3D EFI_MM_SAVE_STATE_REGISTER_IO) { + // + // Get SMM Revision ID + // + MmSaveStateReadRegisterByIndex (CpuIndex, INTEL_MM_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 + // + MmSaveStateReadRegisterByIndex (CpuIndex, INTEL_MM_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_MM_SAVE_STATE_IO_TYPE_IN= PUT) && + (mSmmCpuIoType[IoMisc.Bits.Type] !=3D EFI_MM_SAVE_STATE_IO_TYPE_OU= TPUT)) + { + 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) || (mSmmCpuIoT= ype[IoMisc.Bits.Type] =3D=3D 0)) { + return EFI_NOT_FOUND; + } + + // + // Make sure the incoming buffer is large enough to hold IoInfo before= accessing + // + if (Width < sizeof (EFI_MM_SAVE_STATE_IO_INFO)) { + return EFI_INVALID_PARAMETER; + } + + // + // Zero the IoInfo structure that will be returned in Buffer + // + IoInfo =3D (EFI_MM_SAVE_STATE_IO_INFO *)Buffer; + ZeroMem (IoInfo, sizeof (EFI_MM_SAVE_STATE_IO_INFO)); + + // + // Use lookup tables to help fill in all the fields of the IoInfo stru= cture + // + IoInfo->IoPort =3D (UINT16)IoMisc.Bits.Port; + IoInfo->IoWidth =3D mSmmCpuIoWidth[IoMisc.Bits.Length].IoWidth; + IoInfo->IoType =3D mSmmCpuIoType[IoMisc.Bits.Type]; + MmSaveStateReadRegister (CpuIndex, EFI_MM_SAVE_STATE_REGISTER_RAX, mSm= mCpuIoWidth[IoMisc.Bits.Length].Width, &IoInfo->IoData); + return EFI_SUCCESS; + } + + // + // Convert Register to a register lookup table index + // + return MmSaveStateReadRegisterByIndex (CpuIndex, MmSaveStateGetRegisterI= ndex (Register, INTEL_MM_SAVE_STATE_REGISTER_MAX_INDEX), Width, Buffer); +} + +/** + Writes an SMM Save State register on the target processor. If this func= tion + 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 field = 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 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_INVALID_PARAMTER Buffer is NULL. + @retval EFI_UNSUPPORTED This function does not support writing Reg= ister. + @retval EFI_NOT_FOUND If desired Register not found. +**/ +EFI_STATUS +EFIAPI +MmSaveStateWriteRegister ( + IN UINTN CpuIndex, + IN EFI_MM_SAVE_STATE_REGISTER Register, + IN UINTN Width, + IN CONST VOID *Buffer + ) +{ + UINTN RegisterIndex; + SMRAM_SAVE_STATE_MAP *CpuSaveState; + + // + // Writes to EFI_MM_SAVE_STATE_REGISTER_LMA are ignored + // + if (Register =3D=3D EFI_MM_SAVE_STATE_REGISTER_LMA) { + return EFI_SUCCESS; + } + + // + // Writes to EFI_MM_SAVE_STATE_REGISTER_IO are not supported + // + if (Register =3D=3D EFI_MM_SAVE_STATE_REGISTER_IO) { + return EFI_NOT_FOUND; + } + + // + // Convert Register to a register lookup table index + // + RegisterIndex =3D MmSaveStateGetRegisterIndex (Register, INTEL_MM_SAVE_S= TATE_REGISTER_MAX_INDEX); + if (RegisterIndex =3D=3D 0) { + return EFI_NOT_FOUND; + } + + CpuSaveState =3D gSmst->CpuSaveState[CpuIndex]; + + // + // Do not write non-writable SaveState, because it will cause exception. + // + if (!mCpuWidthOffset[RegisterIndex].Writeable) { + return EFI_UNSUPPORTED; + } + + // + // Check CPU mode + // + if (MmSaveStateGetRegisterLma () =3D=3D EFI_MM_SAVE_STATE_REGISTER_LMA_= 32BIT) { + // + // If 32-bit mode width is zero, then the specified register can not b= e accessed + // + if (mCpuWidthOffset[RegisterIndex].Width32 =3D=3D 0) { + return EFI_NOT_FOUND; + } + + // + // If Width is bigger than the 32-bit mode width, then the specified r= egister can not be accessed + // + if (Width > mCpuWidthOffset[RegisterIndex].Width32) { + return EFI_INVALID_PARAMETER; + } + + // + // Write SMM State register + // + ASSERT (CpuSaveState !=3D NULL); + CopyMem ((UINT8 *)CpuSaveState + mCpuWidthOffset[RegisterIndex].Offset= 32, Buffer, Width); + } else { + // + // If 64-bit mode width is zero, then the specified register can not b= e accessed + // + if (mCpuWidthOffset[RegisterIndex].Width64 =3D=3D 0) { + return EFI_NOT_FOUND; + } + + // + // If Width is bigger than the 64-bit mode width, then the specified r= egister can not be accessed + // + if (Width > mCpuWidthOffset[RegisterIndex].Width64) { + return EFI_INVALID_PARAMETER; + } + + // + // Write at most 4 of the lower bytes of SMM State register + // + CopyMem ((UINT8 *)CpuSaveState + mCpuWidthOffset[RegisterIndex].Offset= 64Lo, Buffer, MIN (4, Width)); + if (Width > 4) { + // + // Write at most 4 of the upper bytes of SMM State register + // + CopyMem ((UINT8 *)CpuSaveState + mCpuWidthOffset[RegisterIndex].Offs= et64Hi, (UINT8 *)Buffer + 4, Width - 4); + } + } + + return EFI_SUCCESS; +} + +/** + Returns LMA value of the Processor. + + @retval UINT8 returns LMA bit value. +**/ +UINT8 +MmSaveStateGetRegisterLma ( + VOID + ) +{ + UINT32 RegEax; + UINT32 RegEdx; + UINTN FamilyId; + UINTN ModelId; + UINT8 SmmSaveStateRegisterLma; + + // + // Retrieve CPU Family + // + AsmCpuid (CPUID_VERSION_INFO, &RegEax, NULL, NULL, NULL); + FamilyId =3D (RegEax >> 8) & 0xf; + ModelId =3D (RegEax >> 4) & 0xf; + if ((FamilyId =3D=3D 0x06) || (FamilyId =3D=3D 0x0f)) { + ModelId =3D ModelId | ((RegEax >> 12) & 0xf0); + } + + RegEdx =3D 0; + AsmCpuid (CPUID_EXTENDED_FUNCTION, &RegEax, NULL, NULL, NULL); + if (RegEax >=3D CPUID_EXTENDED_CPU_SIG) { + AsmCpuid (CPUID_EXTENDED_CPU_SIG, NULL, NULL, NULL, &RegEdx); + } + + // + // Determine the mode of the CPU at the time an SMI occurs + // Intel(R) 64 and IA-32 Architectures Software Developer's Manual + // Volume 3C, Section 34.4.1.1 + // + SmmSaveStateRegisterLma =3D EFI_MM_SAVE_STATE_REGISTER_LMA_32BIT; + if ((RegEdx & BIT29) !=3D 0) { + SmmSaveStateRegisterLma =3D EFI_MM_SAVE_STATE_REGISTER_LMA_64BIT; + } + + if (FamilyId =3D=3D 0x06) { + if ((ModelId =3D=3D 0x17) || (ModelId =3D=3D 0x0f) || (ModelId =3D=3D = 0x1c)) { + SmmSaveStateRegisterLma =3D EFI_MM_SAVE_STATE_REGISTER_LMA_64BIT; + } + } + + return SmmSaveStateRegisterLma; +} --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#104795): https://edk2.groups.io/g/devel/message/104795 Mute This Topic: https://groups.io/mt/98848081/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri Apr 19 02:57:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+104797+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1683894775893177.90820665444642; Fri, 12 May 2023 05:32:55 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 26nqYY1788612xk5pW61pjap; Fri, 12 May 2023 05:32:55 -0700 X-Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.107.243.66]) by mx.groups.io with SMTP id smtpd.web10.23686.1683894774635185976 for ; Fri, 12 May 2023 05:32:54 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NBfMcNNZnZK095Gro6qOGwU2UZJkl0DRLyCq2KeEF6LQG/yNY2sbI4rXd4i1nUunOYBW35IVam7jj/rMw57v1+fhBjdGKFn2RMaiY8pvQSj738rJ6z7VdzXV7URHvawMDLKzkYmJZW8ZZTuMojJ16sa/hL0DVbG0iz5OELUFBBGEAPJMUVqfPKwZK1WLT+iyEmO4ON6HWQIuPVVOHwNJ1RRxxu2zOfLsOzwSHd1Ke9/FLqXhWww9Tz9xDv0Im6zzIPBigdkGBZCdKPmrnW7wdEq3vg+idIL/OvUHODWaxll2PQnmCfj+qJ6Jd6punJp6uJxmZuJd6K2yhmHZ3xAJLA== 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=h40ao77p69x6kZH6Ahlc2HWkc6C95ITJtdxQhtEZ56Q=; b=VrdfTbYa4EsG9Occ4hzjDx8wo0K3vHg3rPweReBcDTj8SJVJ1S8Uhi7yumAFctG+tR8ZuUqPfMrrsREvCHRdpM5J1TeoQV0xVzvU2GbtZpvqGMbo0SnIVgLg2cMqgheQcyzRbKmw1Xi4PiQ5sAvmGfjofKiuqz9Xt7gg88iA0a8ktcC1Qak4yva5iTigPQaqqMKeU6sTuyAuNrZT6xu9WyXUzOmLTO3OJVLusHt4EW3adHWMvvAkuGGdsSqOrBiPoYHrgBI8irlXpO0rDuyT0McCTtGzPCpLWX+ESSAge3mo75B3Be02XQBR3xWA3fvBVRzQRnozF0jEpHoJfREjTw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none X-Received: from MW4PR03CA0132.namprd03.prod.outlook.com (2603:10b6:303:8c::17) by DM4PR12MB6086.namprd12.prod.outlook.com (2603:10b6:8:b2::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.18; Fri, 12 May 2023 12:32:51 +0000 X-Received: from CO1NAM11FT104.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8c:cafe::17) by MW4PR03CA0132.outlook.office365.com (2603:10b6:303:8c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.24 via Frontend Transport; Fri, 12 May 2023 12:32:51 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+104797+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT104.mail.protection.outlook.com (10.13.174.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6387.24 via Frontend Transport; Fri, 12 May 2023 12:32:51 +0000 X-Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Fri, 12 May 2023 07:32:48 -0500 X-Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Fri, 12 May 2023 05:32:48 -0700 X-Received: from BLR-LAB-SFW01.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Fri, 12 May 2023 07:32:45 -0500 From: "Abdul Lateef Attar via groups.io" To: CC: Abdul Lateef Attar , Paul Grimes , Abner Chang , Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann , Ard Biesheuvel , Jiewen Yao , Jordan Justen Subject: [edk2-devel] [PATCH v13 7/8] UefiCpuPkg: Removes SmmCpuFeaturesReadSaveStateRegister Date: Fri, 12 May 2023 18:02:23 +0530 Message-ID: <6d3753ef65f94fd56b7ab9b5c9f43f96963caf63.1683894329.git.abdattar@amd.com> In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT104:EE_|DM4PR12MB6086:EE_ X-MS-Office365-Filtering-Correlation-Id: 433287ca-af9b-48d7-5b09-08db52e500c4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: tvAcPIc83/INkx1mLqw8sgG4AD0DoBmgn7QAui778G/3BmH4DF9lCqHNX4rw1sausGKIEWknVSG5jTz80qNwO5WwPoG9ouQyVVHY1CNLUSjECOLfk0n9Qn2MGD8FsfjH9Ljg+4nQL9ci2z7VidnYzCZkzWWCI00pa9E1rZBn57gcozgjVIKaeR/9CQ5qtS0Lml4lagNPdqqLW79o0cokVlPGesK9w/6tcnibjc3TF7Nl/hVF241Ok4lJvp7nnnOLCggACsONkWnsCAcOwmj0143i1RvPTbva/smqoiZ7Eh2Qw5RRJ5udcdpqyu7JyziaXwvA1ej/MD+PVuM8HcksMMHZ1hzfNwUO5uoJMtBPzXn2aPpY2Kx9ByM7rDk/YTTJapSIApgyXXg5kAbVfYIz9lCcUtSV0JrzXVQz52pBkjjlW/M6W3Qv5on+yc31mBEiilW+L7eHDv36p89DELe9Wt631X5Do5VmD+7p86ZbIwoOtWS8hRfa/1f1z69hue4WqWeQl9IO2LgrtF8pnysC4zS2GJD1/Q1vfRpMvWRSlN/l+Fu09s5B85MP3cDg4oTPNC9WmdO0j06BmmfoUaxW/B51g7tQb71XcgqaVLQaONu4X2ZgZ6HsceTUberK2bC5WXp+DvHJi8xmoPITFI8YD2pisZDU3dwnF9CwMyprs9nbxX2i3wtmaXhyXyyy33T/nDR/44S1UrxSZ3NxoTTjIkzLQ+rWAxdLs/50dYELdquOaue+ZHKTpB2ED0AbB4eD0RRGaE99TdvZB7CKuDjZW0EHixEx2s+h7i9O0dgtKbI= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 May 2023 12:32:51.5195 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 433287ca-af9b-48d7-5b09-08db52e500c4 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT104.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6086 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,abdattar@amd.com X-Gm-Message-State: C2JupwJbDJX9S42eABsjANNAx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1683894775; bh=iHRfqacUQ1oItYc6kaFBATlzhWx3xNtefEm1HBEKOU0=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=c+8XiDi371v0lNoLcvSWDD3UCyoP/5QFIwPRo3MOD4P/iSOoDhYhbNI0csKn10LyRZ0 w494Xe/Zdq/hcMMjPwZ3X/Z+bXsLpjIrRodGkSlEmu8uwVlo+7WQF/Pna9w9L+ChmA10A hDKE1tpXW4I/55XYbhENlT4RCz9QuMkIcgk= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1683894777285100011 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4182 Removes SmmCpuFeaturesReadSaveStateRegister and SmmCpuFeaturesWirteSaveStat= eRegister function from SmmCpuFeaturesLib library. 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 and AMD. Cc: Paul Grimes 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 Reviewed-by: Abner Chang Reviewed-by: Ray Ni --- 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(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf b/UefiCpuPkg/PiSm= mCpuDxeSmm/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/In= clude/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 functi= on - 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 field= 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 stat= e. - @param[out] Buffer Upon return, this holds the CPU register value read - 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 Reg= ister. - -**/ -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 func= tion - 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 field = 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 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_INVALID_PARAMETER Buffer is NULL. - @retval EFI_UNSUPPORTED This function does not support writing Reg= ister. -**/ -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 gEfiSmmReadyToLockProtocolG= uid notification is completely processed. diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h b/UefiCpuPkg/PiSmmC= puDxeSmm/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 Vect= or 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 re= gister 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 relocat= ion 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 s= tate. -@param[out] Buffer Upon return, this holds the CPU register value = 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 Sta= te of Processor. -@retval EFI_INVALID_PARAMETER Buffer is NULL, or Width does not meet requi= rement 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 re= gister 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 relocat= ion handler. - -@param[in] CpuIndex Specifies the zero-based index of the CPU save s= tate. -@param[in] RegisterIndex Index into mSmmCpuWidthOffset[] look up table. -@param[in] Width The number of bytes to read from the CPU save st= ate. -@param[in] Buffer Upon entry, this holds the new CPU register valu= e. - -@retval EFI_SUCCESS The register was written to Save State. -@retval EFI_NOT_FOUND The register is not defined for the Save Sta= te 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 functi= on - 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 field= 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 stat= e. - @param[out] Buffer Upon return, this holds the CPU register value read - 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 Reg= ister. - -**/ -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 func= tion - 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 field = 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 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_INVALID_PARAMTER Buffer is NULL. - @retval EFI_UNSUPPORTED This function does not support writing Reg= ister. -**/ -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 functi= on - 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 field= 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 stat= e. - @param[out] Buffer Upon return, this holds the CPU register value read - 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 Reg= ister. - -**/ -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 func= tion - 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 field = 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 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_INVALID_PARAMETER Buffer is NULL. - @retval EFI_UNSUPPORTED This function does not support writing Reg= ister. -**/ -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/PiSmmC= puDxeSmm/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 Vect= or 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, Widt= h, 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, Wid= th, 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/PiSmmC= puDxeSmm/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_S= TATE_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_S= TATE_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 offs= ets -/// 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 information -/// -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_REGI= STER -/// 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_ST= ATE_REGISTER_LDTINFO), - SMM_REGISTER_RANGE (EFI_SMM_SAVE_STATE_REGISTER_ES, EFI_SMM_SAVE_ST= ATE_REGISTER_RIP), - SMM_REGISTER_RANGE (EFI_SMM_SAVE_STATE_REGISTER_RFLAGS, EFI_SMM_SAVE_ST= ATE_REGISTER_CR4), - { (EFI_SMM_SAVE_STATE_REGISTER)0, (EFI_SMM_SAVE_S= TATE_REGISTER)0, 0} -}; - -/// -/// Lookup table used to retrieve the widths and offsets associated with e= ach -/// 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 CP= U Protocol. - // - { 4, 4, SMM_CPU_OFFSET (x86.SMMRevId), SMM_CPU_OFFSET (x64.SMMRevId), = 0, FALSE }, // SMM_SAVE_STATE_REGIST= ER_SMMREVID_INDEX =3D 1 - { 4, 4, SMM_CPU_OFFSET (x86.IOMisc), SMM_CPU_OFFSET (x64.IOMisc), = 0, FALSE }, // SMM_SAVE_STATE_REGIST= ER_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_REGIST= ER_IOMEMADDR_INDEX =3D 3 - - // - // CPU Save State registers defined in PI SMM CPU Protocol. - // - { 0, 8, 0, SMM_CPU_OFFSET (x64.GdtBaseLoDwo= rd), SMM_CPU_OFFSET (x64.GdtBaseHiDword), FALSE }, // EFI_SMM_SAVE_STATE_R= EGISTER_GDTBASE =3D 4 - { 0, 8, 0, SMM_CPU_OFFSET (x64.IdtBaseLoDwo= rd), SMM_CPU_OFFSET (x64.IdtBaseHiDword), FALSE }, // EFI_SMM_SAVE_STATE_R= EGISTER_IDTBASE =3D 5 - { 0, 8, 0, SMM_CPU_OFFSET (x64.LdtBaseLoDwo= rd), SMM_CPU_OFFSET (x64.LdtBaseHiDword), FALSE }, // EFI_SMM_SAVE_STATE_R= EGISTER_LDTBASE =3D 6 - { 0, 0, 0, 0, = 0, FALSE }, // EFI_SMM_SAVE_STATE_R= EGISTER_GDTLIMIT =3D 7 - { 0, 0, 0, 0, = 0, FALSE }, // EFI_SMM_SAVE_STATE_R= EGISTER_IDTLIMIT =3D 8 - { 0, 0, 0, 0, = 0, FALSE }, // EFI_SMM_SAVE_STATE_R= EGISTER_LDTLIMIT =3D 9 - { 0, 0, 0, 0, = 0, FALSE }, // EFI_SMM_SAVE_STATE_R= EGISTER_LDTINFO =3D 10 - - { 4, 4, SMM_CPU_OFFSET (x86._ES), SMM_CPU_OFFSET (x64._ES), = 0, FALSE }, // EFI_SMM_SAVE_STATE_R= EGISTER_ES =3D 20 - { 4, 4, SMM_CPU_OFFSET (x86._CS), SMM_CPU_OFFSET (x64._CS), = 0, FALSE }, // EFI_SMM_SAVE_STATE_R= EGISTER_CS =3D 21 - { 4, 4, SMM_CPU_OFFSET (x86._SS), SMM_CPU_OFFSET (x64._SS), = 0, FALSE }, // EFI_SMM_SAVE_STATE_R= EGISTER_SS =3D 22 - { 4, 4, SMM_CPU_OFFSET (x86._DS), SMM_CPU_OFFSET (x64._DS), = 0, FALSE }, // EFI_SMM_SAVE_STATE_R= EGISTER_DS =3D 23 - { 4, 4, SMM_CPU_OFFSET (x86._FS), SMM_CPU_OFFSET (x64._FS), = 0, FALSE }, // EFI_SMM_SAVE_STATE_R= EGISTER_FS =3D 24 - { 4, 4, SMM_CPU_OFFSET (x86._GS), SMM_CPU_OFFSET (x64._GS), = 0, FALSE }, // EFI_SMM_SAVE_STATE_R= EGISTER_GS =3D 25 - { 0, 4, 0, SMM_CPU_OFFSET (x64._LDTR), = 0, FALSE }, // EFI_SMM_SAVE_STATE_R= EGISTER_LDTR_SEL =3D 26 - { 4, 4, SMM_CPU_OFFSET (x86._TR), SMM_CPU_OFFSET (x64._TR), = 0, FALSE }, // EFI_SMM_SAVE_STATE_R= EGISTER_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_R= EGISTER_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_R= EGISTER_DR6 =3D 29 - { 0, 8, 0, SMM_CPU_OFFSET (x64._R8), = SMM_CPU_OFFSET (x64._R8) + 4, TRUE }, // EFI_SMM_SAVE_STATE_R= EGISTER_R8 =3D 30 - { 0, 8, 0, SMM_CPU_OFFSET (x64._R9), = SMM_CPU_OFFSET (x64._R9) + 4, TRUE }, // EFI_SMM_SAVE_STATE_R= EGISTER_R9 =3D 31 - { 0, 8, 0, SMM_CPU_OFFSET (x64._R10), = SMM_CPU_OFFSET (x64._R10) + 4, TRUE }, // EFI_SMM_SAVE_STATE_R= EGISTER_R10 =3D 32 - { 0, 8, 0, SMM_CPU_OFFSET (x64._R11), = SMM_CPU_OFFSET (x64._R11) + 4, TRUE }, // EFI_SMM_SAVE_STATE_R= EGISTER_R11 =3D 33 - { 0, 8, 0, SMM_CPU_OFFSET (x64._R12), = SMM_CPU_OFFSET (x64._R12) + 4, TRUE }, // EFI_SMM_SAVE_STATE_R= EGISTER_R12 =3D 34 - { 0, 8, 0, SMM_CPU_OFFSET (x64._R13), = SMM_CPU_OFFSET (x64._R13) + 4, TRUE }, // EFI_SMM_SAVE_STATE_R= EGISTER_R13 =3D 35 - { 0, 8, 0, SMM_CPU_OFFSET (x64._R14), = SMM_CPU_OFFSET (x64._R14) + 4, TRUE }, // EFI_SMM_SAVE_STATE_R= EGISTER_R14 =3D 36 - { 0, 8, 0, SMM_CPU_OFFSET (x64._R15), = SMM_CPU_OFFSET (x64._R15) + 4, TRUE }, // EFI_SMM_SAVE_STATE_R= EGISTER_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_R= EGISTER_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_R= EGISTER_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_R= EGISTER_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_R= EGISTER_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_R= EGISTER_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_R= EGISTER_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_R= EGISTER_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_R= EGISTER_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_R= EGISTER_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_R= EGISTER_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_R= EGISTER_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_R= EGISTER_CR3 =3D 53 - { 0, 4, 0, SMM_CPU_OFFSET (x64._CR4), = 0, FALSE }, // EFI_SMM_SAVE_STATE_R= EGISTER_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 state. - - @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; mSmmCpuR= egisterRanges[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 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 reloc= ation 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 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_32BI= T) { - // - // If 32-bit mode width is zero, then the specified register can not b= e 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 r= egister 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[RegisterIn= dex].Offset32, Width); - } else { - // - // If 64-bit mode width is zero, then the specified register can not b= e 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 r= egister 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[RegisterIn= dex].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 + mSmmCpuWidthOf= fset[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 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 reloc= ation 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 req= uirement 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_SMMREV= ID_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_I= NPUT) && - (mSmmCpuIoType[IoMisc.Bits.Type] !=3D EFI_SMM_SAVE_STATE_IO_TYPE_O= UTPUT)) - { - 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) || (mSmmCpuIoT= ype[IoMisc.Bits.Type] =3D=3D 0)) { - return EFI_NOT_FOUND; - } - - // - // Make sure the incoming buffer is large enough to hold IoInfo before= 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 stru= cture - // - 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, mSmm= CpuIoWidth[IoMisc.Bits.Length].Width, &IoInfo->IoData); - return EFI_SUCCESS; - } - - // - // Convert Register to a register lookup table index - // - return ReadSaveStateRegisterByIndex (CpuIndex, GetRegisterIndex (Registe= r), Width, 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 reloc= ation 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 - ) -{ - 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 exception. - // - if (!mSmmCpuWidthOffset[RegisterIndex].Writeable) { - return EFI_UNSUPPORTED; - } - - // - // Check CPU mode - // - if (mSmmSaveStateRegisterLma =3D=3D EFI_SMM_SAVE_STATE_REGISTER_LMA_32BI= T) { - // - // If 32-bit mode width is zero, then the specified register can not b= e 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 r= egister 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].Off= set32, Buffer, Width); - } else { - // - // If 64-bit mode width is zero, then the specified register can not b= e 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 r= egister 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].Off= set64Lo, Buffer, MIN (4, Width)); - if (Width > 4) { - // - // Write at most 4 of the upper bytes of SMM State register - // - CopyMem ((UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].O= ffset64Hi, (UINT8 *)Buffer + 4, Width - 4); - } - } - - return EFI_SUCCESS; -} - /** Hook the code executed immediately after an RSM instruction on the curre= ntly executing CPU. The mode of code executed immediately after RSM must be --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#104797): https://edk2.groups.io/g/devel/message/104797 Mute This Topic: https://groups.io/mt/98848083/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri Apr 19 02:57:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+104798+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1683894783676487.5573410028394; Fri, 12 May 2023 05:33:03 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id T3oCYY1788612x7qYU9UdjZk; Fri, 12 May 2023 05:33:02 -0700 X-Received: from NAM04-MW2-obe.outbound.protection.outlook.com (NAM04-MW2-obe.outbound.protection.outlook.com [40.107.101.75]) by mx.groups.io with SMTP id smtpd.web10.23687.1683894781565491840 for ; Fri, 12 May 2023 05:33:01 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eHg09NILceynrFrgBKS/w14Hj1kfTTwR0m3qKx9v84+nZbhbQ9zH8W59wWkDNyQxWlEd0f9Ugm9wRs98EtxOG/Hht4pQOUNz7DVFiUqSlf8za02sAjGYIMoRXzGHkRc42/xaCSyMjz40peruuW0USeUio5IG9anh2EKSdNJL9jyxj5e6F9fcZfidYVi+lKtDjq5BtC3vYrFDHgM6WhbAVA71wJ8CMA25IrFy1IX4ev9dpuUOpbu7p3qTcc2ndL+xWoZNSKA7trTGe2cPpz9RjAlxg4NfEmQOgOFSV6Ge1ihXvbU8t+89wCU/32dysV1VS+by9JoZPM6gFKSi9kHo/A== 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=TGflBf/RW7MjGtkF+DVeCcqI47x1/yYo0vlWHQj+bvY=; b=aCu3Yrso52VxI7Wvk4COUe/VyolSIbPMY+EL6tKnqtls+Y+/tcxUUdM9GOMeOkHfVJ+fYMWa9Yf1y7oEGBbynoXOHZFBkPNI7BCGXwc/kJ6RCMzeTG/YvZelBx6q7D6mqZzpFxvTi8U3jqQrxe/BVPtEng1UQEOehz1R6H5cq0M5e6UiH2i0uH8NKwpp9AVIktoyEpUNurmWWTODNWEz9aJk7M7Gi5a9sjWUdh+9tYaqK90LEO/0TwlMOygwVNYuVH78fA7paPA8+cn7jNa3kR9Yd/UkygAXYAUQgAdCednDEaadj+lQWaRH8r2a/gJaFwcnu7c9aCPvKCrdzlOjng== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none X-Received: from MW3PR05CA0005.namprd05.prod.outlook.com (2603:10b6:303:2b::10) by BL1PR12MB5125.namprd12.prod.outlook.com (2603:10b6:208:309::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.22; Fri, 12 May 2023 12:32:59 +0000 X-Received: from CO1NAM11FT080.eop-nam11.prod.protection.outlook.com (2603:10b6:303:2b:cafe::ec) by MW3PR05CA0005.outlook.office365.com (2603:10b6:303:2b::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.9 via Frontend Transport; Fri, 12 May 2023 12:32:58 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+104798+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT080.mail.protection.outlook.com (10.13.174.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6387.25 via Frontend Transport; Fri, 12 May 2023 12:32:58 +0000 X-Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Fri, 12 May 2023 07:32:57 -0500 X-Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Fri, 12 May 2023 05:32:57 -0700 X-Received: from BLR-LAB-SFW01.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Fri, 12 May 2023 07:32:48 -0500 From: "Abdul Lateef Attar via groups.io" To: CC: Abdul Lateef Attar , Paul Grimes , Abner Chang , Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann , Ard Biesheuvel , Jiewen Yao , Jordan Justen , Abdul Lateef Attar , "Jiewen Yao" Subject: [edk2-devel] [PATCH v13 8/8] OvmfPkg: Uses MmSaveStateLib library Date: Fri, 12 May 2023 18:02:24 +0530 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT080:EE_|BL1PR12MB5125:EE_ X-MS-Office365-Filtering-Correlation-Id: 4d233687-25c2-4ad9-af7d-08db52e504be X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: dvF3CHbmPvfMzsAleQ3+QNV7nnvCa15HY+92NudEIIR0hZLN7Hx1ogbhUmYO/b+8dkmySY8wJeWjCJkDhkNCQrYzK2j2DBW2hQBOF/BAA7NGhiO+Io65e+bJkul2gZfztdb5LDmXjNFHCa9pmLvU24eiq4zEZmbxahDW7ZRl68qj+bYmh59egYq26AMQDVxNCgIBzfsUBcAx+TM6fFVuxhs9kbtaQnz8nT/lgo/B2KAolPR0rRWBxfjRhqi0CKQE64OoXp3oLQpqijyKA12cscCR/524IcdSfg0Td14IraWviBPYVKwNbayOemVhz9wzZ6j9dueZ0DHx2r7MhFj5N2qKKDI4s3KDNPTfCXJCA16P0SxtNqKeRaETz3s1oKxBrw0u+Iq5atg5LNwLzidpwu1AvPmDwaafpWsHm9y6aWm59AqLMQkNvWCNPCeN7EovR4ybHUf3BXO9rIPZM5wUEtb849tdDPbwdLRHzWGnhxhA+RLIl69HYRP9K8y09OqkcP6Ic2svIGCItVuCs6jOcbDMRYmYTXwyFNzNIWRZZXlyQFdA8SzsEkW/S3Wysyow8NoEf5cSql4PqBQQJoRiG17pB/vK4L3th67HhJsQjRnKh9RNWi/hDsL7qA/nbsozexPK9601ZGbAwpWs2Ps8pBNimOX7mVKALrk7qumNla/30FvuHxMrxgyr8dEJt71vnq3n12Pr/Ak5VW+L/nRcR5JHmVsXqWLiaULZHoZMRXZswpIQ6HVEUM6qr/erIp87 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 May 2023 12:32:58.2245 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4d233687-25c2-4ad9-af7d-08db52e504be X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT080.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5125 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,abdattar@amd.com X-Gm-Message-State: Qiq7egDx93hZtIolJkqCv6Rox1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1683894782; bh=yJYrJFs0CyE4kkhqN8ReSiK35OYABu8tRWxaxKKha0o=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Tl7I/jrGwC2+syXd9guK38FL5Ab4OhOnR9hEYOzvu3JtF98+6rw8baw7ChD86Ur7ozF cxCv1e10HZyxoZL1pnibbyAe+L1T0ztbWywliXiDBTaI+454Aq3NfSOiIkZYywdNR6iV/ a5vwjUoE0Q3KDL6o84WsubCd1LFgl7sJfaA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1683894785156100003 Content-Type: text/plain; charset="utf-8" From: Abdul Lateef Attar BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4182 Uses new MmSaveStateLib library instance. Cc: Paul Grimes 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 Acked-by: Jiewen Yao --- OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 3 + OvmfPkg/OvmfPkgX64.dsc | 1 + .../SmmCpuFeaturesLib/SmmCpuFeaturesLib.c | 767 ------------------ 4 files changed, 5 insertions(+), 767 deletions(-) diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index e333b8b41803..86fc9f6174b2 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -972,6 +972,7 @@ [Components] SmmCpuPlatformHookLib|OvmfPkg/Library/SmmCpuPlatformHookLibQemu/SmmC= puPlatformHookLibQemu.inf SmmCpuFeaturesLib|OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLi= b.inf + MmSaveStateLib|UefiCpuPkg/Library/MmSaveStateLib/AmdMmSaveStateLib.i= nf } =20 # diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 25974230a27e..da5fd7042f4f 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -4,6 +4,7 @@ # Copyright (c) 2006 - 2023, Intel Corporation. All rights reserved.
# (C) Copyright 2016 Hewlett Packard Enterprise Development LP
# Copyright (c) Microsoft Corporation. +# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -444,6 +445,7 @@ [LibraryClasses.common.DXE_SMM_DRIVER] BaseCryptLib|CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf SmmCpuRendezvousLib|UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezv= ousLib.inf + MmSaveStateLib|UefiCpuPkg/Library/MmSaveStateLib/AmdMmSaveStateLib.inf =20 [LibraryClasses.common.SMM_CORE] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf @@ -990,6 +992,7 @@ [Components.X64] SmmCpuPlatformHookLib|OvmfPkg/Library/SmmCpuPlatformHookLibQemu/SmmC= puPlatformHookLibQemu.inf SmmCpuFeaturesLib|OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLi= b.inf + MmSaveStateLib|UefiCpuPkg/Library/MmSaveStateLib/AmdMmSaveStateLib.i= nf } =20 # diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index c1762ffca445..ae706a5099c5 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -1066,6 +1066,7 @@ [Components] SmmCpuPlatformHookLib|OvmfPkg/Library/SmmCpuPlatformHookLibQemu/SmmC= puPlatformHookLibQemu.inf SmmCpuFeaturesLib|OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLi= b.inf + MmSaveStateLib|UefiCpuPkg/Library/MmSaveStateLib/AmdMmSaveStateLib.i= nf } =20 # diff --git a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c b/OvmfPk= g/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c index a009123dae88..4c354bafe42f 100644 --- a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c +++ b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c @@ -578,773 +578,6 @@ SmmCpuFeaturesSetSmmRegister ( ASSERT (FALSE); } =20 -/// -/// Macro used to simplify the lookup table entries of type -/// CPU_SMM_SAVE_STATE_LOOKUP_ENTRY -/// -#define SMM_CPU_OFFSET(Field) OFFSET_OF (QEMU_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 offs= ets -/// associated with each supported EFI_SMM_SAVE_STATE_REGISTER value -/// - -#define SMM_SAVE_STATE_REGISTER_FIRST_INDEX 1 - -typedef struct { - UINT8 Width32; - UINT8 Width64; - UINT16 Offset32; - UINT16 Offset64Lo; - UINT16 Offset64Hi; - BOOLEAN Writeable; -} CPU_SMM_SAVE_STATE_LOOKUP_ENTRY; - -/// -/// Table used by GetRegisterIndex() to convert an EFI_SMM_SAVE_STATE_REGI= STER -/// value to an index into a table of type CPU_SMM_SAVE_STATE_LOOKUP_ENTRY -/// -STATIC 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 e= ach -/// supported EFI_SMM_SAVE_STATE_REGISTER value -/// -STATIC CONST CPU_SMM_SAVE_STATE_LOOKUP_ENTRY mSmmCpuWidthOffset[] =3D { - { - 0, // Width32 - 0, // Width64 - 0, // Offset32 - 0, // Offset64Lo - 0, // Offset64Hi - FALSE // Writeable - }, // Reserved - - // - // CPU Save State registers defined in PI SMM CPU Protocol. - // - { - 0, // Width32 - 8, // Width64 - 0, // Offset32 - SMM_CPU_OFFSET (x64._GDTRBase), // Offset64Lo - SMM_CPU_OFFSET (x64._GDTRBase) + 4, // Offset64Hi - FALSE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_GDTBASE =3D 4 - - { - 0, // Width32 - 8, // Width64 - 0, // Offset32 - SMM_CPU_OFFSET (x64._IDTRBase), // Offset64Lo - SMM_CPU_OFFSET (x64._IDTRBase) + 4, // Offset64Hi - FALSE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_IDTBASE =3D 5 - - { - 0, // Width32 - 8, // Width64 - 0, // Offset32 - SMM_CPU_OFFSET (x64._LDTRBase), // Offset64Lo - SMM_CPU_OFFSET (x64._LDTRBase) + 4, // Offset64Hi - FALSE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_LDTBASE =3D 6 - - { - 0, // Width32 - 0, // Width64 - 0, // Offset32 - SMM_CPU_OFFSET (x64._GDTRLimit), // Offset64Lo - SMM_CPU_OFFSET (x64._GDTRLimit) + 4, // Offset64Hi - FALSE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_GDTLIMIT =3D 7 - - { - 0, // Width32 - 0, // Width64 - 0, // Offset32 - SMM_CPU_OFFSET (x64._IDTRLimit), // Offset64Lo - SMM_CPU_OFFSET (x64._IDTRLimit) + 4, // Offset64Hi - FALSE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_IDTLIMIT =3D 8 - - { - 0, // Width32 - 0, // Width64 - 0, // Offset32 - SMM_CPU_OFFSET (x64._LDTRLimit), // Offset64Lo - SMM_CPU_OFFSET (x64._LDTRLimit) + 4, // Offset64Hi - FALSE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_LDTLIMIT =3D 9 - - { - 0, // Width32 - 0, // Width64 - 0, // Offset32 - 0, // Offset64Lo - 0 + 4, // Offset64Hi - FALSE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_LDTINFO =3D 10 - - { - 4, // Width32 - 4, // Width64 - SMM_CPU_OFFSET (x86._ES), // Offset32 - SMM_CPU_OFFSET (x64._ES), // Offset64Lo - 0, // Offset64Hi - FALSE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_ES =3D 20 - - { - 4, // Width32 - 4, // Width64 - SMM_CPU_OFFSET (x86._CS), // Offset32 - SMM_CPU_OFFSET (x64._CS), // Offset64Lo - 0, // Offset64Hi - FALSE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_CS =3D 21 - - { - 4, // Width32 - 4, // Width64 - SMM_CPU_OFFSET (x86._SS), // Offset32 - SMM_CPU_OFFSET (x64._SS), // Offset64Lo - 0, // Offset64Hi - FALSE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_SS =3D 22 - - { - 4, // Width32 - 4, // Width64 - SMM_CPU_OFFSET (x86._DS), // Offset32 - SMM_CPU_OFFSET (x64._DS), // Offset64Lo - 0, // Offset64Hi - FALSE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_DS =3D 23 - - { - 4, // Width32 - 4, // Width64 - SMM_CPU_OFFSET (x86._FS), // Offset32 - SMM_CPU_OFFSET (x64._FS), // Offset64Lo - 0, // Offset64Hi - FALSE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_FS =3D 24 - - { - 4, // Width32 - 4, // Width64 - SMM_CPU_OFFSET (x86._GS), // Offset32 - SMM_CPU_OFFSET (x64._GS), // Offset64Lo - 0, // Offset64Hi - FALSE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_GS =3D 25 - - { - 0, // Width32 - 4, // Width64 - 0, // Offset32 - SMM_CPU_OFFSET (x64._LDTR), // Offset64Lo - 0, // Offset64Hi - FALSE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_LDTR_SEL =3D 26 - - { - 4, // Width32 - 4, // Width64 - SMM_CPU_OFFSET (x86._TR), // Offset32 - SMM_CPU_OFFSET (x64._TR), // Offset64Lo - 0, // Offset64Hi - FALSE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_TR_SEL =3D 27 - - { - 4, // Width32 - 8, // Width64 - SMM_CPU_OFFSET (x86._DR7), // Offset32 - SMM_CPU_OFFSET (x64._DR7), // Offset64Lo - SMM_CPU_OFFSET (x64._DR7) + 4, // Offset64Hi - FALSE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_DR7 =3D 28 - - { - 4, // Width32 - 8, // Width64 - SMM_CPU_OFFSET (x86._DR6), // Offset32 - SMM_CPU_OFFSET (x64._DR6), // Offset64Lo - SMM_CPU_OFFSET (x64._DR6) + 4, // Offset64Hi - FALSE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_DR6 =3D 29 - - { - 0, // Width32 - 8, // Width64 - 0, // Offset32 - SMM_CPU_OFFSET (x64._R8), // Offset64Lo - SMM_CPU_OFFSET (x64._R8) + 4, // Offset64Hi - TRUE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_R8 =3D 30 - - { - 0, // Width32 - 8, // Width64 - 0, // Offset32 - SMM_CPU_OFFSET (x64._R9), // Offset64Lo - SMM_CPU_OFFSET (x64._R9) + 4, // Offset64Hi - TRUE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_R9 =3D 31 - - { - 0, // Width32 - 8, // Width64 - 0, // Offset32 - SMM_CPU_OFFSET (x64._R10), // Offset64Lo - SMM_CPU_OFFSET (x64._R10) + 4, // Offset64Hi - TRUE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_R10 =3D 32 - - { - 0, // Width32 - 8, // Width64 - 0, // Offset32 - SMM_CPU_OFFSET (x64._R11), // Offset64Lo - SMM_CPU_OFFSET (x64._R11) + 4, // Offset64Hi - TRUE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_R11 =3D 33 - - { - 0, // Width32 - 8, // Width64 - 0, // Offset32 - SMM_CPU_OFFSET (x64._R12), // Offset64Lo - SMM_CPU_OFFSET (x64._R12) + 4, // Offset64Hi - TRUE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_R12 =3D 34 - - { - 0, // Width32 - 8, // Width64 - 0, // Offset32 - SMM_CPU_OFFSET (x64._R13), // Offset64Lo - SMM_CPU_OFFSET (x64._R13) + 4, // Offset64Hi - TRUE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_R13 =3D 35 - - { - 0, // Width32 - 8, // Width64 - 0, // Offset32 - SMM_CPU_OFFSET (x64._R14), // Offset64Lo - SMM_CPU_OFFSET (x64._R14) + 4, // Offset64Hi - TRUE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_R14 =3D 36 - - { - 0, // Width32 - 8, // Width64 - 0, // Offset32 - SMM_CPU_OFFSET (x64._R15), // Offset64Lo - SMM_CPU_OFFSET (x64._R15) + 4, // Offset64Hi - TRUE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_R15 =3D 37 - - { - 4, // Width32 - 8, // Width64 - SMM_CPU_OFFSET (x86._EAX), // Offset32 - SMM_CPU_OFFSET (x64._RAX), // Offset64Lo - SMM_CPU_OFFSET (x64._RAX) + 4, // Offset64Hi - TRUE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_RAX =3D 38 - - { - 4, // Width32 - 8, // Width64 - SMM_CPU_OFFSET (x86._EBX), // Offset32 - SMM_CPU_OFFSET (x64._RBX), // Offset64Lo - SMM_CPU_OFFSET (x64._RBX) + 4, // Offset64Hi - TRUE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_RBX =3D 39 - - { - 4, // Width32 - 8, // Width64 - SMM_CPU_OFFSET (x86._ECX), // Offset32 - SMM_CPU_OFFSET (x64._RCX), // Offset64Lo - SMM_CPU_OFFSET (x64._RCX) + 4, // Offset64Hi - TRUE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_RCX =3D 40 - - { - 4, // Width32 - 8, // Width64 - SMM_CPU_OFFSET (x86._EDX), // Offset32 - SMM_CPU_OFFSET (x64._RDX), // Offset64Lo - SMM_CPU_OFFSET (x64._RDX) + 4, // Offset64Hi - TRUE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_RDX =3D 41 - - { - 4, // Width32 - 8, // Width64 - SMM_CPU_OFFSET (x86._ESP), // Offset32 - SMM_CPU_OFFSET (x64._RSP), // Offset64Lo - SMM_CPU_OFFSET (x64._RSP) + 4, // Offset64Hi - TRUE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_RSP =3D 42 - - { - 4, // Width32 - 8, // Width64 - SMM_CPU_OFFSET (x86._EBP), // Offset32 - SMM_CPU_OFFSET (x64._RBP), // Offset64Lo - SMM_CPU_OFFSET (x64._RBP) + 4, // Offset64Hi - TRUE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_RBP =3D 43 - - { - 4, // Width32 - 8, // Width64 - SMM_CPU_OFFSET (x86._ESI), // Offset32 - SMM_CPU_OFFSET (x64._RSI), // Offset64Lo - SMM_CPU_OFFSET (x64._RSI) + 4, // Offset64Hi - TRUE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_RSI =3D 44 - - { - 4, // Width32 - 8, // Width64 - SMM_CPU_OFFSET (x86._EDI), // Offset32 - SMM_CPU_OFFSET (x64._RDI), // Offset64Lo - SMM_CPU_OFFSET (x64._RDI) + 4, // Offset64Hi - TRUE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_RDI =3D 45 - - { - 4, // Width32 - 8, // Width64 - SMM_CPU_OFFSET (x86._EIP), // Offset32 - SMM_CPU_OFFSET (x64._RIP), // Offset64Lo - SMM_CPU_OFFSET (x64._RIP) + 4, // Offset64Hi - TRUE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_RIP =3D 46 - - { - 4, // Width32 - 8, // Width64 - SMM_CPU_OFFSET (x86._EFLAGS), // Offset32 - SMM_CPU_OFFSET (x64._RFLAGS), // Offset64Lo - SMM_CPU_OFFSET (x64._RFLAGS) + 4, // Offset64Hi - TRUE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_RFLAGS =3D 51 - - { - 4, // Width32 - 8, // Width64 - SMM_CPU_OFFSET (x86._CR0), // Offset32 - SMM_CPU_OFFSET (x64._CR0), // Offset64Lo - SMM_CPU_OFFSET (x64._CR0) + 4, // Offset64Hi - FALSE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_CR0 =3D 52 - - { - 4, // Width32 - 8, // Width64 - SMM_CPU_OFFSET (x86._CR3), // Offset32 - SMM_CPU_OFFSET (x64._CR3), // Offset64Lo - SMM_CPU_OFFSET (x64._CR3) + 4, // Offset64Hi - FALSE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_CR3 =3D 53 - - { - 0, // Width32 - 4, // Width64 - 0, // Offset32 - SMM_CPU_OFFSET (x64._CR4), // Offset64Lo - SMM_CPU_OFFSET (x64._CR4) + 4, // Offset64Hi - FALSE // Writeable - }, // EFI_SMM_SAVE_STATE_REGISTER_CR4 =3D 54 -}; - -// -// No support for I/O restart -// - -/** - Read information from the CPU save state. - - @param Register Specifies the CPU register to read form the save state. - - @retval 0 Register is not valid - @retval >0 Index into mSmmCpuWidthOffset[] associated with Register - -**/ -STATIC -UINTN -GetRegisterIndex ( - IN EFI_SMM_SAVE_STATE_REGISTER Register - ) -{ - UINTN Index; - UINTN Offset; - - for (Index =3D 0, Offset =3D SMM_SAVE_STATE_REGISTER_FIRST_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 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 reloc= ation - 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[out] Buffer Upon return, this holds the CPU register value - 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_PARAMTER This or Buffer is NULL. - -**/ -STATIC -EFI_STATUS -ReadSaveStateRegisterByIndex ( - IN UINTN CpuIndex, - IN UINTN RegisterIndex, - IN UINTN Width, - OUT VOID *Buffer - ) -{ - QEMU_SMRAM_SAVE_STATE_MAP *CpuSaveState; - - CpuSaveState =3D (QEMU_SMRAM_SAVE_STATE_MAP *)gSmst->CpuSaveState[CpuInd= ex]; - - if ((CpuSaveState->x86.SMMRevId & 0xFFFF) =3D=3D 0) { - // - // 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 lower 32-bits of return buffer - // - CopyMem ( - Buffer, - (UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset64Lo, - MIN (4, Width) - ); - if (Width >=3D 4) { - // - // Write upper 32-bits of return buffer - // - CopyMem ( - (UINT8 *)Buffer + 4, - (UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset64= Hi, - Width - 4 - ); - } - } - - return EFI_SUCCESS; -} - -/** - Read an SMM Save State register on the target processor. If this functi= on - 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 field= 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 stat= e. - @param[out] Buffer Upon return, this holds the CPU register value read - 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 - ) -{ - UINTN RegisterIndex; - QEMU_SMRAM_SAVE_STATE_MAP *CpuSaveState; - - // - // 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; - } - - CpuSaveState =3D (QEMU_SMRAM_SAVE_STATE_MAP *)gSmst->CpuSaveState[CpuI= ndex]; - - // - // Check CPU mode - // - if ((CpuSaveState->x86.SMMRevId & 0xFFFF) =3D=3D 0) { - *(UINT8 *)Buffer =3D 32; - } else { - *(UINT8 *)Buffer =3D 64; - } - - return EFI_SUCCESS; - } - - // - // Check for special EFI_SMM_SAVE_STATE_REGISTER_IO - // - if (Register =3D=3D EFI_SMM_SAVE_STATE_REGISTER_IO) { - return EFI_NOT_FOUND; - } - - // - // Convert Register to a register lookup table index. Let - // PiSmmCpuDxeSmm implement other special registers (currently - // there is only EFI_SMM_SAVE_STATE_REGISTER_PROCESSOR_ID). - // - RegisterIndex =3D GetRegisterIndex (Register); - if (RegisterIndex =3D=3D 0) { - return (Register < EFI_SMM_SAVE_STATE_REGISTER_IO ? - EFI_NOT_FOUND : - EFI_UNSUPPORTED); - } - - return ReadSaveStateRegisterByIndex (CpuIndex, RegisterIndex, Width, Buf= fer); -} - -/** - Writes an SMM Save State register on the target processor. If this func= tion - 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 field = 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 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_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 - ) -{ - UINTN RegisterIndex; - QEMU_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. Let - // PiSmmCpuDxeSmm implement other special registers (currently - // there is only EFI_SMM_SAVE_STATE_REGISTER_PROCESSOR_ID). - // - RegisterIndex =3D GetRegisterIndex (Register); - if (RegisterIndex =3D=3D 0) { - return (Register < EFI_SMM_SAVE_STATE_REGISTER_IO ? - EFI_NOT_FOUND : - EFI_UNSUPPORTED); - } - - CpuSaveState =3D (QEMU_SMRAM_SAVE_STATE_MAP *)gSmst->CpuSaveState[CpuInd= ex]; - - // - // Do not write non-writable SaveState, because it will cause exception. - // - if (!mSmmCpuWidthOffset[RegisterIndex].Writeable) { - return EFI_UNSUPPORTED; - } - - // - // Check CPU mode - // - if ((CpuSaveState->x86.SMMRevId & 0xFFFF) =3D=3D 0) { - // - // 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 lower 32-bits of SMM State register - // - CopyMem ( - (UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset64Lo, - Buffer, - MIN (4, Width) - ); - if (Width >=3D 4) { - // - // Write upper 32-bits of SMM State register - // - CopyMem ( - (UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset64= Hi, - (UINT8 *)Buffer + 4, - Width - 4 - ); - } - } - - return EFI_SUCCESS; -} - /** This function is hook point called after the gEfiSmmReadyToLockProtocolG= uid notification is completely processed. --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#104798): https://edk2.groups.io/g/devel/message/104798 Mute This Topic: https://groups.io/mt/98848085/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-