From patchwork Tue Feb 20 20:25:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 10230819 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 881E2602A7 for ; Tue, 20 Feb 2018 20:26:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77C77288E0 for ; Tue, 20 Feb 2018 20:26:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C1EB288E2; Tue, 20 Feb 2018 20:26:09 +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=ham 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 BF9D2288E0 for ; Tue, 20 Feb 2018 20:26:08 +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=tcP7mVTgi9RyHVr2bEpdblKMOJiL9W7ojXQ7jvJ+RAo=; b=grm y8I7UQiTNCKvKeuKzZRrSWRgXthy8Y3MIHVQ0lZwLeocDGg5k7eGwROx9N7eLip6L7cWmtMX+MsGs wlqt42fmN5YcptYgdA7BulqetSRQh80kttW2USXQS+N+agR8AyEezc8dkKeDM11rqIXys1djuUMt0 eIJmdOxaUIab9qq42qbMRUSjYjwu5bxudkDvZ/KNActzB9IwH3BNJ7xkT1AAsy2hR1Y8OXoc5nY/2 pKvyrUtcLLH/3Fga6Mlyn2szdDfdC8ktukQUbdcp27vzATqlIsMOW9+E0NbFXhfoZzDTryXDLZToI P13YhB53Xou4YExxk15syvedqeQFsZw==; 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 1eoEUG-0004T6-AQ; Tue, 20 Feb 2018 20:26:04 +0000 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eoETh-0004Ar-6l; Tue, 20 Feb 2018 20:25:31 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A7F581529; Tue, 20 Feb 2018 12:25:16 -0800 (PST) Received: from why.lan (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3CAF43F25C; Tue, 20 Feb 2018 12:25:14 -0800 (PST) From: Marc Zyngier To: Joerg Roedel , Heiko Stuebner Subject: [PATCH] iommu/rockchip: Perform a reset on shutdown Date: Tue, 20 Feb 2018 20:25:04 +0000 Message-Id: <20180220202504.19275-1-marc.zyngier@arm.com> X-Mailer: git-send-email 2.14.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180220_122529_309895_166AF16B X-CRM114-Status: GOOD ( 11.35 ) 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: linux-rockchip@lists.infradead.org, iommu@lists.linux-foundation.org, Robin Murphy , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org 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 Trying to do a kexec whilst the iommus are still on is proving to be a challenging exercise. It is terribly unsafe, as we're reusing the memory allocated for the page tables, leading to a likely crash. Let's implement a shutdown method that will at least try to stop DMA from going crazy behind our back. Note that we need to be extra cautious when doing so, as the IOMMU may not be clocked if controlled by a another master, as typical on Rockchip system. Suggested-by: Robin Murphy Signed-off-by: Marc Zyngier Reviewed-by: Robin Murphy --- drivers/iommu/rockchip-iommu.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c index 9d991c2d8767..6a3719e118da 100644 --- a/drivers/iommu/rockchip-iommu.c +++ b/drivers/iommu/rockchip-iommu.c @@ -1209,6 +1209,23 @@ static int rk_iommu_remove(struct platform_device *pdev) return 0; } +static void rk_iommu_shutdown(struct platform_device *pdev) +{ + struct rk_iommu *iommu = platform_get_drvdata(pdev); + + /* + * Be careful not to try to shutdown an otherwise unused + * IOMMU, as it is likely not to be clocked, and accessing it + * would just block. An IOMMU without a domain is likely to be + * unused, so let's use this as a (weak) guard. + */ + if (iommu && iommu->domain) { + rk_iommu_enable_stall(iommu); + rk_iommu_disable_paging(iommu); + rk_iommu_force_reset(iommu); + } +} + static const struct of_device_id rk_iommu_dt_ids[] = { { .compatible = "rockchip,iommu" }, { /* sentinel */ } @@ -1218,6 +1235,7 @@ MODULE_DEVICE_TABLE(of, rk_iommu_dt_ids); static struct platform_driver rk_iommu_driver = { .probe = rk_iommu_probe, .remove = rk_iommu_remove, + .shutdown = rk_iommu_shutdown, .driver = { .name = "rk_iommu", .of_match_table = rk_iommu_dt_ids,