Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _ASM_SPARC64_DMA_MAPPING_H |
| 2 | #define _ASM_SPARC64_DMA_MAPPING_H |
| 3 | |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 4 | #include <linux/scatterlist.h> |
David S. Miller | 42f1423 | 2006-05-23 02:07:22 -0700 | [diff] [blame] | 5 | #include <linux/mm.h> |
| 6 | |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 7 | #define DMA_ERROR_CODE (~(dma_addr_t)0x0) |
David S. Miller | 9ac6d4a | 2007-05-14 02:56:03 -0700 | [diff] [blame] | 8 | |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 9 | struct dma_ops { |
| 10 | void *(*alloc_coherent)(struct device *dev, size_t size, |
| 11 | dma_addr_t *dma_handle, gfp_t flag); |
| 12 | void (*free_coherent)(struct device *dev, size_t size, |
| 13 | void *cpu_addr, dma_addr_t dma_handle); |
| 14 | dma_addr_t (*map_single)(struct device *dev, void *cpu_addr, |
| 15 | size_t size, |
| 16 | enum dma_data_direction direction); |
| 17 | void (*unmap_single)(struct device *dev, dma_addr_t dma_addr, |
| 18 | size_t size, |
| 19 | enum dma_data_direction direction); |
| 20 | int (*map_sg)(struct device *dev, struct scatterlist *sg, int nents, |
| 21 | enum dma_data_direction direction); |
| 22 | void (*unmap_sg)(struct device *dev, struct scatterlist *sg, |
| 23 | int nhwentries, |
| 24 | enum dma_data_direction direction); |
| 25 | void (*sync_single_for_cpu)(struct device *dev, |
| 26 | dma_addr_t dma_handle, size_t size, |
| 27 | enum dma_data_direction direction); |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 28 | void (*sync_sg_for_cpu)(struct device *dev, struct scatterlist *sg, |
| 29 | int nelems, |
| 30 | enum dma_data_direction direction); |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 31 | }; |
| 32 | extern const struct dma_ops *dma_ops; |
David S. Miller | 42f1423 | 2006-05-23 02:07:22 -0700 | [diff] [blame] | 33 | |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 34 | extern int dma_supported(struct device *dev, u64 mask); |
| 35 | extern int dma_set_mask(struct device *dev, u64 dma_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | static inline void *dma_alloc_coherent(struct device *dev, size_t size, |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 38 | dma_addr_t *dma_handle, gfp_t flag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | { |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 40 | return dma_ops->alloc_coherent(dev, size, dma_handle, flag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | static inline void dma_free_coherent(struct device *dev, size_t size, |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 44 | void *cpu_addr, dma_addr_t dma_handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | { |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 46 | dma_ops->free_coherent(dev, size, cpu_addr, dma_handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | } |
| 48 | |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 49 | static inline dma_addr_t dma_map_single(struct device *dev, void *cpu_addr, |
| 50 | size_t size, |
| 51 | enum dma_data_direction direction) |
David S. Miller | f04dbac | 2007-06-04 23:32:23 -0700 | [diff] [blame] | 52 | { |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 53 | return dma_ops->map_single(dev, cpu_addr, size, direction); |
David S. Miller | f04dbac | 2007-06-04 23:32:23 -0700 | [diff] [blame] | 54 | } |
| 55 | |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 56 | static inline void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, |
| 57 | size_t size, |
| 58 | enum dma_data_direction direction) |
David S. Miller | f04dbac | 2007-06-04 23:32:23 -0700 | [diff] [blame] | 59 | { |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 60 | dma_ops->unmap_single(dev, dma_addr, size, direction); |
David S. Miller | f04dbac | 2007-06-04 23:32:23 -0700 | [diff] [blame] | 61 | } |
| 62 | |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 63 | static inline dma_addr_t dma_map_page(struct device *dev, struct page *page, |
| 64 | unsigned long offset, size_t size, |
| 65 | enum dma_data_direction direction) |
David S. Miller | f04dbac | 2007-06-04 23:32:23 -0700 | [diff] [blame] | 66 | { |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 67 | return dma_ops->map_single(dev, page_address(page) + offset, |
| 68 | size, direction); |
David S. Miller | f04dbac | 2007-06-04 23:32:23 -0700 | [diff] [blame] | 69 | } |
| 70 | |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 71 | static inline void dma_unmap_page(struct device *dev, dma_addr_t dma_address, |
| 72 | size_t size, |
| 73 | enum dma_data_direction direction) |
David S. Miller | f04dbac | 2007-06-04 23:32:23 -0700 | [diff] [blame] | 74 | { |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 75 | dma_ops->unmap_single(dev, dma_address, size, direction); |
David S. Miller | f04dbac | 2007-06-04 23:32:23 -0700 | [diff] [blame] | 76 | } |
| 77 | |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 78 | static inline int dma_map_sg(struct device *dev, struct scatterlist *sg, |
| 79 | int nents, enum dma_data_direction direction) |
David S. Miller | f04dbac | 2007-06-04 23:32:23 -0700 | [diff] [blame] | 80 | { |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 81 | return dma_ops->map_sg(dev, sg, nents, direction); |
David S. Miller | f04dbac | 2007-06-04 23:32:23 -0700 | [diff] [blame] | 82 | } |
| 83 | |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 84 | static inline void dma_unmap_sg(struct device *dev, struct scatterlist *sg, |
| 85 | int nents, enum dma_data_direction direction) |
David S. Miller | f04dbac | 2007-06-04 23:32:23 -0700 | [diff] [blame] | 86 | { |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 87 | dma_ops->unmap_sg(dev, sg, nents, direction); |
David S. Miller | f04dbac | 2007-06-04 23:32:23 -0700 | [diff] [blame] | 88 | } |
| 89 | |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 90 | static inline void dma_sync_single_for_cpu(struct device *dev, |
| 91 | dma_addr_t dma_handle, size_t size, |
| 92 | enum dma_data_direction direction) |
Randy Dunlap | 7233589 | 2006-07-05 20:18:39 -0700 | [diff] [blame] | 93 | { |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 94 | dma_ops->sync_single_for_cpu(dev, dma_handle, size, direction); |
Randy Dunlap | 7233589 | 2006-07-05 20:18:39 -0700 | [diff] [blame] | 95 | } |
| 96 | |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 97 | static inline void dma_sync_single_for_device(struct device *dev, |
| 98 | dma_addr_t dma_handle, |
| 99 | size_t size, |
| 100 | enum dma_data_direction direction) |
Randy Dunlap | 7233589 | 2006-07-05 20:18:39 -0700 | [diff] [blame] | 101 | { |
David S. Miller | 36bb613 | 2007-12-20 01:29:45 -0800 | [diff] [blame^] | 102 | /* No flushing needed to sync cpu writes to the device. */ |
Randy Dunlap | 7233589 | 2006-07-05 20:18:39 -0700 | [diff] [blame] | 103 | } |
| 104 | |
David S. Miller | 6321319 | 2007-07-31 20:43:17 -0700 | [diff] [blame] | 105 | static inline void dma_sync_single_range_for_cpu(struct device *dev, |
| 106 | dma_addr_t dma_handle, |
| 107 | unsigned long offset, |
| 108 | size_t size, |
| 109 | enum dma_data_direction direction) |
| 110 | { |
| 111 | dma_sync_single_for_cpu(dev, dma_handle+offset, size, direction); |
| 112 | } |
| 113 | |
| 114 | static inline void dma_sync_single_range_for_device(struct device *dev, |
| 115 | dma_addr_t dma_handle, |
| 116 | unsigned long offset, |
| 117 | size_t size, |
| 118 | enum dma_data_direction direction) |
| 119 | { |
David S. Miller | 36bb613 | 2007-12-20 01:29:45 -0800 | [diff] [blame^] | 120 | /* No flushing needed to sync cpu writes to the device. */ |
David S. Miller | 6321319 | 2007-07-31 20:43:17 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 124 | static inline void dma_sync_sg_for_cpu(struct device *dev, |
| 125 | struct scatterlist *sg, int nelems, |
| 126 | enum dma_data_direction direction) |
David S. Miller | f04dbac | 2007-06-04 23:32:23 -0700 | [diff] [blame] | 127 | { |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 128 | dma_ops->sync_sg_for_cpu(dev, sg, nelems, direction); |
David S. Miller | f04dbac | 2007-06-04 23:32:23 -0700 | [diff] [blame] | 129 | } |
| 130 | |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 131 | static inline void dma_sync_sg_for_device(struct device *dev, |
| 132 | struct scatterlist *sg, int nelems, |
| 133 | enum dma_data_direction direction) |
David S. Miller | f04dbac | 2007-06-04 23:32:23 -0700 | [diff] [blame] | 134 | { |
David S. Miller | 36bb613 | 2007-12-20 01:29:45 -0800 | [diff] [blame^] | 135 | /* No flushing needed to sync cpu writes to the device. */ |
David S. Miller | f04dbac | 2007-06-04 23:32:23 -0700 | [diff] [blame] | 136 | } |
| 137 | |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 138 | static inline int dma_mapping_error(dma_addr_t dma_addr) |
David S. Miller | f04dbac | 2007-06-04 23:32:23 -0700 | [diff] [blame] | 139 | { |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 140 | return (dma_addr == DMA_ERROR_CODE); |
David S. Miller | f04dbac | 2007-06-04 23:32:23 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Andrew Morton | e5071b5 | 2007-07-31 01:28:33 -0700 | [diff] [blame] | 143 | static inline int dma_get_cache_alignment(void) |
| 144 | { |
| 145 | /* no easy way to get cache size on all processors, so return |
| 146 | * the maximum possible, to be safe */ |
| 147 | return (1 << INTERNODE_CACHE_SHIFT); |
| 148 | } |
| 149 | |
David S. Miller | 3632142 | 2006-06-25 02:07:52 -0700 | [diff] [blame] | 150 | #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) |
| 151 | #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) |
Ralf Baechle | f67637e | 2006-12-06 20:38:54 -0800 | [diff] [blame] | 152 | #define dma_is_consistent(d, h) (1) |
David S. Miller | 3632142 | 2006-06-25 02:07:52 -0700 | [diff] [blame] | 153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | #endif /* _ASM_SPARC64_DMA_MAPPING_H */ |