Skip to content

Commit ee19637

Browse files
Christoph Hellwigtorvalds
authored andcommitted
dma-mapping: consolidate dma_supported
Most architectures just call into ->dma_supported, but some also return 1 if the method is not present, or 0 if no dma ops are present (although that should never happeb). Consolidate this more broad version into common code. Also fix h8300 which inorrectly always returned 0, which would have been a problem if it's dma_set_mask implementation wasn't a similarly buggy noop. As a few architectures have much more elaborate implementations, we still allow for arch overrides. [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 efa21e4 commit ee19637

File tree

18 files changed

+25
-98
lines changed

18 files changed

+25
-98
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_supported(struct device *dev, u64 mask)
16-
{
17-
return get_dma_ops(dev)->dma_supported(dev, mask);
18-
}
19-
2015
static inline int dma_set_mask(struct device *dev, u64 mask)
2116
{
2217
return get_dma_ops(dev)->set_dma_mask(dev, mask);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops)
3838
dev->archdata.dma_ops = ops;
3939
}
4040

41+
#define HAVE_ARCH_DMA_SUPPORTED 1
42+
extern int dma_supported(struct device *dev, u64 mask);
43+
4144
/*
4245
* Note that while the generic code provides dummy dma_{alloc,free}_noncoherent
4346
* implementations, we don't provide a dma_cache_sync function so drivers using
4447
* this API are highlighted with build warnings.
4548
*/
46-
4749
#include <asm-generic/dma-mapping-common.h>
4850

4951
static inline int dma_set_mask(struct device *dev, u64 mask)
@@ -172,8 +174,6 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
172174

173175
static inline void dma_mark_clean(void *addr, size_t size) { }
174176

175-
extern int dma_supported(struct device *dev, u64 mask);
176-
177177
extern int arm_dma_set_mask(struct device *dev, u64 dma_mask);
178178

179179
/**

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +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_supported(struct device *dev, u64 mask)
88-
{
89-
struct dma_map_ops *ops = get_dma_ops(dev);
90-
return ops->dma_supported(dev, mask);
91-
}
92-
9387
static inline int dma_set_mask(struct device *dev, u64 mask)
9488
{
9589
if (!dev->dma_mask || !dma_supported(dev, mask))

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

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

1111
#include <asm-generic/dma-mapping-common.h>
1212

13-
static inline int dma_supported(struct device *dev, u64 mask)
14-
{
15-
return 0;
16-
}
17-
1813
static inline int dma_set_mask(struct device *dev, u64 mask)
1914
{
2015
return 0;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
4343
return dma_ops;
4444
}
4545

46+
#define HAVE_ARCH_DMA_SUPPORTED 1
4647
extern int dma_supported(struct device *dev, u64 mask);
4748
extern int dma_set_mask(struct device *dev, u64 mask);
4849
extern int dma_is_consistent(struct device *dev, dma_addr_t dma_handle);

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +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_supported(struct device *dev, u64 mask)
31-
{
32-
struct dma_map_ops *ops = platform_dma_get_ops(dev);
33-
return ops->dma_supported(dev, mask);
34-
}
35-
3630
static inline int
3731
dma_set_mask (struct device *dev, u64 mask)
3832
{

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,7 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
4444
return &dma_direct_ops;
4545
}
4646

47-
static inline int dma_supported(struct device *dev, u64 mask)
48-
{
49-
struct dma_map_ops *ops = get_dma_ops(dev);
50-
51-
if (unlikely(!ops))
52-
return 0;
53-
if (!ops->dma_supported)
54-
return 1;
55-
return ops->dma_supported(dev, mask);
56-
}
47+
#include <asm-generic/dma-mapping-common.h>
5748

5849
static inline int dma_set_mask(struct device *dev, u64 dma_mask)
5950
{
@@ -69,8 +60,6 @@ static inline int dma_set_mask(struct device *dev, u64 dma_mask)
6960
return 0;
7061
}
7162

72-
#include <asm-generic/dma-mapping-common.h>
73-
7463
static inline void __dma_sync(unsigned long paddr,
7564
size_t size, enum dma_data_direction direction)
7665
{

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ static inline void dma_mark_clean(void *addr, size_t size) {}
3131

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

34-
static inline int dma_supported(struct device *dev, u64 mask)
35-
{
36-
struct dma_map_ops *ops = get_dma_ops(dev);
37-
return ops->dma_supported(dev, mask);
38-
}
39-
4034
static inline int
4135
dma_set_mask(struct device *dev, u64 mask)
4236
{

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
3535
return &or1k_dma_map_ops;
3636
}
3737

38-
#include <asm-generic/dma-mapping-common.h>
39-
38+
#define HAVE_ARCH_DMA_SUPPORTED 1
4039
static inline int dma_supported(struct device *dev, u64 dma_mask)
4140
{
4241
/* Support 32 bit DMA mask exclusively */
4342
return dma_mask == DMA_BIT_MASK(32);
4443
}
4544

