2 * Copyright 2004-2009 Analog Devices Inc.
4 * Licensed under the GPL-2 or later.
7 #ifndef _BLACKFIN_DMA_MAPPING_H
8 #define _BLACKFIN_DMA_MAPPING_H
10 #include <asm/cacheflush.h>
13 void *dma_alloc_coherent(struct device *dev, size_t size,
14 dma_addr_t *dma_handle, gfp_t gfp);
15 void dma_free_coherent(struct device *dev, size_t size, void *vaddr,
16 dma_addr_t dma_handle);
19 * Now for the API extensions over the pci_ one
21 #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
22 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
23 #define dma_supported(d, m) (1)
24 #define dma_get_cache_alignment() (32)
25 #define dma_is_consistent(d, h) (1)
28 dma_set_mask(struct device *dev, u64 dma_mask)
30 if (!dev->dma_mask || !dma_supported(dev, dma_mask))
33 *dev->dma_mask = dma_mask;
39 dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
45 __dma_sync(dma_addr_t addr, size_t size, enum dma_data_direction dir);
47 __dma_sync_inline(dma_addr_t addr, size_t size, enum dma_data_direction dir)
52 case DMA_TO_DEVICE: /* writeback only */
53 flush_dcache_range(addr, addr + size);
55 case DMA_FROM_DEVICE: /* invalidate only */
56 case DMA_BIDIRECTIONAL: /* flush and invalidate */
57 /* Blackfin has no dedicated invalidate (it includes a flush) */
58 invalidate_dcache_range(addr, addr + size);
63 _dma_sync(dma_addr_t addr, size_t size, enum dma_data_direction dir)
65 if (__builtin_constant_p(dir))
66 __dma_sync_inline(addr, size, dir);
68 __dma_sync(addr, size, dir);
71 static inline dma_addr_t
72 dma_map_single(struct device *dev, void *ptr, size_t size,
73 enum dma_data_direction dir)
75 _dma_sync((dma_addr_t)ptr, size, dir);
76 return (dma_addr_t) ptr;
79 static inline dma_addr_t
80 dma_map_page(struct device *dev, struct page *page,
81 unsigned long offset, size_t size,
82 enum dma_data_direction dir)
84 return dma_map_single(dev, page_address(page) + offset, size, dir);
88 dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
89 enum dma_data_direction dir)
91 BUG_ON(!valid_dma_direction(dir));
95 dma_unmap_page(struct device *dev, dma_addr_t dma_addr, size_t size,
96 enum dma_data_direction dir)
98 dma_unmap_single(dev, dma_addr, size, dir);
101 extern int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
102 enum dma_data_direction dir);
105 dma_unmap_sg(struct device *dev, struct scatterlist *sg,
106 int nhwentries, enum dma_data_direction dir)
108 BUG_ON(!valid_dma_direction(dir));
112 dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t handle,
113 unsigned long offset, size_t size,
114 enum dma_data_direction dir)
116 BUG_ON(!valid_dma_direction(dir));
120 dma_sync_single_range_for_device(struct device *dev, dma_addr_t handle,
121 unsigned long offset, size_t size,
122 enum dma_data_direction dir)
124 _dma_sync(handle + offset, size, dir);
128 dma_sync_single_for_cpu(struct device *dev, dma_addr_t handle, size_t size,
129 enum dma_data_direction dir)
131 dma_sync_single_range_for_cpu(dev, handle, 0, size, dir);
135 dma_sync_single_for_device(struct device *dev, dma_addr_t handle, size_t size,
136 enum dma_data_direction dir)
138 dma_sync_single_range_for_device(dev, handle, 0, size, dir);
142 dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nents,
143 enum dma_data_direction dir)
145 BUG_ON(!valid_dma_direction(dir));
149 dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
150 int nents, enum dma_data_direction dir);
153 dma_cache_sync(struct device *dev, void *vaddr, size_t size,
154 enum dma_data_direction dir)
156 _dma_sync((dma_addr_t)vaddr, size, dir);
159 #endif /* _BLACKFIN_DMA_MAPPING_H */