blob: 49dbab09ef2b05ac113aebd464631be17a572ea4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _X8664_DMA_MAPPING_H
2#define _X8664_DMA_MAPPING_H 1
3
4/*
5 * IOMMU interface. See Documentation/DMA-mapping.txt and DMA-API.txt for
6 * documentation.
7 */
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
10#include <asm/scatterlist.h>
11#include <asm/io.h>
12#include <asm/swiotlb.h>
13
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010014struct dma_mapping_ops {
15 int (*mapping_error)(dma_addr_t dma_addr);
16 void* (*alloc_coherent)(struct device *dev, size_t size,
17 dma_addr_t *dma_handle, gfp_t gfp);
18 void (*free_coherent)(struct device *dev, size_t size,
19 void *vaddr, dma_addr_t dma_handle);
20 dma_addr_t (*map_single)(struct device *hwdev, void *ptr,
21 size_t size, int direction);
22 /* like map_single, but doesn't check the device mask */
23 dma_addr_t (*map_simple)(struct device *hwdev, char *ptr,
24 size_t size, int direction);
25 void (*unmap_single)(struct device *dev, dma_addr_t addr,
26 size_t size, int direction);
27 void (*sync_single_for_cpu)(struct device *hwdev,
28 dma_addr_t dma_handle, size_t size,
29 int direction);
30 void (*sync_single_for_device)(struct device *hwdev,
31 dma_addr_t dma_handle, size_t size,
32 int direction);
33 void (*sync_single_range_for_cpu)(struct device *hwdev,
34 dma_addr_t dma_handle, unsigned long offset,
35 size_t size, int direction);
36 void (*sync_single_range_for_device)(struct device *hwdev,
37 dma_addr_t dma_handle, unsigned long offset,
38 size_t size, int direction);
39 void (*sync_sg_for_cpu)(struct device *hwdev,
40 struct scatterlist *sg, int nelems,
41 int direction);
42 void (*sync_sg_for_device)(struct device *hwdev,
43 struct scatterlist *sg, int nelems,
44 int direction);
45 int (*map_sg)(struct device *hwdev, struct scatterlist *sg,
46 int nents, int direction);
47 void (*unmap_sg)(struct device *hwdev,
48 struct scatterlist *sg, int nents,
49 int direction);
50 int (*dma_supported)(struct device *hwdev, u64 mask);
51 int is_phys;
52};
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054extern dma_addr_t bad_dma_address;
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010055extern struct dma_mapping_ops* dma_ops;
56extern int iommu_merge;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010058static inline int dma_mapping_error(dma_addr_t dma_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059{
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010060 if (dma_ops->mapping_error)
61 return dma_ops->mapping_error(dma_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010063 return (dma_addr == bad_dma_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064}
65
Jeff Garzik259886a72007-02-03 01:14:03 -080066#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
67#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
68
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010069extern void *dma_alloc_coherent(struct device *dev, size_t size,
70 dma_addr_t *dma_handle, gfp_t gfp);
71extern void dma_free_coherent(struct device *dev, size_t size, void *vaddr,
72 dma_addr_t dma_handle);
73
74static inline dma_addr_t
75dma_map_single(struct device *hwdev, void *ptr, size_t size,
76 int direction)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077{
Jon Masona3c042a2006-06-26 13:58:08 +020078 BUG_ON(!valid_dma_direction(direction));
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010079 return dma_ops->map_single(hwdev, ptr, size, direction);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080}
81
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010082static inline void
83dma_unmap_single(struct device *dev, dma_addr_t addr,size_t size,
84 int direction)
85{
Jon Masona3c042a2006-06-26 13:58:08 +020086 BUG_ON(!valid_dma_direction(direction));
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010087 dma_ops->unmap_single(dev, addr, size, direction);
88}
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90#define dma_map_page(dev,page,offset,size,dir) \
91 dma_map_single((dev), page_address(page)+(offset), (size), (dir))
92
Linus Torvalds1da177e2005-04-16 15:20:36 -070093#define dma_unmap_page dma_unmap_single
94
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010095static inline void
96dma_sync_single_for_cpu(struct device *hwdev, dma_addr_t dma_handle,
97 size_t size, int direction)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098{
Jon Masona3c042a2006-06-26 13:58:08 +020099 BUG_ON(!valid_dma_direction(direction));
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +0100100 if (dma_ops->sync_single_for_cpu)
101 dma_ops->sync_single_for_cpu(hwdev, dma_handle, size,
102 direction);
103 flush_write_buffers();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104}
105
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +0100106static inline void
107dma_sync_single_for_device(struct device *hwdev, dma_addr_t dma_handle,
108 size_t size, int direction)
109{
Jon Masona3c042a2006-06-26 13:58:08 +0200110 BUG_ON(!valid_dma_direction(direction));
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +0100111 if (dma_ops->sync_single_for_device)
112 dma_ops->sync_single_for_device(hwdev, dma_handle, size,
113 direction);
114 flush_write_buffers();
115}
116
117static inline void
118dma_sync_single_range_for_cpu(struct device *hwdev, dma_addr_t dma_handle,
119 unsigned long offset, size_t size, int direction)
120{
Jon Masona3c042a2006-06-26 13:58:08 +0200121 BUG_ON(!valid_dma_direction(direction));
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +0100122 if (dma_ops->sync_single_range_for_cpu) {
123 dma_ops->sync_single_range_for_cpu(hwdev, dma_handle, offset, size, direction);
124 }
125
126 flush_write_buffers();
127}
128
129static inline void
130dma_sync_single_range_for_device(struct device *hwdev, dma_addr_t dma_handle,
131 unsigned long offset, size_t size, int direction)
132{
Jon Masona3c042a2006-06-26 13:58:08 +0200133 BUG_ON(!valid_dma_direction(direction));
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +0100134 if (dma_ops->sync_single_range_for_device)
135 dma_ops->sync_single_range_for_device(hwdev, dma_handle,
136 offset, size, direction);
137
138 flush_write_buffers();
139}
140
141static inline void
142dma_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg,
143 int nelems, int direction)
144{
Jon Masona3c042a2006-06-26 13:58:08 +0200145 BUG_ON(!valid_dma_direction(direction));
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +0100146 if (dma_ops->sync_sg_for_cpu)
147 dma_ops->sync_sg_for_cpu(hwdev, sg, nelems, direction);
148 flush_write_buffers();
149}
150
151static inline void
152dma_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg,
153 int nelems, int direction)
154{
Jon Masona3c042a2006-06-26 13:58:08 +0200155 BUG_ON(!valid_dma_direction(direction));
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +0100156 if (dma_ops->sync_sg_for_device) {
157 dma_ops->sync_sg_for_device(hwdev, sg, nelems, direction);
158 }
159
160 flush_write_buffers();
161}
162
163static inline int
164dma_map_sg(struct device *hwdev, struct scatterlist *sg, int nents, int direction)
165{
Jon Masona3c042a2006-06-26 13:58:08 +0200166 BUG_ON(!valid_dma_direction(direction));
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +0100167 return dma_ops->map_sg(hwdev, sg, nents, direction);
168}
169
170static inline void
171dma_unmap_sg(struct device *hwdev, struct scatterlist *sg, int nents,
172 int direction)
173{
Jon Masona3c042a2006-06-26 13:58:08 +0200174 BUG_ON(!valid_dma_direction(direction));
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +0100175 dma_ops->unmap_sg(hwdev, sg, nents, direction);
176}
177
178extern int dma_supported(struct device *hwdev, u64 mask);
179
180/* same for gart, swiotlb, and nommu */
181static inline int dma_get_cache_alignment(void)
182{
183 return boot_cpu_data.x86_clflush_size;
184}
185
Ralf Baechlef67637e2006-12-06 20:38:54 -0800186#define dma_is_consistent(d, h) 1
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +0100187
188extern int dma_set_mask(struct device *dev, u64 mask);
189
190static inline void
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800191dma_cache_sync(struct device *dev, void *vaddr, size_t size,
192 enum dma_data_direction dir)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193{
194 flush_write_buffers();
195}
196
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +0100197extern struct device fallback_dev;
198extern int panic_on_overflow;
199
200#endif /* _X8664_DMA_MAPPING_H */