From patchwork Tue Aug 5 10:47:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 34937 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f198.google.com (mail-pd0-f198.google.com [209.85.192.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7F4A220523 for ; Tue, 5 Aug 2014 10:51:15 +0000 (UTC) Received: by mail-pd0-f198.google.com with SMTP id fp1sf4685789pdb.1 for ; Tue, 05 Aug 2014 03:51:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list:content-type :content-transfer-encoding; bh=JK0C5ocCqaJ09bjhiqCo1sEwIAqiJXasvBXECaYUmD0=; b=KtTBladZ5aSPIHQY0Jx4ELJH0GJ0i8+4EGElFCgLoQBzKb3yQaeRQRGGfd303KM+KR YzTYzuzf95ibs9/T0QxGoaiaxQhb1hFTKfKwUsKdnQiBtAel1opwtLfjYMUL2b+4AA5w UexZSLtFVS2QOFYHnY14ah8cv1mpHww4lSRYEAopIM1loGbHD23YhaKUQvU800c2h3Qn GOLAH0BCqoDi0d6g0WNtgSb4N6ED9cKTQyqGKqrqS4wfNO3cePNBTQM6rnHh45jMgERR CGit4f/un3yBtj0KzTjRXUy+lMpT8JfBIgPhpeQZBsfIbA+iO0wa+a3ZcLIekaXoKzoj dZ5w== X-Gm-Message-State: ALoCoQkjoteb/5Ku+i1dPPWx2rV/VZlx4wc126I5QzG4F3mVHp0JnSqoT+TXgD+LiQF/WI2+yN/b X-Received: by 10.70.40.172 with SMTP id y12mr842369pdk.8.1407235874768; Tue, 05 Aug 2014 03:51:14 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.97.52 with SMTP id l49ls190077qge.69.gmail; Tue, 05 Aug 2014 03:51:14 -0700 (PDT) X-Received: by 10.220.133.13 with SMTP id d13mr392985vct.66.1407235874608; Tue, 05 Aug 2014 03:51:14 -0700 (PDT) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id th5si784158vdb.39.2014.08.05.03.51.14 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 05 Aug 2014 03:51:14 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 as permitted sender) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id ik5so1090948vcb.20 for ; Tue, 05 Aug 2014 03:51:14 -0700 (PDT) X-Received: by 10.52.144.232 with SMTP id sp8mr828300vdb.61.1407235874509; Tue, 05 Aug 2014 03:51:14 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp374712vcb; Tue, 5 Aug 2014 03:51:13 -0700 (PDT) X-Received: by 10.140.27.108 with SMTP id 99mr3940855qgw.77.1407235873812; Tue, 05 Aug 2014 03:51:13 -0700 (PDT) Received: from ip-10-141-164-156.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id s11si2141770qgs.97.2014.08.05.03.51.13 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 05 Aug 2014 03:51:13 -0700 (PDT) Received-SPF: none (google.com: linaro-mm-sig-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-141-164-156.ec2.internal) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XEcKl-0005ZK-Va; Tue, 05 Aug 2014 10:51:11 +0000 Received: from mailout1.w1.samsung.com ([210.118.77.11]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XEcIp-0005Fe-Q1 for linaro-mm-sig@lists.linaro.org; Tue, 05 Aug 2014 10:49:11 +0000 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout1.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N9T00GB0Y1R2P00@mailout1.w1.samsung.com> for linaro-mm-sig@lists.linaro.org; Tue, 05 Aug 2014 11:49:03 +0100 (BST) X-AuditID: cbfec7f4-b7f156d0000063c7-e1-53e0b6a47c17 Received: from eusync3.samsung.com ( [203.254.199.213]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 41.2C.25543.4A6B0E35; Tue, 05 Aug 2014 11:49:08 +0100 (BST) Received: from amdc1339.digital.local ([106.116.147.30]) by eusync3.samsung.com (Oracle Communications Messaging Server 7u4-23.01 (7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0N9T0057MY17SE80@eusync3.samsung.com>; Tue, 05 Aug 2014 11:49:08 +0100 (BST) From: Marek Szyprowski To: iommu@lists.linux-foundation.org, linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Date: Tue, 05 Aug 2014 12:47:51 +0200 Message-id: <1407235677-26324-24-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 In-reply-to: <1407235677-26324-1-git-send-email-m.szyprowski@samsung.com> References: <1407235677-26324-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrOLMWRmVeSWpSXmKPExsVy+t/xq7pLtj0INtg2x8bi76Rj7BbNi9ez WUy6P4HFYsF+a4vO2RvYLXoXXGWzONv0ht2ic+ISdosvVx4yWWx6fI3V4vKuOWwWM87vY7JY e+Quu8Wp65/ZLP71HmS0OHP6EqvF/z072C0Ov2lntTjycDe7xapdfxgtbv/mcxD1eHJwHpPH 71+TGD12zrrL7jG7Yyarx6ZVnWwe++euYffYvKTe4/a/x8wek28sZ/S4cqKJ1aO3+R2bx5ar 7SwefVtWMXp83iQXwBfFZZOSmpNZllqkb5fAlbHz0XSmgnUaFVennGVqYDys0MXIySEhYCKx Zu9NJghbTOLCvfVsXYxcHEICSxklDr7dCJYQEuhjkpjyMQPEZhMwlOh62wVWJCLQyyjR3/SD CcRhFljHKrG/9zoLSJWwgK/E3wO7wGwWAVWJvu5tbCA2r4CnxIXn76DWyUn8f7kCzOYEih++ eYAVYpuHxM8Na9gnMPIuYGRYxSiaWppcUJyUnmuoV5yYW1yal66XnJ+7iRESOV92MC4+ZnWI UYCDUYmH1+D03WAh1sSy4srcQ4wSHMxKIrwSax4EC/GmJFZWpRblxxeV5qQWH2Jk4uCUamBc XXLlw8E/vsJ7ln9O7r2/VfhHmVOigWB/uP/ltX+ur1t4r7q4RcE3fIeVek+L0Yybl4JDW2aW 8Zb/yhTzemlUIdq/Xa0gQ5XHcHZRF5uj75yX1xluvfn8Ka3P/yvztAUvFvIYec7+W13P/lK9 IWj5/kv68U9Swne3NjVVvHLlKOG47sqwz0uJpTgj0VCLuag4EQAY0Q5YegIAAA== Cc: Rob Herring , Thierry Reding , Shaik Ameer Basha , Arnd Bergmann , Inki Dae , Greg Kroah-Hartman , Joerg Roedel , "Rafael J. Wysocki" , Tomasz Figa , linaro-mm-sig@lists.linaro.org, Kyungmin Park , Kukjin Kim , Laurent Pinchart , Sylwester Nawrocki , Olof Johansson , Cho KyongHo Subject: [Linaro-mm-sig] [PATCH 23/29] iommu: exynos: init iommu controllers from device tree X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: linaro-mm-sig-bounces@lists.linaro.org Sender: linaro-mm-sig-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: m.szyprowski@samsung.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 This patch adds code to initialize and assign SYSMMU controllers to their master devices defined in device tree. Signed-off-by: Marek Szyprowski --- drivers/iommu/exynos-iommu.c | 152 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 145 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c index 46e0edc..845f547 100644 --- a/drivers/iommu/exynos-iommu.c +++ b/drivers/iommu/exynos-iommu.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -211,6 +212,9 @@ struct sysmmu_drvdata { struct list_head owner_node; phys_addr_t pgtable; int version; + const char *name; + dma_addr_t base; + size_t size; }; static bool set_sysmmu_active(struct sysmmu_drvdata *data) @@ -574,6 +578,11 @@ static int __init exynos_sysmmu_probe(struct platform_device *pdev) } data->sysmmu = dev; + + /* default io address space parameters */ + data->base = SZ_1G; + data->size = SZ_2G; + spin_lock_init(&data->lock); platform_set_drvdata(pdev, data); @@ -1055,30 +1064,159 @@ static phys_addr_t exynos_iommu_iova_to_phys(struct iommu_domain *domain, return phys; } +static void __free_owner_struct(struct exynos_iommu_owner *owner, + struct device *dev) +{ + while (!list_empty(&owner->clients)) + list_del_init(owner->clients.next); + + kfree(owner); + dev->archdata.iommu = NULL; +} + +static int __init_master_sysmmu(struct device *dev) +{ + struct of_phandle_args sysmmu_spec; + struct exynos_iommu_owner *owner; + int i = 0; + int ret; + + owner = kzalloc(sizeof(*owner), GFP_KERNEL); + if (!owner) + return -ENOMEM; + INIT_LIST_HEAD(&owner->clients); + + while (!of_parse_phandle_with_args(dev->of_node, "iommus", + "#iommu-cells", i, + &sysmmu_spec)) { + struct platform_device *sysmmu; + struct sysmmu_drvdata *data; + + sysmmu = of_find_device_by_node(sysmmu_spec.np); + if (!sysmmu) { + dev_err(dev, "sysmmu node not found\n"); + ret = -ENODEV; + goto err; + } + data = platform_get_drvdata(sysmmu); + if (!data) { + ret = -ENODEV; + goto err; + } + + of_property_read_string_index(dev->of_node, "iommu-names", i, + &data->name); + + if (sysmmu_spec.args_count == 2) { + data->base = sysmmu_spec.args[0]; + data->size = sysmmu_spec.args[1]; + } else if (sysmmu_spec.args_count != 0) { + dev_err(dev, "incorrect iommu property specified\n"); + ret = -EINVAL; + goto err; + } + + list_add_tail(&data->owner_node, &owner->clients); + + i++; + } + + if (i == 0) { + ret = -ENODEV; + goto err; + } + + dev->archdata.iommu = owner; + dev_dbg(dev, "registered %d sysmmu controllers\n", i); + + return 0; +err: + __free_owner_struct(owner, dev); + return ret; +} + +static int __init_subdevice_sysmmu(struct device *dev) +{ + struct device *parent = dev->parent; + struct exynos_iommu_owner *owner; + struct sysmmu_drvdata *data; + char *name; + + name = strrchr(dev_name(dev), ':'); + if (!name) + return -ENODEV; + name++; + + owner = parent->archdata.iommu; + if (!owner) + return -ENODEV; + + list_for_each_entry(data, &owner->clients, owner_node) + if (strcmp(name, data->name) == 0) + break; + if (!data) + return -ENODEV; + + owner = kzalloc(sizeof(*owner), GFP_KERNEL); + if (!owner) + return -ENOMEM; + INIT_LIST_HEAD(&owner->clients); + + /* move sysmmu from parent to child device */ + list_del(&data->owner_node); + list_add_tail(&data->owner_node, &owner->clients); + + dev->archdata.iommu = owner; + dev_dbg(dev->parent, + "registered sysmmu controller for %s subdevice\n", data->name); + + return 0; +} + static int exynos_iommu_add_device(struct device *dev) { struct iommu_group *group; int ret; - group = iommu_group_get(dev); + BUG_ON(dev->archdata.iommu != NULL); - if (!group) { - group = iommu_group_alloc(); - if (IS_ERR(group)) { - dev_err(dev, "Failed to allocate IOMMU group\n"); - return PTR_ERR(group); - } + if (of_get_property(dev->of_node, "iommus", NULL)) + ret = __init_master_sysmmu(dev); + else if (dev->parent && + of_get_property(dev->parent->of_node, "iommus", NULL)) + ret = __init_subdevice_sysmmu(dev); + else + return -ENODEV; + + if (ret) + return ret; + + group = iommu_group_alloc(); + if (IS_ERR(group)) { + dev_err(dev, "Failed to allocate IOMMU group\n"); + ret = PTR_ERR(group); + goto err; } ret = iommu_group_add_device(group, dev); + if (ret != 0) + goto err; + iommu_group_put(group); + return 0; +err: + __free_owner_struct(dev->archdata.iommu, dev); return ret; } static void exynos_iommu_remove_device(struct device *dev) { + struct exynos_iommu_owner *owner = dev->archdata.iommu; + iommu_group_remove_device(dev); + if (owner) + __free_owner_struct(owner, dev); } static const struct iommu_ops exynos_iommu_ops = {