blob: ecd0f6125ba3b3c005be3192c44ce07e4383021e [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
Jens Axboe46856af2007-05-10 11:59:55 +02009#include <linux/scatterlist.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <asm/io.h>
11#include <asm/swiotlb.h>
12
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010013struct dma_mapping_ops {
14 int (*mapping_error)(dma_addr_t dma_addr);
15 void* (*alloc_coherent)(struct device *dev, size_t size,
16 dma_addr_t *dma_handle, gfp_t gfp);
17 void (*free_coherent)(struct device *dev, size_t size,
18 void *vaddr, dma_addr_t dma_handle);
19 dma_addr_t (*map_single)(struct device *hwdev, void *ptr,
20 size_t size, int direction);
21 /* like map_single, but doesn't check the device mask */
22 dma_addr_t (*map_simple)(struct device *hwdev, char *ptr,
23 size_t size, int direction);
24 void (*unmap_single)(struct device *dev, dma_addr_t addr,
25 size_t size, int direction);
26 void (*sync_single_for_cpu)(struct device *hwdev,
27 dma_addr_t dma_handle, size_t size,
28 int direction);
29 void (*sync_single_for_device)(struct device *hwdev,
30 dma_addr_t dma_handle, size_t size,
31 int direction);
32 void (*sync_single_range_for_cpu)(struct device *hwdev,
33 dma_addr_t dma_handle, unsigned long offset,
34 size_t size, int direction);
35 void (*sync_single_range_for_device)(struct device *hwdev,
36 dma_addr_t dma_handle, unsigned long offset,
37 size_t size, int direction);
38 void (*sync_sg_for_cpu)(struct device *hwdev,
39 struct scatterlist *sg, int nelems,
40 int direction);
41 void (*sync_sg_for_device)(struct device *hwdev,
42 struct scatterlist *sg, int nelems,
43 int direction);
44 int (*map_sg)(struct device *hwdev, struct scatterlist *sg,
45 int nents, int direction);
46 void (*unmap_sg)(struct device *hwdev,
47 struct scatterlist *sg, int nents,
48 int direction);
49 int (*dma_supported)(struct device *hwdev, u64 mask);
50 int is_phys;
51};
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053extern dma_addr_t bad_dma_address;
Stephen Hemmingere6584502007-05-02 19:27:06 +020054extern const struct dma_mapping_ops* dma_ops;
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010055extern int iommu_merge;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010057static inline int dma_mapping_error(dma_addr_t dma_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010059 if (dma_ops->mapping_error)
60 return dma_ops->mapping_error(dma_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010062 return (dma_addr == bad_dma_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063}
64
Jeff Garzik259886a72007-02-03 01:14:03 -080065#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
66#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
67
Jeff Garzik2fa8a052007-02-13 13:26:24 +010068#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
69#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
70
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010071extern void *dma_alloc_coherent(struct device *dev, size_t size,
72 dma_addr_t *dma_handle, gfp_t gfp);
73extern void dma_free_coherent(struct device *dev, size_t size, void *vaddr,
74 dma_addr_t dma_handle);
75
76static inline dma_addr_t
77dma_map_single(struct device *hwdev, void *ptr, size_t size,
78 int direction)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079{
Jon Masona3c042a2006-06-26 13:58:08 +020080 BUG_ON(!valid_dma_direction(direction));
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010081 return dma_ops->map_single(hwdev, ptr, size, direction);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082}
83
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010084static inline void
85dma_unmap_single(struct device *dev, dma_addr_t addr,size_t size,
86 int direction)
87{
Jon Masona3c042a2006-06-26 13:58:08 +020088 BUG_ON(!valid_dma_direction(direction));
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010089 dma_ops->unmap_single(dev, addr, size, direction);
90}
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92#define dma_map_page(dev,page,offset,size,dir) \
93 dma_map_single((dev), page_address(page)+(offset), (size), (dir))
94
Linus Torvalds1da177e2005-04-16 15:20:36 -070095#define dma_unmap_page dma_unmap_single
96
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010097static inline void
98dma_sync_single_for_cpu(struct device *hwdev, dma_addr_t dma_handle,
99 size_t size, int direction)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100{
Jon Masona3c042a2006-06-26 13:58:08 +0200101 BUG_ON(!valid_dma_direction(direction));
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +0100102 if (dma_ops->sync_single_for_cpu)
103 dma_ops->sync_single_for_cpu(hwdev, dma_handle, size,
104 direction);
105 flush_write_buffers();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106}
107
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +0100108static inline void
109dma_sync_single_for_device(struct device *hwdev, dma_addr_t dma_handle,
110 size_t size, int direction)
111{
Jon Masona3c042a2006-06-26 13:58:08 +0200112 BUG_ON(!valid_dma_direction(direction));
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +0100113 if (dma_ops->sync_single_for_device)
114 dma_ops->sync_single_for_device(hwdev, dma_handle, size,
115 direction);
116 flush_write_buffers();
117}
118
119static inline void
120dma_sync_single_range_for_cpu(struct device *hwdev, dma_addr_t dma_handle,
121 unsigned long offset, size_t size, int direction)
122{
Jon Masona3c042a2006-06-26 13:58:08 +0200123 BUG_ON(!valid_dma_direction(direction));
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +0100124 if (dma_ops->sync_single_range_for_cpu) {
125 dma_ops->sync_single_range_for_cpu(hwdev, dma_handle, offset, size, direction);
126 }
127
128 flush_write_buffers();
129}
130
131static inline void
132dma_sync_single_range_for_device(struct device *hwdev, dma_addr_t dma_handle,
133 unsigned long offset, size_t size, int direction)
134{
Jon Masona3c042a2006-06-26 13:58:08 +0200135 BUG_ON(!valid_dma_direction(direction));
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +0100136 if (dma_ops->sync_single_range_for_device)
137 dma_ops->sync_single_range_for_device(hwdev, dma_handle,
138 offset, size, direction);
139
140 flush_write_buffers();
141}
142
143static inline void
144dma_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg,
145 int nelems, int direction)
146{
Jon Masona3c042a2006-06-26 13:58:08 +0200147 BUG_ON(!valid_dma_direction(direction));
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +0100148 if (dma_ops->sync_sg_for_cpu)
149 dma_ops->sync_sg_for_cpu(hwdev, sg, nelems, direction);
150 flush_write_buffers();
151}
152
153static inline void
154dma_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg,
155 int nelems, int direction)
156{
Jon Masona3c042a2006-06-26 13:58:08 +0200157 BUG_ON(!valid_dma_direction(direction));
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +0100158 if (dma_ops->sync_sg_for_device) {
159 dma_ops->sync_sg_for_device(hwdev, sg, nelems, direction);
160 }
161
162 flush_write_buffers();
163}
164
165static inline int
166dma_map_sg(struct device *hwdev, struct scatterlist *sg, int nents, int direction)
167{
Jon Masona3c042a2006-06-26 13:58:08 +0200168 BUG_ON(!valid_dma_direction(direction));
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +0100169 return dma_ops->map_sg(hwdev, sg, nents, direction);
170}
171
172static inline void
173dma_unmap_sg(struct device *hwdev, struct scatterlist *sg, int nents,
174 int direction)
175{
Jon Masona3c042a2006-06-26 13:58:08 +0200176 BUG_ON(!valid_dma_direction(direction));
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +0100177 dma_ops->unmap_sg(hwdev, sg, nents, direction);
178}
179
180extern int dma_supported(struct device *hwdev, u64 mask);
181
182/* same for gart, swiotlb, and nommu */
183static inline int dma_get_cache_alignment(void)
184{
185 return boot_cpu_data.x86_clflush_size;
186}
187
Ralf Baechlef67637e2006-12-06 20:38:54 -0800188#define dma_is_consistent(d, h) 1
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +0100189
190extern int dma_set_mask(struct device *dev, u64 mask);
191
192static inline void
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800193dma_cache_sync(struct device *dev, void *vaddr, size_t size,
194 enum dma_data_direction dir)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195{
196 flush_write_buffers();
197}
198
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +0100199extern struct device fallback_dev;
200extern int panic_on_overflow;
201
202#endif /* _X8664_DMA_MAPPING_H */