Skip to content

Commit 452e06a

Browse files
Christoph Hellwigtorvalds
authored andcommitted
dma-mapping: consolidate dma_set_mask
Almost everyone implements dma_set_mask the same way, although some time that's hidden in ->set_dma_mask methods. This patch consolidates those into a common implementation that either calls ->set_dma_mask if present or otherwise uses the default implementation. Some architectures used to only call ->set_dma_mask after the initial checks, and those instance have been fixed to do the full work. h8300 implemented dma_set_mask bogusly as a no-ops and has been fixed. Unfortunately some architectures overload unrelated semantics like changing the dma_ops into it so we still need to allow for an architecture override for now. [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 ee19637 commit 452e06a

File tree

24 files changed

+28
-169
lines changed

24 files changed

+28
-169
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_set_mask(struct device *dev, u64 mask)
16-
{
17-
return get_dma_ops(dev)->set_dma_mask(dev, mask);
18-
}
19-
2015
#define dma_cache_sync(dev, va, size, dir) ((void)0)
2116

2217
#endif /* _ALPHA_DMA_MAPPING_H */

arch/alpha/kernel/pci-noop.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,23 +166,13 @@ static int alpha_noop_supported(struct device *dev, u64 mask)
166166
return mask < 0x00ffffffUL ? 0 : 1;
167167
}
168168

169-
static int alpha_noop_set_mask(struct device *dev, u64 mask)
170-
{
171-
if (!dev->dma_mask || !dma_supported(dev, mask))
172-
return -EIO;
173-
174-
*dev->dma_mask = mask;
175-
return 0;
176-
}
177-
178169
struct dma_map_ops alpha_noop_ops = {
179170
.alloc = alpha_noop_alloc_coherent,
180171
.free = alpha_noop_free_coherent,
181172
.map_page = alpha_noop_map_page,
182173
.map_sg = alpha_noop_map_sg,
183174
.mapping_error = alpha_noop_mapping_error,
184175
.dma_supported = alpha_noop_supported,
185-
.set_dma_mask = alpha_noop_set_mask,
186176
};
187177

188178
struct dma_map_ops *dma_ops = &alpha_noop_ops;

arch/alpha/kernel/pci_iommu.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -939,16 +939,6 @@ static int alpha_pci_mapping_error(struct device *dev, dma_addr_t dma_addr)
939939
return dma_addr == 0;
940940
}
941941

942-
static int alpha_pci_set_mask(struct device *dev, u64 mask)
943-
{
944-
if (!dev->dma_mask ||
945-
!pci_dma_supported(alpha_gendev_to_pci(dev), mask))
946-
return -EIO;
947-
948-
*dev->dma_mask = mask;
949-
return 0;
950-
}
951-
952942
struct dma_map_ops alpha_pci_ops = {
953943
.alloc = alpha_pci_alloc_coherent,
954944
.free = alpha_pci_free_coherent,
@@ -958,7 +948,6 @@ struct dma_map_ops alpha_pci_ops = {
958948
.unmap_sg = alpha_pci_unmap_sg,
959949
.mapping_error = alpha_pci_mapping_error,
960950
.dma_supported = alpha_pci_supported,
961-
.set_dma_mask = alpha_pci_set_mask,
962951
};
963952

964953
struct dma_map_ops *dma_ops = &alpha_pci_ops;

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ extern int dma_supported(struct device *dev, u64 mask);
4848
*/
4949
#include <asm-generic/dma-mapping-common.h>
5050

51-
static inline int dma_set_mask(struct device *dev, u64 mask)
52-
{
53-
return get_dma_ops(dev)->set_dma_mask(dev, mask);
54-
}
55-
5651
#ifdef __arch_page_to_dma
5752
#error Please update to __arch_pfn_to_dma
5853
#endif

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +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_set_mask(struct device *dev, u64 mask)
88-
{
89-
if (!dev->dma_mask || !dma_supported(dev, mask))
90-
return -EIO;
91-
*dev->dma_mask = mask;
92-
93-
return 0;
94-
}
95-
9687
static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
9788
{
9889
if (!dev->dma_mask)

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,4 @@ 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_set_mask(struct device *dev, u64 mask)
14-
{
15-
return 0;
16-
}
17-
1813
#endif

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
4545

4646
#define HAVE_ARCH_DMA_SUPPORTED 1
4747
extern int dma_supported(struct device *dev, u64 mask);
48-
extern int dma_set_mask(struct device *dev, u64 mask);
4948
extern int dma_is_consistent(struct device *dev, dma_addr_t dma_handle);
5049
extern void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
5150
enum dma_data_direction direction);

arch/hexagon/kernel/dma.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,6 @@ int dma_supported(struct device *dev, u64 mask)
4444
}
4545
EXPORT_SYMBOL(dma_supported);
4646

