Skip to content

Commit

Permalink
dma-mapping: consolidate dma_supported
Browse files Browse the repository at this point in the history
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.

[[email protected]: fix xtensa]
Signed-off-by: Christoph Hellwig <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Russell King <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Yoshinori Sato <[email protected]>
Cc: Michal Simek <[email protected]>
Cc: Jonas Bonn <[email protected]>
Cc: Chris Metcalf <[email protected]>
Cc: Guan Xuetao <[email protected]>
Cc: Ralf Baechle <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: Andy Shevchenko <[email protected]>
Signed-off-by: Max Filippov <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Christoph Hellwig authored and torvalds committed Sep 10, 2015
1 parent efa21e4 commit ee19637
Show file tree
Hide file tree
Showing 18 changed files with 25 additions and 98 deletions.
5 changes: 0 additions & 5 deletions arch/alpha/include/asm/dma-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_supported(struct device *dev, u64 mask)
{
return get_dma_ops(dev)->dma_supported(dev, mask);
}

static inline int dma_set_mask(struct device *dev, u64 mask)
{
return get_dma_ops(dev)->set_dma_mask(dev, mask);
Expand Down
6 changes: 3 additions & 3 deletions arch/arm/include/asm/dma-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops)
dev->archdata.dma_ops = ops;
}

#define HAVE_ARCH_DMA_SUPPORTED 1
extern int dma_supported(struct device *dev, u64 mask);

/*
* Note that while the generic code provides dummy dma_{alloc,free}_noncoherent
* implementations, we don't provide a dma_cache_sync function so drivers using
* this API are highlighted with build warnings.
*/

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

static inline int dma_set_mask(struct device *dev, u64 mask)
Expand Down Expand Up @@ -172,8 +174,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) { }

extern int dma_supported(struct device *dev, u64 mask);

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

/**
Expand Down
6 changes: 0 additions & 6 deletions arch/arm64/include/asm/dma-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +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_supported(struct device *dev, u64 mask)
{
struct dma_map_ops *ops = get_dma_ops(dev);
return ops->dma_supported(dev, mask);
}

static inline int dma_set_mask(struct device *dev, u64 mask)
{
if (!dev->dma_mask || !dma_supported(dev, mask))
Expand Down
5 changes: 0 additions & 5 deletions arch/h8300/include/asm/dma-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)

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

static inline int dma_supported(struct device *dev, u64 mask)
{
return 0;
}

static inline int dma_set_mask(struct device *dev, u64 mask)
{
return 0;
Expand Down
1 change: 1 addition & 0 deletions arch/hexagon/include/asm/dma-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
return dma_ops;
}

#define HAVE_ARCH_DMA_SUPPORTED 1
extern int dma_supported(struct device *dev, u64 mask);
extern int dma_set_mask(struct device *dev, u64 mask);
extern int dma_is_consistent(struct device *dev, dma_addr_t dma_handle);
Expand Down
6 changes: 0 additions & 6 deletions arch/ia64/include/asm/dma-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ extern void machvec_dma_sync_sg(struct device *, struct scatterlist *, int,

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

static inline int dma_supported(struct device *dev, u64 mask)
{
struct dma_map_ops *ops = platform_dma_get_ops(dev);
return ops->dma_supported(dev, mask);
}

static inline int
dma_set_mask (struct device *dev, u64 mask)
{
Expand Down
13 changes: 1 addition & 12 deletions arch/microblaze/include/asm/dma-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,7 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
return &dma_direct_ops;
}

static inline int dma_supported(struct device *dev, u64 mask)
{
struct dma_map_ops *ops = get_dma_ops(dev);

if (unlikely(!ops))
return 0;
if (!ops->dma_supported)
return 1;
return ops->dma_supported(dev, mask);
}
#include <asm-generic/dma-mapping-common.h>

static inline int dma_set_mask(struct device *dev, u64 dma_mask)
{
Expand All @@ -69,8 +60,6 @@ static inline int dma_set_mask(struct device *dev, u64 dma_mask)
return 0;
}

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

static inline void __dma_sync(unsigned long paddr,
size_t size, enum dma_data_direction direction)
{
Expand Down
6 changes: 0 additions & 6 deletions arch/mips/include/asm/dma-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ static inline void dma_mark_clean(void *addr, size_t size) {}

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

static inline int dma_supported(struct device *dev, u64 mask)
{
struct dma_map_ops *ops = get_dma_ops(dev);
return ops->dma_supported(dev, mask);
}

static inline int
dma_set_mask(struct device *dev, u64 mask)
{
Expand Down
5 changes: 3 additions & 2 deletions arch/openrisc/include/asm/dma-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
return &or1k_dma_map_ops;
}

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

#define HAVE_ARCH_DMA_SUPPORTED 1
static inline int dma_supported(struct device *dev, u64 dma_mask)
{
/* Support 32 bit DMA mask exclusively */
return dma_mask == DMA_BIT_MASK(32);
}

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

