Skip to content

Commit c5e8c39

Browse files
committed
Merge remote-tracking branch 'iommu/vfio-notifier-fix' into v5.19/vfio/next
Merge IOMMU dependencies for vfio. Signed-off-by: Alex Williamson <[email protected]>
2 parents ff806cb + 0286300 commit c5e8c39

File tree

19 files changed

+417
-362
lines changed

19 files changed

+417
-362
lines changed

drivers/amba/bus.c

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
#include <linux/platform_device.h>
2121
#include <linux/reset.h>
2222
#include <linux/of_irq.h>
23+
#include <linux/of_device.h>
24+
#include <linux/acpi.h>
25+
#include <linux/iommu.h>
26+
#include <linux/dma-map-ops.h>
2327

2428
#define to_amba_driver(d) container_of(d, struct amba_driver, drv)
2529

@@ -273,6 +277,36 @@ static void amba_shutdown(struct device *dev)
273277
drv->shutdown(to_amba_device(dev));
274278
}
275279

280+
static int amba_dma_configure(struct device *dev)
281+
{
282+
struct amba_driver *drv = to_amba_driver(dev->driver);
283+
enum dev_dma_attr attr;
284+
int ret = 0;
285+
286+
if (dev->of_node) {
287+
ret = of_dma_configure(dev, dev->of_node, true);
288+
} else if (has_acpi_companion(dev)) {
289+
attr = acpi_get_dma_attr(to_acpi_device_node(dev->fwnode));
290+
ret = acpi_dma_configure(dev, attr);
291+
}
292+
293+
if (!ret && !drv->driver_managed_dma) {
294+
ret = iommu_device_use_default_domain(dev);
295+
if (ret)
296+
arch_teardown_dma_ops(dev);
297+
}
298+
299+
return ret;
300+
}
301+
302+
static void amba_dma_cleanup(struct device *dev)
303+
{
304+
struct amba_driver *drv = to_amba_driver(dev->driver);
305+
306+
if (!drv->driver_managed_dma)
307+
iommu_device_unuse_default_domain(dev);
308+
}
309+
276310
#ifdef CONFIG_PM
277311
/*
278312
* Hooks to provide runtime PM of the pclk (bus clock). It is safe to
@@ -341,7 +375,8 @@ struct bus_type amba_bustype = {
341375
.probe = amba_probe,
342376
.remove = amba_remove,
343377
.shutdown = amba_shutdown,
344-
.dma_configure = platform_dma_configure,
378+
.dma_configure = amba_dma_configure,
379+
.dma_cleanup = amba_dma_cleanup,
345380
.pm = &amba_pm,
346381
};
347382
EXPORT_SYMBOL_GPL(amba_bustype);

drivers/base/dd.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,8 @@ static int really_probe(struct device *dev, struct device_driver *drv)
671671
if (dev->bus)
672672
blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
673673
BUS_NOTIFY_DRIVER_NOT_BOUND, dev);
674+
if (dev->bus && dev->bus->dma_cleanup)
675+
dev->bus->dma_cleanup(dev);
674676
pinctrl_bind_failed:
675677
device_links_no_driver(dev);
676678
device_unbind_cleanup(dev);
@@ -1199,6 +1201,9 @@ static void __device_release_driver(struct device *dev, struct device *parent)
11991201

12001202
device_remove(dev);
12011203

1204+
if (dev->bus && dev->bus->dma_cleanup)
1205+
dev->bus->dma_cleanup(dev);
1206+
12021207
device_links_driver_cleanup(dev);
12031208
device_unbind_cleanup(dev);
12041209

drivers/base/platform.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include <linux/property.h>
3131
#include <linux/kmemleak.h>
3232
#include <linux/types.h>
33+
#include <linux/iommu.h>
34+
#include <linux/dma-map-ops.h>
3335

3436
#include "base.h"
3537
#include "power/power.h"
@@ -1454,9 +1456,9 @@ static void platform_shutdown(struct device *_dev)
14541456
drv->shutdown(dev);
14551457
}
14561458

1457-
1458-
int platform_dma_configure(struct device *dev)
1459+
static int platform_dma_configure(struct device *dev)
14591460
{
1461+
struct platform_driver *drv = to_platform_driver(dev->driver);
14601462
enum dev_dma_attr attr;
14611463
int ret = 0;
14621464

@@ -1467,9 +1469,23 @@ int platform_dma_configure(struct device *dev)
14671469
ret = acpi_dma_configure(dev, attr);
14681470
}
14691471

1472+
if (!ret && !drv->driver_managed_dma) {
1473+
ret = iommu_device_use_default_domain(dev);
1474+
if (ret)
1475+
arch_teardown_dma_ops(dev);
1476+
}
1477+
14701478
return ret;
14711479
}
14721480

1481+
static void platform_dma_cleanup(struct device *dev)
1482+
{
1483+
struct platform_driver *drv = to_platform_driver(dev->driver);
1484+
1485+
if (!drv->driver_managed_dma)
1486+
iommu_device_unuse_default_domain(dev);
1487+
}
1488+
14731489
static const struct dev_pm_ops platform_dev_pm_ops = {
14741490
SET_RUNTIME_PM_OPS(pm_generic_runtime_suspend, pm_generic_runtime_resume, NULL)
14751491
USE_PLATFORM_PM_SLEEP_OPS
@@ -1484,6 +1500,7 @@ struct bus_type platform_bus_type = {
14841500
.remove = platform_remove,
14851501
.shutdown = platform_shutdown,
14861502
.dma_configure = platform_dma_configure,
1503+
.dma_cleanup = platform_dma_cleanup,
14871504
.pm = &platform_dev_pm_ops,
14881505
};
14891506
EXPORT_SYMBOL_GPL(platform_bus_type);

drivers/bus/fsl-mc/fsl-mc-bus.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/dma-mapping.h>
2222
#include <linux/acpi.h>
2323
#include <linux/iommu.h>
24+
#include <linux/dma-map-ops.h>
2425

2526
#include "fsl-mc-private.h"
2627

@@ -140,15 +141,33 @@ static int fsl_mc_dma_configure(struct device *dev)
140141
{
141142
struct device *dma_dev = dev;
142143
struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
144+
struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(dev->driver);
143145
u32 input_id = mc_dev->icid;
146+
int ret;
144147

145148
while (dev_is_fsl_mc(dma_dev))
146149
dma_dev = dma_dev->parent;
147150

148151
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);
150168

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);
152171
}
153172

154173
static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
@@ -312,6 +331,7 @@ struct bus_type fsl_mc_bus_type = {
312331
.match = fsl_mc_bus_match,
313332
.uevent = fsl_mc_bus_uevent,
314333
.dma_configure = fsl_mc_dma_configure,
334+
.dma_cleanup = fsl_mc_dma_cleanup,
315335
.dev_groups = fsl_mc_dev_groups,
316336
.bus_groups = fsl_mc_bus_groups,
317337
};

0 commit comments

Comments
 (0)