blob: 36d16dfbac88d7e9b48cd6e254726571dd535650 [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
15extern dma_addr_t bad_dma_address;
16#define dma_mapping_error(x) \
17 (swiotlb ? swiotlb_dma_mapping_error(x) : ((x) == bad_dma_address))
18
19void *dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
Al Virof80aabb2005-10-21 03:21:43 -040020 gfp_t gfp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070021void dma_free_coherent(struct device *dev, size_t size, void *vaddr,
22 dma_addr_t dma_handle);
23
24#ifdef CONFIG_GART_IOMMU
25
26extern dma_addr_t dma_map_single(struct device *hwdev, void *ptr, size_t size,
27 int direction);
28extern void dma_unmap_single(struct device *dev, dma_addr_t addr,size_t size,
29 int direction);
30
31#else
32
33/* No IOMMU */
34
35static inline dma_addr_t dma_map_single(struct device *hwdev, void *ptr,
36 size_t size, int direction)
37{
38 dma_addr_t addr;
39
40 if (direction == DMA_NONE)
41 out_of_line_bug();
42 addr = virt_to_bus(ptr);
43
44 if ((addr+size) & ~*hwdev->dma_mask)
45 out_of_line_bug();
46 return addr;
47}
48
49static inline void dma_unmap_single(struct device *hwdev, dma_addr_t dma_addr,
50 size_t size, int direction)
51{
52 if (direction == DMA_NONE)
53 out_of_line_bug();
54 /* Nothing to do */
55}
56
57#endif
58
59#define dma_map_page(dev,page,offset,size,dir) \
60 dma_map_single((dev), page_address(page)+(offset), (size), (dir))
61
62static inline void dma_sync_single_for_cpu(struct device *hwdev,
63 dma_addr_t dma_handle,
64 size_t size, int direction)
65{
66 if (direction == DMA_NONE)
67 out_of_line_bug();
68
69 if (swiotlb)
70 return swiotlb_sync_single_for_cpu(hwdev,dma_handle,size,direction);
71
72 flush_write_buffers();
73}
74
75static inline void dma_sync_single_for_device(struct device *hwdev,
76 dma_addr_t dma_handle,
77 size_t size, int direction)
78{
79 if (direction == DMA_NONE)
80 out_of_line_bug();
81
82 if (swiotlb)
83 return swiotlb_sync_single_for_device(hwdev,dma_handle,size,direction);
84
85 flush_write_buffers();
86}
87
John W. Linville8d15d192005-09-29 14:45:52 -070088static inline void dma_sync_single_range_for_cpu(struct device *hwdev,
89 dma_addr_t dma_handle,
90 unsigned long offset,
91 size_t size, int direction)
92{
93 if (direction == DMA_NONE)
94 out_of_line_bug();
95
96 if (swiotlb)
97 return swiotlb_sync_single_range_for_cpu(hwdev,dma_handle,offset,size,direction);
98
99 flush_write_buffers();
100}
101
102static inline void dma_sync_single_range_for_device(struct device *hwdev,
103 dma_addr_t dma_handle,
104 unsigned long offset,
105 size_t size, int direction)
106{
107 if (direction == DMA_NONE)
108 out_of_line_bug();
109
110 if (swiotlb)
111 return swiotlb_sync_single_range_for_device(hwdev,dma_handle,offset,size,direction);
112
113 flush_write_buffers();
114}
Andi Kleen27183ebd2005-09-12 18:49:24 +0200115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116static inline void dma_sync_sg_for_cpu(struct device *hwdev,
117 struct scatterlist *sg,
118 int nelems, int direction)
119{
120 if (direction == DMA_NONE)
121 out_of_line_bug();
122
123 if (swiotlb)
124 return swiotlb_sync_sg_for_cpu(hwdev,sg,nelems,direction);
125
126 flush_write_buffers();
127}
128
129static inline void dma_sync_sg_for_device(struct device *hwdev,
130 struct scatterlist *sg,
131 int nelems, int direction)
132{
133 if (direction == DMA_NONE)
134 out_of_line_bug();
135
136 if (swiotlb)
137 return swiotlb_sync_sg_for_device(hwdev,sg,nelems,direction);
138
139 flush_write_buffers();
140}
141
142extern int dma_map_sg(struct device *hwdev, struct scatterlist *sg,
143 int nents, int direction);
144extern void dma_unmap_sg(struct device *hwdev, struct scatterlist *sg,
145 int nents, int direction);
146
147#define dma_unmap_page dma_unmap_single
148
149extern int dma_supported(struct device *hwdev, u64 mask);
150extern int dma_get_cache_alignment(void);
151#define dma_is_consistent(h) 1
152
153static inline int dma_set_mask(struct device *dev, u64 mask)
154{
155 if (!dev->dma_mask || !dma_supported(dev, mask))
156 return -EIO;
157 *dev->dma_mask = mask;
158 return 0;
159}
160
161static inline void dma_cache_sync(void *vaddr, size_t size, enum dma_data_direction dir)
162{
163 flush_write_buffers();
164}
165
166#endif