Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Jens Axboe | 46856af | 2007-05-10 11:59:55 +0200 | [diff] [blame] | 9 | #include <linux/scatterlist.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <asm/io.h> |
| 11 | #include <asm/swiotlb.h> |
| 12 | |
Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 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; |
| 51 | }; |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | extern dma_addr_t bad_dma_address; |
Stephen Hemminger | e658450 | 2007-05-02 19:27:06 +0200 | [diff] [blame] | 54 | extern const struct dma_mapping_ops* dma_ops; |
Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 55 | extern int iommu_merge; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 57 | static inline int dma_mapping_error(dma_addr_t dma_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | { |
Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 59 | if (dma_ops->mapping_error) |
| 60 | return dma_ops->mapping_error(dma_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 62 | return (dma_addr == bad_dma_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Jeff Garzik | 259886a7 | 2007-02-03 01:14:03 -0800 | [diff] [blame] | 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) |
| 67 | |
Jeff Garzik | 2fa8a05 | 2007-02-13 13:26:24 +0100 | [diff] [blame] | 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) |
| 70 | |
Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 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); |
| 75 | |
| 76 | static inline dma_addr_t |
| 77 | dma_map_single(struct device *hwdev, void *ptr, size_t size, |
| 78 | int direction) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | { |
Jon Mason | a3c042a | 2006-06-26 13:58:08 +0200 | [diff] [blame] | 80 | BUG_ON(!valid_dma_direction(direction)); |
Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 81 | return dma_ops->map_single(hwdev, ptr, size, direction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 84 | static inline void |
| 85 | dma_unmap_single(struct device *dev, dma_addr_t addr,size_t size, |
| 86 | int direction) |
| 87 | { |
Jon Mason | a3c042a | 2006-06-26 13:58:08 +0200 | [diff] [blame] | 88 | BUG_ON(!valid_dma_direction(direction)); |
Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 89 | dma_ops->unmap_single(dev, addr, size, direction); |
| 90 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
| 92 | #define dma_map_page(dev,page,offset,size,dir) \ |
| 93 | dma_map_single((dev), page_address(page)+(offset), (size), (dir)) |
| 94 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | #define dma_unmap_page dma_unmap_single |
| 96 | |
Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 97 | static inline void |
| 98 | dma_sync_single_for_cpu(struct device *hwdev, dma_addr_t dma_handle, |
| 99 | size_t size, int direction) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | { |
Jon Mason | a3c042a | 2006-06-26 13:58:08 +0200 | [diff] [blame] | 101 | BUG_ON(!valid_dma_direction(direction)); |
Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 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(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 108 | static inline void |
| 109 | dma_sync_single_for_device(struct device *hwdev, dma_addr_t dma_handle, |
| 110 | size_t size, int direction) |
| 111 | { |
Jon Mason | a3c042a | 2006-06-26 13:58:08 +0200 | [diff] [blame] | 112 | BUG_ON(!valid_dma_direction(direction)); |
Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 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(); |
| 117 | } |
| 118 | |
| 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) |
| 122 | { |
Jon Mason | a3c042a | 2006-06-26 13:58:08 +0200 | [diff] [blame] | 123 | BUG_ON(!valid_dma_direction(direction)); |
Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 124 | if (dma_ops->sync_single_range_for_cpu) { |
| 125 | dma_ops->sync_single_range_for_cpu(hwdev, dma_handle, offset, size, direction); |
| 126 | } |
| 127 | |
| 128 | flush_write_buffers(); |
| 129 | } |
| 130 | |
| 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) |
| 134 | { |
Jon Mason | a3c042a | 2006-06-26 13:58:08 +0200 | [diff] [blame] | 135 | BUG_ON(!valid_dma_direction(direction)); |
Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 136 | if (dma_ops->sync_single_range_for_device) |
| 137 | dma_ops->sync_single_range_for_device(hwdev, dma_handle, |
| 138 | offset, size, direction); |
| 139 | |
| 140 | flush_write_buffers(); |
| 141 | } |
| 142 | |
| 143 | static inline void |
| 144 | dma_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg, |
| 145 | int nelems, int direction) |
| 146 | { |
Jon Mason | a3c042a | 2006-06-26 13:58:08 +0200 | [diff] [blame] | 147 | BUG_ON(!valid_dma_direction(direction)); |
Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 148 | if (dma_ops->sync_sg_for_cpu) |
| 149 | dma_ops->sync_sg_for_cpu(hwdev, sg, nelems, direction); |
| 150 | flush_write_buffers(); |
| 151 | } |
| 152 | |
| 153 | static inline void |
| 154 | dma_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg, |
| 155 | int nelems, int direction) |
| 156 | { |
Jon Mason | a3c042a | 2006-06-26 13:58:08 +0200 | [diff] [blame] | 157 | BUG_ON(!valid_dma_direction(direction)); |
Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 158 | if (dma_ops->sync_sg_for_device) { |
| 159 | dma_ops->sync_sg_for_device(hwdev, sg, nelems, direction); |
| 160 | } |
| 161 | |
| 162 | flush_write_buffers(); |
| 163 | } |
| 164 | |
| 165 | static inline int |
| 166 | dma_map_sg(struct device *hwdev, struct scatterlist *sg, int nents, int direction) |
| 167 | { |
Jon Mason | a3c042a | 2006-06-26 13:58:08 +0200 | [diff] [blame] | 168 | BUG_ON(!valid_dma_direction(direction)); |
Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 169 | return dma_ops->map_sg(hwdev, sg, nents, direction); |
| 170 | } |
| 171 | |
| 172 | static inline void |
| 173 | dma_unmap_sg(struct device *hwdev, struct scatterlist *sg, int nents, |
| 174 | int direction) |
| 175 | { |
Jon Mason | a3c042a | 2006-06-26 13:58:08 +0200 | [diff] [blame] | 176 | BUG_ON(!valid_dma_direction(direction)); |
Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 177 | dma_ops->unmap_sg(hwdev, sg, nents, direction); |
| 178 | } |
| 179 | |
| 180 | extern int dma_supported(struct device *hwdev, u64 mask); |
| 181 | |
| 182 | /* same for gart, swiotlb, and nommu */ |
| 183 | static inline int dma_get_cache_alignment(void) |
| 184 | { |
| 185 | return boot_cpu_data.x86_clflush_size; |
| 186 | } |
| 187 | |
Ralf Baechle | f67637e | 2006-12-06 20:38:54 -0800 | [diff] [blame] | 188 | #define dma_is_consistent(d, h) 1 |
Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 189 | |
| 190 | extern int dma_set_mask(struct device *dev, u64 mask); |
| 191 | |
| 192 | static inline void |
Ralf Baechle | d3fa72e | 2006-12-06 20:38:56 -0800 | [diff] [blame] | 193 | dma_cache_sync(struct device *dev, void *vaddr, size_t size, |
| 194 | enum dma_data_direction dir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | { |
| 196 | flush_write_buffers(); |
| 197 | } |
| 198 | |
Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 199 | extern struct device fallback_dev; |
| 200 | extern int panic_on_overflow; |
| 201 | |
| 202 | #endif /* _X8664_DMA_MAPPING_H */ |