From patchwork Fri Mar 31 14:30:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 9656525 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 C840960351 for ; Fri, 31 Mar 2017 14:30:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA38F286B2 for ; Fri, 31 Mar 2017 14:30:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AED02286CA; Fri, 31 Mar 2017 14:30:55 +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 [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 5644E286B2 for ; Fri, 31 Mar 2017 14:30:55 +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=yXKbL1cQI4ZqdkJh/9ZNQYFqvPnjgrQr0z9VP8XP+EY=; b=XLU FDWklJO2ORUo1kICiMJ3eBHRdGQMVUtKEaUKbeztMDqlDoBwvPJ99uCtalxFHS3IJqazc/TWu9F4R sbP2kM95Jd1B06fKWDa/KhHNNogijUxKnn026t4dM9E39Os6vkHw5gt0Ar4F0I9U1s7iFNmQF3S4q i+9bOCyso0vkmmyR0QROGqHlgrzn/lKyL9jzgG9S27aTYX3BIZVtv7fRny2PPl0C/P3Q4bG4SqqcJ 7Fd7IYjjR3FqD4oteYb6p3L8Y5CZ6RmwT6Dt9lTfkzXLgS7Zmb3rzjmZpi+xmmmEVOCJgmHEsfgoz SjEcPg1Gf9Nyg4ZPQS9z+urHeXp1egw==; 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 1ctxZm-0004kx-HE; Fri, 31 Mar 2017 14:30:54 +0000 Received: from 8bytes.org ([81.169.241.247] helo=theia.8bytes.org) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ctxZh-0004i4-Ho; Fri, 31 Mar 2017 14:30:52 +0000 Received: by theia.8bytes.org (Postfix, from userid 1000) id 40A40576; Fri, 31 Mar 2017 16:30:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1490970627; bh=AmHsHM6fTAouzQlsx5Ckb6thXoVE4jFiXPgA8xoQLd4=; h=From:To:Cc:Subject:Date:From; b=Kjgs+4LNL/1wcC1iKyMuobN9gXVhxd7fnzryGZ7wo16cVlm4frgquidGPNNGuuvzh F2ZdHA4nLkvYkcDrZzLiE0S4YDn4ZMBfdNfGWefQSLIqQTJGnJFOXWClhaFeGzYKeI zLGUOT0LJnDeyZvU6NJetJ/cva8+vfDc9Kw5Z3r264N8I/uIk5hSbrkik/ZsAraP6B IVLYIRbev+vjimgPfDH3jYLxGo0pJh+VGXVZaiOqR7DugyVcTcUHbHUBN7hUnA6h/3 8tLkI+lx4+Oc3H6MF5XodlPIjx2uRIwKYnAjORi9YEPdsT/OG1KIJa0fkF8+ooZbzQ lMgHAWe3YlluQ== From: Joerg Roedel To: Heiko Stuebner , iommu@lists.linux-foundation.org Subject: [PATCH] iommu/rockchip: Make use of 'struct iommu_device' Date: Fri, 31 Mar 2017 16:30:24 +0200 Message-Id: <1490970624-19981-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_073049_767775_AE01C3A9 X-CRM114-Status: GOOD ( 11.44 ) 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: linux-rockchip@lists.infradead.org, Joerg Roedel , 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 Register hardware IOMMUs seperatly with the iommu-core code and add a sysfs representation of the iommu topology. Signed-off-by: Joerg Roedel Tested-by: Heiko Stuebner --- drivers/iommu/rockchip-iommu.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c index 9afcbf7..36d0890 100644 --- a/drivers/iommu/rockchip-iommu.c +++ b/drivers/iommu/rockchip-iommu.c @@ -90,6 +90,7 @@ struct rk_iommu { void __iomem **bases; int num_mmu; int irq; + struct iommu_device iommu; struct list_head node; /* entry in rk_iommu_domain.iommus */ struct iommu_domain *domain; /* domain to which iommu is attached */ }; @@ -1032,6 +1033,7 @@ static int rk_iommu_group_set_iommudata(struct iommu_group *group, static int rk_iommu_add_device(struct device *dev) { struct iommu_group *group; + struct rk_iommu *iommu; int ret; if (!rk_iommu_is_dev_iommu_master(dev)) @@ -1054,6 +1056,10 @@ static int rk_iommu_add_device(struct device *dev) if (ret) goto err_remove_device; + iommu = rk_iommu_from_dev(dev); + if (iommu) + iommu_device_link(&iommu->iommu, dev); + iommu_group_put(group); return 0; @@ -1067,9 +1073,15 @@ static int rk_iommu_add_device(struct device *dev) static void rk_iommu_remove_device(struct device *dev) { + struct rk_iommu *iommu; + if (!rk_iommu_is_dev_iommu_master(dev)) return; + iommu = rk_iommu_from_dev(dev); + if (iommu) + iommu_device_unlink(&iommu->iommu, dev); + iommu_group_remove_device(dev); } @@ -1117,7 +1129,7 @@ static int rk_iommu_probe(struct platform_device *pdev) struct rk_iommu *iommu; struct resource *res; int num_res = pdev->num_resources; - int i; + int err, i; iommu = devm_kzalloc(dev, sizeof(*iommu), GFP_KERNEL); if (!iommu) @@ -1150,11 +1162,25 @@ static int rk_iommu_probe(struct platform_device *pdev) return -ENXIO; } - return 0; + err = iommu_device_sysfs_add(&iommu->iommu, dev, NULL, dev_name(dev)); + if (err) + return err; + + iommu_device_set_ops(&iommu->iommu, &rk_iommu_ops); + err = iommu_device_register(&iommu->iommu); + + return err; } static int rk_iommu_remove(struct platform_device *pdev) { + struct rk_iommu *iommu = platform_get_drvdata(pdev); + + if (iommu) { + iommu_device_sysfs_remove(&iommu->iommu); + iommu_device_unregister(&iommu->iommu); + } + return 0; }