From nobody Sun Dec 29 02:04:08 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; dkim=fail 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 1495668789528388.17902430467893; Wed, 24 May 2017 16:33:09 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 05EA62095A3D4; Wed, 24 May 2017 16:33:04 -0700 (PDT) Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on061e.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe46::61e]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 5613A21969F9A for ; Wed, 24 May 2017 16:33:01 -0700 (PDT) Received: from leduran-Precision-WorkStation-T5400.amd.com (165.204.77.1) by CY4PR12MB1240.namprd12.prod.outlook.com (10.168.167.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1101.14; Wed, 24 May 2017 23:32:59 +0000 X-Original-To: edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=2tCGS+uGfdgj+CD68fXph/w2bC0uYCrzCbXs4TuNGsE=; b=N+0JPqKOH2qms26YrCUbg/x8OGdi141m7q3qkQFusYhMOf1G1N+/VKuLr4G71JKdUuYsTx8G8yI8pTk8jFRw0qy6J7kWGIRxz7xtLmBHUFioB0pZgA9iEliztf8W+phJOz6TKfRc23rWKdpYjK4VV9v6zAl4sXPJTJO862vPbz4= Authentication-Results: lists.01.org; dkim=none (message not signed) header.d=none;lists.01.org; dmarc=none action=none header.from=amd.com; From: Leo Duran To: Date: Wed, 24 May 2017 18:32:48 -0500 Message-ID: <1495668768-10416-3-git-send-email-leo.duran@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1495668768-10416-1-git-send-email-leo.duran@amd.com> References: <1495668768-10416-1-git-send-email-leo.duran@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: DM5PR15CA0024.namprd15.prod.outlook.com (10.173.207.162) To CY4PR12MB1240.namprd12.prod.outlook.com (10.168.167.15) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PR12MB1240: X-MS-Office365-Filtering-Correlation-Id: 59cda4bb-5088-4151-599d-08d4a2fd36d4 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(201703131423075)(201703031133081); SRVR:CY4PR12MB1240; X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1240; 3:SNK7VZ7PUYGZ0y8aecG9ILBN9v7CqbUquR1OzJrodpQGz8UnXGsieugQvN1WCUDBN3XAPFkt9xEQNflNJn3yNX+HXG4NwIE4hHjUvnHlXEts6YELSpblM9kTF98IZFEl7rFDVNvAEhNVfzbVtn647mTgXdbmX7HWyCFcOEOfduirgyrZs0mySChB06se1mNvIL2sEL/+zwK+Q5Lc1RnhL5J3BMFxQ9KZyqcJ8qPMOaBUYRxlGXB+nVgOafKv2WM+VFP7I3sqJMnTUnw1c76FyANZF0FQv9F7RG09dS++It1rXClL+XIVrCX4Y4JGpz9Nu6EyBh63oGoBjgCtP1G1u6OfPWlcM7/jCCWNutpE4Ho=; 25:7rA9f09+dPBZ2ezGVR922mmkZnxeKPHUjSjjOqe2h3fx6kVUh8qFI98GYHSa8CPzqK80qy+6yzgAPe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3sLGYT3rHErLBv7/AJ9AGLD6bxD+xt1qhRyJ8+vagHCuCe1DjB0Fj0YKrXn5OFBkDWvSHAoNa669Mb50ewRoylYNCvw/sCV2vCeETN34O X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(228905959029699); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93001095)(6055026)(6041248)(20161123562025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123555025)(20161123560025)(6072148); SRVR:CY4PR12MB1240; BCL:0; PCL:0; RULEID:; SRVR:CY4PR12MB1240; X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1240; 4:z6p/5ClXqDwpHw4QAmZdoTfZ7XCKzOrdyIbL9mRlOrXu4iioFzm8VxBkh6CZke//abjYUwfZODWsxdXk8/t0vMF3Zur3oVeEcKm0MRuwBfXoWab5MQaML8uWRsx84S7tyewwubda2bOZE2fR/Zy239OxGDTkpViaxt/ykIzY5gmgVb+WkeM6wGtmS69ofl1H1kvPX9tztZbOhzFBqdIwuTy+UKJQ37ujPYdQbd8MEd8TFjamgGCtnyoKJIlMNs8tzuqcHN5HKGXJPnC0iH3+5I6IoDah7LdAv/azTNIT2wttv8kYbtS8GaTFEHrzk0yDG91XHcUOhU3KhwaTVJFGO5jmXIUqVqvswZkH5liAjYZI8Ihl0L3XH7bGppEi/Dlc6NzRWLRgnRMsYRw9iymx45vaLgS+x/Q6fTzXBY6lPyvtX058TRNfm1EYa7wk8EM7HX90lEoCwo0npqhLdPTIXuRT2FhAY0PLvYxKis3LJOl7MD5YrDj2GInZ/xAoh+eKOdQn+bnKETKi2AnGXfyzgXWfDGILwJF1YvTYB7rb1vz02Z3PgrCNb922bmSDP1gL0h+8YR8B4+HEFAQ8T0w/0KxSI0ziCqWHVHOwDd0De/E2JBo5rpuUXoEKTr8uR4Ft+lC5g/ocrWncoX+WDLQCqVUw7G6dF+g2npGm/ovbgzpvQ4ZZcZfQk6L+yHkKgwz+jwHz4Jj4gUcbUCZefjzjm6SzZATj6Dd/nQJnBoMqpESaSWSs97uusI/diG4b1xkmlrqnN14QaFaU7U+Vz7NOr64GdslXRKsXJVlrT8VnqtuVS1UBHHEMmskX6xBTZsXABbLim4rE0VxnBsT3wR5zr2ZYfcO1IpKNwkfiKqvf4kITMxXHu8sdCntFTJbPSbxp X-Forefront-PRVS: 031763BCAF X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6029001)(6009001)(39860400002)(39850400002)(39400400002)(39450400003)(39840400002)(39410400002)(50466002)(48376002)(2351001)(2906002)(5660300001)(478600001)(47776003)(36756003)(3846002)(86362001)(54906002)(53936002)(6116002)(6486002)(7736002)(305945005)(38730400002)(4326008)(33646002)(8676002)(25786009)(53416004)(5003940100001)(6666003)(50226002)(189998001)(110136004)(42186005)(2950100002)(6916009)(66066001)(81166006)(76176999)(50986999)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR12MB1240; H:leduran-Precision-WorkStation-T5400.amd.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY4PR12MB1240; 23:clPrsd7XBfx6fF2MEokBpMhZuUw6boDtWlJjSXfFN?= =?us-ascii?Q?/K3pBebNf68XeNwj2Dp4EyzkV+xZb+9gjeyJREnz2fae07a2CWrndgr2bOgf?= =?us-ascii?Q?DiLDNrSDMZoRb2kfDm/RyCVSx0ToFoH/SEIuwisTpLoopnoODeWh0va/1ToG?= =?us-ascii?Q?PuiNiWIHXi2p0eqEoUjQn6pu/1zJvqr3QHaoDMfzt80wtX7v11GyOEOXnaVS?= =?us-ascii?Q?of4lEZQNPgbogf+EahtcEdmPgXKHbjU4qnZhO3TGW9EmgQariyVdUNcaiuoR?= =?us-ascii?Q?Id1cKydnOouXDTR8UVZaeiyoI4JXRIL8k5mhMfJM4vgO5qHsAa2646qdq4TA?= =?us-ascii?Q?We3OYkdXzPRgRWXXYXV8FyDrmmiILZGekBtJtC3u7T8uImAo57/Y5PMWWWgf?= =?us-ascii?Q?beba+xnEcAtqGJjuNb++QJWixB47DrzILH+mTUEM8FhSFrl6nCWxMPhA9K95?= =?us-ascii?Q?Uub/Y65PsbGfe3c5Uhp13jjrSZX41nwgwR4UlaqMYoIXImgt3t6a+7BU+X2T?= =?us-ascii?Q?N+CpBhRD7vUvd2foPKmg/drtLkQghN8jhYy0xYWzA4E4EppfoxaHTifI3pAD?= =?us-ascii?Q?GQh4nhaEvkDj8fNqU9MJRtGK7cpPw4DgMGbOppa+6//1+snZghc2KlXekZ1X?= =?us-ascii?Q?BZVmIDSp/Zdxzzr1gKyJDytzzvEjygD5zoM71/PethIWxanW8zZRTfDfsZzd?= =?us-ascii?Q?Cf5iO0soQ2K+nDepFH3uYa+tkMLGdpb/U3MtLEQLYN83jA0d+enxk7HJPQQP?= =?us-ascii?Q?BhN+d2TxaViVtIcFwCY8natwS9nHQM5eUuQmiqWoJJE3WIO7XeEE1Rha0peZ?= =?us-ascii?Q?bxSLlyByKDHGs58SME7hT1Ra3C1KwAxKyJ3hZpqSLVdfUDMYoAw402tYy/oV?= =?us-ascii?Q?wv/2Tv/qahVhmyKStv8ZMfsxrKgTWXL0AWqtAtCBgMlU8C4Ho74XFLf0JTsw?= =?us-ascii?Q?HhEF/8uHfksl6kk2QvKrel49KdXnnDbMAQINeCQhdF0bglXLgdzobcla/90O?= =?us-ascii?Q?o0PWckVzOmLhpo7Fwmu3R5c7CRDOOg56+cxcFw/+/P7tBt9E/zjfaqGJuoKn?= =?us-ascii?Q?dK7X/esnPpmWStGJFznW6jDIC3lN+lcq9nRf2klitX/hP19NQtPNjBN5TquU?= =?us-ascii?Q?AbhEyyI41c=3D?= X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1240; 6:Rj/iL4q5FwrnevfBRySvSCQfcw9D6lognjuB11vrgpDz4nL3B7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YLIYXk6WVZheL+gHqV4un2c8teUN6wFc6VfKpdkUgcUsrsB/5JP66cNpOgYz1kRSrKWibqB/McjHh0cNSStBpbu6/Gx2AaddVyfj9HV0TKePG0K7YbVIxNOwtT6zc/7BZTXg0l0zyZvrpjKy7+w==; 20:Xzc4GzkU27tOypfNxPuIthKtBV3lvqfk8CBTAJtMuyoD5DUENWbBKPdDZV5jdLz3cJn6uU/2nlAPkBI0x9fs9v9yjpCphfQXaLXqZoaFCO23GnQ/LmtXWHqLDoCxpVeklxMsHQbH8F/A1xstwk3X2C6en3KDoy3iObxxzcLGqYCDzvXWX4/SagmF8YrkENQt+bO03avIKehC7coQsNu1vQpTfFGlJ577Ew8odY/m1WfOr+q9i8whFMIUYOzHwm4u X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 May 2017 23:32:59.3562 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1240 Subject: [edk2] [PATCH 2/2] UefiCpuPkg: Modify GetProcessorLocationByApicId() to support AMD. 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: Jordan Justen , Leo Duran , Jeff Fan , Liming Gao Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Cc: Jordan Justen Cc: Jeff Fan Cc: Liming Gao Cc: Brijesh Singh Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Leo Duran --- UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c | 85 +++++++++++++-----= ---- .../BaseXApicX2ApicLib/BaseXApicX2ApicLib.c | 85 +++++++++++++-----= ---- 2 files changed, 98 insertions(+), 72 deletions(-) mode change 100644 =3D> 100755 UefiCpuPkg/Library/BaseXApicLib/BaseXApicLi= b.c diff --git a/UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c b/UefiCpuPkg/Li= brary/BaseXApicLib/BaseXApicLib.c old mode 100644 new mode 100755 index f81bbb2..da45d7a --- a/UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c +++ b/UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c @@ -4,6 +4,8 @@ This local APIC library instance supports xAPIC mode only. =20 Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2017, AMD Inc. All rights reserved.
+ This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -15,6 +17,7 @@ **/ =20 #include +#include #include #include =20 @@ -966,20 +969,22 @@ GetProcessorLocationByApicId ( OUT UINT32 *Thread OPTIONAL ) { - BOOLEAN TopologyLeafSupported; - UINTN ThreadBits; - UINTN CoreBits; - CPUID_VERSION_INFO_EBX VersionInfoEbx; - CPUID_VERSION_INFO_EDX VersionInfoEdx; - CPUID_CACHE_PARAMS_EAX CacheParamsEax; - CPUID_EXTENDED_TOPOLOGY_EAX ExtendedTopologyEax; - CPUID_EXTENDED_TOPOLOGY_EBX ExtendedTopologyEbx; - CPUID_EXTENDED_TOPOLOGY_ECX ExtendedTopologyEcx; - UINT32 MaxCpuIdIndex; - UINT32 SubIndex; - UINTN LevelType; - UINT32 MaxLogicProcessorsPerPackage; - UINT32 MaxCoresPerPackage; + CPUID_VERSION_INFO_EBX VersionInfoEbx; + CPUID_VERSION_INFO_EDX VersionInfoEdx; + CPUID_CACHE_PARAMS_EAX CacheParamsEax; + CPUID_EXTENDED_TOPOLOGY_EAX ExtendedTopologyEax; + CPUID_EXTENDED_TOPOLOGY_EBX ExtendedTopologyEbx; + CPUID_EXTENDED_TOPOLOGY_ECX ExtendedTopologyEcx; + CPUID_AMD_EXTENDED_CPU_SIG_ECX AmdExtendedCpuSigEcx; + CPUID_AMD_PROCESSOR_TOPOLOGY_EBX AmdProcessorTopologyEbx; + UINT32 MaxStandardCpuIdIndex; + UINT32 MaxExtendedCpuIdIndex; + UINT32 SubIndex; + UINTN LevelType; + UINT32 MaxLogicProcessorsPerPackage; + UINT32 MaxCoresPerPackage; + UINTN ThreadBits; + UINTN CoreBits; =20 // // Check if the processor is capable of supporting more than one logical= processor. @@ -1002,20 +1007,16 @@ GetProcessorLocationByApicId ( CoreBits =3D 0; =20 // - // Assume three-level mapping of APIC ID: Package:Core:SMT. + // Get the max index of CPUID // - TopologyLeafSupported =3D FALSE; - - // - // Get the max index of basic CPUID - // - AsmCpuid(CPUID_SIGNATURE, &MaxCpuIdIndex, NULL, NULL, NULL); + AsmCpuid(CPUID_SIGNATURE, &MaxStandardCpuIdIndex, NULL, NULL, NULL); + AsmCpuid(CPUID_EXTENDED_FUNCTION, &MaxExtendedCpuIdIndex, NULL, NULL, NU= LL); =20 // // If the extended topology enumeration leaf is available, it // is the preferred mechanism for enumerating topology. // - if (MaxCpuIdIndex >=3D CPUID_EXTENDED_TOPOLOGY) { + if (MaxStandardCpuIdIndex >=3D CPUID_EXTENDED_TOPOLOGY) { AsmCpuidEx( CPUID_EXTENDED_TOPOLOGY, 0, @@ -1030,8 +1031,6 @@ GetProcessorLocationByApicId ( // supported on that processor. // if (ExtendedTopologyEbx.Uint32 !=3D 0) { - TopologyLeafSupported =3D TRUE; - // // Sub-leaf index 0 (ECX=3D 0 as input) provides enumeration paramet= ers to extract // the SMT sub-field of x2APIC ID. @@ -1061,26 +1060,40 @@ GetProcessorLocationByApicId ( } SubIndex++; } while (LevelType !=3D CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_INVALID); + goto GetLocation; } } =20 - if (!TopologyLeafSupported) { - AsmCpuid(CPUID_VERSION_INFO, NULL, &VersionInfoEbx.Uint32, NULL, NULL); - MaxLogicProcessorsPerPackage =3D VersionInfoEbx.Bits.MaximumAddressabl= eIdsForLogicalProcessors; - if (MaxCpuIdIndex >=3D CPUID_CACHE_PARAMS) { - AsmCpuidEx(CPUID_CACHE_PARAMS, 0, &CacheParamsEax.Uint32, NULL, NULL= , NULL); + AsmCpuid(CPUID_VERSION_INFO, NULL, &VersionInfoEbx.Uint32, NULL, NULL); + MaxLogicProcessorsPerPackage =3D VersionInfoEbx.Bits.MaximumAddressableI= dsForLogicalProcessors; + + if (MaxStandardCpuIdIndex >=3D CPUID_CACHE_PARAMS) { + AsmCpuidEx(CPUID_CACHE_PARAMS, 0, &CacheParamsEax.Uint32, NULL, NULL, = NULL); + if (CacheParamsEax.Uint32 !=3D 0) { MaxCoresPerPackage =3D CacheParamsEax.Bits.MaximumAddressableIdsForL= ogicalProcessors + 1; + goto GetBits; } - else { - // - // Must be a single-core processor. - // - MaxCoresPerPackage =3D 1; + } + + if (MaxExtendedCpuIdIndex >=3D CPUID_AMD_PROCESSOR_TOPOLOGY) { + AsmCpuid(CPUID_EXTENDED_CPU_SIG, NULL, NULL, &AmdExtendedCpuSigEcx.Uin= t32, NULL); + if (AmdExtendedCpuSigEcx.Bits.TopologyExtensions !=3D 0) { + AsmCpuid(CPUID_AMD_PROCESSOR_TOPOLOGY, NULL, &AmdProcessorTopologyEb= x.Uint32, NULL, NULL); + MaxCoresPerPackage =3D MaxLogicProcessorsPerPackage / (AmdProcessorT= opologyEbx.Bits.ThreadsPerCore + 1); + goto GetBits; } + } + + // + // Must be a single-thread-per-core processor. + // + MaxCoresPerPackage =3D MaxLogicProcessorsPerPackage; =20 - ThreadBits =3D (UINTN)(HighBitSet32(MaxLogicProcessorsPerPackage / Max= CoresPerPackage - 1) + 1); - CoreBits =3D (UINTN)(HighBitSet32(MaxCoresPerPackage - 1) + 1); } +GetBits: + ThreadBits =3D (UINTN)(HighBitSet32(MaxLogicProcessorsPerPackage / MaxCo= resPerPackage - 1) + 1); + CoreBits =3D (UINTN)(HighBitSet32(MaxCoresPerPackage - 1) + 1); =20 +GetLocation: if (Thread !=3D NULL) { *Thread =3D InitialApicId & ((1 << ThreadBits) - 1); } diff --git a/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c b/U= efiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c index e690d2a..a240a44 100644 --- a/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c +++ b/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c @@ -5,6 +5,8 @@ which have xAPIC and x2APIC modes. =20 Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2017, AMD Inc. All rights reserved.
+ This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -16,6 +18,7 @@ **/ =20 #include +#include #include #include =20 @@ -1061,20 +1064,22 @@ GetProcessorLocationByApicId ( OUT UINT32 *Thread OPTIONAL ) { - BOOLEAN TopologyLeafSupported; - UINTN ThreadBits; - UINTN CoreBits; - CPUID_VERSION_INFO_EBX VersionInfoEbx; - CPUID_VERSION_INFO_EDX VersionInfoEdx; - CPUID_CACHE_PARAMS_EAX CacheParamsEax; - CPUID_EXTENDED_TOPOLOGY_EAX ExtendedTopologyEax; - CPUID_EXTENDED_TOPOLOGY_EBX ExtendedTopologyEbx; - CPUID_EXTENDED_TOPOLOGY_ECX ExtendedTopologyEcx; - UINT32 MaxCpuIdIndex; - UINT32 SubIndex; - UINTN LevelType; - UINT32 MaxLogicProcessorsPerPackage; - UINT32 MaxCoresPerPackage; + CPUID_VERSION_INFO_EBX VersionInfoEbx; + CPUID_VERSION_INFO_EDX VersionInfoEdx; + CPUID_CACHE_PARAMS_EAX CacheParamsEax; + CPUID_EXTENDED_TOPOLOGY_EAX ExtendedTopologyEax; + CPUID_EXTENDED_TOPOLOGY_EBX ExtendedTopologyEbx; + CPUID_EXTENDED_TOPOLOGY_ECX ExtendedTopologyEcx; + CPUID_AMD_EXTENDED_CPU_SIG_ECX AmdExtendedCpuSigEcx; + CPUID_AMD_PROCESSOR_TOPOLOGY_EBX AmdProcessorTopologyEbx; + UINT32 MaxStandardCpuIdIndex; + UINT32 MaxExtendedCpuIdIndex; + UINT32 SubIndex; + UINTN LevelType; + UINT32 MaxLogicProcessorsPerPackage; + UINT32 MaxCoresPerPackage; + UINTN ThreadBits; + UINTN CoreBits; =20 // // Check if the processor is capable of supporting more than one logical= processor. @@ -1097,20 +1102,16 @@ GetProcessorLocationByApicId ( CoreBits =3D 0; =20 // - // Assume three-level mapping of APIC ID: Package:Core:SMT. + // Get the max index of CPUID // - TopologyLeafSupported =3D FALSE; - - // - // Get the max index of basic CPUID - // - AsmCpuid(CPUID_SIGNATURE, &MaxCpuIdIndex, NULL, NULL, NULL); + AsmCpuid(CPUID_SIGNATURE, &MaxStandardCpuIdIndex, NULL, NULL, NULL); + AsmCpuid(CPUID_EXTENDED_FUNCTION, &MaxExtendedCpuIdIndex, NULL, NULL, NU= LL); =20 // // If the extended topology enumeration leaf is available, it // is the preferred mechanism for enumerating topology. // - if (MaxCpuIdIndex >=3D CPUID_EXTENDED_TOPOLOGY) { + if (MaxStandardCpuIdIndex >=3D CPUID_EXTENDED_TOPOLOGY) { AsmCpuidEx( CPUID_EXTENDED_TOPOLOGY, 0, @@ -1125,8 +1126,6 @@ GetProcessorLocationByApicId ( // supported on that processor. // if (ExtendedTopologyEbx.Uint32 !=3D 0) { - TopologyLeafSupported =3D TRUE; - // // Sub-leaf index 0 (ECX=3D 0 as input) provides enumeration paramet= ers to extract // the SMT sub-field of x2APIC ID. @@ -1156,26 +1155,40 @@ GetProcessorLocationByApicId ( } SubIndex++; } while (LevelType !=3D CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_INVALID); + goto GetLocation; } } =20 - if (!TopologyLeafSupported) { - AsmCpuid(CPUID_VERSION_INFO, NULL, &VersionInfoEbx.Uint32, NULL, NULL); - MaxLogicProcessorsPerPackage =3D VersionInfoEbx.Bits.MaximumAddressabl= eIdsForLogicalProcessors; - if (MaxCpuIdIndex >=3D CPUID_CACHE_PARAMS) { - AsmCpuidEx(CPUID_CACHE_PARAMS, 0, &CacheParamsEax.Uint32, NULL, NULL= , NULL); + AsmCpuid(CPUID_VERSION_INFO, NULL, &VersionInfoEbx.Uint32, NULL, NULL); + MaxLogicProcessorsPerPackage =3D VersionInfoEbx.Bits.MaximumAddressableI= dsForLogicalProcessors; + + if (MaxStandardCpuIdIndex >=3D CPUID_CACHE_PARAMS) { + AsmCpuidEx(CPUID_CACHE_PARAMS, 0, &CacheParamsEax.Uint32, NULL, NULL, = NULL); + if (CacheParamsEax.Uint32 !=3D 0) { MaxCoresPerPackage =3D CacheParamsEax.Bits.MaximumAddressableIdsForL= ogicalProcessors + 1; + goto GetBits; } - else { - // - // Must be a single-core processor. - // - MaxCoresPerPackage =3D 1; + } + + if (MaxExtendedCpuIdIndex >=3D CPUID_AMD_PROCESSOR_TOPOLOGY) { + AsmCpuid(CPUID_EXTENDED_CPU_SIG, NULL, NULL, &AmdExtendedCpuSigEcx.Uin= t32, NULL); + if (AmdExtendedCpuSigEcx.Bits.TopologyExtensions !=3D 0) { + AsmCpuid(CPUID_AMD_PROCESSOR_TOPOLOGY, NULL, &AmdProcessorTopologyEb= x.Uint32, NULL, NULL); + MaxCoresPerPackage =3D MaxLogicProcessorsPerPackage / (AmdProcessorT= opologyEbx.Bits.ThreadsPerCore + 1); + goto GetBits; } + } + + // + // Must be a single-thread-per-core processor. + // + MaxCoresPerPackage =3D MaxLogicProcessorsPerPackage; =20 - ThreadBits =3D (UINTN)(HighBitSet32(MaxLogicProcessorsPerPackage / Max= CoresPerPackage - 1) + 1); - CoreBits =3D (UINTN)(HighBitSet32(MaxCoresPerPackage - 1) + 1); } +GetBits: + ThreadBits =3D (UINTN)(HighBitSet32(MaxLogicProcessorsPerPackage / MaxCo= resPerPackage - 1) + 1); + CoreBits =3D (UINTN)(HighBitSet32(MaxCoresPerPackage - 1) + 1); =20 +GetLocation: if (Thread !=3D NULL) { *Thread =3D InitialApicId & ((1 << ThreadBits) - 1); } --=20 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel