blob: 49a81a66516e9ba2d6556c0154925d970d0ceaf8 [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
9#include <linux/config.h>
10
11#include <asm/scatterlist.h>
12#include <asm/io.h>
13#include <asm/swiotlb.h>
14
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010015struct dma_mapping_ops {
16 int (*mapping_error)(dma_addr_t dma_addr);
17 void* (*alloc_coherent)(struct device *dev, size_t size,
18 dma_addr_t *dma_handle, gfp_t gfp);
19 void (*free_coherent)(struct device *dev, size_t size,
20 void *vaddr, dma_addr_t dma_handle);
21 dma_addr_t (*map_single)(struct device *hwdev, void *ptr,
22 size_t size, int direction);
23 /* like map_single, but doesn't check the device mask */
24 dma_addr_t (*map_simple)(struct device *hwdev, char *ptr,
25 size_t size, int direction);
26 void (*unmap_single)(struct device *dev, dma_addr_t addr,
27 size_t size, int direction);
28 void (*sync_single_for_cpu)(struct device *hwdev,
29 dma_addr_t dma_handle, size_t size,
30 int direction);
31 void (*sync_single_for_device)(struct device *hwdev,
32 dma_addr_t dma_handle, size_t size,
33 int direction);
34 void (*sync_single_range_for_cpu)(struct device *hwdev,
35 dma_addr_t dma_handle, unsigned long offset,
36 size_t size, int direction);
37 void (*sync_single_range_for_device)(struct device *hwdev,
38 dma_addr_t dma_handle, unsigned long offset,
39 size_t size, int direction);
40 void (*sync_sg_for_cpu)(struct device *hwdev,
41 struct scatterlist *sg, int nelems,
42 int direction);
43 void (*sync_sg_for_device)(struct device *hwdev,
44 struct scatterlist *sg, int nelems,
45 int direction);
46 int (*map_sg)(struct device *hwdev, struct scatterlist *sg,
47 int nents, int direction);
48 void (*unmap_sg)(struct device *hwdev,
49 struct scatterlist *sg, int nents,
50 int direction);
51 int (*dma_supported)(struct device *hwdev, u64 mask);
52 int is_phys;
53};
54
Linus Torvalds1da177e2005-04-16 15:20:36 -070055extern dma_addr_t bad_dma_address;
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010056extern struct dma_mapping_ops* dma_ops;
57extern int iommu_merge;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010059static inline int dma_mapping_error(dma_addr_t dma_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010061 if (dma_ops->mapping_error)
62 return dma_ops->mapping_error(dma_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010064 return (dma_addr == bad_dma_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065}
66
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010067extern void *dma_alloc_coherent(struct device *dev, size_t size,
68 dma_addr_t *dma_handle, gfp_t gfp);
69extern void dma_free_coherent(struct device *dev, size_t size, void *vaddr,
70 dma_addr_t dma_handle);
71
72static inline dma_addr_t
73dma_map_single(struct device *hwdev, void *ptr, size_t size,
74 int direction)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010076 return dma_ops->map_single(hwdev, ptr, size, direction);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077}
78
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010079static inline void
80dma_unmap_single(struct device *dev, dma_addr_t addr,size_t size,
81 int direction)
82{
83 dma_ops->unmap_single(dev, addr, size, direction);
84}
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86#define dma_map_page(dev,page,offset,size,dir) \
87 dma_map_single((dev), page_address(page)+(offset), (size), (dir))
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089#define dma_unmap_page dma_unmap_single
90
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010091static inline void
92dma_sync_single_for_cpu(struct device *hwdev, dma_addr_t dma_handle,
93 size_t size, int direction)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094{
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010095 if (dma_ops->sync_single_for_cpu)
96 dma_ops->sync_single_for_cpu(hwdev, dma_handle, size,
97 direction);
98 flush_write_buffers();
Linus Torvalds1da177e2005-04-16 15:20:36 -070099}
100
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +0100101static inline void
102dma_sync_single_for_device(struct device *hwdev, dma_addr_t dma_handle,
103 size_t size, int direction)
104{
105 if (dma_ops->sync_single_for_device)
106 dma_ops->sync_single_for_device(hwdev, dma_handle, size,
107 direction);
108 flush_write_buffers();
109}
110
111static inline void
112dma_sync_single_range_for_cpu(struct device *hwdev, dma_addr_t dma_handle,
113 unsigned long offset, size_t size, int direction)
114{
115 if (dma_ops->sync_single_range_for_cpu) {
116 dma_ops->sync_single_range_for_cpu(hwdev, dma_handle, offset, size, direction);
117 }
118
119 flush_write_buffers();
120}
121
122static inline void
123dma_sync_single_range_for_device(struct device *hwdev, dma_addr_t dma_handle,
124 unsigned long offset, size_t size, int direction)
125{
126 if (dma_ops->sync_single_range_for_device)
127 dma_ops->sync_single_range_for_device(hwdev, dma_handle,
128 offset, size, direction);
129
130 flush_write_buffers();
131}
132
133static inline void
134dma_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg,
135 int nelems, int direction)
136{
137 if (dma_ops->sync_sg_for_cpu)
138 dma_ops->sync_sg_for_cpu(hwdev, sg, nelems, direction);
139 flush_write_buffers();
140}
141
142static inline void
143dma_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg,
144 int nelems, int direction)
145{
146 if (dma_ops->sync_sg_for_device) {
147 dma_ops->sync_sg_for_device(hwdev, sg, nelems, direction);
148 }
149
150 flush_write_buffers();
151}
152
153static inline int
154dma_map_sg(struct device *hwdev, struct scatterlist *sg, int nents, int direction)
155{
156 return dma_ops->map_sg(hwdev, sg, nents, direction);
157}
158
159static inline void
160dma_unmap_sg(struct device *hwdev, struct scatterlist *sg, int nents,
161 int direction)
162{
163 dma_ops->unmap_sg(hwdev, sg, nents, direction);
164}
165
166extern int dma_supported(struct device *hwdev, u64 mask);
167
168/* same for gart, swiotlb, and nommu */
169static inline int dma_get_cache_alignment(void)
170{
171 return boot_cpu_data.x86_clflush_size;
172}
173
174#define dma_is_consistent(h) 1
175
176extern int dma_set_mask(struct device *dev, u64 mask);
177
178static inline void
179dma_cache_sync(void *vaddr, size_t size, enum dma_data_direction dir)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180{
181 flush_write_buffers();
182}
183
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +0100184extern struct device fallback_dev;
185extern int panic_on_overflow;
186
187#endif /* _X8664_DMA_MAPPING_H */