]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
dma-mapping: cosolidate dma_mapping_error
authorChristoph Hellwig <hch@lst.de>
Wed, 9 Sep 2015 22:39:46 +0000 (15:39 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 10 Sep 2015 20:29:01 +0000 (13:29 -0700)
Currently there are three valid implementations of dma_mapping_error:

 (1) call ->mapping_error
 (2) check for a hardcoded error code
 (3) always return 0

This patch provides a common implementation that calls ->mapping_error
if present, then checks for DMA_ERROR_CODE if defined or otherwise
returns 0.

[jcmvbkbc@gmail.com: fix xtensa]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Jonas Bonn <jonas@southpole.se>
Cc: Chris Metcalf <cmetcalf@ezchip.com>
Cc: Guan Xuetao <gxt@mprc.pku.edu.cn>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
18 files changed:
arch/alpha/include/asm/dma-mapping.h
arch/arm/include/asm/dma-mapping.h
arch/arm64/include/asm/dma-mapping.h
arch/h8300/include/asm/dma-mapping.h
arch/hexagon/include/asm/dma-mapping.h
arch/ia64/include/asm/dma-mapping.h
arch/microblaze/include/asm/dma-mapping.h
arch/mips/include/asm/dma-mapping.h
arch/openrisc/include/asm/dma-mapping.h
arch/powerpc/include/asm/dma-mapping.h
arch/s390/include/asm/dma-mapping.h
arch/sh/include/asm/dma-mapping.h
arch/sparc/include/asm/dma-mapping.h
arch/tile/include/asm/dma-mapping.h
arch/unicore32/include/asm/dma-mapping.h
arch/x86/include/asm/dma-mapping.h
arch/xtensa/include/asm/dma-mapping.h
include/asm-generic/dma-mapping-common.h

index 0552bf097245d901b050e289e2ff5961acda83b2..80ac3e835efeb74bb2332767a4fa6b385b61a6af 100644 (file)
@@ -12,11 +12,6 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
 
 #include <asm-generic/dma-mapping-common.h>
 
-static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
-{
-       return get_dma_ops(dev)->mapping_error(dev, dma_addr);
-}
-
 static inline int dma_supported(struct device *dev, u64 mask)
 {
        return get_dma_ops(dev)->dma_supported(dev, mask);
index 0b7787167b640946aa225132112d0924f4feb08b..9bef3c541c3973422fc44fe5a9cbf63f4ef760a4 100644 (file)
@@ -172,15 +172,6 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
 
 static inline void dma_mark_clean(void *addr, size_t size) { }
 
-/*
- * DMA errors are defined by all-bits-set in the DMA address.
- */
-static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
-{
-       debug_dma_mapping_error(dev, dma_addr);
-       return dma_addr == DMA_ERROR_CODE;
-}
-
 extern int dma_supported(struct device *dev, u64 mask);
 
 extern int arm_dma_set_mask(struct device *dev, u64 dma_mask);
index 178e60b8092248598d873e30f89da24ab043f27d..f45f444b7a66ac4b71fff6c0436c35edf15f73d5 100644 (file)
@@ -84,13 +84,6 @@ static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
        return (phys_addr_t)dev_addr;
 }
 
-static inline int dma_mapping_error(struct device *dev, dma_addr_t dev_addr)
-{
-       struct dma_map_ops *ops = get_dma_ops(dev);
-       debug_dma_mapping_error(dev, dev_addr);
-       return ops->mapping_error(dev, dev_addr);
-}
-
 static inline int dma_supported(struct device *dev, u64 mask)
 {
        struct dma_map_ops *ops = get_dma_ops(dev);
index 72465ce594539c272a2e896c7a5dba784c94dfe2..5eef05382fffbb8c966e652af573dccbc6d4892f 100644 (file)
@@ -20,9 +20,4 @@ static inline int dma_set_mask(struct device *dev, u64 mask)
        return 0;
 }
 
-static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
-{
-       return 0;
-}
-
 #endif
index 58d2d8f1544acb3a5af9d88a2eec3abffdb52b3f..e66119290ecab709093bbe8464bb7e096cbedfc8 100644 (file)
@@ -31,6 +31,7 @@
 
 struct device;
 extern int bad_dma_address;
+#define DMA_ERROR_CODE bad_dma_address
 
 extern struct dma_map_ops *dma_ops;
 
@@ -57,14 +58,4 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
        return addr + size - 1 <= *dev->dma_mask;
 }
 
-static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
-{
-       struct dma_map_ops *dma_ops = get_dma_ops(dev);
-
-       if (dma_ops->mapping_error)
-               return dma_ops->mapping_error(dev, dma_addr);
-
-       return (dma_addr == bad_dma_address);
-}
-
 #endif
