Skip to content

Commit efa21e4

Browse files
Christoph Hellwigtorvalds
authored andcommitted
dma-mapping: cosolidate dma_mapping_error
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>
1 parent 1e89375 commit efa21e4

File tree

18 files changed

+19
-146
lines changed

18 files changed

+19
-146
lines changed

arch/alpha/include/asm/dma-mapping.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
1212

1313
#include <asm-generic/dma-mapping-common.h>
1414

15-
static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
16-
{
17-
return get_dma_ops(dev)->mapping_error(dev, dma_addr);
18-
}
19-
2015
static inline int dma_supported(struct device *dev, u64 mask)
2116
{
2217
return get_dma_ops(dev)->dma_supported(dev, mask);

arch/arm/include/asm/dma-mapping.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,6 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
172172

173173
static inline void dma_mark_clean(void *addr, size_t size) { }
174174

175-
/*
176-
* DMA errors are defined by all-bits-set in the DMA address.
177-
*/
178-
static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
179-
{
180-
debug_dma_mapping_error(dev, dma_addr);
181-
return dma_addr == DMA_ERROR_CODE;
182-
}
183-
184175
extern int dma_supported(struct device *dev, u64 mask);
185176

186177
extern int arm_dma_set_mask(struct device *dev, u64 dma_mask);

arch/arm64/include/asm/dma-mapping.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,6 @@ static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
8484
return (phys_addr_t)dev_addr;
8585
}
8686

87-
static inline int dma_mapping_error(struct device *dev, dma_addr_t dev_addr)
88-
{
89-
struct dma_map_ops *ops = get_dma_ops(dev);
90-
debug_dma_mapping_error(dev, dev_addr);
91-
return ops->mapping_error(dev, dev_addr);
92-
}
93-
9487
static inline int dma_supported(struct device *dev, u64 mask)
9588
{
9689
struct dma_map_ops *ops = get_dma_ops(dev);

arch/h8300/include/asm/dma-mapping.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,4 @@ static inline int dma_set_mask(struct device *dev, u64 mask)
2020
return 0;
2121
}
2222

23-
static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
24-
{
25-
return 0;
26-
}
27-
2823
#endif

arch/hexagon/include/asm/dma-mapping.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
struct device;
3333
extern int bad_dma_address;
34+
#define DMA_ERROR_CODE bad_dma_address
3435

3536
extern struct dma_map_ops *dma_ops;
3637

@@ -57,14 +58,4 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
5758
return addr + size - 1 <= *dev->dma_mask;
5859
}
5960

60-
static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
61-
{
62-
struct dma_map_ops *dma_ops = get_dma_ops(dev);
63-
64-
if (dma_ops->mapping_error)
65-
return dma_ops->mapping_error(dev, dma_addr);
66-
67-
return (dma_addr == bad_dma_address);
68-
}
69-
7061
#endif

arch/ia64/include/asm/dma-mapping.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ extern void machvec_dma_sync_sg(struct device *, struct scatterlist *, int,
2727

2828
#include <asm-generic/dma-mapping-common.h>
2929

30-
static inline int dma_mapping_error(struct device *dev, dma_addr_t daddr)
31-
{
32-
struct dma_map_ops *ops = platform_dma_get_ops(dev);
33-
debug_dma_mapping_error(dev, daddr);
34-
return ops->mapping_error(dev, daddr);
35-
}
36-
3730
static inline int dma_supported(struct device *dev, u64 mask)
3831
{
3932
struct dma_map_ops *ops = platform_dma_get_ops(dev);

arch/microblaze/include/asm/dma-mapping.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,6 @@ static inline void __dma_sync(unsigned long paddr,
8787
}
8888
}
8989

90-
static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
91-
{
92-
struct dma_map_ops *ops = get_dma_ops(dev);
93-
94-
debug_dma_mapping_error(dev, dma_addr);
95-
if (ops->mapping_error)
96-
return ops->mapping_error(dev, dma_addr);
97-
98-
return (dma_addr == DMA_ERROR_CODE);
99-
}
100-
10190
static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
10291
enum dma_data_direction direction)
10392
{

arch/mips/include/asm/dma-mapping.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,6 @@ static inline int dma_supported(struct device *dev, u64 mask)
3737
return ops->dma_supported(dev, mask);
3838
}
3939

40-
static inline int dma_mapping_error(struct device *dev, u64 mask)
41-
{
42-
struct dma_map_ops *ops = get_dma_ops(dev);
43-
44-
debug_dma_mapping_error(dev, mask);
45-
return ops->mapping_error(dev, mask);
46-
}
47-
4840
static inline int
4941
dma_set_mask(struct device *dev, u64 mask)
5042
{

arch/openrisc/include/asm/dma-mapping.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ static inline int dma_supported(struct device *dev, u64 dma_mask)
4343
return dma_mask == DMA_BIT_MASK(32);
4444
}
4545

46-
static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
47-
{
48-
return 0;
49-
}
50-
5146
static inline int dma_set_mask(struct device *dev, u64 dma_mask)
5247
{
5348
if (!dev->dma_mask || !dma_supported(dev, dma_mask))

arch/powerpc/include/asm/dma-mapping.h

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
#include <asm/io.h>
1919
#include <asm/swiotlb.h>
2020

21+
#ifdef CONFIG_PPC64
2122
#define DMA_ERROR_CODE (~(dma_addr_t)0x0)
23+
#endif
2224

2325
/* Some dma direct funcs must be visible for use in other dma_ops */
2426
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);
137139
extern int __dma_set_mask(struct device *dev, u64 dma_mask);
138140
extern u64 __dma_get_required_mask(struct device *dev);
139141

