From nobody Sun Apr 28 08:10:47 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1495804418014708.866376997848; Fri, 26 May 2017 06:13:38 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C0EFB21A0292F; Fri, 26 May 2017 06:13:36 -0700 (PDT) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id B65DA21A0292F for ; Fri, 26 May 2017 06:13:33 -0700 (PDT) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP; 26 May 2017 06:13:33 -0700 Received: from jfan12-desk.ccr.corp.intel.com ([10.239.158.57]) by FMSMGA003.fm.intel.com with ESMTP; 26 May 2017 06:13:32 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,397,1491289200"; d="scan'208";a="861623804" From: Jeff Fan To: edk2-devel@lists.01.org Date: Fri, 26 May 2017 21:12:07 +0800 Message-Id: <20170526131209.23020-2-jeff.fan@intel.com> X-Mailer: git-send-email 2.9.3.windows.2 In-Reply-To: <20170526131209.23020-1-jeff.fan@intel.com> References: <20170526131209.23020-1-jeff.fan@intel.com> Subject: [edk2] [PATCH v3 1/3] UefiCpuPkg/CpuCommonFeaturesLib: Support X2APIC enable X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael D Kinney , Eric Dong MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Current X2APIC is enabled in MpInitLib (used by CpuMpPei and CpuDxe) to fol= low SDM suggestion. That means we only enable X2APIC if we found there are any initial CPU ID value >=3D 255. This patch is to provide one chance for platform to enable X2APIC even ther= e is no any initial CPU ID value >=3D 255. Cc: Michael D Kinney Cc: Eric Dong Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan Reviewed-by: Eric Dong --- .../CpuCommonFeaturesLib/CpuCommonFeatures.h | 15 +++++ .../CpuCommonFeaturesLib/CpuCommonFeaturesLib.c | 2 +- UefiCpuPkg/Library/CpuCommonFeaturesLib/X2Apic.c | 72 ++++++++++++++++++= +--- 3 files changed, 78 insertions(+), 11 deletions(-) diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h b/= UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h index aa6d112..9a7afed 100644 --- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h @@ -798,6 +798,21 @@ C1eInitialize ( ); =20 /** + Prepares for the data used by CPU feature detection and initialization. + + @param[in] NumberOfProcessors The number of CPUs in the platform. + + @return Pointer to a buffer of CPU related configuration data. + + @note This service could be called by BSP only. +**/ +VOID * +EFIAPI +X2ApicGetConfigData ( + IN UINTN NumberOfProcessors + ); + +/** Detects if X2Apci feature supported on current processor. =20 Detect if X2Apci has been already enabled. diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c= b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c index 3390aa8..793a095 100644 --- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c @@ -211,7 +211,7 @@ CpuCommonFeaturesLibConstructor ( if (IsCpuFeatureSupported (CPU_FEATURE_X2APIC)) { Status =3D RegisterCpuFeature ( "X2Apic", - NULL, + X2ApicGetConfigData, X2ApicSupport, X2ApicInitialize, CPU_FEATURE_X2APIC, diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/X2Apic.c b/UefiCpuPkg/= Library/CpuCommonFeaturesLib/X2Apic.c index 9c2ad9a..fe36368 100644 --- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/X2Apic.c +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/X2Apic.c @@ -15,6 +15,28 @@ #include "CpuCommonFeatures.h" =20 /** + Prepares for the data used by CPU feature detection and initialization. + + @param[in] NumberOfProcessors The number of CPUs in the platform. + + @return Pointer to a buffer of CPU related configuration data. + + @note This service could be called by BSP only. +**/ +VOID * +EFIAPI +X2ApicGetConfigData ( + IN UINTN NumberOfProcessors + ) +{ + BOOLEAN *ConfigData; + + ConfigData =3D AllocateZeroPool (sizeof (BOOLEAN) * NumberOfProcessors); + ASSERT (ConfigData !=3D NULL); + return ConfigData; +} + +/** Detects if X2Apci feature supported on current processor. =20 Detect if X2Apci has been already enabled. @@ -39,8 +61,17 @@ X2ApicSupport ( IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, IN VOID *ConfigData OPTIONAL ) -{ - return (GetApicMode () =3D=3D LOCAL_APIC_MODE_X2APIC); +{ =20 + BOOLEAN *X2ApicEnabled; + + ASSERT (ConfigData !=3D NULL); + X2ApicEnabled =3D (BOOLEAN *) ConfigData; + // + // *ConfigData indicates if X2APIC enabled on current processor + // + X2ApicEnabled[ProcessorNumber] =3D (GetApicMode () =3D=3D LOCAL_APIC_MOD= E_X2APIC) ? TRUE : FALSE; + + return (CpuInfo->CpuIdVersionInfoEcx.Bits.x2APIC =3D=3D 1); } =20 /** @@ -69,13 +100,34 @@ X2ApicInitialize ( IN BOOLEAN State ) { - PRE_SMM_CPU_REGISTER_TABLE_WRITE_FIELD ( - ProcessorNumber, - Msr, - MSR_IA32_APIC_BASE, - MSR_IA32_APIC_BASE_REGISTER, - Bits.EXTD, - (State) ? 1 : 0 - ); + BOOLEAN *X2ApicEnabled; + + ASSERT (ConfigData !=3D NULL); + X2ApicEnabled =3D (BOOLEAN *) ConfigData; + if (X2ApicEnabled[ProcessorNumber]) { + PRE_SMM_CPU_REGISTER_TABLE_WRITE_FIELD ( + ProcessorNumber, + Msr, + MSR_IA32_APIC_BASE, + MSR_IA32_APIC_BASE_REGISTER, + Bits.EXTD, + 1 + ); + } else { + // + // Enable X2APIC mode only if X2APIC is not enabled, + // Needn't to disabe X2APIC mode again if X2APIC is not enabled + // + if (State) { + CPU_REGISTER_TABLE_WRITE_FIELD ( + ProcessorNumber, + Msr, + MSR_IA32_APIC_BASE, + MSR_IA32_APIC_BASE_REGISTER, + Bits.EXTD, + 1 + ); + } + } return RETURN_SUCCESS; } --=20 2.9.3.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sun Apr 28 08:10:47 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1495804421645700.5449182869877; Fri, 26 May 2017 06:13:41 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id F142121AEBAA3; Fri, 26 May 2017 06:13:36 -0700 (PDT) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 2C9EF21A0292F for ; Fri, 26 May 2017 06:13:34 -0700 (PDT) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP; 26 May 2017 06:13:34 -0700 Received: from jfan12-desk.ccr.corp.intel.com ([10.239.158.57]) by FMSMGA003.fm.intel.com with ESMTP; 26 May 2017 06:13:33 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,397,1491289200"; d="scan'208";a="861623812" From: Jeff Fan To: edk2-devel@lists.01.org Date: Fri, 26 May 2017 21:12:08 +0800 Message-Id: <20170526131209.23020-3-jeff.fan@intel.com> X-Mailer: git-send-email 2.9.3.windows.2 In-Reply-To: <20170526131209.23020-1-jeff.fan@intel.com> References: <20170526131209.23020-1-jeff.fan@intel.com> Subject: [edk2] [PATCH v3 2/3] UefiCpuPkg/MpInitLib: Check APIC mode change around AP function X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael D Kinney , Eric Dong MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" If APIC ID values are changed during AP functions execution, we need to upd= ate new APIC ID values in local data structure accordingly. But if APIC mode change happened during AP function execution, we do not su= pport APIC ID value changed. Cc: Michael D Kinney Cc: Eric Dong Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan Reviewed-by: Eric Dong --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 735e099..c6f8191 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -547,6 +547,7 @@ ApWakeupFunction ( volatile UINT32 *ApStartupSignalBuffer; CPU_INFO_IN_HOB *CpuInfoInHob; UINT64 ApTopOfStack; + UINTN CurrentApicMode; =20 // // AP finished assembly code and begin to execute C code @@ -560,6 +561,7 @@ ApWakeupFunction ( ProgramVirtualWireMode (); SyncLocalApicTimerSetting (CpuMpData); =20 + CurrentApicMode =3D GetApicMode (); while (TRUE) { if (CpuMpData->InitFlag =3D=3D ApInitConfig) { // @@ -627,11 +629,23 @@ ApWakeupFunction ( ApStartupSignalBuffer =3D CpuMpData->CpuData[ProcessorNumber].= StartupApSignal; CpuInfoInHob[ProcessorNumber].ApTopOfStack =3D CpuInfoInHob[Cp= uMpData->NewBspNumber].ApTopOfStack; } else { - // - // Re-get the CPU APICID and Initial APICID - // - CpuInfoInHob[ProcessorNumber].ApicId =3D GetApicId (); - CpuInfoInHob[ProcessorNumber].InitialApicId =3D GetInitialApic= Id (); + if (CpuInfoInHob[ProcessorNumber].ApicId !=3D GetApicId () || + CpuInfoInHob[ProcessorNumber].InitialApicId !=3D GetInitia= lApicId ()) { + if (CurrentApicMode !=3D GetApicMode ()) { + // + // If APIC mode change happened during AP function executi= on, + // we do not support APIC ID value changed. + // + ASSERT (FALSE); + CpuDeadLoop (); + } else { + // + // Re-get the CPU APICID and Initial APICID if they are ch= anged + // + CpuInfoInHob[ProcessorNumber].ApicId =3D GetApicId = (); + CpuInfoInHob[ProcessorNumber].InitialApicId =3D GetInitial= ApicId (); + } + } } } SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateFinished= ); --=20 2.9.3.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sun Apr 28 08:10:47 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1495804424734524.463962050684; Fri, 26 May 2017 06:13:44 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3286221B0387D; Fri, 26 May 2017 06:13:37 -0700 (PDT) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 830392095A389 for ; Fri, 26 May 2017 06:13:35 -0700 (PDT) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP; 26 May 2017 06:13:35 -0700 Received: from jfan12-desk.ccr.corp.intel.com ([10.239.158.57]) by FMSMGA003.fm.intel.com with ESMTP; 26 May 2017 06:13:34 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,397,1491289200"; d="scan'208";a="861623822" From: Jeff Fan To: edk2-devel@lists.01.org Date: Fri, 26 May 2017 21:12:09 +0800 Message-Id: <20170526131209.23020-4-jeff.fan@intel.com> X-Mailer: git-send-email 2.9.3.windows.2 In-Reply-To: <20170526131209.23020-1-jeff.fan@intel.com> References: <20170526131209.23020-1-jeff.fan@intel.com> Subject: [edk2] [PATCH v3 3/3] UefiCpuPkg/MpInitLib: Force to enable X2APIC if CPU number > 255 X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael D Kinney , Eric Dong MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Cc: Michael D Kinney Cc: Eric Dong Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan Reviewed-by: Eric Dong --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index c6f8191..df19b43 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -451,6 +451,12 @@ CollectProcessorCount ( CpuPause (); } =20 + if (CpuMpData->CpuCount > 255) { + // + // If there are more than 255 processor found, force to enable X2APIC + // + CpuMpData->X2ApicEnable =3D TRUE; + } if (CpuMpData->X2ApicEnable) { DEBUG ((DEBUG_INFO, "Force x2APIC mode!\n")); // @@ -1412,7 +1418,7 @@ MpInitLibInitialize ( CpuInfoInHob =3D (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob; for (Index =3D 0; Index < CpuMpData->CpuCount; Index++) { InitializeSpinLock(&CpuMpData->CpuData[Index].ApLock); - if (CpuInfoInHob[Index].InitialApicId >=3D 255) { + if (CpuInfoInHob[Index].InitialApicId >=3D 255 || Index > 254) { CpuMpData->X2ApicEnable =3D TRUE; } CpuMpData->CpuData[Index].CpuHealthy =3D (CpuInfoInHob[Index].Health= =3D=3D 0)? TRUE:FALSE; --=20 2.9.3.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel