OSDN Git Service

iommu/rockchip: Perform a reset on shutdown
authorMarc Zyngier <marc.zyngier@arm.com>
Tue, 20 Feb 2018 20:25:04 +0000 (20:25 +0000)
committerJoerg Roedel <jroedel@suse.de>
Thu, 15 Mar 2018 14:11:56 +0000 (15:11 +0100)
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 <robin.murphy@arm.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/rockchip-iommu.c

index 9d991c2..6a3719e 100644 (file)
@@ -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,