From patchwork Thu Jun 15 10:29:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Damm X-Patchwork-Id: 9788493 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 2945F60384 for ; Thu, 15 Jun 2017 10:33:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 196E3284C5 for ; Thu, 15 Jun 2017 10:33:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D7D5284DC; Thu, 15 Jun 2017 10:33:33 +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=unavailable 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 AF912284C5 for ; Thu, 15 Jun 2017 10:33:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752360AbdFOKdU (ORCPT ); Thu, 15 Jun 2017 06:33:20 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:33416 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752352AbdFOKdT (ORCPT ); Thu, 15 Jun 2017 06:33:19 -0400 Received: by mail-pg0-f68.google.com with SMTP id a70so1251938pge.0; Thu, 15 Jun 2017 03:33:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:date:message-id:in-reply-to:references:subject; bh=5gBD7CksvmLO20sDgFo3GcziOWaeoZ8PAaEtHexmB2w=; b=Q1ZMwxquWRSgaD19wWq9k8C9z6aMjKaQxl4eDu43PHUmCwRJHhSHiTXxdiFsV/xdUw phxzNmqiQe6s/RnxJ2CDqEZ39xIxZZIjrX1wygtcqfvuQVs5my8PNLkU2YfuV727EbY9 me02kayNINUr9aRH8Qaa1kuzPSUWqye19+R/Pofh7aObKk5lEQu4qg9xVnTtcI08xRv4 ZENffqEZicLOYjEkTNwnndkT8guAicwgrK2r/+kBgDhv7JKWP9UC5xioA/CXrZPRUkmy 6qlusif+p9tS1X/bjr1ObtAYFRj+ZwGWyRWB8wjffTTymQ7Jvc9l9gwA8MBBMvK+9Z4L bgAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:date:message-id:in-reply-to :references:subject; bh=5gBD7CksvmLO20sDgFo3GcziOWaeoZ8PAaEtHexmB2w=; b=kZAVBYb//YsnmcyLuFNrfuwty7Cxo7CKslVQBZOxaYBFm3kT9OlEJ4iLwr7x7Ayxjb KwVvtPczIn28B4CrZoSTgJMGdDABjrzgZ8kV2XGt6pYX5r4KWbvt1HQXazAkSr+SLzy3 UU9Dzn4b0tsTxYOLIFoRCslw+Fw9NjJ9W8ERio+p/ir/qhEw9EM8JYeZfSGbLp2ekiyV Dxs3BIYiDc+gnv9TCgQNlhqS2rzyNoBQowv3FOf9NslSP7JFBlDBpefGpHKnmXHbWEb4 Qjbncm0zMr1DvJuo5XbENg/TTG5yPhTmWkuw7aZ/BN4QZOAGqlDb6fBcfDNY+jPHExWj TLkA== X-Gm-Message-State: AKS2vOwQWlpvbXkIXLwu21rV58HBpWgc8reMKxRMKOAnJYgC/zr26t5G As+h7bTVmRQzEg== X-Received: by 10.84.143.68 with SMTP id 62mr5473102ply.123.1497522798662; Thu, 15 Jun 2017 03:33: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 c27sm5120757pfj.107.2017.06.15.03.33.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Jun 2017 03:33:17 -0700 (PDT) From: Magnus Damm To: joro@8bytes.org Cc: laurent.pinchart+renesas@ideasonboard.com, geert+renesas@glider.be, sricharan@codeaurora.org, will.deacon@arm.com, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, iommu@lists.linux-foundation.org, horms+renesas@verge.net.au, Magnus Damm , robin.murphy@arm.com, m.szyprowski@samsung.com Date: Thu, 15 Jun 2017 19:29:27 +0900 Message-Id: <149752256764.21887.17904093211691192196.sendpatchset@little-apple> In-Reply-To: <149752254550.21887.15183665699230243235.sendpatchset@little-apple> References: <149752254550.21887.15183665699230243235.sendpatchset@little-apple> Subject: [PATCH 02/04] iommu/ipmmu-vmsa: Consistent ->of_xlate() handling 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 The 32-bit ARM code gets updated to make use of ->of_xlate() and the code is shared between 64-bit and 32-bit ARM. The of_device_is_available() check gets dropped since it is included in of_iommu_xlate(). Suggested-by: Robin Murphy Signed-off-by: Magnus Damm --- drivers/iommu/ipmmu-vmsa.c | 51 ++++++++++++++------------------------------ 1 file changed, 17 insertions(+), 34 deletions(-) --- 0009/drivers/iommu/ipmmu-vmsa.c +++ work/drivers/iommu/ipmmu-vmsa.c 2017-06-15 17:22:27.460607110 +0900 @@ -680,6 +680,10 @@ static int ipmmu_init_platform_device(st int num_utlbs; int ret = -ENODEV; + /* Initialize once - xlate() will call multiple times */ + if (to_priv(dev)) + return 0; + /* Find the master corresponding to the device. */ num_utlbs = of_count_phandle_with_args(dev->of_node, "iommus", @@ -734,6 +738,12 @@ error: return ret; } +static int ipmmu_of_xlate(struct device *dev, + struct of_phandle_args *spec) +{ + return ipmmu_init_platform_device(dev); +} + #if defined(CONFIG_ARM) && !defined(CONFIG_IOMMU_DMA) static struct iommu_domain *ipmmu_domain_alloc(unsigned type) @@ -750,11 +760,11 @@ static int ipmmu_add_device(struct devic struct iommu_group *group; int ret; - if (to_priv(dev)) { - dev_warn(dev, "IOMMU driver already assigned to device %s\n", - dev_name(dev)); - return -EINVAL; - } + /* + * Only let through devices that have been verified in xlate() + */ + if (!to_priv(dev)) + return -ENODEV; /* Create a device group and add the device to it. */ group = iommu_group_alloc(); @@ -773,10 +783,6 @@ static int ipmmu_add_device(struct devic goto error; } - ret = ipmmu_init_platform_device(dev); - if (ret < 0) - goto error; - /* * Create the ARM mapping, used by the ARM DMA mapping core to allocate * VAs. This will allocate a corresponding IOMMU domain. @@ -817,24 +823,13 @@ error: if (!IS_ERR_OR_NULL(group)) iommu_group_remove_device(dev); - kfree(to_priv(dev)->utlbs); - kfree(to_priv(dev)); - set_priv(dev, NULL); - return ret; } static void ipmmu_remove_device(struct device *dev) { - struct ipmmu_vmsa_iommu_priv *priv = to_priv(dev); - arm_iommu_detach_device(dev); iommu_group_remove_device(dev); - - kfree(priv->utlbs); - kfree(priv); - - set_priv(dev, NULL); } static const struct iommu_ops ipmmu_ops = { @@ -849,6 +844,7 @@ static const struct iommu_ops ipmmu_ops .add_device = ipmmu_add_device, .remove_device = ipmmu_remove_device, .pgsize_bitmap = SZ_1G | SZ_2M | SZ_4K, + .of_xlate = ipmmu_of_xlate, }; #endif /* !CONFIG_ARM && CONFIG_IOMMU_DMA */ @@ -958,19 +954,6 @@ static struct iommu_group *ipmmu_find_gr return group; } -static int ipmmu_of_xlate_dma(struct device *dev, - struct of_phandle_args *spec) -{ - /* If the IPMMU device is disabled in DT then return error - * to make sure the of_iommu code does not install ops - * even though the iommu device is disabled - */ - if (!of_device_is_available(spec->np)) - return -ENODEV; - - return ipmmu_init_platform_device(dev); -} - static const struct iommu_ops ipmmu_ops = { .domain_alloc = ipmmu_domain_alloc_dma, .domain_free = ipmmu_domain_free_dma, @@ -984,7 +967,7 @@ static const struct iommu_ops ipmmu_ops .remove_device = ipmmu_remove_device_dma, .device_group = ipmmu_find_group_dma, .pgsize_bitmap = SZ_1G | SZ_2M | SZ_4K, - .of_xlate = ipmmu_of_xlate_dma, + .of_xlate = ipmmu_of_xlate, }; #endif /* CONFIG_IOMMU_DMA */