From nobody Thu May 16 23:01:08 2024 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+106323+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+106323+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1687703978; cv=none; d=zohomail.com; s=zohoarc; b=TH25a88mdJkwS/lWhWS7JZUFuto3tiyrja8YfBf0X3d40uTzaAuqFA8gmset57J5RO47gEwnlgBPAptte0+ar1BlyhRbVQaAWqSA7lMwXxbtN3rexa7PTpI8Yoj94zikpdaeinBbVV9tVyI2HmQxfjl82y1pb6XpBNLZKhSdHAg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687703978; h=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=kLCX1bBMkcI7ZWbnoZtW5Yv2z17avFF/bg6Y6QRTOQ8=; b=JonLMNkRz8kA9L4b/4ciu98KhNmYfklfDRHxuSFkNYdowptM7MrhY9xD/Lx09BUzLHdkSGRFC9Lg+EYMKXuHo8y9ROgpBwIvnqDMd09f5F4IHWDZSIAI5aG88jQA4IO8ZO7rKb6p4HuTdVPLAODlBbkOyA88uZoN7oCQOiugmHA= 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+106323+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 1687703978297349.0229089511538; Sun, 25 Jun 2023 07:39:38 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id hhFqYY1788612xatwOwukbtw; Sun, 25 Jun 2023 07:39:38 -0700 X-Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web10.12565.1687703974569737167 for ; Sun, 25 Jun 2023 07:39:37 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="363624303" X-IronPort-AV: E=Sophos;i="6.01,157,1684825200"; d="scan'208";a="363624303" X-Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2023 07:39:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="785871770" X-IronPort-AV: E=Sophos;i="6.01,157,1684825200"; d="scan'208";a="785871770" X-Received: from shwdeopenlab705.ccr.corp.intel.com ([10.239.55.55]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2023 07:39:35 -0700 From: "Yuanhao Xie" To: devel@edk2.groups.io Cc: Gerd Hoffmann , Eric Dong , Ray Ni , Rahul Kumar , Tom Lendacky , Yuanhao Xie Subject: [edk2-devel] [Patch V2 1/6] UefiCpuPkg: Refactor the logic for placing APs in HltLoop. Date: Sun, 25 Jun 2023 22:39:15 +0800 Message-Id: <20230625143920.57095-2-yuanhao.xie@intel.com> In-Reply-To: <20230625143920.57095-1-yuanhao.xie@intel.com> References: <20230625143920.57095-1-yuanhao.xie@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,yuanhao.xie@intel.com X-Gm-Message-State: vULthHuJCdxfvezvaSl4gAbRx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1687703978; bh=P/FTOj5jL2J2boF+hjYq1JVtume1xrkRw/UqMY8wIVM=; h=Cc:Date:From:Reply-To:Subject:To; b=W0t6C45K0er6f/q9g32judhOn740u2nZppRL1G5VdUgKKtsunMTZ5ihV/7Jl79pLgHx c/rFDDsVz5D0cxbXaUSljv/y2PJutHRbzhST68ezPQh0J/9058lHejlsQ15gQIZwV1BSg 2Dvw7n0koaDpyl18Q46rb8gFa09F1DF9H48= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1687703979415100007 Content-Type: text/plain; charset="utf-8" Refactor the logic for placing APs in HltLoop into a separate function. Cc: Gerd Hoffmann Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Tom Lendacky Signed-off-by: Yuanhao Xie --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 35 ++++++++++++++++++++++++--------= --- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index f1f2840714..9560b39220 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -636,6 +636,28 @@ InitializeApData ( SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateIdle); } =20 +/** + This function place APs in Halt loop. + + @param[in] CpuMpData Pointer to CPU MP Data +**/ +VOID +PlaceAPInHltLoop ( + IN CPU_MP_DATA *CpuMpData + ) +{ + while (TRUE) { + DisableInterrupts (); + if (CpuMpData->UseSevEsAPMethod) { + SevEsPlaceApHlt (CpuMpData); + } else { + CpuSleep (); + } + + CpuPause (); + } +} + /** This function will be called from AP reset code if BSP uses WakeUpAP. =20 @@ -812,19 +834,10 @@ ApWakeupFunction ( // Place AP is specified loop mode // if (CpuMpData->ApLoopMode =3D=3D ApInHltLoop) { + PlaceAPInHltLoop (CpuMpData); // - // Place AP in HLT-loop + // Never run here // - while (TRUE) { - DisableInterrupts (); - if (CpuMpData->UseSevEsAPMethod) { - SevEsPlaceApHlt (CpuMpData); - } else { - CpuSleep (); - } - - CpuPause (); - } } =20 while (TRUE) { --=20 2.36.1.windows.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 (#106323): https://edk2.groups.io/g/devel/message/106323 Mute This Topic: https://groups.io/mt/99769824/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 Thu May 16 23:01:08 2024 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+106324+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+106324+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1687703981; cv=none; d=zohomail.com; s=zohoarc; b=HLv6zHR2oRGVDEi0mcuPmDajwTFpKI6VxxKAxCXMxC9eoQeqEN3TJXSfTHOQ9+Absfkt4KGHM/qf5RULNITXK0AK/niXn02cK4hcbaGiMgP9zLmap39X2biGRnkwFiEwPZcvT9gOB1uXm+YnUYphLHP6NpAxKPBbXKO7iCnJf0I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687703981; h=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=2UKDzDdGvE6exD1BPPTcVaSmKl+OYkAdvM2o6+NkcwI=; b=PNrE1ekp0gMH8tj5ecsPASPvS0vkpl6MMeObqkwPvzyjmuL0zdjG5TgRDkORIosqXvFUEktgEc8KxygRe1a0G2pm/X+uxGHWFPhTIBQtP0qlNMjXe+tKodM6i1isF4DfvEex2IH/tP3zQ+xN514XYxdyNPxIfk7tuaLtrM8e8kg= 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+106324+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 1687703981324663.8988174609001; Sun, 25 Jun 2023 07:39:41 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Kqa8YY1788612xz63xHH1pLV; Sun, 25 Jun 2023 07:39:41 -0700 X-Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web10.12565.1687703974569737167 for ; Sun, 25 Jun 2023 07:39:40 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="363624317" X-IronPort-AV: E=Sophos;i="6.01,157,1684825200"; d="scan'208";a="363624317" X-Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2023 07:39:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="785871779" X-IronPort-AV: E=Sophos;i="6.01,157,1684825200"; d="scan'208";a="785871779" X-Received: from shwdeopenlab705.ccr.corp.intel.com ([10.239.55.55]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2023 07:39:38 -0700 From: "Yuanhao Xie" To: devel@edk2.groups.io Cc: Gerd Hoffmann , Eric Dong , Ray Ni , Rahul Kumar , Tom Lendacky , Yuanhao Xie Subject: [edk2-devel] [Patch V2 2/6] UefiCpuPkg: Refactor the logic for placing APs in Mwait/Runloop. Date: Sun, 25 Jun 2023 22:39:16 +0800 Message-Id: <20230625143920.57095-3-yuanhao.xie@intel.com> In-Reply-To: <20230625143920.57095-1-yuanhao.xie@intel.com> References: <20230625143920.57095-1-yuanhao.xie@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,yuanhao.xie@intel.com X-Gm-Message-State: NHHvP0rUtdbmH5NMDhaw59DSx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1687703981; bh=nBsyhSEcsPaQgalF8LULptk1pdQ39rZHg8rzshSHlss=; h=Cc:Date:From:Reply-To:Subject:To; b=dYyfqkiBHhQU87EItqw40f22wxM+OQ+1dTlnCgYIsRXZstqbCxEs/HES5ZWoM4fFSEr iUsAbno2AA+7jcpDij+0Zqp2UoDWYlOjELsQ5rkfEtiMPH9np7j7JEPWn1W9B0BXZIa3/ xiWf6n3H+zo1H4IdgDL/4jx79JoGQQUgscA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1687703983059100001 Content-Type: text/plain; charset="utf-8" Refactor the logic for placing APs in Mwait/Runloop into a separate function. Cc: Gerd Hoffmann Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Tom Lendacky Signed-off-by: Yuanhao Xie --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 83 ++++++++++++++++++++++++++++++++= ++++++++++++++++++--------------------------------- 1 file changed, 50 insertions(+), 33 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 9560b39220..e8dd640f9b 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -658,6 +658,54 @@ PlaceAPInHltLoop ( } } =20 +/** + This function place APs in Mwait or Run loop. + + @param[in] ApLoopMode Ap Loop Mode + @param[in] ApStartupSignalBuffer Pointer to Ap Startup Signal Buf= fer + @param[in] ApTargetCState Ap Target CState +**/ +VOID +PlaceAPInMwaitLoopOrRunLoop ( + IN UINT8 ApLoopMode, + IN volatile UINT32 *ApStartupSignalBuffer, + IN UINT8 ApTargetCState + ) +{ + while (TRUE) { + DisableInterrupts (); + if (ApLoopMode =3D=3D ApInMwaitLoop) { + // + // Place AP in MWAIT-loop + // + AsmMonitor ((UINTN)ApStartupSignalBuffer, 0, 0); + if (*ApStartupSignalBuffer !=3D WAKEUP_AP_SIGNAL) { + // + // Check AP start-up signal again. + // If AP start-up signal is not set, place AP into + // the specified C-state + // + AsmMwait (ApTargetCState << 4, 0); + } + } else if (ApLoopMode =3D=3D ApInRunLoop) { + // + // Place AP in Run-loop + // + CpuPause (); + } else { + ASSERT (FALSE); + } + + // + // If AP start-up signal is written, AP is waken up + // otherwise place AP in loop again + // + if (*ApStartupSignalBuffer =3D=3D WAKEUP_AP_SIGNAL) { + break; + } + } +} + /** This function will be called from AP reset code if BSP uses WakeUpAP. =20 @@ -838,39 +886,8 @@ ApWakeupFunction ( // // Never run here // - } - - while (TRUE) { - DisableInterrupts (); - if (CpuMpData->ApLoopMode =3D=3D ApInMwaitLoop) { - // - // Place AP in MWAIT-loop - // - AsmMonitor ((UINTN)ApStartupSignalBuffer, 0, 0); - if (*ApStartupSignalBuffer !=3D WAKEUP_AP_SIGNAL) { - // - // Check AP start-up signal again. - // If AP start-up signal is not set, place AP into - // the specified C-state - // - AsmMwait (CpuMpData->ApTargetCState << 4, 0); - } - } else if (CpuMpData->ApLoopMode =3D=3D ApInRunLoop) { - // - // Place AP in Run-loop - // - CpuPause (); - } else { - ASSERT (FALSE); - } - - // - // If AP start-up signal is written, AP is waken up - // otherwise place AP in loop again - // - if (*ApStartupSignalBuffer =3D=3D WAKEUP_AP_SIGNAL) { - break; - } + } else { + PlaceAPInMwaitLoopOrRunLoop (CpuMpData->ApLoopMode, ApStartupSignalB= uffer, CpuMpData->ApTargetCState); } } } --=20 2.36.1.windows.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 (#106324): https://edk2.groups.io/g/devel/message/106324 Mute This Topic: https://groups.io/mt/99769825/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 Thu May 16 23:01:08 2024 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+106325+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+106325+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1687703983; cv=none; d=zohomail.com; s=zohoarc; b=Z162Vcv8kTIVfplxyKTcfDBYgH7vFham8aHCjIzb/y+7RBptm3x15IH6ljwuTRbg/v0UmiWdtLz8PjTK1H4UPbztfaeuXUy62AXnVr6xpM2whuu8/VKIFTLDEgZC+iq1W6QKpeoyFU0je97hbrUgDonlrt1GkktILP55oIqmtTQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687703983; h=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=aLNlkB9Mt05u599ZkrJ3AZW9HIj0ncn6515ktnEPG40=; b=NSAU+XOOdgd3/rMpWt/g4/Aae1xZqFQD842qbhtgRhbW/jyLwhP1AfhwrYFHvU6V2mOzWBnj9p10zNSmp+x5ivOzF95SEkSWFRt0roJpO/zcsgETfDUCKSTkFraZfNdQ0pzAOiXyPPsDRYziMEb9GHrCQk/p4m51MgYWfRYJw/8= 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+106325+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 1687703983869849.1264119584455; Sun, 25 Jun 2023 07:39:43 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 2ErfYY1788612xnqJPc17G9e; Sun, 25 Jun 2023 07:39:43 -0700 X-Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web10.12565.1687703974569737167 for ; Sun, 25 Jun 2023 07:39:43 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="363624335" X-IronPort-AV: E=Sophos;i="6.01,157,1684825200"; d="scan'208";a="363624335" X-Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2023 07:39:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="785871798" X-IronPort-AV: E=Sophos;i="6.01,157,1684825200"; d="scan'208";a="785871798" X-Received: from shwdeopenlab705.ccr.corp.intel.com ([10.239.55.55]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2023 07:39:40 -0700 From: "Yuanhao Xie" To: devel@edk2.groups.io Cc: Gerd Hoffmann , Eric Dong , Ray Ni , Rahul Kumar , Tom Lendacky , Yuanhao Xie Subject: [edk2-devel] [Patch V2 3/6] UefiCpuPkg: Create MpHandOff. Date: Sun, 25 Jun 2023 22:39:17 +0800 Message-Id: <20230625143920.57095-4-yuanhao.xie@intel.com> In-Reply-To: <20230625143920.57095-1-yuanhao.xie@intel.com> References: <20230625143920.57095-1-yuanhao.xie@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,yuanhao.xie@intel.com X-Gm-Message-State: biwjiQ0E0cda4BzFDfKEP77yx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1687703983; bh=FW+90nWQsuZoNVu9PDjiI7e0tl6hvnZbBiuVhjcNQYE=; h=Cc:Date:From:Reply-To:Subject:To; b=Nt5temNfnXU5zf4XYSj6NDB0XpSDiuuQZNl3HU9yyQMAe7mPOb0b7D7qrs/ybj+wS3D /qkvBEzwhoYkFiby8qp4lUxR6NAd3ruaa7CXe0vmEcuD/XhFu4fpEIxcDbJdEbpxueG8D bMTV7StmjvblRJEs0GjP7Ms/SXpasEZK2y0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1687703985081100005 Content-Type: text/plain; charset="utf-8" Initially, the purpose of the Hob was twofold: it served as a way to transfer information from PEI to DXE. However, during the DXE phase, only a few fields from the CPU_MP_DATA which collected in PEI phase were needed. A new Hob was specifically created to transfer information to the DXE phase. This new Hob contained only the essential fields required for reuse in DXE. For instance, instead of directly including the BspNumber in MpHandOff, the DXE phase introduced the use of GetBspNumber() to collect the BspNumber from ApicID and CpuCount. The SaveCpuMpData() function was updated to construct the MP_HAND_OFF Hob. Additionally, the function introduced the MP_HAND_OFF_SIGNAL, which solely served the purpose of awakening the APs and transitioning their context from PEI to DXE. The WaitLoopExecutionMode field indicated whether the bit mode of PEI matched that of DXE. Both of them were filled only if the ApLoopMode was not ApInHltLoop. In the case of ApLoopMode, it remained necessary to wake up the APs using the init-sipi-sipi sequence. The function GetMpHandOffHob() was added to facilitate access to the collected MpHandOff in the DXE phase. The CpuMpData in the DXE phase was updated by gathering information from MpHandOff. Since MpHandOff replaced the usage of OldCpuMpData and contained essential information from the PEI phase to the DXE phase. AmdSevUpdateCpuMpData was included to maintain the original implementation of AmdSev, ensuring that OldCpuMpData->NewCpuMpData pointed to CpuMpData. Cc: Gerd Hoffmann Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Tom Lendacky Signed-off-by: Yuanhao Xie --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 100 ++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------- UefiCpuPkg/Library/MpInitLib/MpLib.h | 66 ++++++++++++++++++++++++++++= ++++++++++++++++++++++++++++++++++++++ UefiCpuPkg/Library/MpInitLib/PeiMpLib.c | 32 ++++++++++++++++++++++++++++= +++- 3 files changed, 184 insertions(+), 14 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index e8dd640f9b..1252ee9673 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -14,6 +14,7 @@ #include =20 EFI_GUID mCpuInitMpLibHobGuid =3D CPU_INIT_MP_LIB_HOB_GUID; +EFI_GUID mMpHandOffGuid =3D MP_HANDOFF_GUID; =20 /** Save the volatile registers required to be restored following INIT IPI. @@ -1814,6 +1815,54 @@ CheckAllAPs ( return EFI_NOT_READY; } =20 +/** + This function Get BspNumber. + + @param[in] MpHandOff Pointer to MpHandOff + @return BspNumber +**/ +UINT32 +GetBspNumber ( + IN CONST MP_HAND_OFF *MpHandOff + ) +{ + UINT32 ApicId; + UINT32 BspNumber; + UINT32 Index; + + // + // Get the processor number for the BSP + // + BspNumber =3D MAX_UINT32; + ApicId =3D GetInitialApicId (); + for (Index =3D 0; Index < MpHandOff->CpuCount; Index++) { + if (MpHandOff->Info[Index].ApicId =3D=3D ApicId) { + BspNumber =3D Index; + } + } + + ASSERT (BspNumber !=3D MAX_UINT32); + + return BspNumber; +} + +/** + Get pointer to CPU MP Data structure from GUIDed HOB. + + @param[in] CpuMpData The pointer to CPU MP Data structure. +**/ +VOID +AmdSevUpdateCpuMpData ( + IN CPU_MP_DATA *CpuMpData + ) +{ + CPU_MP_DATA *OldCpuMpData; + + OldCpuMpData =3D GetCpuMpDataFromGuidedHob (); + + OldCpuMpData->NewCpuMpData =3D CpuMpData; +} + /** MP Initialize Library initialization. =20 @@ -1833,7 +1882,7 @@ MpInitLibInitialize ( VOID ) { - CPU_MP_DATA *OldCpuMpData; + MP_HAND_OFF *MpHandOff; CPU_INFO_IN_HOB *CpuInfoInHob; UINT32 MaxLogicalProcessorNumber; UINT32 ApStackSize; @@ -1852,11 +1901,11 @@ MpInitLibInitialize ( UINTN BackupBufferAddr; UINTN ApIdtBase; =20 - OldCpuMpData =3D GetCpuMpDataFromGuidedHob (); - if (OldCpuMpData =3D=3D NULL) { + MpHandOff =3D GetMpHandOffHob (); + if (MpHandOff =3D=3D NULL) { MaxLogicalProcessorNumber =3D PcdGet32 (PcdCpuMaxLogicalProcessorNumbe= r); } else { - MaxLogicalProcessorNumber =3D OldCpuMpData->CpuCount; + MaxLogicalProcessorNumber =3D MpHandOff->CpuCount; } =20 ASSERT (MaxLogicalProcessorNumber !=3D 0); @@ -2000,7 +2049,7 @@ MpInitLibInitialize ( // ProgramVirtualWireMode (); =20 - if (OldCpuMpData =3D=3D NULL) { + if (MpHandOff =3D=3D NULL) { if (MaxLogicalProcessorNumber > 1) { // // Wakeup all APs and calculate the processor count in system @@ -2012,15 +2061,18 @@ MpInitLibInitialize ( // APs have been wakeup before, just get the CPU Information // from HOB // - OldCpuMpData->NewCpuMpData =3D CpuMpData; - CpuMpData->CpuCount =3D OldCpuMpData->CpuCount; - CpuMpData->BspNumber =3D OldCpuMpData->BspNumber; - CpuMpData->CpuInfoInHob =3D OldCpuMpData->CpuInfoInHob; - CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->Cp= uInfoInHob; + AmdSevUpdateCpuMpData (CpuMpData); + CpuMpData->CpuCount =3D MpHandOff->CpuCount; + CpuMpData->BspNumber =3D GetBspNumber (MpHandOff); + CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoI= nHob; for (Index =3D 0; Index < CpuMpData->CpuCount; Index++) { InitializeSpinLock (&CpuMpData->CpuData[Index].ApLock); - CpuMpData->CpuData[Index].CpuHealthy =3D (CpuInfoInHob[Index].Health= =3D=3D 0) ? TRUE : FALSE; + CpuMpData->CpuData[Index].CpuHealthy =3D (MpHandOff->Info[Index].Hea= lth =3D=3D 0) ? TRUE : FALSE; CpuMpData->CpuData[Index].ApFunction =3D 0; + CpuInfoInHob[Index].InitialApicId =3D MpHandOff->Info[Index].Apic= Id; + CpuInfoInHob[Index].ApTopOfStack =3D CpuMpData->Buffer + (Index = + 1) * CpuMpData->CpuApStackSize; + CpuInfoInHob[Index].ApicId =3D MpHandOff->Info[Index].Apic= Id; + CpuInfoInHob[Index].Health =3D MpHandOff->Info[Index].Heal= th; } } =20 @@ -2049,7 +2101,7 @@ MpInitLibInitialize ( // Wakeup APs to do some AP initialize sync (Microcode & MTRR) // if (CpuMpData->CpuCount > 1) { - if (OldCpuMpData !=3D NULL) { + if (MpHandOff !=3D NULL) { // // Only needs to use this flag for DXE phase to update the wake up // buffer. Wakeup buffer allocated in PEI phase is no longer valid @@ -2066,7 +2118,7 @@ MpInitLibInitialize ( CpuPause (); } =20 - if (OldCpuMpData !=3D NULL) { + if (MpHandOff !=3D NULL) { CpuMpData->InitFlag =3D ApInitDone; } =20 @@ -2793,6 +2845,28 @@ StartupThisAPWorker ( return Status; } =20 +/** + Get pointer to MP_HAND_OFF GUIDed HOB. + + @return The pointer to MP_HAND_OFF structure. +**/ +MP_HAND_OFF * +GetMpHandOffHob ( + VOID + ) +{ + EFI_HOB_GUID_TYPE *GuidHob; + MP_HAND_OFF *MpHandOff; + + MpHandOff =3D NULL; + GuidHob =3D GetFirstGuidHob (&mMpHandOffGuid); + if (GuidHob !=3D NULL) { + MpHandOff =3D (MP_HAND_OFF *)GET_GUID_HOB_DATA (GuidHob); + } + + return MpHandOff; +} + /** Get pointer to CPU MP Data structure from GUIDed HOB. =20 diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index b694c7b40f..daf9e62012 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -41,12 +41,25 @@ #include =20 #define WAKEUP_AP_SIGNAL SIGNATURE_32 ('S', 'T', 'A', 'P') +// +// To trigger the start-up signal, BSP writes the specified +// StartupSignalValue to the StartupSignalAddress of each processor. +// This address is monitored by the APs, and as soon as they receive +// the value that matches the MP_HAND_OFF_SIGNAL, they will wake up +// and switch the context from PEI to DXE phase. +// +#define MP_HAND_OFF_SIGNAL SIGNATURE_32 ('M', 'P', 'H', 'O') =20 #define CPU_INIT_MP_LIB_HOB_GUID \ { \ 0x58eb6a19, 0x3699, 0x4c68, { 0xa8, 0x36, 0xda, 0xcd, 0x8e, 0xdc, 0xad= , 0x4a } \ } =20 +#define MP_HANDOFF_GUID \ + { \ + 0x11e2bd88, 0xed38, 0x4abd, {0xa3, 0x99, 0x21, 0xf2, 0x5f, 0xd0, 0x7a,= 0x60 } \ + } + // // The MP data for switch BSP // @@ -59,6 +72,37 @@ // #define DEFAULT_MAX_MICROCODE_PATCH_NUM 8 =20 +// +// The information required to transfer from the PEI phase to the +// DXE phase is contained within the MP_HAND_OFF and PROCESSOR_HAND_OFF. +// If the SizeOfPointer (WaitLoopExecutionMode) of both phases are equal, +// and the APs is not in halt mode, +// then the APs can be awakened by triggering the start-up +// signal, rather than using INIT-SIPI-SIPI. +// To trigger the start-up signal, BSP writes the specified +// StartupSignalValue to the StartupSignalAddress of each processor. +// This address is monitored by the APs. +// +typedef struct { + UINT32 ApicId; + UINT32 Health; + UINT64 StartupSignalAddress; + UINT64 StartupProcedureAddress; +} PROCESSOR_HAND_OFF; + +typedef struct { + // + // The ProcessorIndex indicates the range of processors. If it is set to= 0, it signifies + // processors from 0 to CpuCount - 1. Multiple instances in the HOB list= describe + // processors from ProcessorIndex to ProcessorIndex + CpuCount - 1. + // + UINT32 ProcessorIndex; + UINT32 CpuCount; + UINT32 WaitLoopExecutionMode; + UINT32 StartupSignalValue; + PROCESSOR_HAND_OFF Info[]; +} MP_HAND_OFF; + // // Data structure for microcode patch information // @@ -347,6 +391,7 @@ typedef ); =20 extern EFI_GUID mCpuInitMpLibHobGuid; +extern EFI_GUID mMpHandOffGuid; =20 /** Assembly code to place AP into safe loop mode. @@ -452,6 +497,17 @@ SaveCpuMpData ( IN CPU_MP_DATA *CpuMpData ); =20 +/** + This function Get BspNumber. + + @param[in] MpHandOff Pointer to MpHandOff + @return BspNumber +**/ +UINT32 +GetBspNumber ( + IN CONST MP_HAND_OFF *MpHandOff + ); + /** Get available system memory below 1MB by specified size. =20 @@ -652,6 +708,16 @@ EnableDisableApWorker ( IN UINT32 *HealthFlag OPTIONAL ); =20 +/** + Get pointer to MP_HAND_OFF GUIDed HOB. + + @return The pointer to MP_HAND_OFF structure. +**/ +MP_HAND_OFF * +GetMpHandOffHob ( + VOID + ); + /** Get pointer to CPU MP Data structure from GUIDed HOB. =20 diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c b/UefiCpuPkg/Library/M= pInitLib/PeiMpLib.c index 013f89b197..f80e00edcf 100644 --- a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c @@ -126,7 +126,37 @@ SaveCpuMpData ( IN CPU_MP_DATA *CpuMpData ) { - UINT64 Data64; + UINT64 Data64; + UINTN Index; + CPU_INFO_IN_HOB *CpuInfoInHob; + MP_HAND_OFF *MpHandOff; + UINTN MpHandOffSize; + + // + // When APs are in a state that can be waken up by a store operation to = a memory address, + // report the MP_HAND_OFF data for DXE to use. + // + CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob; + MpHandOffSize =3D sizeof (MP_HAND_OFF) + sizeof (PROCESSOR_HAND_OFF) * C= puMpData->CpuCount; + MpHandOff =3D (MP_HAND_OFF *)BuildGuidHob (&mMpHandOffGuid, MpHandOf= fSize); + ASSERT (MpHandOff !=3D NULL); + ZeroMem (MpHandOff, MpHandOffSize); + MpHandOff->ProcessorIndex =3D 0; + + MpHandOff->CpuCount =3D CpuMpData->CpuCount; + if (CpuMpData->ApLoopMode !=3D ApInHltLoop) { + MpHandOff->StartupSignalValue =3D MP_HAND_OFF_SIGNAL; + MpHandOff->WaitLoopExecutionMode =3D sizeof (VOID *); + } + + for (Index =3D 0; Index < MpHandOff->CpuCount; Index++) { + MpHandOff->Info[Index].ApicId =3D CpuInfoInHob[Index].ApicId; + MpHandOff->Info[Index].Health =3D CpuInfoInHob[Index].Health; + if (CpuMpData->ApLoopMode !=3D ApInHltLoop) { + MpHandOff->Info[Index].StartupSignalAddress =3D (UINT64)(UINTN)Cp= uMpData->CpuData[Index].StartupApSignal; + MpHandOff->Info[Index].StartupProcedureAddress =3D (UINT64)(UINTN)&C= puMpData->CpuData[Index].ApFunction; + } + } =20 // // Build location of CPU MP DATA buffer in HOB --=20 2.36.1.windows.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 (#106325): https://edk2.groups.io/g/devel/message/106325 Mute This Topic: https://groups.io/mt/99769826/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 Thu May 16 23:01:08 2024 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+106326+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+106326+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1687703986; cv=none; d=zohomail.com; s=zohoarc; b=MOQhVzYeGt/kXxC4Y8kFf6y4RNNnpk4AUU/LTIxb8yuCukI2ih35qOdRpacsogj1ddRbaVdfe32/q/CkrxfLZlVH/OHievclvYg2/6UwGKmlDojW5J3YgHRhYdhGK22LAMT+nokd+zZsZx/HZO+7O1Vrfy0EvWsxaUw3xifzwbc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687703986; h=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=zX6kfuiiRxgEL4ngPFFZSaG8DW2XaYm+KLDzRuU04Lo=; b=WfFxGGZuT57AZM9ixJxkGyX25UEDH5Wpcoowk9oUmZ22csPYJJieAeQfzPKYql6N94wgZ8RaYqf9URugnpvtVGLlNtvUkxJbcrzDDKEQOJ2M44B9CuH9H9nuXBCC34yfp8pd1icKEIffosnvofXhoyMapSUe3LkPe9/u8mOWzFw= 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+106326+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 1687703986858525.5490475418271; Sun, 25 Jun 2023 07:39:46 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Zv0JYY1788612xe6IM0Ovk6p; Sun, 25 Jun 2023 07:39:46 -0700 X-Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web10.12565.1687703974569737167 for ; Sun, 25 Jun 2023 07:39:45 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="363624353" X-IronPort-AV: E=Sophos;i="6.01,157,1684825200"; d="scan'208";a="363624353" X-Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2023 07:39:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="785871838" X-IronPort-AV: E=Sophos;i="6.01,157,1684825200"; d="scan'208";a="785871838" X-Received: from shwdeopenlab705.ccr.corp.intel.com ([10.239.55.55]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2023 07:39:43 -0700 From: "Yuanhao Xie" To: devel@edk2.groups.io Cc: Gerd Hoffmann , Eric Dong , Ray Ni , Rahul Kumar , Tom Lendacky , Yuanhao Xie Subject: [edk2-devel] [Patch V2 4/6] UefiCpuPkg: ApWakeupFunction directly use CpuMpData. Date: Sun, 25 Jun 2023 22:39:18 +0800 Message-Id: <20230625143920.57095-5-yuanhao.xie@intel.com> In-Reply-To: <20230625143920.57095-1-yuanhao.xie@intel.com> References: <20230625143920.57095-1-yuanhao.xie@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,yuanhao.xie@intel.com X-Gm-Message-State: 5hx6ZwW4lSwtqsMn5J6hwAHHx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1687703986; bh=hWHQg8BMdD+1EoS+dVSD55wUCPfM2Xz6ylR107khSpI=; h=Cc:Date:From:Reply-To:Subject:To; b=VMoYGgKduV0w8mCix/BxNERcm0VoLq4QdXsjiXt+u1uW/4DhP1U70rBQPGF5+MzV5k3 1Ng+nt/bei97JaHTTYVvsTO2LJpiyf8EbJqhQMnunQAyLhy+oIMQqxPslXZfljICCgVLk RViWgZsWo3/SsIx83NBWj2hTADccYN4Q+gc= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1687703987101100010 Content-Type: text/plain; charset="utf-8" In the original design, once the APs finished executing their assembly code and switched to executing C code, they would enter a continuous loop within a function. In this function, they would collect CpuMpData using the MP_CPU_EXCHANGE_INFO mechanism. However, in the updated approach, CpuMpData can now be passed directly to the ApWakeUpFunction, bypassing the need for MP_CPU_EXCHANGE_INFO. This modification is made in preparation for eliminating the requirement of a second INIT-SIPI-SIPI sequence in the DXE phase. Cc: Gerd Hoffmann Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Tom Lendacky Signed-off-by: Yuanhao Xie --- UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm | 4 ++-- UefiCpuPkg/Library/MpInitLib/MpLib.c | 12 +++--------- UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 3 +-- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm b/UefiCpuPkg/Li= brary/MpInitLib/Ia32/MpFuncs.nasm index 59db4081d6..d117f09ef5 100644 --- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm +++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm @@ -197,8 +197,8 @@ CProcedureInvoke: =20 push ebx ; Push ApIndex mov eax, esi - add eax, MP_CPU_EXCHANGE_INFO_OFFSET - push eax ; push address of exchange info data buff= er + add eax, MP_CPU_EXCHANGE_INFO_FIELD (CpuMpData) + push dword [eax] ; push address of CpuMpData =20 mov edi, esi add edi, MP_CPU_EXCHANGE_INFO_FIELD (CFunction) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 1252ee9673..15b24b1805 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -710,17 +710,16 @@ PlaceAPInMwaitLoopOrRunLoop ( /** This function will be called from AP reset code if BSP uses WakeUpAP. =20 - @param[in] ExchangeInfo Pointer to the MP exchange info buffer + @param[in] CpuMpData Pointer to CPU MP Data @param[in] ApIndex Number of current executing AP **/ VOID EFIAPI ApWakeupFunction ( - IN MP_CPU_EXCHANGE_INFO *ExchangeInfo, - IN UINTN ApIndex + IN CPU_MP_DATA *CpuMpData, + IN UINTN ApIndex ) { - CPU_MP_DATA *CpuMpData; UINTN ProcessorNumber; EFI_AP_PROCEDURE Procedure; VOID *Parameter; @@ -731,11 +730,6 @@ ApWakeupFunction ( UINTN CurrentApicMode; AP_STACK_DATA *ApStackData; =20 - // - // AP finished assembly code and begin to execute C code - // - CpuMpData =3D ExchangeInfo->CpuMpData; - // // AP's local APIC settings will be lost after received INIT IPI // We need to re-initialize them at here diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm b/UefiCpuPkg/Lib= rary/MpInitLib/X64/MpFuncs.nasm index 5bcdf7726b..40e80ffab4 100644 --- a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm +++ b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm @@ -259,8 +259,7 @@ CProcedureInvoke: add rsp, 20h =20 mov edx, ebx ; edx is ApIndex - mov ecx, esi - add ecx, MP_CPU_EXCHANGE_INFO_OFFSET ; rcx is address of exchan= ge info data buffer + mov rcx, qword [esi + MP_CPU_EXCHANGE_INFO_FIELD (CpuMpData)] =20 mov edi, esi add edi, MP_CPU_EXCHANGE_INFO_FIELD (CFunction) --=20 2.36.1.windows.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 (#106326): https://edk2.groups.io/g/devel/message/106326 Mute This Topic: https://groups.io/mt/99769827/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 Thu May 16 23:01:08 2024 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+106327+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+106327+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1687703989; cv=none; d=zohomail.com; s=zohoarc; b=F5rzJWf21F2J+ej7UL1YgnfjG0D7dJZAitM/a7EY9i7cz9E6MHL2bn78fLx6gs3RNLP2glcMUZBZvXZOfGfm+bzcNfXxLhVsvUs2cRIxhUS0g0VzPF0fQQ8ml6LKrmL7m5Wd4AXAPae4UxtZXfkfTqbu2OC2fGpSn5n5tirHZiE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687703989; h=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=jkmV6+yiqntFAaHQIMsCd2dsTg0Jt7tBDw0e9Ikajfw=; b=N2n99GSC/Nw84GpQ9OCIHZYHS912NaiwE5+oWzks42w4v3AP/f+CNgOq4us60k5WZXyJXMmIlKuvOQTL/1t7/dG+Ak1cErFSt0ybCLJgFwl77jSHJACv97v/Qs2xiCHy8gNPENMuPCWGHVKMCYyAs3Aj2GPDUgjNdiLD9G+A4WI= 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+106327+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 1687703989385374.9503204524947; Sun, 25 Jun 2023 07:39:49 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 3TL9YY1788612xvg3fvR4NkS; Sun, 25 Jun 2023 07:39:49 -0700 X-Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web10.12565.1687703974569737167 for ; Sun, 25 Jun 2023 07:39:48 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="363624372" X-IronPort-AV: E=Sophos;i="6.01,157,1684825200"; d="scan'208";a="363624372" X-Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2023 07:39:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="785871853" X-IronPort-AV: E=Sophos;i="6.01,157,1684825200"; d="scan'208";a="785871853" X-Received: from shwdeopenlab705.ccr.corp.intel.com ([10.239.55.55]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2023 07:39:46 -0700 From: "Yuanhao Xie" To: devel@edk2.groups.io Cc: Gerd Hoffmann , Eric Dong , Ray Ni , Rahul Kumar , Tom Lendacky , Yuanhao Xie Subject: [edk2-devel] [Patch V2 5/6] UefiCpuPkg: Eliminate the second INIT-SIPI-SIPI sequence. Date: Sun, 25 Jun 2023 22:39:19 +0800 Message-Id: <20230625143920.57095-6-yuanhao.xie@intel.com> In-Reply-To: <20230625143920.57095-1-yuanhao.xie@intel.com> References: <20230625143920.57095-1-yuanhao.xie@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,yuanhao.xie@intel.com X-Gm-Message-State: 0WAlk5aSzXl8H47zxUWa7NWrx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1687703989; bh=kguEyhmL0H1exyW92qcu1U4BZ/wnHcigfkU1BVv3HjI=; h=Cc:Date:From:Reply-To:Subject:To; b=v7sVpo0VM/4HwwGSiY+l48Ggptujwkioneqq0Cg4G8/vQbGNCoxvjIU953Ar37ZwEC9 qsPcBB5JVn52I5B5ml8k0WRJaxn30zMEp2bj8bpqaTG/sBkifXhrpZwj3jGpTgjn6F/P+ uczDj17mqYbTl7ImMSzDZoIVzlLb8pQqcPY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1687703991104100001 Content-Type: text/plain; charset="utf-8" When both the PEI and DXE phases operate in the same execution mode(32-bit/64-bit), the BSP send a special start-up signal during the DXE phase to awaken the Application APs. To eliminate the need for the INIT-SIPI-SIPI sequence at the beginning of the DXE phase, the BSP call the SwitchApContext function to trigger the special start-up signal. By writing the specified StartupSignalValue to the designated StartupSignalAddress, the BSP wakes up the APs from mwait mode. Once the APs receive the MP_HAND_OFF_SIGNAL value, they are awakened and proceed to execute the SwitchContextPerAp procedure. They enter another while loop, transitioning their context from the PEI phase to the DXE phase. The original state transitions for an AP during the procedure are as follows: Idle ----> Ready ----> Busy ----> Idle [BSP] [AP] [AP] Instead of init-sipi-sipi sequence, we make use of a start-up signal to awaken the APs and transfer their context from PEI to DXE. Consequently, APs, rather than the BSP, to set their state to CpuStateReady. Cc: Gerd Hoffmann Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Tom Lendacky Signed-off-by: Yuanhao Xie --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 136 +++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++++++++++++++++++++++++++-- UefiCpuPkg/Library/MpInitLib/MpLib.h | 9 +++++++++ 2 files changed, 143 insertions(+), 2 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 15b24b1805..391e6f19ef 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -680,7 +680,7 @@ PlaceAPInMwaitLoopOrRunLoop ( // Place AP in MWAIT-loop // AsmMonitor ((UINTN)ApStartupSignalBuffer, 0, 0); - if (*ApStartupSignalBuffer !=3D WAKEUP_AP_SIGNAL) { + if ((*ApStartupSignalBuffer !=3D WAKEUP_AP_SIGNAL) && (*ApStartupSig= nalBuffer !=3D MP_HAND_OFF_SIGNAL)) { // // Check AP start-up signal again. // If AP start-up signal is not set, place AP into @@ -701,7 +701,7 @@ PlaceAPInMwaitLoopOrRunLoop ( // If AP start-up signal is written, AP is waken up // otherwise place AP in loop again // - if (*ApStartupSignalBuffer =3D=3D WAKEUP_AP_SIGNAL) { + if ((*ApStartupSignalBuffer =3D=3D WAKEUP_AP_SIGNAL) || (*ApStartupSig= nalBuffer =3D=3D MP_HAND_OFF_SIGNAL)) { break; } } @@ -729,6 +729,7 @@ ApWakeupFunction ( UINT64 ApTopOfStack; UINTN CurrentApicMode; AP_STACK_DATA *ApStackData; + UINT32 OriginalValue; =20 // // AP's local APIC settings will be lost after received INIT IPI @@ -769,6 +770,15 @@ ApWakeupFunction ( // Clear AP start-up signal when AP waken up // ApStartupSignalBuffer =3D CpuMpData->CpuData[ProcessorNumber].Startu= pApSignal; + OriginalValue =3D InterlockedCompareExchange32 ( + (UINT32 *)ApStartupSignalBuffer, + MP_HAND_OFF_SIGNAL, + 0 + ); + if (OriginalValue =3D=3D MP_HAND_OFF_SIGNAL) { + SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateReady); + } + InterlockedCompareExchange32 ( (UINT32 *)ApStartupSignalBuffer, WAKEUP_AP_SIGNAL, @@ -887,6 +897,32 @@ ApWakeupFunction ( } } =20 +/** + This function serves as the entry point for APs when + they are awakened by the stores in the memory address + indicated by the MP_HANDOFF_INFO structure. + + @param[in] CpuMpData Pointer to PEI CPU MP Data +**/ +VOID +EFIAPI +DxeApEntryPoint ( + CPU_MP_DATA *CpuMpData + ) +{ + UINTN ProcessorNumber; + + GetProcessorNumber (CpuMpData, &ProcessorNumber); + InterlockedIncrement ((UINT32 *)&CpuMpData->FinishedCount); + RestoreVolatileRegisters (&CpuMpData->CpuData[0].VolatileRegisters, FALS= E); + PlaceAPInMwaitLoopOrRunLoop ( + CpuMpData->ApLoopMode, + CpuMpData->CpuData[ProcessorNumber].StartupApSignal, + CpuMpData->ApTargetCState + ); + ApWakeupFunction (CpuMpData, ProcessorNumber); +} + /** Wait for AP wakeup and write AP start-up signal till AP is waken up. =20 @@ -1457,6 +1493,70 @@ CalculateTimeout ( } } =20 +/** + Switch Context for each AP. + +**/ +VOID +EFIAPI +SwitchContextPerAp ( + VOID + ) +{ + UINTN ProcessorNumber; + CPU_MP_DATA *CpuMpData; + CPU_INFO_IN_HOB *CpuInfoInHob; + + CpuMpData =3D GetCpuMpData (); + CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob; + GetProcessorNumber (CpuMpData, &ProcessorNumber); + + SwitchStack ( + (SWITCH_STACK_ENTRY_POINT)(UINTN)DxeApEntryPoint, + (VOID *)(UINTN)CpuMpData, + NULL, + (VOID *)((UINTN)CpuInfoInHob[ProcessorNumber].ApTopOfStack) + ); +} + +/** + This function is intended to be invoked by the BSP in order + to wake up the AP. The BSP accomplishes this by triggering a + start-up signal, which in turn causes any APs that are + currently in a loop on the PEI-prepared memory to awaken and + begin running the procedure called SwitchContextPerAp. + This procedure allows the AP to switch to another section of + memory and continue its loop there. + + @param[in] MpHandOff Pointer to MP hand-off data structure. +**/ +VOID +SwitchApContext ( + IN MP_HAND_OFF *MpHandOff + ) +{ + UINTN Index; + UINT32 BspNumber; + + BspNumber =3D GetBspNumber (MpHandOff); + + for (Index =3D 0; Index < MpHandOff->CpuCount; Index++) { + if (Index !=3D BspNumber) { + *(UINTN *)(UINTN)MpHandOff->Info[Index].StartupProcedureAddress =3D = (UINTN)SwitchContextPerAp; + *(UINT32 *)(UINTN)MpHandOff->Info[Index].StartupSignalAddress =3D = MpHandOff->StartupSignalValue; + } + } + + // + // Wait all APs waken up if this is not the 1st broadcast of SIPI + // + for (Index =3D 0; Index < MpHandOff->CpuCount; Index++) { + if (Index !=3D BspNumber) { + WaitApWakeup ((UINT32 *)(UINTN)(MpHandOff->Info[Index].StartupSignal= Address)); + } + } +} + /** Checks whether timeout expires. =20 @@ -2068,6 +2168,38 @@ MpInitLibInitialize ( CpuInfoInHob[Index].ApicId =3D MpHandOff->Info[Index].Apic= Id; CpuInfoInHob[Index].Health =3D MpHandOff->Info[Index].Heal= th; } + + DEBUG ((DEBUG_INFO, "MpHandOff->WaitLoopExecutionMode: %04d, sizeof (V= OID *): %04d\n", MpHandOff->WaitLoopExecutionMode, sizeof (VOID *))); + if (MpHandOff->WaitLoopExecutionMode =3D=3D sizeof (VOID *)) { + // + // In scenarios where both the PEI and DXE phases run in the same + // execution mode (32bit or 64bit), the BSP triggers + // a start-up signal during the DXE phase to wake up the APs. This c= auses any + // APs that are currently in a loop on the memory prepared during th= e PEI + // phase to awaken and run the SwitchContextPerAp procedure. This pr= ocedure + // enables the APs to switch to a different memory section and conti= nue their + // looping process there. + // + CpuMpData->FinishedCount =3D 0; + CpuMpData->InitFlag =3D ApInitDone; + SaveCpuMpData (CpuMpData); + SwitchApContext (MpHandOff); + ASSERT (CpuMpData->FinishedCount =3D=3D (CpuMpData->CpuCount - 1)); + + // + // Set Apstate as Idle, otherwise Aps cannot be waken-up again. + // If any enabled AP is not idle, return EFI_NOT_READY during waken-= up. + // + for (Index =3D 0; Index < CpuMpData->CpuCount; Index++) { + SetApState (&CpuMpData->CpuData[Index], CpuStateIdle); + } + + // + // Initialize global data for MP support + // + InitMpGlobalData (CpuMpData); + return EFI_SUCCESS; + } } =20 if (!GetMicrocodePatchInfoFromHob ( diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index daf9e62012..468d3a5925 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -521,6 +521,15 @@ GetWakeupBuffer ( IN UINTN WakeupBufferSize ); =20 +/** + Switch Context for each AP. + +**/ +VOID +SwitchApContext ( + IN MP_HAND_OFF *MpHandOff + ); + /** Get available EfiBootServicesCode memory below 4GB by specified size. =20 --=20 2.36.1.windows.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 (#106327): https://edk2.groups.io/g/devel/message/106327 Mute This Topic: https://groups.io/mt/99769828/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 Thu May 16 23:01:08 2024 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+106328+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+106328+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1687704021; cv=none; d=zohomail.com; s=zohoarc; b=AaA+tO3nleP7KfzuHlxTXpW+SU9tBx9iFKBJtmcsvwMCEIC9CbJMU8Mz2x+p0TkjKW9aBjGxLjKc+1WyxyGpY+b8I0Ae1/w0Cz7aVb/+MdDMcXVViFoyNxv0HEAl7K3UDsKq/FfdTWt51oKhZSrzr3jSvpBQktpintbI/F4v5yw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687704021; h=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=jEy0CzuDaFL6ZoOzWqTC7Q/zAz10hKX0Bz3+PMQAgH0=; b=Gv1bqAyBWUWeO1UEREStMtsmaNTuhVnnulysH5zOT0B6JF2zF4nLuwXSpAPMR8/iOlHYoWIC9emw9nCo28qYkqp+9C6EedtKB8fU6rte8DR3EvAOYrR+ifEiS4t6+dgMPJoLgpdAHCKuXBkuZ+Ht9bWeqDMpz6YyGirSxwwsRys= 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+106328+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 1687704020930522.165699012664; Sun, 25 Jun 2023 07:40:20 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ITGZYY1788612xoA4vNyOqLb; Sun, 25 Jun 2023 07:40:20 -0700 X-Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web11.12343.1687704019653525203 for ; Sun, 25 Jun 2023 07:40:20 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="363624393" X-IronPort-AV: E=Sophos;i="6.01,157,1684825200"; d="scan'208";a="363624393" X-Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2023 07:39:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="785871869" X-IronPort-AV: E=Sophos;i="6.01,157,1684825200"; d="scan'208";a="785871869" X-Received: from shwdeopenlab705.ccr.corp.intel.com ([10.239.55.55]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2023 07:39:49 -0700 From: "Yuanhao Xie" To: devel@edk2.groups.io Cc: Gerd Hoffmann , Eric Dong , Ray Ni , Rahul Kumar , Tom Lendacky , Yuanhao Xie Subject: [edk2-devel] [Patch V2 6/6] UefiCpuPkg: Enhance MpHandOff Handling. Date: Sun, 25 Jun 2023 22:39:20 +0800 Message-Id: <20230625143920.57095-7-yuanhao.xie@intel.com> In-Reply-To: <20230625143920.57095-1-yuanhao.xie@intel.com> References: <20230625143920.57095-1-yuanhao.xie@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,yuanhao.xie@intel.com X-Gm-Message-State: QIOyzCkJRF6VtTNL3oahW4aIx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1687704020; bh=HCgFoC0SU0Te4eIEVu/cCPv6Osr5KMxDkTjlk93e3B4=; h=Cc:Date:From:Reply-To:Subject:To; b=cdyL1e8uw+zL8ilDkEXVJGn6XiOVVMJT20FIXYMiA+oI+l2seG3jhvpNG7D6HeR01Qg +RuLQgnm/QImfBLPEmoVtVup29mgU8auSclO5bFFegVdpE57q8Ej99XWeD3CBC7+CmtbW AAo9hrrACt0i4VIiqdzfn/PxOe9iwd6QLHs= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1687704023167100003 Content-Type: text/plain; charset="utf-8" Enhance MpHandOff Handling for Systems with a Large Number of Processors. Cc: Gerd Hoffmann Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Tom Lendacky Signed-off-by: Yuanhao Xie --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 128 ++++++++++++++++++++++++++++= ++++++++++++++++++++++++++++++++++++++++-----------------------------------= ------------------------- UefiCpuPkg/Library/MpInitLib/MpLib.h | 22 +++++++++------------- UefiCpuPkg/Library/MpInitLib/PeiMpLib.c | 56 ++++++++++++++++++++++++++++= +++++++++++----------------- 3 files changed, 116 insertions(+), 90 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 391e6f19ef..087bf3ea92 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -1528,32 +1528,48 @@ SwitchContextPerAp ( This procedure allows the AP to switch to another section of memory and continue its loop there. =20 - @param[in] MpHandOff Pointer to MP hand-off data structure. + @param[in] BspNumber Bsp Number **/ VOID SwitchApContext ( - IN MP_HAND_OFF *MpHandOff + IN UINT32 BspNumber ) { - UINTN Index; - UINT32 BspNumber; - - BspNumber =3D GetBspNumber (MpHandOff); + UINTN Index; + UINTN LimitationOfMpHandOffHob; + UINTN NumberOfProcessorsInCurrentHob; + UINTN CpuCountInCurrentHob; + MP_HAND_OFF *MpHandOff; + BOOLEAN BspFound; + + BspFound =3D FALSE; + + MpHandOff =3D GetMpHandOffHob (); + CpuCountInCurrentHob =3D 0; + LimitationOfMpHandOffHob =3D (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE) - size= of (MP_HAND_OFF)) / sizeof (PROCESSOR_HAND_OFF); + while (CpuCountInCurrentHob < MpHandOff->CpuCount) { + // + // Get the processor number for the BSP + // + NumberOfProcessorsInCurrentHob =3D MIN (MpHandOff->CpuCount - CpuCount= InCurrentHob, LimitationOfMpHandOffHob); =20 - for (Index =3D 0; Index < MpHandOff->CpuCount; Index++) { - if (Index !=3D BspNumber) { - *(UINTN *)(UINTN)MpHandOff->Info[Index].StartupProcedureAddress =3D = (UINTN)SwitchContextPerAp; - *(UINT32 *)(UINTN)MpHandOff->Info[Index].StartupSignalAddress =3D = MpHandOff->StartupSignalValue; + for (Index =3D 0; Index < NumberOfProcessorsInCurrentHob; Index++) { + if ((Index =3D=3D BspNumber) && (BspFound =3D=3D FALSE)) { + BspFound =3D TRUE; + } else { + *(UINTN *)(UINTN)MpHandOff->Info[Index].StartupProcedureAddress = =3D (UINTN)SwitchContextPerAp; + *(UINT32 *)(UINTN)MpHandOff->Info[Index].StartupSignalAddress = =3D MpHandOff->StartupSignalValue; + WaitApWakeup ((UINT32 *)(UINTN)(MpHandOff->Info[Index].StartupSign= alAddress)); + } } - } =20 - // - // Wait all APs waken up if this is not the 1st broadcast of SIPI - // - for (Index =3D 0; Index < MpHandOff->CpuCount; Index++) { - if (Index !=3D BspNumber) { - WaitApWakeup ((UINT32 *)(UINTN)(MpHandOff->Info[Index].StartupSignal= Address)); + if (CpuCountInCurrentHob + NumberOfProcessorsInCurrentHob >=3D MpHandO= ff->CpuCount) { + break; } + + MpHandOff =3D (MP_HAND_OFF *)((UINT8 *)MpHandOff + sizeof (MP_HAND_OFF= ) + sizeof (EFI_HOB_GUID_TYPE) + sizeof (PROCESSOR_HAND_OFF) * NumberOfProc= essorsInCurrentHob); + + CpuCountInCurrentHob +=3D NumberOfProcessorsInCurrentHob; } } =20 @@ -1909,37 +1925,6 @@ CheckAllAPs ( return EFI_NOT_READY; } =20 -/** - This function Get BspNumber. - - @param[in] MpHandOff Pointer to MpHandOff - @return BspNumber -**/ -UINT32 -GetBspNumber ( - IN CONST MP_HAND_OFF *MpHandOff - ) -{ - UINT32 ApicId; - UINT32 BspNumber; - UINT32 Index; - - // - // Get the processor number for the BSP - // - BspNumber =3D MAX_UINT32; - ApicId =3D GetInitialApicId (); - for (Index =3D 0; Index < MpHandOff->CpuCount; Index++) { - if (MpHandOff->Info[Index].ApicId =3D=3D ApicId) { - BspNumber =3D Index; - } - } - - ASSERT (BspNumber !=3D MAX_UINT32); - - return BspNumber; -} - /** Get pointer to CPU MP Data structure from GUIDed HOB. =20 @@ -1994,8 +1979,13 @@ MpInitLibInitialize ( UINTN ApResetVectorSizeAbove1Mb; UINTN BackupBufferAddr; UINTN ApIdtBase; + UINTN LimitationOfMpHandOffHob; + UINTN NumberOfProcessorsInCurrentHob; + UINTN ProcessedCpuCount; + UINTN CurrentProcessorIndex; =20 MpHandOff =3D GetMpHandOffHob (); + if (MpHandOff =3D=3D NULL) { MaxLogicalProcessorNumber =3D PcdGet32 (PcdCpuMaxLogicalProcessorNumbe= r); } else { @@ -2156,17 +2146,35 @@ MpInitLibInitialize ( // from HOB // AmdSevUpdateCpuMpData (CpuMpData); - CpuMpData->CpuCount =3D MpHandOff->CpuCount; - CpuMpData->BspNumber =3D GetBspNumber (MpHandOff); - CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoI= nHob; - for (Index =3D 0; Index < CpuMpData->CpuCount; Index++) { - InitializeSpinLock (&CpuMpData->CpuData[Index].ApLock); - CpuMpData->CpuData[Index].CpuHealthy =3D (MpHandOff->Info[Index].Hea= lth =3D=3D 0) ? TRUE : FALSE; - CpuMpData->CpuData[Index].ApFunction =3D 0; - CpuInfoInHob[Index].InitialApicId =3D MpHandOff->Info[Index].Apic= Id; - CpuInfoInHob[Index].ApTopOfStack =3D CpuMpData->Buffer + (Index = + 1) * CpuMpData->CpuApStackSize; - CpuInfoInHob[Index].ApicId =3D MpHandOff->Info[Index].Apic= Id; - CpuInfoInHob[Index].Health =3D MpHandOff->Info[Index].Heal= th; + CpuMpData->CpuCount =3D MpHandOff->CpuCount; + CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoIn= Hob; + + LimitationOfMpHandOffHob =3D (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE) - si= zeof (MP_HAND_OFF)) / sizeof (PROCESSOR_HAND_OFF); + ProcessedCpuCount =3D 0; + while (ProcessedCpuCount < MpHandOff->CpuCount) { + NumberOfProcessorsInCurrentHob =3D MIN (MpHandOff->CpuCount - Proces= sedCpuCount, LimitationOfMpHandOffHob); + + for (Index =3D 0; Index < NumberOfProcessorsInCurrentHob; Index++) { + CurrentProcessorIndex =3D Index+MpHandOff->ProcessorIndex; + if (MpHandOff->Info[Index].ApicId =3D=3D GetInitialApicId ()) { + CpuMpData->BspNumber =3D (UINT32)Index; + } + + InitializeSpinLock (&CpuMpData->CpuData[CurrentProcessorIndex].ApL= ock); + CpuMpData->CpuData[CurrentProcessorIndex].CpuHealthy =3D (MpHandOf= f->Info[Index].Health =3D=3D 0) ? TRUE : FALSE; + CpuMpData->CpuData[CurrentProcessorIndex].ApFunction =3D 0; + CpuInfoInHob[CurrentProcessorIndex].InitialApicId =3D MpHandOff= ->Info[Index].ApicId; + CpuInfoInHob[CurrentProcessorIndex].ApTopOfStack =3D CpuMpData= ->Buffer + (Index + 1) * CpuMpData->CpuApStackSize; + CpuInfoInHob[CurrentProcessorIndex].ApicId =3D MpHandOff= ->Info[Index].ApicId; + CpuInfoInHob[CurrentProcessorIndex].Health =3D MpHandOff= ->Info[Index].Health; + } + + if (ProcessedCpuCount+NumberOfProcessorsInCurrentHob >=3D MpHandOff-= >CpuCount) { + break; + } + + MpHandOff =3D (MP_HAND_OFF *)((UINT8 *)MpHandOff + sizeof (= MP_HAND_OFF) + sizeof (EFI_HOB_GUID_TYPE) + sizeof (PROCESSOR_HAND_OFF) * N= umberOfProcessorsInCurrentHob); + ProcessedCpuCount +=3D NumberOfProcessorsInCurrentHob; } =20 DEBUG ((DEBUG_INFO, "MpHandOff->WaitLoopExecutionMode: %04d, sizeof (V= OID *): %04d\n", MpHandOff->WaitLoopExecutionMode, sizeof (VOID *))); @@ -2183,7 +2191,7 @@ MpInitLibInitialize ( CpuMpData->FinishedCount =3D 0; CpuMpData->InitFlag =3D ApInitDone; SaveCpuMpData (CpuMpData); - SwitchApContext (MpHandOff); + SwitchApContext (CpuMpData->BspNumber); ASSERT (CpuMpData->FinishedCount =3D=3D (CpuMpData->CpuCount - 1)); =20 // diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index 468d3a5925..6af635a80c 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -497,17 +497,6 @@ SaveCpuMpData ( IN CPU_MP_DATA *CpuMpData ); =20 -/** - This function Get BspNumber. - - @param[in] MpHandOff Pointer to MpHandOff - @return BspNumber -**/ -UINT32 -GetBspNumber ( - IN CONST MP_HAND_OFF *MpHandOff - ); - /** Get available system memory below 1MB by specified size. =20 @@ -522,12 +511,19 @@ GetWakeupBuffer ( ); =20 /** - Switch Context for each AP. + This function is intended to be invoked by the BSP in order + to wake up the AP. The BSP accomplishes this by triggering a + start-up signal, which in turn causes any APs that are + currently in a loop on the PEI-prepared memory to awaken and + begin running the procedure called SwitchContextPerAp. + This procedure allows the AP to switch to another section of + memory and continue its loop there. =20 + @param[in] BspNumber Bsp Number **/ VOID SwitchApContext ( - IN MP_HAND_OFF *MpHandOff + IN UINT32 BspNumber ); =20 /** diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c b/UefiCpuPkg/Library/M= pInitLib/PeiMpLib.c index f80e00edcf..18f83d9ed5 100644 --- a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c @@ -131,31 +131,53 @@ SaveCpuMpData ( CPU_INFO_IN_HOB *CpuInfoInHob; MP_HAND_OFF *MpHandOff; UINTN MpHandOffSize; + UINT32 LimitationOfMpHandOffHob; + UINT32 NumberOfProcessorsInCurrentHob; + UINT32 ProcessedCpuCount; + UINTN CurrentProcessorIndex; =20 // // When APs are in a state that can be waken up by a store operation to = a memory address, // report the MP_HAND_OFF data for DXE to use. // - CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob; - MpHandOffSize =3D sizeof (MP_HAND_OFF) + sizeof (PROCESSOR_HAND_OFF) * C= puMpData->CpuCount; - MpHandOff =3D (MP_HAND_OFF *)BuildGuidHob (&mMpHandOffGuid, MpHandOf= fSize); - ASSERT (MpHandOff !=3D NULL); - ZeroMem (MpHandOff, MpHandOffSize); - MpHandOff->ProcessorIndex =3D 0; - - MpHandOff->CpuCount =3D CpuMpData->CpuCount; - if (CpuMpData->ApLoopMode !=3D ApInHltLoop) { - MpHandOff->StartupSignalValue =3D MP_HAND_OFF_SIGNAL; - MpHandOff->WaitLoopExecutionMode =3D sizeof (VOID *); - } + CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob; + // + // Maximum number of processor could be saved in the HOB. + // + LimitationOfMpHandOffHob =3D (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE) - size= of (MP_HAND_OFF)) / sizeof (PROCESSOR_HAND_OFF); + ProcessedCpuCount =3D 0; + while (ProcessedCpuCount < CpuMpData->CpuCount) { + NumberOfProcessorsInCurrentHob =3D MIN ((UINT32)CpuMpData->CpuCount - = ProcessedCpuCount, LimitationOfMpHandOffHob); + MpHandOffSize =3D sizeof (MP_HAND_OFF) + sizeof (PROC= ESSOR_HAND_OFF) * NumberOfProcessorsInCurrentHob; + MpHandOff =3D (MP_HAND_OFF *)BuildGuidHob ( + &mMpHandOffGuid, + MpHandOffSize + ); + ASSERT (MpHandOff !=3D NULL); + ZeroMem (MpHandOff, MpHandOffSize); + // + // Each individual processor can be uniquely identified by + // combining the processorIndex with the mMpHandOffGuid. + // + MpHandOff->ProcessorIndex =3D ProcessedCpuCount; + MpHandOff->CpuCount =3D CpuMpData->CpuCount; =20 - for (Index =3D 0; Index < MpHandOff->CpuCount; Index++) { - MpHandOff->Info[Index].ApicId =3D CpuInfoInHob[Index].ApicId; - MpHandOff->Info[Index].Health =3D CpuInfoInHob[Index].Health; if (CpuMpData->ApLoopMode !=3D ApInHltLoop) { - MpHandOff->Info[Index].StartupSignalAddress =3D (UINT64)(UINTN)Cp= uMpData->CpuData[Index].StartupApSignal; - MpHandOff->Info[Index].StartupProcedureAddress =3D (UINT64)(UINTN)&C= puMpData->CpuData[Index].ApFunction; + MpHandOff->StartupSignalValue =3D MP_HAND_OFF_SIGNAL; + MpHandOff->WaitLoopExecutionMode =3D sizeof (VOID *); } + + for (Index =3D MpHandOff->ProcessorIndex; Index < NumberOfProcessorsIn= CurrentHob + MpHandOff->ProcessorIndex; Index++) { + CurrentProcessorIndex =3D Index-MpHandOff->P= rocessorIndex; + MpHandOff->Info[CurrentProcessorIndex].ApicId =3D CpuInfoInHob[Index= ].ApicId; + MpHandOff->Info[CurrentProcessorIndex].Health =3D CpuInfoInHob[Index= ].Health; + if (CpuMpData->ApLoopMode !=3D ApInHltLoop) { + MpHandOff->Info[CurrentProcessorIndex].StartupSignalAddress =3D= (UINT64)(UINTN)CpuMpData->CpuData[Index].StartupApSignal; + MpHandOff->Info[CurrentProcessorIndex].StartupProcedureAddress =3D= (UINT64)(UINTN)&CpuMpData->CpuData[Index].ApFunction; + } + } + + ProcessedCpuCount +=3D LimitationOfMpHandOffHob; } =20 // --=20 2.36.1.windows.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 (#106328): https://edk2.groups.io/g/devel/message/106328 Mute This Topic: https://groups.io/mt/99769836/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-