blob: 4e21c2f3065ca16988802fab9067f80c43e2dddc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _ASM_SPARC64_DMA_MAPPING_H
2#define _ASM_SPARC64_DMA_MAPPING_H
3
Linus Torvalds1da177e2005-04-16 15:20:36 -07004
5#ifdef CONFIG_PCI
David S. Miller42f14232006-05-23 02:07:22 -07006
7/* we implement the API below in terms of the existing PCI one,
8 * so include it */
9#include <linux/pci.h>
10/* need struct page definitions */
11#include <linux/mm.h>
12
David S. Miller9ac6d4a2007-05-14 02:56:03 -070013#include <asm/of_device.h>
14
David S. Miller42f14232006-05-23 02:07:22 -070015static inline int
16dma_supported(struct device *dev, u64 mask)
17{
David S. Miller9ac6d4a2007-05-14 02:56:03 -070018 BUG_ON(dev->bus != &pci_bus_type &&
19 dev->bus != &ebus_bus_type);
David S. Miller42f14232006-05-23 02:07:22 -070020
21 return pci_dma_supported(to_pci_dev(dev), mask);
22}
23
24static inline int
25dma_set_mask(struct device *dev, u64 dma_mask)
26{
David S. Miller9ac6d4a2007-05-14 02:56:03 -070027 BUG_ON(dev->bus != &pci_bus_type &&
28 dev->bus != &ebus_bus_type);
David S. Miller42f14232006-05-23 02:07:22 -070029
30 return pci_set_dma_mask(to_pci_dev(dev), dma_mask);
31}
32
33static inline void *
34dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
35 gfp_t flag)
36{
David S. Miller9ac6d4a2007-05-14 02:56:03 -070037 BUG_ON(dev->bus != &pci_bus_type &&
38 dev->bus != &ebus_bus_type);
David S. Miller42f14232006-05-23 02:07:22 -070039
40 return pci_iommu_ops->alloc_consistent(to_pci_dev(dev), size, dma_handle, flag);
41}
42
43static inline void
44dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
45 dma_addr_t dma_handle)
46{
David S. Miller9ac6d4a2007-05-14 02:56:03 -070047 BUG_ON(dev->bus != &pci_bus_type &&
48 dev->bus != &ebus_bus_type);
David S. Miller42f14232006-05-23 02:07:22 -070049
50 pci_free_consistent(to_pci_dev(dev), size, cpu_addr, dma_handle);
51}
52
53static inline dma_addr_t
54dma_map_single(struct device *dev, void *cpu_addr, size_t size,
55 enum dma_data_direction direction)
56{
David S. Miller9ac6d4a2007-05-14 02:56:03 -070057 BUG_ON(dev->bus != &pci_bus_type &&
58 dev->bus != &ebus_bus_type);
David S. Miller42f14232006-05-23 02:07:22 -070059
60 return pci_map_single(to_pci_dev(dev), cpu_addr, size, (int)direction);
61}
62
63static inline void
64dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
65 enum dma_data_direction direction)
66{
David S. Miller9ac6d4a2007-05-14 02:56:03 -070067 BUG_ON(dev->bus != &pci_bus_type &&
68 dev->bus != &ebus_bus_type);
David S. Miller42f14232006-05-23 02:07:22 -070069
70 pci_unmap_single(to_pci_dev(dev), dma_addr, size, (int)direction);
71}
72
73static inline dma_addr_t
74dma_map_page(struct device *dev, struct page *page,
75 unsigned long offset, size_t size,
76 enum dma_data_direction direction)
77{
David S. Miller9ac6d4a2007-05-14 02:56:03 -070078 BUG_ON(dev->bus != &pci_bus_type &&
79 dev->bus != &ebus_bus_type);
David S. Miller42f14232006-05-23 02:07:22 -070080
81 return pci_map_page(to_pci_dev(dev), page, offset, size, (int)direction);
82}
83
84static inline void
85dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
86 enum dma_data_direction direction)
87{
David S. Miller9ac6d4a2007-05-14 02:56:03 -070088 BUG_ON(dev->bus != &pci_bus_type &&
89 dev->bus != &ebus_bus_type);
David S. Miller42f14232006-05-23 02:07:22 -070090
91 pci_unmap_page(to_pci_dev(dev), dma_address, size, (int)direction);
92}
93
94static inline int
95dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
96 enum dma_data_direction direction)
97{
David S. Miller9ac6d4a2007-05-14 02:56:03 -070098 BUG_ON(dev->bus != &pci_bus_type &&
99 dev->bus != &ebus_bus_type);
David S. Miller42f14232006-05-23 02:07:22 -0700100
101 return pci_map_sg(to_pci_dev(dev), sg, nents, (int)direction);
102}
103
104static inline void
105dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
106 enum dma_data_direction direction)
107{
David S. Miller9ac6d4a2007-05-14 02:56:03 -0700108 BUG_ON(dev->bus != &pci_bus_type &&
109 dev->bus != &ebus_bus_type);
David S. Miller42f14232006-05-23 02:07:22 -0700110
111 pci_unmap_sg(to_pci_dev(dev), sg, nhwentries, (int)direction);
112}
113
114static inline void
115dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size,
116 enum dma_data_direction direction)
117{
David S. Miller9ac6d4a2007-05-14 02:56:03 -0700118 BUG_ON(dev->bus != &pci_bus_type &&
119 dev->bus != &ebus_bus_type);
David S. Miller42f14232006-05-23 02:07:22 -0700120
121 pci_dma_sync_single_for_cpu(to_pci_dev(dev), dma_handle,
122 size, (int)direction);
123}
124
125static inline void
126dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle, size_t size,
127 enum dma_data_direction direction)
128{
David S. Miller9ac6d4a2007-05-14 02:56:03 -0700129 BUG_ON(dev->bus != &pci_bus_type &&
130 dev->bus != &ebus_bus_type);
David S. Miller42f14232006-05-23 02:07:22 -0700131
132 pci_dma_sync_single_for_device(to_pci_dev(dev), dma_handle,
133 size, (int)direction);
134}
135
136static inline void
137dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems,
138 enum dma_data_direction direction)
139{
David S. Miller9ac6d4a2007-05-14 02:56:03 -0700140 BUG_ON(dev->bus != &pci_bus_type &&
141 dev->bus != &ebus_bus_type);
David S. Miller42f14232006-05-23 02:07:22 -0700142
143 pci_dma_sync_sg_for_cpu(to_pci_dev(dev), sg, nelems, (int)direction);
144}
145
146static inline void
147dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nelems,
148 enum dma_data_direction direction)
149{
David S. Miller9ac6d4a2007-05-14 02:56:03 -0700150 BUG_ON(dev->bus != &pci_bus_type &&
151 dev->bus != &ebus_bus_type);
David S. Miller42f14232006-05-23 02:07:22 -0700152
153 pci_dma_sync_sg_for_device(to_pci_dev(dev), sg, nelems, (int)direction);
154}
155
156static inline int
157dma_mapping_error(dma_addr_t dma_addr)
158{
159 return pci_dma_mapping_error(dma_addr);
160}
161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162#else
163
164struct device;
David S. Millerf04dbac2007-06-04 23:32:23 -0700165struct page;
166struct scatterlist;
167
168static inline int
169dma_supported(struct device *dev, u64 mask)
170{
171 BUG();
172 return 0;
173}
174
175static inline int
176dma_set_mask(struct device *dev, u64 dma_mask)
177{
178 BUG();
179 return 0;
180}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
182static inline void *dma_alloc_coherent(struct device *dev, size_t size,
Al Viro970a9e72005-10-21 03:21:53 -0400183 dma_addr_t *dma_handle, gfp_t flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184{
185 BUG();
186 return NULL;
187}
188
189static inline void dma_free_coherent(struct device *dev, size_t size,
190 void *vaddr, dma_addr_t dma_handle)
191{
192 BUG();
193}
194
David S. Millerf04dbac2007-06-04 23:32:23 -0700195static inline dma_addr_t
196dma_map_single(struct device *dev, void *cpu_addr, size_t size,
197 enum dma_data_direction direction)
198{
199 BUG();
200 return 0;
201}
202
203static inline void
204dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
205 enum dma_data_direction direction)
206{
207 BUG();
208}
209
210static inline dma_addr_t
211dma_map_page(struct device *dev, struct page *page,
212 unsigned long offset, size_t size,
213 enum dma_data_direction direction)
214{
215 BUG();
216 return 0;
217}
218
219static inline void
220dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
221 enum dma_data_direction direction)
222{
223 BUG();
224}
225
226static inline int
227dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
228 enum dma_data_direction direction)
229{
230 BUG();
231 return 0;
232}
233
234static inline void
235dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
236 enum dma_data_direction direction)
237{
238 BUG();
239}
240
Randy Dunlap72335892006-07-05 20:18:39 -0700241static inline void
242dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size,
243 enum dma_data_direction direction)
244{
245 BUG();
246}
247
248static inline void
249dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle, size_t size,
250 enum dma_data_direction direction)
251{
252 BUG();
253}
254
David S. Millerf04dbac2007-06-04 23:32:23 -0700255static inline void
256dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems,
257 enum dma_data_direction direction)
258{
259 BUG();
260}
261
262static inline void
263dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nelems,
264 enum dma_data_direction direction)
265{
266 BUG();
267}
268
269static inline int
270dma_mapping_error(dma_addr_t dma_addr)
271{
272 BUG();
273 return 0;
274}
275
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276#endif /* PCI */
277
David S. Miller36321422006-06-25 02:07:52 -0700278
279/* Now for the API extensions over the pci_ one */
280
281#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
282#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
Ralf Baechlef67637e2006-12-06 20:38:54 -0800283#define dma_is_consistent(d, h) (1)
David S. Miller36321422006-06-25 02:07:52 -0700284
285static inline int
286dma_get_cache_alignment(void)
287{
288 /* no easy way to get cache size on all processors, so return
289 * the maximum possible, to be safe */
290 return (1 << INTERNODE_CACHE_SHIFT);
291}
292
293static inline void
294dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t dma_handle,
295 unsigned long offset, size_t size,
296 enum dma_data_direction direction)
297{
298 /* just sync everything, that's all the pci API can do */
299 dma_sync_single_for_cpu(dev, dma_handle, offset+size, direction);
300}
301
302static inline void
303dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle,
304 unsigned long offset, size_t size,
305 enum dma_data_direction direction)
306{
307 /* just sync everything, that's all the pci API can do */
308 dma_sync_single_for_device(dev, dma_handle, offset+size, direction);
309}
310
311static inline void
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800312dma_cache_sync(struct device *dev, void *vaddr, size_t size,
David S. Miller36321422006-06-25 02:07:52 -0700313 enum dma_data_direction direction)
314{
315 /* could define this in terms of the dma_cache ... operations,
316 * but if you get this on a platform, you should convert the platform
317 * to using the generic device DMA API */
318 BUG();
319}
320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321#endif /* _ASM_SPARC64_DMA_MAPPING_H */