Skip to contentSkip to conversation

ARM: dma-mapping: Add macro to_dma_iommu_mapping()

PATCH New Hiroshi Doyu 1 participant 2 messages Jan 24, 2013 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 ARM: dma-mapping: Add macro to_dma_iommu_mapping()

This can be built without CONFIG_ARM_DMA_USE_IOMMU.

---
 arch/arm/include/asm/device.h |    6 ++++++
 1 file changed, 6 insertions(+)
arch/arm/include/asm/device.h +6 -0
index 5191a83..6fbe514 100644
@@ -33,4 +33,10 @@ struct pdev_archdata {
 #endif
 };
 
+#ifdef CONFIG_ARM_DMA_USE_IOMMU
+#define to_dma_iommu_mapping(dev) ((dev)->archdata.mapping)
+#else
+#define to_dma_iommu_mapping(dev) NULL
+#endif
+
 #endif
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 2/2 ARM: dma-mapping: Add arm_iommu_detach_device()

A counter part of arm_iommu_attach_device().

---
 arch/arm/include/asm/dma-iommu.h |    1 +
 arch/arm/mm/dma-mapping.c        |   25 +++++++++++++++++++++++++
 2 files changed, 26 insertions(+)
arch/arm/include/asm/dma-iommu.h +1 -0
index 799b094..af1ac4ed 100644
@@ -29,6 +29,7 @@ void arm_iommu_release_mapping(struct dma_iommu_mapping *mapping);
 
 int arm_iommu_attach_device(struct device *dev,
 					struct dma_iommu_mapping *mapping);
+void arm_iommu_detach_device(struct device *dev);
 
 #endif /* __KERNEL__ */
 #endif
arch/arm/mm/dma-mapping.c +25 -0
index 6b2fb87..b075a1f 100644
@@ -1842,4 +1842,29 @@ int arm_iommu_attach_device(struct device *dev,
 	return 0;
 }
 
+/**
+ * arm_iommu_detach_device
+ * @dev: valid struct device pointer
+ *
+ * Detaches the provided device from a previously attached map.
+ * This voids the dma operations (dma_map_ops pointer)
+ */
+void arm_iommu_detach_device(struct device *dev)
+{
+	struct dma_iommu_mapping *mapping;
+
+	mapping = to_dma_iommu_mapping(dev);
+	if (!mapping) {
+		dev_warn(dev, "Not attached\n");
+		return;
+	}
+
+	iommu_detach_device(mapping->domain, dev);
+	kref_put(&mapping->kref, release_iommu_mapping);
+	mapping = NULL;
+	set_dma_ops(dev, NULL);
+
+	pr_debug("Detached IOMMU controller from %s device.\n", dev_name(dev));
+}
+
 #endif
Signature · 1 line
1.7.9.5