From bd60ad374e87b77eb9cca8aa69584bdda1dd81b6 Mon Sep 17 00:00:00 2001 From: Pawel Osciak Date: Wed, 16 Sep 2015 21:21:49 +0900 Subject: [PATCH] CHROMIUM: vb2: Add a new "use_dma_bidirectional" queue flag. When set to 1 for CAPTURE queues by the driver on calling vb2_queue_init(), forces the buffers on the queue to be allocated/mapped with DMA_BIDIRECTIONAL DMA direction flag, instead of DMA_FROM_DEVICE. This allows the device not only to write to the buffers, but also read out from them. This may be useful e.g. for codec hardware, which may be using CAPTURE buffers as reference to decode other buffers. This flag is ignored for OUTPUT queues, as we don't want to allow HW to be able to write to OUTPUT buffers. Signed-off-by: Pawel Osciak BUG=chrome-os-partner:45346 TEST=video playback Reviewed-on: https://chromium-review.googlesource.com/300726 Commit-Ready: Pawel Osciak Tested-by: Pawel Osciak Reviewed-by: Tomasz Figa Change-Id: Ifba955eef75ac23c9a13edab04bc1fe7f5375c70 Signed-off-by: Jeffy Chen Signed-off-by: Yakir Yang --- drivers/media/v4l2-core/videobuf2-core.c | 8 ++++++-- include/media/videobuf2-core.h | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c index fad3d24c964d..40dc1dd3292b 100644 --- a/drivers/media/v4l2-core/videobuf2-core.c +++ b/drivers/media/v4l2-core/videobuf2-core.c @@ -2063,8 +2063,12 @@ int vb2_core_queue_init(struct vb2_queue *q) if (q->buf_struct_size == 0) q->buf_struct_size = sizeof(struct vb2_buffer); - q->dma_dir = q->is_output - ? DMA_TO_DEVICE : DMA_FROM_DEVICE; + if (q->is_output) + q->dma_dir = DMA_TO_DEVICE; + else + q->dma_dir = q->use_dma_bidirectional + ? DMA_BIDIRECTIONAL : DMA_FROM_DEVICE; + return 0; } EXPORT_SYMBOL_GPL(vb2_core_queue_init); diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index f18ac1fe522b..8c4e172b80ca 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -380,6 +380,9 @@ struct vb2_buf_ops { * @fileio_read_once: report EOF after reading the first buffer * @fileio_write_immediately: queue buffer after each write() call * @allow_zero_bytesused: allow bytesused == 0 to be passed to the driver + * @use_dma_bidirectional: use DMA_BIDIRECTIONAL for CAPTURE buffers; this + * allows HW to read from the CAPTURE buffers in + * addition to writing; ignored for OUTPUT queues * @lock: pointer to a mutex that protects the vb2_queue struct. The * driver can set this to a mutex to let the v4l2 core serialize * the queuing ioctls. If the driver wants to handle locking @@ -443,6 +446,7 @@ struct vb2_queue { unsigned fileio_read_once:1; unsigned fileio_write_immediately:1; unsigned allow_zero_bytesused:1; + unsigned use_dma_bidirectional:1; struct mutex *lock; void *owner; -- 2.34.1