Merge branch 'linus' into timers/core
[pandora-kernel.git] / arch / blackfin / include / asm / dma-mapping.h
1 /*
2  * Copyright 2004-2009 Analog Devices Inc.
3  *
4  * Licensed under the GPL-2 or later.
5  */
6
7 #ifndef _BLACKFIN_DMA_MAPPING_H
8 #define _BLACKFIN_DMA_MAPPING_H
9
10 #include <asm/cacheflush.h>
11 struct scatterlist;
12
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);
17
18 /*
19  * Now for the API extensions over the pci_ one
20  */
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)
26
27 static inline int
28 dma_set_mask(struct device *dev, u64 dma_mask)
29 {
30         if (!dev->dma_mask || !dma_supported(dev, dma_mask))
31                 return -EIO;
32
33         *dev->dma_mask = dma_mask;
34
35         return 0;
36 }
37
38 static inline int
39 dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
40 {
41         return 0;
42 }
43
44 extern void
45 __dma_sync(dma_addr_t addr, size_t size, enum dma_data_direction dir);
46 static inline void
47 __dma_sync_inline(dma_addr_t addr, size_t size, enum dma_data_direction dir)
48 {
49         switch (dir) {
50         case DMA_NONE:
51                 BUG();
52         case DMA_TO_DEVICE:             /* writeback only */
53                 flush_dcache_range(addr, addr + size);
54                 break;
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);
59                 break;
60         }
61 }
62 static inline void
63 _dma_sync(dma_addr_t addr, size_t size, enum dma_data_direction dir)
64 {
65         if (__builtin_constant_p(dir))
66                 __dma_sync_inline(addr, size, dir);
67         else
68                 __dma_sync(addr, size, dir);
69 }
70
71 static inline dma_addr_t
72 dma_map_single(struct device *dev, void *ptr, size_t size,
73                enum dma_data_direction dir)
74 {
75         _dma_sync((dma_addr_t)ptr, size, dir);
76         return (dma_addr_t) ptr;
77 }
78
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)
83 {
84         return dma_map_single(dev, page_address(page) + offset, size, dir);
85 }
86
87 static inline void
88 dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
89                  enum dma_data_direction dir)
90 {
91         BUG_ON(!valid_dma_direction(dir));
92 }
93
94 static inline void
95 dma_unmap_page(struct device *dev, dma_addr_t dma_addr, size_t size,
96                enum dma_data_direction dir)
97 {
98         dma_unmap_single(dev, dma_addr, size, dir);
99 }
100
101 extern int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
102                       enum dma_data_direction dir);
103
104 static inline void
105 dma_unmap_sg(struct device *dev, struct scatterlist *sg,
106              int nhwentries, enum dma_data_direction dir)
107 {
108         BUG_ON(!valid_dma_direction(dir));
109 }
110
111 static inline void
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)
115 {
116         BUG_ON(!valid_dma_direction(dir));
117 }
118
119 static inline void
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)
123 {
124         _dma_sync(handle + offset, size, dir);
125 }
126
127 static inline void
128 dma_sync_single_for_cpu(struct device *dev, dma_addr_t handle, size_t size,
129                         enum dma_data_direction dir)
130 {
131         dma_sync_single_range_for_cpu(dev, handle, 0, size, dir);
132 }
133
134 static inline void
135 dma_sync_single_for_device(struct device *dev, dma_addr_t handle, size_t size,
136                            enum dma_data_direction dir)
137 {
138         dma_sync_single_range_for_device(dev, handle, 0, size, dir);
139 }
140
141 static inline void
142 dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nents,
143                     enum dma_data_direction dir)
144 {
145         BUG_ON(!valid_dma_direction(dir));
146 }
147
148 extern void
149 dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
150                        int nents, enum dma_data_direction dir);
151
152 static inline void
153 dma_cache_sync(struct device *dev, void *vaddr, size_t size,
154                enum dma_data_direction dir)
155 {
156         _dma_sync((dma_addr_t)vaddr, size, dir);
157 }
158
159 #endif                          /* _BLACKFIN_DMA_MAPPING_H */