Received: by 10.223.185.116 with SMTP id b49csp7250394wrg; Thu, 1 Mar 2018 02:22:55 -0800 (PST) X-Google-Smtp-Source: AG47ELt1zK4CegUphue4jHQ3gMy1dETPQOeH/ZJGJHy98dUdGl5oYkZoidrz7IxhU4+gVpmeHk1g X-Received: by 10.99.163.80 with SMTP id v16mr1134362pgn.19.1519899775623; Thu, 01 Mar 2018 02:22:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519899775; cv=none; d=google.com; s=arc-20160816; b=me7lp/qJXwr2raVLawq0Z2Hwd0MZwvRRly+EgfvQxhcOThDKuHecMv9tKhZlTt8sVd mSyO7gtRV4ImMF96hZ3CvO9GkXJobtzOIbNrT6nGT6t/wTBEZwEcnTBTd9c1miy0goSc Y+G4Luy0/nd9c9z+eA4x27Qy8uUM2bcu2yvqoodAt2yU63Xa22eT8sr4NpXgIvmG5Xcs 2SCkeg2JB7zi7vSWsluKLxRplIL9hm44SIi+rwdGab2UcvOa36+Sp907nVYnfQFjMRKX bjaTZSi00/zjPM2TujofQNpJhjOpAvbX5tGYua97DFwdZbDWrUkMya/QyLarvplL/B60 tYRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=HW7guz8ZxXxSS3YKWdjcuwlVaa3P6l5qYJP0hdO0nIY=; b=pn4u3UeQgd1kMr2NPcYm7xn5CDR9HUTBXWbQ89JQcrDn+Pgsx8FlDcHVYVLId+0jo7 Nj4YvAq6Il91aYAG88zKNvg9ZVisEp4zQJg/A3EkIiOWAthokQ2lbHOVVmGeEgiozH+l QBkllj2pgADuxgt3MilBwmvdz/CwTTm2ms7MKsxSpXksGhuwbW1euZ9LWDhGjHgEKQnj bA6kin6DeIlSRv1nKVdV8LWUBUUt9NFc7ye/sLzSJICKOoYAcwfAveI7P7z9QTI3g0fQ x9fhGT0I/0gtKotTncG9RJTTe+vFGLyXM2pQ0Gu4HyoAjaeWjWtbkZi98veFMenaiEvw 1hGw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h129si2291447pgc.169.2018.03.01.02.22.40; Thu, 01 Mar 2018 02:22:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967334AbeCAKVZ (ORCPT + 99 others); Thu, 1 Mar 2018 05:21:25 -0500 Received: from regular1.263xmail.com ([211.150.99.141]:52302 "EHLO regular1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934985AbeCAKVV (ORCPT ); Thu, 1 Mar 2018 05:21:21 -0500 Received: from jeffy.chen?rock-chips.com (unknown [192.168.167.225]) by regular1.263xmail.com (Postfix) with ESMTP id 32A8374; Thu, 1 Mar 2018 18:21:18 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-KSVirus-check: 0 X-ABS-CHECKED: 4 Received: from localhost (localhost [127.0.0.1]) by smtp.263.net (Postfix) with ESMTPA id AAA84380; Thu, 1 Mar 2018 18:21:09 +0800 (CST) X-RL-SENDER: jeffy.chen@rock-chips.com X-FST-TO: linux-kernel@vger.kernel.org X-SENDER-IP: 103.29.142.67 X-LOGIN-NAME: jeffy.chen@rock-chips.com X-UNIQUE-TAG: X-ATTACHMENT-NUM: 0 X-SENDER: cjf@rock-chips.com X-DNS-TYPE: 0 Received: from localhost (unknown [103.29.142.67]) by smtp.263.net (Postfix) whith ESMTP id 2943OSXR12; Thu, 01 Mar 2018 18:21:18 +0800 (CST) From: Jeffy Chen To: linux-kernel@vger.kernel.org Cc: jcliang@chromium.org, robin.murphy@arm.com, xxm@rock-chips.com, tfiga@chromium.org, Jeffy Chen , Heiko Stuebner , linux-rockchip@lists.infradead.org, iommu@lists.linux-foundation.org, Joerg Roedel , linux-arm-kernel@lists.infradead.org Subject: [RESEND PATCH v6 14/14] iommu/rockchip: Support sharing IOMMU between masters Date: Thu, 1 Mar 2018 18:18:37 +0800 Message-Id: <20180301101837.27969-15-jeffy.chen@rock-chips.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180301101837.27969-1-jeffy.chen@rock-chips.com> References: <20180301101837.27969-1-jeffy.chen@rock-chips.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There would be some masters sharing the same IOMMU device. Put them in the same iommu group and share the same iommu domain. Signed-off-by: Jeffy Chen Reviewed-by: Robin Murphy --- Changes in v6: None Changes in v5: None Changes in v4: None Changes in v3: Remove rk_iommudata->domain. Changes in v2: None drivers/iommu/rockchip-iommu.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c index 0e0a42f41818..f4ce7706fc34 100644 --- a/drivers/iommu/rockchip-iommu.c +++ b/drivers/iommu/rockchip-iommu.c @@ -104,6 +104,7 @@ struct rk_iommu { struct iommu_device iommu; struct list_head node; /* entry in rk_iommu_domain.iommus */ struct iommu_domain *domain; /* domain to which iommu is attached */ + struct iommu_group *group; }; struct rk_iommudata { @@ -1083,6 +1084,15 @@ static void rk_iommu_remove_device(struct device *dev) iommu_group_remove_device(dev); } +static struct iommu_group *rk_iommu_device_group(struct device *dev) +{ + struct rk_iommu *iommu; + + iommu = rk_iommu_from_dev(dev); + + return iommu->group; +} + static int rk_iommu_of_xlate(struct device *dev, struct of_phandle_args *args) { @@ -1114,7 +1124,7 @@ static const struct iommu_ops rk_iommu_ops = { .add_device = rk_iommu_add_device, .remove_device = rk_iommu_remove_device, .iova_to_phys = rk_iommu_iova_to_phys, - .device_group = generic_device_group, + .device_group = rk_iommu_device_group, .pgsize_bitmap = RK_IOMMU_PGSIZE_BITMAP, .of_xlate = rk_iommu_of_xlate, }; @@ -1183,9 +1193,15 @@ static int rk_iommu_probe(struct platform_device *pdev) if (err) return err; + iommu->group = iommu_group_alloc(); + if (IS_ERR(iommu->group)) { + err = PTR_ERR(iommu->group); + goto err_unprepare_clocks; + } + err = iommu_device_sysfs_add(&iommu->iommu, dev, NULL, dev_name(dev)); if (err) - goto err_unprepare_clocks; + goto err_put_group; iommu_device_set_ops(&iommu->iommu, &rk_iommu_ops); iommu_device_set_fwnode(&iommu->iommu, &dev->of_node->fwnode); @@ -1209,6 +1225,8 @@ static int rk_iommu_probe(struct platform_device *pdev) return 0; err_remove_sysfs: iommu_device_sysfs_remove(&iommu->iommu); +err_put_group: + iommu_group_put(iommu->group); err_unprepare_clocks: clk_bulk_unprepare(iommu->num_clocks, iommu->clocks); return err; -- 2.11.0