From patchwork Tue Dec 15 13:06:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Damm X-Patchwork-Id: 7854581 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B81EDBEEE1 for ; Tue, 15 Dec 2015 13:06:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4AB6F20304 for ; Tue, 15 Dec 2015 13:06:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3867A2035E for ; Tue, 15 Dec 2015 13:06:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933437AbbLONEy (ORCPT ); Tue, 15 Dec 2015 08:04:54 -0500 Received: from mail-pf0-f169.google.com ([209.85.192.169]:35837 "EHLO mail-pf0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932176AbbLONEw (ORCPT ); Tue, 15 Dec 2015 08:04:52 -0500 Received: by mail-pf0-f169.google.com with SMTP id 63so4739999pff.2; Tue, 15 Dec 2015 05:04:52 -0800 (PST) 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=WGUBCjUPRzc5MxUb1uMCgv2kmnOR08t0evHYqRqeBJc=; b=wm6tuYmdZbiXQ8H+Uw4SeqcSnchLvy6Se7l3e+OtF1SE1mCXqCk/dAGM3N4mie36Sy L78jA4gR7pbGO+H7vJedPOVxAfh6TtW372km+aSbAC0PpSN5FN1b6DiUlEtLJEvr/U0w sog9GAawH1xdsASPjidG3odkNbYmBJc7t3+m6w1HhIlmeszNdNSOLnvtv4+ZbuwfdUfz u//aiVXpASqHtwdINgfXk4s3Xj+Wv7GwKb1UzHz5qfdnOoXeY07UqEl4FZHq7Ui00+P2 zb99f5/6kWI0U55aLdVa2R4wBdD90EtsXmU9G2JwKS57uGWZfT0ScmRnUIJQrUkeLOL4 GWHg== X-Received: by 10.98.8.152 with SMTP id 24mr25651362pfi.122.1450184692230; Tue, 15 Dec 2015 05:04:52 -0800 (PST) Received: from [127.0.0.1] (s214090.ppp.asahi-net.or.jp. [220.157.214.90]) by smtp.gmail.com with ESMTPSA id y75sm2308023pfi.64.2015.12.15.05.04.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Dec 2015 05:04:51 -0800 (PST) From: Magnus Damm To: iommu@lists.linux-foundation.org Cc: laurent.pinchart+renesas@ideasonboard.com, geert+renesas@glider.be, linux-sh@vger.kernel.org, joro@8bytes.org, linux-kernel@vger.kernel.org, horms+renesas@verge.net.au, Magnus Damm Date: Tue, 15 Dec 2015 22:06:32 +0900 Message-Id: <20151215130632.13535.48038.sendpatchset@little-apple> In-Reply-To: <20151215130508.13535.26186.sendpatchset@little-apple> References: <20151215130508.13535.26186.sendpatchset@little-apple> Subject: [PATCH/RFC 09/10] iommu/ipmmu-vmsa: Add new IOMMU_DOMAIN_DMA ops Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@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, T_DKIM_INVALID, T_RP_MATCHES_RCVD, 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 and IOMMU_OF_DECLARE() used on r8a7795. The ->of_xlate() callback is wrapped in #ifdefs to also compile of x86_64. Signed-off-by: Magnus Damm --- drivers/iommu/ipmmu-vmsa.c | 89 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) -- To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- 0020/drivers/iommu/ipmmu-vmsa.c +++ work/drivers/iommu/ipmmu-vmsa.c 2015-12-15 21:23:05.770513000 +0900 @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -895,6 +896,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 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_4K, +#ifdef CONFIG_OF_IOMMU + .of_xlate = ipmmu_of_xlate_dma, +#endif +}; + /* ----------------------------------------------------------------------------- * Probe/remove and init */ @@ -1068,7 +1155,7 @@ static int __init ipmmu_vmsa_iommu_of_se { const struct of_device_id *match; const struct ipmmu_features *feature; - static const struct iommu_ops *ops = &ipmmu_ops; + static const struct iommu_ops *ops = &ipmmu_ops_dma; ipmmu_init();