index a925ff03c964083f152e536b70a170c45b28ff48..27b713d0edbc3725a03543d437eae24b79857d41 100644 (file)
@@ -27,13 +27,6 @@ extern void machvec_dma_sync_sg(struct device *, struct scatterlist *, int,
 
 #include <asm-generic/dma-mapping-common.h>
 
-static inline int dma_mapping_error(struct device *dev, dma_addr_t daddr)
-{
-       struct dma_map_ops *ops = platform_dma_get_ops(dev);
-       debug_dma_mapping_error(dev, daddr);
-       return ops->mapping_error(dev, daddr);
-}
-
 static inline int dma_supported(struct device *dev, u64 mask)
 {
        struct dma_map_ops *ops = platform_dma_get_ops(dev);
index bc81625d486fd9827fa0caeef868ac6747c59a08..e5b84383926301817fea7287163ae19eb821597e 100644 (file)
@@ -87,17 +87,6 @@ static inline void __dma_sync(unsigned long paddr,
        }
 }
 
-static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
-{
-       struct dma_map_ops *ops = get_dma_ops(dev);
-
-       debug_dma_mapping_error(dev, dma_addr);
-       if (ops->mapping_error)
-               return ops->mapping_error(dev, dma_addr);
-
-       return (dma_addr == DMA_ERROR_CODE);
-}
-
 static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
                enum dma_data_direction direction)
 {
index 709b2ba79cc33ee1e698c1113d17c6936c5ea416..158bb36bdcb4c7d70f9f4ae6144d9a7b3e8f4025 100644 (file)
@@ -37,14 +37,6 @@ static inline int dma_supported(struct device *dev, u64 mask)
        return ops->dma_supported(dev, mask);
 }
 
-static inline int dma_mapping_error(struct device *dev, u64 mask)
-{
-       struct dma_map_ops *ops = get_dma_ops(dev);
-
-       debug_dma_mapping_error(dev, mask);
-       return ops->mapping_error(dev, mask);
-}
-
 static inline int
 dma_set_mask(struct device *dev, u64 mask)
 {
index 57722528ea4d46b2638529f95f4721c6f37e1217..7dfe9d50856e7ef99bd66100733d8c2f17dfa407 100644 (file)
@@ -43,11 +43,6 @@ static inline int dma_supported(struct device *dev, u64 dma_mask)
        return dma_mask == DMA_BIT_MASK(32);
 }
 
-static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
-{
-       return 0;
-}
-
 static inline int dma_set_mask(struct device *dev, u64 dma_mask)
 {
        if (!dev->dma_mask || !dma_supported(dev, dma_mask))
index 7971b421c6771d8bc7096c17175c7e327d32a6be..712d5afc055af1092ba855d75a1326abd17da649 100644 (file)
@@ -18,7 +18,9 @@
 #include <asm/io.h>
 #include <asm/swiotlb.h>
 
+#ifdef CONFIG_PPC64
 #define DMA_ERROR_CODE         (~(dma_addr_t)0x0)
+#endif
 
 /* Some dma direct funcs must be visible for use in other dma_ops */
 extern void *__dma_direct_alloc_coherent(struct device *dev, size_t size,
@@ -137,21 +139,6 @@ extern int dma_set_mask(struct device *dev, u64 dma_mask);
 extern int __dma_set_mask(struct device *dev, u64 dma_mask);
 extern u64 __dma_get_required_mask(struct device *dev);
 
-static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
-{
-       struct dma_map_ops *dma_ops = get_dma_ops(dev);
-
-       debug_dma_mapping_error(dev, dma_addr);
-       if (dma_ops->mapping_error)
-               return dma_ops->mapping_error(dev, dma_addr);
-
-#ifdef CONFIG_PPC64
-       return (dma_addr == DMA_ERROR_CODE);
-#else
-       return 0;
-#endif
-}
-
 static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
 {
 #ifdef CONFIG_SWIOTLB
index b729efeb9ad8bba7f06a4fd131b756b240f5de3a..3c293291319bc8d4de3a497857038d4d3dc571a5 100644 (file)
@@ -43,14 +43,4 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
        return addr + size - 1 <= *dev->dma_mask;
 }
 
-static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
-{
-       struct dma_map_ops *dma_ops = get_dma_ops(dev);
-
-       debug_dma_mapping_error(dev, dma_addr);
-       if (dma_ops->mapping_error)
-               return dma_ops->mapping_error(dev, dma_addr);
-       return dma_addr == DMA_ERROR_CODE;
-}
-
 #endif /* _ASM_S390_DMA_MAPPING_H */
index 2c3fa2ccbe9b452721c3ac599cb8dfbaa1acc753..98308c497162c22e15e88e17e452918eae00f4ba 100644 (file)
@@ -9,6 +9,8 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
        return dma_ops;
 }
 
+#define DMA_ERROR_CODE 0
+
 #include <asm-generic/dma-mapping-common.h>
 
 static inline int dma_supported(struct device *dev, u64 mask)
@@ -38,17 +40,6 @@ static inline int dma_set_mask(struct device *dev, u64 mask)
 void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
                    enum dma_data_direction dir);
 
