Merge tag 'driver-core-5.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-microblaze.git] / drivers / base / platform.c
index 5259f1f..51bb228 100644 (file)
@@ -30,6 +30,8 @@
 #include <linux/property.h>
 #include <linux/kmemleak.h>
 #include <linux/types.h>
+#include <linux/iommu.h>
+#include <linux/dma-map-ops.h>
 
 #include "base.h"
 #include "power/power.h"
@@ -1436,9 +1438,9 @@ static void platform_shutdown(struct device *_dev)
                drv->shutdown(dev);
 }
 
-
-int platform_dma_configure(struct device *dev)
+static int platform_dma_configure(struct device *dev)
 {
+       struct platform_driver *drv = to_platform_driver(dev->driver);
        enum dev_dma_attr attr;
        int ret = 0;
 
@@ -1449,9 +1451,23 @@ int platform_dma_configure(struct device *dev)
                ret = acpi_dma_configure(dev, attr);
        }
 
+       if (!ret && !drv->driver_managed_dma) {
+               ret = iommu_device_use_default_domain(dev);
+               if (ret)
+                       arch_teardown_dma_ops(dev);
+       }
+
        return ret;
 }
 
+static void platform_dma_cleanup(struct device *dev)
+{
+       struct platform_driver *drv = to_platform_driver(dev->driver);
+
+       if (!drv->driver_managed_dma)
+               iommu_device_unuse_default_domain(dev);
+}
+
 static const struct dev_pm_ops platform_dev_pm_ops = {
        SET_RUNTIME_PM_OPS(pm_generic_runtime_suspend, pm_generic_runtime_resume, NULL)
        USE_PLATFORM_PM_SLEEP_OPS
@@ -1466,6 +1482,7 @@ struct bus_type platform_bus_type = {
        .remove         = platform_remove,
        .shutdown       = platform_shutdown,
        .dma_configure  = platform_dma_configure,
+       .dma_cleanup    = platform_dma_cleanup,
        .pm             = &platform_dev_pm_ops,
 };
 EXPORT_SYMBOL_GPL(platform_bus_type);