From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-SN1-obe.outbound.protection.outlook.com (mail-sn1nam01on060a.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe40::60a]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 915BD21AE3CC0 for ; Thu, 25 May 2017 07:32:49 -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=0e9CFxcw+HPzKTM4TeW5fTXMPUMm3ZHww0iS9O8cu4g=; b=5M//O0XXoMN5N2J+wZ/DXOsaZ9h+tQgMntlBlKLciON5agA1kkFn9JQXY681D1SVgF059JA/dXpAnsSlRGoroz81HVUwtamE5c83e64DXdD7h6Qj6GFrEulKlSvEyoCMMyhBSnsK18X/S32L5f9YdIkqNyWKNw7DcDoLLYKo7fs= 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; Thu, 25 May 2017 14:32:47 +0000 From: Leo Duran To: CC: Leo Duran , Jordan Justen , Jeff Fan , Liming Gao , Brijesh Singh Date: Thu, 25 May 2017 09:32:32 -0500 Message-ID: <1495722752-17445-3-git-send-email-leo.duran@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1495722752-17445-1-git-send-email-leo.duran@amd.com> References: <1495722752-17445-1-git-send-email-leo.duran@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: CO2PR05CA0073.namprd05.prod.outlook.com (10.166.88.169) To CY4PR12MB1240.namprd12.prod.outlook.com (10.168.167.15) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PR12MB1240: X-MS-Office365-Filtering-Correlation-Id: 3c7e2f8f-0a68-42bb-dffa-08d4a37aea99 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:fxjLUVqu//3m/E9PY0JQKn1HmNZsOqSJ3kCS1ZrKC9m3bC5oOPpog3Mle/TlhpQyUseQZwdhq0nN2t7UNWIV20xj9XIVnwdfRdmyQkP3E40oGK19iuyAcom0UuafdoZ1XzYd1vh8ZZ5AnYCw/dYIK24u8gCLO+8MsN2VFIsh4rmy1ZJYzluHbBnLUvnOSa3Lpb5Yvc2okjKSGIEDeafWZUe8tRfVxRt1KN88nmXhB7dojthUDHGYPgMAfN9vJIE7+Qk8Y958X3b+fopC1oHT/pOZdR++oAVFLNuuPVBYfMzq/VxksXURY2SDvzW6APfipCg9UuvY3o+CFvF3jKW3tJ6KVHOX6BO486BPaqKGQho=; 25:Ev9f6saGeguPwsSncm1hG0l7/9+HX+zA6p9XTAOkfTAdmCPYjWEpSQCUakec7SuEZTtqnHWwzmybK0X/nOOq0CM+j3NcEN9ZDRv/uKvpZTxBoI6OQEmGOToTJnj9CvhVCS2VUb3ortX/7+HJCGX1RT4FBMCkKcaxJoFCZi/8itQN10+pkXIVwqDhm2CJgIuk1A7NgpELaJe5BUJrvPCRH3YzSUoFkQv3PuPPEbfZjLHRngJsw+Gz98ak0dOB52XKUFaJ9ISb3gLlNMuZ1hs2JMEC+nwudJHbI7ED9BC7pH1Eucis5WHZckYr6JFkJkGDW2ZX0p9aXdWL1CqrHwpVQL1yv4mIYiK/d12hxgT+nyuP0r2oGFJlzNDWNoYr7yTmKAOI6WeCPklKC+qGlnSJPo+0PHlzRO3iqBr+fkqLM/gOZZ8btzgJXjdWh4+h/xxfDPKNQYvf1O1r6VFwlke5D/uMDPuq5duOqZX3Bg5hF68= X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1240; 31:/OCVOblAYMCbne63rewZ4St4EEU/DYsPsQ+fX95WQsCX1HHdac/2Kxxx4U+N72RqqAxaElhdP15X+q6FQX0mgxnLmHmnOuIuDFlUaOhxUGrx9OvKu0I+pNqCBtNRZmb53MfIkuXccnErKqI79U4bhdNSHyG9zKuGUtZvIfs0AyKQBocEC/9N0V4w9DfC8TRLh1AY7Hu4euT5/OSWDyqHmtjA6gRX6F7Zo974qKLj4xc=; 20:K+E23eHLqTRn+MqnX5Si95Q/QH1pnYDNCUu5rmTrhNda6Bdq5GpmquuCFAuHvRUAPlmIasA8fF2TzvSkc3jPrYlF1XL+PqmDDKq9HhUlxeNYvgwba8fZXAJ0aQOGc51G+28c1uCV27ikeK3spAuXDj5MugZCAvopb8CIL4t97u3VgDOmaD58M4UdJOV9W3F5RpjmyhUF7HQ0dQWfXvnBtIhw5/qAKe+ufnfM+eSUQk4aGGNT6nMBy8rGiD8l2yZmaKg+ybw+BNnD94ipxqlNMDBRobzpELjBXl2WbcgQBNjdF8ivJnkzrvJwgwXblNw1v0ox715zhMB/oXc1wrfJz64WWYlFoKukWd+9ezv9UKWK5+7pmTWCIbQIL/DXTV3MZmoQvLYgYOzRemlTsMDdEQCg5Cz9YqzCooqjYSeQiPBpBsYso2DJHHW9A18LwmimzuL39pFPz3wVGxNZZcrEz6JK0LR5q7xpuai67xR7OR5s5incTBpKc7ojQ+xRdoSP 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)(8121501046)(5005006)(93006095)(93001095)(3002001)(10201501046)(6055026)(6041248)(20161123560025)(20161123562025)(20161123558100)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(6072148); SRVR:CY4PR12MB1240; BCL:0; PCL:0; RULEID:; SRVR:CY4PR12MB1240; X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1240; 4:U3eAWHNU0HV9+BL1SjhsSLOUJclzYR4GsUQBEeScst62rmEuVmJQqVc/rpfiDrG+v+9eEQag9kmTzog2LWxfc/YHzeeVzqo0Sv7NJbmyTsevh6tc3P7+8ueOPoPrCe3HTyQ3Mzbq+wb6uYJEyIC3BWS88YRQpqPwzVK4U72jYLfCHJie99WDlZsayXcPrUtUXNKFjl6FGLphtLQ/JfECZbgVW5G+oawmLDT00/jfPvtOuTxRW9z0Jq8DlbX1nFUSxYr3wAwud6xPe7hfrKuDySMz8TVYL8wyh3h+J83To6QPwM+VGHTVPR7WL4MqcGAGFEWGLEhKpVx02pRaHaNqEJMxxxvtgx4thYd9TYNU9oktC1Uzk94InvCdvxmuMmlXGB++YRiIv7GNGYM1S3yWYIuuPEj7Noo91wTFHc/m8H7TuEvgcYIeZs4YQp4qcbiRlweEaxvC0DvCb3U1Rk3J750T8B0fW5vhPv7Iaj8sKqVKf6YdbSnmiV4+r0GXDfpKET9u8MZXkD1NgfGVVdkBbCwT4/T9j5GNGCApqHopQTi4LgRfjs1BvF20R89OtRn/O8N2AL+7sbixdFJptZo9aOXYUh2zirZqz92NA8ymakIJapV0rdbIV8RxkS6S8auZg445SZeoTJ6bKaNLDRzc+bMm8uQON4a5hgoF6YxMALvKEUK1W1ISJ6VX3zeaIDLHyHoRNFyrdeFRn1GXU7yTiP69kMwOtFpBBRBC4ierrG6VocDsCIhtVsDURlpqesItSOw1JH0IJOHDe9w+3KmZl8vQUO5HjawbMTcy5P0kdh7oWvm/ArgWrJJPLY5ydtD//oAjGVMtIqbGHzbiv0zHBvuY62XG0EAxS1HZlRsX4h+ty7bAW6EKEXtP6syC9vf1 X-Forefront-PRVS: 0318501FAE X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6029001)(6009001)(39860400002)(39850400002)(39400400002)(39450400003)(39840400002)(39410400002)(48376002)(2906002)(478600001)(50466002)(47776003)(5660300001)(36756003)(2351001)(3846002)(86362001)(53936002)(6116002)(6486002)(38730400002)(7736002)(305945005)(4326008)(33646002)(8676002)(25786009)(53416004)(50226002)(5003940100001)(6666003)(189998001)(2950100002)(42186005)(6916009)(66066001)(81166006)(76176999)(50986999)(110136004)(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:Aih7XUlzB9rohFZOlUA5bPgu9Wour8MiygGBb/m3/?= =?us-ascii?Q?Clqp42eNUNu3dBd9Pvn3dLIMZc4WpOTa2AS82a3cKEEUTjn2atyzRzGv5ov6?= =?us-ascii?Q?PloxUDv+frogdqL4m+1zRZXeP983D81oFTGbHfdXI231S740GrSFVfqR8OrD?= =?us-ascii?Q?8sgSgnu7RzguI/t4H+U7+GQs8QSk1zefoy9rBJouX09lWM/lpAz1//h4X1IG?= =?us-ascii?Q?IWqJdV71zfgctV6T5oNRBQ7WJ9KyHCfbgMMFl3EOusqQLobzaaSNWGredK5V?= =?us-ascii?Q?pG62lS9ISHCMBpcWX8R1OxXvgR5ylZwPrlB0g54yP2zK66/nJwHeJApxehWh?= =?us-ascii?Q?scMasuozRkKSlMGlqLopdsKPwPs59Bb8eckp9bBhprcO0yWr9OhBOw5pmspQ?= =?us-ascii?Q?C/9f63VPUyZfO/VIgJh0DfG+hBVbjv9cfuPBuUBpV4XZCG7oY87rRLJzaf90?= =?us-ascii?Q?fDE4JvDH1CgM13E1Yo3ui7jjXJMCIAdTIC3rDyAql9RqZBE7hdd2kuwyEZxo?= =?us-ascii?Q?2tRZmNCMJLjulzmXszxVI+QcoHqUe90A/Y/YG/Dd+KiApRaeSBRYJIQjEO6s?= =?us-ascii?Q?l04YkKS+yPZS1d2DkP/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Swluzgy2KQHcDgbwQjDHwXo9sJ6f1 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 May 2017 14:32:47.7428 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1240 Subject: [PATCH v2 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: Thu, 25 May 2017 14:32:50 -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..dfdbd8e --- 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-core processor. + // + MaxCoresPerPackage = 1; - 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..d1dcb17 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-core processor. + // + MaxCoresPerPackage = 1; - 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