]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - arch/sparc/include/asm/dma-mapping.h
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
[mirror_ubuntu-zesty-kernel.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
f05a6865 10int 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
87e677c4
SR
15extern struct dma_map_ops *dma_ops;
16extern struct dma_map_ops *leon_dma_ops;
17extern struct dma_map_ops pci32_dma_ops;
18
ee664a92 19extern struct bus_type pci_bus_type;
d6986415 20
02f7a189 21static inline struct dma_map_ops *get_dma_ops(struct device *dev)
d6986415 22{
b84ca92e 23#ifdef CONFIG_SPARC_LEON
87e677c4
SR
24 if (sparc_cpu_model == sparc_leon)
25 return leon_dma_ops;
b84ca92e
AL
26#endif
27#if defined(CONFIG_SPARC32) && defined(CONFIG_PCI)
28 if (dev->bus == &pci_bus_type)
ee664a92
FT
29 return &pci32_dma_ops;
30#endif
02f7a189 31 return dma_ops;
d6986415
FT
32}
33
02f7a189 34#include <asm-generic/dma-mapping-common.h>
d6986415 35
c416258a
AP
36#define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL)
37
38static inline void *dma_alloc_attrs(struct device *dev, size_t size,
39 dma_addr_t *dma_handle, gfp_t flag,
40 struct dma_attrs *attrs)
d6986415 41{
02f7a189 42 struct dma_map_ops *ops = get_dma_ops(dev);
451d7400 43 void *cpu_addr;
d6986415 44
c416258a 45 cpu_addr = ops->alloc(dev, size, dma_handle, flag, attrs);
451d7400
FT
46 debug_dma_alloc_coherent(dev, size, *dma_handle, cpu_addr);
47 return cpu_addr;
d6986415 48}
b9f69f4f 49
c416258a
AP
50#define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL)
51
52static inline void dma_free_attrs(struct device *dev, size_t size,
53 void *cpu_addr, dma_addr_t dma_handle,
54 struct dma_attrs *attrs)
b9f69f4f 55{
02f7a189 56 struct dma_map_ops *ops = get_dma_ops(dev);
b9f69f4f 57
451d7400 58 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
c416258a 59 ops->free(dev, size, cpu_addr, dma_handle, attrs);
b9f69f4f
FT
60}
61
d6986415
FT
62static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
63{
5d346d10 64 debug_dma_mapping_error(dev, dma_addr);
d6986415
FT
65 return (dma_addr == DMA_ERROR_CODE);
66}
67
34900429
FT
68static inline int dma_set_mask(struct device *dev, u64 mask)
69{
70#ifdef CONFIG_PCI
71 if (dev->bus == &pci_bus_type) {
72 if (!dev->dma_mask || !dma_supported(dev, mask))
73 return -EINVAL;
74 *dev->dma_mask = mask;
75 return 0;
76 }
77#endif
78 return -EINVAL;
79}
80
f5e706ad 81#endif