diff options
author | Muli Ben-Yehuda <mulix@mulix.org> | 2006-01-11 16:44:42 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-01-11 22:04:55 -0500 |
commit | 17a941d854a3f7b0bb916fdeee4c9ffdcc19d8d3 (patch) | |
tree | b6b3b55318336adf769bf57141a01a9defbbb202 /include/asm-x86_64/dma-mapping.h | |
parent | 8a6fdd3e912e0ce6f723431d66baf704bf8a1d26 (diff) |
[PATCH] x86_64: Use function pointers to call DMA mapping functions
AK: I hacked Muli's original patch a lot and there were a lot
of changes - all bugs are probably to blame on me now.
There were also some changes in the fall back behaviour
for swiotlb - in particular it doesn't try to use GFP_DMA
now anymore. Also all DMA mapping operations use the
same core dma_alloc_coherent code with proper fallbacks now.
And various other changes and cleanups.
Known problems: iommu=force swiotlb=force together breaks
needs more testing.
This patch cleans up x86_64's DMA mapping dispatching code. Right now
we have three possible IOMMU types: AGP GART, swiotlb and nommu, and
in the future we will also have Xen's x86_64 swiotlb and other HW
IOMMUs for x86_64. In order to support all of them cleanly, this
patch:
- introduces a struct dma_mapping_ops with function pointers for each
of the DMA mapping operations of gart (AMD HW IOMMU), swiotlb
(software IOMMU) and nommu (no IOMMU).
- gets rid of:
if (swiotlb)
return swiotlb_xxx();
- PCI_DMA_BUS_IS_PHYS is now checked against the dma_ops being set
This makes swiotlb faster by avoiding double copying in some cases.
Signed-Off-By: Muli Ben-Yehuda <mulix@mulix.org>
Signed-Off-By: Jon D. Mason <jdmason@us.ibm.com>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'include/asm-x86_64/dma-mapping.h')
-rw-r--r-- | include/asm-x86_64/dma-mapping.h | 221 |
1 files changed, 121 insertions, 100 deletions
diff --git a/include/asm-x86_64/dma-mapping.h b/include/asm-x86_64/dma-mapping.h index 36d16dfbac88..49a81a66516e 100644 --- a/include/asm-x86_64/dma-mapping.h +++ b/include/asm-x86_64/dma-mapping.h | |||
@@ -12,155 +12,176 @@ | |||
12 | #include <asm/io.h> | 12 | #include <asm/io.h> |
13 | #include <asm/swiotlb.h> | 13 | #include <asm/swiotlb.h> |
14 | 14 | ||
15 | extern dma_addr_t bad_dma_address; | 15 | struct dma_mapping_ops { |
16 | #define dma_mapping_error(x) \ | 16 | int (*mapping_error)(dma_addr_t dma_addr); |
17 | (swiotlb ? swiotlb_dma_mapping_error(x) : ((x) == bad_dma_address)) | 17 | void* (*alloc_coherent)(struct device *dev, size_t size, |
18 | 18 | dma_addr_t *dma_handle, gfp_t gfp); | |
19 | void *dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, | 19 | void (*free_coherent)(struct device *dev, size_t size, |
20 | gfp_t gfp); | 20 | void *vaddr, dma_addr_t dma_handle); |
21 | void dma_free_coherent(struct device *dev, size_t size, void *vaddr, | 21 | dma_addr_t (*map_single)(struct device *hwdev, void *ptr, |
22 | dma_addr_t dma_handle); | 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 | }; | ||
23 | 54 | ||
24 | #ifdef CONFIG_GART_IOMMU | 55 | extern dma_addr_t bad_dma_address; |
56 | extern struct dma_mapping_ops* dma_ops; | ||
57 | extern int iommu_merge; | ||
25 | 58 | ||
26 | extern dma_addr_t dma_map_single(struct device *hwdev, void *ptr, size_t size, | 59 | static inline int dma_mapping_error(dma_addr_t dma_addr) |
27 | int direction); | 60 | { |
28 | extern void dma_unmap_single(struct device *dev, dma_addr_t addr,size_t size, | 61 | if (dma_ops->mapping_error) |
29 | int direction); | 62 | return dma_ops->mapping_error(dma_addr); |
30 | 63 | ||
31 | #else | 64 | return (dma_addr == bad_dma_address); |
65 | } | ||
32 | 66 | ||
33 | /* No IOMMU */ | 67 | extern void *dma_alloc_coherent(struct device *dev, size_t size, |
68 | dma_addr_t *dma_handle, gfp_t gfp); | ||
69 | extern void dma_free_coherent(struct device *dev, size_t size, void *vaddr, | ||
70 | dma_addr_t dma_handle); | ||
34 | 71 | ||
35 | static inline dma_addr_t dma_map_single(struct device *hwdev, void *ptr, | 72 | static inline dma_addr_t |
36 | size_t size, int direction) | 73 | dma_map_single(struct device *hwdev, void *ptr, size_t size, |
74 | int direction) | ||
37 | { | 75 | { |
38 | dma_addr_t addr; | 76 | return dma_ops->map_single(hwdev, ptr, size, direction); |
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 | } | 77 | } |
48 | 78 | ||
49 | static inline void dma_unmap_single(struct device *hwdev, dma_addr_t dma_addr, | 79 | static inline void |
50 | size_t size, int direction) | 80 | dma_unmap_single(struct device *dev, dma_addr_t addr,size_t size, |
81 | int direction) | ||
51 | { | 82 | { |
52 | if (direction == DMA_NONE) | 83 | dma_ops->unmap_single(dev, addr, size, direction); |
53 | out_of_line_bug(); | ||
54 | /* Nothing to do */ | ||
55 | } | 84 | } |
56 | 85 | ||
57 | #endif | ||
58 | |||
59 | #define dma_map_page(dev,page,offset,size,dir) \ | 86 | #define dma_map_page(dev,page,offset,size,dir) \ |
60 | dma_map_single((dev), page_address(page)+(offset), (size), (dir)) | 87 | dma_map_single((dev), page_address(page)+(offset), (size), (dir)) |
61 | 88 | ||
62 | static inline void dma_sync_single_for_cpu(struct device *hwdev, | 89 | #define dma_unmap_page dma_unmap_single |
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 | 90 | ||
91 | static inline void | ||
92 | dma_sync_single_for_cpu(struct device *hwdev, dma_addr_t dma_handle, | ||
93 | size_t size, int direction) | ||
94 | { | ||
95 | if (dma_ops->sync_single_for_cpu) | ||
96 | dma_ops->sync_single_for_cpu(hwdev, dma_handle, size, | ||
97 | direction); | ||
72 | flush_write_buffers(); | 98 | flush_write_buffers(); |
73 | } | 99 | } |
74 | 100 | ||
75 | static inline void dma_sync_single_for_device(struct device *hwdev, | 101 | static inline void |
76 | dma_addr_t dma_handle, | 102 | dma_sync_single_for_device(struct device *hwdev, dma_addr_t dma_handle, |
77 | size_t size, int direction) | 103 | size_t size, int direction) |
78 | { | 104 | { |
79 | if (direction == DMA_NONE) | 105 | if (dma_ops->sync_single_for_device) |
80 | out_of_line_bug(); | 106 | dma_ops->sync_single_for_device(hwdev, dma_handle, size, |
81 | 107 | direction); | |
82 | if (swiotlb) | ||
83 | return swiotlb_sync_single_for_device(hwdev,dma_handle,size,direction); | ||
84 | |||
85 | flush_write_buffers(); | 108 | flush_write_buffers(); |
86 | } | 109 | } |
87 | 110 | ||
88 | static inline void dma_sync_single_range_for_cpu(struct device *hwdev, | 111 | static inline void |
89 | dma_addr_t dma_handle, | 112 | dma_sync_single_range_for_cpu(struct device *hwdev, dma_addr_t dma_handle, |
90 | unsigned long offset, | 113 | unsigned long offset, size_t size, int direction) |
91 | size_t size, int direction) | ||
92 | { | 114 | { |
93 | if (direction == DMA_NONE) | 115 | if (dma_ops->sync_single_range_for_cpu) { |
94 | out_of_line_bug(); | 116 | dma_ops->sync_single_range_for_cpu(hwdev, dma_handle, offset, size, direction); |
95 | 117 | } | |
96 | if (swiotlb) | ||
97 | return swiotlb_sync_single_range_for_cpu(hwdev,dma_handle,offset,size,direction); | ||
98 | 118 | ||
99 | flush_write_buffers(); | 119 | flush_write_buffers(); |
100 | } | 120 | } |
101 | 121 | ||
102 | static inline void dma_sync_single_range_for_device(struct device *hwdev, | 122 | static inline void |
103 | dma_addr_t dma_handle, | 123 | dma_sync_single_range_for_device(struct device *hwdev, dma_addr_t dma_handle, |
104 | unsigned long offset, | 124 | unsigned long offset, size_t size, int direction) |
105 | size_t size, int direction) | ||
106 | { | 125 | { |
107 | if (direction == DMA_NONE) | 126 | if (dma_ops->sync_single_range_for_device) |
108 | out_of_line_bug(); | 127 | dma_ops->sync_single_range_for_device(hwdev, dma_handle, |
109 | 128 | offset, size, direction); | |
110 | if (swiotlb) | ||
111 | return swiotlb_sync_single_range_for_device(hwdev,dma_handle,offset,size,direction); | ||
112 | 129 | ||
113 | flush_write_buffers(); | 130 | flush_write_buffers(); |
114 | } | 131 | } |
115 | 132 | ||
116 | static inline void dma_sync_sg_for_cpu(struct device *hwdev, | 133 | static inline void |
117 | struct scatterlist *sg, | 134 | dma_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg, |
118 | int nelems, int direction) | 135 | int nelems, int direction) |
119 | { | 136 | { |
120 | if (direction == DMA_NONE) | 137 | if (dma_ops->sync_sg_for_cpu) |
121 | out_of_line_bug(); | 138 | dma_ops->sync_sg_for_cpu(hwdev, sg, nelems, direction); |
122 | |||
123 | if (swiotlb) | ||
124 | return swiotlb_sync_sg_for_cpu(hwdev,sg,nelems,direction); | ||
125 | |||
126 | flush_write_buffers(); | 139 | flush_write_buffers(); |
127 | } | 140 | } |
128 | 141 | ||
129 | static inline void dma_sync_sg_for_device(struct device *hwdev, | 142 | static inline void |
130 | struct scatterlist *sg, | 143 | dma_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg, |
131 | int nelems, int direction) | 144 | int nelems, int direction) |
132 | { | 145 | { |
133 | if (direction == DMA_NONE) | 146 | if (dma_ops->sync_sg_for_device) { |
134 | out_of_line_bug(); | 147 | dma_ops->sync_sg_for_device(hwdev, sg, nelems, direction); |
135 | 148 | } | |
136 | if (swiotlb) | ||
137 | return swiotlb_sync_sg_for_device(hwdev,sg,nelems,direction); | ||
138 | 149 | ||
139 | flush_write_buffers(); | 150 | flush_write_buffers(); |
140 | } | 151 | } |
141 | 152 | ||
142 | extern int dma_map_sg(struct device *hwdev, struct scatterlist *sg, | 153 | static inline int |
143 | int nents, int direction); | 154 | dma_map_sg(struct device *hwdev, struct scatterlist *sg, int nents, int direction) |
144 | extern void dma_unmap_sg(struct device *hwdev, struct scatterlist *sg, | 155 | { |
145 | int nents, int direction); | 156 | return dma_ops->map_sg(hwdev, sg, nents, direction); |
157 | } | ||
146 | 158 | ||
147 | #define dma_unmap_page dma_unmap_single | 159 | static inline void |
160 | dma_unmap_sg(struct device *hwdev, struct scatterlist *sg, int nents, | ||
161 | int direction) | ||
162 | { | ||
163 | dma_ops->unmap_sg(hwdev, sg, nents, direction); | ||
164 | } | ||
148 | 165 | ||
149 | extern int dma_supported(struct device *hwdev, u64 mask); | 166 | extern int dma_supported(struct device *hwdev, u64 mask); |
150 | extern int dma_get_cache_alignment(void); | ||
151 | #define dma_is_consistent(h) 1 | ||
152 | 167 | ||
153 | static inline int dma_set_mask(struct device *dev, u64 mask) | 168 | /* same for gart, swiotlb, and nommu */ |
169 | static inline int dma_get_cache_alignment(void) | ||
154 | { | 170 | { |
155 | if (!dev->dma_mask || !dma_supported(dev, mask)) | 171 | return boot_cpu_data.x86_clflush_size; |
156 | return -EIO; | ||
157 | *dev->dma_mask = mask; | ||
158 | return 0; | ||
159 | } | 172 | } |
160 | 173 | ||
161 | static inline void dma_cache_sync(void *vaddr, size_t size, enum dma_data_direction dir) | 174 | #define dma_is_consistent(h) 1 |
175 | |||
176 | extern int dma_set_mask(struct device *dev, u64 mask); | ||
177 | |||
178 | static inline void | ||
179 | dma_cache_sync(void *vaddr, size_t size, enum dma_data_direction dir) | ||
162 | { | 180 | { |
163 | flush_write_buffers(); | 181 | flush_write_buffers(); |
164 | } | 182 | } |
165 | 183 | ||
166 | #endif | 184 | extern struct device fallback_dev; |
185 | extern int panic_on_overflow; | ||
186 | |||
187 | #endif /* _X8664_DMA_MAPPING_H */ | ||