45+
#include <asm-generic/dma-mapping-common.h>
46+
4647
static inline int dma_set_mask(struct device *dev, u64 dma_mask)
4748
{
4849
if (!dev->dma_mask || !dma_supported(dev, dma_mask))

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,6 @@ static inline void set_dma_offset(struct device *dev, dma_addr_t off)
124124

125125
#include <asm-generic/dma-mapping-common.h>
126126

127-
static inline int dma_supported(struct device *dev, u64 mask)
128-
{
129-
struct dma_map_ops *dma_ops = get_dma_ops(dev);
130-
131-
if (unlikely(dma_ops == NULL))
132-
return 0;
133-
if (dma_ops->dma_supported == NULL)
134-
return 1;
135-
return dma_ops->dma_supported(dev, mask);
136-
}
137-
138127
extern int dma_set_mask(struct device *dev, u64 dma_mask);
139128
extern int __dma_set_mask(struct device *dev, u64 dma_mask);
140129
extern u64 __dma_get_required_mask(struct device *dev);

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,6 @@ static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
2727

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

30-
static inline int dma_supported(struct device *dev, u64 mask)
31-
{
32-
struct dma_map_ops *dma_ops = get_dma_ops(dev);
33-
34-
if (dma_ops->dma_supported == NULL)
35-
return 1;
36-
return dma_ops->dma_supported(dev, mask);
37-
}
38-
3930
static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
4031
{
4132
if (!dev->dma_mask)

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
1313

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

16-
static inline int dma_supported(struct device *dev, u64 mask)
17-
{
18-
struct dma_map_ops *ops = get_dma_ops(dev);
19-
20-
if (ops->dma_supported)
21-
return ops->dma_supported(dev, mask);
22-
23-
return 1;
24-
}
25-
2616
static inline int dma_set_mask(struct device *dev, u64 mask)
2717
{
2818
struct dma_map_ops *ops = get_dma_ops(dev);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#define DMA_ERROR_CODE (~(dma_addr_t)0x0)
99

10+
#define HAVE_ARCH_DMA_SUPPORTED 1
1011
int dma_supported(struct device *dev, u64 mask);
1112

1213
static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size,

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +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_supported(struct device *dev, u64 mask)
79-
{
80-
return get_dma_ops(dev)->dma_supported(dev, mask);
81-
}
82-
8377
static inline int
8478
dma_set_mask(struct device *dev, u64 mask)
8579
{

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,6 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
2828
return &swiotlb_dma_map_ops;
2929
}
3030

31-
static inline int dma_supported(struct device *dev, u64 mask)
32-
{
33-
struct dma_map_ops *dma_ops = get_dma_ops(dev);
34-
35-
if (unlikely(dma_ops == NULL))
36-
return 0;
37-
38-
return dma_ops->dma_supported(dev, mask);
39-
}
40-
4131
#include <asm-generic/dma-mapping-common.h>
4232

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

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
4343
bool arch_dma_alloc_attrs(struct device **dev, gfp_t *gfp);
4444
#define arch_dma_alloc_attrs arch_dma_alloc_attrs
4545

46+
#define HAVE_ARCH_DMA_SUPPORTED 1
47+
extern int dma_supported(struct device *hwdev, u64 mask);
48+
4649
#include <asm-generic/dma-mapping-common.h>
4750

48-
extern int dma_supported(struct device *hwdev, u64 mask);
4951
extern int dma_set_mask(struct device *dev, u64 mask);
5052

5153
extern void *dma_generic_alloc_coherent(struct device *dev, size_t size,

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +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_supported(struct device *dev, u64 mask)
37-
{
38-
return 1;
39-
}
40-
4135
static inline int
4236
dma_set_mask(struct device *dev, u64 mask)
4337
{

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,4 +327,17 @@ static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
327327
#endif
328328
}
329329

330+
#ifndef HAVE_ARCH_DMA_SUPPORTED
331+
static inline int dma_supported(struct device *dev, u64 mask)
332+
{
333+
struct dma_map_ops *ops = get_dma_ops(dev);
334+
335+
if (!ops)
336+
return 0;
337+
if (!ops->dma_supported)
338+
return 1;
339+
return ops->dma_supported(dev, mask);
340+
}
341+
#endif
342+
330343
#endif

0 commit comments

Comments
 (0)