From patchwork Mon Sep 30 15:28:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonios Motakis X-Patchwork-Id: 2966171 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 56978BFF0B for ; Mon, 30 Sep 2013 15:29:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 27014201C8 for ; Mon, 30 Sep 2013 15:29:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BFCDB20274 for ; Mon, 30 Sep 2013 15:29:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756000Ab3I3P3P (ORCPT ); Mon, 30 Sep 2013 11:29:15 -0400 Received: from mail-wg0-f50.google.com ([74.125.82.50]:41601 "EHLO mail-wg0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755286Ab3I3P3O (ORCPT ); Mon, 30 Sep 2013 11:29:14 -0400 Received: by mail-wg0-f50.google.com with SMTP id f12so5926116wgh.5 for ; Mon, 30 Sep 2013 08:29:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Rq104829IrpN0JHcQfbD2Uxy7sQnDXd6zWaC226Er1E=; b=BAxVVJN6ainclHH/9KrswZTRfavFYWLo6gF3dkWDB2IqcPEqxlTMrXOQlsblr753mj Aottdd/4b1uQCXhLXDXiF5VKYvG93LNStzwnDbNY+SyO/II+D4STCvPSWPWZOOZPg9ot w0ap0MMhRqkpqk127zj+B+91z8W5LQA29TwciU1D9eAiNGQP9ufXpX5apUJxPbR0Qh5h AjvREANyapB7nMC7nc2QI+ikq/W47lYq5+nWlWLJxMK23rYFvAYJM/Cdp6pY5jUj+ZRc jwQvLW6Be9/sE4QIcWxAIWNeNFey7idIEF0+gmV6s9w8QfF8V2OuvaHY0ObdVegYbs7S FH6g== X-Gm-Message-State: ALoCoQkkH4PF1grUTE8O60O6pC6uhbN38f9EpDx+7f9BLJnqurcZii6D8iuZKOir58H7Nu0T58FE X-Received: by 10.180.187.175 with SMTP id ft15mr14449051wic.20.1380554953290; Mon, 30 Sep 2013 08:29:13 -0700 (PDT) Received: from localhost.localdomain (home.tvelocity.eu. [82.67.68.96]) by mx.google.com with ESMTPSA id ey4sm2015579wic.11.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 30 Sep 2013 08:29:12 -0700 (PDT) From: Antonios Motakis To: kvmarm@lists.cs.columbia.edu, alex.williamson@redhat.com Cc: iommu@lists.linux-foundation.org, linux-samsung-soc@vger.kernel.org, kvm@vger.kernel.org, agraf@suse.de, B08248@freescale.com, tech@virtualopensystems.com, Antonios Motakis Subject: [PATCH 1/7] VFIO_IOMMU_TYPE1 workaround to build for platform devices Date: Mon, 30 Sep 2013 17:28:37 +0200 Message-Id: <1380554923-17818-2-git-send-email-a.motakis@virtualopensystems.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1380554923-17818-1-git-send-email-a.motakis@virtualopensystems.com> References: <1380554923-17818-1-git-send-email-a.motakis@virtualopensystems.com> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is a workaround to make the VFIO_IOMMU_TYPE1 driver usable with platform devices instead of PCI. A future permanent fix should support both. This is required in order to use the Exynos SMMU, or ARM SMMU driver with VFIO. Signed-off-by: Antonios Motakis --- drivers/vfio/Kconfig | 2 +- drivers/vfio/vfio_iommu_type1.c | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/drivers/vfio/Kconfig b/drivers/vfio/Kconfig index 7cd5dec..1f84eda 100644 --- a/drivers/vfio/Kconfig +++ b/drivers/vfio/Kconfig @@ -6,7 +6,7 @@ config VFIO_IOMMU_TYPE1 menuconfig VFIO tristate "VFIO Non-Privileged userspace driver framework" depends on IOMMU_API - select VFIO_IOMMU_TYPE1 if X86 + select VFIO_IOMMU_TYPE1 if X86 || ARM help VFIO provides a framework for secure userspace device drivers. See Documentation/vfio.txt for more details. diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 6f3fbc4..d7e6a12 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -30,7 +30,8 @@ #include #include #include -#include /* pci_bus_type */ +#include /* pci_bus_type */ +#include /* platform_bus_type */ #include #include #include @@ -46,6 +47,8 @@ module_param_named(allow_unsafe_interrupts, allow_unsafe_interrupts, bool, S_IRUGO | S_IWUSR); MODULE_PARM_DESC(allow_unsafe_interrupts, "Enable VFIO IOMMU support for on platforms without interrupt remapping support."); +static struct bus_type *iommu_bus_type = NULL; +static bool require_cap_intr_remap = false; struct vfio_iommu { struct iommu_domain *domain; @@ -612,7 +615,8 @@ static void *vfio_iommu_type1_open(unsigned long arg) /* * Wish we didn't have to know about bus_type here. */ - iommu->domain = iommu_domain_alloc(&pci_bus_type); + iommu->domain = iommu_domain_alloc(iommu_bus_type); + if (!iommu->domain) { kfree(iommu); return ERR_PTR(-EIO); @@ -624,7 +628,7 @@ static void *vfio_iommu_type1_open(unsigned long arg) * the way. Fortunately we know interrupt remapping is global for * our iommus. */ - if (!allow_unsafe_interrupts && + if (require_cap_intr_remap && !allow_unsafe_interrupts && !iommu_domain_has_cap(iommu->domain, IOMMU_CAP_INTR_REMAP)) { pr_warn("%s: No interrupt remapping support. Use the module param \"allow_unsafe_interrupts\" to enable VFIO IOMMU support on this platform\n", __func__); @@ -733,7 +737,17 @@ static const struct vfio_iommu_driver_ops vfio_iommu_driver_ops_type1 = { static int __init vfio_iommu_type1_init(void) { - if (!iommu_present(&pci_bus_type)) +#ifdef CONFIG_PCI + if (iommu_present(&pci_bus_type)) { + iommu_bus_type = &pci_bus_type; + /* For PCI targets, IOMMU_CAP_INTR_REMAP is required */ + require_cap_intr_remap = true; + } +#endif + if (!iommu_bus_type && iommu_present(&platform_bus_type)) + iommu_bus_type = &platform_bus_type; + + if(!iommu_bus_type) return -ENODEV; return vfio_register_iommu_driver(&vfio_iommu_driver_ops_type1);