-static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
-{
-       struct dma_map_ops *ops = get_dma_ops(dev);
-
-       debug_dma_mapping_error(dev, dma_addr);
-       if (ops->mapping_error)
-               return ops->mapping_error(dev, dma_addr);
-
-       return dma_addr == 0;
-}
-
 /* arch/sh/mm/consistent.c */
 extern void *dma_generic_alloc_coherent(struct device *dev, size_t size,
                                        dma_addr_t *dma_addr, gfp_t flag,
index 2564edcb97280e1f1c535d673d260038e495b3a4..5069d137453b432d215879c71d4cf60010d8f557 100644 (file)
@@ -38,12 +38,6 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
 
 #include <asm-generic/dma-mapping-common.h>
 
-static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
-{
-       debug_dma_mapping_error(dev, dma_addr);
-       return (dma_addr == DMA_ERROR_CODE);
-}
-
 static inline int dma_set_mask(struct device *dev, u64 mask)
 {
 #ifdef CONFIG_PCI
index e982dfa5d2f4b0394f389041696e5ac963852167..f8f7a05023bfc352894dc3980f3b08dd04644751 100644 (file)
@@ -74,13 +74,6 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
        return addr + size - 1 <= *dev->dma_mask;
 }
 
-static inline int
-dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
-{
-       debug_dma_mapping_error(dev, dma_addr);
-       return get_dma_ops(dev)->mapping_error(dev, dma_addr);
-}
-
 static inline int
 dma_supported(struct device *dev, u64 mask)
 {
index 636e942940a0402195d794a1c7eeb6e7347262f0..175d7e3f7b0ab573ec30c9f2a04cac1355a5bcb1 100644 (file)
@@ -38,16 +38,6 @@ static inline int dma_supported(struct device *dev, u64 mask)
        return dma_ops->dma_supported(dev, mask);
 }
 
-static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
-{
-       struct dma_map_ops *dma_ops = get_dma_ops(dev);
-
-       if (dma_ops->mapping_error)
-               return dma_ops->mapping_error(dev, dma_addr);
-
-       return 0;
-}
-
 #include <asm-generic/dma-mapping-common.h>
 
 static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
index 7e47e4d6e69cd990ddc9c0d6fb074b85f429cfc2..bbca62e3e43f5e7dc06c7280f3470c89399849ca 100644 (file)
@@ -45,17 +45,6 @@ bool arch_dma_alloc_attrs(struct device **dev, gfp_t *gfp);
 
 #include <asm-generic/dma-mapping-common.h>
 
-/* Make sure we keep the same behaviour */
-static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
-{
-       struct dma_map_ops *ops = get_dma_ops(dev);
-       debug_dma_mapping_error(dev, dma_addr);
-       if (ops->mapping_error)
-               return ops->mapping_error(dev, dma_addr);
-
-       return (dma_addr == DMA_ERROR_CODE);
-}
-
 extern int dma_supported(struct device *hwdev, u64 mask);
 extern int dma_set_mask(struct device *dev, u64 mask);
 
index 0a19581375dac2a0d382746d9349510a95baa14b..21925bfdaff7018d6522c16428f6ae251542b38f 100644 (file)
@@ -32,15 +32,6 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
 
 #include <asm-generic/dma-mapping-common.h>
 
-static inline int
-dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
-{
-       struct dma_map_ops *ops = get_dma_ops(dev);
-
-       debug_dma_mapping_error(dev, dma_addr);
-       return ops->mapping_error(dev, dma_addr);
-}
-
 static inline int
 dma_supported(struct device *dev, u64 mask)
 {
index ec321dd98f93bbc56010337831f0c2359f8059a2..cdaa24193d4cff2939fb134e5a7094abbc8acb04 100644 (file)
@@ -313,4 +313,18 @@ static inline void dma_free_noncoherent(struct device *dev, size_t size,
        dma_free_attrs(dev, size, cpu_addr, dma_handle, &attrs);
 }
 
+static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
+{
+       debug_dma_mapping_error(dev, dma_addr);
+
+       if (get_dma_ops(dev)->mapping_error)
+               return get_dma_ops(dev)->mapping_error(dev, dma_addr);
+
+#ifdef DMA_ERROR_CODE
+       return dma_addr == DMA_ERROR_CODE;
+#else
+       return 0;
+#endif
+}
+
 #endif