diff options
author | Tomasz Figa <tfiga@chromium.org> | 2016-02-01 16:34:42 -0500 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2016-02-11 10:33:38 -0500 |
commit | ccc66e738252cede5c13e8d529b93b5a35b307c2 (patch) | |
tree | 9edac37e6cd7c014632076427dc2da92eee787b4 | |
parent | 14d3ae2efeed4ebcc6313fad61470803eb904126 (diff) |
ARM: 8508/2: videobuf2-dc: Let drivers specify DMA attrs
DMA allocations might be subject to certain requirements specific to the
hardware using the buffers, such as availability of kernel mapping (for
contents fix-ups in the driver). The only entity that knows them is the
driver, so it must share this knowledge with vb2-dc.
This patch extends the alloc_ctx initialization interface to let the
driver specify DMA attrs, which are then stored inside the allocation
context and will be used for all allocations with that context.
As a side effect, all dma_*_coherent() calls are turned into
dma_*_attrs() calls, because the attributes need to be carried over
through all DMA operations.
Signed-off-by: Tomasz Figa <tfiga@chromium.org>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Tested-by: Javier Martinez Canillas <javier@osg.samsung.com>
Acked-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
-rw-r--r-- | drivers/media/v4l2-core/videobuf2-dma-contig.c | 33 | ||||
-rw-r--r-- | include/media/videobuf2-dma-contig.h | 11 |
2 files changed, 32 insertions, 12 deletions
diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c b/drivers/media/v4l2-core/videobuf2-dma-contig.c index c33127284cfe..5361197f3e57 100644 --- a/drivers/media/v4l2-core/videobuf2-dma-contig.c +++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c | |||
@@ -23,13 +23,16 @@ | |||
23 | 23 | ||
24 | struct vb2_dc_conf { | 24 | struct vb2_dc_conf { |
25 | struct device *dev; | 25 | struct device *dev; |
26 | struct dma_attrs attrs; | ||
26 | }; | 27 | }; |
27 | 28 | ||
28 | struct vb2_dc_buf { | 29 | struct vb2_dc_buf { |
29 | struct device *dev; | 30 | struct device *dev; |
30 | void *vaddr; | 31 | void *vaddr; |
31 | unsigned long size; | 32 | unsigned long size; |
33 | void *cookie; | ||
32 | dma_addr_t dma_addr; | 34 | dma_addr_t dma_addr; |
35 | struct dma_attrs attrs; | ||
33 | enum dma_data_direction dma_dir; | 36 | enum dma_data_direction dma_dir; |
34 | struct sg_table *dma_sgt; | 37 | struct sg_table *dma_sgt; |
35 | struct frame_vector *vec; | 38 | struct frame_vector *vec; |
@@ -131,7 +134,8 @@ static void vb2_dc_put(void *buf_priv) | |||
131 | sg_free_table(buf->sgt_base); | 134 | sg_free_table(buf->sgt_base); |
132 | kfree(buf->sgt_base); | 135 | kfree(buf->sgt_base); |
133 | } | 136 | } |
134 | dma_free_coherent(buf->dev, buf->size, buf->vaddr, buf->dma_addr); | 137 | dma_free_attrs(buf->dev, buf->size, buf->cookie, buf->dma_addr, |
138 | &buf->attrs); | ||
135 | put_device(buf->dev); | 139 | put_device(buf->dev); |
136 | kfree(buf); | 140 | kfree(buf); |
137 | } | 141 | } |
@@ -147,14 +151,18 @@ static void *vb2_dc_alloc(void *alloc_ctx, unsigned long size, | |||
147 | if (!buf) | 151 | if (!buf) |
148 | return ERR_PTR(-ENOMEM); | 152 | return ERR_PTR(-ENOMEM); |
149 | 153 | ||
150 | buf->vaddr = dma_alloc_coherent(dev, size, &buf->dma_addr, | 154 | buf->attrs = conf->attrs; |
151 | GFP_KERNEL | gfp_flags); | 155 | buf->cookie = dma_alloc_attrs(dev, size, &buf->dma_addr, |
152 | if (!buf->vaddr) { | 156 | GFP_KERNEL | gfp_flags, &buf->attrs); |
157 | if (!buf->cookie) { | ||
153 | dev_err(dev, "dma_alloc_coherent of size %ld failed\n", size); | 158 | dev_err(dev, "dma_alloc_coherent of size %ld failed\n", size); |
154 | kfree(buf); | 159 | kfree(buf); |
155 | return ERR_PTR(-ENOMEM); | 160 | return ERR_PTR(-ENOMEM); |
156 | } | 161 | } |
157 | 162 | ||
163 | if (!dma_get_attr(DMA_ATTR_NO_KERNEL_MAPPING, &buf->attrs)) | ||
164 | buf->vaddr = buf->cookie; | ||
165 | |||
158 | /* Prevent the device from being released while the buffer is used */ | 166 | /* Prevent the device from being released while the buffer is used */ |
159 | buf->dev = get_device(dev); | 167 | buf->dev = get_device(dev); |
160 | buf->size = size; | 168 | buf->size = size; |
@@ -185,8 +193,8 @@ static int vb2_dc_mmap(void *buf_priv, struct vm_area_struct *vma) | |||
185 | */ | 193 | */ |
186 | vma->vm_pgoff = 0; | 194 | vma->vm_pgoff = 0; |
187 | 195 | ||
188 | ret = dma_mmap_coherent(buf->dev, vma, buf->vaddr, | 196 | ret = dma_mmap_attrs(buf->dev, vma, buf->cookie, |
189 | buf->dma_addr, buf->size); | 197 | buf->dma_addr, buf->size, &buf->attrs); |
190 | 198 | ||
191 | if (ret) { | 199 | if (ret) { |
192 | pr_err("Remapping memory failed, error: %d\n", ret); | 200 | pr_err("Remapping memory failed, error: %d\n", ret); |
@@ -329,7 +337,7 @@ static void *vb2_dc_dmabuf_ops_kmap(struct dma_buf *dbuf, unsigned long pgnum) | |||
329 | { | 337 | { |
330 | struct vb2_dc_buf *buf = dbuf->priv; | 338 | struct vb2_dc_buf *buf = dbuf->priv; |
331 | 339 | ||
332 | return buf->vaddr + pgnum * PAGE_SIZE; | 340 | return buf->vaddr ? buf->vaddr + pgnum * PAGE_SIZE : NULL; |
333 | } | 341 | } |
334 | 342 | ||
335 | static void *vb2_dc_dmabuf_ops_vmap(struct dma_buf *dbuf) | 343 | static void *vb2_dc_dmabuf_ops_vmap(struct dma_buf *dbuf) |
@@ -368,8 +376,8 @@ static struct sg_table *vb2_dc_get_base_sgt(struct vb2_dc_buf *buf) | |||
368 | return NULL; | 376 | return NULL; |
369 | } | 377 | } |
370 | 378 | ||
371 | ret = dma_get_sgtable(buf->dev, sgt, buf->vaddr, buf->dma_addr, | 379 | ret = dma_get_sgtable_attrs(buf->dev, sgt, buf->cookie, buf->dma_addr, |
372 | buf->size); | 380 | buf->size, &buf->attrs); |
373 | if (ret < 0) { | 381 | if (ret < 0) { |
374 | dev_err(buf->dev, "failed to get scatterlist from DMA API\n"); | 382 | dev_err(buf->dev, "failed to get scatterlist from DMA API\n"); |
375 | kfree(sgt); | 383 | kfree(sgt); |
@@ -721,7 +729,8 @@ const struct vb2_mem_ops vb2_dma_contig_memops = { | |||
721 | }; | 729 | }; |
722 | EXPORT_SYMBOL_GPL(vb2_dma_contig_memops); | 730 | EXPORT_SYMBOL_GPL(vb2_dma_contig_memops); |
723 | 731 | ||
724 | void *vb2_dma_contig_init_ctx(struct device *dev) | 732 | void *vb2_dma_contig_init_ctx_attrs(struct device *dev, |
733 | struct dma_attrs *attrs) | ||
725 | { | 734 | { |
726 | struct vb2_dc_conf *conf; | 735 | struct vb2_dc_conf *conf; |
727 | 736 | ||
@@ -730,10 +739,12 @@ void *vb2_dma_contig_init_ctx(struct device *dev) | |||
730 | return ERR_PTR(-ENOMEM); | 739 | return ERR_PTR(-ENOMEM); |
731 | 740 | ||
732 | conf->dev = dev; | 741 | conf->dev = dev; |
742 | if (attrs) | ||
743 | conf->attrs = *attrs; | ||
733 | 744 | ||
734 | return conf; | 745 | return conf; |
735 | } | 746 | } |
736 | EXPORT_SYMBOL_GPL(vb2_dma_contig_init_ctx); | 747 | EXPORT_SYMBOL_GPL(vb2_dma_contig_init_ctx_attrs); |
737 | 748 | ||
738 | void vb2_dma_contig_cleanup_ctx(void *alloc_ctx) | 749 | void vb2_dma_contig_cleanup_ctx(void *alloc_ctx) |
739 | { | 750 | { |
diff --git a/include/media/videobuf2-dma-contig.h b/include/media/videobuf2-dma-contig.h index c33dfa69d7ab..2087c9a68be3 100644 --- a/include/media/videobuf2-dma-contig.h +++ b/include/media/videobuf2-dma-contig.h | |||
@@ -16,6 +16,8 @@ | |||
16 | #include <media/videobuf2-v4l2.h> | 16 | #include <media/videobuf2-v4l2.h> |
17 | #include <linux/dma-mapping.h> | 17 | #include <linux/dma-mapping.h> |
18 | 18 | ||
19 | struct dma_attrs; | ||
20 | |||
19 | static inline dma_addr_t | 21 | static inline dma_addr_t |
20 | vb2_dma_contig_plane_dma_addr(struct vb2_buffer *vb, unsigned int plane_no) | 22 | vb2_dma_contig_plane_dma_addr(struct vb2_buffer *vb, unsigned int plane_no) |
21 | { | 23 | { |
@@ -24,7 +26,14 @@ vb2_dma_contig_plane_dma_addr(struct vb2_buffer *vb, unsigned int plane_no) | |||
24 | return *addr; | 26 | return *addr; |
25 | } | 27 | } |
26 | 28 | ||
27 | void *vb2_dma_contig_init_ctx(struct device *dev); | 29 | void *vb2_dma_contig_init_ctx_attrs(struct device *dev, |
30 | struct dma_attrs *attrs); | ||
31 | |||
32 | static inline void *vb2_dma_contig_init_ctx(struct device *dev) | ||
33 | { | ||
34 | return vb2_dma_contig_init_ctx_attrs(dev, NULL); | ||
35 | } | ||
36 | |||
28 | void vb2_dma_contig_cleanup_ctx(void *alloc_ctx); | 37 | void vb2_dma_contig_cleanup_ctx(void *alloc_ctx); |
29 | 38 | ||
30 | extern const struct vb2_mem_ops vb2_dma_contig_memops; | 39 | extern const struct vb2_mem_ops vb2_dma_contig_memops; |