DMA teardown fixes
Subsystems (2)
v2 cover DMA teardown fixes
Hi again,
Here's v2 of the DMA teardown fixes I posted on Monday:
http://lists.infradead.org/pipermail/linux-arm-kernel/2015-January/315366.html
The only change since v1 is that I've moved the conversion to using to_dma_iommu_mapping into a separate patch and converted the whole of dma-mapping.c in the process (suggested by Laurent).
I plan to send patches 2 and 3 via rmk and I hope that arm-soc can pick up the first one.
Will
--->8
Will Deacon (3):
of/platform: teardown DMA mappings on device destruction
ARM: dma-mapping: don't detach devices without an IOMMU during
teardown
ARM: dma-mapping: use to_dma_iommu_mapping instead of accessing
archdata
arch/arm/mm/dma-mapping.c | 25 ++++++++++++++----------- drivers/of/platform.c | 1 + 2 files changed, 15 insertions(+), 11 deletions(-)
Signature · 1 line
2.1.4
PATCH v2 1/3 of/platform: teardown DMA mappings on device destruction
Now that we can create and attach to IOMMU domains via of_dma_configure, make sure we give the architecture a chance to tear them down when a platform or amba device is destroyed.
--- drivers/of/platform.c | 1 + 1 file changed, 1 insertion(+)
drivers/of/platform.c +1 -0
@@ -526,6 +526,7 @@ static int of_platform_device_destroy(struct device *dev, void *data)amba_device_unregister (to_amba_device (dev));#endif +of_dma_deconfigure (dev);of_node_clear_flag (dev->of_node,OF_POPULATED );of_node_clear_flag (dev->of_node,OF_POPULATED_BUS );return 0 ;
Signature · 1 line
2.1.4
PATCH v2 2/3 ARM: dma-mapping: don't detach devices without an IOMMU during teardown
In reply to Will DeaconWhen tearing down the DMA ops for a device via of_dma_deconfigure, we unconditionally detach the device from its IOMMU domain. For devices that aren't actually behind an IOMMU, this produces a "Not attached" warning message on the console.
This patch changes the teardown code so that we don't detach from the IOMMU domain when there isn't an IOMMU dma mapping to start with.
--- arch/arm/mm/dma-mapping.c | 3 +++ 1 file changed, 3 insertions(+)
arch/arm/mm/dma-mapping.c +3 -0
@@ -2025,6 +2025,9 @@ static void arm_teardown_iommu_dma_ops(struct device *dev) {struct dma_iommu_mapping *mapping = dev->archdata.mapping; +if (!mapping) +return ; +arm_iommu_detach_device (dev);arm_iommu_release_mapping (mapping); }
Signature · 1 line
2.1.4
PATCH v2 3/3 ARM: dma-mapping: use to_dma_iommu_mapping instead of accessing archdata
In reply to Will DeaconWhen using the IOMMU-backed DMA ops for a device, we store a pointer to the dma_iommu_mapping structure (used to keep track of the address space) in the archdata.mapping field of the struct device.
Rather than access this field directly, use the to_dma_iommu_mapping helper in dma-mapping, so that we don't really care where the mapping information is held.
--- arch/arm/mm/dma-mapping.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
arch/arm/mm/dma-mapping.c +11 -11
@@ -1206,7 +1206,7 @@ __iommu_alloc_remap(struct page **pages, size_t size, gfp_t gfp, pgprot_t prot,static dma_addr_t __iommu_create_mapping (struct device *dev,struct page **pages,size_t size) { -struct dma_iommu_mapping *mapping = dev->archdata.mapping; +struct dma_iommu_mapping *mapping =to_dma_iommu_mapping (dev);unsigned int count =PAGE_ALIGN (size) >>PAGE_SHIFT ;dma_addr_t dma_addr, iova;int i, ret =DMA_ERROR_CODE ;
@@ -1242,7 +1242,7 @@ fail:static int __iommu_remove_mapping (struct device *dev,dma_addr_t iova,size_t size) { -struct dma_iommu_mapping *mapping = dev->archdata.mapping; +struct dma_iommu_mapping *mapping =to_dma_iommu_mapping (dev);/* * add optional in-page offset from iova to size and align
@@ -1457,7 +1457,7 @@ static int __map_sg_chunk(struct device *dev, struct scatterlist *sg, enum dma_data_direction dir, struct dma_attrs *attrs, bool is_coherent) { - struct dma_iommu_mapping *mapping = dev->archdata.mapping; + struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev);dma_addr_t iova, iova_base;int ret =0 ;unsigned int count;
@@ -1678,7 +1678,7 @@ static dma_addr_t arm_coherent_iommu_map_page(struct device *dev, struct page *p unsigned long offset, size_t size, enum dma_data_direction dir, struct dma_attrs *attrs) { - struct dma_iommu_mapping *mapping = dev->archdata.mapping; + struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev);dma_addr_t dma_addr;int ret, prot, len =PAGE_ALIGN (size + offset);
@@ -1731,7 +1731,7 @@ static void arm_coherent_iommu_unmap_page(struct device *dev, dma_addr_t handle, size_t size, enum dma_data_direction dir, struct dma_attrs *attrs) { - struct dma_iommu_mapping *mapping = dev->archdata.mapping; + struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev);dma_addr_t iova = handle &PAGE_MASK ;int offset = handle & ~PAGE_MASK ;int len =PAGE_ALIGN (size + offset);
@@ -1756,7 +1756,7 @@ static void arm_iommu_unmap_page(struct device *dev, dma_addr_t handle, size_t size, enum dma_data_direction dir, struct dma_attrs *attrs) { - struct dma_iommu_mapping *mapping = dev->archdata.mapping; + struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev);dma_addr_t iova = handle &PAGE_MASK ;struct page *page =phys_to_page (iommu_iova_to_phys (mapping->domain, iova));int offset = handle & ~PAGE_MASK ;
@@ -1775,7 +1775,7 @@ static void arm_iommu_unmap_page(struct device *dev, dma_addr_t handle,static void arm_iommu_sync_single_for_cpu (struct device *dev,dma_addr_t handle,size_t size,enum dma_data_direction dir) { -struct dma_iommu_mapping *mapping = dev->archdata.mapping; +struct dma_iommu_mapping *mapping =to_dma_iommu_mapping (dev);dma_addr_t iova = handle &PAGE_MASK ;struct page *page =phys_to_page (iommu_iova_to_phys (mapping->domain, iova));unsigned int offset = handle & ~PAGE_MASK ;
@@ -1789,7 +1789,7 @@ static void arm_iommu_sync_single_for_cpu(struct device *dev,static void arm_iommu_sync_single_for_device (struct device *dev,dma_addr_t handle,size_t size,enum dma_data_direction dir) { -struct dma_iommu_mapping *mapping = dev->archdata.mapping; +struct dma_iommu_mapping *mapping =to_dma_iommu_mapping (dev);dma_addr_t iova = handle &PAGE_MASK ;struct page *page =phys_to_page (iommu_iova_to_phys (mapping->domain, iova));unsigned int offset = handle & ~PAGE_MASK ;
@@ -1960,7 +1960,7 @@ int arm_iommu_attach_device(struct device *dev,return err;kref_get (&mapping->kref); - dev->archdata.mapping = mapping; +to_dma_iommu_mapping (dev) = mapping;pr_debug ("Attached IOMMU controller to %s device.\n" ,dev_name (dev));return 0 ;
@@ -1985,7 +1985,7 @@ void arm_iommu_detach_device(struct device *dev)iommu_detach_device (mapping->domain, dev);kref_put (&mapping->kref, release_iommu_mapping); - dev->archdata.mapping =NULL ; +to_dma_iommu_mapping (dev) =NULL ;pr_debug ("Detached IOMMU controller from %s device.\n" ,dev_name (dev)); }
@@ -2023,7 +2023,7 @@ static bool arm_setup_iommu_dma_ops(struct device *dev, u64 dma_base, u64 size,static void arm_teardown_iommu_dma_ops (struct device *dev) { -struct dma_iommu_mapping *mapping = dev->archdata.mapping; +struct dma_iommu_mapping *mapping =to_dma_iommu_mapping (dev);if (!mapping)return ;
Signature · 1 line
2.1.4
PATCH v2 1/3 of/platform: teardown DMA mappings on device destruction
In reply to Will DeaconQuoted 6 lines · Will Deacon
Now that we can create and attach to IOMMU domains via
of_dma_configure, make sure we give the architecture a chance to tear them down when a platform or amba device is destroyed.Reported-by Laurent Pinchart <[email protected]>Signed-off-by Will Deacon <[email protected]>
Quoted 24 lines
--- drivers/of/platform.c | 1 + 1 file changed, 1 insertion(+)drivers/of/platform.c +1
-1@@ -526,6 +526,7 @@ static int of_platform_device_destroy(struct device *dev, void *data)amba_device_unregister (to_amba_device (dev));#endif +of_dma_deconfigure (dev);of_node_clear_flag (dev->of_node,OF_POPULATED );of_node_clear_flag (dev->of_node,OF_POPULATED_BUS );return 0 ; --2.1.4
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel