From patchwork Fri Oct 14 12:08:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Escande X-Patchwork-Id: 9376483 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 254AB6075E for ; Fri, 14 Oct 2016 12:11:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 169A92A671 for ; Fri, 14 Oct 2016 12:11:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0671C2A66A; Fri, 14 Oct 2016 12:11:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E325D2A66A for ; Fri, 14 Oct 2016 12:11:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754649AbcJNMK4 (ORCPT ); Fri, 14 Oct 2016 08:10:56 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:50572 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753660AbcJNMKy (ORCPT ); Fri, 14 Oct 2016 08:10:54 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tescande) with ESMTPSA id 88BE72670AA From: Thierry Escande To: Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Pawel Osciak , Marek Szyprowski , Kyungmin Park Subject: [PATCH 2/2] [media] vb2: Add support for use_dma_bidirectional queue flag Date: Fri, 14 Oct 2016 14:08:14 +0200 Message-Id: <1476446894-4220-3-git-send-email-thierry.escande@collabora.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1476446894-4220-1-git-send-email-thierry.escande@collabora.com> References: <1476446894-4220-1-git-send-email-thierry.escande@collabora.com> MIME-Version: 1.0 Content-Transfert-Encoding: 8bit Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Pawel Osciak When this flag is set for CAPTURE queues by the driver on calling vb2_queue_init(), it forces the buffers on the queue to be allocated/mapped with DMA_BIDIRECTIONAL 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 Tested-by: Pawel Osciak Reviewed-by: Tomasz Figa Signed-off-by: Thierry Escande --- drivers/media/v4l2-core/videobuf2-v4l2.c | 8 ++++++-- include/media/videobuf2-core.h | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c index fde1e2d..9255291 100644 --- a/drivers/media/v4l2-core/videobuf2-v4l2.c +++ b/drivers/media/v4l2-core/videobuf2-v4l2.c @@ -659,8 +659,12 @@ int vb2_queue_init(struct vb2_queue *q) * queues will always initialize waiting_for_buffers to false. */ q->quirk_poll_must_check_waiting_for_buffers = true; - q->dma_dir = V4L2_TYPE_IS_OUTPUT(q->type) - ? DMA_TO_DEVICE : DMA_FROM_DEVICE; + + if (V4L2_TYPE_IS_OUTPUT(q->type)) + q->dma_dir = DMA_TO_DEVICE; + else + q->dma_dir = q->use_dma_bidirectional + ? DMA_BIDIRECTIONAL : DMA_FROM_DEVICE; return vb2_core_queue_init(q); } diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index 38410dd..e613c74 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -433,6 +433,9 @@ struct vb2_buf_ops { * @quirk_poll_must_check_waiting_for_buffers: Return POLLERR at poll when QBUF * has not been called. This is a vb1 idiom that has been adopted * also by vb2. + * @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 @@ -500,6 +503,7 @@ struct vb2_queue { unsigned fileio_write_immediately:1; unsigned allow_zero_bytesused:1; unsigned quirk_poll_must_check_waiting_for_buffers:1; + unsigned use_dma_bidirectional:1; struct mutex *lock; void *owner;