From nobody Fri May 17 09:01:50 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+106715+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+106715+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1688707750; cv=none; d=zohomail.com; s=zohoarc; b=SQTT+Ry4T2ImOmoO3ZD/TJwg88yw385dZvLHxWomv+AidHbNkPeDqclYKfDcJn3IaKpf5VgP1PaSG/WTST7vvlN85POnDIEB1Y9jESdOKxQSn+jGp1g9NEfn4SFleJvRohOGKvn/aqTuaxKGqDYlCRIWfn/8nNoy1A6kl9ZuRTk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688707750; 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=9RDOkiM2oBFQXuoQ6EGQzqKrSf64ldRQbhnrT+JS3ec=; b=EmYVAR6E7w/nln48B/DKxrMGtyloyYfqTY+H/7h6HOIBWSLbGyAf1M7kfI1N3OIgwQKKW+ryTWI0hLcvyI8Skc2aoU9T6XfGhzisD2wZZYo31vhJ4EZwH/CJAi+F9Op8MQQrfAWGa83EO1F5NJrDKJq+xp8vyhCL9e0wKp1tiC0= 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+106715+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 1688707750879139.43798349572205; Thu, 6 Jul 2023 22:29:10 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id eqooYY1788612xmkhzAogZCs; Thu, 06 Jul 2023 22:29:10 -0700 X-Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web10.6404.1688707749454802251 for ; Thu, 06 Jul 2023 22:29:10 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10763"; a="353650624" X-IronPort-AV: E=Sophos;i="6.01,187,1684825200"; d="scan'208";a="353650624" X-Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2023 22:29:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10763"; a="833232027" X-IronPort-AV: E=Sophos;i="6.01,187,1684825200"; d="scan'208";a="833232027" X-Received: from shwdeopenlab706.ccr.corp.intel.com ([10.239.55.95]) by fmsmga002.fm.intel.com with ESMTP; 06 Jul 2023 22:29:08 -0700 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Eric Dong , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH 1/4] UefiCpuPkg/MpInitLib: Separate X2APIC enabling to subfunction Date: Fri, 7 Jul 2023 13:28:58 +0800 Message-Id: <20230707052901.869-2-ray.ni@intel.com> In-Reply-To: <20230707052901.869-1-ray.ni@intel.com> References: <20230707052901.869-1-ray.ni@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,ray.ni@intel.com X-Gm-Message-State: XzYsr0si1V1qsmkR20tvHQrzx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1688707750; bh=l/cmBGDw+7bUcqZml1RvX8fMCg3tXpfOOfNtcU2ZB6A=; h=Cc:Date:From:Reply-To:Subject:To; b=rHZz/qC2do2eq27AObSTrEo6BLZQjSlmruNQoWmSEgWfzbHVIWgv2aruVYGfO6AjIZx k5I33Ldpz3QZITjBwam6pbzISDLdLK1G1ii7cGgD0Foieg+fb9K33T41tfzxO0sxfCENg ckWf+TRQcuEQmpoCrckweFIjGBSpX8PNTjU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1688707752215100004 Content-Type: text/plain; charset="utf-8" It's very confusing that auto X2 APIC enabling and APIC ID sorting are all performed inside CollectProcessorCount(). The change is to separate the X2 APIC enabling to AutoEnableX2Apic() and call that from MpInitLibInitialize(). SortApicId() is called from MpInitLibInitialize() as well. Signed-off-by: Ray Ni Cc: Eric Dong Cc: Rahul Kumar Cc: Gerd Hoffmann Acked-by: Gerd Hoffmann Tested-by: Gerd Hoffmann --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 65 ++++++++++++++++++---------- 1 file changed, 42 insertions(+), 23 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index f1f2840714..bf80455965 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -495,33 +495,20 @@ GetProcessorNumber ( } =20 /** - This function will get CPU count in the system. + Enable x2APIC mode if + 1. Number of CPU is greater than 255; or + 2. There are any logical processors reporting an Initial APIC ID of 255 = or greater. =20 @param[in] CpuMpData Pointer to PEI CPU MP Data - - @return CPU count detected **/ -UINTN -CollectProcessorCount ( +VOID +AutoEnableX2Apic ( IN CPU_MP_DATA *CpuMpData ) { + BOOLEAN X2Apic; UINTN Index; CPU_INFO_IN_HOB *CpuInfoInHob; - BOOLEAN X2Apic; - - // - // Send 1st broadcast IPI to APs to wakeup APs - // - CpuMpData->InitFlag =3D ApInitConfig; - WakeUpAP (CpuMpData, TRUE, 0, NULL, NULL, TRUE); - CpuMpData->InitFlag =3D ApInitDone; - // - // When InitFlag =3D=3D ApInitConfig, WakeUpAP () guarantees all APs are= checked in. - // FinishedCount is the number of check-in APs. - // - CpuMpData->CpuCount =3D CpuMpData->FinishedCount + 1; - ASSERT (CpuMpData->CpuCount <=3D PcdGet32 (PcdCpuMaxLogicalProcessorNumb= er)); =20 // // Enable x2APIC mode if @@ -570,12 +557,32 @@ CollectProcessorCount ( } =20 DEBUG ((DEBUG_INFO, "APIC MODE is %d\n", GetApicMode ())); +} + +/** + This function will get CPU count in the system. + + @param[in] CpuMpData Pointer to PEI CPU MP Data + + @return CPU count detected +**/ +UINTN +CollectProcessorCount ( + IN CPU_MP_DATA *CpuMpData + ) +{ // - // Sort BSP/Aps by CPU APIC ID in ascending order + // Send 1st broadcast IPI to APs to wakeup APs // - SortApicId (CpuMpData); - - DEBUG ((DEBUG_INFO, "MpInitLib: Find %d processors in system.\n", CpuMpD= ata->CpuCount)); + CpuMpData->InitFlag =3D ApInitConfig; + WakeUpAP (CpuMpData, TRUE, 0, NULL, NULL, TRUE); + CpuMpData->InitFlag =3D ApInitDone; + // + // When InitFlag =3D=3D ApInitConfig, WakeUpAP () guarantees all APs are= checked in. + // FinishedCount is the number of check-in APs. + // + CpuMpData->CpuCount =3D CpuMpData->FinishedCount + 1; + ASSERT (CpuMpData->CpuCount <=3D PcdGet32 (PcdCpuMaxLogicalProcessorNumb= er)); =20 return CpuMpData->CpuCount; } @@ -1976,6 +1983,18 @@ MpInitLibInitialize ( // Wakeup all APs and calculate the processor count in system // CollectProcessorCount (CpuMpData); + + // + // Enable X2APIC if needed. + // + AutoEnableX2Apic (CpuMpData); + + // + // Sort BSP/Aps by CPU APIC ID in ascending order + // + SortApicId (CpuMpData); + + DEBUG ((DEBUG_INFO, "MpInitLib: Find %d processors in system.\n", Cp= uMpData->CpuCount)); } } else { // --=20 2.39.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 (#106715): https://edk2.groups.io/g/devel/message/106715 Mute This Topic: https://groups.io/mt/100000875/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076= /xyzzy [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 17 09:01:50 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+106716+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+106716+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1688707752; cv=none; d=zohomail.com; s=zohoarc; b=aQgBuiaT2Vy3JJ5/n1TXRbXl9z2UpFxkGb9wZ8+UF4WeqYRPeVWd4kTE3cZuL+7tG2uNLTNhQiZBvSFaIu27pWA9ohgR+3U2ZLIYTTu8JkXrU+7vQg5G4s3m03qQ0OFAzk0srALaud1muiQhop+7n0w1Zny96jpsIIQ3d5HWVsA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688707752; 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=UbjtmLUxa+PYAIFGREmbqbJ0jOy+vU7DmoCxxZYHkXw=; b=GuZ4H7Cklh/rVZZVuyyo6pstDo5Muv4ES39Z4BpY42aqHAuF/Ka4tE14NXRcwr2k9tja34FjN7WgPkBwIoq5zump3yQKYn6jYvWpRyIvrOzMQRpznOBXSEIdZqHi2m/YbGFwsbADKCTEGe1tgML0JmK8AkSZJisQod9eACJ8kLw= 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+106716+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 1688707752177489.9482279904571; Thu, 6 Jul 2023 22:29:12 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 2sDsYY1788612xxG2vhQEGdj; Thu, 06 Jul 2023 22:29:11 -0700 X-Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web10.6404.1688707749454802251 for ; Thu, 06 Jul 2023 22:29:11 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10763"; a="353650640" X-IronPort-AV: E=Sophos;i="6.01,187,1684825200"; d="scan'208";a="353650640" X-Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2023 22:29:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10763"; a="833232032" X-IronPort-AV: E=Sophos;i="6.01,187,1684825200"; d="scan'208";a="833232032" X-Received: from shwdeopenlab706.ccr.corp.intel.com ([10.239.55.95]) by fmsmga002.fm.intel.com with ESMTP; 06 Jul 2023 22:29:09 -0700 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Eric Dong , Gerd Hoffmann Subject: [edk2-devel] [PATCH 2/4] UefiCpuPkg/MpInitLib: Sync BSP's APIC mode to APs in InitConfig path Date: Fri, 7 Jul 2023 13:28:59 +0800 Message-Id: <20230707052901.869-3-ray.ni@intel.com> In-Reply-To: <20230707052901.869-1-ray.ni@intel.com> References: <20230707052901.869-1-ray.ni@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,ray.ni@intel.com X-Gm-Message-State: nseWYeXN0zEVJr6l4uxHoMLVx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1688707751; bh=GeGUF2bgkvegBgvljD0GInBrXNANLcfOBwF4+jMJ6Qo=; h=Cc:Date:From:Reply-To:Subject:To; b=u2PXeIRYhR7XqQcTq+7TNdcLvh1enMAUJwLwCL9xd1nzQyXzG2VqXcgkmKUcEHdj394 EoFCgB+7w75BssiLqQK6T6TMhjzCq7kCI2jUpeiM6Xqz0W6iC/OklZOf0oNNZSfoLqx8t PW6YPqtlA1LsC9o06HlfNsixU5EbDE8Hf6s= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1688707754143100012 Content-Type: text/plain; charset="utf-8" The change saves the BSP's initial APIC mode and syncs to all APs in first time wakeup. It allows certain platforms to switch to X2 APIC as early as possible and also independent on CpuFeaturePei/Dxe. The platform should switch BSP to X2 APIC mode first before the CpuMpPeim runs. Signed-off-by: Ray Ni Cc: Eric Dong Cc: Gerd Hoffmann Acked-by: Gerd Hoffmann Tested-by: Gerd Hoffmann --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 11 +++++++++++ UefiCpuPkg/Library/MpInitLib/MpLib.h | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index bf80455965..2372475a04 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -694,6 +694,12 @@ ApWakeupFunction ( ApStackData =3D (AP_STACK_DATA *)((UINTN)ApTopOfStack - sizeof (AP_= STACK_DATA)); BistData =3D (UINT32)ApStackData->Bist; =20 + // + // Synchronize APIC mode with BSP in the first time AP wakeup ONLY. + // + SetApicMode (CpuMpData->InitialBspApicMode); + CurrentApicMode =3D CpuMpData->InitialBspApicMode; + // // CpuMpData->CpuData[0].VolatileRegisters is initialized based on B= SP environment, // to initialize AP in InitConfig path. @@ -1977,6 +1983,11 @@ MpInitLibInitialize ( // ProgramVirtualWireMode (); =20 + // + // Save APIC mode for AP to sync + // + CpuMpData->InitialBspApicMode =3D GetApicMode (); + if (OldCpuMpData =3D=3D NULL) { if (MaxLogicalProcessorNumber > 1) { // diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index b694c7b40f..1ede253334 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -243,6 +243,17 @@ struct _CPU_MP_DATA { // SPIN_LOCK MpLock; UINTN Buffer; + // + // InitialBspApicMode stores the initial BSP APIC mode. + // It is used to synchroneize the BSP APIC mode with APs + // in the first time APs wake up. + // Its value doesn't reflect the current APIC mode since there are + // two cases the APIC mode is changed: + // 1. MpLib explicitly switches to X2 APIC mode because number of thread= s is greater than 255, + // or there are any logical processors reporting an initial APIC ID o= f 255 or greater. + // 2. Some code switches to X2 APIC mode in all threads through MP servi= ces PPI/Protocol. + // + UINTN InitialBspApicMode; UINTN CpuApStackSize; MP_ASSEMBLY_ADDRESS_MAP AddressMap; UINTN WakeupBuffer; --=20 2.39.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 (#106716): https://edk2.groups.io/g/devel/message/106716 Mute This Topic: https://groups.io/mt/100000876/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076= /xyzzy [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 17 09:01:50 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+106717+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+106717+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1688707753; cv=none; d=zohomail.com; s=zohoarc; b=H8YIf5CUrr8mrg5BHLJ6vWo0ln64O+gH3u5BQXt0sDWmiBZ1a0D7WA0SGaT3VVzfNsDITjPJasMNblDVdGO5IRQWYu4pBIG+YJNMnJyAMIS1sGaC59AvCDHGSsBFzzVdMDGZxwg2Me173yBjKMHTznUxrZa66866+vOh7/n6Y+A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688707753; 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=gAHZLkS92TKVw4pPeg+ygsC//dGfF/rRc/q6kpAjWHQ=; b=T55+rgN8VOKvkUacffFe/Ng8QEGCCDwDnWIoGMYW/FcEWcohov5qu5MoC4shHZ7az97HHbJvQ468JBkumD3My1gZE6ohuZ2JezBgfAcmpd4eDuuWVE3nwn8HAtCaXJcE2ZsEh01oLlM46U731aGXlYZDzilPdl/rwHK/HN2yHbA= 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+106717+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 1688707753365681.286878466133; Thu, 6 Jul 2023 22:29:13 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id w75kYY1788612xWxVZDfOFY9; Thu, 06 Jul 2023 22:29:13 -0700 X-Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web10.6404.1688707749454802251 for ; Thu, 06 Jul 2023 22:29:12 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10763"; a="353650660" X-IronPort-AV: E=Sophos;i="6.01,187,1684825200"; d="scan'208";a="353650660" X-Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2023 22:29:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10763"; a="833232036" X-IronPort-AV: E=Sophos;i="6.01,187,1684825200"; d="scan'208";a="833232036" X-Received: from shwdeopenlab706.ccr.corp.intel.com ([10.239.55.95]) by fmsmga002.fm.intel.com with ESMTP; 06 Jul 2023 22:29:11 -0700 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Eric Dong , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH 3/4] UefiCpuPkg/MpInitLib: Skip X2APIC enabling when BSP in X2APIC already Date: Fri, 7 Jul 2023 13:29:00 +0800 Message-Id: <20230707052901.869-4-ray.ni@intel.com> In-Reply-To: <20230707052901.869-1-ray.ni@intel.com> References: <20230707052901.869-1-ray.ni@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,ray.ni@intel.com X-Gm-Message-State: QWhtILDhcqJfbqKB5Eb15mYJx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1688707753; bh=8pRd3cvgUbGPtKA2s5HqaFQTZsKo80o2AfMaXz6pi5k=; h=Cc:Date:From:Reply-To:Subject:To; b=nZBK3bOAeuJxCAmcBgyFS2BZsVL7YV3hhX+eoKdq1NLTX3v8IQWpnwCo7oYY5oh1/T5 1Y3WFzMShWnRAxlzl5IIUMldry99fcD6U1Oxc09IBDso+LdLXGf8Mns9fi0X6WkZ5urTh GP7eSqVdmvXeKG+mWObojQ4EXGWt0XP1VUI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1688707754065100011 Content-Type: text/plain; charset="utf-8" The BSP's APIC mode is synced to all APs in CollectProcessorCount(). So, it's safe to skip the X2 APIC enabling in AutoEnableX2Apic() which runs later when BSP's APIC mode is X2 APIC already. Signed-off-by: Ray Ni Cc: Eric Dong Cc: Rahul Kumar Cc: Gerd Hoffmann Acked-by: Gerd Hoffmann Tested-by: Gerd Hoffmann --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 2372475a04..5a8ed027be 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -1998,7 +1998,9 @@ MpInitLibInitialize ( // // Enable X2APIC if needed. // - AutoEnableX2Apic (CpuMpData); + if (CpuMpData->InitialBspApicMode =3D=3D LOCAL_APIC_MODE_XAPIC) { + AutoEnableX2Apic (CpuMpData); + } =20 // // Sort BSP/Aps by CPU APIC ID in ascending order --=20 2.39.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 (#106717): https://edk2.groups.io/g/devel/message/106717 Mute This Topic: https://groups.io/mt/100000877/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076= /xyzzy [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 17 09:01:50 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+106718+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+106718+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1688707754; cv=none; d=zohomail.com; s=zohoarc; b=iRpZrwpC8PY6Sm2SdcYJCIQAgjxHFuaJTdTyLyA0+NcGG+c9zzAzAMlWfIz6s7J8EnEo+qhIjm5rDLGDw4Gi5O7x9rlGF3xbgV19y8qiqQaN+ivZcp1HqzxDWKD3vrumii8G8bkpFBM9yUVxXaY8YHuytqpG0YGhdDib58UZ99g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688707754; 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=TcWED8wgCTB7gZGh1v7GnNytBWARJmUt01BffwG6/qA=; b=BpRPewbZUXcvHPSRdyng1SbUWVQfDGYtTwSWFm5O1isQ/m4sMXV5QFPcFDFXQfmO7oRmRJBVXJjtMDXSRvLeeSqwqR4TU0MsMcZTQ1vp1JfHHBLMuz70ZVVFiQnkaZq1PvTg44wmuxhKCDIR9xnUmWYhKMXJbEfyEJ6F//BnO/A= 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+106718+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 1688707754873926.1854605792051; Thu, 6 Jul 2023 22:29:14 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id PttLYY1788612x5gEoVyTnLL; Thu, 06 Jul 2023 22:29:14 -0700 X-Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web10.6404.1688707749454802251 for ; Thu, 06 Jul 2023 22:29:14 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10763"; a="353650684" X-IronPort-AV: E=Sophos;i="6.01,187,1684825200"; d="scan'208";a="353650684" X-Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2023 22:29:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10763"; a="833232040" X-IronPort-AV: E=Sophos;i="6.01,187,1684825200"; d="scan'208";a="833232040" X-Received: from shwdeopenlab706.ccr.corp.intel.com ([10.239.55.95]) by fmsmga002.fm.intel.com with ESMTP; 06 Jul 2023 22:29:12 -0700 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Eric Dong , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH 4/4] UefiCpuPkg/CpuFeatures: Deprecate CPU_FEATURE_X2APIC Date: Fri, 7 Jul 2023 13:29:01 +0800 Message-Id: <20230707052901.869-5-ray.ni@intel.com> In-Reply-To: <20230707052901.869-1-ray.ni@intel.com> References: <20230707052901.869-1-ray.ni@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,ray.ni@intel.com X-Gm-Message-State: 0G9Oxa0CuOnmnbjlpt6jmGfrx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1688707754; bh=1paFga3vjFc9RbZArbjJISnoLoM1+h8nxsegGNBxuTg=; h=Cc:Date:From:Reply-To:Subject:To; b=uZOIDEN7VRaxn94aWVA7QGAjivMP3qSLd9/FrNMjsUifaT7Wh2aSC7gt8czQe4chYTH GPlESP490rM84mB7lfK5Hjm7UOW1Qf2A6bCumB7qaGbau6WtW3tRzVgS9PGYfvD0kZR5F qoaq2E39yL5OgeD68EIItaaGLSFxDxbLb4I= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1688707756758100019 Content-Type: text/plain; charset="utf-8" Since MpLib supports to sync BSP's initial APIC mode to APs, platform can set BSP to X2 APIC mode before MpLib runs and expect MpLib syncs the X2 APIC mode to all APs. With such capability in MpLib, CpuCommonFeaturesLib's X2 APIC enable logic is dropped for simplificity. Such code removal also removes the confusion regarding how platform controls the X2 APIC enabling. Signed-off-by: Ray Ni Cc: Eric Dong Cc: Rahul Kumar Cc: Gerd Hoffmann Acked-by: Gerd Hoffmann Tested-by: Gerd Hoffmann --- .../Include/Library/RegisterCpuFeaturesLib.h | 2 +- .../CpuCommonFeaturesLib/CpuCommonFeatures.h | 69 +-------- .../CpuCommonFeaturesLib.c | 14 +- .../CpuCommonFeaturesLib.inf | 1 - .../Library/CpuCommonFeaturesLib/X2Apic.c | 138 ------------------ 5 files changed, 3 insertions(+), 221 deletions(-) delete mode 100644 UefiCpuPkg/Library/CpuCommonFeaturesLib/X2Apic.c diff --git a/UefiCpuPkg/Include/Library/RegisterCpuFeaturesLib.h b/UefiCpuP= kg/Include/Library/RegisterCpuFeaturesLib.h index 36459afc5e..ac5419141e 100644 --- a/UefiCpuPkg/Include/Library/RegisterCpuFeaturesLib.h +++ b/UefiCpuPkg/Include/Library/RegisterCpuFeaturesLib.h @@ -44,7 +44,7 @@ #define CPU_FEATURE_C_STATE 21 #define CPU_FEATURE_TM 22 #define CPU_FEATURE_TM2 23 -#define CPU_FEATURE_X2APIC 24 +#define CPU_FEATURE_X2APIC 24 ///< deprecated, do= not use it to enable X2 APIC. #define CPU_FEATURE_RESERVED_25 25 #define CPU_FEATURE_RESERVED_26 26 #define CPU_FEATURE_RESERVED_27 27 diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h b/= UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h index 5434a45f6a..22ecab82e8 100644 --- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h @@ -1,7 +1,7 @@ /** @file CPU Common features library header file. =20 - Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.
+ Copyright (c) 2017 - 2013, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -781,73 +781,6 @@ C1eInitialize ( IN BOOLEAN State ); =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. - - Detect if X2Apci has been already enabled. - - @param[in] ProcessorNumber The index of the CPU executing this functio= n. - @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION - structure for the CPU executing this functi= on. - @param[in] ConfigData A pointer to the configuration buffer retur= ned - by CPU_FEATURE_GET_CONFIG_DATA. NULL if - CPU_FEATURE_GET_CONFIG_DATA was not provide= d in - RegisterCpuFeature(). - - @retval TRUE X2Apci feature is supported. - @retval FALSE X2Apci feature is not supported. - - @note This service could be called by BSP/APs. -**/ -BOOLEAN -EFIAPI -X2ApicSupport ( - IN UINTN ProcessorNumber, - IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, - IN VOID *ConfigData OPTIONAL - ); - -/** - Initializes X2Apci feature to specific state. - - @param[in] ProcessorNumber The index of the CPU executing this functio= n. - @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION - structure for the CPU executing this functi= on. - @param[in] ConfigData A pointer to the configuration buffer retur= ned - by CPU_FEATURE_GET_CONFIG_DATA. NULL if - CPU_FEATURE_GET_CONFIG_DATA was not provide= d in - RegisterCpuFeature(). - @param[in] State If TRUE, then the X2Apci feature must be en= abled. - If FALSE, then the X2Apci feature must be d= isabled. - - @retval RETURN_SUCCESS X2Apci feature is initialized. - - @note This service could be called by BSP only. -**/ -RETURN_STATUS -EFIAPI -X2ApicInitialize ( - IN UINTN ProcessorNumber, - IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, - IN VOID *ConfigData OPTIONAL, - IN BOOLEAN State - ); - /** Prepares for the data used by CPU feature detection and initialization. =20 diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c= b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c index 7f0e1004b9..cc8807c19d 100644 --- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c @@ -2,7 +2,7 @@ This library registers CPU features defined in Intel(R) 64 and IA-32 Architectures Software Developer's Manual. =20 - Copyright (c) 2017 - 2020, Intel Corporation. All rights reserved.
+ Copyright (c) 2017 - 2023, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -192,18 +192,6 @@ CpuCommonFeaturesLibConstructor ( ASSERT_EFI_ERROR (Status); } =20 - if (IsCpuFeatureSupported (CPU_FEATURE_X2APIC)) { - Status =3D RegisterCpuFeature ( - "X2Apic", - X2ApicGetConfigData, - X2ApicSupport, - X2ApicInitialize, - CPU_FEATURE_X2APIC, - CPU_FEATURE_END - ); - ASSERT_EFI_ERROR (Status); - } - if (IsCpuFeatureSupported (CPU_FEATURE_PPIN)) { Status =3D RegisterCpuFeature ( "PPIN", diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.i= nf b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf index 1b823155b1..1a95e745b5 100644 --- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf @@ -40,7 +40,6 @@ MachineCheck.c MonitorMwait.c PendingBreak.c - X2Apic.c Ppin.c ProcTrace.c =20 diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/X2Apic.c b/UefiCpuPkg/= Library/CpuCommonFeaturesLib/X2Apic.c deleted file mode 100644 index 220f307e5a..0000000000 --- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/X2Apic.c +++ /dev/null @@ -1,138 +0,0 @@ -/** @file - X2Apic feature. - - Copyright (c) 2017, Intel Corporation. All rights reserved.
- SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include "CpuCommonFeatures.h" - -/** - 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. - - Detect if X2Apci has been already enabled. - - @param[in] ProcessorNumber The index of the CPU executing this functio= n. - @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION - structure for the CPU executing this functi= on. - @param[in] ConfigData A pointer to the configuration buffer retur= ned - by CPU_FEATURE_GET_CONFIG_DATA. NULL if - CPU_FEATURE_GET_CONFIG_DATA was not provide= d in - RegisterCpuFeature(). - - @retval TRUE X2Apci feature is supported. - @retval FALSE X2Apci feature is not supported. - - @note This service could be called by BSP/APs. -**/ -BOOLEAN -EFIAPI -X2ApicSupport ( - IN UINTN ProcessorNumber, - IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, - IN VOID *ConfigData OPTIONAL - ) -{ - 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); -} - -/** - Initializes X2Apci feature to specific state. - - @param[in] ProcessorNumber The index of the CPU executing this functio= n. - @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION - structure for the CPU executing this functi= on. - @param[in] ConfigData A pointer to the configuration buffer retur= ned - by CPU_FEATURE_GET_CONFIG_DATA. NULL if - CPU_FEATURE_GET_CONFIG_DATA was not provide= d in - RegisterCpuFeature(). - @param[in] State If TRUE, then the X2Apci feature must be en= abled. - If FALSE, then the X2Apci feature must be d= isabled. - - @retval RETURN_SUCCESS X2Apci feature is initialized. - - @note This service could be called by BSP only. -**/ -RETURN_STATUS -EFIAPI -X2ApicInitialize ( - IN UINTN ProcessorNumber, - IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, - IN VOID *ConfigData OPTIONAL, - IN BOOLEAN State - ) -{ - BOOLEAN *X2ApicEnabled; - - // - // The scope of the MSR_IA32_APIC_BASE is core for below processor type,= only program - // MSR_IA32_APIC_BASE for thread 0 in each core. - // - if (IS_SILVERMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayMod= el)) { - if (CpuInfo->ProcessorInfo.Location.Thread !=3D 0) { - return RETURN_SUCCESS; - } - } - - 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.39.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 (#106718): https://edk2.groups.io/g/devel/message/106718 Mute This Topic: https://groups.io/mt/100000878/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076= /xyzzy [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-