From nobody Fri Dec 19 20:35:57 2025 Delivered-To: importer@patchew.org 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+81122+1787277+3901457@groups.io; helo=mail02.groups.io; 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+81122+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1632611152; cv=none; d=zohomail.com; s=zohoarc; b=jHXtihLWfp7RruoLYUkxJyTQcHleH+MYc0h7jzuQUfA3K+aH/H9CnLsiS8ZKV4FKEzUCxdEB9fRJqToI+h+nkMNsORWB6Di8ptNtEkNnH1h4MW3UnMFWm4FtbAIlRRsY5orCbl4ighqj7rLgOW1EFLnlBT/IIpIv/+02Ygtmr7E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632611152; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=J1YM5iK+Q5nkPIyMDBnZtTcj+AZex29GtGCjhP406uY=; b=ew6VesU185iGeSHmMKXZv7JC8FYyfmj4xkrfsBnxUG2fKCW+VVAnYYWFieB4n5bKvXpkDC0WX1JDvmlTGV78r0iQk6H1UCJoEqiiIvUmc+Lu/i0c7BcvAeYSOgIQyPQo2THySCS8RcFsJU6Mp/UHBzzWOJBcQc7ByZXlG2GwIis= ARC-Authentication-Results: i=1; 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+81122+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1632611152303563.4779284224633; Sat, 25 Sep 2021 16:05:52 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id dRpXYY1788612xu06JOjvvTa; Sat, 25 Sep 2021 16:05:52 -0700 X-Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web09.12624.1632611151004339490 for ; Sat, 25 Sep 2021 16:05:51 -0700 X-IronPort-AV: E=McAfee;i="6200,9189,10118"; a="285311472" X-IronPort-AV: E=Sophos;i="5.85,322,1624345200"; d="scan'208";a="285311472" X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2021 16:05:50 -0700 X-IronPort-AV: E=Sophos;i="5.85,322,1624345200"; d="scan'208";a="586418276" X-Received: from gdong1-mobl1.amr.corp.intel.com ([10.255.67.241]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2021 16:05:49 -0700 From: "Guo Dong" To: devel@edk2.groups.io Cc: ray.ni@intel.com, maurice.ma@intel.com, benjamin.you@intel.com, Guo Dong Subject: [edk2-devel] [`edk2-devel][PATCH 2/8] UefiPayloadPkg: Add a common SMM control Runtime DXE module Date: Sat, 25 Sep 2021 16:05:24 -0700 Message-Id: <20210925230530.861-3-guo.dong@intel.com> In-Reply-To: <20210925230530.861-1-guo.dong@intel.com> References: <20210925230530.861-1-guo.dong@intel.com> MIME-Version: 1.0 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,guo.dong@intel.com X-Gm-Message-State: dcSM5qFf2etbjQpunxTb764Ax1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1632611152; bh=hpXipV02JQH47EYf5siE1EdN4wtN9vZis4O7VcrFYBs=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=gUd7bYtGgRuQkMWepk05/bOMTgQ8PHNPDbZfDtZAZ7GpJS7NcJdF/qjpcLbFqw4vKXy nxGK7I1KJ/poogho7RZE3Ce3b63mRMWLF56ihrLZNLD/EvBRsqbhtJs/FxxaJ4/771/xb e6tK7EezyJ2Dqp3RoGFBCOxn4i5amXFKdKE= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1632612055065100001 Content-Type: text/plain; charset="utf-8" From: Guo Dong This module consumes SMM Registers HOB (SMI_GBL_EN and SMI_APM_EN) to install SMM control 2 protocol gEfiSmmControl2ProtocolGuid. The protocol activate() would set SMI_GBL_EN and SMI_APM_EN and trigger SMI by writing to IO port 0xB3 and 0xB2. Signed-off-by: Guo Dong --- .../Include/Guid/SmmRegisterInfoGuid.h | 48 ++++ .../SmmControlRuntimeDxe.c | 252 ++++++++++++++++++ .../SmmControlRuntimeDxe.inf | 50 ++++ UefiPayloadPkg/UefiPayloadPkg.dec | 2 + 4 files changed, 352 insertions(+) create mode 100644 UefiPayloadPkg/Include/Guid/SmmRegisterInfoGuid.h create mode 100644 UefiPayloadPkg/SmmControlRuntimeDxe/SmmControlRuntimeDx= e.c create mode 100644 UefiPayloadPkg/SmmControlRuntimeDxe/SmmControlRuntimeDx= e.inf diff --git a/UefiPayloadPkg/Include/Guid/SmmRegisterInfoGuid.h b/UefiPayloa= dPkg/Include/Guid/SmmRegisterInfoGuid.h new file mode 100644 index 0000000000..bf908b24f2 --- /dev/null +++ b/UefiPayloadPkg/Include/Guid/SmmRegisterInfoGuid.h @@ -0,0 +1,48 @@ +/** @file + This file defines the SMM info hob structure. + + Copyright (c) 2021, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef __PAYLOAD_SMM_REGISTER_INFO_GUID_H__ +#define __PAYLOAD_SMM_REGISTER_INFO_GUID_H__ + +#include + +/// +/// SMM Information GUID +/// +extern EFI_GUID gSmmRegisterInfoGuid; + +/// +/// Reuse ACPI definition +/// AddressSpaceId(0xC0=EF=BF=BD0xFF) is defined by OEM for MSR and other = spaces +/// +typedef EFI_ACPI_3_0_GENERIC_ADDRESS_STRUCTURE PLD_GENERIC_ADDRESS; + +#define REGISTER_ID_SMI_GBL_EN 1 +#define REGISTER_ID_SMI_GBL_EN_LOCK 2 +#define REGISTER_ID_SMI_EOS 3 +#define REGISTER_ID_SMI_APM_EN 4 +#define REGISTER_ID_SMI_APM_STS 5 + +#pragma pack(1) +typedef struct { + UINT64 Id; + UINT64 Value; + PLD_GENERIC_ADDRESS Address; +} PLD_GENERIC_REGISTER; + +typedef struct { + UINT16 Revision; + UINT16 Reserved; + UINT32 Count; + PLD_GENERIC_REGISTER Registers[0]; +} PLD_SMM_REGISTERS; + + +#pragma pack() + +#endif diff --git a/UefiPayloadPkg/SmmControlRuntimeDxe/SmmControlRuntimeDxe.c b/U= efiPayloadPkg/SmmControlRuntimeDxe/SmmControlRuntimeDxe.c new file mode 100644 index 0000000000..1558b17319 --- /dev/null +++ b/UefiPayloadPkg/SmmControlRuntimeDxe/SmmControlRuntimeDxe.c @@ -0,0 +1,252 @@ +/** @file + This module produces the SMM Control2 Protocol + + Copyright (c) 2021, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define SMM_DATA_PORT 0xB3 +#define SMM_CONTROL_PORT 0xB2 + +typedef struct { + UINT8 GblBitOffset; + UINT8 ApmBitOffset; + UINT32 Address; +} SMM_CONTROL2_REG; + +SMM_CONTROL2_REG mSmiCtrlReg; + +/** + Generates an SMI using the parameters passed in. + + @param This A pointer to an instance of + EFI_SMM_CONTROL_PROTOCOL + @param ArgumentBuffer The argument buffer + @param ArgumentBufferSize The size of the argument buffer + @param Periodic TRUE to indicate a periodical SMI + @param ActivationInterval Interval of the periodical SMI + + @retval EFI_INVALID_PARAMETER Periodic is TRUE or ArgumentBufferSize > 1 + @retval EFI_SUCCESS SMI generated + +**/ +EFI_STATUS +EFIAPI +Activate ( + IN CONST EFI_SMM_CONTROL2_PROTOCOL *This, + IN OUT UINT8 *CommandPort OPTIONAL, + IN OUT UINT8 *DataPort OPTIONAL, + IN BOOLEAN Periodic OPTIONAL, + IN EFI_SMM_PERIOD ActivationInterval OPTIONAL + ) +{ + UINT32 SmiEn; + UINT32 SmiEnableBits; + + if (Periodic) { + return EFI_INVALID_PARAMETER; + } + + SmiEn =3D IoRead32 (mSmiCtrlReg.Address); + SmiEnableBits =3D (1 << mSmiCtrlReg.GblBitOffset) | (1 << mSmiCtrlReg.Ap= mBitOffset); + if ((SmiEn & SmiEnableBits) !=3D SmiEnableBits) { + // + // Set the "global SMI enable" bit and APM bit + // + IoWrite32 (mSmiCtrlReg.Address, SmiEn | SmiEnableBits); + } + + IoWrite8 (SMM_DATA_PORT, DataPort =3D=3D NULL ? 0 : *DataPort); + IoWrite8 (SMM_CONTROL_PORT, CommandPort =3D=3D NULL ? 0 : *CommandPort); + return EFI_SUCCESS; +} + +/** + Clears an SMI. + + @param This Pointer to an instance of EFI_SMM_CONTROL_PROTOCOL + @param Periodic TRUE to indicate a periodical SMI + + @return Return value from SmmClear () + +**/ +EFI_STATUS +EFIAPI +Deactivate ( + IN CONST EFI_SMM_CONTROL2_PROTOCOL *This, + IN BOOLEAN Periodic + ) +{ + if (Periodic) { + return EFI_INVALID_PARAMETER; + } + + // + // Temporarily do nothing here + // + return EFI_SUCCESS; +} + +/// +/// SMM COntrol2 Protocol instance +/// +EFI_SMM_CONTROL2_PROTOCOL mSmmControl2 =3D { + Activate, + Deactivate, + 0 +}; + +/** + Get specified SMI register based on given register ID + + @param[in] SmmRegister SMI related register array from bootloader + @param[in] Id The register ID to get. + + @retval NULL The register is not found or the format is not = expected. + @return smi register + +**/ +PLD_GENERIC_REGISTER * +GetSmmCtrlRegById ( + IN PLD_SMM_REGISTERS *SmmRegister, + IN UINT32 Id + ) +{ + UINT32 Index; + PLD_GENERIC_REGISTER *PldReg; + + PldReg =3D NULL; + for (Index =3D 0; Index < SmmRegister->Count; Index++) { + if (SmmRegister->Registers[Index].Id =3D=3D Id) { + PldReg =3D &SmmRegister->Registers[Index]; + break; + } + } + + if (PldReg =3D=3D NULL) { + DEBUG ((DEBUG_INFO, "Register %d not found.\n", Id)); + return NULL; + } + + // + // Checking the register if it is expected. + // + if ((PldReg->Address.AccessSize !=3D EFI_ACPI_3_0_DWORD) || + (PldReg->Address.Address =3D=3D 0) || + (PldReg->Address.RegisterBitWidth !=3D 1) || + (PldReg->Address.AddressSpaceId !=3D EFI_ACPI_3_0_SYSTEM_IO) || + (PldReg->Value !=3D 1)) { + DEBUG ((DEBUG_INFO, "Unexpected SMM register.\n")); + DEBUG ((DEBUG_INFO, "AddressSpaceId=3D 0x%x\n", PldReg->Address.Addres= sSpaceId)); + DEBUG ((DEBUG_INFO, "RegBitWidth =3D 0x%x\n", PldReg->Address.Regist= erBitWidth)); + DEBUG ((DEBUG_INFO, "RegBitOffset =3D 0x%x\n", PldReg->Address.Regist= erBitOffset)); + DEBUG ((DEBUG_INFO, "AccessSize =3D 0x%x\n", PldReg->Address.Access= Size)); + DEBUG ((DEBUG_INFO, "Address =3D 0x%lx\n",PldReg->Address.Addres= s )); + return NULL; + } + return PldReg; +} + + +/** + Fixup data pointers so that the services can be called in virtual mode. + + @param[in] Event The event registered. + @param[in] Context Event context. + +**/ +VOID +EFIAPI +SmmControlVirtualAddressChangeEvent ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EfiConvertPointer (0x0, (VOID **) &(mSmmControl2.Trigger)); + EfiConvertPointer (0x0, (VOID **) &(mSmmControl2.Clear)); +} + + +/** + This function installs EFI_SMM_CONTROL2_PROTOCOL. + + @param ImageHandle Handle for the image of this driver + @param SystemTable Pointer to the EFI System Table + + @retval EFI_UNSUPPORTED There's no Intel ICH on this platform + @return The status returned from InstallProtocolInterface(). + +**/ +EFI_STATUS +EFIAPI +SmmControlEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_HOB_GUID_TYPE *GuidHob; + PLD_SMM_REGISTERS *SmmRegister; + PLD_GENERIC_REGISTER *SmiGblEnReg; + PLD_GENERIC_REGISTER *SmiApmEnReg; + EFI_EVENT Event; + + GuidHob =3D GetFirstGuidHob (&gSmmRegisterInfoGuid); + if (GuidHob =3D=3D NULL) { + return EFI_UNSUPPORTED; + } + + SmmRegister =3D (PLD_SMM_REGISTERS *) (GET_GUID_HOB_DATA(GuidHob)); + SmiGblEnReg =3D GetSmmCtrlRegById (SmmRegister, REGISTER_ID_SMI_GBL_EN); + if (SmiGblEnReg =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "SMI global enable reg not found.\n")); + return EFI_NOT_FOUND; + } + mSmiCtrlReg.Address =3D (UINT32)SmiGblEnReg->Address.Address; + mSmiCtrlReg.GblBitOffset =3D SmiGblEnReg->Address.RegisterBitOffset; + + SmiApmEnReg =3D GetSmmCtrlRegById (SmmRegister, REGISTER_ID_SMI_APM_EN); + if (SmiApmEnReg =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "SMI APM enable reg not found.\n")); + return EFI_NOT_FOUND; + } + + if (SmiApmEnReg->Address.Address !=3D mSmiCtrlReg.Address) { + DEBUG ((DEBUG_ERROR, "SMI APM EN and SMI GBL EN are expected to have s= ame register base\n")); + DEBUG ((DEBUG_ERROR, "APM:0x%x, GBL:0x%x\n", SmiApmEnReg->Address.Addr= ess, mSmiCtrlReg.Address)); + return EFI_UNSUPPORTED; + } + mSmiCtrlReg.ApmBitOffset =3D SmiApmEnReg->Address.RegisterBitOffset; + + // + // Install our protocol interfaces on the device's handle + // + Status =3D gBS->InstallMultipleProtocolInterfaces ( + &ImageHandle, + &gEfiSmmControl2ProtocolGuid, + &mSmmControl2, + NULL + ); + ASSERT_EFI_ERROR (Status); + + Status =3D gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_NOTIFY, + SmmControlVirtualAddressChangeEvent, + NULL, + &gEfiEventVirtualAddressChangeGuid, + &Event + ); + return Status; +} diff --git a/UefiPayloadPkg/SmmControlRuntimeDxe/SmmControlRuntimeDxe.inf b= /UefiPayloadPkg/SmmControlRuntimeDxe/SmmControlRuntimeDxe.inf new file mode 100644 index 0000000000..f0c2a4586b --- /dev/null +++ b/UefiPayloadPkg/SmmControlRuntimeDxe/SmmControlRuntimeDxe.inf @@ -0,0 +1,50 @@ +## @file +# SMM Control runtime DXE Module +# +# Provides the ability to generate a software SMI. +# +# Copyright (c) 2021, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D SmmControlRuntimeDxe + FILE_GUID =3D C3099578-F815-4a96-84A3-FC593760181D + MODULE_TYPE =3D DXE_RUNTIME_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D SmmControlEntryPoint + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[Sources] + SmmControlRuntimeDxe.c + +[Packages] + MdePkg/MdePkg.dec + UefiPayloadPkg/UefiPayloadPkg.dec + +[LibraryClasses] + UefiDriverEntryPoint + DebugLib + UefiBootServicesTableLib + UefiRuntimeLib + PcdLib + IoLib + HobLib + +[Guids] + gSmmRegisterInfoGuid + gEfiEventVirtualAddressChangeGuid + +[Protocols] + gEfiSmmControl2ProtocolGuid ## PRODUCES + +[Depex] + TRUE diff --git a/UefiPayloadPkg/UefiPayloadPkg.dec b/UefiPayloadPkg/UefiPayload= Pkg.dec index 8f0a7e3f95..1705f28ec4 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dec +++ b/UefiPayloadPkg/UefiPayloadPkg.dec @@ -37,6 +37,8 @@ gUefiSerialPortInfoGuid =3D { 0x6c6872fe, 0x56a9, 0x4403, { 0xbb, 0x98,= 0x95, 0x8d, 0x62, 0xde, 0x87, 0xf1 } } gLoaderMemoryMapInfoGuid =3D { 0xa1ff7424, 0x7a1a, 0x478e, { 0xa9, 0xe4,= 0x92, 0xf3, 0x57, 0xd1, 0x28, 0x32 } } =20 + gSmmRegisterInfoGuid =3D { 0xaa9bd7a7, 0xcafb, 0x4499, { 0xa4, 0xa9,= 0xb, 0x34, 0x6b, 0x40, 0xa6, 0x22 } } + [Ppis] gEfiPayLoadHobBasePpiGuid =3D { 0xdbe23aa1, 0xa342, 0x4b97, {0x85, 0xb6,= 0xb2, 0x26, 0xf1, 0x61, 0x73, 0x89} } =20 --=20 2.32.0.windows.2 -=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 (#81122): https://edk2.groups.io/g/devel/message/81122 Mute This Topic: https://groups.io/mt/85870024/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-