2 * linux/arch/unicore32/include/asm/dma-mapping.h
4 * Code specific to PKUnity SoC and UniCore ISA
6 * Copyright (C) 2001-2010 GUAN Xue-tao
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 #ifndef __UNICORE_DMA_MAPPING_H__
13 #define __UNICORE_DMA_MAPPING_H__
17 #include <linux/mm_types.h>
18 #include <linux/scatterlist.h>
19 #include <linux/swiotlb.h>
21 #include <asm/memory.h>
22 #include <asm/cacheflush.h>
24 extern struct dma_map_ops swiotlb_dma_map_ops;
26 static inline struct dma_map_ops *get_dma_ops(struct device *dev)
28 return &swiotlb_dma_map_ops;
31 static inline int dma_supported(struct device *dev, u64 mask)
33 struct dma_map_ops *dma_ops = get_dma_ops(dev);
35 if (unlikely(dma_ops == NULL))
38 return dma_ops->dma_supported(dev, mask);
41 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
43 struct dma_map_ops *dma_ops = get_dma_ops(dev);
45 if (dma_ops->mapping_error)
46 return dma_ops->mapping_error(dev, dma_addr);
51 #include <asm-generic/dma-mapping-common.h>
53 static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
55 if (dev && dev->dma_mask)
56 return addr + size - 1 <= *dev->dma_mask;
61 static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
66 static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
71 static inline void dma_mark_clean(void *addr, size_t size) {}
73 static inline int dma_set_mask(struct device *dev, u64 dma_mask)
75 if (!dev->dma_mask || !dma_supported(dev, dma_mask))
78 *dev->dma_mask = dma_mask;
83 #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
84 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
86 static inline void dma_cache_sync(struct device *dev, void *vaddr,
87 size_t size, enum dma_data_direction direction)
89 unsigned long start = (unsigned long)vaddr;
90 unsigned long end = start + size;
96 case DMA_BIDIRECTIONAL: /* writeback and invalidate */
97 __cpuc_dma_flush_range(start, end);
99 case DMA_TO_DEVICE: /* writeback only */
100 __cpuc_dma_clean_range(start, end);
105 #endif /* __KERNEL__ */