|
21 | 21 | #include <linux/dma-mapping.h> |
22 | 22 | #include <linux/acpi.h> |
23 | 23 | #include <linux/iommu.h> |
| 24 | +#include <linux/dma-map-ops.h> |
24 | 25 |
|
25 | 26 | #include "fsl-mc-private.h" |
26 | 27 |
|
@@ -140,15 +141,33 @@ static int fsl_mc_dma_configure(struct device *dev) |
140 | 141 | { |
141 | 142 | struct device *dma_dev = dev; |
142 | 143 | struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); |
| 144 | + struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(dev->driver); |
143 | 145 | u32 input_id = mc_dev->icid; |
| 146 | + int ret; |
144 | 147 |
|
145 | 148 | while (dev_is_fsl_mc(dma_dev)) |
146 | 149 | dma_dev = dma_dev->parent; |
147 | 150 |
|
148 | 151 | if (dev_of_node(dma_dev)) |
149 | | - return of_dma_configure_id(dev, dma_dev->of_node, 0, &input_id); |
| 152 | + ret = of_dma_configure_id(dev, dma_dev->of_node, 0, &input_id); |
| 153 | + else |
| 154 | + ret = acpi_dma_configure_id(dev, DEV_DMA_COHERENT, &input_id); |
| 155 | + |
| 156 | + if (!ret && !mc_drv->driver_managed_dma) { |
| 157 | + ret = iommu_device_use_default_domain(dev); |
| 158 | + if (ret) |
| 159 | + arch_teardown_dma_ops(dev); |
| 160 | + } |
| 161 | + |
| 162 | + return ret; |
| 163 | +} |
| 164 | + |
| 165 | +static void fsl_mc_dma_cleanup(struct device *dev) |
| 166 | +{ |
| 167 | + struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(dev->driver); |
150 | 168 |
|
151 | | - return acpi_dma_configure_id(dev, DEV_DMA_COHERENT, &input_id); |
| 169 | + if (!mc_drv->driver_managed_dma) |
| 170 | + iommu_device_unuse_default_domain(dev); |
152 | 171 | } |
153 | 172 |
|
154 | 173 | static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, |
@@ -312,6 +331,7 @@ struct bus_type fsl_mc_bus_type = { |
312 | 331 | .match = fsl_mc_bus_match, |
313 | 332 | .uevent = fsl_mc_bus_uevent, |
314 | 333 | .dma_configure = fsl_mc_dma_configure, |
| 334 | + .dma_cleanup = fsl_mc_dma_cleanup, |
315 | 335 | .dev_groups = fsl_mc_dev_groups, |
316 | 336 | .bus_groups = fsl_mc_bus_groups, |
317 | 337 | }; |
|
0 commit comments