From patchwork Tue Mar 6 03:27:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeffy Chen X-Patchwork-Id: 10260645 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 04C156037E for ; Tue, 6 Mar 2018 03:30:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E8F6F28B55 for ; Tue, 6 Mar 2018 03:30:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DCC8828B66; Tue, 6 Mar 2018 03:30: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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.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 8E0DB28B55 for ; Tue, 6 Mar 2018 03:30:33 +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=zDODQktatXlolLJr8SNtYOC4GvMWD+LK0GojFwABkYI=; b=YrUnhZOoHSW5cuj83R/5InrGrJ VYkj9d/mJBy9V1An4lPNjZfauQ61PCbLeFqlKnWV+VEoVfv5LQ3+TUy8TgDgFB42lYzUrpdcgFhIn pJEJEjy/wH40ytK96seOxLZOTstz4jiew4udOwfQ3xe6iJ+Ch7cl8vdxyVGI4v4MQse+ddw3vNZDL 4++ciRKcXHoJWLZQ+4F5j7WH7UxpSyGB/B9Nh6qNJ71Zp+gE90Ykh0xEugq3nHoB7Zlrl9kg5n11S 4Hv1ctp419w4WDpLUCEVg7VTYo7OIIrpnayDG+2s9YB3nyyYFVR/kU5LbU+ih/ZICC3JvRAN1DCUq yfhTMLmA==; 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 1et3J2-00069X-C9; Tue, 06 Mar 2018 03:30:24 +0000 Received: from regular1.263xmail.com ([211.150.99.130]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1et3Hm-0004mQ-Ol; Tue, 06 Mar 2018 03:29:13 +0000 Received: from jeffy.chen?rock-chips.com (unknown [192.168.167.228]) by regular1.263xmail.com (Postfix) with ESMTP id C1F4CB34A; Tue, 6 Mar 2018 11:28:56 +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 4AD553C1; Tue, 6 Mar 2018 11:28:54 +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 986A0QVDO; Tue, 06 Mar 2018 11:28:56 +0800 (CST) From: Jeffy Chen To: linux-kernel@vger.kernel.org Subject: [PATCH v7 14/14] iommu/rockchip: Support sharing IOMMU between masters Date: Tue, 6 Mar 2018 11:27:59 +0800 Message-Id: <20180306032759.29069-5-jeffy.chen@rock-chips.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180306032759.29069-1-jeffy.chen@rock-chips.com> References: <20180306030252.3197-1-jeffy.chen@rock-chips.com> <20180306032759.29069-1-jeffy.chen@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180305_192907_716399_D4D815FF X-CRM114-Status: GOOD ( 11.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: 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-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=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 Reviewed-by: Robin Murphy --- Changes in v7: Use iommu_group_ref_get to avoid ref leak 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 db08978203f7..6a1c7efa7c17 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; }; /** @@ -1091,6 +1092,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_ref_get(iommu->group); +} + static int rk_iommu_of_xlate(struct device *dev, struct of_phandle_args *args) { @@ -1122,7 +1132,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, }; @@ -1191,9 +1201,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); @@ -1217,6 +1233,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;