Merge to Fedora kernel-2.6.18-1.2255_FC5-vs2.0.2.2-rc9 patched with stable patch...
[linux-2.6.git] / include / asm-x86_64 / mach-xen / asm / dma-mapping.h
1 #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
10 #include <asm/scatterlist.h>
11 #include <asm/io.h>
12 #include <asm/swiotlb.h>
13
14 struct 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
54 extern dma_addr_t bad_dma_address;
55 extern struct dma_mapping_ops* dma_ops;
56 extern int iommu_merge;
57
58 #if 0
59 static inline int valid_dma_direction(int dma_direction)
60 {
61         return ((dma_direction == DMA_BIDIRECTIONAL) ||
62                 (dma_direction == DMA_TO_DEVICE) ||
63                 (dma_direction == DMA_FROM_DEVICE));
64 }
65
66 static inline int dma_mapping_error(dma_addr_t dma_addr)
67 {
68         if (dma_ops->mapping_error)
69                 return dma_ops->mapping_error(dma_addr);
70
71         return (dma_addr == bad_dma_address);
72 }
73
74 extern void *dma_alloc_coherent(struct device *dev, size_t size,
75                                 dma_addr_t *dma_handle, gfp_t gfp);
76 extern void dma_free_coherent(struct device *dev, size_t size, void *vaddr,
77                               dma_addr_t dma_handle);
78
79 static inline dma_addr_t
80 dma_map_single(struct device *hwdev, void *ptr, size_t size,
81                int direction)
82 {
83         BUG_ON(!valid_dma_direction(direction));
84         return dma_ops->map_single(hwdev, ptr, size, direction);
85 }
86
87 static inline void
88 dma_unmap_single(struct device *dev, dma_addr_t addr,size_t size,
89                  int direction)
90 {
91         BUG_ON(!valid_dma_direction(direction));
92         dma_ops->unmap_single(dev, addr, size, direction);
93 }
94
95 #define dma_map_page(dev,page,offset,size,dir) \
96         dma_map_single((dev), page_address(page)+(offset), (size), (dir))
97
98 #define dma_unmap_page dma_unmap_single
99
100 static inline void
101 dma_sync_single_for_cpu(struct device *hwdev, dma_addr_t dma_handle,
102                         size_t size, int direction)
103 {
104         BUG_ON(!valid_dma_direction(direction));
105         if (dma_ops->sync_single_for_cpu)
106                 dma_ops->sync_single_for_cpu(hwdev, dma_handle, size,
107                                              direction);
108         flush_write_buffers();
109 }
110
111 static inline void
112 dma_sync_single_for_device(struct device *hwdev, dma_addr_t dma_handle,
113                            size_t size, int direction)
114 {
115         BUG_ON(!valid_dma_direction(direction));
116         if (dma_ops->sync_single_for_device)
117                 dma_ops->sync_single_for_device(hwdev, dma_handle, size,
118                                                 direction);
119         flush_write_buffers();
120 }
121
122 static inline void
123 dma_sync_single_range_for_cpu(struct device *hwdev, dma_addr_t dma_handle,
124                               unsigned long offset, size_t size, int direction)
125 {
126         BUG_ON(!valid_dma_direction(direction));
127         if (dma_ops->sync_single_range_for_cpu) {
128                 dma_ops->sync_single_range_for_cpu(hwdev, dma_handle, offset, size, direction);
129         }
130
131         flush_write_buffers();
132 }
133
134 static inline void
135 dma_sync_single_range_for_device(struct device *hwdev, dma_addr_t dma_handle,
136                                  unsigned long offset, size_t size, int direction)
137 {
138         BUG_ON(!valid_dma_direction(direction));
139         if (dma_ops->sync_single_range_for_device)
140                 dma_ops->sync_single_range_for_device(hwdev, dma_handle,
141                                                       offset, size, direction);
142
143         flush_write_buffers();
144 }
145
146 static inline void
147 dma_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg,
148                     int nelems, int direction)
149 {
150         BUG_ON(!valid_dma_direction(direction));
151         if (dma_ops->sync_sg_for_cpu)
152                 dma_ops->sync_sg_for_cpu(hwdev, sg, nelems, direction);
153         flush_write_buffers();
154 }
155
156 static inline void
157 dma_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg,
158                        int nelems, int direction)
159 {
160         BUG_ON(!valid_dma_direction(direction));
161         if (dma_ops->sync_sg_for_device) {
162                 dma_ops->sync_sg_for_device(hwdev, sg, nelems, direction);
163         }
164
165         flush_write_buffers();
166 }
167
168 static inline int
169 dma_map_sg(struct device *hwdev, struct scatterlist *sg, int nents, int direction)
170 {
171         BUG_ON(!valid_dma_direction(direction));
172         return dma_ops->map_sg(hwdev, sg, nents, direction);
173 }
174
175 static inline void
176 dma_unmap_sg(struct device *hwdev, struct scatterlist *sg, int nents,
177              int direction)
178 {
179         BUG_ON(!valid_dma_direction(direction));
180         dma_ops->unmap_sg(hwdev, sg, nents, direction);
181 }
182
183 extern int dma_supported(struct device *hwdev, u64 mask);
184
185 /* same for gart, swiotlb, and nommu */
186 static inline int dma_get_cache_alignment(void)
187 {
188         return boot_cpu_data.x86_clflush_size;
189 }
190
191 #define dma_is_consistent(h) 1
192
193 extern int dma_set_mask(struct device *dev, u64 mask);
194
195 static inline void
196 dma_cache_sync(void *vaddr, size_t size, enum dma_data_direction dir)
197 {
198         flush_write_buffers();
199 }
200
201 extern struct device fallback_dev;
202 #endif
203 extern int panic_on_overflow;
204
205 #endif /* _X8664_DMA_MAPPING_H */
206
207 #include <asm-i386/mach-xen/asm/dma-mapping.h>