From patchwork Fri Mar 31 14:29:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 9656521 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 41C4860351 for ; Fri, 31 Mar 2017 14:30:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 33827286C8 for ; Fri, 31 Mar 2017 14:30:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 27EAE286CC; Fri, 31 Mar 2017 14:30:01 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, T_DKIM_INVALID autolearn=no 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 E3112286C8 for ; Fri, 31 Mar 2017 14:29:50 +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: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:In-Reply-To: References:List-Owner; bh=klAXHCwevHBlnU+dV2kKwioRAKBs90SBTWaXEUl+9y0=; b=nmW aBcJvzJ77wWx/8kxFSyfCvovp880VXnwLosRbbaWWirnzbr6X1gPpDEWJWX2tg/M+LbwnOVewtwn1 jWZFnyKybYGrAGGGMrDl7b0hVyfHBxHww+sL6xvTIJFeqA12ngOx3NHFy0kGRv0QZ1n3WGoYiHMfL EG0XzDPqWrAGj1S7yuqIrod9XhWePXy7iFH9UZnrXsMIsuxan9xh8j+9XV1tSMXLGwQyqE5NAf2A4 2fWEhCp9PzYnDylRIuPc9iKnurbseCX1e+E28HmAebNJbtJdbi3U3OqAIJSUmcYSL2s9eu50fjIt4 hG9CvWMxHgBZ3eFwE0FTfui2NEUsP3g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ctxYi-0003Bp-4n; Fri, 31 Mar 2017 14:29:48 +0000 Received: from 8bytes.org ([2a01:238:4383:600:38bc:a715:4b6d:a889] helo=theia.8bytes.org) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ctxYe-0002xk-AG; Fri, 31 Mar 2017 14:29:46 +0000 Received: by theia.8bytes.org (Postfix, from userid 1000) id ABC69576; Fri, 31 Mar 2017 16:29:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1490970556; bh=GUzxkyZzseyHL0w3ObKHmXpA7KxmhM9gmENxOQeUAfU=; h=From:To:Cc:Subject:Date:From; b=ISr0ICo8IHgDVGGl2cCtzBoZjtAkrQYlM1UDWqUkI7ea9stj12XLqfnDUDQGSAc5t iZNqHN0cEX5zRHBJgjoVpl7sLer5oam1GJ6t0/pgXV15lrFxel53E9NMFxe7I703zL pdlAvWYRq8NLDIK535l0C6kXcI5Y4QdceSE+baMp+NvKuPFlaRqDkHm9Z7Bw0CbM7q oAT+/ctuQVdT4v+RSp+3IgBR+WGZ6+o/0seRvx03SXOGE7nr1U+oNq0ETTNQFjl1gc NyajBsgY4QZK8eyhjG3AuCPOyg9yn3W8GFx/WB1Q4ircnU3se5mAJfXjfk168qhnR8 J1SY8o4u9GQ8w== From: Joerg Roedel To: Matthias Brugger , iommu@lists.linux-foundation.org Subject: [PATCH] iommu/mediatek: Teach MTK-IOMMUv1 about 'struct iommu_device' Date: Fri, 31 Mar 2017 16:29:13 +0200 Message-Id: <1490970553-19787-1-git-send-email-joro@8bytes.org> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170331_072944_527890_B67B2723 X-CRM114-Status: GOOD ( 10.34 ) 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: Joerg Roedel , linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org 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 From: Joerg Roedel Make use of the iommu_device_register() interface. Signed-off-by: Joerg Roedel --- drivers/iommu/mtk_iommu_v1.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/mtk_iommu_v1.c b/drivers/iommu/mtk_iommu_v1.c index 19e0100..a27ef57 100644 --- a/drivers/iommu/mtk_iommu_v1.c +++ b/drivers/iommu/mtk_iommu_v1.c @@ -431,9 +431,10 @@ static int mtk_iommu_create_mapping(struct device *dev, static int mtk_iommu_add_device(struct device *dev) { - struct iommu_group *group; struct of_phandle_args iommu_spec; struct of_phandle_iterator it; + struct mtk_iommu_data *data; + struct iommu_group *group; int err; of_for_each_phandle(&it, err, dev->of_node, "iommus", @@ -450,6 +451,9 @@ static int mtk_iommu_add_device(struct device *dev) if (!dev->iommu_fwspec || dev->iommu_fwspec->ops != &mtk_iommu_ops) return -ENODEV; /* Not a iommu client device */ + data = dev->iommu_fwspec->iommu_priv; + iommu_device_link(&data->iommu, dev); + group = iommu_group_get_for_dev(dev); if (IS_ERR(group)) return PTR_ERR(group); @@ -460,9 +464,14 @@ static int mtk_iommu_add_device(struct device *dev) static void mtk_iommu_remove_device(struct device *dev) { + struct mtk_iommu_data *data; + if (!dev->iommu_fwspec || dev->iommu_fwspec->ops != &mtk_iommu_ops) return; + data = dev->iommu_fwspec->iommu_priv; + iommu_device_unlink(&data->iommu, dev); + iommu_group_remove_device(dev); iommu_fwspec_free(dev); } @@ -627,6 +636,17 @@ static int mtk_iommu_probe(struct platform_device *pdev) if (ret) return ret; + ret = iommu_device_sysfs_add(&data->iommu, &pdev->dev, NULL, + dev_name(&pdev->dev)); + if (ret) + return ret; + + iommu_device_set_ops(&data->iommu, &mtk_iommu_ops); + + ret = iommu_device_register(&data->iommu); + if (ret) + return ret; + if (!iommu_present(&platform_bus_type)) bus_set_iommu(&platform_bus_type, &mtk_iommu_ops); @@ -637,6 +657,9 @@ static int mtk_iommu_remove(struct platform_device *pdev) { struct mtk_iommu_data *data = platform_get_drvdata(pdev); + iommu_device_sysfs_remove(&data->iommu); + iommu_device_unregister(&data->iommu); + if (iommu_present(&platform_bus_type)) bus_set_iommu(&platform_bus_type, NULL);