diff options
| author | Marek Szyprowski <m.szyprowski@samsung.com> | 2012-05-16 12:31:23 -0400 |
|---|---|---|
| committer | Marek Szyprowski <m.szyprowski@samsung.com> | 2012-05-21 09:06:22 -0400 |
| commit | f99d60341238fe73fc514129cd9ae4e44e1b2c47 (patch) | |
| tree | 4e3214b9cdfbcddd9243f14161c77956eb3f5791 | |
| parent | 51fde3499b531d4cf278f4d2eaa6c45b2865b16b (diff) | |
ARM: dma-mapping: use alloc, mmap, free from dma_ops
This patch converts dma_alloc/free/mmap_{coherent,writecombine}
functions to use generic alloc/free/mmap methods from dma_map_ops
structure. A new DMA_ATTR_WRITE_COMBINE DMA attribute have been
introduced to implement writecombine methods.
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Tested-By: Subash Patel <subash.ramaswamy@linaro.org>
| -rw-r--r-- | arch/arm/common/dmabounce.c | 3 | ||||
| -rw-r--r-- | arch/arm/include/asm/dma-mapping.h | 107 | ||||
| -rw-r--r-- | arch/arm/mm/dma-mapping.c | 60 |
3 files changed, 104 insertions, 66 deletions
diff --git a/arch/arm/common/dmabounce.c b/arch/arm/common/dmabounce.c index 813c29dc6613..9d7eb530f95f 100644 --- a/arch/arm/common/dmabounce.c +++ b/arch/arm/common/dmabounce.c | |||
| @@ -449,6 +449,9 @@ static int dmabounce_set_mask(struct device *dev, u64 dma_mask) | |||
| 449 | } | 449 | } |
| 450 | 450 | ||
| 451 | static struct dma_map_ops dmabounce_ops = { | 451 | static struct dma_map_ops dmabounce_ops = { |
| 452 | .alloc = arm_dma_alloc, | ||
| 453 | .free = arm_dma_free, | ||
| 454 | .mmap = arm_dma_mmap, | ||
| 452 | .map_page = dmabounce_map_page, | 455 | .map_page = dmabounce_map_page, |
| 453 | .unmap_page = dmabounce_unmap_page, | 456 | .unmap_page = dmabounce_unmap_page, |
| 454 | .sync_single_for_cpu = dmabounce_sync_for_cpu, | 457 | .sync_single_for_cpu = dmabounce_sync_for_cpu, |
diff --git a/arch/arm/include/asm/dma-mapping.h b/arch/arm/include/asm/dma-mapping.h index 7a7c3c762f5f..bbef15d04890 100644 --- a/arch/arm/include/asm/dma-mapping.h +++ b/arch/arm/include/asm/dma-mapping.h | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | 5 | ||
| 6 | #include <linux/mm_types.h> | 6 | #include <linux/mm_types.h> |
| 7 | #include <linux/scatterlist.h> | 7 | #include <linux/scatterlist.h> |
| 8 | #include <linux/dma-attrs.h> | ||
| 8 | #include <linux/dma-debug.h> | 9 | #include <linux/dma-debug.h> |
| 9 | 10 | ||
| 10 | #include <asm-generic/dma-coherent.h> | 11 | #include <asm-generic/dma-coherent.h> |
| @@ -110,68 +111,115 @@ static inline void dma_free_noncoherent(struct device *dev, size_t size, | |||
| 110 | extern int dma_supported(struct device *dev, u64 mask); | 111 | extern int dma_supported(struct device *dev, u64 mask); |
| 111 | 112 | ||
| 112 | /** | 113 | /** |
| 113 | * dma_alloc_coherent - allocate consistent memory for DMA | 114 | * arm_dma_alloc - allocate consistent memory for DMA |
| 114 | * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices | 115 | * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices |
| 115 | * @size: required memory size | 116 | * @size: required memory size |
| 116 | * @handle: bus-specific DMA address | 117 | * @handle: bus-specific DMA address |
| 118 | * @attrs: optinal attributes that specific mapping properties | ||
| 117 | * | 119 | * |
| 118 | * Allocate some uncached, unbuffered memory for a device for | 120 | * Allocate some memory for a device for performing DMA. This function |
| 119 | * performing DMA. This function allocates pages, and will | 121 | * allocates pages, and will return the CPU-viewed address, and sets @handle |
| 120 | * return the CPU-viewed address, and sets @handle to be the | 122 | * to be the device-viewed address. |
| 121 | * device-viewed address. | ||
| 122 | */ | 123 | */ |
| 123 | extern void *dma_alloc_coherent(struct device *, size_t, dma_addr_t *, gfp_t); | 124 | extern void *arm_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, |
| 125 | gfp_t gfp, struct dma_attrs *attrs); | ||
| 126 | |||
| 127 | #define dma_alloc_coherent(d, s, h, f) dma_alloc_attrs(d, s, h, f, NULL) | ||
| 128 | |||
| 129 | static inline void *dma_alloc_attrs(struct device *dev, size_t size, | ||
| 130 | dma_addr_t *dma_handle, gfp_t flag, | ||
| 131 | struct dma_attrs *attrs) | ||
| 132 | { | ||
| 133 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
| 134 | void *cpu_addr; | ||
| 135 | BUG_ON(!ops); | ||
| 136 | |||
| 137 | cpu_addr = ops->alloc(dev, size, dma_handle, flag, attrs); | ||
| 138 | debug_dma_alloc_coherent(dev, size, *dma_handle, cpu_addr); | ||
| 139 | return cpu_addr; | ||
| 140 | } | ||
| 124 | 141 | ||
| 125 | /** | 142 | /** |
| 126 | * dma_free_coherent - free memory allocated by dma_alloc_coherent | 143 | * arm_dma_free - free memory allocated by arm_dma_alloc |
| 127 | * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices | 144 | * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices |
| 128 | * @size: size of memory originally requested in dma_alloc_coherent | 145 | * @size: size of memory originally requested in dma_alloc_coherent |
| 129 | * @cpu_addr: CPU-view address returned from dma_alloc_coherent | 146 | * @cpu_addr: CPU-view address returned from dma_alloc_coherent |
| 130 | * @handle: device-view address returned from dma_alloc_coherent | 147 | * @handle: device-view address returned from dma_alloc_coherent |
| 148 | * @attrs: optinal attributes that specific mapping properties | ||
| 131 | * | 149 | * |
| 132 | * Free (and unmap) a DMA buffer previously allocated by | 150 | * Free (and unmap) a DMA buffer previously allocated by |
| 133 | * dma_alloc_coherent(). | 151 | * arm_dma_alloc(). |
| 134 | * | 152 | * |
| 135 | * References to memory and mappings associated with cpu_addr/handle | 153 | * References to memory and mappings associated with cpu_addr/handle |
| 136 | * during and after this call executing are illegal. | 154 | * during and after this call executing are illegal. |
| 137 | */ | 155 | */ |
| 138 | extern void dma_free_coherent(struct device *, size_t, void *, dma_addr_t); | 156 | extern void arm_dma_free(struct device *dev, size_t size, void *cpu_addr, |
| 157 | dma_addr_t handle, struct dma_attrs *attrs); | ||
| 158 | |||
| 159 | #define dma_free_coherent(d, s, c, h) dma_free_attrs(d, s, c, h, NULL) | ||
| 160 | |||
| 161 | static inline void dma_free_attrs(struct device *dev, size_t size, | ||
| 162 | void *cpu_addr, dma_addr_t dma_handle, | ||
| 163 | struct dma_attrs *attrs) | ||
| 164 | { | ||
| 165 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
| 166 | BUG_ON(!ops); | ||
| 167 | |||
| 168 | debug_dma_free_coherent(dev, size, cpu_addr, dma_handle); | ||
| 169 | ops->free(dev, size, cpu_addr, dma_handle, attrs); | ||
| 170 | } | ||
| 139 | 171 | ||
| 140 | /** | 172 | /** |
| 141 | * dma_mmap_coherent - map a coherent DMA allocation into user space | 173 | * arm_dma_mmap - map a coherent DMA allocation into user space |
| 142 | * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices | 174 | * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices |
| 143 | * @vma: vm_area_struct describing requested user mapping | 175 | * @vma: vm_area_struct describing requested user mapping |
| 144 | * @cpu_addr: kernel CPU-view address returned from dma_alloc_coherent | 176 | * @cpu_addr: kernel CPU-view address returned from dma_alloc_coherent |
| 145 | * @handle: device-view address returned from dma_alloc_coherent | 177 | * @handle: device-view address returned from dma_alloc_coherent |
| 146 | * @size: size of memory originally requested in dma_alloc_coherent | 178 | * @size: size of memory originally requested in dma_alloc_coherent |
| 179 | * @attrs: optinal attributes that specific mapping properties | ||
| 147 | * | 180 | * |
| 148 | * Map a coherent DMA buffer previously allocated by dma_alloc_coherent | 181 | * Map a coherent DMA buffer previously allocated by dma_alloc_coherent |
| 149 | * into user space. The coherent DMA buffer must not be freed by the | 182 | * into user space. The coherent DMA buffer must not be freed by the |
| 150 | * driver until the user space mapping has been released. | 183 | * driver until the user space mapping has been released. |
| 151 | */ | 184 | */ |
| 152 | int dma_mmap_coherent(struct device *, struct vm_area_struct *, | 185 | extern int arm_dma_mmap(struct device *dev, struct vm_area_struct *vma, |
| 153 | void *, dma_addr_t, size_t); | 186 | void *cpu_addr, dma_addr_t dma_addr, size_t size, |
| 187 | struct dma_attrs *attrs); | ||
| 154 | 188 | ||
| 189 | #define dma_mmap_coherent(d, v, c, h, s) dma_mmap_attrs(d, v, c, h, s, NULL) | ||
| 155 | 190 | ||
| 156 | /** | 191 | static inline int dma_mmap_attrs(struct device *dev, struct vm_area_struct *vma, |
| 157 | * dma_alloc_writecombine - allocate writecombining memory for DMA | 192 | void *cpu_addr, dma_addr_t dma_addr, |
| 158 | * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices | 193 | size_t size, struct dma_attrs *attrs) |
| 159 | * @size: required memory size | 194 | { |
| 160 | * @handle: bus-specific DMA address | 195 | struct dma_map_ops *ops = get_dma_ops(dev); |
| 161 | * | 196 | BUG_ON(!ops); |
| 162 | * Allocate some uncached, buffered memory for a device for | 197 | return ops->mmap(dev, vma, cpu_addr, dma_addr, size, attrs); |
| 163 | * performing DMA. This function allocates pages, and will | 198 | } |
| 164 | * return the CPU-viewed address, and sets @handle to be the | ||
| 165 | * device-viewed address. | ||
| 166 | */ | ||
| 167 | extern void *dma_alloc_writecombine(struct device *, size_t, dma_addr_t *, | ||
| 168 | gfp_t); | ||
| 169 | 199 | ||
| 170 | #define dma_free_writecombine(dev,size,cpu_addr,handle) \ | 200 | static inline void *dma_alloc_writecombine(struct device *dev, size_t size, |
| 171 | dma_free_coherent(dev,size,cpu_addr,handle) | 201 | dma_addr_t *dma_handle, gfp_t flag) |
| 202 | { | ||
| 203 | DEFINE_DMA_ATTRS(attrs); | ||
| 204 | dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs); | ||
| 205 | return dma_alloc_attrs(dev, size, dma_handle, flag, &attrs); | ||
| 206 | } | ||
| 172 | 207 | ||
| 173 | int dma_mmap_writecombine(struct device *, struct vm_area_struct *, | 208 | static inline void dma_free_writecombine(struct device *dev, size_t size, |
| 174 | void *, dma_addr_t, size_t); | 209 | void *cpu_addr, dma_addr_t dma_handle) |
| 210 | { | ||
| 211 | DEFINE_DMA_ATTRS(attrs); | ||
| 212 | dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs); | ||
| 213 | return dma_free_attrs(dev, size, cpu_addr, dma_handle, &attrs); | ||
| 214 | } | ||
| 215 | |||
| 216 | static inline int dma_mmap_writecombine(struct device *dev, struct vm_area_struct *vma, | ||
| 217 | void *cpu_addr, dma_addr_t dma_addr, size_t size) | ||
| 218 | { | ||
| 219 | DEFINE_DMA_ATTRS(attrs); | ||
| 220 | dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs); | ||
| 221 | return dma_mmap_attrs(dev, vma, cpu_addr, dma_addr, size, &attrs); | ||
| 222 | } | ||
