bac3159379f785ede25f4d8aefa586a498a7d687
[linux-2.6.git] / arch / ia64 / include / asm / dma-mapping.h
1 #ifndef _ASM_IA64_DMA_MAPPING_H
2 #define _ASM_IA64_DMA_MAPPING_H
3
4 /*
5  * Copyright (C) 2003-2004 Hewlett-Packard Co
6  *      David Mosberger-Tang <davidm@hpl.hp.com>
7  */
8 #include <asm/machvec.h>
9 #include <linux/scatterlist.h>
10 #include <asm/swiotlb.h>
11
12 struct dma_mapping_ops {
13         int             (*mapping_error)(struct device *dev,
14                                          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, unsigned long ptr,
20                                 size_t size, int direction);
21         void            (*unmap_single)(struct device *dev, dma_addr_t addr,
22                                 size_t size, int direction);
23         dma_addr_t      (*map_single_attrs)(struct device *dev, void *cpu_addr,
24                                             size_t size, int direction,
25                                             struct dma_attrs *attrs);
26         void            (*unmap_single_attrs)(struct device *dev,
27                                               dma_addr_t dma_addr,
28                                               size_t size, int direction,
29                                               struct dma_attrs *attrs);
30         void            (*sync_single_for_cpu)(struct device *hwdev,
31                                 dma_addr_t dma_handle, size_t size,
32                                 int direction);
33         void            (*sync_single_for_device)(struct device *hwdev,
34                                 dma_addr_t dma_handle, size_t size,
35                                 int direction);
36         void            (*sync_single_range_for_cpu)(struct device *hwdev,
37                                 dma_addr_t dma_handle, unsigned long offset,
38                                 size_t size, int direction);
39         void            (*sync_single_range_for_device)(struct device *hwdev,
40                                 dma_addr_t dma_handle, unsigned long offset,
41                                 size_t size, int direction);
42         void            (*sync_sg_for_cpu)(struct device *hwdev,
43                                 struct scatterlist *sg, int nelems,
44                                 int direction);
45         void            (*sync_sg_for_device)(struct device *hwdev,
46                                 struct scatterlist *sg, int nelems,
47                                 int direction);
48         int             (*map_sg)(struct device *hwdev, struct scatterlist *sg,
49                                 int nents, int direction);
50         void            (*unmap_sg)(struct device *hwdev,
51                                 struct scatterlist *sg, int nents,
52                                 int direction);
53         int             (*map_sg_attrs)(struct device *dev,
54                                         struct scatterlist *sg, int nents,
55                                         int direction, struct dma_attrs *attrs);
56         void            (*unmap_sg_attrs)(struct device *dev,
57                                           struct scatterlist *sg, int nents,
58                                           int direction,
59                                           struct dma_attrs *attrs);
60         int             (*dma_supported_op)(struct device *hwdev, u64 mask);
61         int             is_phys;
62 };
63
64 extern struct dma_mapping_ops *dma_ops;
65 extern struct ia64_machine_vector ia64_mv;
66 extern void set_iommu_machvec(void);
67
68 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
69                                        dma_addr_t *daddr, gfp_t gfp)
70 {
71         struct dma_mapping_ops *ops = platform_dma_get_ops(dev);
72         return ops->alloc_coherent(dev, size, daddr, gfp | GFP_DMA);
73 }
74
75 static inline void dma_free_coherent(struct device *dev, size_t size,
76                                      void *caddr, dma_addr_t daddr)
77 {
78         struct dma_mapping_ops *ops = platform_dma_get_ops(dev);
79         ops->free_coherent(dev, size, caddr, daddr);
80 }
81
82 #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
83 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
84
85 static inline dma_addr_t dma_map_single_attrs(struct device *dev,
86                                               void *caddr, size_t size,
87                                               enum dma_data_direction dir,
88                                               struct dma_attrs *attrs)
89 {
90         struct dma_mapping_ops *ops = platform_dma_get_ops(dev);
91         return ops->map_single_attrs(dev, caddr, size, dir, attrs);
92 }
93
94 static inline void dma_unmap_single_attrs(struct device *dev, dma_addr_t daddr,
95                                           size_t size,
96                                           enum dma_data_direction dir,
97                                           struct dma_attrs *attrs)
98 {
99         struct dma_mapping_ops *ops = platform_dma_get_ops(dev);
100         ops->unmap_single_attrs(dev, daddr, size, dir, attrs);
101 }
102
103 #define dma_map_single(d, a, s, r) dma_map_single_attrs(d, a, s, r, NULL)
104 #define dma_unmap_single(d, a, s, r) dma_unmap_single_attrs(d, a, s, r, NULL)
105
106 static inline int dma_map_sg_attrs(struct device *dev, struct scatterlist *sgl,
107                                    int nents, enum dma_data_direction dir,
108                                    struct dma_attrs *attrs)
109 {
110         struct dma_mapping_ops *ops = platform_dma_get_ops(dev);
111         return ops->map_sg_attrs(dev, sgl, nents, dir, attrs);
112 }
113
114 static inline void dma_unmap_sg_attrs(struct device *dev,
115                                       struct scatterlist *sgl, int nents,
116                                       enum dma_data_direction dir,
117                                       struct dma_attrs *attrs)
118 {
119         struct dma_mapping_ops *ops = platform_dma_get_ops(dev);
120         ops->unmap_sg_attrs(dev, sgl, nents, dir, attrs);
121 }
122
123 #define dma_map_sg(d, s, n, r) dma_map_sg_attrs(d, s, n, r, NULL)
124 #define dma_unmap_sg(d, s, n, r) dma_unmap_sg_attrs(d, s, n, r, NULL)
125
126 static inline void dma_sync_single_for_cpu(struct device *dev, dma_addr_t daddr,
127                                            size_t size,
128                                            enum dma_data_direction dir)
129 {
130         struct dma_mapping_ops *ops = platform_dma_get_ops(dev);
131         ops->sync_single_for_cpu(dev, daddr, size, dir);
132 }
133
134 static inline void dma_sync_sg_for_cpu(struct device *dev,
135                                        struct scatterlist *sgl,
136                                        int nents, enum dma_data_direction dir)
137 {
138         struct dma_mapping_ops *ops = platform_dma_get_ops(dev);
139         ops->sync_sg_for_cpu(dev, sgl, nents, dir);
140 }
141
142 static inline void dma_sync_single_for_device(struct device *dev,
143                                               dma_addr_t daddr,
144                                               size_t size,
145                                               enum dma_data_direction dir)
146 {
147         struct dma_mapping_ops *ops = platform_dma_get_ops(dev);
148         ops->sync_single_for_device(dev, daddr, size, dir);
149 }
150
151 static inline void dma_sync_sg_for_device(struct device *dev,
152                                           struct scatterlist *sgl,
153                                           int nents,
154                                           enum dma_data_direction dir)
155 {
156         struct dma_mapping_ops *ops = platform_dma_get_ops(dev);
157         ops->sync_sg_for_device(dev, sgl, nents, dir);
158 }
159
160 static inline int dma_mapping_error(struct device *dev, dma_addr_t daddr)
161 {
162         struct dma_mapping_ops *ops = platform_dma_get_ops(dev);
163         return ops->mapping_error(dev, daddr);
164 }
165
166 #define dma_map_page(dev, pg, off, size, dir)                           \
167         dma_map_single(dev, page_address(pg) + (off), (size), (dir))
168 #define dma_unmap_page(dev, dma_addr, size, dir)                        \
169         dma_unmap_single(dev, dma_addr, size, dir)
170
171 /*
172  * Rest of this file is part of the "Advanced DMA API".  Use at your own risk.
173  * See Documentation/DMA-API.txt for details.
174  */
175
176 #define dma_sync_single_range_for_cpu(dev, dma_handle, offset, size, dir)       \
177         dma_sync_single_for_cpu(dev, dma_handle, size, dir)
178 #define dma_sync_single_range_for_device(dev, dma_handle, offset, size, dir)    \
179         dma_sync_single_for_device(dev, dma_handle, size, dir)
180
181 static inline int dma_supported(struct device *dev, u64 mask)
182 {
183         struct dma_mapping_ops *ops = platform_dma_get_ops(dev);
184         return ops->dma_supported_op(dev, mask);
185 }
186
187 static inline int
188 dma_set_mask (struct device *dev, u64 mask)
189 {
190         if (!dev->dma_mask || !dma_supported(dev, mask))
191                 return -EIO;
192         *dev->dma_mask = mask;
193         return 0;
194 }
195
196 extern int dma_get_cache_alignment(void);
197
198 static inline void
199 dma_cache_sync (struct device *dev, void *vaddr, size_t size,
200         enum dma_data_direction dir)
201 {
202         /*
203          * IA-64 is cache-coherent, so this is mostly a no-op.  However, we do need to
204          * ensure that dma_cache_sync() enforces order, hence the mb().
205          */
206         mb();
207 }
208
209 #define dma_is_consistent(d, h) (1)     /* all we do is coherent memory... */
210
211 #endif /* _ASM_IA64_DMA_MAPPING_H */