]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
dma-mapping: tidy up dma_parms default handling
authorRobin Murphy <robin.murphy@arm.com>
Sat, 7 Nov 2015 00:32:51 +0000 (16:32 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 7 Nov 2015 01:50:42 +0000 (17:50 -0800)
Many DMA controllers and other devices set max_segment_size to
indicate their scatter-gather capability, but have no interest in
segment_boundary_mask. However, the existence of a dma_parms structure
precludes the use of any default value, leaving them as zeros (assuming
a properly kzalloc'ed structure). If a well-behaved IOMMU (or SWIOTLB)
then tries to respect this by ensuring a mapped segment does not cross
a zero-byte boundary, hilarity ensues.

Since zero is a nonsensical value for either parameter, treat it as an
indicator for "default", as might be expected. In the process, clean up
a bit by replacing the bare constants with slightly more meaningful
macros and removing the superfluous "else" statements.

[akpm@linux-foundation.org: dma-mapping.h needs sizes.h for SZ_64K]
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Reviewed-by: Sumit Semwal <sumit.semwal@linaro.org>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Sakari Ailus <sakari.ailus@iki.fi>
Cc: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/dma-mapping.h

index ac07ff090919309c4f51d0a29cfeb9f9a7d673e4..2e551e2d2d03a7d78c80633637672a483ae42199 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef _LINUX_DMA_MAPPING_H
 #define _LINUX_DMA_MAPPING_H
 
+#include <linux/sizes.h>
 #include <linux/string.h>
 #include <linux/device.h>
 #include <linux/err.h>
@@ -145,7 +146,9 @@ static inline void arch_teardown_dma_ops(struct device *dev) { }
 
 static inline unsigned int dma_get_max_seg_size(struct device *dev)
 {
-       return dev->dma_parms ? dev->dma_parms->max_segment_size : 65536;
+       if (dev->dma_parms && dev->dma_parms->max_segment_size)
+               return dev->dma_parms->max_segment_size;
+       return SZ_64K;
 }
 
 static inline unsigned int dma_set_max_seg_size(struct device *dev,
@@ -154,14 +157,15 @@ static inline unsigned int dma_set_max_seg_size(struct device *dev,
        if (dev->dma_parms) {
                dev->dma_parms->max_segment_size = size;
                return 0;
-       } else
-               return -EIO;
+       }
+       return -EIO;
 }
 
 static inline unsigned long dma_get_seg_boundary(struct device *dev)
 {
-       return dev->dma_parms ?
-               dev->dma_parms->segment_boundary_mask : 0xffffffff;
+       if (dev->dma_parms && dev->dma_parms->segment_boundary_mask)
+               return dev->dma_parms->segment_boundary_mask;
+       return DMA_BIT_MASK(32);
 }
 
 static inline int dma_set_seg_boundary(struct device *dev, unsigned long mask)
@@ -169,8 +173,8 @@ static inline int dma_set_seg_boundary(struct device *dev, unsigned long mask)
        if (dev->dma_parms) {
                dev->dma_parms->segment_boundary_mask = mask;
                return 0;
-       } else
-               return -EIO;
+       }
+       return -EIO;
 }
 
 #ifndef dma_max_pfn