Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Tomasz Figa and committed by
Russell King
ccc66e73 14d3ae2e

+32 -12
+22 -11
drivers/media/v4l2-core/videobuf2-dma-contig.c
··· 23 23 24 24 struct vb2_dc_conf { 25 25 struct device *dev; 26 + struct dma_attrs attrs; 26 27 }; 27 28 28 29 struct vb2_dc_buf { 29 30 struct device *dev; 30 31 void *vaddr; 31 32 unsigned long size; 33 + void *cookie; 32 34 dma_addr_t dma_addr; 35 + struct dma_attrs attrs; 33 36 enum dma_data_direction dma_dir; 34 37 struct sg_table *dma_sgt; 35 38 struct frame_vector *vec; ··· 134 131 sg_free_table(buf->sgt_base); 135 132 kfree(buf->sgt_base); 136 133 } 137 - dma_free_coherent(buf->dev, buf->size, buf->vaddr, buf->dma_addr); 134 + dma_free_attrs(buf->dev, buf->size, buf->cookie, buf->dma_addr, 135 + &buf->attrs); 138 136 put_device(buf->dev); 139 137 kfree(buf); 140 138 } ··· 151 147 if (!buf) 152 148 return ERR_PTR(-ENOMEM); 153 149 154 - buf->vaddr = dma_alloc_coherent(dev, size, &buf->dma_addr, 155 - GFP_KERNEL | gfp_flags); 156 - if (!buf->vaddr) { 150 + buf->attrs = conf->attrs; 151 + buf->cookie = dma_alloc_attrs(dev, size, &buf->dma_addr, 152 + GFP_KERNEL | gfp_flags, &buf->attrs); 153 + if (!buf->cookie) { 157 154 dev_err(dev, "dma_alloc_coherent of size %ld failed\n", size); 158 155 kfree(buf); 159 156 return ERR_PTR(-ENOMEM); 160 157 } 158 + 159 + if (!dma_get_attr(DMA_ATTR_NO_KERNEL_MAPPING, &buf->attrs)) 160 + buf->vaddr = buf->cookie; 161 161 162 162 /* Prevent the device from being released while the buffer is used */ 163 163 buf->dev = get_device(dev); ··· 193 185 */ 194 186 vma->vm_pgoff = 0; 195 187 196 - ret = dma_mmap_coherent(buf->dev, vma, buf->vaddr, 197 - buf->dma_addr, buf->size); 188 + ret = dma_mmap_attrs(buf->dev, vma, buf->cookie, 189 + buf->dma_addr, buf->size, &buf->attrs); 198 190 199 191 if (ret) { 200 192 pr_err("Remapping memory failed, error: %d\n", ret); ··· 337 329 { 338 330 struct vb2_dc_buf *buf = dbuf->priv; 339 331 340 - return buf->vaddr + pgnum * PAGE_SIZE; 332 + return buf->vaddr ? buf->vaddr + pgnum * PAGE_SIZE : NULL; 341 333 } 342 334 343 335 static void *vb2_dc_dmabuf_ops_vmap(struct dma_buf *dbuf) ··· 376 368 return NULL; 377 369 } 378 370 379 - ret = dma_get_sgtable(buf->dev, sgt, buf->vaddr, buf->dma_addr, 380 - buf->size); 371 + ret = dma_get_sgtable_attrs(buf->dev, sgt, buf->cookie, buf->dma_addr, 372 + buf->size, &buf->attrs); 381 373 if (ret < 0) { 382 374 dev_err(buf->dev, "failed to get scatterlist from DMA API\n"); 383 375 kfree(sgt); ··· 729 721 }; 730 722 EXPORT_SYMBOL_GPL(vb2_dma_contig_memops); 731 723 732 - void *vb2_dma_contig_init_ctx(struct device *dev) 724 + void *vb2_dma_contig_init_ctx_attrs(struct device *dev, 725 + struct dma_attrs *attrs) 733 726 { 734 727 struct vb2_dc_conf *conf; 735 728 ··· 739 730 return ERR_PTR(-ENOMEM); 740 731 741 732 conf->dev = dev; 733 + if (attrs) 734 + conf->attrs = *attrs; 742 735 743 736 return conf; 744 737 } 745 - EXPORT_SYMBOL_GPL(vb2_dma_contig_init_ctx); 738 + EXPORT_SYMBOL_GPL(vb2_dma_contig_init_ctx_attrs); 746 739 747 740 void vb2_dma_contig_cleanup_ctx(void *alloc_ctx) 748 741 {
+10 -1
include/media/videobuf2-dma-contig.h
··· 16 16 #include <media/videobuf2-v4l2.h> 17 17 #include <linux/dma-mapping.h> 18 18 19 + struct dma_attrs; 20 + 19 21 static inline dma_addr_t 20 22 vb2_dma_contig_plane_dma_addr(struct vb2_buffer *vb, unsigned int plane_no) 21 23 { ··· 26 24 return *addr; 27 25 } 28 26 29 - void *vb2_dma_contig_init_ctx(struct device *dev); 27 + void *vb2_dma_contig_init_ctx_attrs(struct device *dev, 28 + struct dma_attrs *attrs); 29 + 30 + static inline void *vb2_dma_contig_init_ctx(struct device *dev) 31 + { 32 + return vb2_dma_contig_init_ctx_attrs(dev, NULL); 33 + } 34 + 30 35 void vb2_dma_contig_cleanup_ctx(void *alloc_ctx); 31 36 32 37 extern const struct vb2_mem_ops vb2_dma_contig_memops;