From patchwork Tue Sep 20 13:44:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Damm X-Patchwork-Id: 9341711 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C5DE4607D0 for ; Tue, 20 Sep 2016 13:53:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B69BF296F4 for ; Tue, 20 Sep 2016 13:53:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AADB229778; Tue, 20 Sep 2016 13:53:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1CE0296F4 for ; Tue, 20 Sep 2016 13:53:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755213AbcITNxW (ORCPT ); Tue, 20 Sep 2016 09:53:22 -0400 Received: from mail-pa0-f66.google.com ([209.85.220.66]:35069 "EHLO mail-pa0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753882AbcITNxT (ORCPT ); Tue, 20 Sep 2016 09:53:19 -0400 Received: by mail-pa0-f66.google.com with SMTP id hi10so964971pac.2; Tue, 20 Sep 2016 06:53:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:date:message-id:in-reply-to:references:subject; bh=oYF/CQXm1Q1191CiQ0dUlbUIVRWrBlcETQaNrkMjya8=; b=PwRvhi7NSLgFaZ8rh3whuP3bK8vVhfUDEVwMMgpWcKB90sEJSl71jFIsdnzuUGqHZ1 XqEfp2Ex2Ljyc3Jtz0ZMGUN90PkJMgYsFGDNBNf70hnbn/yV7g5foq/TNuE0Avuv+mo8 9kc34kO0pILRm0j0bWwfpqQhkTGJ9PsmLIC9LzfIMb89TmwS9TudqLjjw1fMp1A+ir0G b2adroi557Gvau+2lWwlnwQ9zaiTp4RVQG4tRsGMwBOeE3InZDv2rdpAV8D9w1U/Ctis 8+fNC0moCw7SuvrCPAUaKxIhXVi+/K4w2+T7WnVv8xpi4vf+E5pDHZ4gMINhGRQ17ICs hnyA== 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:date:message-id:in-reply-to :references:subject; bh=oYF/CQXm1Q1191CiQ0dUlbUIVRWrBlcETQaNrkMjya8=; b=H+5+BaYv+iCGy9FMuEMe6+LWlKBKeGAJ9qpzD1ad+pUcNcgdVFv4v7TZaxQSj4db3b Ju68mE6Xf8f4rT97cIXTzi5vsUObuUsiqUGbA+K9TBK1onXJf94vsrAEvGnzIJBUT9sX ENwYwaCrwliCe6yOJRx+7CBQA/vvs0OV2EozpDS3pl3cKowZkrkGx540KKM5gT6juxXN QnFb6yZpNpOAScUP5oY8YzlRExhteLw6ncVwWBmUrMi1+DkZpMtdcSdDe1lIxxAnraXs ojgR2oltToxQCqHWK2G7xEF6IW9aXVrlDAgvWmxpABf5rET9ScYk+pDx0BiiuzGvy/Ro pKJw== X-Gm-Message-State: AE9vXwNKe7IewjOXzdGItlptbe28Ef/6tRp4NrHyESPaXOVpldalV3Tnxych0dxpZDP9xA== X-Received: by 10.66.134.18 with SMTP id pg18mr55935304pab.107.1474379598260; Tue, 20 Sep 2016 06:53:18 -0700 (PDT) Received: from [127.0.0.1] (s214090.ppp.asahi-net.or.jp. [220.157.214.90]) by smtp.gmail.com with ESMTPSA id q9sm34032141pfi.35.2016.09.20.06.53.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Sep 2016 06:53:17 -0700 (PDT) From: Magnus Damm To: iommu@lists.linux-foundation.org Cc: laurent.pinchart+renesas@ideasonboard.com, geert+renesas@glider.be, joro@8bytes.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, horms+renesas@verge.net.au, Magnus Damm , robin.murphy@arm.com, m.szyprowski@samsung.com Date: Tue, 20 Sep 2016 22:44:46 +0900 Message-Id: <20160920134446.25470.22322.sendpatchset@little-apple> In-Reply-To: <20160920134355.25470.93701.sendpatchset@little-apple> References: <20160920134355.25470.93701.sendpatchset@little-apple> Subject: [PATCH v5 05/07] iommu/ipmmu-vmsa: Add new IOMMU_DOMAIN_DMA ops Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Magnus Damm Introduce an alternative set of iommu_ops suitable for 64-bit ARM as well as 32-bit ARM when CONFIG_IOMMU_DMA=y. Also adjust the Kconfig to depend on ARM or IOMMU_DMA. Signed-off-by: Magnus Damm --- Changes since V4: - Added Kconfig hunk to depend on ARM or IOMMU_DMA Changes since V3: - Removed group parameter from ipmmu_init_platform_device() Changes since V2: - Included this new patch from the following series: [PATCH 00/04] iommu/ipmmu-vmsa: IPMMU CONFIG_IOMMU_DMA update - Use only a single iommu_ops structure with #ifdef CONFIG_IOMMU_DMA - Folded in #ifdefs to handle CONFIG_ARM and CONFIG_IOMMU_DMA - of_xlate() is now used without #ifdefs - Made sure code compiles on both 32-bit and 64-bit ARM. drivers/iommu/Kconfig | 1 drivers/iommu/ipmmu-vmsa.c | 111 ++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 104 insertions(+), 8 deletions(-) --- 0001/drivers/iommu/Kconfig +++ work/drivers/iommu/Kconfig 2016-09-20 22:10:15.280607110 +0900 @@ -274,6 +274,7 @@ config EXYNOS_IOMMU_DEBUG config IPMMU_VMSA bool "Renesas VMSA-compatible IPMMU" + depends on ARM || IOMMU_DMA depends on ARM_LPAE depends on ARCH_RENESAS || COMPILE_TEST select IOMMU_API --- 0006/drivers/iommu/ipmmu-vmsa.c +++ work/drivers/iommu/ipmmu-vmsa.c 2016-09-20 22:08:58.300607110 +0900 @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -22,8 +23,10 @@ #include #include +#if defined(CONFIG_ARM) && !defined(CONFIG_IOMMU_DMA) #include #include +#endif #include "io-pgtable.h" @@ -520,14 +523,6 @@ static struct iommu_domain *__ipmmu_doma return &domain->io_domain; } -static struct iommu_domain *ipmmu_domain_alloc(unsigned type) -{ - if (type != IOMMU_DOMAIN_UNMANAGED) - return NULL; - - return __ipmmu_domain_alloc(type); -} - static void ipmmu_domain_free(struct iommu_domain *io_domain) { struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain); @@ -714,6 +709,8 @@ error: return ret; } +#if defined(CONFIG_ARM) && !defined(CONFIG_IOMMU_DMA) + static int ipmmu_add_device(struct device *dev) { struct ipmmu_vmsa_archdata *archdata; @@ -807,6 +804,14 @@ static void ipmmu_remove_device(struct d dev->archdata.iommu = NULL; } +static struct iommu_domain *ipmmu_domain_alloc(unsigned type) +{ + if (type != IOMMU_DOMAIN_UNMANAGED) + return NULL; + + return __ipmmu_domain_alloc(type); +} + static const struct iommu_ops ipmmu_ops = { .domain_alloc = ipmmu_domain_alloc, .domain_free = ipmmu_domain_free, @@ -821,6 +826,94 @@ static const struct iommu_ops ipmmu_ops .pgsize_bitmap = SZ_1G | SZ_2M | SZ_4K, }; +#endif /* !CONFIG_ARM && CONFIG_IOMMU_DMA */ + +#ifdef CONFIG_IOMMU_DMA + +static struct iommu_domain *ipmmu_domain_alloc_dma(unsigned type) +{ + struct iommu_domain *io_domain; + + if (type != IOMMU_DOMAIN_DMA) + return NULL; + + io_domain = __ipmmu_domain_alloc(type); + if (io_domain) + iommu_get_dma_cookie(io_domain); + + return io_domain; +} + +static void ipmmu_domain_free_dma(struct iommu_domain *io_domain) +{ + iommu_put_dma_cookie(io_domain); + ipmmu_domain_free(io_domain); +} + +static int ipmmu_add_device_dma(struct device *dev) +{ + struct iommu_group *group; + + /* only accept devices with iommus property */ + if (of_count_phandle_with_args(dev->of_node, "iommus", + "#iommu-cells") < 0) + return -ENODEV; + + group = iommu_group_get_for_dev(dev); + if (IS_ERR(group)) + return PTR_ERR(group); + + return 0; +} + +static void ipmmu_remove_device_dma(struct device *dev) +{ + iommu_group_remove_device(dev); +} + +static struct iommu_group *ipmmu_device_group_dma(struct device *dev) +{ + struct iommu_group *group; + int ret; + + group = generic_device_group(dev); + if (IS_ERR(group)) + return group; + + ret = ipmmu_init_platform_device(dev); + if (ret) { + iommu_group_put(group); + group = ERR_PTR(ret); + } + + return group; +} + +static int ipmmu_of_xlate_dma(struct device *dev, + struct of_phandle_args *spec) +{ + /* dummy callback to satisfy of_iommu_configure() */ + return 0; +} + +static const struct iommu_ops ipmmu_ops = { + .domain_alloc = ipmmu_domain_alloc_dma, + .domain_free = ipmmu_domain_free_dma, + .attach_dev = ipmmu_attach_device, + .detach_dev = ipmmu_detach_device, + .map = ipmmu_map, + .unmap = ipmmu_unmap, + .map_sg = default_iommu_map_sg, + .iova_to_phys = ipmmu_iova_to_phys, + .add_device = ipmmu_add_device_dma, + .remove_device = ipmmu_remove_device_dma, + .device_group = ipmmu_device_group_dma, + .pgsize_bitmap = SZ_1G | SZ_2M | SZ_4K, + .of_xlate = ipmmu_of_xlate_dma, +}; + +#endif /* CONFIG_IOMMU_DMA */ + /* ----------------------------------------------------------------------------- * Probe/remove and init */ @@ -910,7 +1003,9 @@ static int ipmmu_remove(struct platform_ list_del(&mmu->list); spin_unlock(&ipmmu_devices_lock); +#if defined(CONFIG_ARM) && !defined(CONFIG_IOMMU_DMA) arm_iommu_release_mapping(mmu->mapping); +#endif ipmmu_device_reset(mmu);