@@ -758,6 +758,9 @@ size_t arm_iommu_iova_avail(struct device *dev)
size_t size = 0;
unsigned long start = 0;
+ BUG_ON(!dev);
+ BUG_ON(!mapping);
+
spin_lock_irqsave(&mapping->lock, flags);
while (1) {
unsigned long end;
@@ -1513,7 +1516,7 @@ arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, size_t size,
mapping->domain = iommu_domain_alloc(bus);
if (!mapping->domain)
goto err3;
-
+ bus->map = mapping;
kref_init(&mapping->kref);
return mapping;
err3:
@@ -21,6 +21,8 @@
#include <linux/slab.h>
#include <linux/pm_runtime.h>
+#include <asm/dma-iommu.h>
+
#include "base.h"
#define to_platform_driver(drv) (container_of((drv), struct platform_driver, \
@@ -305,8 +307,13 @@ int platform_device_add(struct platform_device *pdev)
dev_name(&pdev->dev), dev_name(pdev->dev.parent));
ret = device_add(&pdev->dev);
- if (ret == 0)
- return ret;
+ if (ret)
+ goto failed;
+
+ if (platform_bus_type.map)
+ arm_iommu_attach_device(&pdev->dev, platform_bus_type.map);
+
+ return 0;
failed:
while (--i >= 0) {
@@ -34,6 +34,7 @@ struct subsys_private;
struct bus_type;
struct device_node;
struct iommu_ops;
+struct dma_iommu_mapping;
struct bus_attribute {
struct attribute attr;
@@ -101,6 +102,7 @@ struct bus_type {
const struct dev_pm_ops *pm;
struct iommu_ops *iommu_ops;
+ struct dma_iommu_mapping *map;
struct subsys_private *p;
};