Received: by 10.223.176.46 with SMTP id f43csp569709wra; Wed, 24 Jan 2018 02:38:22 -0800 (PST) X-Google-Smtp-Source: AH8x226BGhOnXtfCRXSEUX3uZATo/hihzW1z17PYxmTUNtskajjUYNWCQARtKOtQv81rbqNwUtEu X-Received: by 2002:a17:902:7d8b:: with SMTP id a11-v6mr7596617plm.216.1516790301919; Wed, 24 Jan 2018 02:38:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516790301; cv=none; d=google.com; s=arc-20160816; b=gdERLx5PP8R31DoRmD260J9utH4uHiqLguwxrrfH1XLzcLkaLPXr/65lLqhhTb0e7a sK2B47WK859Ad4UYvStxQHGSwlk4shkCjPJ5efWO1GpF+a9qh5XRhYkCH8uoPwjHl/fI 2GFLkVR3D7cnLEgh+cIVN8tTCMz6h9LGZIYYTrIYUHV47cU12fxzhsQzLoAErFK0TSPM al9UMFKvTcdojk8c0fz/CRe2WAEfXYMOAue024mJSy/bkQ3yEqcwUCJaccnS+yzkjXcp sIaUFdm6KwPfYzgxK6oFHQKUZADYacgVdSzJ/saqtA98ZxSQu7F6STi8TVsWOORhkp76 B4Mw== 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=/qlNH7LflmVvjUkoT9zX0wz/E9CPtxwYph1wxdVHaos=; b=EmumADOPdR7YxzZ7vpQPx6/SFWT7tXvYJemSLDo6/sDUfwpt4sNWLidvLgJ6WR/VaM pScv3K8avnzdgN2Df4TXOeku4+nq1xcdweMcAmMcUY0ixSZvt4UcHv4eR4RyOtCdFL8z +LYY3tmN7KzvnzT9GS39T9fi4xmthUiK8tCQgqz1E8AL9YaNR6AJN9QnQmVo0UFw1hMO V8hJR5jCwS2cPOWveJHwFm4K8xk9kZ/oxbv90tu1lnYelF9oTHVv6VgvL1KNIG9R/osC avchgCI7CaoOIy2pAGm+3J1xwriTmV9i4qGP4X2rVc1+XELfFTFLqy15uHQO03HDveF5 gmGg== 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 u125si293018pgc.453.2018.01.24.02.38.08; Wed, 24 Jan 2018 02:38:21 -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 S933100AbeAXKhX (ORCPT + 99 others); Wed, 24 Jan 2018 05:37:23 -0500 Received: from regular1.263xmail.com ([211.150.99.132]:35329 "EHLO regular1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932859AbeAXKhU (ORCPT ); Wed, 24 Jan 2018 05:37:20 -0500 Received: from jeffy.chen?rock-chips.com (unknown [192.168.167.110]) by regular1.263xmail.com (Postfix) with ESMTP id D3CD79416; Wed, 24 Jan 2018 18:37:15 +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 B3B59369; Wed, 24 Jan 2018 18:37:14 +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: <7a2cf170bd77a7b980ab4ee4cd1eb8f3> 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 14569XJPCQX; Wed, 24 Jan 2018 18:37:17 +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: [PATCH v5 13/13] iommu/rockchip: Support sharing IOMMU between masters Date: Wed, 24 Jan 2018 18:35:16 +0800 Message-Id: <20180124103516.2571-14-jeffy.chen@rock-chips.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180124103516.2571-1-jeffy.chen@rock-chips.com> References: <20180124103516.2571-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 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 f2a0f06d0a5f..eaa91108a4b0 100644 --- a/drivers/iommu/rockchip-iommu.c +++ b/drivers/iommu/rockchip-iommu.c @@ -99,6 +99,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 { @@ -1110,6 +1111,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) { @@ -1141,7 +1151,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, }; @@ -1201,9 +1211,15 @@ static int rk_iommu_probe(struct platform_device *pdev) if (err) goto err_put_clocks; + 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); @@ -1227,6 +1243,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); err_put_clocks: -- 2.11.0