From patchwork Sat Aug 4 12:45:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 10555717 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A03A66CB for ; Sat, 4 Aug 2018 12:45:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DDBE2A13A for ; Sat, 4 Aug 2018 12:45:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8005D2A146; Sat, 4 Aug 2018 12:45:44 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham 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 0F2342A13A for ; Sat, 4 Aug 2018 12:45:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727600AbeHDOqT (ORCPT ); Sat, 4 Aug 2018 10:46:19 -0400 Received: from lb2-smtp-cloud7.xs4all.net ([194.109.24.28]:36168 "EHLO lb2-smtp-cloud7.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727821AbeHDOqN (ORCPT ); Sat, 4 Aug 2018 10:46:13 -0400 Received: from tschai.fritz.box ([212.251.195.8]) by smtp-cloud7.xs4all.net with ESMTPA id lvvyfCzUl6brUlvw7fFM6E; Sat, 04 Aug 2018 14:45:35 +0200 From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Hans Verkuil Subject: [PATCHv17 27/34] videobuf2-core: add uses_requests/qbuf flags Date: Sat, 4 Aug 2018 14:45:19 +0200 Message-Id: <20180804124526.46206-28-hverkuil@xs4all.nl> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180804124526.46206-1-hverkuil@xs4all.nl> References: <20180804124526.46206-1-hverkuil@xs4all.nl> X-CMAE-Envelope: MS4wfDg7zxaNOE+U5oktLgSfAa/1BQGPRRohFQ0UfP2hc1ubr/xy8AMcK0bJ1qNqmL0gbVVZHKxIolA7KwyzKWucJik0J9ff3gsxTsn9nLhYK5uK0tYSUutQ oLzcfv9mTw9wHsl206yUemTLOg2PNCwkMr8+UPCBWVAPF9N0fT4z24gIZI8JdJQ/8/U+JjZZpZ+qGEo8b1KyuenAriL/CHOxfDU= 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: Hans Verkuil Set the first time a buffer from a request is queued to vb2 (uses_requests) or directly queued (uses_qbuf). Cleared when the queue is canceled. Signed-off-by: Hans Verkuil Reviewed-by: Mauro Carvalho Chehab --- drivers/media/common/videobuf2/videobuf2-core.c | 13 +++++++++++++ include/media/videobuf2-core.h | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index f8af7add35ab..5d7946ec80d8 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -1491,9 +1491,17 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb, vb = q->bufs[index]; + if ((req && q->uses_qbuf) || + (!req && vb->state != VB2_BUF_STATE_IN_REQUEST && + q->uses_requests)) { + dprintk(1, "queue in wrong mode (qbuf vs requests)\n"); + return -EPERM; + } + if (req) { int ret; + q->uses_requests = 1; if (vb->state != VB2_BUF_STATE_DEQUEUED) { dprintk(1, "buffer %d not in dequeued state\n", vb->index); @@ -1523,6 +1531,9 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb, return 0; } + if (vb->state != VB2_BUF_STATE_IN_REQUEST) + q->uses_qbuf = 1; + switch (vb->state) { case VB2_BUF_STATE_DEQUEUED: case VB2_BUF_STATE_IN_REQUEST: @@ -1825,6 +1836,8 @@ static void __vb2_queue_cancel(struct vb2_queue *q) q->start_streaming_called = 0; q->queued_count = 0; q->error = 0; + q->uses_requests = 0; + q->uses_qbuf = 0; /* * Remove all buffers from videobuf's list... diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index cad712403d14..daffdf259fce 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -468,6 +468,12 @@ struct vb2_buf_ops { * @quirk_poll_must_check_waiting_for_buffers: Return %EPOLLERR at poll when QBUF * has not been called. This is a vb1 idiom that has been adopted * also by vb2. + * @uses_qbuf: qbuf was used directly for this queue. Set to 1 the first + * time this is called. Set to 0 when the queue is canceled. + * If this is 1, then you cannot queue buffers from a request. + * @uses_requests: requests are used for this queue. Set to 1 the first time + * a request is queued. Set to 0 when the queue is canceled. + * If this is 1, then you cannot queue buffers directly. * @lock: pointer to a mutex that protects the &struct vb2_queue. The * driver can set this to a mutex to let the v4l2 core serialize * the queuing ioctls. If the driver wants to handle locking @@ -535,6 +541,8 @@ struct vb2_queue { unsigned fileio_write_immediately:1; unsigned allow_zero_bytesused:1; unsigned quirk_poll_must_check_waiting_for_buffers:1; + unsigned uses_qbuf:1; + unsigned uses_requests:1; struct mutex *lock; void *owner;