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_is_consistent(d, h) (1)
27 dma_set_mask(struct device *dev, u64 dma_mask)
29 if (!dev->dma_mask || !dma_supported(dev, dma_mask))
32 *dev->dma_mask = dma_mask;
38 dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
44 __dma_sync(dma_addr_t addr, size_t size, enum dma_data_direction dir);
46 __dma_sync_inline(dma_addr_t addr, size_t size, enum dma_data_direction dir)
51 case DMA_TO_DEVICE: /* writeback only */
52 flush_dcache_range(addr, addr + size);
54 case DMA_FROM_DEVICE: /* invalidate only */
55 case DMA_BIDIRECTIONAL: /* flush and invalidate */
56 /* Blackfin has no dedicated invalidate (it includes a flush) */
57 invalidate_dcache_range(addr, addr + size);
62 _dma_sync(dma_addr_t addr, size_t size, enum dma_data_direction dir)
64 if (__builtin_constant_p(dir))
65 __dma_sync_inline(addr, size, dir);
67 __dma_sync(addr, size, dir);
70 static inline dma_addr_t
71 dma_map_single(struct device *dev, void *ptr, size_t size,
72 enum dma_data_direction dir)
74 _dma_sync((dma_addr_t)ptr, size, dir);
75 return (dma_addr_t) ptr;
78 static inline dma_addr_t
79 dma_map_page(struct device *dev, struct page *page,
80 unsigned long offset, size_t size,
81 enum dma_data_direction dir)
83 return dma_map_single(dev, page_address(page) + offset, size, dir);
87 dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
88 enum dma_data_direction dir)
90 BUG_ON(!valid_dma_direction(dir));
94 dma_unmap_page(struct device *dev, dma_addr_t dma_addr, size_t size,
95 enum dma_data_direction dir)
97 dma_unmap_single(dev, dma_addr, size, dir);
100 extern int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
101 enum dma_data_direction dir);
104 dma_unmap_sg(struct device *dev, struct scatterlist *sg,
105 int nhwentries, enum dma_data_direction dir)
107 BUG_ON(!valid_dma_direction(dir));
111 dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t handle,
112 unsigned long offset, size_t size,
113 enum dma_data_direction dir)
115 BUG_ON(!valid_dma_direction(dir));
119 dma_sync_single_range_for_device(struct device *dev, dma_addr_t handle,
120 unsigned long offset, size_t size,
121 enum dma_data_direction dir)
123 _dma_sync(handle + offset, size, dir);
127 dma_sync_single_for_cpu(struct device *dev, dma_addr_t handle, size_t size,
128 enum dma_data_direction dir)
130 dma_sync_single_range_for_cpu(dev, handle, 0, size, dir);
134 dma_sync_single_for_device(struct device *dev, dma_addr_t handle, size_t size,
135 enum dma_data_direction dir)
137 dma_sync_single_range_for_device(dev, handle, 0, size, dir);
141 dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nents,
142 enum dma_data_direction dir)
144 BUG_ON(!valid_dma_direction(dir));
148 dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
149 int nents, enum dma_data_direction dir);
152 dma_cache_sync(struct device *dev, void *vaddr, size_t size,
153 enum dma_data_direction dir)
155 _dma_sync((dma_addr_t)vaddr, size, dir);
158 #endif /* _BLACKFIN_DMA_MAPPING_H */