OSDN Git Service

media: videobuf2-core: add uses_requests/qbuf flags
authorHans Verkuil <hans.verkuil@cisco.com>
Wed, 23 May 2018 11:51:25 +0000 (07:51 -0400)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Fri, 31 Aug 2018 15:22:56 +0000 (11:22 -0400)
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 <hans.verkuil@cisco.com>
Reviewed-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
drivers/media/common/videobuf2/videobuf2-core.c
include/media/videobuf2-core.h

index f941bf4..2dc3fc9 100644 (file)
@@ -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...
index a9f2a7e..881f53b 100644 (file)
@@ -472,6 +472,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
@@ -539,6 +545,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;