From patchwork Tue Feb 23 14:12:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 62717 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp1857240lbl; Tue, 23 Feb 2016 06:21:43 -0800 (PST) X-Received: by 10.66.119.71 with SMTP id ks7mr47032382pab.151.1456237303045; Tue, 23 Feb 2016 06:21:43 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z63si47661622pfi.63.2016.02.23.06.21.42; Tue, 23 Feb 2016 06:21:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753614AbcBWOVl (ORCPT + 30 others); Tue, 23 Feb 2016 09:21:41 -0500 Received: from mail-bn1on0092.outbound.protection.outlook.com ([157.56.110.92]:59392 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753088AbcBWOOH (ORCPT ); Tue, 23 Feb 2016 09:14:07 -0500 Authentication-Results: 8bytes.org; dkim=none (message not signed) header.d=none; 8bytes.org; dmarc=none action=none header.from=amd.com; Received: from localhost.localdomain (124.121.8.20) by BLUPR12MB0436.namprd12.prod.outlook.com (10.162.92.141) with Microsoft SMTP Server (TLS) id 15.1.409.15; Tue, 23 Feb 2016 14:14:01 +0000 From: Suravee Suthikulpanit To: , , , , CC: , , , , , "Suravee Suthikulpanit" Subject: [PATCH V5 03/10] perf/amd/iommu: Modify functions to query max banks and counters Date: Tue, 23 Feb 2016 08:12:37 -0600 Message-ID: <1456236764-1569-4-git-send-email-Suravee.Suthikulpanit@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1456236764-1569-1-git-send-email-Suravee.Suthikulpanit@amd.com> References: <1456236764-1569-1-git-send-email-Suravee.Suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [124.121.8.20] X-ClientProxiedBy: HKNPR06CA0045.apcprd06.prod.outlook.com (10.141.16.35) To BLUPR12MB0436.namprd12.prod.outlook.com (25.162.92.141) X-MS-Office365-Filtering-Correlation-Id: 5a5d128d-dc01-4d7a-0ac4-08d33c5b96b1 X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0436; 2:0Y/gmdpyKnRHzZmTz73ABqMnTEKpSKGRrQo8XjQAtnza49qDpbY2otYi3SY5VpQVfU3Rw3hd6o/unpkmxBsxMmmeTJW3HGgtKU3cHdL/uJMgU7EeJrVzKY+YHqTSZKwUqtCgwN/zYHx16O/YNGJlHeKJKE783fEv/1xpMOGMr1bly8AnsiX5kCAlka6TFEjP; 3:durGeu0m8M3EYWPg2/usait3xoqmS1Gl+LYxhNPucpbqurvTDPLz5jb5oT+hkS9G+62FPEh36B+Pjy7rJiCNN9knNg5LxXniQIQGG3XoC6gZtF3Z58Uois8qrTzJOHD9; 25:9Iw0JsPEizQ0jn/rTaQitZfYCDUKB6YoM8onUAtvUPJeEyo4nHTEl+EwyyxIasuEJO4pPH8Ya+46vLhrpjROf/fVI2K+kZ/bre1oQdhnX+lpQyYuso/qoJu6iamCrTpOaiKHvIWkcu+y5DDIIooH46vTKfxAYqk08fShh/ZLqbSM50mOuc/L6PySoWtPzDDmKnygOrDhNy2FSnB+hNNrMskETVfoztuxjNHtecXBPY+shmCpfZLG5NZgTjjLrPkv1Td+2YX8q4PRqgz32zZOrAru5Um8oRgZLqwncrdND25XqJsCzFVgzPu9nVxzLwFzlSPuZ6wwS4GTksOBvcq3/i6SWQkieKRBdBUFVAQr+K4= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR12MB0436; X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0436; 20:+X32WmyKsCMKq2Iu4J/xl+c8uUdwAvg4XALBAVttthG6ak1KGYv6utFt2cz0WYjzTnnAQKqWl4Fm5DmeO/9LibhDVzyjlskC3uNY+F3ultOhT7ibMO1q+unN9S/dgTjryejVHYgAR980Th8nhGgFs5fpQUXg7Oy0+2NLUO2BPnQkgeERiyICeY66DapgED9JI/iRD5B8LT3j/lamMnfArGF+t1Aln1X38MwNC0utNae93FhV7Guvz52tKrj89rl33fctxy1Ia833vzG8g6dPmGwDchU5Sn5fd8wfZk0xfietGou3el0AXyDVxsjbh0yK/egvqpmVSWkfrtmEd8A7p1V7Xn/bk0MQDzrNe+Pypsm0G8W/W5iV9Lw7sk8NstPnxlpQaqVIrJPrvmp3jBoc1fDS04XyeK3DR+FAUbQ9xOkvNMVZoEqpZPqZTxxTpjk8HXf+Y8tZC4zq7dSaZisosU/GjIaI8zWjfSxO2icpEGwccWn3ryxL6lJEiUPTHCCk; 4:9A3gmLtibZrx4/x0sTzPrAxhPhP6ZlA7bJFBmoeegrcxxxlrm0E+IeOLJvomUK/DkAdj1zQHrbuz5xa8nY7hGxUHGsCcxh8EP7YSAwNOeUt6D4tWSwwdWnIcQTYkyUk6IDdVriG103PeR7DTWXFMjv6YBWlJAjmkQHnvKiY1kl4IM/tRT+b5/tyHdtyMo3pvR/W8hlOSGhvcYlkePQ+PYvQPIH7EFZe9FiBC9ZI3tjWL3G7R0eCaNbOyDmOJU2MasoVtNyRyFigHkV1ULNHDAUHmD+9alDXsoXjluAxeLI4r58mSmoXLmNWXIloWOcVlpMCkcOgGlVCl/3dwgQS/558WB8q7fEFGbBPQGgGyGLOl+ddRrdT3HyMCqF1irE7tkbsnWj5nnfpKvX7W5+7mlQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001); SRVR:BLUPR12MB0436; BCL:0; PCL:0; RULEID:; SRVR:BLUPR12MB0436; X-Forefront-PRVS: 08617F610C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6069001)(5004730100002)(48376002)(77096005)(4326007)(2950100001)(2906002)(3846002)(6116002)(15650500001)(42186005)(5008740100001)(19580405001)(1096002)(19580395003)(86362001)(40100003)(50466002)(586003)(122386002)(36756003)(76176999)(5001960100002)(47776003)(66066001)(50986999)(5001770100001)(189998001)(229853001)(50226001)(87976001)(92566002)(2201001); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR12MB0436; H:localhost.localdomain; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BLUPR12MB0436; 23:qfQxf/5ZCHp3m4/L67a1/qCLzNPGIRua3R4OCoP/a?= =?us-ascii?Q?qFUUApERjbMJVxqka0baWJyqk0zWwLayWBDQiPiUtUvQ9wH7H1JAVr86yiGl?= =?us-ascii?Q?ngBlUwPPaAHGq84oTZ5gGmiC05cp89OMaJEw0uWasvF7CRiinoNy0l75SDjz?= =?us-ascii?Q?3h4wYefvyR7ZRR2ICtHNqgktOu52wtWPMOd5oaoHQDfuMaZjE9IETa7Wmq1t?= =?us-ascii?Q?FCC+/IeQHPqEmCgYYPZW1IXETd+07rKT97ZS1qykS1a9GrRpAnF3W8cpt73z?= =?us-ascii?Q?MrFY3oJGRQ2i+sIQSAAVUVUFCzYEfZiVFBqGtYzTCU2LveHQLgMY203juyl/?= =?us-ascii?Q?2krNTtFbAWXhg1hUQIFiUogcWst7g/yd3ixZacnKZTXNXT3RlDziBN4cMTgb?= =?us-ascii?Q?QhKhGmf7PDOULaaSUx9g5cUiE3bAEJxfrWVx9RVumG0fksxea8mmwvwPNQ3u?= =?us-ascii?Q?pXDHO/C9Vd5BNXar9GhhCoZjIB0eTV4aFgWGJLr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CHxJV1LHuKBIciN8uqaYt8gehqfXjZCk+nC20mmnrgQLppb5Gw/ZFc1jPd2UiPwgRpqko9Dh/Se2D4oGflfWuLWhr X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Feb 2016 14:14:01.8027 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR12MB0436 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, amd_iommu_pc_get_max_[banks|counters]() use end-point device ID to locate an IOMMU and check the reported max banks/counters. The logic assumes that the IOMMU_BASE_DEVID belongs to the first IOMMU, and uses it to acquire a reference to the first IOMMU, which does not work on certain systems. Instead, we modify the function to take IOMMU index, and use it to query the corresponded AMD IOMMU instance. Note that we currently hard-code the IOMMU index to 0, since the current AMD IOMMU perf implementation only supports single IOMMU. Subsequent patch will add support for multi-IOMMU, and will use proper IOMMU index. Signed-off-by: Suravee Suthikulpanit --- arch/x86/events/amd/iommu.c | 17 +++++++---------- arch/x86/include/asm/perf/amd/iommu.h | 7 ++----- drivers/iommu/amd_iommu_init.c | 35 +++++++++++++++++++++-------------- 3 files changed, 30 insertions(+), 29 deletions(-) -- 1.9.1 diff --git a/arch/x86/events/amd/iommu.c b/arch/x86/events/amd/iommu.c index fb4aa7b..67ff3f1 100644 --- a/arch/x86/events/amd/iommu.c +++ b/arch/x86/events/amd/iommu.c @@ -232,14 +232,6 @@ static int perf_iommu_event_init(struct perf_event *event) return -EINVAL; } - /* integrate with iommu base devid (0000), assume one iommu */ - perf_iommu->max_banks = - amd_iommu_pc_get_max_banks(IOMMU_BASE_DEVID); - perf_iommu->max_counters = - amd_iommu_pc_get_max_counters(IOMMU_BASE_DEVID); - if ((perf_iommu->max_banks == 0) || (perf_iommu->max_counters == 0)) - return -EINVAL; - /* update the hw_perf_event struct with the iommu config data */ hwc->config = config; hwc->extra_reg.config = config1; @@ -451,6 +443,11 @@ static __init int _init_perf_amd_iommu( if (_init_events_attrs(perf_iommu) != 0) pr_err("perf: amd_iommu: Only support raw events.\n"); + perf_iommu->max_banks = amd_iommu_pc_get_max_banks(0); + perf_iommu->max_counters = amd_iommu_pc_get_max_counters(0); + if (!perf_iommu->max_banks || !perf_iommu->max_counters) + return -EINVAL; + /* Init null attributes */ perf_iommu->null_group = NULL; perf_iommu->pmu.attr_groups = perf_iommu->attr_groups; @@ -461,8 +458,8 @@ static __init int _init_perf_amd_iommu( amd_iommu_pc_exit(); } else { pr_info("perf: amd_iommu: Detected. (%d banks, %d counters/bank)\n", - amd_iommu_pc_get_max_banks(IOMMU_BASE_DEVID), - amd_iommu_pc_get_max_counters(IOMMU_BASE_DEVID)); + amd_iommu_pc_get_max_banks(0), + amd_iommu_pc_get_max_counters(0)); } return ret; diff --git a/arch/x86/include/asm/perf/amd/iommu.h b/arch/x86/include/asm/perf/amd/iommu.h index 72f64b7..466be63 100644 --- a/arch/x86/include/asm/perf/amd/iommu.h +++ b/arch/x86/include/asm/perf/amd/iommu.h @@ -24,15 +24,12 @@ #define PC_MAX_SPEC_BNKS 64 #define PC_MAX_SPEC_CNTRS 16 -/* iommu pc reg masks*/ -#define IOMMU_BASE_DEVID 0x0000 - /* amd_iommu_init.c external support functions */ bool amd_iommu_pc_supported(void); -u8 amd_iommu_pc_get_max_banks(u16 devid); +u8 amd_iommu_pc_get_max_banks(int idx); -u8 amd_iommu_pc_get_max_counters(u16 devid); +u8 amd_iommu_pc_get_max_counters(int idx); int amd_iommu_pc_set_reg_val(u16 devid, u8 bank, u8 cntr, u8 fxn, u64 *value); diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c index d30f4b2..dde960f 100644 --- a/drivers/iommu/amd_iommu_init.c +++ b/drivers/iommu/amd_iommu_init.c @@ -2244,6 +2244,19 @@ bool amd_iommu_v2_supported(void) } EXPORT_SYMBOL(amd_iommu_v2_supported); +static struct amd_iommu *get_amd_iommu(int idx) +{ + int i = 0; + struct amd_iommu *iommu = NULL; + + for_each_iommu(iommu) { + if (i == idx) + break; + i++; + } + return iommu; +} + /**************************************************************************** * * IOMMU EFR Performance Counter support functionality. This code allows @@ -2251,17 +2264,14 @@ EXPORT_SYMBOL(amd_iommu_v2_supported); * ****************************************************************************/ -u8 amd_iommu_pc_get_max_banks(u16 devid) +u8 amd_iommu_pc_get_max_banks(int idx) { - struct amd_iommu *iommu; - u8 ret = 0; + struct amd_iommu *iommu = get_amd_iommu(idx); - /* locate the iommu governing the devid */ - iommu = amd_iommu_rlookup_table[devid]; if (iommu) - ret = iommu->max_banks; + return iommu->max_banks; - return ret; + return 0; } EXPORT_SYMBOL(amd_iommu_pc_get_max_banks); @@ -2271,17 +2281,14 @@ bool amd_iommu_pc_supported(void) } EXPORT_SYMBOL(amd_iommu_pc_supported); -u8 amd_iommu_pc_get_max_counters(u16 devid) +u8 amd_iommu_pc_get_max_counters(int idx) { - struct amd_iommu *iommu; - u8 ret = 0; + struct amd_iommu *iommu = get_amd_iommu(idx); - /* locate the iommu governing the devid */ - iommu = amd_iommu_rlookup_table[devid]; if (iommu) - ret = iommu->max_counters; + return iommu->max_counters; - return ret; + return 0; } EXPORT_SYMBOL(amd_iommu_pc_get_max_counters);