Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1 | /* |
| 2 | * uvc_queue.c -- USB Video Class driver - Buffers management |
| 3 | * |
Laurent Pinchart | 11fc5ba | 2010-09-20 06:10:10 -0300 | [diff] [blame] | 4 | * Copyright (C) 2005-2010 |
| 5 | * Laurent Pinchart (laurent.pinchart@ideasonboard.com) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | */ |
| 13 | |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 14 | #include <linux/atomic.h> |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 15 | #include <linux/kernel.h> |
Andrea Righi | 27ac792 | 2008-07-23 21:28:13 -0700 | [diff] [blame] | 16 | #include <linux/mm.h> |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 17 | #include <linux/list.h> |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/usb.h> |
| 20 | #include <linux/videodev2.h> |
| 21 | #include <linux/vmalloc.h> |
| 22 | #include <linux/wait.h> |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 23 | #include <media/videobuf2-vmalloc.h> |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 24 | |
| 25 | #include "uvcvideo.h" |
| 26 | |
| 27 | /* ------------------------------------------------------------------------ |
| 28 | * Video buffers queue management. |
| 29 | * |
| 30 | * Video queues is initialized by uvc_queue_init(). The function performs |
| 31 | * basic initialization of the uvc_video_queue struct and never fails. |
| 32 | * |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 33 | * Video buffers are managed by videobuf2. The driver uses a mutex to protect |
| 34 | * the videobuf2 queue operations by serializing calls to videobuf2 and a |
| 35 | * spinlock to protect the IRQ queue that holds the buffers to be processed by |
| 36 | * the driver. |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 37 | */ |
| 38 | |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 39 | /* ----------------------------------------------------------------------------- |
| 40 | * videobuf2 queue operations |
Laurent Pinchart | 8e815e17 | 2010-11-21 14:46:44 -0300 | [diff] [blame] | 41 | */ |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 42 | |
| 43 | static int uvc_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt, |
| 44 | unsigned int *nbuffers, unsigned int *nplanes, |
| 45 | unsigned int sizes[], void *alloc_ctxs[]) |
Laurent Pinchart | 8e815e17 | 2010-11-21 14:46:44 -0300 | [diff] [blame] | 46 | { |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 47 | struct uvc_video_queue *queue = vb2_get_drv_priv(vq); |
| 48 | struct uvc_streaming *stream = |
| 49 | container_of(queue, struct uvc_streaming, queue); |
Laurent Pinchart | 8e815e17 | 2010-11-21 14:46:44 -0300 | [diff] [blame] | 50 | |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 51 | if (*nbuffers > UVC_MAX_VIDEO_BUFFERS) |
| 52 | *nbuffers = UVC_MAX_VIDEO_BUFFERS; |
Laurent Pinchart | 8e815e17 | 2010-11-21 14:46:44 -0300 | [diff] [blame] | 53 | |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 54 | *nplanes = 1; |
| 55 | |
| 56 | sizes[0] = stream->ctrl.dwMaxVideoFrameSize; |
Laurent Pinchart | 8e815e17 | 2010-11-21 14:46:44 -0300 | [diff] [blame] | 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 61 | static int uvc_buffer_prepare(struct vb2_buffer *vb) |
Laurent Pinchart | 8e815e17 | 2010-11-21 14:46:44 -0300 | [diff] [blame] | 62 | { |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 63 | struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue); |
| 64 | struct uvc_buffer *buf = container_of(vb, struct uvc_buffer, buf); |
Laurent Pinchart | 8e815e17 | 2010-11-21 14:46:44 -0300 | [diff] [blame] | 65 | |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 66 | if (vb->v4l2_buf.type == V4L2_BUF_TYPE_VIDEO_OUTPUT && |
| 67 | vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0)) { |
| 68 | uvc_trace(UVC_TRACE_CAPTURE, "[E] Bytes used out of bounds.\n"); |
| 69 | return -EINVAL; |
| 70 | } |
Laurent Pinchart | 8e815e17 | 2010-11-21 14:46:44 -0300 | [diff] [blame] | 71 | |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 72 | if (unlikely(queue->flags & UVC_QUEUE_DISCONNECTED)) |
| 73 | return -ENODEV; |
| 74 | |
| 75 | buf->state = UVC_BUF_STATE_QUEUED; |
| 76 | buf->error = 0; |
| 77 | buf->mem = vb2_plane_vaddr(vb, 0); |
| 78 | buf->length = vb2_plane_size(vb, 0); |
| 79 | if (vb->v4l2_buf.type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 80 | buf->bytesused = 0; |
| 81 | else |
| 82 | buf->bytesused = vb2_get_plane_payload(vb, 0); |
| 83 | |
| 84 | return 0; |
Laurent Pinchart | 8e815e17 | 2010-11-21 14:46:44 -0300 | [diff] [blame] | 85 | } |
| 86 | |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 87 | static void uvc_buffer_queue(struct vb2_buffer *vb) |
| 88 | { |
| 89 | struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue); |
| 90 | struct uvc_buffer *buf = container_of(vb, struct uvc_buffer, buf); |
| 91 | unsigned long flags; |
| 92 | |
| 93 | spin_lock_irqsave(&queue->irqlock, flags); |
| 94 | if (likely(!(queue->flags & UVC_QUEUE_DISCONNECTED))) { |
| 95 | list_add_tail(&buf->queue, &queue->irqqueue); |
| 96 | } else { |
| 97 | /* If the device is disconnected return the buffer to userspace |
| 98 | * directly. The next QBUF call will fail with -ENODEV. |
| 99 | */ |
| 100 | buf->state = UVC_BUF_STATE_ERROR; |
| 101 | vb2_buffer_done(&buf->buf, VB2_BUF_STATE_ERROR); |
| 102 | } |
| 103 | |
| 104 | spin_unlock_irqrestore(&queue->irqlock, flags); |
| 105 | } |
| 106 | |
Laurent Pinchart | 66847ef | 2011-09-24 10:46:55 -0300 | [diff] [blame] | 107 | static int uvc_buffer_finish(struct vb2_buffer *vb) |
| 108 | { |
| 109 | struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue); |
| 110 | struct uvc_streaming *stream = |
| 111 | container_of(queue, struct uvc_streaming, queue); |
| 112 | struct uvc_buffer *buf = container_of(vb, struct uvc_buffer, buf); |
| 113 | |
| 114 | uvc_video_clock_update(stream, &vb->v4l2_buf, buf); |
| 115 | return 0; |
| 116 | } |
| 117 | |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 118 | static struct vb2_ops uvc_queue_qops = { |
| 119 | .queue_setup = uvc_queue_setup, |
| 120 | .buf_prepare = uvc_buffer_prepare, |
| 121 | .buf_queue = uvc_buffer_queue, |
Laurent Pinchart | 66847ef | 2011-09-24 10:46:55 -0300 | [diff] [blame] | 122 | .buf_finish = uvc_buffer_finish, |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 123 | }; |
| 124 | |
Ezequiel Garcia | 5712661 | 2012-09-26 07:30:34 -0300 | [diff] [blame] | 125 | int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type, |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 126 | int drop_corrupted) |
| 127 | { |
Ezequiel Garcia | 5712661 | 2012-09-26 07:30:34 -0300 | [diff] [blame] | 128 | int ret; |
| 129 | |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 130 | queue->queue.type = type; |
Javier Martin | ab86e9e | 2012-01-02 11:12:23 -0300 | [diff] [blame] | 131 | queue->queue.io_modes = VB2_MMAP | VB2_USERPTR; |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 132 | queue->queue.drv_priv = queue; |
| 133 | queue->queue.buf_struct_size = sizeof(struct uvc_buffer); |
| 134 | queue->queue.ops = &uvc_queue_qops; |
| 135 | queue->queue.mem_ops = &vb2_vmalloc_memops; |
Ezequiel Garcia | 5712661 | 2012-09-26 07:30:34 -0300 | [diff] [blame] | 136 | ret = vb2_queue_init(&queue->queue); |
| 137 | if (ret) |
| 138 | return ret; |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 139 | |
| 140 | mutex_init(&queue->mutex); |
| 141 | spin_lock_init(&queue->irqlock); |
| 142 | INIT_LIST_HEAD(&queue->irqqueue); |
| 143 | queue->flags = drop_corrupted ? UVC_QUEUE_DROP_CORRUPTED : 0; |
Ezequiel Garcia | 5712661 | 2012-09-26 07:30:34 -0300 | [diff] [blame] | 144 | |
| 145 | return 0; |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | /* ----------------------------------------------------------------------------- |
| 149 | * V4L2 queue operations |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 150 | */ |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 151 | |
| 152 | int uvc_alloc_buffers(struct uvc_video_queue *queue, |
| 153 | struct v4l2_requestbuffers *rb) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 154 | { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 155 | int ret; |
| 156 | |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 157 | mutex_lock(&queue->mutex); |
| 158 | ret = vb2_reqbufs(&queue->queue, rb); |
| 159 | mutex_unlock(&queue->mutex); |
| 160 | |
| 161 | return ret ? ret : rb->count; |
| 162 | } |
| 163 | |
| 164 | void uvc_free_buffers(struct uvc_video_queue *queue) |
| 165 | { |
| 166 | mutex_lock(&queue->mutex); |
| 167 | vb2_queue_release(&queue->queue); |
| 168 | mutex_unlock(&queue->mutex); |
| 169 | } |
| 170 | |
| 171 | int uvc_query_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf) |
| 172 | { |
| 173 | int ret; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 174 | |
| 175 | mutex_lock(&queue->mutex); |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 176 | ret = vb2_querybuf(&queue->queue, buf); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 177 | mutex_unlock(&queue->mutex); |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 178 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 179 | return ret; |
| 180 | } |
| 181 | |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 182 | int uvc_queue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf) |
| 183 | { |
| 184 | int ret; |
| 185 | |
| 186 | mutex_lock(&queue->mutex); |
| 187 | ret = vb2_qbuf(&queue->queue, buf); |
| 188 | mutex_unlock(&queue->mutex); |
| 189 | |
| 190 | return ret; |
| 191 | } |
| 192 | |
| 193 | int uvc_dequeue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf, |
| 194 | int nonblocking) |
| 195 | { |
| 196 | int ret; |
| 197 | |
| 198 | mutex_lock(&queue->mutex); |
| 199 | ret = vb2_dqbuf(&queue->queue, buf, nonblocking); |
| 200 | mutex_unlock(&queue->mutex); |
| 201 | |
| 202 | return ret; |
| 203 | } |
| 204 | |
| 205 | int uvc_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma) |
| 206 | { |
| 207 | int ret; |
| 208 | |
| 209 | mutex_lock(&queue->mutex); |
| 210 | ret = vb2_mmap(&queue->queue, vma); |
| 211 | mutex_unlock(&queue->mutex); |
| 212 | |
| 213 | return ret; |
| 214 | } |
| 215 | |
Laurent Pinchart | 4742c82 | 2012-04-30 08:19:10 -0300 | [diff] [blame] | 216 | #ifndef CONFIG_MMU |
| 217 | unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue, |
| 218 | unsigned long pgoff) |
| 219 | { |
| 220 | unsigned long ret; |
| 221 | |
| 222 | mutex_lock(&queue->mutex); |
| 223 | ret = vb2_get_unmapped_area(&queue->queue, 0, 0, pgoff, 0); |
| 224 | mutex_unlock(&queue->mutex); |
| 225 | return ret; |
| 226 | } |
| 227 | #endif |
| 228 | |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 229 | unsigned int uvc_queue_poll(struct uvc_video_queue *queue, struct file *file, |
| 230 | poll_table *wait) |
| 231 | { |
| 232 | unsigned int ret; |
| 233 | |
| 234 | mutex_lock(&queue->mutex); |
| 235 | ret = vb2_poll(&queue->queue, file, wait); |
| 236 | mutex_unlock(&queue->mutex); |
| 237 | |
| 238 | return ret; |
| 239 | } |
| 240 | |
| 241 | /* ----------------------------------------------------------------------------- |
| 242 | * |
| 243 | */ |
| 244 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 245 | /* |
Laurent Pinchart | 23ff604 | 2009-06-04 09:26:39 -0300 | [diff] [blame] | 246 | * Check if buffers have been allocated. |
| 247 | */ |
| 248 | int uvc_queue_allocated(struct uvc_video_queue *queue) |
| 249 | { |
| 250 | int allocated; |
| 251 | |
| 252 | mutex_lock(&queue->mutex); |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 253 | allocated = vb2_is_busy(&queue->queue); |
Laurent Pinchart | 23ff604 | 2009-06-04 09:26:39 -0300 | [diff] [blame] | 254 | mutex_unlock(&queue->mutex); |
| 255 | |
| 256 | return allocated; |
| 257 | } |
| 258 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 259 | /* |
| 260 | * Enable or disable the video buffers queue. |
| 261 | * |
| 262 | * The queue must be enabled before starting video acquisition and must be |
| 263 | * disabled after stopping it. This ensures that the video buffers queue |
| 264 | * state can be properly initialized before buffers are accessed from the |
| 265 | * interrupt handler. |
| 266 | * |
Laurent Pinchart | 650b95f | 2010-10-02 11:06:05 -0300 | [diff] [blame] | 267 | * Enabling the video queue returns -EBUSY if the queue is already enabled. |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 268 | * |
| 269 | * Disabling the video queue cancels the queue and removes all buffers from |
| 270 | * the main queue. |
| 271 | * |
| 272 | * This function can't be called from interrupt context. Use |
| 273 | * uvc_queue_cancel() instead. |
| 274 | */ |
| 275 | int uvc_queue_enable(struct uvc_video_queue *queue, int enable) |
| 276 | { |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 277 | unsigned long flags; |
| 278 | int ret; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 279 | |
| 280 | mutex_lock(&queue->mutex); |
| 281 | if (enable) { |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 282 | ret = vb2_streamon(&queue->queue, queue->queue.type); |
| 283 | if (ret < 0) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 284 | goto done; |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 285 | |
Laurent Pinchart | ff92420 | 2008-12-28 22:32:29 -0300 | [diff] [blame] | 286 | queue->buf_used = 0; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 287 | } else { |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 288 | ret = vb2_streamoff(&queue->queue, queue->queue.type); |
| 289 | if (ret < 0) |
| 290 | goto done; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 291 | |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 292 | spin_lock_irqsave(&queue->irqlock, flags); |
| 293 | INIT_LIST_HEAD(&queue->irqqueue); |
| 294 | spin_unlock_irqrestore(&queue->irqlock, flags); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | done: |
| 298 | mutex_unlock(&queue->mutex); |
| 299 | return ret; |
| 300 | } |
| 301 | |
| 302 | /* |
| 303 | * Cancel the video buffers queue. |
| 304 | * |
| 305 | * Cancelling the queue marks all buffers on the irq queue as erroneous, |
Laurent Pinchart | 2c2d264 | 2009-01-03 19:12:40 -0300 | [diff] [blame] | 306 | * wakes them up and removes them from the queue. |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 307 | * |
| 308 | * If the disconnect parameter is set, further calls to uvc_queue_buffer will |
| 309 | * fail with -ENODEV. |
| 310 | * |
| 311 | * This function acquires the irq spinlock and can be called from interrupt |
| 312 | * context. |
| 313 | */ |
| 314 | void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect) |
| 315 | { |
| 316 | struct uvc_buffer *buf; |
| 317 | unsigned long flags; |
| 318 | |
| 319 | spin_lock_irqsave(&queue->irqlock, flags); |
| 320 | while (!list_empty(&queue->irqqueue)) { |
| 321 | buf = list_first_entry(&queue->irqqueue, struct uvc_buffer, |
| 322 | queue); |
| 323 | list_del(&buf->queue); |
| 324 | buf->state = UVC_BUF_STATE_ERROR; |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 325 | vb2_buffer_done(&buf->buf, VB2_BUF_STATE_ERROR); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 326 | } |
| 327 | /* This must be protected by the irqlock spinlock to avoid race |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 328 | * conditions between uvc_buffer_queue and the disconnection event that |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 329 | * could result in an interruptible wait in uvc_dequeue_buffer. Do not |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 330 | * blindly replace this logic by checking for the UVC_QUEUE_DISCONNECTED |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 331 | * state outside the queue code. |
| 332 | */ |
| 333 | if (disconnect) |
| 334 | queue->flags |= UVC_QUEUE_DISCONNECTED; |
| 335 | spin_unlock_irqrestore(&queue->irqlock, flags); |
| 336 | } |
| 337 | |
| 338 | struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, |
| 339 | struct uvc_buffer *buf) |
| 340 | { |
| 341 | struct uvc_buffer *nextbuf; |
| 342 | unsigned long flags; |
| 343 | |
Laurent Pinchart | 9bde9f2 | 2010-06-17 06:52:37 -0300 | [diff] [blame] | 344 | if ((queue->flags & UVC_QUEUE_DROP_CORRUPTED) && buf->error) { |
| 345 | buf->error = 0; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 346 | buf->state = UVC_BUF_STATE_QUEUED; |
Jayakrishnan Memana | 8a3f0ed | 2012-07-15 10:54:03 -0300 | [diff] [blame] | 347 | buf->bytesused = 0; |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 348 | vb2_set_plane_payload(&buf->buf, 0, 0); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 349 | return buf; |
| 350 | } |
| 351 | |
| 352 | spin_lock_irqsave(&queue->irqlock, flags); |
| 353 | list_del(&buf->queue); |
| 354 | if (!list_empty(&queue->irqqueue)) |
| 355 | nextbuf = list_first_entry(&queue->irqqueue, struct uvc_buffer, |
| 356 | queue); |
| 357 | else |
| 358 | nextbuf = NULL; |
| 359 | spin_unlock_irqrestore(&queue->irqlock, flags); |
| 360 | |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 361 | buf->state = buf->error ? VB2_BUF_STATE_ERROR : UVC_BUF_STATE_DONE; |
| 362 | vb2_set_plane_payload(&buf->buf, 0, buf->bytesused); |
| 363 | vb2_buffer_done(&buf->buf, VB2_BUF_STATE_DONE); |
| 364 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 365 | return nextbuf; |
| 366 | } |