Merge tag 'v3.14.25' into backport/v3.14.24-ltsi-rc1+v3.14.25/snapshot-merge.wip
[platform/adaptation/renesas_rcar/renesas_kernel.git] / include / media / videobuf2-core.h
index 941055e..2e49a38 100644 (file)
@@ -142,6 +142,7 @@ enum vb2_fileio_flags {
 /**
  * enum vb2_buffer_state - current video buffer state
  * @VB2_BUF_STATE_DEQUEUED:    buffer under userspace control
+ * @VB2_BUF_STATE_PREPARING:   buffer is being prepared in videobuf
  * @VB2_BUF_STATE_PREPARED:    buffer prepared in videobuf and by the driver
  * @VB2_BUF_STATE_QUEUED:      buffer queued in videobuf, but not in driver
  * @VB2_BUF_STATE_ACTIVE:      buffer queued in driver and possibly used
@@ -154,6 +155,7 @@ enum vb2_fileio_flags {
  */
 enum vb2_buffer_state {
        VB2_BUF_STATE_DEQUEUED,
+       VB2_BUF_STATE_PREPARING,
        VB2_BUF_STATE_PREPARED,
        VB2_BUF_STATE_QUEUED,
        VB2_BUF_STATE_ACTIVE,
@@ -250,10 +252,13 @@ struct vb2_buffer {
  *                     receive buffers with @buf_queue callback before
  *                     @start_streaming is called; the driver gets the number
  *                     of already queued buffers in count parameter; driver
- *                     can return an error if hardware fails or not enough
- *                     buffers has been queued, in such case all buffers that
- *                     have been already given by the @buf_queue callback are
- *                     invalidated.
+ *                     can return an error if hardware fails, in that case all
+ *                     buffers that have been already given by the @buf_queue
+ *                     callback are invalidated.
+ *                     If there were not enough queued buffers to start
+ *                     streaming, then this callback returns -ENOBUFS, and the
+ *                     vb2 core will retry calling @start_streaming when a new
+ *                     buffer is queued.
  * @stop_streaming:    called when 'streaming' state must be disabled; driver
  *                     should stop any DMA transactions or wait until they
  *                     finish and give back all buffers it got from buf_queue()
@@ -310,17 +315,27 @@ struct v4l2_fh;
  * @gfp_flags: additional gfp flags used when allocating the buffers.
  *             Typically this is 0, but it may be e.g. GFP_DMA or __GFP_DMA32
  *             to force the buffer allocation to a specific memory zone.
+ * @min_buffers_needed: the minimum number of buffers needed before
+ *             start_streaming() can be called. Used when a DMA engine
+ *             cannot be started unless at least this number of buffers
+ *             have been queued into the driver.
  *
  * @memory:    current memory type used
  * @bufs:      videobuf buffer structures
  * @num_buffers: number of allocated/used buffers
  * @queued_list: list of buffers currently queued from userspace
- * @queued_count: number of buffers owned by the driver
+ * @queued_count: number of buffers queued and ready for streaming.
+ * @owned_by_drv_count: number of buffers owned by the driver
  * @done_list: list of buffers ready to be dequeued to userspace
  * @done_lock: lock to protect done_list list
  * @done_wq:   waitqueue for processes waiting for buffers ready to be dequeued
  * @alloc_ctx: memory type/allocator-specific contexts for each plane
  * @streaming: current streaming state
+ * @start_streaming_called: start_streaming() was called successfully and we
+ *             started streaming.
+ * @waiting_for_buffers: used in poll() to check if vb2 is still waiting for
+ *             buffers. Only set for capture queues if qbuf has not yet been
+ *             called since poll() needs to return POLLERR in that situation.
  * @fileio:    file io emulator internal data, used only if emulator is active
  */
 struct vb2_queue {
@@ -336,6 +351,7 @@ struct vb2_queue {
        unsigned int                    buf_struct_size;
        u32                             timestamp_type;
        gfp_t                           gfp_flags;
+       u32                             min_buffers_needed;
 
 /* private: internal use only */
        enum v4l2_memory                memory;
@@ -343,8 +359,9 @@ struct vb2_queue {
        unsigned int                    num_buffers;
 
        struct list_head                queued_list;
+       unsigned int                    queued_count;
 
-       atomic_t                        queued_count;
+       atomic_t                        owned_by_drv_count;
        struct list_head                done_list;
        spinlock_t                      done_lock;
        wait_queue_head_t               done_wq;
@@ -353,6 +370,8 @@ struct vb2_queue {
        unsigned int                    plane_sizes[VIDEO_MAX_PLANES];
 
        unsigned int                    streaming:1;
+       unsigned int                    start_streaming_called:1;
+       unsigned int                    waiting_for_buffers:1;
 
        struct vb2_fileio_data          *fileio;
 };
@@ -491,6 +510,7 @@ int vb2_ioctl_expbuf(struct file *file, void *priv,
 
 int vb2_fop_mmap(struct file *file, struct vm_area_struct *vma);
 int vb2_fop_release(struct file *file);
+int _vb2_fop_release(struct file *file, struct mutex *lock);
 ssize_t vb2_fop_write(struct file *file, const char __user *buf,
                size_t count, loff_t *ppos);
 ssize_t vb2_fop_read(struct file *file, char __user *buf,