Merge branch 'for-2.6.37/drivers' into for-linus
[deliverable/linux.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)
d6986415 14
ee664a92
FT
15extern struct dma_map_ops *dma_ops, pci32_dma_ops;
16extern struct bus_type pci_bus_type;
d6986415 17
02f7a189 18static inline struct dma_map_ops *get_dma_ops(struct device *dev)
d6986415 19{
ee664a92
FT
20#if defined(CONFIG_SPARC32) && defined(CONFIG_PCI)
21 if (dev->bus == &pci_bus_type)
22 return &pci32_dma_ops;
23#endif
02f7a189 24 return dma_ops;
d6986415
FT
25}
26
02f7a189 27#include <asm-generic/dma-mapping-common.h>
d6986415 28
02f7a189
FT
29static inline void *dma_alloc_coherent(struct device *dev, size_t size,
30 dma_addr_t *dma_handle, gfp_t flag)
d6986415 31{
02f7a189 32 struct dma_map_ops *ops = get_dma_ops(dev);
451d7400 33 void *cpu_addr;
d6986415 34
451d7400
FT
35 cpu_addr = ops->alloc_coherent(dev, size, dma_handle, flag);
36 debug_dma_alloc_coherent(dev, size, *dma_handle, cpu_addr);
37 return cpu_addr;
d6986415 38}
b9f69f4f 39
02f7a189
FT
40static inline void dma_free_coherent(struct device *dev, size_t size,
41 void *cpu_addr, dma_addr_t dma_handle)
b9f69f4f 42{
02f7a189 43 struct dma_map_ops *ops = get_dma_ops(dev);
b9f69f4f 44
451d7400 45 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
02f7a189 46 ops->free_coherent(dev, size, cpu_addr, dma_handle);
b9f69f4f
FT
47}
48
d6986415
FT
49static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
50{
51 return (dma_addr == DMA_ERROR_CODE);
52}
53
34900429
FT
54static inline int dma_set_mask(struct device *dev, u64 mask)
55{
56#ifdef CONFIG_PCI
57 if (dev->bus == &pci_bus_type) {
58 if (!dev->dma_mask || !dma_supported(dev, mask))
59 return -EINVAL;
60 *dev->dma_mask = mask;
61 return 0;
62 }
63#endif
64 return -EINVAL;
65}
66
f5e706ad 67#endif
This page took 0.187345 seconds and 5 git commands to generate.