Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <asm/machvec.h> |
Jens Axboe | 9b6eccf | 2007-10-16 11:27:26 +0200 | [diff] [blame] | 9 | #include <linux/scatterlist.h> |
Fenghua Yu | 62fdd76 | 2008-10-17 12:14:13 -0700 | [diff] [blame] | 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); |
FUJITA Tomonori | e751ab3 | 2009-01-05 23:36:06 +0900 | [diff] [blame] | 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); |
Fenghua Yu | 62fdd76 | 2008-10-17 12:14:13 -0700 | [diff] [blame] | 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); |
FUJITA Tomonori | e751ab3 | 2009-01-05 23:36:06 +0900 | [diff] [blame] | 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); |
Fenghua Yu | 62fdd76 | 2008-10-17 12:14:13 -0700 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
FUJITA Tomonori | b7ea6e9 | 2009-01-05 23:36:13 +0900 | [diff] [blame] | 68 | static inline void *dma_alloc_coherent(struct device *dev, size_t size, |
| 69 | dma_addr_t *daddr, gfp_t gfp) |
| 70 | { |
FUJITA Tomonori | c190ab0 | 2009-01-05 23:36:16 +0900 | [diff] [blame^] | 71 | struct dma_mapping_ops *ops = platform_dma_get_ops(dev); |
| 72 | return ops->alloc_coherent(dev, size, daddr, gfp | GFP_DMA); |
FUJITA Tomonori | b7ea6e9 | 2009-01-05 23:36:13 +0900 | [diff] [blame] | 73 | } |
FUJITA Tomonori | 3a80b6a | 2008-09-08 18:10:10 +0900 | [diff] [blame] | 74 | |
FUJITA Tomonori | b7ea6e9 | 2009-01-05 23:36:13 +0900 | [diff] [blame] | 75 | static inline void dma_free_coherent(struct device *dev, size_t size, |
| 76 | void *caddr, dma_addr_t daddr) |
Roland Dreier | b7de8e7 | 2007-02-14 00:32:53 -0800 | [diff] [blame] | 77 | { |
FUJITA Tomonori | c190ab0 | 2009-01-05 23:36:16 +0900 | [diff] [blame^] | 78 | struct dma_mapping_ops *ops = platform_dma_get_ops(dev); |
| 79 | ops->free_coherent(dev, size, caddr, daddr); |
Roland Dreier | b7de8e7 | 2007-02-14 00:32:53 -0800 | [diff] [blame] | 80 | } |
FUJITA Tomonori | b7ea6e9 | 2009-01-05 23:36:13 +0900 | [diff] [blame] | 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) |
Roland Dreier | b7de8e7 | 2007-02-14 00:32:53 -0800 | [diff] [blame] | 89 | { |
FUJITA Tomonori | c190ab0 | 2009-01-05 23:36:16 +0900 | [diff] [blame^] | 90 | struct dma_mapping_ops *ops = platform_dma_get_ops(dev); |
| 91 | return ops->map_single_attrs(dev, caddr, size, dir, attrs); |
Roland Dreier | b7de8e7 | 2007-02-14 00:32:53 -0800 | [diff] [blame] | 92 | } |
FUJITA Tomonori | b7ea6e9 | 2009-01-05 23:36:13 +0900 | [diff] [blame] | 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) |
Arthur Kepner | 309df0c | 2008-04-29 01:00:32 -0700 | [diff] [blame] | 98 | { |
FUJITA Tomonori | c190ab0 | 2009-01-05 23:36:16 +0900 | [diff] [blame^] | 99 | struct dma_mapping_ops *ops = platform_dma_get_ops(dev); |
| 100 | ops->unmap_single_attrs(dev, daddr, size, dir, attrs); |
Arthur Kepner | 309df0c | 2008-04-29 01:00:32 -0700 | [diff] [blame] | 101 | } |
FUJITA Tomonori | b7ea6e9 | 2009-01-05 23:36:13 +0900 | [diff] [blame] | 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) |
Arthur Kepner | 309df0c | 2008-04-29 01:00:32 -0700 | [diff] [blame] | 109 | { |
FUJITA Tomonori | c190ab0 | 2009-01-05 23:36:16 +0900 | [diff] [blame^] | 110 | struct dma_mapping_ops *ops = platform_dma_get_ops(dev); |
| 111 | return ops->map_sg_attrs(dev, sgl, nents, dir, attrs); |
Arthur Kepner | 309df0c | 2008-04-29 01:00:32 -0700 | [diff] [blame] | 112 | } |
FUJITA Tomonori | b7ea6e9 | 2009-01-05 23:36:13 +0900 | [diff] [blame] | 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) |
Arthur Kepner | 309df0c | 2008-04-29 01:00:32 -0700 | [diff] [blame] | 118 | { |
FUJITA Tomonori | c190ab0 | 2009-01-05 23:36:16 +0900 | [diff] [blame^] | 119 | struct dma_mapping_ops *ops = platform_dma_get_ops(dev); |
| 120 | ops->unmap_sg_attrs(dev, sgl, nents, dir, attrs); |
Arthur Kepner | 309df0c | 2008-04-29 01:00:32 -0700 | [diff] [blame] | 121 | } |
FUJITA Tomonori | b7ea6e9 | 2009-01-05 23:36:13 +0900 | [diff] [blame] | 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) |
Arthur Kepner | 309df0c | 2008-04-29 01:00:32 -0700 | [diff] [blame] | 129 | { |
FUJITA Tomonori | c190ab0 | 2009-01-05 23:36:16 +0900 | [diff] [blame^] | 130 | struct dma_mapping_ops *ops = platform_dma_get_ops(dev); |
| 131 | ops->sync_single_for_cpu(dev, daddr, size, dir); |
Arthur Kepner | 309df0c | 2008-04-29 01:00:32 -0700 | [diff] [blame] | 132 | } |
FUJITA Tomonori | b7ea6e9 | 2009-01-05 23:36:13 +0900 | [diff] [blame] | 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 | { |
FUJITA Tomonori | c190ab0 | 2009-01-05 23:36:16 +0900 | [diff] [blame^] | 138 | struct dma_mapping_ops *ops = platform_dma_get_ops(dev); |
| 139 | ops->sync_sg_for_cpu(dev, sgl, nents, dir); |
FUJITA Tomonori | b7ea6e9 | 2009-01-05 23:36:13 +0900 | [diff] [blame] | 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 | { |
FUJITA Tomonori | c190ab0 | 2009-01-05 23:36:16 +0900 | [diff] [blame^] | 147 | struct dma_mapping_ops *ops = platform_dma_get_ops(dev); |
| 148 | ops->sync_single_for_device(dev, daddr, size, dir); |
FUJITA Tomonori | b7ea6e9 | 2009-01-05 23:36:13 +0900 | [diff] [blame] | 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 | { |
FUJITA Tomonori | c190ab0 | 2009-01-05 23:36:16 +0900 | [diff] [blame^] | 156 | struct dma_mapping_ops *ops = platform_dma_get_ops(dev); |
| 157 | ops->sync_sg_for_device(dev, sgl, nents, dir); |
FUJITA Tomonori | b7ea6e9 | 2009-01-05 23:36:13 +0900 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | static inline int dma_mapping_error(struct device *dev, dma_addr_t daddr) |
| 161 | { |
FUJITA Tomonori | c190ab0 | 2009-01-05 23:36:16 +0900 | [diff] [blame^] | 162 | struct dma_mapping_ops *ops = platform_dma_get_ops(dev); |
| 163 | return ops->mapping_error(dev, daddr); |
FUJITA Tomonori | b7ea6e9 | 2009-01-05 23:36:13 +0900 | [diff] [blame] | 164 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
FUJITA Tomonori | b7ea6e9 | 2009-01-05 23:36:13 +0900 | [diff] [blame] | 181 | static inline int dma_supported(struct device *dev, u64 mask) |
| 182 | { |
FUJITA Tomonori | c190ab0 | 2009-01-05 23:36:16 +0900 | [diff] [blame^] | 183 | struct dma_mapping_ops *ops = platform_dma_get_ops(dev); |
| 184 | return ops->dma_supported_op(dev, mask); |
FUJITA Tomonori | b7ea6e9 | 2009-01-05 23:36:13 +0900 | [diff] [blame] | 185 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
John W. Linville | e1531b4 | 2005-11-07 00:57:54 -0800 | [diff] [blame] | 196 | extern int dma_get_cache_alignment(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
| 198 | static inline void |
Ralf Baechle | d3fa72e | 2006-12-06 20:38:56 -0800 | [diff] [blame] | 199 | dma_cache_sync (struct device *dev, void *vaddr, size_t size, |
| 200 | enum dma_data_direction dir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Ralf Baechle | f67637e | 2006-12-06 20:38:54 -0800 | [diff] [blame] | 209 | #define dma_is_consistent(d, h) (1) /* all we do is coherent memory... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | #endif /* _ASM_IA64_DMA_MAPPING_H */ |