From nobody Fri Mar 29 09:41:19 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+101862+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 1679722738886454.0907988064441; Fri, 24 Mar 2023 22:38:58 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 8VLHYY1788612xLae8CIksD9; Fri, 24 Mar 2023 22:38:58 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.81]) by mx.groups.io with SMTP id smtpd.web11.16378.1679722737782120817 for ; Fri, 24 Mar 2023 22:38:57 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LYN2eyOUhxR8ruUVSRRhEM9Y80mFrlAV/WHblm5jWOfKTxt17arBtJtOFCUI5aS7NQN/GjTcgzd14E5sq0hTLMme0mqUUxzasVfP8YO3ALP5IS/jqD0sC0OJRRs5Q5WIMjdxZN6fOb1adKTybKvfayuRscycO9Sm3BRsOBFBVUXcAC/8sRTtqq4O+1obyemeiBPYSXdQhCClr/4ZXMdReWt8Jg4/o9+5bqXxIUS7qM0UvhW5R0eiwIS7OCzhPNgOeb9rGSEcV6VHeMtRUe3BAyc6Tgyn2q4CiUtzDHnQt3jqgGwM50DHZzBuEVr5x3QafAO9DhC4Y7MyUM4ILlH4mA== 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=0W892hzgxT1qiTRcVstNFQFWrbfJozRUxBsisNQT+E4=; b=hvu/jcUtzzaOVJRfx0MQd5wtv4SnhtFG+FHhn1INnAiK8geoEBQ87hoAKivjviXcqnhDckbZ5J21H7bSkneRq/S2QHYDX7N0u9qbcS2DFRsXRK/UFwdt5fBFxn9LZKDhGIkjPAoanxOO71sBihK18zAeYrxk/7AzWXk9AIdc6ma9SIw91cY6c9xMPgV4ctUpg/osFWqVRhuNLS3lfKaHNDSDqYu2T/ilhJJI8i6EVSox3Y/BKzA1Unh3zvotGXYu74e0sLrpslUQ2avC7z8wbLiEWKrAmk0L18GoKRL9IkdmbuVFRiXQTT1nBCZTdjCy0nBuB9jf0LenWgBFFzn0OA== 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 BN9PR03CA0719.namprd03.prod.outlook.com (2603:10b6:408:ef::34) by SJ0PR12MB5611.namprd12.prod.outlook.com (2603:10b6:a03:426::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37; Sat, 25 Mar 2023 05:38:54 +0000 X-Received: from BN8NAM11FT080.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ef:cafe::5c) by BN9PR03CA0719.outlook.office365.com (2603:10b6:408:ef::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.38 via Frontend Transport; Sat, 25 Mar 2023 05:38:54 +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+101862+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 BN8NAM11FT080.mail.protection.outlook.com (10.13.176.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6222.22 via Frontend Transport; Sat, 25 Mar 2023 05:38:54 +0000 X-Received: from SATLEXMB07.amd.com (10.181.41.45) 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; Sat, 25 Mar 2023 00:38:54 -0500 X-Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Fri, 24 Mar 2023 22:38:53 -0700 X-Received: from BLR-LAB-SFW01.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Sat, 25 Mar 2023 00:38:51 -0500 From: "Abdul Lateef Attar via groups.io" To: CC: Abdul Lateef Attar , Paul Grimes , Garrett Kirkendall , Abner Chang , Michael D Kinney , "Liming Gao" , Zhiguang Liu Subject: [edk2-devel] [PATCH v6 1/6] MdePkg: Adds AMD SMRAM save state map Date: Sat, 25 Mar 2023 11:08:40 +0530 Message-ID: <9657437d32ec09cb1e6f87e3fd928a3f0c7dba44.1679722393.git.abdattar@amd.com> In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT080:EE_|SJ0PR12MB5611:EE_ X-MS-Office365-Filtering-Correlation-Id: 4ec45726-8e61-4869-cc4a-08db2cf338b9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: xX4qOXwQKF+nmN7UhYW4zHP3F39w057MtZJczPVi40g0OJIFg9EJUG9a1YZW2a2mgI2YTQF66ovrRz73Jq5WdlpaaRwOrblfbKrcGTGiV7uIoRB0sA6yk6NV1ZlvZBFm5vuYkPLj83uvPtVFCQJHmWp3elbmuIfcZG4HqSMF71vij+vy3Q68dblHqCRDxDvlHnt7RqvMkC6FIgutohys+rr44AUYUI4V7JX4CcdnygM3AjdpCZ8j5LQHP0VgezmIMm2XB4ARcCGhaXqYj3f1nG/rq33C8uFAtNbN9z2nssc8cJEffxn2F+VfAVfx45zbtQpkeg9y6ezs7MkQCxqzkxZS4S6sSBKNdw9zMM5CXh8EU/bo4CoPxGrcrXlAarF2Wk3nDAvNmuVIGzm22SHDXGr8GulGTnCH2dBKZBKHGej2yGCaylLYgaTle+KBw5vF74l6RR0e7Imp0epGgGljTpIC2wXf32Hv2x+pMUnuFMMYtj7x2hTnEhwmFvLinpAvHNErbYhCzwI+8oEC1kfVTf8Rzw9xL4hqR+WgZT+vWp7O2QNZ1WV4tIjj1efHe9jlD/SasrTxcv6SkIgKTjvv8tF9Heuc87XuCSZ2QsSCpgRnEBg50GwWe/uAHO6W8ZE+CuswfKH5eHDgmZJBWbvQvO6NAL+JsD6tSJmFRhznYR7PLGNmwL0ydgbmfQ5pjFPfbQ8vBaRaWgaIz2tvGaTULhja+4nYbcyLDYPP3/ZGThM= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2023 05:38:54.2964 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4ec45726-8e61-4869-cc4a-08db2cf338b9 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: BN8NAM11FT080.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB5611 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: wrqQ5x1vX2kkuOJMwsGdhNhVx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679722738; bh=/qrVJBC1B0Ps+rk22plC6QbU3AQobwsihJ6OBRZX8Hs=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=NdfapDZeXmW4+TplXshtvaSfU8Xg3pBahySM46SPnikhzIuf6hqItu+0oCyy4BGGW/c gF8ptwx8JYGseFxoYgMmj+kwkF/0GgdblQPlHMp+6jyoVpxdUyJ/tDV8quhScIJhpaDP0 n6kZR1ffz4IIKhvOKuMoFZmxGPj8pC/pARA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679722740433100006 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: Garrett Kirkendall 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 6ba85ebe6186..ac8c93c975ac 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 ## { @@ -67,7 +68,8 @@ "Include/Library/PcdLib.h", "Include/Library/SafeIntLib.h", "Include/Protocol/DebugSupport.h", - "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c" + "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c", + "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 (#101862): https://edk2.groups.io/g/devel/message/101862 Mute This Topic: https://groups.io/mt/97839112/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 Mar 29 09:41:19 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+101863+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 1679722740839255.3413161274134; Fri, 24 Mar 2023 22:39:00 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id UuIFYY1788612xPtYIwALi6y; Fri, 24 Mar 2023 22:39:00 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.41]) by mx.groups.io with SMTP id smtpd.web11.16379.1679722739598078141 for ; Fri, 24 Mar 2023 22:38:59 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fkKhaiIeXSVJNce93hwoNQnv76LZsHpdN1RxjtQZNEbbkL//B+R1r1Y+n3U2uYt/1kYt5aXsrCuAVfyVgW2iqcGfeRK3IP78J5fWquZbdugzVTr4h8dipWUaWHJCXHBkbdXFxObjGi+vxQwaRyXc7iniDrdxhaJLkJ3H70X4n0u/PDP3G+IoykMAoij8pYmxJL7U8y7GKn7W/Z0IIdE+xvOLfUg2vEy/llFb7G+ab379hl5/40IG+nlWbFwtWGT+TUFR2YSB36nZRD0FDDaHvcOLdfOCG5rdM+MMmPb5TZ6HHuvUWHLLPsz0iNfxF1YwTokqob20jIt4JlMjsxAC3Q== 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=+mZvzW5oawn0/6Umyy3XYNgAFQMYP4kgn8SiXipoK60=; b=ddqkkciRDnUaprF2u+22k7Z3MjZoEDj7gp8LwdInvOHJwprJDjQiEZWgbfB645dMijwl5mAE3wQ4u069cMN8fCjvRfTzDUhDMImVdFgPcUg4Hd0GY3bmunoRPYFSWZNO6NqnP5S3jMc5fVrcHtUOxJCoxTnQMoATB4KnpaUB3sUhCVDLfG9lT3C3CWU8OT2cv9bJ2chYPVJw1BWGeX+UMvv95wENRu7oXMv50Jihnh65OuZxTM9fGdsqpmAr5ygi5xTcjfp7s3Au4AA4vzmzDBNZDM0FfK1YEWPCFUqXlnXol+dJNaxwFPtbe8ch5jFlPr52/pzVZVUWtiA4rCbx1A== 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 DS7PR03CA0115.namprd03.prod.outlook.com (2603:10b6:5:3b7::30) by SJ0PR12MB6965.namprd12.prod.outlook.com (2603:10b6:a03:448::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.39; Sat, 25 Mar 2023 05:38:57 +0000 X-Received: from DS1PEPF0000E637.namprd02.prod.outlook.com (2603:10b6:5:3b7:cafe::f5) by DS7PR03CA0115.outlook.office365.com (2603:10b6:5:3b7::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.38 via Frontend Transport; Sat, 25 Mar 2023 05:38:57 +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+101863+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 DS1PEPF0000E637.mail.protection.outlook.com (10.167.17.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6178.30 via Frontend Transport; Sat, 25 Mar 2023 05:38:57 +0000 X-Received: from SATLEXMB07.amd.com (10.181.41.45) 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; Sat, 25 Mar 2023 00:38:56 -0500 X-Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Fri, 24 Mar 2023 22:38:56 -0700 X-Received: from BLR-LAB-SFW01.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Sat, 25 Mar 2023 00:38:54 -0500 From: "Abdul Lateef Attar via groups.io" To: CC: Abdul Lateef Attar , Paul Grimes , Garrett Kirkendall , Abner Chang , Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH v6 2/6] UefiCpuPkg: Adds SmmSmramSaveStateLib library class Date: Sat, 25 Mar 2023 11:08:41 +0530 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E637:EE_|SJ0PR12MB6965:EE_ X-MS-Office365-Filtering-Correlation-Id: ba6dad7a-d231-42f8-2bed-08db2cf33a6d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: PpFwKeL4OYoTXwZhG66x+QcFdxBNyEJN4qZ87QFyUpm4caAKH8Ixl7wt2JKbYQ+1eViFcxMEC3rbcMMyF3mSAPguCHhyAsDFjlrcXq/VWwSzymbyS8DtXmGeLLXTCDiB96RHpcO1Xpt89oL5mimlNPHFV3D5gui2VdHTesxASDkx+m/MUs5pefacoBo2IUjmlfqsEmRni+xF0p1irNzLykEL1+gtJCzbWJLSlPbGZ7Je4vIuACm7Ujyni4bhH+dGRdxWBfKGscQD1q0TbzTei1jj4CEuk6SUKaELxHCPu9O14PbSUprRHFVdtarPobFH2S4F239eQXPtyGrhG393vZbcItDr5Z3kxHimmlljzDroNeR9ksCu582FPGR0c9NiPHhKvyr59PdekLXIFq41p0VPkmg4IfziXzRXanYRovxM8+5qj5eFUyHkhvGu1t+IcXOI/XVuoAubJEMrcoynRqf11r8wtCqZ0cGquCTva0oSIOg+sTGO8cFfiLUN1kNaGNWTF6xPTdMr0amZP9sqnEmo0mfJxFE0Eti5SmleAj7PaxdF9ciTzOYN4M5ocnUg2AAJ/xkp8XXnEUmvpsow+n4alCAJG08TZU/Tx9x1yJREh4i3/MRjU2hSIS1tkYdYfIOjY/evjTohKUhBT4c0gYG5nvbu5uNsHOK1xuoOejAdSqe3FZRRTu1yAyNS8p6Ikl8SRWslN5BWQYN9yYyqVodrxKWEOKeMsuVSQXJPXhW1I2omI5uFeXvpdSBKcWbr X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2023 05:38:57.1184 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ba6dad7a-d231-42f8-2bed-08db2cf33a6d 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: DS1PEPF0000E637.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6965 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: KErJtobavUNG5tTEkEMOmIgEx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679722740; bh=uB5hnCcIcjiQBAkLXHdbfppBwsrEJrxcvRZ8eF64WjU=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=KIoLBpjmoCEDrcdGSPvuO68s7YMEJbCLrqyFQJqmKJ8PiZQQ69rp/Ph0chtwijahgwd rf5TRJuvO0Wfi3lYioJJMqH/OUOJ866e87qyIz2XkM2BkZmEp0I/CPy4PqxVxA2NXpnjI bFsy0lCO4ktx04YbddN5mJ8BINGKNpdn44E= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679722742423100009 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4182 Adds SmmSmramSaveStateLib Library class in UefiCpuPkg.dec. Adds function declaration header file. Cc: Paul Grimes Cc: Garrett Kirkendall 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.dec | 4 ++ .../Include/Library/SmmSmramSaveStateLib.h | 70 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 UefiCpuPkg/Include/Library/SmmSmramSaveStateLib.h diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index 2115aa4387a2..8284237511cc 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 # @@ -65,6 +66,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. + SmmSmramSaveSateLib|Include/Library/SmmSmramSaveStateLib.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/SmmSmramSaveStateLib.h b/UefiCpuPkg= /Include/Library/SmmSmramSaveStateLib.h new file mode 100644 index 000000000000..46bc6381bcde --- /dev/null +++ b/UefiCpuPkg/Include/Library/SmmSmramSaveStateLib.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 SMM_SMRAM_SAVE_STATE_LIB_H_ +#define SMM_SMRAM_SAVE_STATE_LIB_H_ + +#include +#include + +/** + 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 +SmramSaveStateReadRegister ( + 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_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 +SmramSaveStateWriteRegister ( + IN UINTN CpuIndex, + IN EFI_SMM_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 (#101863): https://edk2.groups.io/g/devel/message/101863 Mute This Topic: https://groups.io/mt/97839113/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 Mar 29 09:41:19 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+101864+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 1679722745247504.5443676487123; Fri, 24 Mar 2023 22:39:05 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 4XSZYY1788612x0hiAZ337pk; Fri, 24 Mar 2023 22:39:04 -0700 X-Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com [40.107.237.73]) by mx.groups.io with SMTP id smtpd.web11.16381.1679722744083447586 for ; Fri, 24 Mar 2023 22:39:04 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aAASBzcyCeWEuAzzi0Xoms2ShyeOeBfVfsIJ5Fc+XJs/csLr9t+cOXSfLFyMMsexShUtpWqlJVittnXJHfjkmSiXL8D+0oEWLqT2uNjiRm7xKZr3pdic0orJub/pt8rJdX/2q+Hb7209/Oel4+4dzDych7DKcji1BT1YkR5ME08ZxWN9Abt+Y8Fyoy4SBhWaIONFRsmb/GyY8/s81isNKAzNkXSJ9KQP/QJEWnzcNiK/HE6CcGPukPSlMuYkj9rHKu3eU/wcgpclZXGK0SDMq1sMeKE9O7mOm9yU6ppyp1zg8u0qBbNnHKWYVFHW7OIP/ioSiO2+rkY6GMob8eKHow== 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=zJMdZkKehHzpruQ1VUi5kUTB3MfeLp14eMW7srZcqeU=; b=iEK9y4QWo/k7J8svH3u3EW+65MxqBWErspNO3GLaPgW1ZqI9coRJnttxVyNtDl51NZn4Un+7v08mijuBbf7YwwJE/V0Vg/tx2nV4BtLmUxYDLifC+RGMC08Dw49iFfhOlXKVhvZGMVD2pmQ+AkotcTz++kAW2sDjD4nF+8OxIr5fcRNSD7YwIKIyhIjucOEwg2avIxnFkBngTUokvogPodKgWVy/INKS1eMk0krR6OwDNkj8Qkbv6aWwzk3HWS8rxN30PPYM4HyTda2M+kHkDFrVLrzfhL5QPHEIgQqpue7RGrG1luDby0nnFbhuGAZ6wtfJURrCd8F8JiBYo5N0Yg== 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 BN0PR08CA0025.namprd08.prod.outlook.com (2603:10b6:408:142::10) by PH7PR12MB6634.namprd12.prod.outlook.com (2603:10b6:510:211::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.38; Sat, 25 Mar 2023 05:39:00 +0000 X-Received: from BN8NAM11FT101.eop-nam11.prod.protection.outlook.com (2603:10b6:408:142:cafe::75) by BN0PR08CA0025.outlook.office365.com (2603:10b6:408:142::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.39 via Frontend Transport; Sat, 25 Mar 2023 05:39:00 +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+101864+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 BN8NAM11FT101.mail.protection.outlook.com (10.13.177.126) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6199.26 via Frontend Transport; Sat, 25 Mar 2023 05:39:00 +0000 X-Received: from SATLEXMB04.amd.com (10.181.40.145) 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; Sat, 25 Mar 2023 00:38:59 -0500 X-Received: from BLR-LAB-SFW01.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Sat, 25 Mar 2023 00:38:56 -0500 From: "Abdul Lateef Attar via groups.io" To: CC: Abdul Lateef Attar , Paul Grimes , Garrett Kirkendall , "Abner Chang" , Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann , Abdul Lateef Attar Subject: [edk2-devel] [PATCH v6 3/6] UefiCpuPkg: Implements SmmSmramSaveStateLib library class Date: Sat, 25 Mar 2023 11:08:42 +0530 Message-ID: <4545e74788d5cf001f35d4d74d984602f5bb6f2e.1679722393.git.abdattar@amd.com> In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT101:EE_|PH7PR12MB6634:EE_ X-MS-Office365-Filtering-Correlation-Id: 08120d9a-c782-451c-1327-08db2cf33c4d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: 3aYUAiuC4acA97Rsk94oq40a107OHvmAscbNQ3f4PnvWVJbpaEMDsghbW+qL133PP1MpTc6rEkeW+XpeSDM6m4M2yjl6i87ojg8Ga0VoUkFXbgHzM/6Xd7b/2+VdiwQQ6AGytGdX7PaHrg1Yulb98rtRrsqMY4kY9NdXv2ySZz7pYGF/IoO39JYTK8veqRhfhP0XP7RK2X0xdTsmdlsB8u9aCs2D/SwPMO8oF7nN9tzthlQP/+LUnDiawzNBR/GjdNXnxms80BAtnlYyJowMpEgWLQyzbYbc/BK89RyUOoVR7cQgX0yNUaJ1fi7oRpNEiN6kicmPxNTDV4ftMKOuAW9rMI3DenJEx8cGfWoBwNi5grKoelS0t400e4zVMwNPbLdZipIU6+WkejfDFrkTpgKmqsUEM8flsZDapRxDFVp3I7YqtwpOi4SqaGiG6PTvCqNP/RRdYS/32D1IgZYKthG8X4Vh1ow2Iq8LTniPVpsUmUPRx573m74ywNTVLaX0bk1y/PYzV14FszjJpK5IFqYSII/vPy7SRpYM/4g0+JsWTLbbbEqwEzO3x3QTZMoHcdHD2jq5ncdbO9Ck01b8QHTeM76eVEynk5liAJn1Fq4yZBF3FsyR8rFtwF9P8n9nTY1N1phzPBSc/J0b6PKt2ebdaooejC9fZhK0GBgAGqE9j6iWd4Af/i5pBPIXEYN0/p8Bvg90BR+lzFNoDetdiWaAkxo0bEW9+che4flB020C1/Z2M7+Mrss04ru/yWBA X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2023 05:39:00.2947 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 08120d9a-c782-451c-1327-08db2cf33c4d 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: BN8NAM11FT101.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6634 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: WaURKIppJMBqSl2WcB9Wg1v1x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679722744; bh=+k8FnP2ovsLtLaIxXu9Vjb+qGh8hhOeEIIdmD2qJHu0=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=TYi5FOZfPZ7fayvV2x/bc7dnNdoccxsLHtdwLtGyR2NunENlhK92cRvFR5nRL57FMRC aTcbSlp4QpubgTewiDby8RGcODH+ciOb/VBeMXI2wXozSqsQyzbU9byiTW3Wt9TZapzzI 7H57mm0m243UzfCy6Ng4wpdlvUJWYIuUflA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679722746477100001 Content-Type: text/plain; charset="utf-8" From: Abdul Lateef Attar BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4182 Implements SmmSmramSaveStateLib Library class for AMD cpu family. Cc: Paul Grimes Cc: Garrett Kirkendall 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 + .../AmdSmmSmramSaveStateLib.inf | 28 ++ .../SmmSmramSaveStateLib/SmramSaveState.h | 101 ++++++ .../SmmSmramSaveStateLib/AmdSmramSaveState.c | 318 ++++++++++++++++++ .../SmramSaveStateCommon.c | 124 +++++++ 5 files changed, 574 insertions(+) create mode 100644 UefiCpuPkg/Library/SmmSmramSaveStateLib/AmdSmmSmramSave= StateLib.inf create mode 100644 UefiCpuPkg/Library/SmmSmramSaveStateLib/SmramSaveState.h create mode 100644 UefiCpuPkg/Library/SmmSmramSaveStateLib/AmdSmramSaveSta= te.c create mode 100644 UefiCpuPkg/Library/SmmSmramSaveStateLib/SmramSaveStateC= ommon.c diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index a7318d3fe9db..c9bbff986fbd 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 # @@ -104,6 +105,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 + SmmSmramSaveStateLib|UefiCpuPkg/Library/SmmSmramSaveStateLib/AmdSmmSmram= SaveStateLib.inf =20 [LibraryClasses.common.MM_STANDALONE] MmServicesTableLib|MdePkg/Library/StandaloneMmServicesTableLib/Standalon= eMmServicesTableLib.inf @@ -191,6 +193,7 @@ [Components.IA32, Components.X64] UnitTestResultReportLib|UnitTestFrameworkPkg/Library/UnitTestResultR= eportLib/UnitTestResultReportLibConOut.inf } + UefiCpuPkg/Library/SmmSmramSaveStateLib/AmdSmmSmramSaveStateLib.inf =20 [Components.X64] UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandle= rLibUnitTest.inf diff --git a/UefiCpuPkg/Library/SmmSmramSaveStateLib/AmdSmmSmramSaveStateLi= b.inf b/UefiCpuPkg/Library/SmmSmramSaveStateLib/AmdSmmSmramSaveStateLib.inf new file mode 100644 index 000000000000..91f8927e0419 --- /dev/null +++ b/UefiCpuPkg/Library/SmmSmramSaveStateLib/AmdSmmSmramSaveStateLib.inf @@ -0,0 +1,28 @@ +## @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 AmdSmmSmramSaveStateLib + FILE_GUID =3D FB7D0A60-E8D4-4EFA-90AA-B357BC569879 + MODULE_TYPE =3D DXE_SMM_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D SmmSmramSaveStateLib + +[Sources] + SmramSaveState.h + SmramSaveStateCommon.c + AmdSmramSaveState.c + +[Packages] + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec diff --git a/UefiCpuPkg/Library/SmmSmramSaveStateLib/SmramSaveState.h b/Uef= iCpuPkg/Library/SmmSmramSaveStateLib/SmramSaveState.h new file mode 100644 index 000000000000..6c424e3e36e9 --- /dev/null +++ b/UefiCpuPkg/Library/SmmSmramSaveStateLib/SmramSaveState.h @@ -0,0 +1,101 @@ +/** @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 SMRAM_SAVESTATE_H_ +#define SMRAM_SAVESTATE_H_ + +#include +#include +#include +#include +#include +#include + +// EFER register LMA bit +#define LMA BIT10 + +// Macro used to simplify the lookup table entries of type CPU_SMM_SAVE_ST= ATE_REGISTER_RANGE +#define SMM_REGISTER_RANGE(Start, End) { Start, End, End - Start + 1 } + +#define SMM_SAVE_STATE_REGISTER_MAX_INDEX 2 + +// 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 offse= ts +// associated with each supported EFI_SMM_SAVE_STATE_REGISTER value + +typedef struct { + UINT8 Width32; + UINT8 Width64; + UINT16 Offset32; + UINT16 Offset64Lo; + UINT16 Offset64Hi; + BOOLEAN Writeable; +} CPU_SMM_SAVE_STATE_LOOKUP_ENTRY; + +/** + Returns LMA value of the Processor. + + @param[in] VOID + + @retval UINT8 returns LMA bit value. +**/ +UINT8 +SmramSaveStateGetRegisterLma ( + VOID + ); + +/** + 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 mSmmSmramCpuWidthOffset[] associated with Register + +**/ +UINTN +EFIAPI +SmramSaveStateGetRegisterIndex ( + IN EFI_SMM_SAVE_STATE_REGISTER Register + ); + +/** + 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 mSmmSmramCpuWidthOffset[] 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 +EFIAPI +SmramSaveStateReadRegisterByIndex ( + IN UINTN CpuIndex, + IN UINTN RegisterIndex, + IN UINTN Width, + OUT VOID *Buffer + ); + +#endif diff --git a/UefiCpuPkg/Library/SmmSmramSaveStateLib/AmdSmramSaveState.c b/= UefiCpuPkg/Library/SmmSmramSaveStateLib/AmdSmramSaveState.c new file mode 100644 index 000000000000..8fc4466f473e --- /dev/null +++ b/UefiCpuPkg/Library/SmmSmramSaveStateLib/AmdSmramSaveState.c @@ -0,0 +1,318 @@ +/** @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 "SmramSaveState.h" +#include +#include + +#define EFER_ADDRESS 0XC0000080ul +#define SMM_SAVE_STATE_REGISTER_SMMREVID_INDEX 1 + +// Macro used to simplify the lookup table entries of type CPU_SMM_SAVE_ST= ATE_LOOKUP_ENTRY +#define SMM_CPU_OFFSET(Field) OFFSET_OF (AMD_SMRAM_SAVE_STATE_MAP, Field) + +// Table used by SmramSaveStateGetRegisterIndex() to convert an EFI_SMM_SA= VE_STATE_REGISTER +// value to an index into a table of type CPU_SMM_SAVE_STATE_LOOKUP_ENTRY +CONST CPU_SMM_SAVE_STATE_REGISTER_RANGE mSmmSmramCpuRegisterRanges[] =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 ea= ch +// supported EFI_SMM_SAVE_STATE_REGISTER value +CONST CPU_SMM_SAVE_STATE_LOOKUP_ENTRY mSmmSmramCpuWidthOffset[] =3D { + { 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_R= EGISTER_SMMREVID_INDEX =3D 1 + + // + // CPU Save State registers defined in PI SMM CPU Protocol. + // + { 4, 8, SMM_CPU_OFFSET (x86.GDTBase), SMM_CPU_OFFSET (x64._GDTRBaseLoDw= ord), SMM_CPU_OFFSET (x64._GDTRBaseHiDword), FALSE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_GDTBASE =3D 4 + { 0, 8, 0, SMM_CPU_OFFSET (x64._IDTRBaseLoDw= ord), SMM_CPU_OFFSET (x64._IDTRBaseLoDword), FALSE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_IDTBASE =3D 5 + { 0, 8, 0, SMM_CPU_OFFSET (x64._LDTRBaseLoDw= ord), SMM_CPU_OFFSET (x64._LDTRBaseLoDword), FALSE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_LDTBASE =3D 6 + { 0, 2, 0, SMM_CPU_OFFSET (x64._GDTRLimit), = 0, FALSE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_GDTLIMIT =3D 7 + { 0, 2, 0, SMM_CPU_OFFSET (x64._IDTRLimit), = 0, FALSE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_IDTLIMIT =3D 8 + { 0, 4, 0, SMM_CPU_OFFSET (x64._LDTRLimit), = 0, FALSE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_LDTLIMIT =3D 9 + { 0, 0, 0, 0, = 0, FALSE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_LDTINFO =3D 10 + { 4, 2, SMM_CPU_OFFSET (x86._ES), SMM_CPU_OFFSET (x64._ES), = 0, FALSE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_ES =3D 20 + { 4, 2, SMM_CPU_OFFSET (x86._CS), SMM_CPU_OFFSET (x64._CS), = 0, FALSE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_CS =3D 21 + { 4, 2, SMM_CPU_OFFSET (x86._SS), SMM_CPU_OFFSET (x64._SS), = 0, FALSE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_SS =3D 22 + { 4, 2, SMM_CPU_OFFSET (x86._DS), SMM_CPU_OFFSET (x64._DS), = 0, FALSE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_DS =3D 23 + { 4, 2, SMM_CPU_OFFSET (x86._FS), SMM_CPU_OFFSET (x64._FS), = 0, FALSE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_FS =3D 24 + { 4, 2, SMM_CPU_OFFSET (x86._GS), SMM_CPU_OFFSET (x64._GS), = 0, FALSE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_GS =3D 25 + { 0, 2, 0, SMM_CPU_OFFSET (x64._LDTR), = 0, FALSE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_LDTR_SEL =3D 26 + { 0, 2, 0, SMM_CPU_OFFSET (x64._TR), = 0, FALSE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_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_ST= ATE_REGISTER_DR7 =3D 28 + { 4, 8, SMM_CPU_OFFSET (x86._DR6), SMM_CPU_OFFSET (x64._DR6), = SMM_CPU_OFFSET (x64._DR6) + 4, FALSE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_DR6 =3D 29 + { 0, 8, 0, SMM_CPU_OFFSET (x64._R8), = SMM_CPU_OFFSET (x64._R8) + 4, TRUE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_R8 =3D 30 + { 0, 8, 0, SMM_CPU_OFFSET (x64._R9), = SMM_CPU_OFFSET (x64._R9) + 4, TRUE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_R9 =3D 31 + { 0, 8, 0, SMM_CPU_OFFSET (x64._R10), = SMM_CPU_OFFSET (x64._R10) + 4, TRUE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_R10 =3D 32 + { 0, 8, 0, SMM_CPU_OFFSET (x64._R11), = SMM_CPU_OFFSET (x64._R11) + 4, TRUE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_R11 =3D 33 + { 0, 8, 0, SMM_CPU_OFFSET (x64._R12), = SMM_CPU_OFFSET (x64._R12) + 4, TRUE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_R12 =3D 34 + { 0, 8, 0, SMM_CPU_OFFSET (x64._R13), = SMM_CPU_OFFSET (x64._R13) + 4, TRUE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_R13 =3D 35 + { 0, 8, 0, SMM_CPU_OFFSET (x64._R14), = SMM_CPU_OFFSET (x64._R14) + 4, TRUE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_R14 =3D 36 + { 0, 8, 0, SMM_CPU_OFFSET (x64._R15), = SMM_CPU_OFFSET (x64._R15) + 4, TRUE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_R15 =3D 37 + { 4, 8, SMM_CPU_OFFSET (x86._EAX), SMM_CPU_OFFSET (x64._RAX), = SMM_CPU_OFFSET (x64._RAX) + 4, TRUE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_RAX =3D 38 + { 4, 8, SMM_CPU_OFFSET (x86._EBX), SMM_CPU_OFFSET (x64._RBX), = SMM_CPU_OFFSET (x64._RBX) + 4, TRUE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_RBX =3D 39 + { 4, 8, SMM_CPU_OFFSET (x86._ECX), SMM_CPU_OFFSET (x64._RCX), = SMM_CPU_OFFSET (x64._RCX) + 4, TRUE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_RBX =3D 39 + { 4, 8, SMM_CPU_OFFSET (x86._EDX), SMM_CPU_OFFSET (x64._RDX), = SMM_CPU_OFFSET (x64._RDX) + 4, TRUE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_RDX =3D 41 + { 4, 8, SMM_CPU_OFFSET (x86._ESP), SMM_CPU_OFFSET (x64._RSP), = SMM_CPU_OFFSET (x64._RSP) + 4, TRUE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_RSP =3D 42 + { 4, 8, SMM_CPU_OFFSET (x86._EBP), SMM_CPU_OFFSET (x64._RBP), = SMM_CPU_OFFSET (x64._RBP) + 4, TRUE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_RBP =3D 43 + { 4, 8, SMM_CPU_OFFSET (x86._ESI), SMM_CPU_OFFSET (x64._RSI), = SMM_CPU_OFFSET (x64._RSI) + 4, TRUE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_RSI =3D 44 + { 4, 8, SMM_CPU_OFFSET (x86._EDI), SMM_CPU_OFFSET (x64._RDI), = SMM_CPU_OFFSET (x64._RDI) + 4, TRUE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_RDI =3D 45 + { 4, 8, SMM_CPU_OFFSET (x86._EIP), SMM_CPU_OFFSET (x64._RIP), = SMM_CPU_OFFSET (x64._RIP) + 4, TRUE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_RIP =3D 46 + + { 4, 8, SMM_CPU_OFFSET (x86._EFLAGS), SMM_CPU_OFFSET (x64._RFLAGS), = SMM_CPU_OFFSET (x64._RFLAGS) + 4, TRUE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_RFLAGS =3D 51 + { 4, 8, SMM_CPU_OFFSET (x86._CR0), SMM_CPU_OFFSET (x64._CR0), = SMM_CPU_OFFSET (x64._CR0) + 4, FALSE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_CR0 =3D 52 + { 4, 8, SMM_CPU_OFFSET (x86._CR3), SMM_CPU_OFFSET (x64._CR3), = SMM_CPU_OFFSET (x64._CR3) + 4, FALSE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_CR3 =3D 53 + { 0, 8, 0, SMM_CPU_OFFSET (x64._CR4), = SMM_CPU_OFFSET (x64._CR4) + 4, FALSE}, // EFI_SMM_SAVE_ST= ATE_REGISTER_CR4 =3D 54 + { 0, 0, 0, 0, = 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_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 +SmramSaveStateReadRegister ( + IN UINTN CpuIndex, + IN EFI_SMM_SAVE_STATE_REGISTER Register, + IN UINTN Width, + OUT VOID *Buffer + ) +{ + UINT32 SmmRevId; + EFI_SMM_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_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 SmramSaveStateGetRegisterLma (); + + 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 + // + SmramSaveStateReadRegisterByIndex (CpuIndex, SMM_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_SMM_SAVE_STATE_IO_INFO *)Buffer; + ZeroMem (IoInfo, sizeof (EFI_SMM_SAVE_STATE_IO_INFO)); + + IoInfo->IoPort =3D (UINT16)(CpuSaveState->x64.IO_DWord >> 16u); + + if (CpuSaveState->x64.IO_DWord & 0x10u) { + IoInfo->IoWidth =3D EFI_SMM_SAVE_STATE_IO_WIDTH_UINT8; + DataWidth =3D 0x01u; + } else if (CpuSaveState->x64.IO_DWord & 0x20u) { + IoInfo->IoWidth =3D EFI_SMM_SAVE_STATE_IO_WIDTH_UINT16; + DataWidth =3D 0x02u; + } else { + IoInfo->IoWidth =3D EFI_SMM_SAVE_STATE_IO_WIDTH_UINT32; + DataWidth =3D 0x04u; + } + + if (CpuSaveState->x64.IO_DWord & 0x01u) { + IoInfo->IoType =3D EFI_SMM_SAVE_STATE_IO_TYPE_INPUT; + } else { + IoInfo->IoType =3D EFI_SMM_SAVE_STATE_IO_TYPE_OUTPUT; + } + + if ((IoInfo->IoType =3D=3D EFI_SMM_SAVE_STATE_IO_TYPE_INPUT) || (IoInf= o->IoType =3D=3D EFI_SMM_SAVE_STATE_IO_TYPE_OUTPUT)) { + SmramSaveStateReadRegister (CpuIndex, EFI_SMM_SAVE_STATE_REGISTER_RA= X, DataWidth, &IoInfo->IoData); + } + + return EFI_SUCCESS; + } + + // Convert Register to a register lookup table index + return SmramSaveStateReadRegisterByIndex (CpuIndex, SmramSaveStateGetReg= isterIndex (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. + @retval EFI_NOT_FOUND If desired Register not found. +**/ +EFI_STATUS +EFIAPI +SmramSaveStateWriteRegister ( + IN UINTN CpuIndex, + IN EFI_SMM_SAVE_STATE_REGISTER Register, + IN UINTN Width, + IN CONST VOID *Buffer + ) +{ + UINTN RegisterIndex; + AMD_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 SmramSaveStateGetRegisterIndex (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 (!mSmmSmramCpuWidthOffset[RegisterIndex].Writeable) { + return EFI_UNSUPPORTED; + } + + // + // Check CPU mode + // + if (SmramSaveStateGetRegisterLma () =3D=3D EFI_SMM_SAVE_STATE_REGISTER_L= MA_32BIT) { + // + // If 32-bit mode width is zero, then the specified register can not b= e accessed + // + if (mSmmSmramCpuWidthOffset[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 > mSmmSmramCpuWidthOffset[RegisterIndex].Width32) { + return EFI_INVALID_PARAMETER; + } + + // + // Write SMM State register + // + ASSERT (CpuSaveState !=3D NULL); + CopyMem ((UINT8 *)CpuSaveState + mSmmSmramCpuWidthOffset[RegisterIndex= ].Offset32, Buffer, Width); + } else { + // + // If 64-bit mode width is zero, then the specified register can not b= e accessed + // + if (mSmmSmramCpuWidthOffset[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 > mSmmSmramCpuWidthOffset[RegisterIndex].Width64) { + return EFI_INVALID_PARAMETER; + } + + // + // Write lower 32-bits of SMM State register + // + CopyMem ((UINT8 *)CpuSaveState + mSmmSmramCpuWidthOffset[RegisterIndex= ].Offset64Lo, Buffer, MIN (4, Width)); + if (Width >=3D 4) { + // + // Write upper 32-bits of SMM State register + // + CopyMem ((UINT8 *)CpuSaveState + mSmmSmramCpuWidthOffset[RegisterInd= ex].Offset64Hi, (UINT8 *)Buffer + 4, Width - 4); + } + } + + return EFI_SUCCESS; +} + +/** + Returns LMA value of the Processor. + + @param[in] VOID + + @retval UINT8 returns LMA bit value. +**/ +UINT8 +SmramSaveStateGetRegisterLma ( + VOID + ) +{ + UINT32 LMAValue; + + LMAValue =3D (UINT32)AsmReadMsr64 (EFER_ADDRESS) & LMA; + if (LMAValue) { + return EFI_SMM_SAVE_STATE_REGISTER_LMA_64BIT; + } + + return EFI_SMM_SAVE_STATE_REGISTER_LMA_32BIT; +} diff --git a/UefiCpuPkg/Library/SmmSmramSaveStateLib/SmramSaveStateCommon.c= b/UefiCpuPkg/Library/SmmSmramSaveStateLib/SmramSaveStateCommon.c new file mode 100644 index 000000000000..98e89f9eec3f --- /dev/null +++ b/UefiCpuPkg/Library/SmmSmramSaveStateLib/SmramSaveStateCommon.c @@ -0,0 +1,124 @@ +/** @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 "SmramSaveState.h" + +extern CONST CPU_SMM_SAVE_STATE_REGISTER_RANGE mSmmSmramCpuRegisterRanges= []; +extern CONST CPU_SMM_SAVE_STATE_LOOKUP_ENTRY mSmmSmramCpuWidthOffset[]; + +/** + 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 mSmmSmramCpuWidthOffset[] associated with Register + +**/ +UINTN +EFIAPI +SmramSaveStateGetRegisterIndex ( + IN EFI_SMM_SAVE_STATE_REGISTER Register + ) +{ + UINTN Index; + UINTN Offset; + + for (Index =3D 0, Offset =3D SMM_SAVE_STATE_REGISTER_MAX_INDEX; mSmmSmra= mCpuRegisterRanges[Index].Length !=3D 0; Index++) { + if ((Register >=3D mSmmSmramCpuRegisterRanges[Index].Start) && (Regist= er <=3D mSmmSmramCpuRegisterRanges[Index].End)) { + return Register - mSmmSmramCpuRegisterRanges[Index].Start + Offset; + } + + Offset +=3D mSmmSmramCpuRegisterRanges[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 mSmmSmramCpuWidthOffset[] 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 +EFIAPI +SmramSaveStateReadRegisterByIndex ( + IN UINTN CpuIndex, + IN UINTN RegisterIndex, + IN UINTN Width, + OUT VOID *Buffer + ) +{ + if (RegisterIndex =3D=3D 0) { + return EFI_NOT_FOUND; + } + + if (SmramSaveStateGetRegisterLma () =3D=3D EFI_SMM_SAVE_STATE_REGISTER_L= MA_32BIT) { + // + // If 32-bit mode width is zero, then the specified register can not b= e accessed + // + if (mSmmSmramCpuWidthOffset[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 > mSmmSmramCpuWidthOffset[RegisterIndex].Width32) { + return EFI_INVALID_PARAMETER; + } + + // + // Write return buffer + // + ASSERT (gSmst->CpuSaveState[CpuIndex] !=3D NULL); + CopyMem (Buffer, (UINT8 *)gSmst->CpuSaveState[CpuIndex] + mSmmSmramCpu= WidthOffset[RegisterIndex].Offset32, Width); + } else { + // + // If 64-bit mode width is zero, then the specified register can not b= e accessed + // + if (mSmmSmramCpuWidthOffset[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 > mSmmSmramCpuWidthOffset[RegisterIndex].Width64) { + return EFI_INVALID_PARAMETER; + } + + // + // Write lower 32-bits of return buffer + // + CopyMem (Buffer, (UINT8 *)gSmst->CpuSaveState[CpuIndex] + mSmmSmramCpu= WidthOffset[RegisterIndex].Offset64Lo, MIN (4, Width)); + if (Width >=3D 4) { + // + // Write upper 32-bits of return buffer + // + CopyMem ((UINT8 *)Buffer + 4, (UINT8 *)gSmst->CpuSaveState[CpuIndex]= + mSmmSmramCpuWidthOffset[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 (#101864): https://edk2.groups.io/g/devel/message/101864 Mute This Topic: https://groups.io/mt/97839114/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 Mar 29 09:41:19 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+101865+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 1679722747536134.624657111327; Fri, 24 Mar 2023 22:39:07 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id FwciYY1788612xH0hWHcqG7y; Fri, 24 Mar 2023 22:39:07 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.83]) by mx.groups.io with SMTP id smtpd.web10.16401.1679722745917750926 for ; Fri, 24 Mar 2023 22:39:06 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D0/l8FlL0RhZLQv/tMmejuKlvlTxIyuu8nFTqr/K3hKvzUYrF4Ds1vBm60r56NqmNNExff3j8dZR6OekOG7RUPHYcAQkM2gENS0MKohxx/tJA4Q1EZeuBO04Qj54FMQvWmI5Se7ns1qU8teTDy5nhI04saPjdsi+NXu/6Etn2rx1X5fq6za/4Wi4kSeGIO3RAJToquZnbeG94+bpWorFeLHGbxMlZVR51dLR9IIsSwJa3Yar3gPhZKORgzHt+Tw96LPtmIJw6/hMSopMeUBZ11fWROeMGr3aHsATy0GIaVF6JRj0kES4smSBv1voYU4CcSexIeIwCNCQH41JpG8OdA== 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=myUhYxsmoeKnM6FRVcyQCEsAcfuzS4+WsLq9xpLrJM4=; b=MyD1P47+8/b80ECIv1MvphzFqR7TUREsEUXwbq9Dng4yp5EfneiX5PurnsR30f3evyLcKHDerjxARU95F2QOJusXtoB5otnW1BnnxPTOcxfPXcPdkAeLJFnFE4IXWspG5F31N+Djm527gmFZh7eCOYu+VgbLpK9Zn5OY2Jzq7MHQTCyr+ICkvs+SXtLkUbi9BdZRxv3quqqydazX4qt8PVYV9zfmmg6AsREk3AOAVLfYBJNZ2pC466/mMi/OOHxE/83b7vHvxblkwor35C9aoQwlQvaSz0cTraEoT1FRujoYnMoPFwbLhxlbNEAEi6XN2xiFcqYhz9XePkQhzWzlew== 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 BN0PR02CA0040.namprd02.prod.outlook.com (2603:10b6:408:e5::15) by IA1PR12MB6354.namprd12.prod.outlook.com (2603:10b6:208:3e2::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.41; Sat, 25 Mar 2023 05:39:03 +0000 X-Received: from BN8NAM11FT023.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e5:cafe::cf) by BN0PR02CA0040.outlook.office365.com (2603:10b6:408:e5::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.38 via Frontend Transport; Sat, 25 Mar 2023 05:39:03 +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+101865+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 BN8NAM11FT023.mail.protection.outlook.com (10.13.177.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6222.22 via Frontend Transport; Sat, 25 Mar 2023 05:39:03 +0000 X-Received: from SATLEXMB05.amd.com (10.181.40.146) 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; Sat, 25 Mar 2023 00:39:02 -0500 X-Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Sat, 25 Mar 2023 00:39:02 -0500 X-Received: from BLR-LAB-SFW01.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Sat, 25 Mar 2023 00:39:00 -0500 From: "Abdul Lateef Attar via groups.io" To: CC: Abdul Lateef Attar , Abner Chang , Garrett Kirkendall , "Paul Grimes" , Eric Dong , Ray Ni , Rahul Kumar Subject: [edk2-devel] [PATCH v6 4/6] UefiCpuPkg/SmmCpuFeaturesLib: Restructure arch-dependent code Date: Sat, 25 Mar 2023 11:08:43 +0530 Message-ID: <6c08995a6408d551cc5ab115c53717ffacfa4a95.1679722393.git.abdattar@amd.com> In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT023:EE_|IA1PR12MB6354:EE_ X-MS-Office365-Filtering-Correlation-Id: d1787cf0-5599-4765-6417-08db2cf33e31 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: nmRpIspL6BPjrBEVOygYmuJafXuFPB8Gr8rCBnfwntfw3LsCYQT7t2Ik4Hl9eFic91xILa64dD6Ype1okDlP1xqJhcYn95lluGHDMeFIZc7lC0HMw5Fc+d1opByipGfMN0PEEnGfsyE+gcdOkffZVcG4S5IsYhNUu3AWUVrFxTGxvXUiJ4Erct5MnU8WYx92PPH+hjiPT5s3TCEqGSEy4tFGKupBajlHOYfyKf9Yb2meUue8WgZtEkeaR1ytHxO9ePvguMUctAVBbei10qM7OUoNrTb9E1MG30Hwbtrd35cu0+ZhwId969CvgpNQMBnyvqP83o3jS9af69Xk7DQboWobkvayu7DqNwcfbUpAyqj9G38PzPRfC7SrW/Sh+2iHKTWHDyOnsNyfWn4vIi3KXZflvjMXPSgulMWkoQ5DWKjNdwrMzLemi1T+I2hWrIWgWG5lzBZNMFMdpwY3Nit0dvm98IYwsVEZdUbM9mmyOl1oXuoxPsGFl58ni69tT283UcTEbBhHpujGV02juUg6R8TFGcaUFsWLvQaJFQ+FOiskKKXlppijXqasovprIp66dL0WdN0CFfZXniGlr5GgM/RB6MTQ5AtqeGut+HceUO1uQdnpRGkQlroZaj9Up/gzh/vb4/dOS1V3q8jhwy5w9VSg58fyOUT82HfrFsypljXmRW7XYrfjrehvx2vPv/tvJzcQ4ly4Ra0qyQElpPs5pCCYWYoESgW/5kYLaACbQ3k= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2023 05:39:03.4687 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d1787cf0-5599-4765-6417-08db2cf33e31 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: BN8NAM11FT023.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6354 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: enPoxAL9G3iZHzwlWuasSnPNx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679722747; bh=y9E4E+gyN+PqXr5IWm6I6NOetVMBCqpPQBWQTWcTKfQ=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=KhMSYVRKWKGmQtVKM/72s3oPuk/j8RPp5mv3kzVIhXdsKYVX/tq2eYDTcfFMP9RNJc9 3Kcx5khWDKz6IcK3DjzjCIexesdCrtuAJSRu5o5mapjG0wTsJEfOQfgfaHaIY7sO+Xy84 IVWgPLgoMmjZbyWlGvr2vm0JBzt0cqa1bwA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679722748494100006 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: Garrett Kirkendall Cc: Paul Grimes Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Signed-off-by: Abdul Lateef Attar Reviewed-by: Abner Chang --- .../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 (#101865): https://edk2.groups.io/g/devel/message/101865 Mute This Topic: https://groups.io/mt/97839115/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 Mar 29 09:41:19 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+101866+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 1679722749812163.02392963129637; Fri, 24 Mar 2023 22:39:09 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id b69JYY1788612xylXPnBT3n9; Fri, 24 Mar 2023 22:39:09 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.80]) by mx.groups.io with SMTP id smtpd.web10.16402.1679722748581515840 for ; Fri, 24 Mar 2023 22:39:08 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d9bl7E/wCy0Tb56iPoEI7MydHFRcCoSLLf2CwU6GHtfIJYHmhNxBZF0jc4TbQWN3OCliB3ai7mbun18irTNhPb7NixvAMpw8P9HYBzmBScOcuU5D3UCnRQffKsZ4UMn/pk5CIyYP9o8vOEXL8bbN4vCGNnZBSTFwuqL8+TAe1vMBsm2XLvsLOuiuw3Gwb7z/DoM6zP9RgCDY5+EaNP7Rejdzja5C4wj/+s6Vjptc/Ur8WwGjP8vliJpS6J7MLeR2eziMwk9koE8YkWsLe+yM6Ias0mJclidErLzDnoDEOJrTX4/J2gH9Uk8mLruGzntv5xsBjkmylziRj1nhcDaKMw== 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=FfNL0Yx5Al8qKVw2yhVHFAoA/zWL6hqc0q8A8myvCog=; b=j/42qTz7UCW0/2TlHcmIlvTAOJD48T7D/x+Ug9HRrKCRpsRTVKg9VoKtICDGYqthChIfqn7E3ZBRPDx3Cxp99aQXyyOzY/tsW2+Ov0deoY0HgiRFc+7hZbwPM6UmxFQHyOLlYKCve5gG2IFVLK+2H4u6jc+mcmtX6Uj4gkEd11pFtdtyb5sTN4ZHNz1ZUiqJnd5hmcwFtjeaom5KPdyrGhhDenUKBV4g74H+XNm0rxKSUbfRIJZldXYI/Z+hInrvU4xilgO9FUbOLzuzfSCIq/k9qqbOWRHU0NIk7h7sOTCWeJInTIhc9rJPB90iaXbysJuJ5AuOTN1c5ll1GMTYeQ== 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 DM5PR07CA0074.namprd07.prod.outlook.com (2603:10b6:4:ad::39) by DS7PR12MB6336.namprd12.prod.outlook.com (2603:10b6:8:93::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.38; Sat, 25 Mar 2023 05:39:06 +0000 X-Received: from DS1PEPF0000E638.namprd02.prod.outlook.com (2603:10b6:4:ad:cafe::4d) by DM5PR07CA0074.outlook.office365.com (2603:10b6:4:ad::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.39 via Frontend Transport; Sat, 25 Mar 2023 05:39:06 +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+101866+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 DS1PEPF0000E638.mail.protection.outlook.com (10.167.17.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6178.30 via Frontend Transport; Sat, 25 Mar 2023 05:39:05 +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; Sat, 25 Mar 2023 00:39:05 -0500 X-Received: from SATLEXMB04.amd.com (10.181.40.145) 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, 24 Mar 2023 22:39:05 -0700 X-Received: from BLR-LAB-SFW01.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Sat, 25 Mar 2023 00:39:02 -0500 From: "Abdul Lateef Attar via groups.io" To: CC: Abdul Lateef Attar , Paul Grimes , Garrett Kirkendall , Abner Chang , Eric Dong , Ray Ni , Rahul Kumar Subject: [edk2-devel] [PATCH v6 5/6] UefiCpuPkg: Initial implementation of AMD's SmmCpuFeaturesLib Date: Sat, 25 Mar 2023 11:08:44 +0530 Message-ID: <012b0e0abb98122b7131a7b019ade8603bc04571.1679722393.git.abdattar@amd.com> In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E638:EE_|DS7PR12MB6336:EE_ X-MS-Office365-Filtering-Correlation-Id: fc28fe79-baa2-4f0e-f670-08db2cf33fb1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: jyNQgOCsKQcZ6q1bW/3kCguIF0dE0vzHNNrEsCr0uVde2bvOlaF69RmUAmTIAyWwa7XAc4FfncRTxJ98p4jxEIq1GxGY/J+ADLmvLOqRhgKtFlFOBw1NZ+MHfmhgdfWf3tAn366iqX7sfxHjBql8NDVQU5qBNcIgkvTFQJv/vSf9ifzZLJ/kpyAiBgqfAbwqTAj/2R/+y/svKLX7hOhFgja77Ezx9/LZJctxZ+R5dBmNhX+gUA4NHfEbkLNO6+l5BUHKSzmfXQAuhRKwvdC78dHjDyN31tEKajcjcn1Ckc45YGHUJvXpMmj3KM4RQyK69OrIx90KkcalqCK3/vH3j5YRqvuVsK9vVCay+A6dBrH2lM38bH8pTChUNraurZ4szDYqMpUcrb0OeF/a5Hu2AdIV3Kfokay4Z2F50awOux3xEHU/36N5iRfxZVSxN4MCbMoZl3PPDrYVc95LSEB50TicW55Zi1wAsogeZpoRo5WWT6mwUMzWFFkmfVxGU0pZKfXuu747/wSIJZ944wh+clJx4XOPhOUgJYUE9PjJom54u8RmCq+lTKGGLD4XxPjSRge8o23nFvppKSJKiTjYzrCbxxSDnuZPzzPxx/hgDVIPD53YZ5pqKQwBV4szu7GIFntijvnvHDrzm3fMx6m32LrBjy8ShfJNUDlDRVCG7kzkns/jSoHfEEFQTtN/ArOahuJj6N20BxsZQ0HsL2Lll8y7lzAeEnEEzgN4y+75ZSw= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2023 05:39:05.9734 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fc28fe79-baa2-4f0e-f670-08db2cf33fb1 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: DS1PEPF0000E638.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB6336 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: BXbW4bPjXbcwMOQZn7hPP163x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679722749; bh=4IsVwVZSFhdTYArTkXJk6tPgpEnMshcw0ZzAAkY2iNc=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=gw0DZPwfoOqc+v6/ltueGiYDx8ilielIjRn6defXIRlUU8A6BVYAZnjvIWihrX2Qqwn uxIk4+uo+GqdgBCntF9p128vnf3GznZ2AZX97/j1Yj1X4BzKK1RDGqj5CFUQSgKJtVsNQ xXfYQWi3aGDJtaq50GQ37fpaRQc/NehwvrU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679722750493100010 Content-Type: text/plain; charset="utf-8" From: Abdul Lateef Attar BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4182 Adds initial defination for AMD's SmmCpuFeaturesLib library implementation. All function's body either empty or just returns value. Its initial skeleton of library implementation. Cc: Paul Grimes Cc: Garrett Kirkendall 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 | 8 + .../AmdSmmCpuFeaturesLib.inf | 33 ++ .../SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.c | 345 ++++++++++++++++++ 3 files changed, 386 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 c9bbff986fbd..5e1060a35b1e 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -178,6 +178,13 @@ [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 + SmmCpuPlatformHookLib|UefiCpuPkg/Library/SmmCpuPlatformHookLibNull/S= mmCpuPlatformHookLibNull.inf + } UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf UefiCpuPkg/ResetVector/Vtf0/Bin/ResetVector.inf UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf @@ -194,6 +201,7 @@ [Components.IA32, Components.X64] UnitTestResultReportLib|UnitTestFrameworkPkg/Library/UnitTestResultR= eportLib/UnitTestResultReportLibConOut.inf } UefiCpuPkg/Library/SmmSmramSaveStateLib/AmdSmmSmramSaveStateLib.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..4c77efc64462 --- /dev/null +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf @@ -0,0 +1,33 @@ +## @file +# The CPU specific programming for PiSmmCpuDxeSmm module. +# +# Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
+# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D SmmCpuFeaturesLib + MODULE_UNI_FILE =3D SmmCpuFeaturesLib.uni + FILE_GUID =3D 5849E964-78EC-428E-8CBD-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 diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.c b/= UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.c new file mode 100644 index 000000000000..c74e1a0c0c5b --- /dev/null +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.c @@ -0,0 +1,345 @@ +/** @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 + +/** + 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 EFI_SUCCESS; +} + +/** + 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 EFI_SUCCESS; +} + +/** + Performs library initialization. + + This initialization function contains common functionality shared betwen= all + library instance constructors. + +**/ +VOID +CpuFeaturesLibInitialization ( + VOID + ) +{ +} + +/** + 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 + ) +{ +} + +/** + 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; +} + +/** + 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 (#101866): https://edk2.groups.io/g/devel/message/101866 Mute This Topic: https://groups.io/mt/97839116/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 Mar 29 09:41:19 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+101867+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 1679722755068995.9847431681573; Fri, 24 Mar 2023 22:39:15 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id YZ47YY1788612xUAgra4zZxS; Fri, 24 Mar 2023 22:39:14 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.52]) by mx.groups.io with SMTP id smtpd.web11.16385.1679722754101063561 for ; Fri, 24 Mar 2023 22:39:14 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kPQXUMvmeahgXau2MaT15xEZaZN1id/UfuO0+M0VLaaMheYiddkn2K5B4+F+pb3rRJ4v//gne2CdszPZ4rKeQPBpB21tNxf5kSuyCl672zCJ92W8muc/I9jcugq+dCihceuPX/ZAAuA5+eIPhpKFFda5bbJ8mwfXnvQpkcXSIk/1hSg4BZ5ShVmijt7tt82+kfaN4NJUYs68R+vE6jbBAT0KUUlOqY6W8dmSeIcxPR17V/G1gZUanWdFfO6IcYOu2QsdJfYIjAiJheaU/YuZppMqxN+44oPItMo2adyihxarqz9ZPzbYNycOsf9ow1PiraIjd94yrpt1lGMqtPxL5g== 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=msWDdxhvyL6I4fManKcVeJDaPEbJyqcLEkXz6/eNe0c=; b=TQ0QdYh0Ny/ncQi8qeWCNEFVBxPFzrAw90+DOQ6ZgQbyXoEE14MXJejz16cgEVxUlGIMs0UU+V3klfDl0A7mAXSifuyNCCOx5l+G1YGjQw8bURNrhoV5VfHDji4A0CcxWM7dg5HrHle8vXmCi8NhxRxokOpQdV94qn/48Y+OPvE7nZMHBilo4vSYZaeLGbBpLsju2bYgFFEdqCUCBemMp3V+YOxiSjsYbApcSZ4myZKigCxiWwUwXAw+Im3i39XsO60+u0ltU26UHU5ygd2hXKzMTIxnbphT+xx9XElKWBvmgO2oRqeAITCkjcck7keinuyr/uBvnrrihfQIlN1rEQ== 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 BN9PR03CA0427.namprd03.prod.outlook.com (2603:10b6:408:113::12) by PH8PR12MB7278.namprd12.prod.outlook.com (2603:10b6:510:222::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.41; Sat, 25 Mar 2023 05:39:09 +0000 X-Received: from BN8NAM11FT059.eop-nam11.prod.protection.outlook.com (2603:10b6:408:113:cafe::f7) by BN9PR03CA0427.outlook.office365.com (2603:10b6:408:113::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.40 via Frontend Transport; Sat, 25 Mar 2023 05:39:08 +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+101867+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 BN8NAM11FT059.mail.protection.outlook.com (10.13.177.120) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6222.22 via Frontend Transport; Sat, 25 Mar 2023 05:39:08 +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; Sat, 25 Mar 2023 00:39:08 -0500 X-Received: from SATLEXMB04.amd.com (10.181.40.145) 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, 24 Mar 2023 22:39:07 -0700 X-Received: from BLR-LAB-SFW01.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Sat, 25 Mar 2023 00:39:05 -0500 From: "Abdul Lateef Attar via groups.io" To: CC: Abdul Lateef Attar , Paul Grimes , Garrett Kirkendall , Abner Chang , Eric Dong , Ray Ni , Rahul Kumar , Abdul Lateef Attar Subject: [edk2-devel] [PATCH v6 6/6] UefiCpuPkg: Implements SmmCpuFeaturesLib for AMD Family Date: Sat, 25 Mar 2023 11:08:45 +0530 Message-ID: <19f2778bccfc88ef2f47960a4ae8c7184df3a303.1679722393.git.abdattar@amd.com> In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT059:EE_|PH8PR12MB7278:EE_ X-MS-Office365-Filtering-Correlation-Id: 96653fe4-f4e1-4437-1c3f-08db2cf3413d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: 75lmcoZ95wEOWXQ8ywimPOpT/0z/EOhg0UmZ21LA0p5/vfaxWMbTrqEoSU2c6sg2jqjC0SnMGHXeLYQqY8Nq1AS26SK6ai1rh8N+ZIlAChLBLfWQXbYLvlv7vpHYW0u5HxvgJGdDz97Hpe9fv/OsegyN0ka8btKhdGaxPx1hFkvLnLttBrRfUsbb+ujeRPm7Noew50NsI1yohdo2gEQCm2KbVetWtVmrMWB857PFKh8RInNtbH62AoyPJHXQlntQjQy9ktWgLv0VwztKngDDwrSuNJ0NxA+gW5U8XsUCDdU+RFYLyjX2tw2IiParLfl5mIwSPz4BqgJNWYKGDkWsgCPPeS8xIeKI3X5quiR7zmAaZK1O68Ux/NwDarO9DLM4gSIkjFTROA0fFuMfMct4WW62Lbh56m8oDSvsKH7T2WxVYIWshOAmQwGMuuUUHN9ig7+P6xEm8GzFHz3qZ3tDwzeZE3oU1n1LjkaMANw/c5/eAtiTbSk40sm+StNALvu3FHSecA4mgTQn6RhnymIrsimGTQaKrPPgxcbTunz5m61HAI7DQB4XEU29d2/qOoThJemcLjwLz6KLMGXnQmxZmTzvaMtJB8unUl/QiN1snHs97P7SbYk68agc3JqocXztowyJJB/bCnmy4uHlIVCkyLNdPqpOvuE0ew3kglX8ygH4LmPuSZKsAqAwA5n2sRgDI2g0yLANQ7+ZI1HYnQ5oSinyf66RzFWpiaQnyG7fbGs= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2023 05:39:08.5787 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 96653fe4-f4e1-4437-1c3f-08db2cf3413d 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: BN8NAM11FT059.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB7278 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: 34fBLF6k01NYTQpqj7KvpYHXx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679722754; bh=par2VW0thMK5/ZINIBp37jRowOeXcjGKom6yLBYNAo0=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=sPivCjEH24sOwjyTRoFqIQnezeYxDOW4P2Zj+njfXbpSOIHbVjOi4aU6Jp6aSyU52J8 hywqbTOfFnm8o61oddDcXuw2l9N7A5F53RAmm5rZqrzR4qZOGDx5KQffX2QA+/95xvIGV oNLgo83XFgE9T/KdYICun7feOavi77LTmTQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679722756511100002 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: Garrett Kirkendall Cc: Abner Chang Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Signed-off-by: Abdul Lateef Attar Reviewed-by: Abner Chang --- .../AmdSmmCpuFeaturesLib.inf | 6 + .../SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.c | 106 +++++++++++++++++- 2 files changed, 109 insertions(+), 3 deletions(-) diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf = b/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf index 4c77efc64462..9d5b8c2e972d 100644 --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf @@ -31,3 +31,9 @@ [LibraryClasses] PcdLib MemoryAllocationLib DebugLib + SmmSmramSaveStateLib + +[FeaturePcd] + gUefiCpuPkgTokenSpaceGuid.PcdSmrrEnable ## CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdSmmFeatureControlEnable ## CONSUMES + diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.c b/= UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.c index c74e1a0c0c5b..af45be3e265a 100644 --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.c +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.c @@ -11,6 +11,21 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #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; =20 /** Read an SMM Save State register on the target processor. If this functi= on @@ -39,7 +54,7 @@ SmmCpuFeaturesReadSaveStateRegister ( OUT VOID *Buffer ) { - return EFI_SUCCESS; + return SmramSaveStateReadRegister (CpuIndex, Register, Width, Buffer); } =20 /** @@ -67,7 +82,7 @@ SmmCpuFeaturesWriteSaveStateRegister ( IN CONST VOID *Buffer ) { - return EFI_SUCCESS; + return SmramSaveStateWriteRegister (CpuIndex, Register, Width, Buffer); } =20 /** @@ -82,6 +97,13 @@ 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; + } } =20 /** @@ -117,6 +139,52 @@ SmmCpuFeaturesInitializeProcessor ( 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)); + } + } } =20 /** @@ -159,7 +227,39 @@ SmmCpuFeaturesHookReturnFromSmm ( IN UINT64 NewInstructionPointer ) { - return 0; + 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; } =20 /** --=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 (#101867): https://edk2.groups.io/g/devel/message/101867 Mute This Topic: https://groups.io/mt/97839119/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-