Merge git://git.kernel.org/pub/scm/linux/kernel/git/sfrench/cifs-2.6
[pandora-kernel.git] / arch / sparc / include / asm / dma-mapping.h
1 #ifndef ___ASM_SPARC_DMA_MAPPING_H
2 #define ___ASM_SPARC_DMA_MAPPING_H
3
4 #include <linux/scatterlist.h>
5 #include <linux/mm.h>
6 #include <linux/dma-debug.h>
7
8 #define DMA_ERROR_CODE  (~(dma_addr_t)0x0)
9
10 extern int dma_supported(struct device *dev, u64 mask);
11
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
16 extern struct dma_map_ops *dma_ops, pci32_dma_ops;
17 extern struct bus_type pci_bus_type;
18
19 static inline struct dma_map_ops *get_dma_ops(struct device *dev)
20 {
21 #if defined(CONFIG_SPARC32) && defined(CONFIG_PCI)
22         if (dev->bus == &pci_bus_type)
23                 return &pci32_dma_ops;
24 #endif
25         return dma_ops;
26 }
27
28 #include <asm-generic/dma-mapping-common.h>
29
30 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
31                                        dma_addr_t *dma_handle, gfp_t flag)
32 {
33         struct dma_map_ops *ops = get_dma_ops(dev);
34         void *cpu_addr;
35
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;
39 }
40
41 static inline void dma_free_coherent(struct device *dev, size_t size,
42                                      void *cpu_addr, dma_addr_t dma_handle)
43 {
44         struct dma_map_ops *ops = get_dma_ops(dev);
45
46         debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
47         ops->free_coherent(dev, size, cpu_addr, dma_handle);
48 }
49
50 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
51 {
52         return (dma_addr == DMA_ERROR_CODE);
53 }
54
55 static inline int dma_get_cache_alignment(void)
56 {
57         /*
58          * no easy way to get cache size on all processors, so return
59          * the maximum possible, to be safe
60          */
61         return (1 << INTERNODE_CACHE_SHIFT);
62 }
63
64 static inline int dma_set_mask(struct device *dev, u64 mask)
65 {
66 #ifdef CONFIG_PCI
67         if (dev->bus == &pci_bus_type) {
68                 if (!dev->dma_mask || !dma_supported(dev, mask))
69                         return -EINVAL;
70                 *dev->dma_mask = mask;
71                 return 0;
72         }
73 #endif
74         return -EINVAL;
75 }
76
77 #endif