13 #include <linux/kernel.h>
15 #include <linux/list.h>
16 #include <linux/module.h>
18 #include <linux/videodev2.h>
20 #include <linux/wait.h>
85 INIT_LIST_HEAD(&queue->mainqueue);
99 for (i = 0; i < queue->count; ++
i) {
100 if (queue->buffer[i].vma_use_count != 0)
122 unsigned int buflength)
142 for (; nbuffers > 0; --nbuffers) {
153 for (i = 0; i < nbuffers; ++
i) {
154 memset(&queue->buffer[i], 0,
sizeof queue->buffer[i]);
155 queue->buffer[
i].buf.index =
i;
156 queue->buffer[
i].buf.m.offset = i *
bufsize;
157 queue->buffer[
i].buf.length = buflength;
158 queue->buffer[
i].buf.type = queue->type;
159 queue->buffer[
i].buf.sequence = 0;
162 queue->buffer[
i].buf.
flags = 0;
167 queue->count = nbuffers;
179 memcpy(v4l2_buf, &buf->
buf,
sizeof *v4l2_buf);
181 if (buf->vma_use_count)
184 switch (buf->
state) {
205 if (v4l2_buf->
index >= queue->count) {
210 __uvc_query_buffer(&queue->buffer[v4l2_buf->
index], v4l2_buf);
230 if (v4l2_buf->
type != queue->type ||
233 "and/or memory (%u).\n", v4l2_buf->
type,
239 if (v4l2_buf->
index >= queue->count) {
245 buf = &queue->buffer[v4l2_buf->
index];
248 "(%u).\n", buf->
state);
261 buf->
buf.bytesused = 0;
267 spin_unlock_irqrestore(&queue->
irqlock, flags);
273 ret = (queue->
flags & UVC_QUEUE_PAUSED) != 0;
274 queue->
flags &= ~UVC_QUEUE_PAUSED;
278 spin_unlock_irqrestore(&queue->
irqlock, flags);
285 static int uvc_queue_waiton(
struct uvc_buffer *buf,
int nonblocking)
309 if (v4l2_buf->
type != queue->type ||
312 "and/or memory (%u).\n", v4l2_buf->
type,
318 if (list_empty(&queue->mainqueue)) {
325 if ((ret = uvc_queue_waiton(buf, nonblocking)) < 0)
331 switch (buf->
state) {
334 "(transmission error).\n");
345 "(driver bug?).\n", buf->
state);
351 __uvc_query_buffer(buf, v4l2_buf);
369 unsigned int mask = 0;
372 if (list_empty(&queue->mainqueue))
377 poll_wait(file, &buf->wait, wait);
393 buffer->vma_use_count++;
399 buffer->vma_use_count--;
402 static struct vm_operations_struct uvc_vm_ops = {
404 .close = uvc_vm_close,
427 for (i = 0; i < queue->count; ++
i) {
433 if (i == queue->count || size != queue->buf_size) {
455 vma->
vm_ops = &uvc_vm_ops;
482 while (!list_empty(&queue->
irqqueue)) {
497 spin_unlock_irqrestore(&queue->
irqlock, flags);
524 if (uvc_queue_streaming(queue)) {
529 queue->
flags |= UVC_QUEUE_STREAMING;
533 INIT_LIST_HEAD(&queue->mainqueue);
535 for (i = 0; i < queue->count; ++
i)
538 queue->
flags &= ~UVC_QUEUE_STREAMING;
552 if ((queue->
flags & UVC_QUEUE_DROP_INCOMPLETE) &&
553 buf->
buf.length != buf->
buf.bytesused) {
555 buf->
buf.bytesused = 0;
566 buf->
buf.sequence = queue->sequence++;
581 queue->
flags |= UVC_QUEUE_PAUSED;