From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 6807B740032 for ; Thu, 27 Jul 2023 02:21:25 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=25rM3V0sMyJhZBqpvbN55Ja41bxZ9yj7GdttzJYOexU=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:X-IronPort-AV:X-IronPort-AV:X-Received:X-ExtLoop1:X-IronPort-AV:X-IronPort-AV:X-Received:From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:X-Gm-Message-State:Content-Transfer-Encoding; s=20140610; t=1690424484; v=1; b=vP+O1S3BO1WK54E7OGVIh0cI6v3f86J+HCtFxVG0VMzFiBw4dQpY7AMXKjmn+1CJ8XcB94d1 Zl42fo3vkVZcVC3ef3tKykN9dkIcESjGMo+YDXXpF1HE0427OnBN/v8J7V8gP5P+hKUo4xm5jMJ IzhjNefM24tDf2dL4XtEl2SQ= X-Received: by 127.0.0.2 with SMTP id mmMoYY7687511xrMzLElqU7V; Wed, 26 Jul 2023 19:21:24 -0700 X-Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web11.4243.1690424483657202316 for ; Wed, 26 Jul 2023 19:21:23 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10783"; a="399122682" X-IronPort-AV: E=Sophos;i="6.01,233,1684825200"; d="scan'208";a="399122682" X-Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jul 2023 19:21:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10783"; a="756461003" X-IronPort-AV: E=Sophos;i="6.01,233,1684825200"; d="scan'208";a="756461003" X-Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.158]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jul 2023 19:21:21 -0700 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar Subject: [edk2-devel] [PATCH 5/5] UefiCpuPkg/PiSmmCpuDxe: use MpService2Ppi to wakeup AP in s3 Date: Thu, 27 Jul 2023 10:20:40 +0800 Message-Id: <20230727022040.1910-6-dun.tan@intel.com> In-Reply-To: <20230727022040.1910-1-dun.tan@intel.com> References: <20230727022040.1910-1-dun.tan@intel.com> MIME-Version: 1.0 Precedence: Bulk 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,dun.tan@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: g5XXWNskiooZhhimVTpkJKdAx7686176AA= Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=vP+O1S3B; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io Use MpService2Ppi to wakeup AP in s3 boot flow during initializing CPU. If mSmmS3ResumeState->MpService2Ppi is not 0, then BSP will use MpService2Ppi->StartupAllCPUs to do CPU initialization for both BSP and AP instead of only sending InitSipiSipi for AP. Signed-off-by: Dun Tan Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar --- UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 20 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c index d2e2135d08..8b0e4afc59 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c @@ -7,6 +7,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include "PiSmmCpuDxeSmm.h" +#include +#include #pragma pack(1) typedef struct { @@ -571,12 +573,17 @@ InitializeAp ( SetRegister (FALSE); // - // Place AP into the safe code, count down the number with lock mechanism in the safe code. + // When using MpService2Ppi to wakeup AP, BSP will fail to return from MpService2Ppi if AP hang there. // - TopOfStack = (UINTN)Stack + sizeof (Stack); - TopOfStack &= ~(UINTN)(CPU_STACK_ALIGNMENT - 1); - CopyMem ((VOID *)(UINTN)mApHltLoopCode, mApHltLoopCodeTemplate, sizeof (mApHltLoopCodeTemplate)); - TransferApToSafeState ((UINTN)mApHltLoopCode, TopOfStack, (UINTN)&mNumberToFinish); + if (mSmmS3ResumeState->MpService2Ppi == 0) { + // + // Place AP into the safe code, count down the number with lock mechanism in the safe code. + // + TopOfStack = (UINTN)Stack + sizeof (Stack); + TopOfStack &= ~(UINTN)(CPU_STACK_ALIGNMENT - 1); + CopyMem ((VOID *)(UINTN)mApHltLoopCode, mApHltLoopCodeTemplate, sizeof (mApHltLoopCodeTemplate)); + TransferApToSafeState ((UINTN)mApHltLoopCode, TopOfStack, (UINTN)&mNumberToFinish); + } } /** @@ -634,7 +641,7 @@ PrepareApStartupVector ( The function is invoked before SMBASE relocation in S3 path to restores CPU status. The function is invoked before SMBASE relocation in S3 path. It does first time microcode load - and restores MTRRs for both BSP and APs. + and restores MTRRs for BSP. **/ VOID @@ -689,8 +696,10 @@ InitializeCpuAfterRebase ( // SetRegister (FALSE); - while (mNumberToFinish > 0) { - CpuPause (); + if (mSmmS3ResumeState->MpService2Ppi == 0) { + while (mNumberToFinish > 0) { + CpuPause (); + } } } @@ -742,6 +751,24 @@ InitializeBsp ( } } +/** + Cpu initialization procedure. + + @param[in,out] Buffer The pointer to private data buffer. +**/ +VOID +EFIAPI +InitializeCpuProcedure ( + IN OUT VOID *Buffer + ) +{ + if (mBspApicId == GetApicId ()) { + InitializeBsp (); + } else { + InitializeAp (); + } +} + /** Restore SMM Configuration in S3 boot path. @@ -790,11 +817,12 @@ SmmRestoreCpu ( VOID ) { - SMM_S3_RESUME_STATE *SmmS3ResumeState; - IA32_DESCRIPTOR Ia32Idtr; - IA32_DESCRIPTOR X64Idtr; - IA32_IDT_GATE_DESCRIPTOR IdtEntryTable[EXCEPTION_VECTOR_NUMBER]; - EFI_STATUS Status; + SMM_S3_RESUME_STATE *SmmS3ResumeState; + IA32_DESCRIPTOR Ia32Idtr; + IA32_DESCRIPTOR X64Idtr; + IA32_IDT_GATE_DESCRIPTOR IdtEntryTable[EXCEPTION_VECTOR_NUMBER]; + EFI_STATUS Status; + EDKII_PEI_MP_SERVICES2_PPI *Mp2ServicePpi; DEBUG ((DEBUG_INFO, "SmmRestoreCpu()\n")); @@ -858,15 +886,22 @@ SmmRestoreCpu ( // mInitApsAfterSmmBaseReloc = FALSE; - PrepareApStartupVector (mAcpiCpuData.StartupVector); - // - // Send INIT IPI - SIPI to all APs - // - SendInitSipiSipiAllExcludingSelf ((UINT32)mAcpiCpuData.StartupVector); + if (mSmmS3ResumeState->MpService2Ppi != 0) { + mBspApicId = GetApicId (); + Mp2ServicePpi = (EDKII_PEI_MP_SERVICES2_PPI *)(UINTN)mSmmS3ResumeState->MpService2Ppi; + Mp2ServicePpi->StartupAllCPUs (Mp2ServicePpi, (EFI_AP_PROCEDURE)InitializeCpuProcedure, 0, NULL); + } else { + PrepareApStartupVector (mAcpiCpuData.StartupVector); + // + // Send INIT IPI - SIPI to all APs + // + SendInitSipiSipiAllExcludingSelf ((UINT32)mAcpiCpuData.StartupVector); + InitializeBsp (); + } + } else { + InitializeBsp (); } - InitializeBsp (); - // // Set a flag to restore SMM configuration in S3 path. // -- 2.31.1.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#107283): https://edk2.groups.io/g/devel/message/107283 Mute This Topic: https://groups.io/mt/100383964/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-