From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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) 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; 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 From: Leo Duran To: CC: Leo Duran , Jordan Justen , Jeff Fan , Liming Gao , Brijesh Singh 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+6yzgAPe3XzV25pfGksOysLVsSESdFr1HQT1dCt2Gjj8/QOpXS7WqKUyLZZit7/uUKDEHlAJDzm+uq1TNNdNVH08s9G3b7iBh2O9peENVv19eR5FqYMLSvYbCRTM6bXAQjItpQF8oOSzmMCdc8TctWMNYqy8J/RHSbjxvAgA52ebxp9y3uvW7fukAiUSVjsuOBlTmgmLg8gdCuSC8KQoQQZoLJ1PkwH8ciKhxT9qzAmdDN91DhS/AXDK3cKR9PyO0xVQILF9EZU9KXLdnWU+TBAjU15KpJJxFl1fWNmyGtO83+p9iAf5oWz/AmceNRD6gDuE2avMOoAuvzNSC1Yu4Tp73AITzV/lLSintCDqN19rQK+1JxJ1ob3tQHcKDBtKYFJc8Jjr17852nXYVEzSUNh72p2WQAXSrSnFo= X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1240; 31:idIZTl31P/68p/R5PIvZMfskCczmybXZW+ZptheBCeyB9mAG0SVHZ4AtqYSQVFF2RbdFFKuvk13otke7ay7Izlw/JP2pcwxk0tBZYuk8ljkXutdrLUDXaYhu4HBV8M3xaIUUK058ycZWc+x4qhxzUAGZkyF4251xZtMA4xaZobbfclJslz1pcGY4CrbDea5mjilIEN0hx8xfu2IQxwZRzRO1JWxYQwq7p4VWMkcIuSs=; 20:ierAo2BL/6FrWj8faNmzhwF9YsoLzwTvt8F5wVVsebZG9//3sxvcuddyEEpDlZvoFc2hYrURoj0xq1JsaO3kUDfI1EowdQvZ8mcakPl/LYhkvO72MsNVeBOnTKGYRGP7gmocEKilrRPeuKIm9appMGWWYi3PEA1EioM9kJA1geS0b7XqkLCjLhhg4aIpWpJoZlcxcf94BQvo8Il6814itbRo8UmBXXckkHwHOLJZfFuue7+/ejSAl0CRPg2jptGWfKXt1XXrTVcd9cLO20QQmIm9OA4nGYydscB0GK00+c885rXjFwGxu+s908j3D8knA1iQ7zGZAi3nmirnrZp6Mxm2LRbMkOo3s4GBzLo/d3bh9216wolnKtMB+5yi4gwtnz98yyhW8tIfH1AzqkNtT1g3sLGYT3rHErLBv7/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+snZ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GlJ577Ew8odY/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: [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: , X-List-Received-Date: Wed, 24 May 2017 23:33:01 -0000 Content-Type: text/plain 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 => 100755 UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c diff --git a/UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c b/UefiCpuPkg/Library/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. 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 BSD License which accompanies this distribution. The full text of the license may be found at @@ -15,6 +17,7 @@ **/ #include +#include #include #include @@ -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; // // Check if the processor is capable of supporting more than one logical processor. @@ -1002,20 +1007,16 @@ GetProcessorLocationByApicId ( CoreBits = 0; // - // Assume three-level mapping of APIC ID: Package:Core:SMT. + // Get the max index of CPUID // - TopologyLeafSupported = 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, NULL); // // If the extended topology enumeration leaf is available, it // is the preferred mechanism for enumerating topology. // - if (MaxCpuIdIndex >= CPUID_EXTENDED_TOPOLOGY) { + if (MaxStandardCpuIdIndex >= CPUID_EXTENDED_TOPOLOGY) { AsmCpuidEx( CPUID_EXTENDED_TOPOLOGY, 0, @@ -1030,8 +1031,6 @@ GetProcessorLocationByApicId ( // supported on that processor. // if (ExtendedTopologyEbx.Uint32 != 0) { - TopologyLeafSupported = TRUE; - // // Sub-leaf index 0 (ECX= 0 as input) provides enumeration parameters to extract // the SMT sub-field of x2APIC ID. @@ -1061,26 +1060,40 @@ GetProcessorLocationByApicId ( } SubIndex++; } while (LevelType != CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_INVALID); + goto GetLocation; } } - if (!TopologyLeafSupported) { - AsmCpuid(CPUID_VERSION_INFO, NULL, &VersionInfoEbx.Uint32, NULL, NULL); - MaxLogicProcessorsPerPackage = VersionInfoEbx.Bits.MaximumAddressableIdsForLogicalProcessors; - if (MaxCpuIdIndex >= CPUID_CACHE_PARAMS) { - AsmCpuidEx(CPUID_CACHE_PARAMS, 0, &CacheParamsEax.Uint32, NULL, NULL, NULL); + AsmCpuid(CPUID_VERSION_INFO, NULL, &VersionInfoEbx.Uint32, NULL, NULL); + MaxLogicProcessorsPerPackage = VersionInfoEbx.Bits.MaximumAddressableIdsForLogicalProcessors; + + if (MaxStandardCpuIdIndex >= CPUID_CACHE_PARAMS) { + AsmCpuidEx(CPUID_CACHE_PARAMS, 0, &CacheParamsEax.Uint32, NULL, NULL, NULL); + if (CacheParamsEax.Uint32 != 0) { MaxCoresPerPackage = CacheParamsEax.Bits.MaximumAddressableIdsForLogicalProcessors + 1; + goto GetBits; } - else { - // - // Must be a single-core processor. - // - MaxCoresPerPackage = 1; + } + + if (MaxExtendedCpuIdIndex >= CPUID_AMD_PROCESSOR_TOPOLOGY) { + AsmCpuid(CPUID_EXTENDED_CPU_SIG, NULL, NULL, &AmdExtendedCpuSigEcx.Uint32, NULL); + if (AmdExtendedCpuSigEcx.Bits.TopologyExtensions != 0) { + AsmCpuid(CPUID_AMD_PROCESSOR_TOPOLOGY, NULL, &AmdProcessorTopologyEbx.Uint32, NULL, NULL); + MaxCoresPerPackage = MaxLogicProcessorsPerPackage / (AmdProcessorTopologyEbx.Bits.ThreadsPerCore + 1); + goto GetBits; } + } + + // + // Must be a single-thread-per-core processor. + // + MaxCoresPerPackage = MaxLogicProcessorsPerPackage; - ThreadBits = (UINTN)(HighBitSet32(MaxLogicProcessorsPerPackage / MaxCoresPerPackage - 1) + 1); - CoreBits = (UINTN)(HighBitSet32(MaxCoresPerPackage - 1) + 1); } +GetBits: + ThreadBits = (UINTN)(HighBitSet32(MaxLogicProcessorsPerPackage / MaxCoresPerPackage - 1) + 1); + CoreBits = (UINTN)(HighBitSet32(MaxCoresPerPackage - 1) + 1); +GetLocation: if (Thread != NULL) { *Thread = InitialApicId & ((1 << ThreadBits) - 1); } diff --git a/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c b/UefiCpuPkg/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. 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 BSD License which accompanies this distribution. The full text of the license may be found at @@ -16,6 +18,7 @@ **/ #include +#include #include #include @@ -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; // // Check if the processor is capable of supporting more than one logical processor. @@ -1097,20 +1102,16 @@ GetProcessorLocationByApicId ( CoreBits = 0; // - // Assume three-level mapping of APIC ID: Package:Core:SMT. + // Get the max index of CPUID // - TopologyLeafSupported = 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, NULL); // // If the extended topology enumeration leaf is available, it // is the preferred mechanism for enumerating topology. // - if (MaxCpuIdIndex >= CPUID_EXTENDED_TOPOLOGY) { + if (MaxStandardCpuIdIndex >= CPUID_EXTENDED_TOPOLOGY) { AsmCpuidEx( CPUID_EXTENDED_TOPOLOGY, 0, @@ -1125,8 +1126,6 @@ GetProcessorLocationByApicId ( // supported on that processor. // if (ExtendedTopologyEbx.Uint32 != 0) { - TopologyLeafSupported = TRUE; - // // Sub-leaf index 0 (ECX= 0 as input) provides enumeration parameters to extract // the SMT sub-field of x2APIC ID. @@ -1156,26 +1155,40 @@ GetProcessorLocationByApicId ( } SubIndex++; } while (LevelType != CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_INVALID); + goto GetLocation; } } - if (!TopologyLeafSupported) { - AsmCpuid(CPUID_VERSION_INFO, NULL, &VersionInfoEbx.Uint32, NULL, NULL); - MaxLogicProcessorsPerPackage = VersionInfoEbx.Bits.MaximumAddressableIdsForLogicalProcessors; - if (MaxCpuIdIndex >= CPUID_CACHE_PARAMS) { - AsmCpuidEx(CPUID_CACHE_PARAMS, 0, &CacheParamsEax.Uint32, NULL, NULL, NULL); + AsmCpuid(CPUID_VERSION_INFO, NULL, &VersionInfoEbx.Uint32, NULL, NULL); + MaxLogicProcessorsPerPackage = VersionInfoEbx.Bits.MaximumAddressableIdsForLogicalProcessors; + + if (MaxStandardCpuIdIndex >= CPUID_CACHE_PARAMS) { + AsmCpuidEx(CPUID_CACHE_PARAMS, 0, &CacheParamsEax.Uint32, NULL, NULL, NULL); + if (CacheParamsEax.Uint32 != 0) { MaxCoresPerPackage = CacheParamsEax.Bits.MaximumAddressableIdsForLogicalProcessors + 1; + goto GetBits; } - else { - // - // Must be a single-core processor. - // - MaxCoresPerPackage = 1; + } + + if (MaxExtendedCpuIdIndex >= CPUID_AMD_PROCESSOR_TOPOLOGY) { + AsmCpuid(CPUID_EXTENDED_CPU_SIG, NULL, NULL, &AmdExtendedCpuSigEcx.Uint32, NULL); + if (AmdExtendedCpuSigEcx.Bits.TopologyExtensions != 0) { + AsmCpuid(CPUID_AMD_PROCESSOR_TOPOLOGY, NULL, &AmdProcessorTopologyEbx.Uint32, NULL, NULL); + MaxCoresPerPackage = MaxLogicProcessorsPerPackage / (AmdProcessorTopologyEbx.Bits.ThreadsPerCore + 1); + goto GetBits; } + } + + // + // Must be a single-thread-per-core processor. + // + MaxCoresPerPackage = MaxLogicProcessorsPerPackage; - ThreadBits = (UINTN)(HighBitSet32(MaxLogicProcessorsPerPackage / MaxCoresPerPackage - 1) + 1); - CoreBits = (UINTN)(HighBitSet32(MaxCoresPerPackage - 1) + 1); } +GetBits: + ThreadBits = (UINTN)(HighBitSet32(MaxLogicProcessorsPerPackage / MaxCoresPerPackage - 1) + 1); + CoreBits = (UINTN)(HighBitSet32(MaxCoresPerPackage - 1) + 1); +GetLocation: if (Thread != NULL) { *Thread = InitialApicId & ((1 << ThreadBits) - 1); } -- 2.7.4