Skip to content

Commit d4db5eb

Browse files
sergey-senozhatskymchehab
authored andcommitted
media: videobuf2: add begin/end cpu_access callbacks to dma-sg
Provide begin_cpu_access() and end_cpu_access() dma_buf_ops callbacks for cache synchronisation on exported buffers. V4L2_FLAG_MEMORY_NON_CONSISTENT has no effect on dma-sg buffers. dma-sg allocates memory using the page allocator directly, so there is no memory consistency guarantee. Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
1 parent d5adf1b commit d4db5eb

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

‎drivers/media/common/videobuf2/videobuf2-dma-sg.c‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ static void *vb2_dma_sg_alloc(struct device *dev, unsigned long dma_attrs,
120120
buf->num_pages = size >> PAGE_SHIFT;
121121
buf->dma_sgt = &buf->sg_table;
122122

123+
/*
124+
* NOTE: dma-sg allocates memory using the page allocator directly, so
125+
* there is no memory consistency guarantee, hence dma-sg ignores DMA
126+
* attributes passed from the upper layer. That means that
127+
* V4L2_FLAG_MEMORY_NON_CONSISTENT has no effect on dma-sg buffers.
128+
*/
123129
buf->pages = kvmalloc_array(buf->num_pages, sizeof(struct page *),
124130
GFP_KERNEL | __GFP_ZERO);
125131
if (!buf->pages)
@@ -469,6 +475,28 @@ static void vb2_dma_sg_dmabuf_ops_release(struct dma_buf *dbuf)
469475
vb2_dma_sg_put(dbuf->priv);
470476
}
471477

478+
static int
479+
vb2_dma_sg_dmabuf_ops_begin_cpu_access(struct dma_buf *dbuf,
480+
enum dma_data_direction direction)
481+
{
482+
struct vb2_dma_sg_buf *buf = dbuf->priv;
483+
struct sg_table *sgt = buf->dma_sgt;
484+
485+
dma_sync_sg_for_cpu(buf->dev, sgt->sgl, sgt->nents, buf->dma_dir);
486+
return 0;
487+
}
488+
489+
static int
490+
vb2_dma_sg_dmabuf_ops_end_cpu_access(struct dma_buf *dbuf,
491+
enum dma_data_direction direction)
492+
{
493+
struct vb2_dma_sg_buf *buf = dbuf->priv;
494+
struct sg_table *sgt = buf->dma_sgt;
495+
496+
dma_sync_sg_for_device(buf->dev, sgt->sgl, sgt->nents, buf->dma_dir);
497+
return 0;
498+
}
499+
472500
static void *vb2_dma_sg_dmabuf_ops_vmap(struct dma_buf *dbuf)
473501
{
474502
struct vb2_dma_sg_buf *buf = dbuf->priv;
@@ -487,6 +515,8 @@ static const struct dma_buf_ops vb2_dma_sg_dmabuf_ops = {
487515
.detach = vb2_dma_sg_dmabuf_ops_detach,
488516
.map_dma_buf = vb2_dma_sg_dmabuf_ops_map,
489517
.unmap_dma_buf = vb2_dma_sg_dmabuf_ops_unmap,
518+
.begin_cpu_access = vb2_dma_sg_dmabuf_ops_begin_cpu_access,
519+
.end_cpu_access = vb2_dma_sg_dmabuf_ops_end_cpu_access,
490520
.vmap = vb2_dma_sg_dmabuf_ops_vmap,
491521
.mmap = vb2_dma_sg_dmabuf_ops_mmap,
492522
.release = vb2_dma_sg_dmabuf_ops_release,

0 commit comments

Comments
 (0)