From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-dm3nam03on0045.outbound.protection.outlook.com [104.47.41.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E26BB21AE30D2 for ; Tue, 6 Jun 2017 08:58:07 -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=ej2hwU1zfBh3daZiqDmRLboEO88+pe9DVSPRlkAqzFw=; b=SwwO09yaW4WRVHFaZtA+SJZDcPD1yskVa3LZASK1OpaOoFDJy0KAR0nqsDrzFnQLOPGfToPQmtyoSNXVpDHD0s1tyj8I4KYoSMC9opFTWuKmv5CHPTyW62OTvtlBI6bi4+w6a8R58jZL7JlMYEMOBLC38dGTyF6TCQ7wwvoOrG0= 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 CY4PR12MB1237.namprd12.prod.outlook.com (10.168.167.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1143.10; Tue, 6 Jun 2017 15:59:12 +0000 From: Leo Duran To: edk2-devel@lists.01.org Cc: Leo Duran , Jordan Justen , Jeff Fan , Liming Gao , Brijesh Singh Date: Tue, 6 Jun 2017 10:59:01 -0500 Message-Id: <1496764741-6327-3-git-send-email-leo.duran@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1496764741-6327-1-git-send-email-leo.duran@amd.com> References: <1496764741-6327-1-git-send-email-leo.duran@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: MWHPR14CA0009.namprd14.prod.outlook.com (10.173.227.19) To CY4PR12MB1237.namprd12.prod.outlook.com (10.168.167.12) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PR12MB1237: X-MS-Office365-Filtering-Correlation-Id: 17ae4935-512c-491c-ce78-08d4acf4f9ee X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(201703131423075)(201703031133081); SRVR:CY4PR12MB1237; X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1237; 3:2UORnsSm893s/1AyyaSiUFnkz7tH3ZWpBf0mC6dQcCQzomK4fjqzVEDGIXEwtq9JidtcSFQkR/SN/h85JARiTEFjUqCqfvegInMllp1dBywt1Y/79m4XhCLuJKmfu+loyncaPVp4D+UwHsz4k8Zl4GLUzF0FHhAfqxlZmpzfj5adTkZtovc4aoVnQvJmuMga9BDR5JZc2TM9uphainmVWh0Ru6bjRhUmMSCNXRVEEiIa6qcEZyYJEoPeCwfNu7o1rtXPY6ANnk/RNoWNnzvLykurQLowz0GXrOvkC3LaTwY/gXAoMtRIFfuG47TxqQVWM9CzVwB0o6FvPcu4/GqStBpA7QrpYYU8WbHNhnxU3Mg=; 25:HzniEiE/O/VFDn8grktv+EJ2MglnkkAh29lCPWWdsJ+LhC+FTo6tF71aaUsGOHXtgd7Cl7h5I/NXg0uNkjSuI7yaUk5SKAhnBMVWQ0QkhHBvrbz9c8QtxwyzlhDz8D0S7WmRyUwIFFT3nWaYRMaCJ0g+vZPKqg8M8PjRwpg2cuBPNyGidde0txdWoShJ6/zgknxae6lfYh/WIY5tzNVXALRrjNYuzEMkqrzGb6R7I318JgXmrh0BLKJ8/m8EM6f7ii7mu5mhI4pyVLOhLIWuko7U/QKgiRsFfq6rcokQ3ZJwMU0JbYu0LrZ8i0qXuYn68wWFBNvdpSsq+ygQC2xBgIbKRFHdeqazGsAQpiecf9N2NCtM5KbYnKUtfldlIvkC51w5fpufcQZ8gnE7gEROf7B/ztS2EnjqBGNcasEdQk4RzVvwR+g96kVFJpHG6pFC3BUOe+tf1uzu0/WHG8/uFVhtLRvtz++QnEOqEbw5378= X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1237; 31:o3uOmFTsgK/l4cjAbC044CYaWiL0trI36yWdcz5e/9v4lirRNm0nu5iZ10Ut40y/fXxuyiLvYWYQ4fUJho45FAy13AGdFee0Bhl8pS5pUncQS7oZ0hG9BaubeYug0S2elGg10yjc+6GidPfib4YOFryCRnxQyw+FmH46PFrYSevSWQ1Bz+ij2fpSLR/ADsiXVNCq93mQXxA+cMiQ4yHS+gIHJxN/rACQJh6bOgsJKnM=; 20:W1qqjcKEEwShRcb/BubkhgocjgrU7V/enBx8pHeV7fTDJ/jkKbEEHhhvTqusaK33kAiKyhArbwHLhPobus9gMSmAgT2Spjt4HJZszmPL2feDQy1QIs+MlDX+as2n14dpDNoJtjLBvMT+qqRdwT+rDx+RW2tiW2imsYl6z8uZmr1vL9p/2Z0tASpzMOWo1TBXb246QnGduJ4ACRBERXzABmAY30DsAn2nDw/6tf3or1PtCYRPWJP7CeSeqL6Olsuo4c3SaKTbYf2S/TIZqym+wz33c9uis3yvNX3RGPOp3VBgtWzGdaTNyv4U8l9ToDMwExYR9S2HT9/YHixGu+mmmTLmpa1S6oR8hxYR88vaAP47M7H32uJK6/kz6EJuzaidls98v7TGm4xGiOI3dsn8w1JswQDewGQvmqLtWtVoMIKu4Y6DRHzWkvcHa7nNwYX+LmMcRSuA6RjzU/9xLPrARRoWM3vI0mZZ+giXcIAZWAFUUTUtP252B2fO0CsPH4DS X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(228905959029699); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(100000703101)(100105400095)(93006095)(93001095)(6055026)(6041248)(20161123555025)(20161123560025)(20161123558100)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:CY4PR12MB1237; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:CY4PR12MB1237; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY4PR12MB1237; 4:65atXQ1xFOQbzVb6yPp64vdUPm/SQGIs2E0dzPFyUO?= =?us-ascii?Q?Xhbhazrvpvr1rjRQJElFUhEiVg4E1DGFaibeIRBLI43RUiL6xF8laTFDUXoC?= =?us-ascii?Q?Wf2DJ7dptx9zX/bAAY1zGmoQ79vCVCxHVZhcBQ2H8Iw9jTE0cdxndGNJl/o3?= =?us-ascii?Q?LXZougnANKDEe7ZY67OP5HpFFIxMdVPDnqoCX4KVAA0kIJYaVXG70F0wqf0L?= =?us-ascii?Q?idw+g47zdF5XWsXWeTrGwYnY0/VAO3Tr6kmmJ9VK35yvStuSucNbUt6/dPjS?= =?us-ascii?Q?DZtMsllu7/Q1Uuba7Zmni7v78w0H02T9a9s/IPQHVAofLXiOTzqTBIgcrOZ8?= =?us-ascii?Q?NJcAMcfjTUWhszbLXW8sFPn3ClXwGJM2BzqoiCbJhR2PoCpVGlrXXC75+tv5?= =?us-ascii?Q?W12G8BR1msPJo2L/LilV9yMK1+BLgdxno5lij1T18AFLa0Le+WsnhcPX3oQd?= =?us-ascii?Q?EpE+OLlAa7aYrVrf/WRieg511BYXzzXviN60YL/pMDV4pt9PNN1SNhnJcMCz?= =?us-ascii?Q?v8IHL1NAnMqNnHKX/YWc/VLybQaSyyh57GL/XCEIkrvGN3vkMjBIvyxj+w+W?= =?us-ascii?Q?Fd4HBJqoEccbbWHqN40Oo0zAH5eyV8yP0fd79j+KEKiayDFJjEY/ivkVL+N5?= =?us-ascii?Q?a2+AV697LCVfdkKURUBEjRHu5/n9gVuAcsIi/Ua7z15N3izMXHkN/1HuejQR?= =?us-ascii?Q?dt9brSwBHtiKlMvx6i9lPUbW8a1ZUd8t1bnuD2wvXjkYUZWWgPI+QarfNHnI?= =?us-ascii?Q?7rG34x75SV1hmjmv+tf+MY88fdHceNhsTu+219Q6IyqW3ttVDEX0X4UDC1LX?= =?us-ascii?Q?s3DQ4WqfDNEr95V9+HCw9DAcVuPPWuoghMOGVYT1my8zBO4sDRz4GDKZELB6?= =?us-ascii?Q?0oqwc8FC9KIQ0ZKSLOlxb0jt/UxB3xYeFLDsDhCoZ+gm6jQjLg/J4gSgaACM?= =?us-ascii?Q?AhOCBbMW6TmBVLaRtXyfE2icbrlyQm6rtPxvuIq5/nCl/01ua5g3dE0ILitc?= =?us-ascii?Q?GzlTnVSgeFtKEBKzuyC8IcXmqF5VbNnd9OcBTsn/V40zftNT0n417CPj0H+h?= =?us-ascii?Q?BR8m4bXBifKE4lJyXnRIBnruzfHOdHjodscH9BqsjIZ8StZnt3027yXEFENO?= =?us-ascii?Q?jMAQlKbJ8o+ft85w2k9CZmB38qyrBcY2u8QRwqQdf+/RJsqYKum4PjTzZFIK?= =?us-ascii?Q?GVxRGUPlWEREJRmRK1AKnExrTPrwhbkMcQ2z/QDqAOFnIQW7asOfR9NpXYgQ?= =?us-ascii?Q?A2mpMEvEicdUYdvzc=3D?= X-Forefront-PRVS: 033054F29A X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(979002)(6009001)(6029001)(39860400002)(39410400002)(39400400002)(39840400002)(39850400002)(39450400003)(5003940100001)(2950100002)(305945005)(38730400002)(7736002)(110136004)(48376002)(50466002)(81166006)(2361001)(53936002)(5660300001)(33646002)(189998001)(2351001)(6116002)(53416004)(6486002)(54906002)(2906002)(47776003)(36756003)(3846002)(42186005)(86362001)(66066001)(478600001)(8676002)(76176999)(6916009)(6666003)(25786009)(50226002)(50986999)(4326008)(19627235001)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR12MB1237; H:leduran-Precision-WorkStation-T5400.amd.com; FPR:; SPF:None; MLV:ovrnspm; PTR:InfoNoRecords; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY4PR12MB1237; 23:No3mKowkIsyVChfRcsBzXBGQTqRnCIYhdQzNvjb53?= =?us-ascii?Q?+nfWYJX3gWYMg/jaJKFPLK031E6LOBqBYjjQLDxCSE9HFRl2XGQA9NybzXw6?= =?us-ascii?Q?+9Cj0eOMhtHh7OKbxi6WnMkLA4ci89i5KjGQiPw0D+dT1Ig4PWKnmfzneG9/?= =?us-ascii?Q?Laguz2h4E43MXEVdibfoxQ12dx/821BnTHuLyhdr/rM5aKy+c2NIThlLMzbj?= =?us-ascii?Q?CRwkMa8Nk6uO4OhF6M79ZXaw2EobrQ4zul/I96R2qB9nmo0g1tVYe/AnGtNy?= =?us-ascii?Q?aai9NHEIlKn60fkKlAxFlPrj1fSrIULrvX21ip9YD0+l/rDTZ0fQKR+Oof8j?= =?us-ascii?Q?OL05fS8h19yEJ7viGHp0Hc4lCXjL+guRPLxhhYyWiAIPgptroSnM0ehVqlCy?= =?us-ascii?Q?TOryofh21bQPypC4sdlnFt69Q5GLeCk9ATacLvQFzoqJx6VjmaM4TWv7ryWU?= =?us-ascii?Q?Xh1y7Ksz/61la5hZBGozde6ZE763BsYLVZ10cydKL07Iq4apTKK7c+RLD/MZ?= =?us-ascii?Q?ZTX0FmMtaG6PLZacwK9lf8HsCDc6KIrYM7Xll/P7KFtZXkvcGcUaPUYueyoY?= =?us-ascii?Q?IbNfFRikrncImR9y/2DxyJB4btv/BEG7DAX14hL8YdSx4rirwT5V3dbLNUqI?= =?us-ascii?Q?QhOQP8lngzxKsShmrZkHXqOj+nr2IQj/bVvoSLwfbazX6nmLaV4yhDoSnEqN?= =?us-ascii?Q?1EFT72UbhLcI4MwkqeM/Aric/6O8rJiQMlEbII9Ju+K84w1PSXBaw66mDjTq?= =?us-ascii?Q?eu+xakB2MyND0oOBhm30+50AFjqBhLCtoTVpIeMZdCl6Jf0fhZ89iPTDM31y?= =?us-ascii?Q?gXJGncHFtQLh0s73v5qAuxIDd54a7zPmLAmnYQjuYtN6FQ2mpu4TPUvgrec5?= =?us-ascii?Q?e38Gd7F+L0uN2y/PeLU3K50qNsd6h+MCRXuAnrThIoYmbDkNK/DOs0TXJITj?= =?us-ascii?Q?G52YuFHesmc9iOw+G8P67lRlOqxedopzSvKyQuyJlIy7aiGNS8yvfuHW59OV?= =?us-ascii?Q?qttbl8BXZkAnVFrN+QA5AK8nEGW6Js23I5YFtHaYyVXqqiQBYDy3UEvw1H2l?= =?us-ascii?Q?xHz8aNsvI4VawZpdhf+fn7dCw9b8gUdRkjGYcNiEhuklXsRnZP5lVyjrWN+n?= =?us-ascii?Q?+ZqRwKHIelRcmCmUYX72Xwz2AGJCvfGwHTLZrA4huCQjdRV4zooo6ilgZiO5?= =?us-ascii?Q?iKtt72XOO3rcx+2oBLGZHa0bMzT2GeJxLOqpiOvtd13kWZ8uvyNuwl/CTWFO?= =?us-ascii?Q?pFgj7UJP1SYVtMf66M=3D?= X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1237; 6:4zfUXuNswnO5csDiEGI2MsYl9RpAK5r/kN0Eh9xkPC71yuUCfJWhOeUhcOtfC0d9XjAhA1X96hiaXdavGb/14oVqicAuEAIvkfGKY+WpcUk74Ckf9O33dfoEUHxT2LjNjwpmu6+CplXvVRTBIORc4zacvne7uHyLixOM8EOeJhuAQq5vxPLMl7zj3w+jLY5DWV7H0/RJwk323mkguW0KU/be3lqC+Pibof2PNPqMMbBeg72gfQSe88DpEtJi1UlfLpWhVzupWSlRYHoojCm+fvjspYmSZTW9g2QXiNg1wSL7+ZmjZERNQ1Ma8k6RxV2wD+Av58qhTICyG9+wCFlJ1vLEe76JOR8SL+/s3elSqXBm+K8OoyFArLMBa6nZDiT3JD4hTvG6uLW/jJuzgteA+7z41W/c3dqv26Dx+pCgzdrDbQOVXCOwSsrV0coXpXXwsWrH28tRe663vR8yc5x7oHHdKvLYaZ0GLBov6IbZFNx3NL8enrAB6zT0fHapWqE5hQOpJXq/Yx7qPtpy6DtiworLlvaWUWB6PLLHTymMGMk= X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1237; 5:g/u+GslHUvBkMQmWoy5bs7+RAretpQLYdXoXU41SiWCoiADoOpWTSTp4esQb22TIi55JKF3L+d82zkJB0NWbD0XrZet/Jc/xaEVRCjEZJ5lkZgsi8y3MSQWLO7Xf+YfuUsPrZh1QkA3rMxUNDuK/m6w4bB76o7QCOmDdcGNa5lRvV3HiLyrkvskv0PaOsvbAfxlc63e9ePtSbOyyVG+1/qalctZBsrCSmh5AfBI5yTwq9JAGXaRSEAB/D8EY84M7lhmUz/3G1tGERV41QTwEC5krlVsyXmIIg+0e7S5jxD846cPWYDqUdZlCNWh/TZwoFDe/099KBVEQGMunjg5powwqSZo0Iry8HHiB4phmUoFGedYiD0pXGCwfxUQhh8qhTCfUzuEPRqhog4FxgEAQrll68gxgmDAU1ywWU52g3gJH1poOSsUo9bbX6IH6ki851QeTGMWOKIw9zTQh5nm92pGItAPLEW9Jk9syAuXcBn+swacvKiekRiptWFS4q3i/; 24:XQQZdhYbcf+BdG2XbVGgh9CESv2mGixRXVSJS7los6KCCnsaxCyZc2kzUy5fy16n5/6zZAJHVEhGi19J2ta0OKZYPztFLuOsT5Rn/VLFDPo= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1237; 7:81F85Ci5jJmy5P4mlJ/d2/h7MUUEtz72ejf4tzI64sHJnz55mYhf7fk77uIo+NYlQ6ssma9taHhufR4WdDdduldBk+fXTcEpiOlpxkOE/efBF3JAuZcwWhd+Rwa29jUWEpkoL+DwvJ0mJ8PgnY0Z6qrUWoag1ZJ0Qck2C7YtEdNnG14QGFkAXafF4pqWvq5THzg4JJyjBiQcfKGVTsABDWfRrrQEJPaZn/QuJ4Ruo+Jx30RRCpxbJ51Sw2EECjNvZMncHGuXQcvH9iwyjElJcOkMUxJkAPjUUvQxcEDqjuGCXyZ/f5CZ/ct6LK8rNvuDfo318zqrhLg8/GN9EM2paA==; 20:A8Zo0fgSCjbI8hNq3jjs1Fm2/DGtiJkO/wt1y1kEcOOdJ4pHf4ZtdFgoUyRa0SPh9XX+eV2XUIPcV2FopSRV+wjsytQBnr2gBWiAytv1+lt0Pz11Sgn7IUD1bi3+jMO6loAZyhA2zIGRJ+r8hUgOU+XmWrN2WHcn98yLKfmRJSpzzKy/ncxz/8eCvSukxuy9tTBzBygWY67PSgePsmOfcUtILQVcR3tvxTaC/gOd1gy5RL/1qFM5md7nG6Jlsgn/ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2017 15:59:12.5319 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1237 Subject: [PATCH v3 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: Tue, 06 Jun 2017 15:58:08 -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 | 130 +++++++++++++++------ .../BaseXApicX2ApicLib/BaseXApicX2ApicLib.c | 130 +++++++++++++++------ 2 files changed, 184 insertions(+), 76 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..02dfabc --- 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,29 @@ 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; + CPUID_AMD_PROCESSOR_TOPOLOGY_ECX AmdProcessorTopologyEcx; + CPUID_AMD_VIR_PHY_ADDRESS_SIZE_ECX AmdVirPhyAddressSizeEcx; + UINT32 MaxStandardCpuIdIndex; + UINT32 MaxExtendedCpuIdIndex; + UINT32 SubIndex; + UINTN LevelType; + UINT32 MaxLogicProcessorsPerPackage; + UINT32 MaxCoresPerPackage; + UINT32 MaxThreadPerPackageMask; + UINT32 ActualThreadPerPackageMask; + UINT32 MaxCoresPerNode; + UINT32 CorePerNodeMask; + UINT32 ApicIdShift; + UINTN ThreadBits; + UINTN CoreBits; // // Check if the processor is capable of supporting more than one logical processor. @@ -987,10 +999,10 @@ GetProcessorLocationByApicId ( AsmCpuid(CPUID_VERSION_INFO, NULL, NULL, NULL, &VersionInfoEdx.Uint32); if (VersionInfoEdx.Bits.HTT == 0) { if (Thread != NULL) { - *Thread = 0; + *Thread = 0; } if (Core != NULL) { - *Core = 0; + *Core = 0; } if (Package != NULL) { *Package = 0; @@ -1002,20 +1014,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 +1038,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,31 +1067,79 @@ 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 { + } + + 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, + &AmdProcessorTopologyEcx.Uint32, NULL); + + MaxCoresPerPackage = MaxLogicProcessorsPerPackage / (AmdProcessorTopologyEbx.Bits.ThreadsPerCore + 1); + // - // Must be a single-core processor. + // Account for actual thread count (e.g., SMT disabled) // - MaxCoresPerPackage = 1; + AsmCpuid(CPUID_VIR_PHY_ADDRESS_SIZE, NULL, NULL, &AmdVirPhyAddressSizeEcx.Uint32, NULL); + MaxThreadPerPackageMask = 1 << AmdVirPhyAddressSizeEcx.Bits.ApicIdCoreIdSize; + ActualThreadPerPackageMask = 1; + while (ActualThreadPerPackageMask < MaxLogicProcessorsPerPackage) { + ActualThreadPerPackageMask <<= 1; + } + + if (ActualThreadPerPackageMask < MaxThreadPerPackageMask) { + MaxCoresPerNode = MaxCoresPerPackage / (AmdProcessorTopologyEcx.Bits.NodesPerProcessor + 1); + + CorePerNodeMask = 1; + while (CorePerNodeMask < MaxCoresPerNode) { + CorePerNodeMask <<= 1; + } + CorePerNodeMask -= 1; + + ApicIdShift = 0; + do { + ApicIdShift += 1; + ActualThreadPerPackageMask <<= 1; + } while (ActualThreadPerPackageMask < MaxThreadPerPackageMask); + + // + // Adjust APIC Id to report concatenation of Package|Core|Thread. + // + InitialApicId = ((InitialApicId & ~CorePerNodeMask) >> ApicIdShift) | (InitialApicId & CorePerNodeMask); + } + + 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); + *Thread = InitialApicId & ((1 << ThreadBits) - 1); } if (Core != NULL) { - *Core = (InitialApicId >> ThreadBits) & ((1 << CoreBits) - 1); + *Core = (InitialApicId >> ThreadBits) & ((1 << CoreBits) - 1); } if (Package != NULL) { *Package = (InitialApicId >> (ThreadBits + CoreBits)); diff --git a/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c b/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c index e690d2a..726e1e0 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,29 @@ 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; + CPUID_AMD_PROCESSOR_TOPOLOGY_ECX AmdProcessorTopologyEcx; + CPUID_AMD_VIR_PHY_ADDRESS_SIZE_ECX AmdVirPhyAddressSizeEcx; + UINT32 MaxStandardCpuIdIndex; + UINT32 MaxExtendedCpuIdIndex; + UINT32 SubIndex; + UINTN LevelType; + UINT32 MaxLogicProcessorsPerPackage; + UINT32 MaxCoresPerPackage; + UINT32 MaxThreadPerPackageMask; + UINT32 ActualThreadPerPackageMask; + UINT32 MaxCoresPerNode; + UINT32 CorePerNodeMask; + UINT32 ApicIdShift; + UINTN ThreadBits; + UINTN CoreBits; // // Check if the processor is capable of supporting more than one logical processor. @@ -1082,10 +1094,10 @@ GetProcessorLocationByApicId ( AsmCpuid(CPUID_VERSION_INFO, NULL, NULL, NULL, &VersionInfoEdx.Uint32); if (VersionInfoEdx.Bits.HTT == 0) { if (Thread != NULL) { - *Thread = 0; + *Thread = 0; } if (Core != NULL) { - *Core = 0; + *Core = 0; } if (Package != NULL) { *Package = 0; @@ -1097,20 +1109,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 +1133,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,31 +1162,79 @@ 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 { + } + + 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, + &AmdProcessorTopologyEcx.Uint32, NULL); + + MaxCoresPerPackage = MaxLogicProcessorsPerPackage / (AmdProcessorTopologyEbx.Bits.ThreadsPerCore + 1); + // - // Must be a single-core processor. + // Account for actual thread count (e.g., SMT disabled) // - MaxCoresPerPackage = 1; + AsmCpuid(CPUID_VIR_PHY_ADDRESS_SIZE, NULL, NULL, &AmdVirPhyAddressSizeEcx.Uint32, NULL); + MaxThreadPerPackageMask = 1 << AmdVirPhyAddressSizeEcx.Bits.ApicIdCoreIdSize; + ActualThreadPerPackageMask = 1; + while (ActualThreadPerPackageMask < MaxLogicProcessorsPerPackage) { + ActualThreadPerPackageMask <<= 1; + } + + if (ActualThreadPerPackageMask < MaxThreadPerPackageMask) { + MaxCoresPerNode = MaxCoresPerPackage / (AmdProcessorTopologyEcx.Bits.NodesPerProcessor + 1); + + CorePerNodeMask = 1; + while (CorePerNodeMask < MaxCoresPerNode) { + CorePerNodeMask <<= 1; + } + CorePerNodeMask -= 1; + + ApicIdShift = 0; + do { + ApicIdShift += 1; + ActualThreadPerPackageMask <<= 1; + } while (ActualThreadPerPackageMask < MaxThreadPerPackageMask); + + // + // Adjust APIC Id to report concatenation of Package|Core|Thread. + // + InitialApicId = ((InitialApicId & ~CorePerNodeMask) >> ApicIdShift) | (InitialApicId & CorePerNodeMask); + } + + 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); + *Thread = InitialApicId & ((1 << ThreadBits) - 1); } if (Core != NULL) { - *Core = (InitialApicId >> ThreadBits) & ((1 << CoreBits) - 1); + *Core = (InitialApicId >> ThreadBits) & ((1 << CoreBits) - 1); } if (Package != NULL) { *Package = (InitialApicId >> (ThreadBits + CoreBits)); -- 2.7.4