fs: use kmem_cache_zalloc instead
[pv_ops_mirror.git] / include / asm-x86 / dma-mapping_64.h
blobecd0f6125ba3b3c005be3192c44ce07e4383021e
1 #ifndef _X8664_DMA_MAPPING_H
2 #define _X8664_DMA_MAPPING_H 1
4 /*
5 * IOMMU interface. See Documentation/DMA-mapping.txt and DMA-API.txt for
6 * documentation.
7 */
9 #include <linux/scatterlist.h>
10 #include <asm/io.h>
11 #include <asm/swiotlb.h>
13 struct 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;
53 extern dma_addr_t bad_dma_address;
54 extern const struct dma_mapping_ops* dma_ops;
55 extern int iommu_merge;
57 static inline int dma_mapping_error(dma_addr_t dma_addr)
59 if (dma_ops->mapping_error)
60 return dma_ops->mapping_error(dma_addr);
62 return (dma_addr == bad_dma_address);
65 #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)
68 #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)
71 extern void *dma_alloc_coherent(struct device *dev, size_t size,
72 dma_addr_t *dma_handle, gfp_t gfp);
73 extern void dma_free_coherent(struct device *dev, size_t size, void *vaddr,
74 dma_addr_t dma_handle);
76 static inline dma_addr_t
77 dma_map_single(struct device *hwdev, void *ptr, size_t size,
78 int direction)
80 BUG_ON(!valid_dma_direction(direction));
81 return dma_ops->map_single(hwdev, ptr, size, direction);
84 static inline void
85 dma_unmap_single(struct device *dev, dma_addr_t addr,size_t size,
86 int direction)
88 BUG_ON(!valid_dma_direction(direction));
89 dma_ops->unmap_single(dev, addr, size, direction);
92 #define dma_map_page(dev,page,offset,size,dir) \
93 dma_map_single((dev), page_address(page)+(offset), (size), (dir))
95 #define dma_unmap_page dma_unmap_single
97 static inline void
98 dma_sync_single_for_cpu(struct device *hwdev, dma_addr_t dma_handle,
99 size_t size, int direction)
101 BUG_ON(!valid_dma_direction(direction));
102 if (dma_ops->sync_single_for_cpu)
103 dma_ops->sync_single_for_cpu(hwdev, dma_handle, size,
104 direction);
105 flush_write_buffers();
108 static inline void
109 dma_sync_single_for_device(struct device *hwdev, dma_addr_t dma_handle,
110 size_t size, int direction)
112 BUG_ON(!valid_dma_direction(direction));
113 if (dma_ops->sync_single_for_device)
114 dma_ops->sync_single_for_device(hwdev, dma_handle, size,
115 direction);
116 flush_write_buffers();
119 static inline void
120 dma_sync_single_range_for_cpu(struct device *hwdev, dma_addr_t dma_handle,
121 unsigned long offset, size_t size, int direction)
123 BUG_ON(!valid_dma_direction(direction));
124 if (dma_ops->sync_single_range_for_cpu) {
125 dma_ops->sync_single_range_for_cpu(hwdev, dma_handle, offset, size, direction);
128 flush_write_buffers();
131 static inline void
132 dma_sync_single_range_for_device(struct device *hwdev, dma_addr_t dma_handle,
133 unsigned long offset, size_t size, int direction)
135 BUG_ON(!valid_dma_direction(direction));
136 if (dma_ops->sync_single_range_for_device)
137 dma_ops->sync_single_range_for_device(hwdev, dma_handle,
138 offset, size, direction);
140 flush_write_buffers();
143 static inline void
144 dma_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg,
145 int nelems, int direction)
147 BUG_ON(!valid_dma_direction(direction));
148 if (dma_ops->sync_sg_for_cpu)
149 dma_ops->sync_sg_for_cpu(hwdev, sg, nelems, direction);
150 flush_write_buffers();
153 static inline void
154 dma_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg,
155 int nelems, int direction)
157 BUG_ON(!valid_dma_direction(direction));
158 if (dma_ops->sync_sg_for_device) {
159 dma_ops->sync_sg_for_device(hwdev, sg, nelems, direction);
162 flush_write_buffers();
165 static inline int
166 dma_map_sg(struct device *hwdev, struct scatterlist *sg, int nents, int direction)
168 BUG_ON(!valid_dma_direction(direction));
169 return dma_ops->map_sg(hwdev, sg, nents, direction);
172 static inline void
173 dma_unmap_sg(struct device *hwdev, struct scatterlist *sg, int nents,
174 int direction)
176 BUG_ON(!valid_dma_direction(direction));
177 dma_ops->unmap_sg(hwdev, sg, nents, direction);
180 extern int dma_supported(struct device *hwdev, u64 mask);
182 /* same for gart, swiotlb, and nommu */
183 static inline int dma_get_cache_alignment(void)
185 return boot_cpu_data.x86_clflush_size;
188 #define dma_is_consistent(d, h) 1
190 extern int dma_set_mask(struct device *dev, u64 mask);
192 static inline void
193 dma_cache_sync(struct device *dev, void *vaddr, size_t size,
194 enum dma_data_direction dir)
196 flush_write_buffers();
199 extern struct device fallback_dev;
200 extern int panic_on_overflow;
202 #endif /* _X8664_DMA_MAPPING_H */