From nobody Mon Apr 29 02:42:04 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+97030+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 1670333030162542.226157669633; Tue, 6 Dec 2022 05:23:50 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id KSj9YY1788612xd7isL8kXiS; Tue, 06 Dec 2022 05:23:49 -0800 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.46]) by mx.groups.io with SMTP id smtpd.web11.47418.1670333029006089471 for ; Tue, 06 Dec 2022 05:23:49 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lFWI4/M0dS3S+TXSEwrbIwhS5mI48zSuo+iR3C6BuT00AfnCrQDSkgwWbfs1m/mREoFwY3ScUoWE8Dm8xNWbM3Mlg7VbfCN6geX0uefhNwfzKKiQTvxLZJivpZs4rKxhVEWOxMueYxWtpjRfAb3Hxgtt3i6N2CycGZZckRuHGQTx6sgu+/m+66BEDIZES89+wDK0OZJnHzyLT6736BoGYQVPqFjwiF4XQq5X3+hSfEiz0mqw0WactB3J9e2cYWVWcN8WZlSK9BtI4lxwH25gbhv3udVVRPh25OuAU7tpg2TeUJc4JNYuY8Z6A0UOBPTQ2E7k+KYKYqdiZvcJm6bCRQ== 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=5cBo1WbaT/DWZ3QNvE0zl3Jra2nGRNQlwdqqNLrAhOY=; b=F2TGAcdEDF3K7KAoqVCOzW76D7x1V6zARqyD6DwmAv8aIpGm8exuO8hqR1RHdOpubDXbnP4EDra+Cv3zrOmzCqlfVbdC5KyEYWNYqFsVemaz07Qs6XcGhT0ivEoIHB7jTS84VkrsDTFx+V7rnTWA5R4aSTRIUjyNQgaxj5mT5WB6ELVrt3Fzaqr4Os97t88cHmiHO8GLD5qsQu5EvOmxxMONoKm3F5M4N5nSNHG7DuK8Lri09RQ8XyoQwZfdKuYgJ+PH+sirZSFAU231Ae4XbKkjaUUh3uMvUqvCIJFMGgs3IrBCDrHoWGgWV/01U7+0kcWGI2L+xS2A+NS99dLEOQ== 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 BN9P223CA0015.NAMP223.PROD.OUTLOOK.COM (2603:10b6:408:10b::20) by DM6PR12MB4282.namprd12.prod.outlook.com (2603:10b6:5:223::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.13; Tue, 6 Dec 2022 13:23:47 +0000 X-Received: from BN8NAM11FT078.eop-nam11.prod.protection.outlook.com (2603:10b6:408:10b:cafe::f0) by BN9P223CA0015.outlook.office365.com (2603:10b6:408:10b::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Tue, 6 Dec 2022 13:23:46 +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+97030+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 BN8NAM11FT078.mail.protection.outlook.com (10.13.176.251) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.14 via Frontend Transport; Tue, 6 Dec 2022 13:23:46 +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; Tue, 6 Dec 2022 07:23:45 -0600 X-Received: from SATLEXMB03.amd.com (10.181.40.144) 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; Tue, 6 Dec 2022 05:23:45 -0800 X-Received: from BLR-LAB-SFW01.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 6 Dec 2022 07:23:43 -0600 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 v1 1/5] UefiCpuPkg/SmmCpuFeaturesLib: Restructure arch-dependent code Date: Tue, 6 Dec 2022 18:53:14 +0530 Message-ID: <4c6e06ace12701059f409fc146c227cc28c5ca6b.1670332633.git.abdattar@amd.com> In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT078:EE_|DM6PR12MB4282:EE_ X-MS-Office365-Filtering-Correlation-Id: ca7e7546-582c-4c01-a9b5-08dad78d1ac3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: sWx+fVzn5oIBZ8qmRNRtcW46xnZsnSzG8s/a7jGphGNCVVaSOjANHE+WqH6OHElhc1uXl2RXfAq/HecC4ZXmRWdw8/S+TLobP7IZVaHjc7tTJjuyZoqkKF31K/Zt54M0BnScwz4aS0Cs0Kn/7tzPndNqcw9+KPQJvj/HwNJExH/3DLUJXYLBlbGDslXCnQLcQAPdEZICnuMUkCf5T7KwrOsXxH6xDuTH2OcxPQJcFQYcRZixioGzJFl2njfK5FLb+niyXO32rCc/wPJZTF3A/49D28tMIxICQZTnE+D7ZD3JsNuT8lnNQxdhLOoE0veLzeW+L2TEewKrfqzYUmiTXW4FymnpSMavYl8VcnE7vpv46I2anl/22xPqHEL1FAXKsKIXcPm6oC+d7N1n8iBfdy7WZ9VbrCvyrfC9lmcIx4WMzdk8Rmzj3iJUULcK5ERiN4/5qSIhH6px/8WwXwaDstQ2G2Qww5rSaLdOjMszXs3njSusyEtE53e7+zR858t15oqh5c6VQKZna8OLNdkL7qBAc8WjrvR0aXWgOYjwQvy73bfiAEpDsrcciaFmKkk6xcrQ8Y5l21Ig9I+vy2rubdlVCAEWK3CRaHxBMSieflOmJDyLhcygm/fYq14NSd0kX5iPx3q3oGUa6BZdWa4WsTtz5h4IXvCDSL3jG/u902tpieYE4d2wwJeAntFV8PDL2g18Cp7sG0wD29DyxLaXSBiwVrqIwhKwDFyVzJQPeWu9aoJlXsFnQF4bf8u8IknrdWZTWK3xUVR9Tyihu6lWDA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Dec 2022 13:23:46.4956 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ca7e7546-582c-4c01-a9b5-08dad78d1ac3 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: BN8NAM11FT078.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4282 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: 8FGeU6te3aHHz1yV45WgKnx2x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1670333029; bh=ruFwHG4T+BjeQ3sjSubecOeBDRUNu57WWrUwynNkK7k=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=macEDbdw8PeX0fIfbuOBnbcxg56vNprD2E2Ufn5Rz92QVrstPqu5h9Ju588uCBA0yJU QW/SyesDi0THaNkYkQVQX0BCDYgRlFyVGh4XdQDm1QlsT30T3KpidXT7+9dRwX3WBkLFO CGoErAEur/IeSpdGX5ni9RHqJ2i9cMPYEEo= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1670333032150100001 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 | 140 ++++++++++++++++++ .../SmmCpuFeaturesLibCommon.c | 140 ------------------ 2 files changed, 140 insertions(+), 140 deletions(-) diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c = b/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c index d5eaaa7a991e..994267f393b3 100644 --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c @@ -400,3 +400,143 @@ 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; +} + +/** + This function is hook point called after the gEfiSmmReadyToLockProtocolG= uid + notification is completely processed. +**/ +VOID +EFIAPI +SmmCpuFeaturesCompleteSmmReadyToLock ( + VOID + ) +{ +} diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c= b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c index 7777e52740eb..2f8841bbbf77 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,103 +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. -**/ -VOID -EFIAPI -SmmCpuFeaturesCompleteSmmReadyToLock ( - VOID - ) -{ -} - /** This API provides a method for a CPU to allocate a specific region for s= toring page tables. =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 (#97030): https://edk2.groups.io/g/devel/message/97030 Mute This Topic: https://groups.io/mt/95492565/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 Mon Apr 29 02:42:04 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+97031+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 1670333033687354.07741775860404; Tue, 6 Dec 2022 05:23:53 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id x8NvYY1788612xYtGxXbAdTk; Tue, 06 Dec 2022 05:23:52 -0800 X-Received: from NAM04-BN8-obe.outbound.protection.outlook.com (NAM04-BN8-obe.outbound.protection.outlook.com [40.107.100.49]) by mx.groups.io with SMTP id smtpd.web11.47421.1670333032075072561 for ; Tue, 06 Dec 2022 05:23:52 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jFz4lGC7G4kKFf98bp0R276D1GlJWJRtYqcq9T6KoUt52fnpGV3GaK2MkHTgWVpf5SGHX9bFtnI2oXEq1GyXvKOiLIRFjH+UIiXEY8TMDw0eNfBr4n0C71rWK+LwzQ1gpFslz4vZKS6qH1sfucojN3GomY9J/ftS8BeAWP5kr8FpRklEMy7yFBd2Fki7H0BgIE3tEsRyFZmEAaLtIrX3doD01HvFfGHUN2ULUm6UES9IJsfFjciYMijfuq5RD8/PxoZNXIf5R8N0+jqm4Vwr3vmy78zWxzhd5YSWqqRbgVsBGAp0T33qhEFCuPcmveyOJ4yUvPsew9Fl2Cu4sIwqvg== 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=hDhb8DjHsObBxT/bdgmjFPjGIdRFAWWBu0w7Lolx03k=; b=CsPZBxr2O8AoBcCn31O4O7VIoKvA0JolKMd6mCS6bRGhRiFRK9SkUVSozCQRz3UVVlaIw4cvkZCZsblHDjR0Es/OmCyT1L2RCKQvIrUD5dhODperP+mbBbGhK2Uwo4KgLrBg2BraQpcqWW+h1ai6gD+lCONxPUkMz153MbL6ez/7LLwjAYafWApkXiOeYyFoxG4gfnOmdLxQrLvB5KqJyMftDN4BeizanhAgNqPTSms9NHYUCtbQqjIdJYDeofzR0vgMqi8CNeYXGKqxyTyIlM3loI4QNnyG6/dMZ7J0WO1u08omPKuA/wxrCIYUeOIy1YBhws/tbdKVvNZzyj1GIA== 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 BN1PR13CA0010.namprd13.prod.outlook.com (2603:10b6:408:e2::15) by DM4PR12MB7525.namprd12.prod.outlook.com (2603:10b6:8:113::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Tue, 6 Dec 2022 13:23:49 +0000 X-Received: from BN8NAM11FT050.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e2:cafe::84) by BN1PR13CA0010.outlook.office365.com (2603:10b6:408:e2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5901.8 via Frontend Transport; Tue, 6 Dec 2022 13:23:49 +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+97031+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 BN8NAM11FT050.mail.protection.outlook.com (10.13.177.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.14 via Frontend Transport; Tue, 6 Dec 2022 13:23:49 +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; Tue, 6 Dec 2022 07:23:48 -0600 X-Received: from SATLEXMB03.amd.com (10.181.40.144) 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; Tue, 6 Dec 2022 05:23:48 -0800 X-Received: from BLR-LAB-SFW01.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 6 Dec 2022 07:23:45 -0600 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 v1 2/5] MdePkg: Adds AMD SMRAM save state map Date: Tue, 6 Dec 2022 18:53:15 +0530 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT050:EE_|DM4PR12MB7525:EE_ X-MS-Office365-Filtering-Correlation-Id: e44533df-9831-4cf0-2bb1-08dad78d1c5f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: NrxZXrXV3Uyb2iJRQdw7XidAzMsCR9V9Yr7D1ElKUREGMFNU0zkjzVwt/0+xcCum0RcTACblv5yfGObFZay/iFy5Fks4TV3jr4h4yV5xj4eMhlmv9NH+0f909JTjdVEM09mBqywHgQFFNhBGmFASSX1+Aj2db97JbS9ungrgMuJ3R3p1qVwohs1sVR8eKsAScS83GM0fAY/0u0bYjdxAG/ao1fWxC/QijgKzasBDdwc/qAbvuIJOBuZegtqOcZeIbeW/sE3pTjbVGH32x3z+6LZAgGUfURU4ahTQnWZh2Yg3hWxP5F3bLlC812ptjhefe23dHzJKP5aZElQLTzBibdiv3MYX89+VN58xrsmypimEMMXo+d/k3wEAwAoNuWmSGhMC77PvYROtw1+aSz0WWDN6rlpNhCIArAtEUr72jkZ8WHqT1r4eOPTscvmnXz1bjE44toaRhGhlogahPYh6eYr300rNPa+DErGeC+zwoqlZFiK8RVn9KOctyBRC1uhP8ceNp3ydmAf8XK0xMMwHfnPONBm6ibse9eBZefkIx3ti3MIHKB52h6MpMcAmcLEXKlcRcQJl/Wzrn3tme/5tZJorGS2icWLyiOOqbGRgcjT4pAhVQiBDH2Wnud27LOxWBr/apiKuoj+b3nZD9QNgQcgHIBJJd3ad70IP1g4Acm7+BEQDFOAlnBJBdOSEuDeCIFlkuT5DGxPytJxG9DOKly+ZFP7V0W+ZCOQYc5fHP56A+YvQBbyNbNLPsixzbb1te7WaciEVq4wrsMZDp2Zjpg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Dec 2022 13:23:49.2237 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e44533df-9831-4cf0-2bb1-08dad78d1c5f 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: BN8NAM11FT050.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7525 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: 2gd87x361tpgVeB6a7OtVQeDx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1670333032; bh=9Lwnytz7rw/xHTKW+yp5aGWWkoINH4148dk4dq9k1qY=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=lD3UPTLu5ld3nCLr16t5oQNsDd4E1k33kgoW7kvy0WjZsHRWmiy+Sci2Yuy+DEeRGVi NkkSlxGbL3dvB5NCVWm4Jy0jXgE520nMJIWXVPACWnbzopez9z69N59uMPKoEdPhJCc+A OiWJ9NckleaFYAxmJaUXpyqDL5uqupZU19k= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1670333034169100006 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 --- .../Include/Register/Amd/SmramSaveStateMap.h | 194 ++++++++++++++++++ MdePkg/MdePkg.ci.yaml | 3 +- 2 files changed, 196 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..6da1538608cf --- /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) 2022 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 19bc0138cb76..86c9c502d799 100644 --- a/MdePkg/MdePkg.ci.yaml +++ b/MdePkg/MdePkg.ci.yaml @@ -65,7 +65,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 (#97031): https://edk2.groups.io/g/devel/message/97031 Mute This Topic: https://groups.io/mt/95492567/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 Mon Apr 29 02:42:04 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+97032+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 1670333036604517.9474168217861; Tue, 6 Dec 2022 05:23:56 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 0kixYY1788612xgb1c0ljQVm; Tue, 06 Dec 2022 05:23:56 -0800 X-Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.107.243.54]) by mx.groups.io with SMTP id smtpd.web10.47561.1670333035713353510 for ; Tue, 06 Dec 2022 05:23:55 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZORZxvvG+j0jBnZE9OqJTgUovyB5ndSKZNCeevyFHUqoSdZ4qDUotvDZcrSUs4nb7Tw+pD0GDfDapXhrT/FQ2nOXeZcI7wuhjQbidRRg/J/zSUhBx2A0n8gpJ5lZWrfV6rLoaRCJenx727sK2XTaY2JMKTfUl12uVWK1+qtVxcfOgQHsmFmwH6vV27w1acdA65kK949PFgPVsi32MZQDV6tGDkYFZ7AY44KvVwEmjttRfXQgR7ZO8m/sdqDChOC5uZibC7YYMXfc2WQ+TAsXFTrBfuJdHQ6A8ZetQjkzrt/lDw9KWgkdt+z2FRnbryDnWuPBktAH42fGhS/npMLI5g== 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=Y8hnGvxF98A24hoAFL2GZZzGKrbYAVINPx5CiqrUmK4=; b=V1TL+Waaipud6YoM0YoUDpN86F4D1KBIzYueIZYcAB7W489ODfguqkGcM2fGbP/hmnertaVA4gUf9ouT6Jk7VotVexHtuXn1byyL8B8273zydLmbKJX8CA39pABJqurGG7qHzK3A/TD4m7zEqcwsxWfCTyxIof1PKZO1wgzsp2z2YcFFIAU6MoA8iKA1RiH/WJ/PmFmdsc0K++I5QB1aa2N4RIS+zSbLX1k6R4Gjp1CnUycNKdh0DhW9xdryoEBwjgMw1m7a4+HCyoSEtHmgtCl1C0ztRDGpGPp+CIHmJNXstHMgiXnrmz2k3pWYdrtfkt9IakwlOkrWwe3Zo8n34w== 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 BN8PR07CA0035.namprd07.prod.outlook.com (2603:10b6:408:ac::48) by MN2PR12MB4568.namprd12.prod.outlook.com (2603:10b6:208:260::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Tue, 6 Dec 2022 13:23:52 +0000 X-Received: from BN8NAM11FT069.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ac:cafe::8e) by BN8PR07CA0035.outlook.office365.com (2603:10b6:408:ac::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Tue, 6 Dec 2022 13:23:52 +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+97032+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 BN8NAM11FT069.mail.protection.outlook.com (10.13.176.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.14 via Frontend Transport; Tue, 6 Dec 2022 13:23:51 +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; Tue, 6 Dec 2022 07:23:51 -0600 X-Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 6 Dec 2022 05:23:50 -0800 X-Received: from BLR-LAB-SFW01.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 6 Dec 2022 07:23:48 -0600 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 v1 3/5] UefiCpuPkg: Initial implementation of AMD's SmmCpuFeaturesLib Date: Tue, 6 Dec 2022 18:53:16 +0530 Message-ID: <6d3a8cd3b4c1080edfaa1e6cadeec3855e49b828.1670332633.git.abdattar@amd.com> In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT069:EE_|MN2PR12MB4568:EE_ X-MS-Office365-Filtering-Correlation-Id: e96d2231-04e5-473b-dcbf-08dad78d1dfe X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: /tyGK5VjMIJwdDwfpkN2KJSsSGn4zE5TlVQqe3n1QNYJUewlAhO3bhRb21VPWzzvAlQyFuNA51lbNfqM7kgElFKf3dtEFhP68FrHUAZ63Gy0OdjiqkePGOG+b/2Ty+7FffQFazOApoXr6f1SbL5rEydtv4kpaHKOLq9ydy9DlZQ3H/hxu1WtM+wXfG133yP5AaMudOr8jwPdgupi0x56Ur0LH12YIqV9nulNf961Sz5sdld+jPUCyByuzum9RkkmmmDbzwmv6PUn7SUhsLSUfYz/ldvwsxGxa9fI6L4fJxlymeuCEsutB2jzvnfkZouEvpV2tf7mIvPU3s/1v4Qvnrm6QQ858fSN1gD8zaC/F84/e9hoPqHX+pjMMhdrJGLxchJmEzxUG7eBxv730Puy700QS/WN0Zu5J7OQADFWp7xH4i5J3vui5zBMUICTIUTgiuBRlV5lecAftCr3enCdemVQJQBpVbRGiy/PToOABq3AqEUjXuURcOKukCE/jEzekNvUCMeC8P1dLMTyZfrZZHKMVvA15rLZBIuZNWqV9HhM2V+CR2c1bY72M9F52h+nvcM20dRDrfGM2al9WzbIpJ+4aXahAY7HR52u+n0b5ugbnxeQshf5Xptr1ueY2CK2GifmM1LpTavMIOLNf0qoOq7n0wdR2Kv2KPlDwFihtjH/Y+tLfOF6sawX+rnY887l7Eo0OxNdNSR6ZPl1vGBcJVG2v1Cfm1qdt+RhmimrC5sLBkD0bN9ba831izc2UQPtC5dBDKBWyx0K50UH7oAXbQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Dec 2022 13:23:51.9480 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e96d2231-04e5-473b-dcbf-08dad78d1dfe 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: BN8NAM11FT069.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4568 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: cSOoHDedKZi67pqPF5eHfboRx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1670333036; bh=yPrJ/6576Ev67vL9ihalPdb1vB4I7DABXPlJWDshaMg=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=maPfJTW/b+rg28PBY9jcTqvr0V09IoNDGLXZ2H7qk42GTB56KNfbcvOvGIZ6SfgMaVS oVbtGsPz5GceKoK+n/nqnZuH5Wkln5ZosCbcGeI0MRGkYrimvBL67rizd0EYtwX9zZ35+ LVQuqgvzg3+V+kyj3XE00fU8w0RURxqJbLs= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1670333038207100002 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 --- UefiCpuPkg/UefiCpuPkg.dsc | 9 + .../AmdSmmCpuFeaturesLib.inf | 37 ++ .../SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c | 357 ++++++++++++++++++ 3 files changed, 403 insertions(+) create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesL= ib.inf create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmmCpuFeatures= Lib.c diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index 67b0ce46e455..8aeaf992af9b 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) 2022 Advanced Micro Devices, Inc. All rights reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -160,6 +161,7 @@ [Components.IA32, Components.X64] UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeaturesLib.inf UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeaturesLib.inf UefiCpuPkg/Library/SmmCpuPlatformHookLibNull/SmmCpuPlatformHookLibNull.i= nf + UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf @@ -176,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 diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf = b/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf new file mode 100644 index 000000000000..08ac0262022f --- /dev/null +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf @@ -0,0 +1,37 @@ +## @file +# The CPU specific programming for PiSmmCpuDxeSmm module. +# +# Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
+# Copyright (C) 2022 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 + Amd/SmmCpuFeaturesLib.c + +[Packages] + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + PcdLib + MemoryAllocationLib + DebugLib + +[FeaturePcd] + gUefiCpuPkgTokenSpaceGuid.PcdSmrrEnable ## CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdSmmFeatureControlEnable ## CONSUMES diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c b= /UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c new file mode 100644 index 000000000000..dc3fed0302d2 --- /dev/null +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c @@ -0,0 +1,357 @@ +/** @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) 2022 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; +} + +/** + This function is hook point called after the gEfiSmmReadyToLockProtocolG= uid + notification is completely processed. +**/ +VOID +EFIAPI +SmmCpuFeaturesCompleteSmmReadyToLock ( + VOID + ) +{ +} --=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 (#97032): https://edk2.groups.io/g/devel/message/97032 Mute This Topic: https://groups.io/mt/95492570/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 Mon Apr 29 02:42:04 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+97033+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 1670333039750318.93764827507675; Tue, 6 Dec 2022 05:23:59 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id UuhrYY1788612xXBY7xsWOhI; Tue, 06 Dec 2022 05:23:59 -0800 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.66]) by mx.groups.io with SMTP id smtpd.web11.47423.1670333038083689095 for ; Tue, 06 Dec 2022 05:23:58 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OSAImmxnAWdC/K247ZzOfZSNs2KW3Z2BRm2JVElDherAdIPE2Bon0KqQBXA+nRfma+tfD2H3pNYNJGiIgVTkiMxygmeOCDykiTfC3HxPewioJ6qvFJ47KoY5wABzXuQDrPDIEai6CcYqew42px369PcY6eRXNAu7MvX+bkVdrq6x9HiA5EUs2VZXYbrIPKbTaLfkITP0TZEDUwqTsLii5zlHQ/hJckWy0Cheec4RVbaZMRpMJKxjb2mgCkQApPJ0w+1vDmFodYLCWXq7TLedG5sHgThHaCvzQU/MVGLqkLhXiNGwQc1+J2rprmdH8VCfKp1VbhzlZEJXe6H7r+vu3w== 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=2fXeyuPxkxQfKobfEol0kGvQW/SiO1v+0MAHnXXEkiE=; b=EuXrkyLVqivRjfMUB1VaxhMZ+yPlFetqaqYmDhYFY7/x8bv3ip29Y1C3rpsqdU87NYUUJg9Uf3C713AKghCtCNgmhD0kBheFKXe+zxJVQNJ+5G6QYbt2hDmP5lvoIoXMt+ejJwmPu99X5+tDznunrGWNBLSNXMIFPsjnW4NvUv/1xReP/HorCmoKjqGi8r/bnMX2lM6RhtkkA/74tZyD1Z93e4Sp+QKZVPUooU33uPGU1TcgfnBb551gbZtv+5La0QkfaEANqmVhahYcAhpt1jpwdYLa+fe4IoNlvaC3VWdtnXji7T2PXHMTKi7sS003hVhAjJnt8EtudaerXdQ5Ug== 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 BN0PR02CA0003.namprd02.prod.outlook.com (2603:10b6:408:e4::8) by DM6PR12MB4353.namprd12.prod.outlook.com (2603:10b6:5:2a6::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Tue, 6 Dec 2022 13:23:55 +0000 X-Received: from BN8NAM11FT111.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e4:cafe::ae) by BN0PR02CA0003.outlook.office365.com (2603:10b6:408:e4::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Tue, 6 Dec 2022 13:23:55 +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+97033+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 BN8NAM11FT111.mail.protection.outlook.com (10.13.177.54) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.14 via Frontend Transport; Tue, 6 Dec 2022 13:23:54 +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; Tue, 6 Dec 2022 07:23:54 -0600 X-Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 6 Dec 2022 05:23:53 -0800 X-Received: from BLR-LAB-SFW01.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 6 Dec 2022 07:23:51 -0600 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 v1 4/5] UefiCpuPkg: Implements SmmCpuFeaturesLib for AMD Family Date: Tue, 6 Dec 2022 18:53:17 +0530 Message-ID: <79f976894da303d126fca5f6ace608391082d288.1670332633.git.abdattar@amd.com> In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT111:EE_|DM6PR12MB4353:EE_ X-MS-Office365-Filtering-Correlation-Id: 66d3c090-03de-41fe-d436-08dad78d1f9a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: dPFH3eR0JxrkEGwguScqmdsDDS7lyDjl9AyP6c8bD84mO7zJLaWbNFm0oS4W+ADnengdjKRoXdE1Ft7qVsFQT1JTZ5hKB5aAwr2sX7/kNkc+Y1m5QflrSeJAwTRH5/D6NZB8LaoBorlAJJ2+HwNqC4E6iPEqe+iusEM/JPSnIlG0TxGyqNv0GlxX4bfjtmHyUX+Um91bsBPtcBZ28iHIsQ47V971F2AAbI9Fp1SbGUstktpp2Ttszuk+jG2lOujhFsYsbPc0gQce1naYUlsnx1Sij5DOkJhB+U0lBnGip/WoX8H8LpUdnZPlniQ/QBkqkTC5AZlykuqcETsEWaxthkVuknxyvlXyYRRCjgDtGST2ZjOuqjHXEEWixOS5D0n0veK5urrhV5ycYnJ93uHNrOOEHGSNeeKH2uA3ruRGuC0eJl8W2eU4zlrHKd4jocyH6SMINSaaN60Z7xWXyyB7wLmLKFvGCEQXB3ufViadqz44oAH/ybLiLcZhzk8u0PsyD7G3CWlZfE/UPJ3q9jb8W6e1rVcLNpOZk+Tdxw4/Kr0cyIKCl/1YVR2zvV2muX+OqXRLMYnRmRWS5olrMV/Kp7m+3VEMKtC77/y7OIB0plRsAq50UgFp3lRo0f6tqhHPao2oc4R4Si8lsx1TVxFaNrv1j5aIcMtsTqTZ2JbcAsECvHXYwmrCY2knQxK2TxResd/wrQGkjm77yiD3J4inQWX9W+ic3Rq9nycdKCFnqxi0RTNjRHaigFHm4M9Jr14Mz8LUTNP29mOvPcIMCuYmIw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Dec 2022 13:23:54.6478 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 66d3c090-03de-41fe-d436-08dad78d1f9a 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: BN8NAM11FT111.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4353 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: j4XpFtIIW7AugawKZGmZEtY8x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1670333039; bh=mRDb01sV9XwJazpxvBm9MTrjDFhXL1MBGyebrWjDBWg=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=NLnAeeSezbiqipH60eXnoL1zOVWRQRptGijBlgWmiOfZEixm3lAg630t8fQCvaRO38y bZ3hYBLEY3uunJVrTJDkM5Poa7+ThME51zE6584cKJ47Urf5s5HMcHcfWGPFw2Sb5ckaL fcALNW2J0/9RERICUR0FOvq7iRFFhxzE3CA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1670333040341100001 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 --- .../AmdSmmCpuFeaturesLib.inf | 2 + .../SmmCpuFeaturesLib/Amd/SmramSaveState.h | 109 +++++ .../SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c | 97 ++++- .../SmmCpuFeaturesLib/Amd/SmramSaveState.c | 409 ++++++++++++++++++ 4 files changed, 612 insertions(+), 5 deletions(-) create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmramSaveState= .h create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmramSaveState= .c diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf = b/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf index 08ac0262022f..95eb31d16ead 100644 --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf @@ -21,6 +21,8 @@ [Sources] SmmCpuFeaturesLib.c SmmCpuFeaturesLibCommon.c Amd/SmmCpuFeaturesLib.c + Amd/SmramSaveState.c + Amd/SmramSaveState.h =20 [Packages] MdePkg/MdePkg.dec diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmramSaveState.h b/Ue= fiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmramSaveState.h new file mode 100644 index 000000000000..290ebdbc9227 --- /dev/null +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmramSaveState.h @@ -0,0 +1,109 @@ +/** @file +SMRAM Save State Map header file. + +Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.
+Copyright (C) 2022 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 +#include + +// EFER register LMA bit +#define LMA BIT10 + +// Machine Specific Registers (MSRs) +#define SMMADDR_ADDRESS 0xC0010112ul +#define SMMMASK_ADDRESS 0xC0010113ul +#define EFER_ADDRESS 0XC0000080ul + +// 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) + +// 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 } + +// 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 + +#define SMM_SAVE_STATE_REGISTER_SMMREVID_INDEX 1 +#define SMM_SAVE_STATE_REGISTER_MAX_INDEX 2 + +typedef struct { + UINT8 Width32; + UINT8 Width64; + UINT16 Offset32; + UINT16 Offset64Lo; + UINT16 Offset64Hi; + BOOLEAN Writeable; +} CPU_SMM_SAVE_STATE_LOOKUP_ENTRY; + +/** + 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 +InternalSmmCpuFeaturesReadSaveStateRegister ( + 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. +**/ +EFI_STATUS +EFIAPI +InternalSmmCpuFeaturesWriteSaveStateRegister ( + IN UINTN CpuIndex, + IN EFI_SMM_SAVE_STATE_REGISTER Register, + IN UINTN Width, + IN CONST VOID *Buffer + ); + +#endif diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c b= /UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c index dc3fed0302d2..10bed4116397 100644 --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c @@ -9,8 +9,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ =20 -#include -#include +#include "SmramSaveState.h" + +// The mode of the CPU at the time an SMI occurs +extern UINT8 mSmmSaveStateRegisterLma; =20 /** Read an SMM Save State register on the target processor. If this functi= on @@ -39,7 +41,7 @@ SmmCpuFeaturesReadSaveStateRegister ( OUT VOID *Buffer ) { - return EFI_SUCCESS; + return InternalSmmCpuFeaturesReadSaveStateRegister (CpuIndex, Register, = Width, Buffer); } =20 /** @@ -67,7 +69,7 @@ SmmCpuFeaturesWriteSaveStateRegister ( IN CONST VOID *Buffer ) { - return EFI_SUCCESS; + return InternalSmmCpuFeaturesWriteSaveStateRegister (CpuIndex, Register,= Width, Buffer); } =20 /** @@ -82,6 +84,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 +126,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 +214,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 /** diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmramSaveState.c b/Ue= fiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmramSaveState.c new file mode 100644 index 000000000000..c1e7e6d6c6d9 --- /dev/null +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmramSaveState.c @@ -0,0 +1,409 @@ +/** @file +Provides services to access SMRAM Save State Map + +Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.
+Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "SmramSaveState.h" + +// The mode of the CPU at the time an SMI occurs +extern UINT8 mSmmSaveStateRegisterLma; + +// Table used by GetRegisterIndex() to convert an EFI_SMM_SAVE_STATE_REGIS= TER +// value to an index into a table of type CPU_SMM_SAVE_STATE_LOOKUP_ENTRY +static CONST CPU_SMM_SAVE_STATE_REGISTER_RANGE mSmmCpuRegisterRanges[] = =3D { + SMM_REGISTER_RANGE (EFI_SMM_SAVE_STATE_REGISTER_GDTBASE, EFI_SMM_SAVE_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 +static CONST CPU_SMM_SAVE_STATE_LOOKUP_ENTRY mSmmCpuWidthOffset[] =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 information from the CPU save state. + + @param Register Specifies the CPU register to read form the save state. + + @retval 0 Register is not valid + @retval >0 Index into mSmmCpuWidthOffset[] associated with Register + +**/ +STATIC +UINTN +EFIAPI +GetRegisterIndex ( + IN EFI_SMM_SAVE_STATE_REGISTER Register + ) +{ + UINTN Index; + UINTN Offset; + + for (Index =3D 0, Offset =3D SMM_SAVE_STATE_REGISTER_MAX_INDEX; mSmmCpuR= egisterRanges[Index].Length !=3D 0; Index++) { + if ((Register >=3D mSmmCpuRegisterRanges[Index].Start) && (Register <= =3D mSmmCpuRegisterRanges[Index].End)) { + return Register - mSmmCpuRegisterRanges[Index].Start + Offset; + } + + Offset +=3D mSmmCpuRegisterRanges[Index].Length; + } + + return 0; +} + +/** + Read a CPU Save State register on the target processor. + + This function abstracts the differences that whether the CPU Save State = register is in the + IA32 CPU Save State Map or X64 CPU Save State Map. + + This function supports reading a CPU Save State register in SMBase reloc= ation handler. + + @param[in] CpuIndex Specifies the zero-based index of the CPU sav= e state. + @param[in] RegisterIndex Index into mSmmCpuWidthOffset[] look up table. + @param[in] Width The number of bytes to read from the CPU save= state. + @param[out] Buffer Upon return, this holds the CPU register valu= e read from the save state. + + @retval EFI_SUCCESS The register was read from Save State. + @retval EFI_NOT_FOUND The register is not defined for the Save S= tate of Processor. + @retval EFI_INVALID_PARAMTER This or Buffer is NULL. + +**/ +STATIC +EFI_STATUS +EFIAPI +ReadSaveStateRegisterByIndex ( + IN UINTN CpuIndex, + IN UINTN RegisterIndex, + IN UINTN Width, + OUT VOID *Buffer + ) +{ + AMD_SMRAM_SAVE_STATE_MAP *CpuSaveState; + + // UINT32 SmmRevId; + + if (RegisterIndex =3D=3D 0) { + return EFI_NOT_FOUND; + } + + CpuSaveState =3D gSmst->CpuSaveState[CpuIndex]; + // SmmRevId =3D CpuSaveState->x86.SMMRevId; + + if (mSmmSaveStateRegisterLma =3D=3D EFI_SMM_SAVE_STATE_REGISTER_LMA_32BI= T) { + // + // If 32-bit mode width is zero, then the specified register can not b= e accessed + // + if (mSmmCpuWidthOffset[RegisterIndex].Width32 =3D=3D 0) { + return EFI_NOT_FOUND; + } + + // + // If Width is bigger than the 32-bit mode width, then the specified r= egister can not be accessed + // + if (Width > mSmmCpuWidthOffset[RegisterIndex].Width32) { + return EFI_INVALID_PARAMETER; + } + + // + // Write return buffer + // + ASSERT (CpuSaveState !=3D NULL); + CopyMem (Buffer, (UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIn= dex].Offset32, Width); + } else { + // + // If 64-bit mode width is zero, then the specified register can not b= e accessed + // + if (mSmmCpuWidthOffset[RegisterIndex].Width64 =3D=3D 0) { + return EFI_NOT_FOUND; + } + + // + // If Width is bigger than the 64-bit mode width, then the specified r= egister can not be accessed + // + if (Width > mSmmCpuWidthOffset[RegisterIndex].Width64) { + return EFI_INVALID_PARAMETER; + } + + // + // Write lower 32-bits of return buffer + // + CopyMem (Buffer, (UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIn= dex].Offset64Lo, MIN (4, Width)); + if (Width >=3D 4) { + // + // Write upper 32-bits of return buffer + // + CopyMem ((UINT8 *)Buffer + 4, (UINT8 *)CpuSaveState + mSmmCpuWidthOf= fset[RegisterIndex].Offset64Hi, Width - 4); + } + } + + return EFI_SUCCESS; +} + +/** + Read an SMM Save State register on the target processor. If this functi= on + returns EFI_UNSUPPORTED, then the caller is responsible for reading the + SMM Save Sate register. + + @param[in] CpuIndex The index of the CPU to read the SMM Save State. = The + value must be between 0 and the NumberOfCpus field= in + the System Management System Table (SMST). + @param[in] Register The SMM Save State register to read. + @param[in] Width The number of bytes to read from the CPU save stat= e. + @param[out] Buffer Upon return, this holds the CPU register value read + from the save state. + + @retval EFI_SUCCESS The register was read from Save State. + @retval EFI_INVALID_PARAMTER Buffer is NULL. + @retval EFI_UNSUPPORTED This function does not support reading Reg= ister. + +**/ +EFI_STATUS +EFIAPI +InternalSmmCpuFeaturesReadSaveStateRegister ( + 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 mSmmSaveStateRegisterLma; + + return EFI_SUCCESS; + } + + // Check for special EFI_SMM_SAVE_STATE_REGISTER_IO + + if (Register =3D=3D EFI_SMM_SAVE_STATE_REGISTER_IO) { + // + // Get SMM Revision ID + // + ReadSaveStateRegisterByIndex (CpuIndex, SMM_SAVE_STATE_REGISTER_SMMREV= ID_INDEX, sizeof (SmmRevId), &SmmRevId); + + // + // See if the CPU supports the IOMisc register in the save state + // + if (SmmRevId < 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)) { + SmmCpuFeaturesReadSaveStateRegister (CpuIndex, EFI_SMM_SAVE_STATE_RE= GISTER_RAX, DataWidth, &IoInfo->IoData); + } + + return EFI_SUCCESS; + } + + // Convert Register to a register lookup table index + return ReadSaveStateRegisterByIndex (CpuIndex, GetRegisterIndex (Registe= r), Width, Buffer); +} + +/** + Writes an SMM Save State register on the target processor. If this func= tion + returns EFI_UNSUPPORTED, then the caller is responsible for writing the + SMM Save Sate register. + + @param[in] CpuIndex The index of the CPU to write the SMM Save State. = The + value must be between 0 and the NumberOfCpus field = in + the System Management System Table (SMST). + @param[in] Register The SMM Save State register to write. + @param[in] Width The number of bytes to write to the CPU save state. + @param[in] Buffer Upon entry, this holds the new CPU register value. + + @retval EFI_SUCCESS The register was written to Save State. + @retval EFI_INVALID_PARAMTER Buffer is NULL. + @retval EFI_UNSUPPORTED This function does not support writing Reg= ister. +**/ +EFI_STATUS +EFIAPI +InternalSmmCpuFeaturesWriteSaveStateRegister ( + 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 GetRegisterIndex (Register); + if (RegisterIndex =3D=3D 0) { + return EFI_NOT_FOUND; + } + + CpuSaveState =3D gSmst->CpuSaveState[CpuIndex]; + + // + // Do not write non-writable SaveState, because it will cause exception. + // + if (!mSmmCpuWidthOffset[RegisterIndex].Writeable) { + return EFI_UNSUPPORTED; + } + + // + // Check CPU mode + // + if (mSmmSaveStateRegisterLma =3D=3D EFI_SMM_SAVE_STATE_REGISTER_LMA_32BI= T) { + // + // If 32-bit mode width is zero, then the specified register can not b= e accessed + // + if (mSmmCpuWidthOffset[RegisterIndex].Width32 =3D=3D 0) { + return EFI_NOT_FOUND; + } + + // + // If Width is bigger than the 32-bit mode width, then the specified r= egister can not be accessed + // + if (Width > mSmmCpuWidthOffset[RegisterIndex].Width32) { + return EFI_INVALID_PARAMETER; + } + + // + // Write SMM State register + // + ASSERT (CpuSaveState !=3D NULL); + CopyMem ((UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Off= set32, Buffer, Width); + } else { + // + // If 64-bit mode width is zero, then the specified register can not b= e accessed + // + if (mSmmCpuWidthOffset[RegisterIndex].Width64 =3D=3D 0) { + return EFI_NOT_FOUND; + } + + // + // If Width is bigger than the 64-bit mode width, then the specified r= egister can not be accessed + // + if (Width > mSmmCpuWidthOffset[RegisterIndex].Width64) { + return EFI_INVALID_PARAMETER; + } + + // + // Write lower 32-bits of SMM State register + // + CopyMem ((UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Off= set64Lo, Buffer, MIN (4, Width)); + if (Width >=3D 4) { + // + // Write upper 32-bits of SMM State register + // + CopyMem ((UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].O= ffset64Hi, (UINT8 *)Buffer + 4, 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 (#97033): https://edk2.groups.io/g/devel/message/97033 Mute This Topic: https://groups.io/mt/95492571/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 Mon Apr 29 02:42:04 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+97034+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 1670333040153502.2103547841417; Tue, 6 Dec 2022 05:24:00 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id idVEYY1788612xVTSC2DCvyX; Tue, 06 Dec 2022 05:23:59 -0800 X-Received: from NAM04-MW2-obe.outbound.protection.outlook.com (NAM04-MW2-obe.outbound.protection.outlook.com [40.107.101.45]) by mx.groups.io with SMTP id smtpd.web11.47425.1670333039306875045 for ; Tue, 06 Dec 2022 05:23:59 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Mnm4BCG/jc9NiKpIXFoEBmqt9MFVfHbVEnFrloHjzFQEF9r3Pjk+snOIsScxOjutQpKvPhtGvT6Vh24hv9iHQvFKm/iiXECUb36fNSrImDlKazAbDBxCXmysbTFHHvv60qwENK5YdI+MTFGFYSMMXI/FVRAFmMtCktAUunLhyV7VWCiAN7zK/80RACa0OdOKvFCKgv92ziVbaaMXZs/C+4GNHtQRKDn//253dPQYn1zt1/l11hnB3S6Yo17U6rvQBKCr7FjCyfbSqyTxGV5WbUNwNnA5j5EwscQt6zSL9DfbdmalPrxpoVLuqKoI4CCv4d95e4+8dCw+BQuFFf//+Q== 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=XB6bBUeU7heSAIg9B9kTpU1AJUdEROlGmg32FVQx+UY=; b=kAeGs6QPv734Hk/CPshmjthBWtgcuB5CoWJOMCDbYpLoJLBwUE1Z+wD1NlKPeOBv6G84DjFwOwY241AjG+zTEvlJju+2P//nK7a+9ixP3yBh8I/4EButXIHdefKAWXCfpAzWHtLt13EVxpUIw13tKoR8SAsxEc4gObDk36ySwvHl951xaeKDeb7tyStyDOKX2MDIDVr7roDkEadC7JGUsOBJVT3SJF8mIlMeeyKC67f79DX0OjDMLzQQrDko0izAU6Heo6ZDDHs/USMEHGZt4XTUaOG5o2+i1qcgjHFb5bufgykHqfkWhsIcjdKWeFd5XIeLEx7MX3ZJg+4dgB+dWA== 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 BN9PR03CA0665.namprd03.prod.outlook.com (2603:10b6:408:10e::10) by DM4PR12MB5889.namprd12.prod.outlook.com (2603:10b6:8:65::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Tue, 6 Dec 2022 13:23:57 +0000 X-Received: from BN8NAM11FT004.eop-nam11.prod.protection.outlook.com (2603:10b6:408:10e:cafe::5b) by BN9PR03CA0665.outlook.office365.com (2603:10b6:408:10e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Tue, 6 Dec 2022 13:23: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+97034+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 BN8NAM11FT004.mail.protection.outlook.com (10.13.176.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.14 via Frontend Transport; Tue, 6 Dec 2022 13:23:56 +0000 X-Received: from SATLEXMB03.amd.com (10.181.40.144) 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; Tue, 6 Dec 2022 07:23:56 -0600 X-Received: from BLR-LAB-SFW01.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 6 Dec 2022 07:23:54 -0600 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 v1 5/5] UefiCpuPkg/AmdSmmCpuFeaturesLib: Handles S3 save state Date: Tue, 6 Dec 2022 18:53:18 +0530 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT004:EE_|DM4PR12MB5889:EE_ X-MS-Office365-Filtering-Correlation-Id: 528d72a2-a71f-4e52-e45e-08dad78d20e8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: og8+93OKPAnXxMYUlWp9nrBcMg9252fZPFffyWGjZKKV0DoHNesBV9GNpo9fOy0sanV9+IvzPaw3nbSwH3G0xJzFbiDTvnoDGfLiltDh7upskCShzXbCuhVJov1fqTt7hjG1B2bRa5PgwVmJf6WI6DsgrB9CVnxpBOlMWH3UaU79EfKfGm36mfDDtb1TL5LSnx+2s8zKqUrCpGJe5F1EFnJHXxYPScVn8HlOzE/EMct+WrFLMXTsYNwbI55KDklj0NtgI6ccI3wyVcrxQSL0uYBb3yornWdbJoFBexxMRgC5Wht6WBn+OncYoSWRmE+GeybBYB1ADZ7gAcgmXIPBOXsyG0lIoyrl2f4wejBpA4q/2leR57hbokQcg8CQuAakWCGImOTGEnoRjl+REjdqGLN7uJmRtHsA4FR8X+dvWoSFv43uFGJbAhEXc1M3Gb34Ckc8YNsDfFfgz5+s07COm46ThufWKbwHvRRXXE8oB4fpJSgIMiFJ7SMmS091UN3LJ7Pp/cDLYRW99g6bZ80VBTJIJGZSzUv/QV0Q20lfOl1l74PqRdXImSMyXjeCsdSHwpRK/LEYr0sL6s5qJArM6LcG43ca+NyJ4GeyeJH7+wNNGiBFyc3iqN1xZSfsVNqkxXOF8hmCmzUR1PPBi+8Btrp6DPyXAdGT1V1+qdfTSlYxaKxEzwczTUHBTS+O0CCxcRA6+iYApkFNJKrzex53syjD5+5yfsGtZoOLMa0bOz/XWmeRTzkquUNWGYEsAaC/ZBXUjinyuWN97Na7q5LnkmOYlkQAg+7vMpmErcYJkyY= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Dec 2022 13:23:56.8528 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 528d72a2-a71f-4e52-e45e-08dad78d20e8 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: BN8NAM11FT004.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5889 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: u4wl8r2hrYbrLXo18KaDR4FHx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1670333039; bh=1toEspOrcZYu3BePn4xbLuUVP1JCaw1Q/6bhuGkBN58=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=KaYGPEx7kxksheoJfIrUsXdvSL6YlIVMRhIuNIMdCof1O/hWUrYXVKKEs/qmk0DmRXN WVNrq+DDXzDI1y8mMubBv0kigEdvJxuwKfAV1qaEOlqU+a+Nk/5hW8EqBcNgLrG++CqIk Exi/BLHoMt8h5zjft0gI87bc1xvz6mf7Tbc= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1670333042172100005 Content-Type: text/plain; charset="utf-8" From: Abdul Lateef Attar BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4182 Handles S3 save state restore condition. Implements SmmCpuFeaturesCompleteSmmReadyToLock() to sync all processor and update S3 resume entry point. Cc: Paul Grimes Cc: Garrett Kirkendall Cc: Abner Chang Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Signed-off-by: Abdul Lateef Attar --- .../AmdSmmCpuFeaturesLib.inf | 1 + .../SmmCpuFeaturesLib/Amd/SmramSaveState.h | 19 +++++++++++ .../SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c | 32 +++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf = b/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf index 95eb31d16ead..7fd559e91ad8 100644 --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf @@ -27,6 +27,7 @@ [Sources] [Packages] MdePkg/MdePkg.dec UefiCpuPkg/UefiCpuPkg.dec + MdeModulePkg/MdeModulePkg.dec =20 [LibraryClasses] BaseLib diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmramSaveState.h b/Ue= fiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmramSaveState.h index 290ebdbc9227..474a5dbd9765 100644 --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmramSaveState.h +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmramSaveState.h @@ -17,6 +17,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include =20 // EFER register LMA bit #define LMA BIT10 @@ -106,4 +107,22 @@ InternalSmmCpuFeaturesWriteSaveStateRegister ( IN CONST VOID *Buffer ); =20 +/** + Initialize MP synchronization data. +**/ +VOID +EFIAPI +InitializeMpSyncData ( + VOID + ); + +/** + Perform SMM MP sync Semaphores re-initialization in the S3 boot path. +**/ +VOID +EFIAPI +SmmS3MpSemaphoreInit ( + VOID + ); + #endif diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c b= /UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c index 10bed4116397..b855573d9401 100644 --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c @@ -14,6 +14,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // The mode of the CPU at the time an SMI occurs extern UINT8 mSmmSaveStateRegisterLma; =20 +// SMM S3 resume state Ptr +extern SMM_S3_RESUME_STATE *mSmmS3ResumeState; + /** 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 @@ -441,4 +444,33 @@ SmmCpuFeaturesCompleteSmmReadyToLock ( VOID ) { + if (mSmmS3ResumeState !=3D NULL ) { + mSmmS3ResumeState->SmmS3ResumeEntryPoint =3D (EFI_PHYSICAL_ADDRESS)(UI= NTN)SmmS3MpSemaphoreInit; + } +} + +/** + Perform SMM MP sync Semaphores re-initialization in the S3 boot path. +**/ +VOID +EFIAPI +SmmS3MpSemaphoreInit ( + VOID + ) +{ + InitializeMpSyncData (); + + DEBUG ((DEBUG_INFO, "SMM S3 Return CS =3D %x\n", mSmmS3Re= sumeState->ReturnCs)); + DEBUG ((DEBUG_INFO, "SMM S3 Return Entry Point =3D %x\n", mSmmS3Re= sumeState->ReturnEntryPoint)); + DEBUG ((DEBUG_INFO, "SMM S3 Return Context1 =3D %x\n", mSmmS3Re= sumeState->ReturnContext1)); + DEBUG ((DEBUG_INFO, "SMM S3 Return Context2 =3D %x\n", mSmmS3Re= sumeState->ReturnContext2)); + DEBUG ((DEBUG_INFO, "SMM S3 Return Stack Pointer =3D %x\n", mSmmS3Re= sumeState->ReturnStackPointer)); + + AsmDisablePaging64 ( + mSmmS3ResumeState->ReturnCs, + (UINT32)mSmmS3ResumeState->ReturnEntryPoint, + (UINT32)mSmmS3ResumeState->ReturnContext1, + (UINT32)mSmmS3ResumeState->ReturnContext2, + (UINT32)mSmmS3ResumeState->ReturnStackPointer + ); } --=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 (#97034): https://edk2.groups.io/g/devel/message/97034 Mute This Topic: https://groups.io/mt/95492572/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-