140-
static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
141-
{
142-
struct dma_map_ops *dma_ops = get_dma_ops(dev);
143-
144-
debug_dma_mapping_error(dev, dma_addr);
145-
if (dma_ops->mapping_error)
146-
return dma_ops->mapping_error(dev, dma_addr);
147-
148-
#ifdef CONFIG_PPC64
149-
return (dma_addr == DMA_ERROR_CODE);
150-
#else
151-
return 0;
152-
#endif
153-
}
154-
155142
static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
156143
{
157144
#ifdef CONFIG_SWIOTLB

arch/s390/include/asm/dma-mapping.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,4 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
4343
return addr + size - 1 <= *dev->dma_mask;
4444
}
4545

46-
static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
47-
{
48-
struct dma_map_ops *dma_ops = get_dma_ops(dev);
49-
50-
debug_dma_mapping_error(dev, dma_addr);
51-
if (dma_ops->mapping_error)
52-
return dma_ops->mapping_error(dev, dma_addr);
53-
return dma_addr == DMA_ERROR_CODE;
54-
}
55-
5646
#endif /* _ASM_S390_DMA_MAPPING_H */

arch/sh/include/asm/dma-mapping.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
99
return dma_ops;
1010
}
1111

12+
#define DMA_ERROR_CODE 0
13+
1214
#include <asm-generic/dma-mapping-common.h>
1315

1416
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)
3840
void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
3941
enum dma_data_direction dir);
4042

41-
static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
42-
{
43-
struct dma_map_ops *ops = get_dma_ops(dev);
44-
45-
debug_dma_mapping_error(dev, dma_addr);
46-
if (ops->mapping_error)
47-
return ops->mapping_error(dev, dma_addr);
48-
49-
return dma_addr == 0;
50-
}
51-
5243
/* arch/sh/mm/consistent.c */
5344
extern void *dma_generic_alloc_coherent(struct device *dev, size_t size,
5445
dma_addr_t *dma_addr, gfp_t flag,

arch/sparc/include/asm/dma-mapping.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
3838

3939
#include <asm-generic/dma-mapping-common.h>
4040

41-
static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
42-
{
43-
debug_dma_mapping_error(dev, dma_addr);
44-
return (dma_addr == DMA_ERROR_CODE);
45-
}
46-
4741
static inline int dma_set_mask(struct device *dev, u64 mask)
4842
{
4943
#ifdef CONFIG_PCI

arch/tile/include/asm/dma-mapping.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,6 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
7474
return addr + size - 1 <= *dev->dma_mask;
7575
}
7676

77-
static inline int
78-
dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
79-
{
80-
debug_dma_mapping_error(dev, dma_addr);
81-
return get_dma_ops(dev)->mapping_error(dev, dma_addr);
82-
}
83-
8477
static inline int
8578
dma_supported(struct device *dev, u64 mask)
8679
{

arch/unicore32/include/asm/dma-mapping.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,6 @@ static inline int dma_supported(struct device *dev, u64 mask)
3838
return dma_ops->dma_supported(dev, mask);
3939
}
4040

41-
static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
42-
{
43-
struct dma_map_ops *dma_ops = get_dma_ops(dev);
44-
45-
if (dma_ops->mapping_error)
46-
return dma_ops->mapping_error(dev, dma_addr);
47-
48-
return 0;
49-
}
50-
5141
#include <asm-generic/dma-mapping-common.h>
5242

5343
static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)

arch/x86/include/asm/dma-mapping.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,6 @@ bool arch_dma_alloc_attrs(struct device **dev, gfp_t *gfp);
4545

4646
#include <asm-generic/dma-mapping-common.h>
4747

48-
/* Make sure we keep the same behaviour */
49-
static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
50-
{
51-
struct dma_map_ops *ops = get_dma_ops(dev);
52-
debug_dma_mapping_error(dev, dma_addr);
53-
if (ops->mapping_error)
54-
return ops->mapping_error(dev, dma_addr);
55-
56-
return (dma_addr == DMA_ERROR_CODE);
57-
}
58-
5948
extern int dma_supported(struct device *hwdev, u64 mask);
6049
extern int dma_set_mask(struct device *dev, u64 mask);
6150

arch/xtensa/include/asm/dma-mapping.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,6 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
3232

3333
#include <asm-generic/dma-mapping-common.h>
3434

35-
static inline int
36-
dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
37-
{
38-
struct dma_map_ops *ops = get_dma_ops(dev);
39-
40-
debug_dma_mapping_error(dev, dma_addr);
41-
return ops->mapping_error(dev, dma_addr);
42-
}
43-
4435
static inline int
4536
dma_supported(struct device *dev, u64 mask)
4637
{

include/asm-generic/dma-mapping-common.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,4 +313,18 @@ static inline void dma_free_noncoherent(struct device *dev, size_t size,
313313
dma_free_attrs(dev, size, cpu_addr, dma_handle, &attrs);
314314
}
315315

316+
static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
317+
{
318+
debug_dma_mapping_error(dev, dma_addr);
319+
320+
if (get_dma_ops(dev)->mapping_error)
321+
return get_dma_ops(dev)->mapping_error(dev, dma_addr);
322+
323+
#ifdef DMA_ERROR_CODE
324+
return dma_addr == DMA_ERROR_CODE;
325+
#else
326+
return 0;
327+
#endif
328+
}
329+
316330
#endif

0 commit comments

Comments
 (0)