]> bbs.cooldavid.org Git - net-next-2.6.git/blame - arch/sparc/include/asm/dma-mapping.h
dma-mapping: unify dma_get_cache_alignment implementations
[net-next-2.6.git] / arch / sparc / include / asm / dma-mapping.h
CommitLineData
f5e706ad
SR
1#ifndef ___ASM_SPARC_DMA_MAPPING_H
2#define ___ASM_SPARC_DMA_MAPPING_H
d6986415
FT
3
4#include <linux/scatterlist.h>
5#include <linux/mm.h>
02f7a189 6#include <linux/dma-debug.h>
b9f69f4f
FT
7
8#define DMA_ERROR_CODE (~(dma_addr_t)0x0)
9
10extern int dma_supported(struct device *dev, u64 mask);
b9f69f4f 11
d6986415
FT
12#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
13#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
14#define dma_is_consistent(d, h) (1)
15
ee664a92
FT
16extern struct dma_map_ops *dma_ops, pci32_dma_ops;
17extern struct bus_type pci_bus_type;
d6986415 18
02f7a189 19static inline struct dma_map_ops *get_dma_ops(struct device *dev)
d6986415 20{
ee664a92
FT
21#if defined(CONFIG_SPARC32) && defined(CONFIG_PCI)
22 if (dev->bus == &pci_bus_type)
23 return &pci32_dma_ops;
24#endif
02f7a189 25 return dma_ops;
d6986415
FT
26}
27
02f7a189 28#include <asm-generic/dma-mapping-common.h>
d6986415 29
02f7a189
FT
30static inline void *dma_alloc_coherent(struct device *dev, size_t size,
31 dma_addr_t *dma_handle, gfp_t flag)
d6986415 32{
02f7a189 33 struct dma_map_ops *ops = get_dma_ops(dev);
451d7400 34 void *cpu_addr;
d6986415 35
451d7400
FT
36 cpu_addr = ops->alloc_coherent(dev, size, dma_handle, flag);
37 debug_dma_alloc_coherent(dev, size, *dma_handle, cpu_addr);
38 return cpu_addr;
d6986415 39}
b9f69f4f 40
02f7a189
FT
41static inline void dma_free_coherent(struct device *dev, size_t size,
42 void *cpu_addr, dma_addr_t dma_handle)
b9f69f4f 43{
02f7a189 44 struct dma_map_ops *ops = get_dma_ops(dev);
b9f69f4f 45
451d7400 46 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
02f7a189 47 ops->free_coherent(dev, size, cpu_addr, dma_handle);
b9f69f4f
FT
48}
49
d6986415
FT
50static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
51{
52 return (dma_addr == DMA_ERROR_CODE);
53}
54
34900429
FT
55static inline int dma_set_mask(struct device *dev, u64 mask)
56{
57#ifdef CONFIG_PCI
58 if (dev->bus == &pci_bus_type) {
59 if (!dev->dma_mask || !dma_supported(dev, mask))
60 return -EINVAL;
61 *dev->dma_mask = mask;
62 return 0;
63 }
64#endif
65 return -EINVAL;
66}
67
f5e706ad 68#endif