47-
int dma_set_mask(struct device *dev, u64 mask)
48-
{
49-
if (!dev->dma_mask || !dma_supported(dev, mask))
50-
return -EIO;
51-
52-
*dev->dma_mask = mask;
53-
54-
return 0;
55-
}
56-
EXPORT_SYMBOL(dma_set_mask);
57-
5847
static struct gen_pool *coherent_pool;
5948

6049

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +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
31-
dma_set_mask (struct device *dev, u64 mask)
32-
{
33-
if (!dev->dma_mask || !dma_supported(dev, mask))
34-
return -EIO;
35-
*dev->dma_mask = mask;
36-
return 0;
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/microblaze/include/asm/dma-mapping.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,6 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
4646

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

49-
static inline int dma_set_mask(struct device *dev, u64 dma_mask)
50-
{
51-
struct dma_map_ops *ops = get_dma_ops(dev);
52-
53-
if (unlikely(ops == NULL))
54-
return -EIO;
55-
if (ops->set_dma_mask)
56-
return ops->set_dma_mask(dev, dma_mask);
57-
if (!dev->dma_mask || !dma_supported(dev, dma_mask))
58-
return -EIO;
59-
*dev->dma_mask = dma_mask;
60-
return 0;
61-
}
62-
6349
static inline void __dma_sync(unsigned long paddr,
6450
size_t size, enum dma_data_direction direction)
6551
{

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +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
35-
dma_set_mask(struct device *dev, u64 mask)
36-
{
37-
struct dma_map_ops *ops = get_dma_ops(dev);
38-
39-
if(!dev->dma_mask || !dma_supported(dev, mask))
40-
return -EIO;
41-
42-
if (ops->set_dma_mask)
43-
return ops->set_dma_mask(dev, mask);
44-
45-
*dev->dma_mask = mask;
46-
47-
return 0;
48-
}
49-
5034
extern void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
5135
enum dma_data_direction direction);
5236

arch/mips/loongson64/common/dma-swiotlb.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ static void loongson_dma_sync_sg_for_device(struct device *dev,
8585

8686
static int loongson_dma_set_mask(struct device *dev, u64 mask)
8787
{
88+
if (!dev->dma_mask || !dma_supported(dev, mask))
89+
return -EIO;
90+
8891
if (mask > DMA_BIT_MASK(loongson_sysconf.dma_mask_bits)) {
8992
*dev->dma_mask = DMA_BIT_MASK(loongson_sysconf.dma_mask_bits);
9093
return -EIO;

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,4 @@ static inline int dma_supported(struct device *dev, u64 dma_mask)
4444

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

47-
static inline int dma_set_mask(struct device *dev, u64 dma_mask)
48-
{
49-
if (!dev->dma_mask || !dma_supported(dev, dma_mask))
50-
return -EIO;
51-
52-
*dev->dma_mask = dma_mask;
53-
54-
return 0;
55-
}
5647
#endif /* __ASM_OPENRISC_DMA_MAPPING_H */

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,11 @@ static inline void set_dma_offset(struct device *dev, dma_addr_t off)
122122
/* this will be removed soon */
123123
#define flush_write_buffers()
124124

125+
#define HAVE_ARCH_DMA_SET_MASK 1
126+
extern int dma_set_mask(struct device *dev, u64 dma_mask);
127+
125128
#include <asm-generic/dma-mapping-common.h>
126129

127-
extern int dma_set_mask(struct device *dev, u64 dma_mask);
128130
extern int __dma_set_mask(struct device *dev, u64 dma_mask);
129131
extern u64 __dma_get_required_mask(struct device *dev);
130132

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
1818
return &s390_dma_ops;
1919
}
2020

21-
extern int dma_set_mask(struct device *dev, u64 mask);
22-
2321
static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
2422
enum dma_data_direction direction)
2523
{

arch/s390/pci/pci_dma.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -262,16 +262,6 @@ static void dma_free_iommu(struct zpci_dev *zdev, unsigned long offset, int size
262262
spin_unlock_irqrestore(&zdev->iommu_bitmap_lock, flags);
263263
}
264264

265-
int dma_set_mask(struct device *dev, u64 mask)
266-
{
267-
if (!dev->dma_mask || !dma_supported(dev, mask))
268-
return -EIO;
269-
270-
*dev->dma_mask = mask;
271-
return 0;
272-
}
273-
EXPORT_SYMBOL_GPL(dma_set_mask);
274-
275265
static dma_addr_t s390_dma_map_pages(struct device *dev, struct page *page,
276266
unsigned long offset, size_t size,
277267
enum dma_data_direction direction,

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +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_set_mask(struct device *dev, u64 mask)
17-
{
18-
struct dma_map_ops *ops = get_dma_ops(dev);
19-
20-
if (!dev->dma_mask || !dma_supported(dev, mask))
21-
return -EIO;
22-
if (ops->set_dma_mask)
23-
return ops->set_dma_mask(dev, mask);
24-
25-
*dev->dma_mask = mask;
26-
27-
return 0;
28-
}
29-
3016
void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
3117
enum dma_data_direction dir);
3218

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
3737
return dma_ops;
3838
}
3939

40-
#include <asm-generic/dma-mapping-common.h>
40+
#define HAVE_ARCH_DMA_SET_MASK 1
4141

4242
static inline int dma_set_mask(struct device *dev, u64 mask)
4343
{
@@ -52,4 +52,6 @@ static inline int dma_set_mask(struct device *dev, u64 mask)
5252
return -EINVAL;
5353
}
5454

55+
#include <asm-generic/dma-mapping-common.h>
56+
5557
#endif

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
5959

6060
static inline void dma_mark_clean(void *addr, size_t size) {}
6161

62-
#include <asm-generic/dma-mapping-common.h>
63-
6462
static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops)
6563
{
6664
dev->archdata.dma_ops = ops;
@@ -74,6 +72,10 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
7472
return addr + size - 1 <= *dev->dma_mask;
7573
}
7674

75+
#define HAVE_ARCH_DMA_SET_MASK 1
76+
77+
#include <asm-generic/dma-mapping-common.h>
78+
7779
static inline int
7880
dma_set_mask(struct device *dev, u64 mask)
7981
{

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,6 @@ static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
5050

5151
static inline void dma_mark_clean(void *addr, size_t size) {}
5252

53-
static inline int dma_set_mask(struct device *dev, u64 dma_mask)
54-
{
55-
if (!dev->dma_mask || !dma_supported(dev, dma_mask))
56-
return -EIO;
57-
58-
*dev->dma_mask = dma_mask;
59-
60-
return 0;
61-
}
62-
6353
static inline void dma_cache_sync(struct device *dev, void *vaddr,
6454
size_t size, enum dma_data_direction direction)
6555
{

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ extern int dma_supported(struct device *hwdev, u64 mask);
4848

4949
#include <asm-generic/dma-mapping-common.h>
5050

51-
extern int dma_set_mask(struct device *dev, u64 mask);
52-
5351
extern void *dma_generic_alloc_coherent(struct device *dev, size_t size,
5452
dma_addr_t *dma_addr, gfp_t flag,
5553
struct dma_attrs *attrs);

arch/x86/kernel/pci-dma.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,6 @@ EXPORT_SYMBOL(x86_dma_fallback_dev);
5858
/* Number of entries preallocated for DMA-API debugging */
5959
#define PREALLOC_DMA_DEBUG_ENTRIES 65536
6060

61-
int dma_set_mask(struct device *dev, u64 mask)
62-
{
63-
if (!dev->dma_mask || !dma_supported(dev, mask))
64-
return -EIO;
65-
66-
*dev->dma_mask = mask;
67-
68-
return 0;
69-
}
70-
EXPORT_SYMBOL(dma_set_mask);
71-
7261
void __init pci_iommu_alloc(void)
7362
{
7463
struct iommu_table_entry *p;

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +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_set_mask(struct device *dev, u64 mask)
37-
{
38-
if(!dev->dma_mask || !dma_supported(dev, mask))
39-
return -EIO;
40-
41-
*dev->dma_mask = mask;
42-
43-
return 0;
44-
}
45-
4635
void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
4736
enum dma_data_direction direction);
4837

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,4 +340,19 @@ static inline int dma_supported(struct device *dev, u64 mask)
340340
}
341341
#endif
342342

343+
#ifndef HAVE_ARCH_DMA_SET_MASK
344+
static inline int dma_set_mask(struct device *dev, u64 mask)
345+
{
346+
struct dma_map_ops *ops = get_dma_ops(dev);
347+
348+
if (ops->set_dma_mask)
349+
return ops->set_dma_mask(dev, mask);
350+
351+
if (!dev->dma_mask || !dma_supported(dev, mask))
352+
return -EIO;
353+
*dev->dma_mask = mask;
354+
return 0;
355+
}
356+
#endif
357+
343358
#endif

0 commit comments

Comments
 (0)