intel_pstate: fix PCT_TO_HWP macro
[linux-2.6-block.git] / arch / xtensa / include / asm / dma-mapping.h
1 /*
2  * include/asm-xtensa/dma-mapping.h
3  *
4  * This file is subject to the terms and conditions of the GNU General Public
5  * License.  See the file "COPYING" in the main directory of this archive
6  * for more details.
7  *
8  * Copyright (C) 2003 - 2005 Tensilica Inc.
9  */
10
11 #ifndef _XTENSA_DMA_MAPPING_H
12 #define _XTENSA_DMA_MAPPING_H
13
14 #include <asm/cache.h>
15 #include <asm/io.h>
16 #include <linux/mm.h>
17 #include <linux/scatterlist.h>
18
19 #define DMA_ERROR_CODE          (~(dma_addr_t)0x0)
20
21 /*
22  * DMA-consistent mapping functions.
23  */
24
25 extern void *consistent_alloc(int, size_t, dma_addr_t, unsigned long);
26 extern void consistent_free(void*, size_t, dma_addr_t);
27 extern void consistent_sync(void*, size_t, int);
28
29 #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
30 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
31
32 void *dma_alloc_coherent(struct device *dev, size_t size,
33                            dma_addr_t *dma_handle, gfp_t flag);
34
35 void dma_free_coherent(struct device *dev, size_t size,
36                          void *vaddr, dma_addr_t dma_handle);
37
38 static inline dma_addr_t
39 dma_map_single(struct device *dev, void *ptr, size_t size,
40                enum dma_data_direction direction)
41 {
42         BUG_ON(direction == DMA_NONE);
43         consistent_sync(ptr, size, direction);
44         return virt_to_phys(ptr);
45 }
46
47 static inline void
48 dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
49                  enum dma_data_direction direction)
50 {
51         BUG_ON(direction == DMA_NONE);
52 }
53
54 static inline int
55 dma_map_sg(struct device *dev, struct scatterlist *sglist, int nents,
56            enum dma_data_direction direction)
57 {
58         int i;
59         struct scatterlist *sg;
60
61         BUG_ON(direction == DMA_NONE);
62
63         for_each_sg(sglist, sg, nents, i) {
64                 BUG_ON(!sg_page(sg));
65
66                 sg->dma_address = sg_phys(sg);
67                 consistent_sync(sg_virt(sg), sg->length, direction);
68         }
69
70         return nents;
71 }
72
73 static inline dma_addr_t
74 dma_map_page(struct device *dev, struct page *page, unsigned long offset,
75              size_t size, enum dma_data_direction direction)
76 {
77         BUG_ON(direction == DMA_NONE);
78         return (dma_addr_t)(page_to_pfn(page)) * PAGE_SIZE + offset;
79 }
80
81 static inline void
82 dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
83                enum dma_data_direction direction)
84 {
85         BUG_ON(direction == DMA_NONE);
86 }
87
88
89 static inline void
90 dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
91              enum dma_data_direction direction)
92 {
93         BUG_ON(direction == DMA_NONE);
94 }
95
96 static inline void
97 dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size,
98                 enum dma_data_direction direction)
99 {
100         consistent_sync((void *)bus_to_virt(dma_handle), size, direction);
101 }
102
103 static inline void
104 dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle,
105                            size_t size, enum dma_data_direction direction)
106 {
107         consistent_sync((void *)bus_to_virt(dma_handle), size, direction);
108 }
109
110 static inline void
111 dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t dma_handle,
112                       unsigned long offset, size_t size,
113                       enum dma_data_direction direction)
114 {
115
116         consistent_sync((void *)bus_to_virt(dma_handle)+offset,size,direction);
117 }
118
119 static inline void
120 dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle,
121                       unsigned long offset, size_t size,
122                       enum dma_data_direction direction)
123 {
124
125         consistent_sync((void *)bus_to_virt(dma_handle)+offset,size,direction);
126 }
127 static inline void
128 dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sglist, int nelems,
129                  enum dma_data_direction dir)
130 {
131         int i;
132         struct scatterlist *sg;
133
134         for_each_sg(sglist, sg, nelems, i)
135                 consistent_sync(sg_virt(sg), sg->length, dir);
136 }
137
138 static inline void
139 dma_sync_sg_for_device(struct device *dev, struct scatterlist *sglist,
140                        int nelems, enum dma_data_direction dir)
141 {
142         int i;
143         struct scatterlist *sg;
144
145         for_each_sg(sglist, sg, nelems, i)
146                 consistent_sync(sg_virt(sg), sg->length, dir);
147 }
148 static inline int
149 dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
150 {
151         return 0;
152 }
153
154 static inline int
155 dma_supported(struct device *dev, u64 mask)
156 {
157         return 1;
158 }
159
160 static inline int
161 dma_set_mask(struct device *dev, u64 mask)
162 {
163         if(!dev->dma_mask || !dma_supported(dev, mask))
164                 return -EIO;
165
166         *dev->dma_mask = mask;
167
168         return 0;
169 }
170
171 static inline void
172 dma_cache_sync(struct device *dev, void *vaddr, size_t size,
173                enum dma_data_direction direction)
174 {
175         consistent_sync(vaddr, size, direction);
176 }
177
178 /* Not supported for now */
179 static inline int dma_mmap_coherent(struct device *dev,
180                                     struct vm_area_struct *vma, void *cpu_addr,
181                                     dma_addr_t dma_addr, size_t size)
182 {
183         return -EINVAL;
184 }
185
186 static inline int dma_get_sgtable(struct device *dev, struct sg_table *sgt,
187                                   void *cpu_addr, dma_addr_t dma_addr,
188                                   size_t size)
189 {
190         return -EINVAL;
191 }
192
193 static inline void *dma_alloc_attrs(struct device *dev, size_t size,
194                                     dma_addr_t *dma_handle, gfp_t flag,
195                                     struct dma_attrs *attrs)
196 {
197         return NULL;
198 }
199
200 static inline void dma_free_attrs(struct device *dev, size_t size,
201                                   void *vaddr, dma_addr_t dma_handle,
202                                   struct dma_attrs *attrs)
203 {
204 }
205
206 #endif  /* _XTENSA_DMA_MAPPING_H */