From patchwork Mon Jul 11 10:11:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 71726 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp539323qga; Mon, 11 Jul 2016 03:46:50 -0700 (PDT) X-Received: by 10.66.255.42 with SMTP id an10mr34226632pad.57.1468234010829; Mon, 11 Jul 2016 03:46:50 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ts10si394284pac.256.2016.07.11.03.46.50; Mon, 11 Jul 2016 03:46:50 -0700 (PDT) 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; dkim=pass header.i=@amdcloud.onmicrosoft.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 S1758431AbcGKKqs (ORCPT + 30 others); Mon, 11 Jul 2016 06:46:48 -0400 Received: from mail-by2nam01on0059.outbound.protection.outlook.com ([104.47.34.59]:3680 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1758362AbcGKKqq (ORCPT ); Mon, 11 Jul 2016 06:46:46 -0400 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=ttcIPuBgjYk5Aqbe38cR3sm1BJvBmVu2Nre744OfM1o=; b=znOvAQAlwosyH9cTv2SxOrMj4Vf2u07xOE8JO5qzqB3POQ1sJt/rRwXKGJVmWMz7kDuZgcFuBtYtSXpdZnG3RiN/4jMLvgSj9JKGep3iZUhrygI8TwAn1L1aLCDm+5aEnmJYgjkt6YbRF7/qdsxjctZj1VpEdgPJ1GLvH0vq8ks= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Suravee.Suthikulpanit@amd.com; Received: from localhost.localdomain (124.121.8.20) by CY1PR12MB0444.namprd12.prod.outlook.com (10.163.91.22) with Microsoft SMTP Server (TLS) id 15.1.534.14; Mon, 11 Jul 2016 10:12:39 +0000 From: Suravee Suthikulpanit To: , , , CC: , , , Suravee Suthikulpanit Subject: [PART2 PATCH v3 06/11] iommu/amd: Adding GALOG interrupt handler Date: Mon, 11 Jul 2016 05:11:34 -0500 Message-ID: <1468231899-6987-7-git-send-email-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1468231899-6987-1-git-send-email-suravee.suthikulpanit@amd.com> References: <1468231899-6987-1-git-send-email-suravee.suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [124.121.8.20] X-ClientProxiedBy: SG2PR03CA0026.apcprd03.prod.outlook.com (10.160.233.36) To CY1PR12MB0444.namprd12.prod.outlook.com (10.163.91.22) X-MS-Office365-Filtering-Correlation-Id: 119822cb-4c93-4cfb-6865-08d3a973e54c X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0444; 2:siva4pQbEzK7hX5faF5x86oBPi4K+FMVUOpR5jeso2AKe8s7a1utjUk+0F06M1mtfSI3hmt7aKs7bxFUY3eP/c5sKAZTvyhZ6t3VHRSkASJw4R9ONCVCzf1DnncRcNMqP1wWGKdykF9uIh1sZVJhwNVGaZJO2SB/0HDIJL9hnNu4JW/Yi+zNzjdui77LurQP; 3:tm58W3vVg/JYM77TmJQCZoJm/1QuRG3anuxEF9jWAjn7c5eCtKlRADPyD3ZAHXuRURto8ueOIAT5w9TYalxzc4zNquPmoioqEoTbDoEyIqfpZDscOAxo9uRtcumm0U9t X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR12MB0444; X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0444; 25:8VYM8z0tI+6jWtCgrz0wUKcqnQ9WHkmzTgO3hY7wC/15q9WuDFy5RFtZrJwSnHOBXogA0pT+o10j7QRtkbawKi9e6hzocsfJmgzDMDmaHoyEeHbSUdUMFdpyv092K/Gr6Iy4d72DjBz0zjGQEfXzqUIrThv83QDSc8I44ZllVVHRplwRuN2vVmlTihgW7skPR+si2r3mAjJPerDkVGD2tBdFCZ10NRQTvfmjoRYxpGb+0+NPPOEfeIiTzjXZjAiCQExRAnVm3P35GWTSM38my7xyq2/YhH25RXCzbTcNV7A79lqv2zGmUh/vVIaTNZnavRcPwXE0jipxBanAynAcHQEjmzeF0bys+uVzXhTUW9tucsfcJr3vDwekN0CKyf6Y9fVyS5qOWoYY8RCnmm0WToXhpAE0RrBcXV1TOoAe+48mZtTvt7gqsyDPc84ZSeKSUuiXEe5j3pwYyksGoLpriGEuLE1BIdgVkze/oZ46yWlSaD2u/v8flJBRQU7yNHaWcBkW0MU3+GBa7eQDAVe5lxZoQV9elsK/rLy1C9f0Z+xB5fPUXilMflBKagDwFnjY28Yb6BznkBVVDUjFRkKRMr7gZc0wiKW8EWuVjBdlyQ1A0w2eHdJnDRXvm/8Bwt8t/Z5G2rLnwKb15eznqRdIVTVibVVfivJj/dnAhy6PSx4xSsYA8bBcpOJUTB74BWABiMmpDV+rcDRvEVw2CvSKH2JIKn7AtCvtW0ZSq5Oq20bAIrxR1/Qp1BRK+M/5OL32ivtZ5TIIKTcPYI3lVW56ng== X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0444; 31:5thKH3MWrxp6ON06gOxHrvs7k5oaaT3A6k6rAJPqV4rPPZJvNn9MBqDRb6dQLubv9tXNtwNYyKheWAfnITxfLZlbNOQZ2vTTv/51tLqLYu8bj/fTq4aGMWyx7U/GdR4bTIzN82sL2QjErucKUfFY3zwoMiCI8ECmk4VOr+k4ic1QVtZCTqqXbi1jB+g18QUWAzxxXWj+AdSFZv82SnnRoA==; 20:KCxB4JzRlp8CnQzwoHF3qIklLvN+VJ2ybIx5m8wOY8owL8PQUnSxbsJXARSvTUiFD2SVMCA75FZEn7N4RLO4RgEhIqTdSWjvhB1Z1playKGGw4nXMR0W7etRArQemWCo5qIeUBlpebyzxSdnLMpGE3B1i2IpWJrvZzmsr/y++CA0DuNd8h2KcgaCgSleG3PThHEZHJ1OLqvBZ/nY6/2Z9QXJ5ZRWubby1/uTyOfxlQJ8KbbFyL+MMsfJwT6F8qrYhDHQzUhG9Y7EnO88Rfn7eGutQ2bYGLyR66ShMp6vdI9RDPn+xEt1CJ0W+m2p4OdEiQm0aVXGrHzt4tvwRcoCUITR91KjzXnHWInmPt4xm9Na2lqw7G2r09tLa13DfH9WroQ95pq8kN0KOjjyv5JlaQ5GXKPhKI60UCXQLyRUzaez0H4ApK3D3RsVAtrDNAAgx+DaZPwSRjTTBCbIf1TyExMLQtL2PadKrYBgvTVOuWPTpsqyYMx3rdFRyWSC/5IP X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026); SRVR:CY1PR12MB0444; BCL:0; PCL:0; RULEID:; SRVR:CY1PR12MB0444; X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0444; 4:fkjwZIzoDNbo00XaS01jVA/lTT7qNdkWIxQ0hQoRs2vQx+cnMvjfynRXPg8F5msP6vOUQa3h7XVuYQlKF2RdgEoHmfWRCNW6QENgc7rJdJjiqs88pvSV0fedA3dNEpeDygbNfmoHGOv3WrO5Ttt80DxFYNKZNJSF4Au/850N0du1LG8lw+3oLPIr7OKSUEXjq+uumo1I1dGGZXZZPWHJxPTFJzBXlgueR/lzgjJ97j6WDwFTy0QLSqgWSTaJMtvXeIxMpRBj5/hyfkRZ+cdZzW5H58lrY1LVS6+mRNHxoVBz+RGixerxOghPcSjsqXONIG6cFVVF8FCd6vC4W6mXhEDgo3g2xoLvQpTEX6DjLY6rW8/fYjxoJHEc4YkCo+He6lrJ8JJHSyZPSgx4wDvGXlQhA0vMM7e3a7ZnG13bUjE= X-Forefront-PRVS: 00003DBFE7 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6069001)(7916002)(189002)(199003)(3846002)(6116002)(2201001)(101416001)(81166006)(86362001)(5003940100001)(47776003)(586003)(189998001)(106356001)(66066001)(7736002)(77096005)(5001770100001)(36756003)(97736004)(50466002)(33646002)(50986999)(19580405001)(81156014)(305945005)(68736007)(4326007)(50226002)(19580395003)(48376002)(8676002)(105586002)(76176999)(7846002)(92566002)(42186005)(2906002)(2950100001)(229853001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR12MB0444; H:localhost.localdomain; 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; CY1PR12MB0444; 23:soQBn7IFcC+MEZXijBmkMDHhS3HEVu7YPcogNaATL?= =?us-ascii?Q?UkVSP0QUBfRJfa9DPpAWZ8Zk+Z+0J9G3pRP9WFtafHv4DlQS3VXmxp/AG9cN?= =?us-ascii?Q?XRL97onVUH25jvjnwvzdOYuCQHYRHrhE/ALtQYE3dZnCG6C0nQyG+fWyZxxb?= =?us-ascii?Q?RKqLElR+DrQPnj3U8ZtGkR2/iqh+HxHVO/wVQURjIGas4GQlQ+nQu0RHGHly?= =?us-ascii?Q?PJ8rIzvqfgTgoELMJ76aeWB8mk/kmkNAd3HZiyX7U0UKnZe/y1LUkAT1dPWI?= =?us-ascii?Q?vQEO1u/5N7X5kD/fl7xntB1IxeDIZhCIuqlrTVnOQKMxXJit8zi5913oqE28?= =?us-ascii?Q?ABZqhxyGahB6EEBuNRlzGKWeS7A+bkmgW5WvoQufP+IgbbFaQJLI3H+viOzn?= =?us-ascii?Q?Nh7ZYA9bTaMA2ghR1Y89JsGmWvJo6MNpYHvJWYcn6AW8Zey7/pQxpwIhunua?= =?us-ascii?Q?W23BDJX4M0baV2eA2qXB6L3DFlJDMSJExik/wGNwZR9dRcKaqFfmmDnDJMA1?= =?us-ascii?Q?/gKBMtMtQDv753bT9/II53lwrR57+XZS/4hhqlpCEv+6QafEuce8cQowjwqO?= =?us-ascii?Q?Krk13SwkInpX03R/cB6tl7IkyqwPun0p43jRR2f1TpFPDmYUkeqtbng/6ncE?= =?us-ascii?Q?qvb0aIdoTI2HYAP6GQkB9HPK462OHTYSgtxw2WTye7hWJQB6xSuT/sCtcyRk?= =?us-ascii?Q?mg/pgKonWVLmEU6+pUpYN11dR+RKwuP9skYKRjUMBA9rPlYXD5NsO5NNilla?= =?us-ascii?Q?zBwEjoIqQQCmJrwH27Bi3XLz10GogdbK8UDfBu9IWAW6YiHjRyob/JumtG6X?= =?us-ascii?Q?6y8sQq2E5ZJ4+3bvlwnTzv2xbjs1+LPw1Si+rHNAdDJpFuY6FEbn1F4IUnqm?= =?us-ascii?Q?UMDZMAal5Vdd2R6JhZJBlmOjt+Lss7+msENiVt/BKByie1fr37FrDILYD5x8?= =?us-ascii?Q?0yub/dZF9FlbGWXAx4qtjB4FPjH5Uv8BpR4VlCHVUymgZp8TZKOfXyl1wQDU?= =?us-ascii?Q?0yjWw7PkZsUTPvaDDSvkWlWrPh+6Z7MiB/j9et3Kpq5rAIQcMtsCc1VKWELJ?= =?us-ascii?Q?Sq0wHYQvJjfo894dbR4ybQ0nyWlpDXiB9ucBo+bwB6X5bDEsQ=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0444; 6:JRHZhtUijlJa0khjQROteb91vn38ezk/u6ho3d+jddihxnbqVUaXTqNhQAarkym/NZQImeZFL3cvHgbOpr0vPp7LAljBZtbuhikx5tI+BP/MPoAr8ZEE53xnb0DdbiS64f7/X+kASP7a6eodoCD4sl6ImnlEi1hFfAgesNODMZoj2N8EOYqgta7A6MOy1VejQiF3sPPOyrA7GQ55Qnety0VOMx4rv3YnmwxgLa/JLJwsK6DVQHKSwGWmicxhAqkc3lcfPe/ouNytB5QlBxf4uuZEGljVFnPHbgaBb/k7OKekjxy0vhJreJ46nurH7T2NKQ/vpowZnu+ob4oT7FUG7w==; 5:GnEKY2R+aNGyK9Utb4eUUAUIfu97Zv+bU6aPOqts+3bzsI4xkKqnyePxZw5SgIjdrgMPB4CPLlCTmRqAStv9t0C8zqyTomoW5ponWe2rM1fQc9YSufBrt/b4rv7AUgPdV1+2KxJQvvA96VgaTrodsw==; 24:x+DlOuY9X6Gf3foSS6ebdTkrvpezeVuonCPbC4UTIRcv03v8TcJHoxg7uy84G3iUWwU+G2MUgo07UsDzqHJL4CHU+3jzXuzNcyi0/RGaHDY=; 7:dyHlUroZzXaC/tyZLllUpMswWbEeqy07N6WiWfns+7tkNeEnkkAMUBIdxW6YxHEfOAJEm4Bdjx9ZZ+EDMXodkyhY+GsBTVN5vyvQpyZ1enLtD6dgYDHIODyBc88P30FdfzrQ9QRdJsIt4nFUzHsor++V96lkjLCFdavLj85SO+g/RGH4IEU/qPxGJeKyaNBlUpH9fygJ5OHJyQbWBcp+dbK3F7C3rmmMF9RXLWf4KsCiuUtCNdjP4iuTrJRC+KOh SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0444; 20:5lOr6xtoMTlqHTud/sc6y4ks9Jr9sSfZuUlR3vJWk5+HVm3uSKs+8ppKvdENYvOgvImsL/8kr/RD2lwwW+pKuacq+qeHfm0CdKVAAstGrDQ6U2becUb1VBWof48arXACHNxnTDcxC772bnx6vj6zcnSanwxztiBxXeZ4UDkq7bZVpCRVcUB7cSg+MTwmGTjqirnR909tw5byHJBP2pQMX+tCViVbUL+OhwVoQDDUAaCiJKQfKMnzgazx5iwa4eJ9 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jul 2016 10:12:39.6671 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR12MB0444 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Suravee Suthikulpanit This patch adds AMD IOMMU guest virtual APIC log (GALOG) handler. When IOMMU hardware receives an interrupt targeting a blocking vcpu, it creates an entry in the GALOG, and generates an interrupt to notify the AMD IOMMU driver. At this point, the driver processes the log entry, and notify the SVM driver via the registered iommu_ga_log_notifier function. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd_iommu.c | 100 ++++++++++++++++++++++++++++++++++++++-- drivers/iommu/amd_iommu_init.c | 5 ++ drivers/iommu/amd_iommu_types.h | 14 ++++++ include/linux/amd-iommu.h | 20 ++++++-- 4 files changed, 133 insertions(+), 6 deletions(-) -- 1.9.1 diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index abfb2b7..939ebb8 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -741,14 +741,101 @@ static void iommu_poll_ppr_log(struct amd_iommu *iommu) } } +#ifdef CONFIG_IRQ_REMAP +static int (*iommu_ga_log_notifier)(int, int, int); + +int amd_iommu_register_ga_log_notifier(int (*notifier)(int, int, int)) +{ + iommu_ga_log_notifier = notifier; + + return 0; +} +EXPORT_SYMBOL(amd_iommu_register_ga_log_notifier); + +static void iommu_handle_ga_guest_nr_entry(struct amd_iommu *iommu, + u16 devid, u32 ga_tag) +{ + struct amd_ir_data *ir_data; + unsigned long flags; + int vec = 0; + + if (!iommu_ga_log_notifier) + return; + + spin_lock_irqsave(&iommu->ga_hash_lock, flags); + hash_for_each_possible(iommu->ga_hash, ir_data, hnode, ga_tag) { + struct irte_ga *entry = (struct irte_ga *)ir_data->entry; + + vec = entry->hi.fields.vector; + break; + } + spin_unlock_irqrestore(&iommu->ga_hash_lock, flags); + + if (vec) { + pr_debug("AMD-Vi: %s: devid=%#x, ga_tag=%#x\n", + __func__, devid, ga_tag); + + if (iommu_ga_log_notifier(GATAG_TO_AVICTAG(ga_tag), + GATAG_TO_VCPUID(ga_tag), vec) != 0) + pr_err("AMD-Vi: GA log notifier failed.\n"); + } +} + +static void iommu_poll_ga_log(struct amd_iommu *iommu) +{ + u32 head, tail, cnt = 0; + + if (iommu->ga_log == NULL) + return; + + head = readl(iommu->mmio_base + MMIO_GA_HEAD_OFFSET); + tail = readl(iommu->mmio_base + MMIO_GA_TAIL_OFFSET); + + while (head != tail) { + volatile u64 *raw; + u64 entry; + + raw = (u64 *)(iommu->ga_log + head); + cnt++; + + /* Avoid memcpy function-call overhead */ + entry = *raw; + + /* Update head pointer of hardware ring-buffer */ + head = (head + GA_ENTRY_SIZE) % GA_LOG_SIZE; + writel(head, iommu->mmio_base + MMIO_GA_HEAD_OFFSET); + + /* Handle GA entry */ + switch (GA_REQ_TYPE(entry)) { + case GA_GUEST_NR: + iommu_handle_ga_guest_nr_entry(iommu, + GA_DEVID(entry), + GA_TAG(entry)); + break; + default: + break; + } + + /* Refresh ring-buffer information */ + head = readl(iommu->mmio_base + MMIO_GA_HEAD_OFFSET); + tail = readl(iommu->mmio_base + MMIO_GA_TAIL_OFFSET); + } +} +#endif /* CONFIG_IRQ_REMAP */ + +#define AMD_IOMMU_INT_MASK \ + (MMIO_STATUS_EVT_INT_MASK | \ + MMIO_STATUS_PPR_INT_MASK | \ + MMIO_STATUS_GALOG_INT_MASK) + irqreturn_t amd_iommu_int_thread(int irq, void *data) { struct amd_iommu *iommu = (struct amd_iommu *) data; u32 status = readl(iommu->mmio_base + MMIO_STATUS_OFFSET); - while (status & (MMIO_STATUS_EVT_INT_MASK | MMIO_STATUS_PPR_INT_MASK)) { - /* Enable EVT and PPR interrupts again */ - writel((MMIO_STATUS_EVT_INT_MASK | MMIO_STATUS_PPR_INT_MASK), + while (status & AMD_IOMMU_INT_MASK) { + /* Enable EVT and PPR and GA interrupts again */ + writel(AMD_IOMMU_INT_MASK, iommu->mmio_base + MMIO_STATUS_OFFSET); if (status & MMIO_STATUS_EVT_INT_MASK) { @@ -761,6 +848,13 @@ irqreturn_t amd_iommu_int_thread(int irq, void *data) iommu_poll_ppr_log(iommu); } +#ifdef CONFIG_IRQ_REMAP + if (status & MMIO_STATUS_GALOG_INT_MASK) { + pr_devel("AMD-Vi: Processing IOMMU GA Log\n"); + iommu_poll_ga_log(iommu); + } +#endif + /* * Hardware bug: ERBT1312 * When re-enabling interrupt (by writing 1 diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c index 44483a7..d103c3f 100644 --- a/drivers/iommu/amd_iommu_init.c +++ b/drivers/iommu/amd_iommu_init.c @@ -765,6 +765,11 @@ static int iommu_init_ga(struct amd_iommu *iommu) !iommu_feature(iommu, FEATURE_GAM_VAPIC)) amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA; + if (AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir)) { + hash_init(iommu->ga_hash); + spin_lock_init(&iommu->ga_hash_lock); + } + ret = iommu_init_ga_log(iommu); #endif /* CONFIG_IRQ_REMAP */ diff --git a/drivers/iommu/amd_iommu_types.h b/drivers/iommu/amd_iommu_types.h index d72ab15..926ef6e 100644 --- a/drivers/iommu/amd_iommu_types.h +++ b/drivers/iommu/amd_iommu_types.h @@ -27,6 +27,7 @@ #include #include #include +#include /* * Maximum number of IOMMUs supported @@ -120,6 +121,14 @@ #define MMIO_STATUS_GALOG_OVERFLOW_MASK (1 << 9) #define MMIO_STATUS_GALOG_INT_MASK (1 << 10) +#define AMD_IOMMU_GA_HASH_BITS 16 +#define AMD_IOMMU_GA_HASH_MASK ((1U << AMD_IOMMU_GA_HASH_BITS) - 1) +#define AMD_IOMMU_GATAG(x, y) \ + ((((x & 0xFF) << 8) | (y & 0xFF)) & AMD_IOMMU_GA_HASH_MASK) + +#define GATAG_TO_AVICTAG(x) ((x >> 8) & 0xFF) +#define GATAG_TO_VCPUID(x) (x & 0xFF) + /* event logging constants */ #define EVENT_ENTRY_SIZE 0x10 #define EVENT_TYPE_SHIFT 28 @@ -565,6 +574,10 @@ struct amd_iommu { struct irq_domain *msi_domain; struct amd_irte_ops *irte_ops; + + /* Hash table for ga_tag to irte_ga entry */ + DECLARE_HASHTABLE(ga_hash, AMD_IOMMU_GA_HASH_BITS); + spinlock_t ga_hash_lock; #endif }; @@ -819,6 +832,7 @@ struct amd_irte_ops { }; struct amd_ir_data { + struct hlist_node hnode; struct irq_2_irte irq_2_irte; void *entry; union { diff --git a/include/linux/amd-iommu.h b/include/linux/amd-iommu.h index 2b08e79..8f7a469 100644 --- a/include/linux/amd-iommu.h +++ b/include/linux/amd-iommu.h @@ -168,11 +168,25 @@ typedef void (*amd_iommu_invalidate_ctx)(struct pci_dev *pdev, int pasid); extern int amd_iommu_set_invalidate_ctx_cb(struct pci_dev *pdev, amd_iommu_invalidate_ctx cb); - -#else +#else /* CONFIG_AMD_IOMMU */ static inline int amd_iommu_detect(void) { return -ENODEV; } -#endif +#endif /* CONFIG_AMD_IOMMU */ + +#if defined(CONFIG_AMD_IOMMU) && defined(CONFIG_IRQ_REMAP) + +/* IOMMU AVIC Function */ +extern int amd_iommu_register_ga_log_notifier(int (*notifier)(int, int, int)); + +#else /* defined(CONFIG_AMD_IOMMU) && defined(CONFIG_IRQ_REMAP) */ + +static inline int +amd_iommu_register_ga_log_notifier(int (*notifier)(int, int, int)) +{ + return 0; +} + +#endif /* defined(CONFIG_AMD_IOMMU) && defined(CONFIG_IRQ_REMAP) */ #endif /* _ASM_X86_AMD_IOMMU_H */