blob: 8c0e4f7bb20484a674f663f30bf34789be6877d9 [file] [log] [blame]
Sam Ravnborga439fe52008-07-27 23:00:59 +02001#ifndef ___ASM_SPARC_DMA_MAPPING_H
2#define ___ASM_SPARC_DMA_MAPPING_H
FUJITA Tomonorid6986412009-05-14 16:23:11 +00003
4#include <linux/scatterlist.h>
5#include <linux/mm.h>
FUJITA Tomonori02f7a182009-08-10 11:53:13 +09006#include <linux/dma-debug.h>
FUJITA Tomonorib9f69f42009-05-14 16:23:08 +00007
8#define DMA_ERROR_CODE (~(dma_addr_t)0x0)
9
10extern int dma_supported(struct device *dev, u64 mask);
FUJITA Tomonorib9f69f42009-05-14 16:23:08 +000011
FUJITA Tomonorib9f69f42009-05-14 16:23:08 +000012#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)
FUJITA Tomonorib9f69f42009-05-14 16:23:08 +000014
FUJITA Tomonoriee664a92009-08-10 11:53:16 +090015extern struct dma_map_ops *dma_ops, pci32_dma_ops;
16extern struct bus_type pci_bus_type;
FUJITA Tomonori02f7a182009-08-10 11:53:13 +090017
18static inline struct dma_map_ops *get_dma_ops(struct device *dev)
19{
FUJITA Tomonoriee664a92009-08-10 11:53:16 +090020#if defined(CONFIG_SPARC32) && defined(CONFIG_PCI)
21 if (dev->bus == &pci_bus_type)
22 return &pci32_dma_ops;
23#endif
FUJITA Tomonori02f7a182009-08-10 11:53:13 +090024 return dma_ops;
25}
26
27#include <asm-generic/dma-mapping-common.h>
FUJITA Tomonorid6986412009-05-14 16:23:11 +000028
29static inline void *dma_alloc_coherent(struct device *dev, size_t size,
30 dma_addr_t *dma_handle, gfp_t flag)
31{
FUJITA Tomonori02f7a182009-08-10 11:53:13 +090032 struct dma_map_ops *ops = get_dma_ops(dev);
FUJITA Tomonori451d7402009-08-10 11:53:17 +090033 void *cpu_addr;
FUJITA Tomonori02f7a182009-08-10 11:53:13 +090034
FUJITA Tomonori451d7402009-08-10 11:53:17 +090035 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;
FUJITA Tomonorid6986412009-05-14 16:23:11 +000038}
39
40static inline void dma_free_coherent(struct device *dev, size_t size,
41 void *cpu_addr, dma_addr_t dma_handle)
42{
FUJITA Tomonori02f7a182009-08-10 11:53:13 +090043 struct dma_map_ops *ops = get_dma_ops(dev);
FUJITA Tomonorid6986412009-05-14 16:23:11 +000044
FUJITA Tomonori451d7402009-08-10 11:53:17 +090045 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
FUJITA Tomonori02f7a182009-08-10 11:53:13 +090046 ops->free_coherent(dev, size, cpu_addr, dma_handle);
FUJITA Tomonorid6986412009-05-14 16:23:11 +000047}
48
FUJITA Tomonorid6986412009-05-14 16:23:11 +000049static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
50{
51 return (dma_addr == DMA_ERROR_CODE);
52}
53
FUJITA Tomonori34900422010-03-10 15:23:35 -080054static 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
Sam Ravnborga439fe52008-07-27 23:00:59 +020067#endif