From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web08.12716.1632611149834054906 for ; Sat, 25 Sep 2021 16:05:51 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.31, mailfrom: guo.dong@intel.com) X-IronPort-AV: E=McAfee;i="6200,9189,10118"; a="285311473" X-IronPort-AV: E=Sophos;i="5.85,322,1624345200"; d="scan'208";a="285311473" 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="586418279" 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:50 -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][PATCH 3/8] UefiPayloadPkg: Add bootloader SMM support module Date: Sat, 25 Sep 2021 16:05:25 -0700 Message-Id: <20210925230530.861-4-guo.dong@intel.com> X-Mailer: git-send-email 2.32.0.windows.2 In-Reply-To: <20210925230530.861-1-guo.dong@intel.com> References: <20210925230530.861-1-guo.dong@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Guo Dong This module is only used for SMM S3 support for the bootloader that doesn't support SMM. The payload would save SMM rebase info to SMM communication area in normal boot and expect the bootloader in S3 path to rebase the SMM and trigger SMI by writing 0xB2 port with the given value from SMM communication area. The payload SMM handler would get chance to restore some registers in S3 path. Signed-off-by: Guo Dong --- UefiPayloadPkg/BlSupportSmm/BlSupportSmm.c | 409 ++++++++++++++++++ UefiPayloadPkg/BlSupportSmm/BlSupportSmm.h | 41 ++ UefiPayloadPkg/BlSupportSmm/BlSupportSmm.inf | 49 +++ .../Include/Guid/SmmS3CommunicationInfoGuid.h | 54 +++ UefiPayloadPkg/UefiPayloadPkg.dec | 1 + 5 files changed, 554 insertions(+) create mode 100644 UefiPayloadPkg/BlSupportSmm/BlSupportSmm.c create mode 100644 UefiPayloadPkg/BlSupportSmm/BlSupportSmm.h create mode 100644 UefiPayloadPkg/BlSupportSmm/BlSupportSmm.inf create mode 100644 UefiPayloadPkg/Include/Guid/SmmS3CommunicationInfoGuid.h diff --git a/UefiPayloadPkg/BlSupportSmm/BlSupportSmm.c b/UefiPayloadPkg/Bl= SupportSmm/BlSupportSmm.c new file mode 100644 index 0000000000..f84494d905 --- /dev/null +++ b/UefiPayloadPkg/BlSupportSmm/BlSupportSmm.c @@ -0,0 +1,409 @@ +/** @file=0D + This driver is used for SMM S3 support for the bootloader that=0D + doesn't support SMM.=0D + The payload would save SMM rebase info to SMM communication area.=0D + The bootloader is expected to rebase the SMM and trigger SMI by=0D + writting 0xB2 port with given value from SMM communication area.=0D + The paylaod SMM handler got chance to restore regs in S3 path.=0D +=0D + Copyright (c) 2021, Intel Corporation. All rights reserved.
=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include =0D +=0D +PLD_S3_COMMUNICATION mPldS3Hob;=0D +EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *mSmramHob =3D NULL;=0D +PLD_SMM_REGISTERS *mSmmRegisterHob =3D NULL;;=0D +UINT64 mSmmFeatureControl =3D 0;=0D +=0D +/**=0D + Save SMM rebase and SMI handler information to SMM communication area=0D +=0D + The function detects SMM communication region for boot loader, if it is = detected, it=0D + will save SMM rebase information and S3 SMI handler information to SMM c= ommunication=0D + region. Bootloader should consume these information in S3 path to restor= e smm base,=0D + and write the 0xB2 port to trigger SMI so that payload could resume S3 r= egisters.=0D +=0D + @param[in] Id Value written to 0xB2 to trigger SMI ha= ndler.=0D +=0D + @retval EFI_SUCCESS Save reg Value success.=0D + @retval EFI_NOT_FOUND RegInfo not populated by=0D +**/=0D +EFI_STATUS=0D +SaveSmmInfoForS3 (=0D + IN UINT8 BlSwSmiHandlerInput=0D + )=0D +{=0D + EFI_STATUS Status;=0D + EFI_PROCESSOR_INFORMATION ProcessorInfo;=0D + EFI_MP_SERVICES_PROTOCOL *MpService;=0D + CPU_SMMBASE *SmmBaseInfo;=0D + PLD_TO_BL_SMM_INFO *PldSmmInfo;=0D + UINTN Index;=0D +=0D + PldSmmInfo =3D (PLD_TO_BL_SMM_INFO *)(UINTN)mPldS3Hob.CommBuffer.Physica= lStart;=0D + CopyGuid (&PldSmmInfo->Header.Name, &gS3CommunicationGuid);=0D + PldSmmInfo->Header.Header.HobType =3D EFI_HOB_TYPE_GUID_EXTENSION;=0D + PldSmmInfo->S3Info.SwSmiTriggerValue =3D BlSwSmiHandlerInput;=0D +=0D + //=0D + // Save APIC ID and SMM base=0D + //=0D + Status =3D gBS->LocateProtocol (&gEfiMpServiceProtocolGuid, NULL, (VOID = **)&MpService);=0D + if (EFI_ERROR(Status)) {=0D + return Status;=0D + }=0D +=0D + PldSmmInfo->Header.Header.HobLength =3D (UINT16)(sizeof (PLD_TO_BL_SMM_I= NFO) + gSmst->NumberOfCpus * sizeof (CPU_SMMBASE));=0D + PldSmmInfo->S3Info.CpuCount =3D (UINT32)gSmst->NumberOfCpus;=0D + SmmBaseInfo =3D &PldSmmInfo->S3Info.SmmBase[0];=0D + for (Index =3D 0; Index < gSmst->NumberOfCpus; Index++) {=0D + Status =3D MpService->GetProcessorInfo (MpService, Index, &ProcessorIn= fo);=0D + if (EFI_ERROR(Status)) {=0D + return Status;=0D + }=0D +=0D + SmmBaseInfo->ApicId =3D (UINT32)(UINTN)ProcessorInfo.ProcessorId;=0D + SmmBaseInfo->SmmBase =3D (UINT32)(UINTN)gSmst->CpuSaveState[Index] - S= MRAM_SAVE_STATE_MAP_OFFSET;=0D + DEBUG ((DEBUG_INFO, "CPU%d ID:%02X Base: %08X\n", Index, SmmBaseInfo->= ApicId, SmmBaseInfo->SmmBase));=0D + SmmBaseInfo++;=0D + }=0D +=0D + return EFI_SUCCESS;=0D +}=0D +=0D +=0D +/**=0D + Get specified SMI register based on given register ID=0D +=0D + @param[in] Id The register ID to get.=0D +=0D + @retval NULL The register is not found=0D + @return smi register=0D +=0D +**/=0D +PLD_GENERIC_REGISTER *=0D +GetRegisterById (=0D + UINT64 Id=0D + )=0D +{=0D + UINT32 Index;=0D +=0D + for (Index =3D 0; Index < mSmmRegisterHob->Count; Index++) {=0D + if (mSmmRegisterHob->Registers[Index].Id =3D=3D Id) {=0D + return &mSmmRegisterHob->Registers[Index];=0D + }=0D + }=0D + return NULL;=0D +}=0D +=0D +/**=0D + Set SMM SMI Global enable lock=0D +=0D +**/=0D +VOID=0D +LockSmiGlobalEn (=0D + VOID=0D + )=0D +{=0D + PLD_GENERIC_REGISTER *SmiLockReg;=0D +=0D + DEBUG ((DEBUG_ERROR, "LockSmiGlobalEn .....\n"));=0D +=0D + SmiLockReg =3D GetRegisterById (REGISTER_ID_SMI_GBL_EN_LOCK);=0D + if (SmiLockReg =3D=3D NULL) {=0D + DEBUG ((DEBUG_ERROR, "SMI global enable lock reg not found.\n"));=0D + return;=0D + }=0D +=0D + //=0D + // Set SMM SMI lock in S3 path=0D + //=0D + if ((SmiLockReg->Address.AccessSize =3D=3D EFI_ACPI_3_0_DWORD) &&= =0D + (SmiLockReg->Address.Address !=3D 0) &&=0D + (SmiLockReg->Address.RegisterBitWidth =3D=3D 1) &&=0D + (SmiLockReg->Address.AddressSpaceId =3D=3D EFI_ACPI_3_0_SYSTEM_MEM= ORY) &&=0D + (SmiLockReg->Value =3D=3D 1)) {=0D + DEBUG ((DEBUG_ERROR, "LockSmiGlobalEn ....is locked\n"));=0D +=0D + MmioOr32 ((UINT32)SmiLockReg->Address.Address, 1 << SmiLockReg->Addres= s.RegisterBitOffset);=0D + } else {=0D + DEBUG ((DEBUG_ERROR, "Unexpected SMM SMI lock register, need enhanceme= nt here.\n"));=0D + }=0D +}=0D +=0D +/**=0D + Check and set SMM feature lock bit and code check enable bit=0D + in S3 path.=0D +=0D +**/=0D +VOID=0D +SmmFeatureLockOnS3 (=0D + VOID=0D + )=0D +{=0D +=0D + if (mSmmFeatureControl !=3D 0) {=0D + return;=0D + }=0D +=0D + mSmmFeatureControl =3D AsmReadMsr64(MSR_SMM_FEATURE_CONTROL);=0D + if ((mSmmFeatureControl & 0x5) !=3D 0x5) {=0D + //=0D + // Set Lock bit [BIT0] for this register and SMM code check enable bit= [BIT2]=0D + //=0D + AsmWriteMsr64 (MSR_SMM_FEATURE_CONTROL, mSmmFeatureControl | 0x5);=0D + }=0D + mSmmFeatureControl =3D AsmReadMsr64(MSR_SMM_FEATURE_CONTROL);=0D +}=0D +=0D +=0D +=0D +/**=0D + Function to program SMRR base and mask.=0D +=0D + @param[in] ProcedureArgument Pointer to SMRR_BASE_MASK structure.=0D +**/=0D +VOID=0D +SetSmrr (=0D + IN VOID *ProcedureArgument=0D + )=0D +{=0D + if (ProcedureArgument !=3D NULL) {=0D + AsmWriteMsr64 (MSR_IA32_SMRR_PHYSBASE, ((SMRR_BASE_MASK *)ProcedureArg= ument)->Base);=0D + AsmWriteMsr64 (MSR_IA32_SMRR_PHYSMASK, ((SMRR_BASE_MASK *)ProcedureArg= ument)->Mask);=0D + }=0D +}=0D +=0D +/**=0D + Set SMRR in S3 path.=0D +=0D +**/=0D +VOID=0D +SetSmrrOnS3 (=0D + VOID=0D + )=0D +{=0D + EFI_STATUS Status;=0D + SMRR_BASE_MASK Arguments;=0D + UINTN Index;=0D + UINT32 SmmBase;=0D + UINT32 SmmSize;=0D +=0D + if ((AsmReadMsr64 (MSR_IA32_SMRR_PHYSBASE) !=3D 0) && ((AsmReadMsr64 (MS= R_IA32_SMRR_PHYSMASK) & BIT11) !=3D 0)) {=0D + return;=0D + }=0D +=0D + SmmBase =3D (UINT32)(UINTN)mSmramHob->Descriptor[0].PhysicalStart;=0D + SmmSize =3D (UINT32)(UINTN)mSmramHob->Descriptor[0].PhysicalSize;=0D + if ((mSmramHob->NumberOfSmmReservedRegions > 2) || (mSmramHob->NumberOfS= mmReservedRegions =3D=3D 0)) {=0D + DEBUG ((DEBUG_ERROR, "%d SMM ranges are not supported.\n", mSmramHob->= NumberOfSmmReservedRegions));=0D + return;=0D + } else if (mSmramHob->NumberOfSmmReservedRegions =3D=3D 2) {=0D + if ((mSmramHob->Descriptor[1].PhysicalStart + mSmramHob->Descriptor[1]= .PhysicalSize) =3D=3D SmmBase){=0D + SmmBase =3D (UINT32)(UINTN)mSmramHob->Descriptor[1].PhysicalStart;=0D + } else if (mSmramHob->Descriptor[1].PhysicalStart =3D=3D (SmmBase + Sm= mSize)) {=0D + DEBUG ((DEBUG_ERROR, "Two SMM regions are not continous.\n"));=0D + return;=0D + }=0D + SmmSize +=3D (UINT32)(UINTN)mSmramHob->Descriptor[1].PhysicalSize;=0D + }=0D +=0D + if ((SmmBase =3D=3D 0) || (SmmSize < SIZE_4KB)) {=0D + DEBUG ((DEBUG_ERROR, "Invalid SMM range.\n"));=0D + return ;=0D + }=0D +=0D + //=0D + // SMRR size must be of length 2^n=0D + // SMRR base alignment cannot be less than SMRR length=0D + //=0D + if ((SmmSize !=3D GetPowerOfTwo32 (SmmSize)) || ((SmmBase & ~(SmmSize - = 1)) !=3D SmmBase)) {=0D + DEBUG ((DEBUG_ERROR, " Invalid SMM range.\n"));=0D + return ;=0D + }=0D +=0D + //=0D + // Calculate smrr base, mask and pass them as arguments.=0D + //=0D + Arguments.Base =3D (SmmSize | MTRR_CACHE_WRITE_BACK);=0D + Arguments.Mask =3D (~(SmmSize - 1) & EFI_MSR_SMRR_MASK);=0D +=0D + //=0D + // Set SMRR valid bit=0D + //=0D + Arguments.Mask |=3D BIT11;=0D +=0D + //=0D + // Program smrr base and mask on BSP first and then on APs=0D + //=0D + SetSmrr(&Arguments);=0D + for (Index =3D 0; Index < gSmst->NumberOfCpus; Index++) {=0D + if (Index !=3D gSmst->CurrentlyExecutingCpu) {=0D + Status =3D gSmst->SmmStartupThisAp (SetSmrr, Index, (VOID *)&Argumen= ts);=0D + if (EFI_ERROR(Status)) {=0D + DEBUG ((DEBUG_ERROR, "Programming SMRR on AP# %d status: %r\n", In= dex, Status));=0D + }=0D + }=0D + }=0D +}=0D +=0D +=0D +/**=0D + Software SMI callback for restoring SMRR base and mask in S3 path.=0D +=0D + @param[in] DispatchHandle The unique handle assigned to this handl= er by SmiHandlerRegister().=0D + @param[in] Context Points to an optional handler context wh= ich was specified when the=0D + handler was registered.=0D + @param[in, out] CommBuffer A pointer to a collection of data in mem= ory that will=0D + be conveyed from a non-SMM environment i= nto an SMM environment.=0D + @param[in, out] CommBufferSize The size of the CommBuffer.=0D +=0D + @retval EFI_SUCCESS The interrupt was handled successfully.= =0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +BlSwSmiHandler (=0D + IN EFI_HANDLE DispatchHandle,=0D + IN CONST VOID *Context,=0D + IN OUT VOID *CommBuffer,=0D + IN OUT UINTN *CommBufferSize=0D + )=0D +{=0D + SetSmrrOnS3 ();=0D + SmmFeatureLockOnS3 ();=0D + LockSmiGlobalEn ();=0D +=0D + return EFI_SUCCESS;=0D +}=0D +=0D +=0D +/**=0D + Lock SMI in this SMM ready to lock event.=0D +=0D + @param Protocol Points to the protocol's unique identifier=0D + @param Interface Points to the interface instance=0D + @param Handle The handle on which the interface was installed=0D +=0D + @retval EFI_SUCCESS SmmEventCallback runs successfully=0D + @retval EFI_NOT_FOUND The Fvb protocol for variable is not found.=0D + **/=0D +EFI_STATUS=0D +EFIAPI=0D +BlSupportSmmReadyToLockCallback (=0D + IN CONST EFI_GUID *Protocol,=0D + IN VOID *Interface,=0D + IN EFI_HANDLE Handle=0D + )=0D +{=0D + //=0D + // Set SMM SMI lock=0D + //=0D + LockSmiGlobalEn ();=0D + return EFI_SUCCESS;=0D +}=0D +=0D +=0D +/**=0D + The driver's entry point.=0D +=0D + @param[in] ImageHandle The firmware allocated handle for the EFI image.= =0D + @param[in] SystemTable A pointer to the EFI System Table.=0D +=0D + @retval EFI_SUCCESS The entry point is executed successfully.=0D + @retval Others Some error occurs when executing this entry poin= t.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +BlSupportSmm (=0D + IN EFI_HANDLE ImageHandle,=0D + IN EFI_SYSTEM_TABLE *SystemTable=0D + )=0D +{=0D + EFI_STATUS Status;=0D + EFI_SMM_SW_DISPATCH2_PROTOCOL *SwDispatch;=0D + EFI_SMM_SW_REGISTER_CONTEXT SwContext;=0D + EFI_HANDLE SwHandle;=0D + EFI_HOB_GUID_TYPE *GuidHob;=0D + VOID *SmmHob;=0D + VOID *Registration;=0D +=0D + //=0D + // Get SMM S3 communication hob and save it=0D + //=0D + GuidHob =3D GetFirstGuidHob (&gS3CommunicationGuid);=0D + if (GuidHob !=3D NULL) {=0D + SmmHob =3D (VOID *) (GET_GUID_HOB_DATA(GuidHob));=0D + CopyMem (&mPldS3Hob, SmmHob, GET_GUID_HOB_DATA_SIZE(GuidHob));=0D + } else {=0D + return EFI_NOT_FOUND;=0D + }=0D +=0D + if (mPldS3Hob.PldAcpiS3Enable) {=0D + // Other drivers will take care of S3.=0D + return EFI_SUCCESS;=0D + }=0D +=0D + //=0D + // Get smram hob and save it=0D + //=0D + GuidHob =3D GetFirstGuidHob (&gEfiSmmSmramMemoryGuid);=0D + if (GuidHob !=3D NULL) {=0D + SmmHob =3D (VOID *) (GET_GUID_HOB_DATA(GuidHob));=0D + mSmramHob =3D AllocatePool (GET_GUID_HOB_DATA_SIZE(GuidHob));=0D + if (mSmramHob =3D=3D NULL) {=0D + return EFI_OUT_OF_RESOURCES;=0D + }=0D + CopyMem (mSmramHob, SmmHob, GET_GUID_HOB_DATA_SIZE(GuidHob));=0D + } else {=0D + return EFI_NOT_FOUND;=0D + }=0D +=0D + //=0D + // Get SMM register hob and save it=0D + //=0D + GuidHob =3D GetFirstGuidHob (&gSmmRegisterInfoGuid);=0D + if (GuidHob !=3D NULL) {=0D + SmmHob =3D (VOID *) (GET_GUID_HOB_DATA(GuidHob));=0D + mSmmRegisterHob =3D AllocatePool (GET_GUID_HOB_DATA_SIZE(GuidHob));=0D + if (mSmmRegisterHob =3D=3D NULL) {=0D + return EFI_OUT_OF_RESOURCES;=0D + }=0D + CopyMem (mSmmRegisterHob, SmmHob, GET_GUID_HOB_DATA_SIZE(GuidHob));=0D + } else {=0D + return EFI_NOT_FOUND;=0D + }=0D +=0D + //=0D + // Get the Sw dispatch protocol and register SMI handler.=0D + //=0D + Status =3D gSmst->SmmLocateProtocol (&gEfiSmmSwDispatch2ProtocolGuid, NU= LL, (VOID**)&SwDispatch);=0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D + SwContext.SwSmiInputValue =3D (UINTN) -1;=0D + Status =3D SwDispatch->Register (SwDispatch, BlSwSmiHandler, &SwContext,= &SwHandle);=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_ERROR, "Registering S3 smi handler failed: %r\n", Status= ));=0D + return Status;=0D + }=0D +=0D + //=0D + // Register SMM ready to lock callback=0D + //=0D + Status =3D gSmst->SmmRegisterProtocolNotify (=0D + &gEfiSmmReadyToLockProtocolGuid,=0D + BlSupportSmmReadyToLockCallback,=0D + &Registration=0D + );=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + SaveSmmInfoForS3 ((UINT8)SwContext.SwSmiInputValue);=0D +=0D + return EFI_SUCCESS;=0D +}=0D +=0D diff --git a/UefiPayloadPkg/BlSupportSmm/BlSupportSmm.h b/UefiPayloadPkg/Bl= SupportSmm/BlSupportSmm.h new file mode 100644 index 0000000000..ed2b28960c --- /dev/null +++ b/UefiPayloadPkg/BlSupportSmm/BlSupportSmm.h @@ -0,0 +1,41 @@ +/** @file=0D + The header file of bootloader support SMM.=0D +=0D + Copyright (c) 2021, Intel Corporation. All rights reserved.
=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +#ifndef _BL_SUPPORT_SMM_H=0D +#define _BL_SUPPORT_SMM_H=0D +=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +=0D +#define EFI_MSR_SMRR_MASK 0xFFFFF000=0D +#define MSR_SMM_FEATURE_CONTROL 0x4E0=0D +#define SMRAM_SAVE_STATE_MAP_OFFSET 0xFC00 /// Save state offset from= SMBASE=0D +=0D +typedef struct {=0D + UINT32 Base;=0D + UINT32 Mask;=0D +} SMRR_BASE_MASK;=0D +=0D +#endif=0D +=0D diff --git a/UefiPayloadPkg/BlSupportSmm/BlSupportSmm.inf b/UefiPayloadPkg/= BlSupportSmm/BlSupportSmm.inf new file mode 100644 index 0000000000..75d4777971 --- /dev/null +++ b/UefiPayloadPkg/BlSupportSmm/BlSupportSmm.inf @@ -0,0 +1,49 @@ +## @file=0D +# Bootloader Support SMM module=0D +#=0D +# Copyright (c) 2021, Intel Corporation. All rights reserved.
=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D BlSupportSmm=0D + FILE_GUID =3D AA292DE7-E11E-42E6-846B-5813A5A8D982= =0D + MODULE_TYPE =3D DXE_SMM_DRIVER=0D + PI_SPECIFICATION_VERSION =3D 0x0001000A=0D + VERSION_STRING =3D 1.0=0D + ENTRY_POINT =3D BlSupportSmm=0D +=0D +[Sources]=0D + BlSupportSmm.c=0D + BlSupportSmm.h=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + MdeModulePkg/MdeModulePkg.dec=0D + UefiCpuPkg/UefiCpuPkg.dec=0D + UefiPayloadPkg/UefiPayloadPkg.dec=0D +=0D +[LibraryClasses]=0D + UefiDriverEntryPoint=0D + UefiBootServicesTableLib=0D + SmmServicesTableLib=0D + MemoryAllocationLib=0D + BaseLib=0D + IoLib=0D + HobLib=0D +=0D +[Guids]=0D + gS3CommunicationGuid=0D + gEfiSmmSmramMemoryGuid=0D + gSmmRegisterInfoGuid=0D +=0D +[Protocols]=0D + gEfiSmmSwDispatch2ProtocolGuid=0D + gEfiMpServiceProtocolGuid=0D + gEfiSmmReadyToLockProtocolGuid=0D +=0D +[Depex]=0D + gEfiSmmSwDispatch2ProtocolGuid=0D diff --git a/UefiPayloadPkg/Include/Guid/SmmS3CommunicationInfoGuid.h b/Uef= iPayloadPkg/Include/Guid/SmmS3CommunicationInfoGuid.h new file mode 100644 index 0000000000..0295ae77d2 --- /dev/null +++ b/UefiPayloadPkg/Include/Guid/SmmS3CommunicationInfoGuid.h @@ -0,0 +1,54 @@ +/** @file=0D + This file defines the SMM S3 communication hob structure.=0D +=0D + Copyright (c) 2021, Intel Corporation. All rights reserved.
=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#ifndef __PAYLOAD_S3_COMMUNICATION_GUID_H__=0D +#define __PAYLOAD_S3_COMMUNICATION_GUID_H__=0D +=0D +extern EFI_GUID gS3CommunicationGuid;=0D +=0D +#pragma pack(1)=0D +=0D +typedef struct {=0D + EFI_SMRAM_DESCRIPTOR CommBuffer;=0D + BOOLEAN PldAcpiS3Enable;=0D +} PLD_S3_COMMUNICATION;=0D +=0D +///=0D +/// The information below is used for communication between bootloader and= payload.=0D +/// It is used to save/store some registers in S3 path=0D +///=0D +/// This region exists only when gEfiAcpiVariableGuid HOB exist.=0D +/// when PLD_S3_INFO.PldAcpiS3Enable is false, the communication buffer is= defined as below.=0D +///=0D +=0D +typedef struct {=0D + UINT32 ApicId;=0D + UINT32 SmmBase;=0D +} CPU_SMMBASE;=0D +=0D +typedef struct {=0D + UINT8 SwSmiData;=0D + UINT8 SwSmiTriggerValue;=0D + UINT16 Reserved;=0D + UINT32 CpuCount;=0D + CPU_SMMBASE SmmBase[0];=0D +} SMM_S3_INFO;=0D +=0D +//=0D +// Payload would save this structure to S3 communication area in normal bo= ot.=0D +// In S3 path, bootloader need restore SMM base and writie IO port 0xB2 wi= th SwSmiTriggerValue=0D +// to trigger SMI to let payload to restore S3.=0D +//=0D +typedef struct {=0D + EFI_HOB_GUID_TYPE Header;=0D + SMM_S3_INFO S3Info;=0D +} PLD_TO_BL_SMM_INFO;=0D +=0D +#pragma pack()=0D +=0D +#endif=0D diff --git a/UefiPayloadPkg/UefiPayloadPkg.dec b/UefiPayloadPkg/UefiPayload= Pkg.dec index 1705f28ec4..417a70f4e8 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dec +++ b/UefiPayloadPkg/UefiPayloadPkg.dec @@ -38,6 +38,7 @@ gLoaderMemoryMapInfoGuid =3D { 0xa1ff7424, 0x7a1a, 0x478e, { 0xa9, 0xe4,= 0x92, 0xf3, 0x57, 0xd1, 0x28, 0x32 } }=0D =0D gSmmRegisterInfoGuid =3D { 0xaa9bd7a7, 0xcafb, 0x4499, { 0xa4, 0xa9,= 0xb, 0x34, 0x6b, 0x40, 0xa6, 0x22 } }=0D + gS3CommunicationGuid =3D { 0x88e31ba1, 0x1856, 0x4b8b, { 0xbb, 0xdf,= 0xf8, 0x16, 0xdd, 0x94, 0xa, 0xef } }=0D =0D [Ppis]=0D gEfiPayLoadHobBasePpiGuid =3D { 0xdbe23aa1, 0xa342, 0x4b97, {0x85, 0xb6,= 0xb2, 0x26, 0xf1, 0x61, 0x73, 0x89} }=0D --=20 2.32.0.windows.2