From patchwork Tue Mar 15 17:05:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Damm X-Patchwork-Id: 8590511 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-renesas-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 876809F44D for ; Tue, 15 Mar 2016 17:02:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D422F20272 for ; Tue, 15 Mar 2016 17:02:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E17B3202C8 for ; Tue, 15 Mar 2016 17:02:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965326AbcCORBy (ORCPT ); Tue, 15 Mar 2016 13:01:54 -0400 Received: from mail-pf0-f182.google.com ([209.85.192.182]:32910 "EHLO mail-pf0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965500AbcCORBv (ORCPT ); Tue, 15 Mar 2016 13:01:51 -0400 Received: by mail-pf0-f182.google.com with SMTP id 124so36362650pfg.0; Tue, 15 Mar 2016 10:01:50 -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=JRvCgYsJPY08i9DS6zPnAM8eT7jRnCVYanzyDA83iIg=; b=If9Q2uZwJBFM4wCzK/TMz6smijCNiNGW8AvDHubCd6PMxRb9PJn/gOk75LSUUxMzBs NZygFtUV6INcnx8PR2ok52Y2tL3I+rMnzs6sSBBrI6QZBWFyyhYzvJZkqj5ZDBFDcceI sR09DiMPjsqiO+W7hq8OVQ2UAI2Ke0UlS6VcHseAcmRukSajIv0oBaBLd4pNCvFjpPTp 7oqysnIZpq9D8DjOudunPQTOtFqiyhbI8pl3PEvWur00cU0LovUoue3s8j/s8iiZt4Ux 29PI7FeuQGYWSXi+jElfGaQwr7Dy6cm0Iio6tnyz3Dbzq2u1SbyalmsuGmnoD/JE0lWT t7+Q== 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=JRvCgYsJPY08i9DS6zPnAM8eT7jRnCVYanzyDA83iIg=; b=JvkK2rptzdjxo1VQaSengvavaRcmwNm6UfTUet056lCWIKRPj4wF/i7+ir1LpJ0DPy snz+SxRQDrEjJoKV5Lg5Vji8QrZDfcoERiSC3RqFo2lqRbrCXPHYI7CtDuRM0V7LnsUy u5mp+0pbhV5Yzor1LS8zlPHsyfLtLVooFX9CEl/UwxHjQzETg5vm9WDQMub473IYpnUm UeN46BO4xPLYJClCoL8gO3D+WqdclkXdLL5sfM6ilOzv4u/hv7CzpMFunEqTFZ5zLc+a D8WabF3Y5tBOn0saV3M0TBcr7D431gSfX1fzMdYk9LTwy+l5K5W4+fSyNN1QJpqiWqWV KYBA== X-Gm-Message-State: AD7BkJJG3k4HMdGarePLdOqFiQNHdxwzD5kuUZrP8N0kbcGmEUb272iuLJHI6gx3VwfVtA== X-Received: by 10.66.220.66 with SMTP id pu2mr48351018pac.115.1458061310198; Tue, 15 Mar 2016 10:01:50 -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 n11sm40906293pfb.74.2016.03.15.10.01.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Mar 2016 10:01:49 -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: Wed, 16 Mar 2016 02:05:10 +0900 Message-Id: <20160315170510.20615.16557.sendpatchset@little-apple> In-Reply-To: <20160315170431.20615.30333.sendpatchset@little-apple> References: <20160315170431.20615.30333.sendpatchset@little-apple> Subject: [PATCH 04/04] 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-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable 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 From: Magnus Damm Introduce a new set of iommu_ops suitable for 64-bit ARM as well as 32-bit ARM when CONFIG_IOMMU_DMA=y. The ->of_xlate() callback is needed by the code exported by of_iommu.h and it is wrapped in #ifdefs to also compile of x86_64. Signed-off-by: Magnus Damm Reviewed-by: Laurent Pinchart --- drivers/iommu/ipmmu-vmsa.c | 94 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 2 deletions(-) --- 0011/drivers/iommu/ipmmu-vmsa.c +++ work/drivers/iommu/ipmmu-vmsa.c 2016-03-16 01:35:06.990513000 +0900 @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -804,7 +805,7 @@ static void ipmmu_remove_device(struct d dev->archdata.iommu = NULL; } -static const struct iommu_ops ipmmu_ops = { +static const struct iommu_ops __maybe_unused ipmmu_ops = { .domain_alloc = ipmmu_domain_alloc, .domain_free = ipmmu_domain_free, .attach_dev = ipmmu_attach_device, @@ -818,6 +819,92 @@ static const struct iommu_ops ipmmu_ops .pgsize_bitmap = SZ_1G | SZ_2M | SZ_4K, }; +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, group); + if (ret) { + iommu_group_put(group); + group = ERR_PTR(ret); + } + + return group; +} + +#ifdef CONFIG_OF_IOMMU +static int ipmmu_of_xlate_dma(struct device *dev, + struct of_phandle_args *spec) +{ + /* dummy callback to satisfy of_iommu_configure() */ + return 0; +} +#endif + +static const struct iommu_ops __maybe_unused ipmmu_ops_dma = { + .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, +#ifdef CONFIG_OF_IOMMU + .of_xlate = ipmmu_of_xlate_dma, +#endif +}; + /* ----------------------------------------------------------------------------- * Probe/remove and init */ @@ -929,14 +1016,17 @@ static struct platform_driver ipmmu_driv static int __init ipmmu_init(void) { + const struct iommu_ops *ops; int ret; ret = platform_driver_register(&ipmmu_driver); if (ret < 0) return ret; + ops = IS_ENABLED(CONFIG_IOMMU_DMA) ? &ipmmu_ops_dma : &ipmmu_ops; + if (!iommu_present(&platform_bus_type)) - bus_set_iommu(&platform_bus_type, &ipmmu_ops); + bus_set_iommu(&platform_bus_type, ops); return 0; }