From patchwork Mon Jul 17 13:05:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Damm X-Patchwork-Id: 9844913 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 DED5D6037F for ; Mon, 17 Jul 2017 13:09:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D20D126E4A for ; Mon, 17 Jul 2017 13:09:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C6B1028505; Mon, 17 Jul 2017 13:09: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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 505C826E4A for ; Mon, 17 Jul 2017 13:09:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751471AbdGQNJH (ORCPT ); Mon, 17 Jul 2017 09:09:07 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:33024 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751314AbdGQNJE (ORCPT ); Mon, 17 Jul 2017 09:09:04 -0400 Received: by mail-pf0-f195.google.com with SMTP id e199so19589698pfh.0; Mon, 17 Jul 2017 06:09:03 -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=NEb7v4yc5yDvswjl4E00phUcQca1NfDqvX338xGoZto=; b=CQdIPe0rqXyxjoJjdSFQO4kwiOIN8mRFv69iC2LETLfjvGKjqWuIg8ICSE8BCrQH7q 2oRQ+kbaOVxqG19C4GIzlo04RFcp0sOmRki7xTzYdyUdBc4zqyWwpUOMgDfyu7FuCXDq m24NIz9FqtDie9QM83ftOPeonuDz7Buo+THAI5tpmzQqm3zLxNTu9fJqtPn8cFqsV0T1 5s8D7aLqqBZnJ1y8EIu4iv2wzUlGyyXDL2YptlBHsmTi0OCgb34UGiDbnhYfQ6iu3+sT 6GA3Ciz3ZSmJHm8MmKD8gTUR4Ct3ivP3D8dyBCPVFufCrsVyFOIqn1jXdpJXRyXtxQyr tf5g== 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=NEb7v4yc5yDvswjl4E00phUcQca1NfDqvX338xGoZto=; b=LRYrwlBPYvE7Kr3B/JETXdnw4ZDN5+wbO8sGCRFTulWS2pFrP2BN6MjH+PgRfKE4C1 zHtGiZ7F686c8ICh0ZVwPtdzN4g2T958ZkIrXfOt2zecPeCIOJBnQrflKYI38ROSyscd tdjfkV2Sxqp0scN1eXKr43NJgZBRGJOl43Pjxga4jtg5zQdR44FNAF7m3VCEmaJzgznR /kdqkNTtwlIHRDttxNZNb4AQmtJgAwulXMlLYYankXPhZrALT1lKQ7yWaICd7wvMCbKl gFCQjnZCqt58DuaF2V4xJM+vRm8mo++E4/LRBersIrZoNPxEoaP0Feu+06buiP67sM1e jpjA== X-Gm-Message-State: AIVw113aOOjivYhGM4Q0Pxnd9mR/2lqqnLAuYGu2YZgJHmBeh1hR1OkQ M7A/mi4IBIzPqg== X-Received: by 10.99.102.68 with SMTP id a65mr28398140pgc.252.1500296943436; Mon, 17 Jul 2017 06:09:03 -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 n90sm34017086pfk.105.2017.07.17.06.08.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Jul 2017 06:09:02 -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: Mon, 17 Jul 2017 22:05:41 +0900 Message-Id: <150029674139.22030.9234811024185570759.sendpatchset@little-apple> In-Reply-To: <150029669967.22030.8059216113725566341.sendpatchset@little-apple> References: <150029669967.22030.8059216113725566341.sendpatchset@little-apple> Subject: [PATCH v2 04/05] iommu/ipmmu-vmsa: Replace local utlb code with fwspec ids 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 Now when both 32-bit and 64-bit code inside the driver is using fwspec it is possible to replace the utlb handling with fwspec ids that get populated from ->of_xlate(). Suggested-by: Robin Murphy Signed-off-by: Magnus Damm --- Changes since V1: - Rebased to apply on top of earlier changes in series drivers/iommu/ipmmu-vmsa.c | 104 ++++++++------------------------------------ 1 file changed, 19 insertions(+), 85 deletions(-) --- 0006/drivers/iommu/ipmmu-vmsa.c +++ work/drivers/iommu/ipmmu-vmsa.c 2017-07-17 21:12:11.650607110 +0900 @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -59,8 +60,6 @@ struct ipmmu_vmsa_domain { struct ipmmu_vmsa_iommu_priv { struct ipmmu_vmsa_device *mmu; - unsigned int *utlbs; - unsigned int num_utlbs; struct device *dev; struct list_head list; }; @@ -550,13 +549,14 @@ static int ipmmu_attach_device(struct io struct device *dev) { struct ipmmu_vmsa_iommu_priv *priv = to_priv(dev); + struct iommu_fwspec *fwspec = dev->iommu_fwspec; struct ipmmu_vmsa_device *mmu = priv->mmu; struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain); unsigned long flags; unsigned int i; int ret = 0; - if (!mmu) { + if (!priv || !priv->mmu) { dev_err(dev, "Cannot attach to IPMMU\n"); return -ENXIO; } @@ -583,8 +583,8 @@ static int ipmmu_attach_device(struct io if (ret < 0) return ret; - for (i = 0; i < priv->num_utlbs; ++i) - ipmmu_utlb_enable(domain, priv->utlbs[i]); + for (i = 0; i < fwspec->num_ids; ++i) + ipmmu_utlb_enable(domain, fwspec->ids[i]); return 0; } @@ -592,12 +592,12 @@ static int ipmmu_attach_device(struct io static void ipmmu_detach_device(struct iommu_domain *io_domain, struct device *dev) { - struct ipmmu_vmsa_iommu_priv *priv = to_priv(dev); + struct iommu_fwspec *fwspec = dev->iommu_fwspec; struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain); unsigned int i; - for (i = 0; i < priv->num_utlbs; ++i) - ipmmu_utlb_disable(domain, priv->utlbs[i]); + for (i = 0; i < fwspec->num_ids; ++i) + ipmmu_utlb_disable(domain, fwspec->ids[i]); /* * TODO: Optimize by disabling the context when no device is attached. @@ -633,102 +633,36 @@ static phys_addr_t ipmmu_iova_to_phys(st return domain->iop->iova_to_phys(domain->iop, iova); } -static int ipmmu_find_utlbs(struct ipmmu_vmsa_device *mmu, struct device *dev, - unsigned int *utlbs, unsigned int num_utlbs) -{ - unsigned int i; - - for (i = 0; i < num_utlbs; ++i) { - struct of_phandle_args args; - int ret; - - ret = of_parse_phandle_with_args(dev->of_node, "iommus", - "#iommu-cells", i, &args); - if (ret < 0) - return ret; - - of_node_put(args.np); - - if (args.np != mmu->dev->of_node || args.args_count != 1) - return -EINVAL; - - utlbs[i] = args.args[0]; - } - - return 0; -} - -static int ipmmu_init_platform_device(struct device *dev) +static int ipmmu_init_platform_device(struct device *dev, + struct of_phandle_args *args) { + struct platform_device *ipmmu_pdev; struct ipmmu_vmsa_iommu_priv *priv; - struct ipmmu_vmsa_device *mmu; - unsigned int *utlbs; - unsigned int i; - int num_utlbs; - int ret = -ENODEV; - - /* Find the master corresponding to the device. */ - num_utlbs = of_count_phandle_with_args(dev->of_node, "iommus", - "#iommu-cells"); - if (num_utlbs < 0) + ipmmu_pdev = of_find_device_by_node(args->np); + if (!ipmmu_pdev) return -ENODEV; - utlbs = kcalloc(num_utlbs, sizeof(*utlbs), GFP_KERNEL); - if (!utlbs) - return -ENOMEM; - - spin_lock(&ipmmu_devices_lock); - - list_for_each_entry(mmu, &ipmmu_devices, list) { - ret = ipmmu_find_utlbs(mmu, dev, utlbs, num_utlbs); - if (!ret) { - /* - * TODO Take a reference to the MMU to protect - * against device removal. - */ - break; - } - } - - spin_unlock(&ipmmu_devices_lock); - - if (ret < 0) - goto error; - - for (i = 0; i < num_utlbs; ++i) { - if (utlbs[i] >= mmu->num_utlbs) { - ret = -EINVAL; - goto error; - } - } - priv = kzalloc(sizeof(*priv), GFP_KERNEL); - if (!priv) { - ret = -ENOMEM; - goto error; - } + if (!priv) + return -ENOMEM; - priv->mmu = mmu; - priv->utlbs = utlbs; - priv->num_utlbs = num_utlbs; + priv->mmu = platform_get_drvdata(ipmmu_pdev); priv->dev = dev; dev->iommu_fwspec->iommu_priv = priv; return 0; - -error: - kfree(utlbs); - return ret; } static int ipmmu_of_xlate(struct device *dev, struct of_phandle_args *spec) { + iommu_fwspec_add_ids(dev, spec->args, 1); + /* Initialize once - xlate() will call multiple times */ if (to_priv(dev)) return 0; - return ipmmu_init_platform_device(dev); + return ipmmu_init_platform_device(dev, spec); } #if defined(CONFIG_ARM) && !defined(CONFIG_IOMMU_DMA)