From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0628.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe48::628]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 86A3081D10 for ; Fri, 28 Oct 2016 09:27:25 -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=zbKaHiRCwhazjGm4eM728WqZcOcdP6x/ZNtr0OXdqhI=; b=lec9JRlg1Ef8ytrORmyvCKXR0PVv+B5A9I2YwSZbftetnYaCOZVJaVlkwhbG24EtNRAXf9Ss4NYSSLS0xaQcx91cyWe91RfQd7DWhqiAyPi22R/mAoCsC6sB32J9WVJTEZyRiHdM6Jwic+zVEW+DPKW4gVjIqpQpLJKzz3edXTg= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=leo.duran@amd.com; Received: from leduran-Precision-WorkStation-T5400.amd.com (165.204.77.1) by DM5PR12MB1243.namprd12.prod.outlook.com (10.168.237.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.679.12; Fri, 28 Oct 2016 16:27:24 +0000 From: Leo Duran To: CC: , , Leo Duran Date: Fri, 28 Oct 2016 11:26:55 -0500 Message-ID: <1477672015-17583-2-git-send-email-leo.duran@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1477672015-17583-1-git-send-email-leo.duran@amd.com> References: <1477672015-17583-1-git-send-email-leo.duran@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: CY4PR13CA0023.namprd13.prod.outlook.com (10.168.161.161) To DM5PR12MB1243.namprd12.prod.outlook.com (10.168.237.22) X-MS-Office365-Filtering-Correlation-Id: 5406c4a5-d315-4071-6475-08d3ff4f4d0a X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1243; 2:BfPGskf+pm3hWJurBXw1k/M8GLEzjG4h5s0OLeyK/vzIQe4c/UqMDj6G0/Ol/wx1wwIg5awgdoaU8DxoCPuKDT8vOW5KFd58r288QmcReVXL9+83GdiUl4EBk19+WliPqbw8uraeopZqdtqT8EVmmszRWUAMAMZ/Vcor8CXKOVLHY8IYfqwsktG4lk02KQ3oUDVWf0CM8uVRJYDJZ76gmQ==; 3:wH7s1tCGjYC3u93zuML8QT7nHTb3sRV8IgpHZ6dXX4VbmJ0udE30KQSAi5SYyozZzhMvNISzXBTJQwd/+YlQV1MbQ8+vwsFtLuf21hZKZLgtRv0+WGXwpbCHkSn95RKJfEWE39DF4VDWvSGFYS7aWg==; 25:/C36Sdgc0QMTZKK6pPEWP6IEPcFuc1AgpCS0zvedxVe7/7tyoZQKKdN0LP0mFOEeuyycmU4JI7d5Up4Z3zMsxbS8i+PDaim0vsT82pJKxaNtokYRGJ3iArUBRVIxQdXHSBj9gfEqx9j+DK1O2g2dM/p8L6fr05VaOeSzYxE0dzftOL/2Hd0dH4byBXUir5/uwdyw9kRiZhz5rSnFQDONVBwGEaaOCyN3qbxf+22eZ19tBEIymOoKmEQwPfGDcUNZAGmyEGSE2crT+sFpZoQB8l5QtWGLNfTA6+11QR2X6FPiDxv/+2la1qjfQf41Wd+8p3b3LvFTLFEj3cKS9jlE1+8fYLLYG8N9krXN9yesW32/v39zibSsnCIj79d/0KwO+UoNZiby9IvuejONyeDFtsWKAPhPOM6W0kklPs57DgafJ7+xHIYPwFmpYlILDYq1 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM5PR12MB1243; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1243; 31:I1V7MGXO9sUNVBZQB0M3Fa5TfYztqbVQy+nBcVLchf7pzEAFtRPT8apxCng0op4057w7Y9JCUFX7N3fv1VAyLVwlL9h7fAw7PPmOvp3RmSu00ykvwW5D6uvwHAkEKVkLjaAV6pONZcX946vOY5PDPW02mj22Fs0A9Jkh7M20k0V5ba1ZuAT5HaTjdvajk0VWJN6GYq/dJLPXQ0pRrBpQ3P4fEp5FVGBu5CnpR+DY6kFsShp3+FCsF5HQVBmuKrX6; 20:ySyncorkeVsnBDT9en0ULgMyRy+FCZ7Wo44mmOA0v1VV5aH+WX/kJ5a03s33kd1StkR9P6RcUgWFxgrpm6ldg1S3F1G+zxaN57342nWduHAuTeM9XL6IWBCw6ryh71RZRkPh05wwSW9VfBWlqbHMC0K6tNVTvtMwGfhdN+6OlVsFQ77mpFfVEdl+8TEOsyF9wRwTIocAC1M3S8tBL1mwvMYBeXhux3yaxvE2pn7aeaSGcQ89kAvm0rcpvuQ/e74+BeOqoXCeQK/Cl325rDjXJnj2cDtX4IJ9fbq2cwY7s6+VJ8KlYZ8i9aUzcT2BFktGA3hW5REp9rqVzZc9LBRwFUNo0DckvhtTHNFptKKmKcskmQ7mve5GZbyv2mPRoEMFTsf8PM1sBTr2smMGg9Qxd+Zbj6W1HJ+f0TE8kSPDT4eAJZY36b5Hrw6RcQ4mvfgP/ZTTjdZ76i/H/AYicXPLge5yPMu1/B6ho/ZUD5vAyct5lYGVUt5ew8Z7/Uh08WT8 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026); SRVR:DM5PR12MB1243; BCL:0; PCL:0; RULEID:; SRVR:DM5PR12MB1243; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1243; 4:n7HDaF2s6uVmlKQZeQ4zrwmXCC9CDiTv9ZF0RLFgCIbMwqI7ODRNtJQyl8QO/vc2gn9oJH0GlqhzVMRtKYK+nD/A5gWBHJZt7XOyx4iA9RSMGj8BjDsmkclNevtRRVa4RrkRm/cqaeGw45b1HJaw5w3p76d+vKCFPoUNB1moIhg6wF9esnE7zzsinTQH+7ss/RBGySvM/kl6r4ezEHQOmbIm7saVvNldN5KNSQJggh7ZuJ9lxAUNzaOIO8xnG1Qx5A9nRs8+7FwGchLK3ezh5FVuBNmYIHpVUrdKN8GOYdY/xIjVwNyDrpmV/wq5/wdz/tZOLchhbOUPc0pD3QW2vGLCELO1ZNCzcmHPwn3D4tHHrMZpdl7QjeIVfIl4XAnhyII7K1jhvwzIoDto2YGacZgLO8ixfAdKx3Ip+SVEJsdfOqyftJmwI4QPHJzyFI/wdPaUgC0LzjqEn/oUE3fmxQ== X-Forefront-PRVS: 0109D382B0 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(7916002)(189002)(199003)(5003940100001)(50986999)(229853001)(2351001)(76176999)(33646002)(48376002)(106356001)(105586002)(42186005)(101416001)(50226002)(50466002)(68736007)(6116002)(110136003)(2950100002)(6916009)(5660300001)(575784001)(86362001)(2906002)(4326007)(3846002)(586003)(53416004)(92566002)(77096005)(19580395003)(6666003)(19580405001)(36756003)(189998001)(66066001)(47776003)(81156014)(81166006)(8676002)(7846002)(7736002)(97736004)(305945005)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR12MB1243; H:leduran-Precision-WorkStation-T5400.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR12MB1243; 23:cuOIFJxOm4dVxCuLUUbsoMuNkUGEdJgMu5kNd+/Lz?= =?us-ascii?Q?y1MXa9t0a6z6CAbovMUKDxjphW546rMilGDk1NSiSomcW/QRM8/h8xHOgfLU?= =?us-ascii?Q?DHmV1XOBkTCsge7OdU2UNPWF5gGM+n5dCytRrt/kfcw1uQuRxuXIvG9nj0Fq?= =?us-ascii?Q?9tbF7oOQWXi+YUkM/CtXPSRMRd66FU5SSGr67T8GbB2e2S/jngTG8YgXFrna?= =?us-ascii?Q?mhZ3IBgplDPisFhuVv19YBlayzIpU5RfgvOyfM8NZYzvd+6p4KLxcQQJECVO?= =?us-ascii?Q?kUFBSqVuTmVZGFqKpO/cuBEqKtHRSUAiCEk44R6U89IJYVXhf61yhCqfIO8t?= =?us-ascii?Q?6HPOknBRrjj3Fpv8LKcpkk3TfE4v2dBc0BW1qNfLbjKe0Sq3VyqnHMVGHSN7?= =?us-ascii?Q?3eKI45hWRzM2hFW4eppkhB81L9JYEgJk2JC0f9MmhPjawbKmnjEzboJuStvC?= =?us-ascii?Q?t+JCaxDc26aDrs10CithUHLKXZj8MW/VZeL+9QfsdKsvq9Mzb5rp4B63cu3h?= =?us-ascii?Q?idP/C8P8Fqn5FAHtX2pSVHt/zWGuYJCLPd3cxS+O4Nx8ZlH1JtMbMlUDCT7W?= =?us-ascii?Q?VRTfOuCrezRRDoCKG2bQgruaI6fevaXuZDrdji3XQ3gYoyu6o0vaeqwJUuhj?= =?us-ascii?Q?1HVi6/gpRjvnOIhpB4r/WcCq1Mf9t5VdjOYCuDbNKyaWEWGEcGkHqD4P3s2m?= =?us-ascii?Q?wrxW6MZ50oT9Cfy+Pb4VBeMiA3jg90lDLrtk4A5YMmibTxrIX1aZazJ2XCVI?= =?us-ascii?Q?gEpBsQu2X6jFT2+79gEyb6RIyWFUra3UIHNs0TnvbUlsZ/Sb9tEi+0+zRBZk?= =?us-ascii?Q?OHCt85ePrM9lbCI4iRCtw/KR+FmrFfNxXf2onihlQemez2DFk9G8E8976soS?= =?us-ascii?Q?zVTIFThIgVyFaSPRS0ipZer3lYWH93TC798h7mZGVVU2DcubZxsJY5myvczN?= =?us-ascii?Q?Q7hKq/4wxq/qBFbZckokVaROcaC773LmSmWRUIMMKD6wrursGjRLrweghkaW?= =?us-ascii?Q?ZM0IOnroYmkRvnVXIhZL0GoxUV8oYvc/GFOvCqhkVXrFG0a4MJ0r0IGWILAt?= =?us-ascii?Q?Z6ayGBmSoTkgB1xaS0rWmOe5+45Wy2/l4P4Rv5VY+lhdHRhvXgY6s3r32pvy?= =?us-ascii?Q?n6ELDWVuqZBTemccodXtxi53E5Hb9TKcXQUKCNMdTCVWr8KQwAyfGAnaUyjR?= =?us-ascii?Q?IYSKNnf+NYeeG75eo0Tn1uJoHDxf6t+H/lL?= X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1243; 6:MQjiy+vERmt61CGpPoQ4XoYzM7GAsB9nshFkJQyWNzZX+f1bFqdzpndM/y4jGqlWBLouYPzLfcnBe8G+gC2LN3TUroirteER6anQ0oY9SuUNLdABm1sw4lBKVfgo0C2HH8agefMmjQCrTO6Dx0shiHUvn2Sh+bG2/UKj4ERaJ0yILjABIQQ5pNvE3L1eSyORmtcSA+9Wf6xCwgHU79y91YgVYTcuNCH6kePLvpfgrhYMKySgrYmJ/uORXB0RDsgNI31O775Og6y4LU6qX9QhS0W2mhWlFNvdFA0mHl0naEEablmnc32l5rlzhcSLVtmbQ1HbGHrOBdBuScR+ckZX/zW9CfV6SVATeb/3855MT2g=; 5:6d2OY6iVTLXCVfH+8John7Ao8Nl2SVsoFifHDSngD65yFp9oHK7Qktt2frgy0bgit1u0RKPd3CXj97BJcO6fHEf+FnLk82+yuQgkA9uDnIHlzaeUaT9PWNC4Jg35qb1Dmx8nXwF4tJOsySvmOiXG/bvsaIjdqSkhvTeHBLP/anI=; 24:uzpBVW1F/DUMQnWYxu6BfOgFHD9i3e0Xz8dBmqSG0US+fKz16t+NfrYL34q7q6C/qfKMpFmTIFc3Dk00m4cXuQXGYQJL+7i8iN9aOeU/cyk= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1243; 7:2cRovSDjUe3fmU3nYEhXVrg2endb5P5flarK2hLgfwERsf2BJNIBIdyGAOSBRhwwXBQPvNvT96X7rpbYEcds1t/5mJ818MIRjidElJOqldSzmGXHXh9lHkRdMzCLbZpTLVtywVptkjWb3XnB9aoNnZ4s+ptj3YiNu19SNNw1rr16uZ/uQEI1szl6yw15hFDdaoNVIcNnxPxQG54VDgszz8/ZiDdVnbI7f0wCH5hWTeDO3e0SHyT35ErpzqDoloEyIzZGPSwk8kOpyM5eomLkEeOQDoiJooZPg3vrrLXDm7iVpZMR/NeVSOjnBAzj45pupebqOWIU8TkiO/GV8z29yYItINeeXgASLc6CU17bZDY=; 20:1bGkNxWYM5oI6HufVrWGjTJYuGdGf+JGmaP7Vowa2KW87rAgVCUmqE+N1Fr6ovbao7Hy6XI2bMQSSkhaK6ojyFUTbOMEBP7NXmOsa0GlpuQGvMd0gW29lMUVMlJav5u8cAgBzy6D4o47GPvM7Jml8IZMiyjMuhXDKj9LKWhaqZltcEeuaBwzFTgqZE/JIEBOt+ThZaTxn7t8E5nQ64zOXV0DhbxomfZSuhpdyvquzk5MzqEiAA1dYUIjlh3gqYeY X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2016 16:27:24.6215 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1243 Subject: [PATCH] UefiCpuPkg: Move GetProcessorLocation() to LocalApicLib library X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Oct 2016 16:27:25 -0000 Content-Type: text/plain 1) Remove SmmGetProcessorLocation() from PiSmmCpuDxeSmm driver. 2) Remove ExtractProcessorLocation() from MpInitLib library. 3) Add GetProcessorLocation() to BaseXApicLib and BaseXApicX2ApicLib. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Leo Duran --- UefiCpuPkg/Include/Library/LocalApicLib.h | 18 +++ UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c | 130 +++++++++++++++++++++ .../BaseXApicX2ApicLib/BaseXApicX2ApicLib.c | 130 +++++++++++++++++++++ UefiCpuPkg/Library/MpInitLib/MpLib.c | 128 +------------------- UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c | 121 +------------------ 5 files changed, 280 insertions(+), 247 deletions(-) mode change 100644 => 100755 UefiCpuPkg/Include/Library/LocalApicLib.h mode change 100644 => 100755 UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c mode change 100644 => 100755 UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c mode change 100644 => 100755 UefiCpuPkg/Library/MpInitLib/MpLib.c mode change 100644 => 100755 UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c diff --git a/UefiCpuPkg/Include/Library/LocalApicLib.h b/UefiCpuPkg/Include/Library/LocalApicLib.h old mode 100644 new mode 100755 index cd4e613..1d5599a --- a/UefiCpuPkg/Include/Library/LocalApicLib.h +++ b/UefiCpuPkg/Include/Library/LocalApicLib.h @@ -21,6 +21,9 @@ #define LOCAL_APIC_MODE_XAPIC 0x1 ///< xAPIC mode. #define LOCAL_APIC_MODE_X2APIC 0x2 ///< x2APIC mode. +#include +#include + /** Retrieve the base address of local APIC. @@ -410,6 +413,21 @@ GetApicMsiValue ( IN BOOLEAN LevelTriggered, IN BOOLEAN AssertionLevel ); + +/** +Get Package ID/Core ID/Thread ID of a processor. + +The algorithm assumes the target system has symmetry across physical package boundaries +with respect to the number of logical processors per package, number of cores per package. + +@param InitialApicId Must be the initial APIC ID of the target logical processor. +@param Location Returns the processor location information. +**/ +VOID +GetProcessorLocation( + IN UINT32 InitialApicId, + OUT EFI_CPU_PHYSICAL_LOCATION *Location +); #endif diff --git a/UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c b/UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c old mode 100644 new mode 100755 index 8d0fb02..2995ac3 --- a/UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c +++ b/UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c @@ -941,3 +941,133 @@ GetApicMsiValue ( } return MsiData.Uint64; } + +/** +Get Package ID/Core ID/Thread ID of a processor. + +The algorithm assumes the target system has symmetry across physical package boundaries +with respect to the number of logical processors per package, number of cores per package. + +@param InitialApicId Must be the initial APIC ID of the target logical processor. +@param Location Returns the processor location information. +**/ +VOID +GetProcessorLocation( +IN UINT32 InitialApicId, +OUT EFI_CPU_PHYSICAL_LOCATION *Location +) +{ + 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; + + // + // Check if the processor is capable of supporting more than one logical processor. + // + AsmCpuid(CPUID_VERSION_INFO, NULL, NULL, NULL, &VersionInfoEdx.Uint32); + if (VersionInfoEdx.Bits.HTT == 0) { + Location->Thread = 0; + Location->Core = 0; + Location->Package = 0; + return; + } + + ThreadBits = 0; + CoreBits = 0; + + // + // Assume three-level mapping of APIC ID: Package:Core:SMT. + // + + TopologyLeafSupported = FALSE; + // + // Get the max index of basic CPUID + // + AsmCpuid(CPUID_SIGNATURE, &MaxCpuIdIndex, NULL, NULL, NULL); + + // + // If the extended topology enumeration leaf is available, it + // is the preferred mechanism for enumerating topology. + // + if (MaxCpuIdIndex >= CPUID_EXTENDED_TOPOLOGY) { + AsmCpuidEx( + CPUID_EXTENDED_TOPOLOGY, + 0, + &ExtendedTopologyEax.Uint32, + &ExtendedTopologyEbx.Uint32, + &ExtendedTopologyEcx.Uint32, + NULL + ); + // + // If CPUID.(EAX=0BH, ECX=0H):EBX returns zero and maximum input value for + // basic CPUID information is greater than 0BH, then CPUID.0BH leaf is not + // 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. + // + LevelType = ExtendedTopologyEcx.Bits.LevelType; + ASSERT(LevelType == CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_SMT); + ThreadBits = ExtendedTopologyEax.Bits.ApicIdShift; + + // + // Software must not assume any "level type" encoding + // value to be related to any sub-leaf index, except sub-leaf 0. + // + SubIndex = 1; + do { + AsmCpuidEx( + CPUID_EXTENDED_TOPOLOGY, + SubIndex, + &ExtendedTopologyEax.Uint32, + NULL, + &ExtendedTopologyEcx.Uint32, + NULL + ); + LevelType = ExtendedTopologyEcx.Bits.LevelType; + if (LevelType == CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_CORE) { + CoreBits = ExtendedTopologyEax.Bits.ApicIdShift - ThreadBits; + break; + } + SubIndex++; + } while (LevelType != CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_INVALID); + } + } + + 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); + MaxCoresPerPackage = CacheParamsEax.Bits.MaximumAddressableIdsForLogicalProcessors + 1; + } + else { + // + // Must be a single-core processor. + // + MaxCoresPerPackage = 1; + } + + ThreadBits = (UINTN)(HighBitSet32(MaxLogicProcessorsPerPackage / MaxCoresPerPackage - 1) + 1); + CoreBits = (UINTN)(HighBitSet32(MaxCoresPerPackage - 1) + 1); + } + + Location->Thread = InitialApicId & ((1 << ThreadBits) - 1); + Location->Core = (InitialApicId >> ThreadBits) & ((1 << CoreBits) - 1); + Location->Package = (InitialApicId >> (ThreadBits + CoreBits)); +} diff --git a/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c b/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c old mode 100644 new mode 100755 index 4c42696..60d32d2 --- a/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c +++ b/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c @@ -1036,3 +1036,133 @@ GetApicMsiValue ( } return MsiData.Uint64; } + +/** +Get Package ID/Core ID/Thread ID of a processor. + +The algorithm assumes the target system has symmetry across physical package boundaries +with respect to the number of logical processors per package, number of cores per package. + +@param InitialApicId Must be the initial APIC ID of the target logical processor. +@param Location Returns the processor location information. +**/ +VOID +GetProcessorLocation( +IN UINT32 InitialApicId, +OUT EFI_CPU_PHYSICAL_LOCATION *Location +) +{ + 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; + + // + // Check if the processor is capable of supporting more than one logical processor. + // + AsmCpuid(CPUID_VERSION_INFO, NULL, NULL, NULL, &VersionInfoEdx.Uint32); + if (VersionInfoEdx.Bits.HTT == 0) { + Location->Thread = 0; + Location->Core = 0; + Location->Package = 0; + return; + } + + ThreadBits = 0; + CoreBits = 0; + + // + // Assume three-level mapping of APIC ID: Package:Core:SMT. + // + + TopologyLeafSupported = FALSE; + // + // Get the max index of basic CPUID + // + AsmCpuid(CPUID_SIGNATURE, &MaxCpuIdIndex, NULL, NULL, NULL); + + // + // If the extended topology enumeration leaf is available, it + // is the preferred mechanism for enumerating topology. + // + if (MaxCpuIdIndex >= CPUID_EXTENDED_TOPOLOGY) { + AsmCpuidEx( + CPUID_EXTENDED_TOPOLOGY, + 0, + &ExtendedTopologyEax.Uint32, + &ExtendedTopologyEbx.Uint32, + &ExtendedTopologyEcx.Uint32, + NULL + ); + // + // If CPUID.(EAX=0BH, ECX=0H):EBX returns zero and maximum input value for + // basic CPUID information is greater than 0BH, then CPUID.0BH leaf is not + // 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. + // + LevelType = ExtendedTopologyEcx.Bits.LevelType; + ASSERT(LevelType == CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_SMT); + ThreadBits = ExtendedTopologyEax.Bits.ApicIdShift; + + // + // Software must not assume any "level type" encoding + // value to be related to any sub-leaf index, except sub-leaf 0. + // + SubIndex = 1; + do { + AsmCpuidEx( + CPUID_EXTENDED_TOPOLOGY, + SubIndex, + &ExtendedTopologyEax.Uint32, + NULL, + &ExtendedTopologyEcx.Uint32, + NULL + ); + LevelType = ExtendedTopologyEcx.Bits.LevelType; + if (LevelType == CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_CORE) { + CoreBits = ExtendedTopologyEax.Bits.ApicIdShift - ThreadBits; + break; + } + SubIndex++; + } while (LevelType != CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_INVALID); + } + } + + 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); + MaxCoresPerPackage = CacheParamsEax.Bits.MaximumAddressableIdsForLogicalProcessors + 1; + } + else { + // + // Must be a single-core processor. + // + MaxCoresPerPackage = 1; + } + + ThreadBits = (UINTN)(HighBitSet32(MaxLogicProcessorsPerPackage / MaxCoresPerPackage - 1) + 1); + CoreBits = (UINTN)(HighBitSet32(MaxCoresPerPackage - 1) + 1); + } + + Location->Thread = InitialApicId & ((1 << ThreadBits) - 1); + Location->Core = (InitialApicId >> ThreadBits) & ((1 << CoreBits) - 1); + Location->Package = (InitialApicId >> (ThreadBits + CoreBits)); +} diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c old mode 100644 new mode 100755 index c3fe721..902e212 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -58,132 +58,6 @@ IsBspExecuteDisableEnabled ( } /** - Get CPU Package/Core/Thread location information. - - @param[in] InitialApicId CPU APIC ID - @param[out] Location Pointer to CPU location information -**/ -VOID -ExtractProcessorLocation ( - IN UINT32 InitialApicId, - OUT EFI_CPU_PHYSICAL_LOCATION *Location - ) -{ - 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; - - // - // Check if the processor is capable of supporting more than one logical processor. - // - AsmCpuid (CPUID_VERSION_INFO, NULL, NULL, NULL, &VersionInfoEdx.Uint32); - if (VersionInfoEdx.Bits.HTT == 0) { - Location->Thread = 0; - Location->Core = 0; - Location->Package = 0; - return; - } - - ThreadBits = 0; - CoreBits = 0; - - // - // Assume three-level mapping of APIC ID: Package:Core:SMT. - // - - TopologyLeafSupported = FALSE; - // - // Get the max index of basic CPUID - // - AsmCpuid (CPUID_SIGNATURE, &MaxCpuIdIndex, NULL, NULL, NULL); - - // - // If the extended topology enumeration leaf is available, it - // is the preferred mechanism for enumerating topology. - // - if (MaxCpuIdIndex >= CPUID_EXTENDED_TOPOLOGY) { - AsmCpuidEx ( - CPUID_EXTENDED_TOPOLOGY, - 0, - &ExtendedTopologyEax.Uint32, - &ExtendedTopologyEbx.Uint32, - &ExtendedTopologyEcx.Uint32, - NULL - ); - // - // If CPUID.(EAX=0BH, ECX=0H):EBX returns zero and maximum input value for - // basic CPUID information is greater than 0BH, then CPUID.0BH leaf is not - // 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. - // - LevelType = ExtendedTopologyEcx.Bits.LevelType; - ASSERT (LevelType == CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_SMT); - ThreadBits = ExtendedTopologyEax.Bits.ApicIdShift; - - // - // Software must not assume any "level type" encoding - // value to be related to any sub-leaf index, except sub-leaf 0. - // - SubIndex = 1; - do { - AsmCpuidEx ( - CPUID_EXTENDED_TOPOLOGY, - SubIndex, - &ExtendedTopologyEax.Uint32, - NULL, - &ExtendedTopologyEcx.Uint32, - NULL - ); - LevelType = ExtendedTopologyEcx.Bits.LevelType; - if (LevelType == CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_CORE) { - CoreBits = ExtendedTopologyEax.Bits.ApicIdShift - ThreadBits; - break; - } - SubIndex++; - } while (LevelType != CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_INVALID); - } - } - - 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); - MaxCoresPerPackage = CacheParamsEax.Bits.MaximumAddressableIdsForLogicalProcessors + 1; - } else { - // - // Must be a single-core processor. - // - MaxCoresPerPackage = 1; - } - - ThreadBits = (UINTN) (HighBitSet32 (MaxLogicProcessorsPerPackage / MaxCoresPerPackage - 1) + 1); - CoreBits = (UINTN) (HighBitSet32 (MaxCoresPerPackage - 1) + 1); - } - - Location->Thread = InitialApicId & ((1 << ThreadBits) - 1); - Location->Core = (InitialApicId >> ThreadBits) & ((1 << CoreBits) - 1); - Location->Package = (InitialApicId >> (ThreadBits + CoreBits)); -} - -/** Worker function for SwitchBSP(). Worker function for SwitchBSP(), assigned to the AP which is intended @@ -1451,7 +1325,7 @@ MpInitLibGetProcessorInfo ( // // Get processor location information // - ExtractProcessorLocation (CpuMpData->CpuData[ProcessorNumber].ApicId, &ProcessorInfoBuffer->Location); + GetProcessorLocation (CpuMpData->CpuData[ProcessorNumber].ApicId, &ProcessorInfoBuffer->Location); if (HealthData != NULL) { HealthData->Uint32 = CpuMpData->CpuData[ProcessorNumber].Health; diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c old mode 100644 new mode 100755 index 40f2a17..75b5fc0 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c @@ -27,125 +27,6 @@ EFI_SMM_CPU_SERVICE_PROTOCOL mSmmCpuService = { }; /** - Get Package ID/Core ID/Thread ID of a processor. - - APIC ID must be an initial APIC ID. - - The algorithm below assumes the target system has symmetry across physical package boundaries - with respect to the number of logical processors per package, number of cores per package. - - @param ApicId APIC ID of the target logical processor. - @param Location Returns the processor location information. -**/ -VOID -SmmGetProcessorLocation ( - IN UINT32 ApicId, - OUT EFI_CPU_PHYSICAL_LOCATION *Location - ) -{ - UINTN ThreadBits; - UINTN CoreBits; - UINT32 RegEax; - UINT32 RegEbx; - UINT32 RegEcx; - UINT32 RegEdx; - UINT32 MaxCpuIdIndex; - UINT32 SubIndex; - UINTN LevelType; - UINT32 MaxLogicProcessorsPerPackage; - UINT32 MaxCoresPerPackage; - BOOLEAN TopologyLeafSupported; - - ASSERT (Location != NULL); - - ThreadBits = 0; - CoreBits = 0; - TopologyLeafSupported = FALSE; - - // - // Check if the processor is capable of supporting more than one logical processor. - // - AsmCpuid (CPUID_VERSION_INFO, NULL, NULL, NULL, &RegEdx); - ASSERT ((RegEdx & BIT28) != 0); - - // - // Assume three-level mapping of APIC ID: Package:Core:SMT. - // - - // - // Get the max index of basic CPUID - // - AsmCpuid (CPUID_SIGNATURE, &MaxCpuIdIndex, NULL, NULL, NULL); - - // - // If the extended topology enumeration leaf is available, it - // is the preferred mechanism for enumerating topology. - // - if (MaxCpuIdIndex >= CPUID_EXTENDED_TOPOLOGY) { - AsmCpuidEx (CPUID_EXTENDED_TOPOLOGY, 0, &RegEax, &RegEbx, &RegEcx, NULL); - // - // If CPUID.(EAX=0BH, ECX=0H):EBX returns zero and maximum input value for - // basic CPUID information is greater than 0BH, then CPUID.0BH leaf is not - // supported on that processor. - // - if ((RegEbx & 0xffff) != 0) { - TopologyLeafSupported = TRUE; - - // - // Sub-leaf index 0 (ECX= 0 as input) provides enumeration parameters to extract - // the SMT sub-field of x2APIC ID. - // - LevelType = (RegEcx >> 8) & 0xff; - ASSERT (LevelType == CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_SMT); - if ((RegEbx & 0xffff) > 1 ) { - ThreadBits = RegEax & 0x1f; - } else { - // - // HT is not supported - // - ThreadBits = 0; - } - - // - // Software must not assume any "level type" encoding - // value to be related to any sub-leaf index, except sub-leaf 0. - // - SubIndex = 1; - do { - AsmCpuidEx (CPUID_EXTENDED_TOPOLOGY, SubIndex, &RegEax, NULL, &RegEcx, NULL); - LevelType = (RegEcx >> 8) & 0xff; - if (LevelType == CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_CORE) { - CoreBits = (RegEax & 0x1f) - ThreadBits; - break; - } - SubIndex++; - } while (LevelType != CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_INVALID); - } - } - - if (!TopologyLeafSupported) { - AsmCpuid (CPUID_VERSION_INFO, NULL, &RegEbx, NULL, NULL); - MaxLogicProcessorsPerPackage = (RegEbx >> 16) & 0xff; - if (MaxCpuIdIndex >= CPUID_CACHE_PARAMS) { - AsmCpuidEx (CPUID_CACHE_PARAMS, 0, &RegEax, NULL, NULL, NULL); - MaxCoresPerPackage = (RegEax >> 26) + 1; - } else { - // - // Must be a single-core processor. - // - MaxCoresPerPackage = 1; - } - - ThreadBits = (UINTN) (HighBitSet32 (MaxLogicProcessorsPerPackage / MaxCoresPerPackage - 1) + 1); - CoreBits = (UINTN) (HighBitSet32 (MaxCoresPerPackage - 1) + 1); - } - - Location->Thread = ApicId & ~((-1) << ThreadBits); - Location->Core = (ApicId >> ThreadBits) & ~((-1) << CoreBits); - Location->Package = (ApicId >> (ThreadBits+ CoreBits)); -} - -/** Gets processor information on the requested processor at the instant this call is made. @param[in] This A pointer to the EFI_SMM_CPU_SERVICE_PROTOCOL instance. @@ -280,7 +161,7 @@ SmmAddProcessor ( gSmmCpuPrivate->ProcessorInfo[Index].ProcessorId == INVALID_APIC_ID) { gSmmCpuPrivate->ProcessorInfo[Index].ProcessorId = ProcessorId; gSmmCpuPrivate->ProcessorInfo[Index].StatusFlag = 0; - SmmGetProcessorLocation ((UINT32)ProcessorId, &gSmmCpuPrivate->ProcessorInfo[Index].Location); + GetProcessorLocation ((UINT32)ProcessorId, &gSmmCpuPrivate->ProcessorInfo[Index].Location); *ProcessorNumber = Index; gSmmCpuPrivate->Operation[Index] = SmmCpuAdd; -- 1.9.1