dma-mapping: unify dma_get_cache_alignment implementations
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / sparc / include / asm / dma-mapping.h
blob74db853ec2cf160c2c20ff8dbef9a8ce0239b700
1 #ifndef ___ASM_SPARC_DMA_MAPPING_H
2 #define ___ASM_SPARC_DMA_MAPPING_H
4 #include <linux/scatterlist.h>
5 #include <linux/mm.h>
6 #include <linux/dma-debug.h>
8 #define DMA_ERROR_CODE (~(dma_addr_t)0x0)
10 extern int dma_supported(struct device *dev, u64 mask);
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)
16 extern struct dma_map_ops *dma_ops, pci32_dma_ops;
17 extern struct bus_type pci_bus_type;
19 static inline struct dma_map_ops *get_dma_ops(struct device *dev)
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;
28 #include <asm-generic/dma-mapping-common.h>
30 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
31 dma_addr_t *dma_handle, gfp_t flag)
33 struct dma_map_ops *ops = get_dma_ops(dev);
34 void *cpu_addr;
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;
41 static inline void dma_free_coherent(struct device *dev, size_t size,
42 void *cpu_addr, dma_addr_t dma_handle)
44 struct dma_map_ops *ops = get_dma_ops(dev);
46 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
47 ops->free_coherent(dev, size, cpu_addr, dma_handle);
50 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
52 return (dma_addr == DMA_ERROR_CODE);
55 static inline int dma_set_mask(struct device *dev, u64 mask)
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;
64 #endif
65 return -EINVAL;
68 #endif