blob: 2677818dc781cb934276cb88d10e124d6bfef95f [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);
11extern int dma_set_mask(struct device *dev, u64 dma_mask);
12
FUJITA Tomonorib9f69f42009-05-14 16:23:08 +000013#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
14#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
15#define dma_is_consistent(d, h) (1)
16
FUJITA Tomonoriee664a92009-08-10 11:53:16 +090017extern struct dma_map_ops *dma_ops, pci32_dma_ops;
18extern struct bus_type pci_bus_type;
FUJITA Tomonori02f7a182009-08-10 11:53:13 +090019
20static inline struct dma_map_ops *get_dma_ops(struct device *dev)
21{
FUJITA Tomonoriee664a92009-08-10 11:53:16 +090022#if defined(CONFIG_SPARC32) && defined(CONFIG_PCI)
23 if (dev->bus == &pci_bus_type)
24 return &pci32_dma_ops;
25#endif
FUJITA Tomonori02f7a182009-08-10 11:53:13 +090026 return dma_ops;
27}
28
29#include <asm-generic/dma-mapping-common.h>
FUJITA Tomonorid6986412009-05-14 16:23:11 +000030
31static inline void *dma_alloc_coherent(struct device *dev, size_t size,
32 dma_addr_t *dma_handle, gfp_t flag)
33{
FUJITA Tomonori02f7a182009-08-10 11:53:13 +090034 struct dma_map_ops *ops = get_dma_ops(dev);
35
36 return ops->alloc_coherent(dev, size, dma_handle, flag);
FUJITA Tomonorid6986412009-05-14 16:23:11 +000037}
38
39static inline void dma_free_coherent(struct device *dev, size_t size,
40 void *cpu_addr, dma_addr_t dma_handle)
41{
FUJITA Tomonori02f7a182009-08-10 11:53:13 +090042 struct dma_map_ops *ops = get_dma_ops(dev);
FUJITA Tomonorid6986412009-05-14 16:23:11 +000043
FUJITA Tomonori02f7a182009-08-10 11:53:13 +090044 ops->free_coherent(dev, size, cpu_addr, dma_handle);
FUJITA Tomonorid6986412009-05-14 16:23:11 +000045}
46
FUJITA Tomonorid6986412009-05-14 16:23:11 +000047static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
48{
49 return (dma_addr == DMA_ERROR_CODE);
50}
51
52static inline int dma_get_cache_alignment(void)
53{
54 /*
55 * no easy way to get cache size on all processors, so return
56 * the maximum possible, to be safe
57 */
58 return (1 << INTERNODE_CACHE_SHIFT);
59}
60
Sam Ravnborga439fe52008-07-27 23:00:59 +020061#endif