dma-mapping.h 2.5 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3
#ifndef __ASM_SH_DMA_MAPPING_H
#define __ASM_SH_DMA_MAPPING_H

4 5
extern struct dma_map_ops *dma_ops;
extern void no_iommu_init(void);
L
Linus Torvalds 已提交
6

7 8 9 10 11
static inline struct dma_map_ops *get_dma_ops(struct device *dev)
{
	return dma_ops;
}

12 13 14
#include <asm-generic/dma-coherent.h>
#include <asm-generic/dma-mapping-common.h>

15 16 17
static inline int dma_supported(struct device *dev, u64 mask)
{
	struct dma_map_ops *ops = get_dma_ops(dev);
L
Linus Torvalds 已提交
18

19 20 21 22 23
	if (ops->dma_supported)
		return ops->dma_supported(dev, mask);

	return 1;
}
L
Linus Torvalds 已提交
24 25 26

static inline int dma_set_mask(struct device *dev, u64 mask)
{
27 28
	struct dma_map_ops *ops = get_dma_ops(dev);

L
Linus Torvalds 已提交
29 30
	if (!dev->dma_mask || !dma_supported(dev, mask))
		return -EIO;
31 32
	if (ops->set_dma_mask)
		return ops->set_dma_mask(dev, mask);
L
Linus Torvalds 已提交
33 34 35 36 37 38

	*dev->dma_mask = mask;

	return 0;
}

39 40
void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
		    enum dma_data_direction dir);
L
Linus Torvalds 已提交
41

42 43
#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
P
Paul Mundt 已提交
44

45
static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
L
Linus Torvalds 已提交
46
{
47
	struct dma_map_ops *ops = get_dma_ops(dev);
48

49 50
	if (ops->mapping_error)
		return ops->mapping_error(dev, dma_addr);
51

52 53
	return dma_addr == 0;
}
54

55 56 57 58 59
#define dma_alloc_coherent(d,s,h,f)	dma_alloc_attrs(d,s,h,f,NULL)

static inline void *dma_alloc_attrs(struct device *dev, size_t size,
				    dma_addr_t *dma_handle, gfp_t gfp,
				    struct dma_attrs *attrs)
60 61 62 63 64 65
{
	struct dma_map_ops *ops = get_dma_ops(dev);
	void *memory;

	if (dma_alloc_from_coherent(dev, size, dma_handle, &memory))
		return memory;
66
	if (!ops->alloc)
67 68
		return NULL;

69
	memory = ops->alloc(dev, size, dma_handle, gfp, attrs);
70 71 72 73 74
	debug_dma_alloc_coherent(dev, size, *dma_handle, memory);

	return memory;
}

75 76 77 78 79
#define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL)

static inline void dma_free_attrs(struct device *dev, size_t size,
				  void *vaddr, dma_addr_t dma_handle,
				  struct dma_attrs *attrs)
80 81 82 83 84 85 86
{
	struct dma_map_ops *ops = get_dma_ops(dev);

	if (dma_release_from_coherent(dev, get_order(size), vaddr))
		return;

	debug_dma_free_coherent(dev, size, vaddr, dma_handle);
87 88
	if (ops->free)
		ops->free(dev, size, vaddr, dma_handle, attrs);
89 90 91 92
}

/* arch/sh/mm/consistent.c */
extern void *dma_generic_alloc_coherent(struct device *dev, size_t size,
93 94
					dma_addr_t *dma_addr, gfp_t flag,
					struct dma_attrs *attrs);
95
extern void dma_generic_free_coherent(struct device *dev, size_t size,
96 97
				      void *vaddr, dma_addr_t dma_handle,
				      struct dma_attrs *attrs);
98

L
Linus Torvalds 已提交
99
#endif /* __ASM_SH_DMA_MAPPING_H */