static inline int dma_set_mask(struct device *dev, u64 dma_mask)
{
if (!dev->dma_mask || !dma_supported(dev, dma_mask))
Expand Down
11 changes: 0 additions & 11 deletions arch/powerpc/include/asm/dma-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,6 @@ static inline void set_dma_offset(struct device *dev, dma_addr_t off)

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

static inline int dma_supported(struct device *dev, u64 mask)
{
struct dma_map_ops *dma_ops = get_dma_ops(dev);

if (unlikely(dma_ops == NULL))
return 0;
if (dma_ops->dma_supported == NULL)
return 1;
return dma_ops->dma_supported(dev, mask);
}

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);
Expand Down
9 changes: 0 additions & 9 deletions arch/s390/include/asm/dma-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@ static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size,

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

static inline int dma_supported(struct device *dev, u64 mask)
{
struct dma_map_ops *dma_ops = get_dma_ops(dev);

if (dma_ops->dma_supported == NULL)
return 1;
return dma_ops->dma_supported(dev, mask);
}

static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
{
if (!dev->dma_mask)
Expand Down
10 changes: 0 additions & 10 deletions arch/sh/include/asm/dma-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)

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

static inline int dma_supported(struct device *dev, u64 mask)
{
struct dma_map_ops *ops = get_dma_ops(dev);

if (ops->dma_supported)
return ops->dma_supported(dev, mask);

return 1;
}

static inline int dma_set_mask(struct device *dev, u64 mask)
{
struct dma_map_ops *ops = get_dma_ops(dev);
Expand Down
1 change: 1 addition & 0 deletions arch/sparc/include/asm/dma-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#define DMA_ERROR_CODE (~(dma_addr_t)0x0)

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

static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
Expand Down
6 changes: 0 additions & 6 deletions arch/tile/include/asm/dma-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +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_supported(struct device *dev, u64 mask)
{
return get_dma_ops(dev)->dma_supported(dev, mask);
}

static inline int
dma_set_mask(struct device *dev, u64 mask)
{
Expand Down
10 changes: 0 additions & 10 deletions arch/unicore32/include/asm/dma-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,6 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
return &swiotlb_dma_map_ops;
}

static inline int dma_supported(struct device *dev, u64 mask)
{
struct dma_map_ops *dma_ops = get_dma_ops(dev);

if (unlikely(dma_ops == NULL))
return 0;

return dma_ops->dma_supported(dev, mask);
}

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

static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
Expand Down
4 changes: 3 additions & 1 deletion arch/x86/include/asm/dma-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
bool arch_dma_alloc_attrs(struct device **dev, gfp_t *gfp);
#define arch_dma_alloc_attrs arch_dma_alloc_attrs

#define HAVE_ARCH_DMA_SUPPORTED 1
extern int dma_supported(struct device *hwdev, u64 mask);

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

extern int dma_supported(struct device *hwdev, u64 mask);
extern int dma_set_mask(struct device *dev, u64 mask);

extern void *dma_generic_alloc_coherent(struct device *dev, size_t size,
Expand Down
6 changes: 0 additions & 6 deletions arch/xtensa/include/asm/dma-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +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_supported(struct device *dev, u64 mask)
{
return 1;
}

static inline int
dma_set_mask(struct device *dev, u64 mask)
{
Expand Down
13 changes: 13 additions & 0 deletions include/asm-generic/dma-mapping-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,17 @@ static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
#endif
}

#ifndef HAVE_ARCH_DMA_SUPPORTED
static inline int dma_supported(struct device *dev, u64 mask)
{
struct dma_map_ops *ops = get_dma_ops(dev);

if (!ops)
return 0;
if (!ops->dma_supported)
return 1;
return ops->dma_supported(dev, mask);
}
#endif

#endif

0 comments on commit ee19637

Please sign in to comment.