iommu/amd: Move gart fallback to amd_iommu_init
authorKevin Mitchell <kevmitch@arista.com>
Wed, 12 Jun 2019 21:52:04 +0000 (14:52 -0700)
committerJoerg Roedel <jroedel@suse.de>
Mon, 1 Jul 2019 12:03:07 +0000 (14:03 +0200)
The fallback to the GART driver in the case amd_iommu doesn't work was
executed in a function called free_iommu_resources, which didn't really
make sense. This was even being called twice if amd_iommu=off was
specified on the command line.

The only complication is that it needs to be verified that amd_iommu has
fully relinquished control by calling free_iommu_resources and emptying
the amd_iommu_list.

Signed-off-by: Kevin Mitchell <kevmitch@arista.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/amd_iommu_init.c

index df144dc..b90e26e 100644 (file)
@@ -2340,15 +2340,6 @@ static void __init free_iommu_resources(void)
        amd_iommu_dev_table = NULL;
 
        free_iommu_all();
-
-#ifdef CONFIG_GART_IOMMU
-       /*
-        * We failed to initialize the AMD IOMMU - try fallback to GART
-        * if possible.
-        */
-       gart_iommu_init();
-
-#endif
 }
 
 /* SB IOAPIC is always on this device in AMD systems */
@@ -2767,6 +2758,16 @@ static int __init amd_iommu_init(void)
                }
        }
 
+#ifdef CONFIG_GART_IOMMU
+       if (ret && list_empty(&amd_iommu_list)) {
+               /*
+                * We failed to initialize the AMD IOMMU - try fallback
+                * to GART if possible.
+                */
+               gart_iommu_init();
+       }
+#endif
+
        for_each_iommu(iommu)
                amd_iommu_debugfs_setup(iommu);