From patchwork Wed Jan 17 15:25:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeffy Chen X-Patchwork-Id: 10169635 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 06F9A603ED for ; Wed, 17 Jan 2018 15:43:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA36928676 for ; Wed, 17 Jan 2018 15:43:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DE6972868B; Wed, 17 Jan 2018 15:43:58 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 98C6828676 for ; Wed, 17 Jan 2018 15:43:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Cp5s4kkb4l/mUTOGZC4YuvuZZlyJ4IM2ZtLk2lM2abA=; b=m5GfxagnU4tPsRR6VDjI5B8FtD 0quHWKyMJQEXUQvgrMDBiFs3tCALXmnQ4uvwtWm5H91kpStRA44xXd1qeAt3VQ1+UOfekHiqz1Rco lAmEwClPSVlNH7WOI0tWEoSv69JsVbxTMwtor+myybHLyxPfV9JMhPIx1UrCi6IiiccuRp+DmwtiE bNFSIR895H6Q/xeepL2RxGkJH9mqCLGrxGBc97nzEhmeszSg0ajeeiDJIXKWAAyuv9EyoxOh3fCXy jkTaiz9XO48EDmeBiBZlwD+h8Cdepp2W3L7IwsjP2khOfztajaBeDhcvCW8yg9pySwWVfQHAVgKCF udOAtrnw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1ebpsY-0006Ld-RP; Wed, 17 Jan 2018 15:43:54 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1ebprC-0004YF-4D; Wed, 17 Jan 2018 15:42:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=qp6Kh0TTiwA7Qo7gIb3Fbjl2kc4PEeMRBsmX6dNOa2g=; b=dHN+gpAcETgviJRXkaKgOcba7 0aYaOlSWs8qK2aTZkQDKQDEMm96D3VMFFu5iYOoJxjwfGjuaWuGD7vphYYIYFooW1HbhKFoiP8OFI lfZ2vD77XAOufZjrmQJ3A2ZFCLOHawdTA0k9AtP3mfRKzBbFx4u34z03OpxXd5HNT8pKcZdu/JZFn GPews50tQ8Jx7V/G2xmzC8GPkPJft6rEwTNzEpBN/W91KCX2+yyVTU7nB9A15aUHePP7epUQVrGxM q7VchYJLFoWPLpwKlJcFEYT14Dg+G8QQcW+JFZ/YU2yoaTOPKxpIPsHbUX35ZyFk7ixzqxjlMuTzD ggEB49cVA==; Received: from regular1.263xmail.com ([211.150.99.132]) by casper.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1ebpcv-0003SR-HH; Wed, 17 Jan 2018 15:27:49 +0000 Received: from jeffy.chen?rock-chips.com (unknown [192.168.167.232]) by regular1.263xmail.com (Postfix) with ESMTP id E45B793AA; Wed, 17 Jan 2018 23:27:30 +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 CEBE2323; Wed, 17 Jan 2018 23:27:30 +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: <16404ab2d1e39e10b167483e2262a9e5> 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 26879KA3QJD; Wed, 17 Jan 2018 23:27:33 +0800 (CST) From: Jeffy Chen To: linux-kernel@vger.kernel.org Subject: [PATCH v3 12/12] iommu/rockchip: Support sharing IOMMU between masters Date: Wed, 17 Jan 2018 23:25:42 +0800 Message-Id: <20180117152542.26429-13-jeffy.chen@rock-chips.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180117152542.26429-1-jeffy.chen@rock-chips.com> References: <20180117152542.26429-1-jeffy.chen@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180117_152746_606674_B051996D X-CRM114-Status: GOOD ( 13.50 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: xxm@rock-chips.com, Joerg Roedel , Jeffy Chen , tfiga@chromium.org, jcliang@chromium.org, linux-rockchip@lists.infradead.org, iommu@lists.linux-foundation.org, robin.murphy@arm.com, linux-arm-kernel@lists.infradead.org, Heiko Stuebner MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 b5585d39d95c..95b1b3c1984c 100644 --- a/drivers/iommu/rockchip-iommu.c +++ b/drivers/iommu/rockchip-iommu.c @@ -97,6 +97,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 { @@ -1155,6 +1156,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) { @@ -1190,7 +1200,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, }; @@ -1246,9 +1256,15 @@ static int rk_iommu_probe(struct platform_device *pdev) iommu->reset_disabled = device_property_read_bool(dev, "rockchip,disable-mmu-reset"); + iommu->group = iommu_group_alloc(); + if (IS_ERR(iommu->group)) { + err = PTR_ERR(iommu->group); + goto err_put_clocks; + } + err = iommu_device_sysfs_add(&iommu->iommu, dev, NULL, dev_name(dev)); if (err) - goto err_put_clocks; + goto err_put_group; iommu_device_set_ops(&iommu->iommu, &rk_iommu_ops); iommu_device_set_fwnode(&iommu->iommu, &dev->of_node->fwnode); @@ -1272,6 +1288,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_put_clocks: rk_iommu_put_clocks(iommu); return err;