Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752181AbaBHRcP (ORCPT ); Sat, 8 Feb 2014 12:32:15 -0500 Received: from mail-wi0-f180.google.com ([209.85.212.180]:40259 "EHLO mail-wi0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752120AbaBHRcK (ORCPT ); Sat, 8 Feb 2014 12:32:10 -0500 From: Antonios Motakis To: alex.williamson@redhat.com, kvmarm@lists.cs.columbia.edu, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org Cc: tech@virtualopensystems.com, a.rigo@virtualopensystems.com, B08248@freescale.com, kim.phillips@linaro.org, jan.kiszka@siemens.com, kvm@vger.kernel.org, R65777@freescale.com, B07421@freescale.com, christoffer.dall@linaro.org, agraf@suse.de, B16395@freescale.com, will.deacon@arm.com, Antonios Motakis Subject: [RFC PATCH v4 03/10] VFIO_IOMMU_TYPE1: workaround to build for platform devices Date: Sat, 8 Feb 2014 18:29:33 +0100 Message-Id: <1391880580-471-4-git-send-email-a.motakis@virtualopensystems.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1391880580-471-1-git-send-email-a.motakis@virtualopensystems.com> References: <1391880580-471-1-git-send-email-a.motakis@virtualopensystems.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 26b3d9d..bd50721 100644 --- a/drivers/vfio/Kconfig +++ b/drivers/vfio/Kconfig @@ -11,7 +11,7 @@ config VFIO_IOMMU_SPAPR_TCE 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 select VFIO_IOMMU_SPAPR_TCE if (PPC_POWERNV || PPC_PSERIES) help VFIO provides a framework for secure userspace device drivers. diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index ad7a1f6..81e65f4 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 @@ -47,6 +48,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; static bool disable_hugepages; module_param_named(disable_hugepages, @@ -785,7 +788,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); @@ -797,7 +801,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__); @@ -914,7 +918,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); -- 1.8.3.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/