firewire: remove unnecessary alloc/OOM messages
[linux-2.6/btrfs-unstable.git] / drivers / media / v4l2-core / v4l2-mem2mem.c
blobda99cf7271622bcde65495426686fc00e7beec02
1 /*
2 * Memory-to-memory device framework for Video for Linux 2 and videobuf.
4 * Helper functions for devices that use videobuf buffers for both their
5 * source and destination.
7 * Copyright (c) 2009-2010 Samsung Electronics Co., Ltd.
8 * Pawel Osciak, <pawel@osciak.com>
9 * Marek Szyprowski, <m.szyprowski@samsung.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
16 #include <linux/module.h>
17 #include <linux/sched.h>
18 #include <linux/slab.h>
20 #include <media/videobuf2-core.h>
21 #include <media/v4l2-mem2mem.h>
22 #include <media/v4l2-dev.h>
23 #include <media/v4l2-fh.h>
24 #include <media/v4l2-event.h>
26 MODULE_DESCRIPTION("Mem to mem device framework for videobuf");
27 MODULE_AUTHOR("Pawel Osciak, <pawel@osciak.com>");
28 MODULE_LICENSE("GPL");
30 static bool debug;
31 module_param(debug, bool, 0644);
33 #define dprintk(fmt, arg...) \
34 do { \
35 if (debug) \
36 printk(KERN_DEBUG "%s: " fmt, __func__, ## arg);\
37 } while (0)
40 /* Instance is already queued on the job_queue */
41 #define TRANS_QUEUED (1 << 0)
42 /* Instance is currently running in hardware */
43 #define TRANS_RUNNING (1 << 1)
46 /* Offset base for buffers on the destination queue - used to distinguish
47 * between source and destination buffers when mmapping - they receive the same
48 * offsets but for different queues */
49 #define DST_QUEUE_OFF_BASE (1 << 30)
52 /**
53 * struct v4l2_m2m_dev - per-device context
54 * @curr_ctx: currently running instance
55 * @job_queue: instances queued to run
56 * @job_spinlock: protects job_queue
57 * @m2m_ops: driver callbacks
59 struct v4l2_m2m_dev {
60 struct v4l2_m2m_ctx *curr_ctx;
62 struct list_head job_queue;
63 spinlock_t job_spinlock;
65 const struct v4l2_m2m_ops *m2m_ops;
68 static struct v4l2_m2m_queue_ctx *get_queue_ctx(struct v4l2_m2m_ctx *m2m_ctx,
69 enum v4l2_buf_type type)
71 if (V4L2_TYPE_IS_OUTPUT(type))
72 return &m2m_ctx->out_q_ctx;
73 else
74 return &m2m_ctx->cap_q_ctx;
77 /**
78 * v4l2_m2m_get_vq() - return vb2_queue for the given type
80 struct vb2_queue *v4l2_m2m_get_vq(struct v4l2_m2m_ctx *m2m_ctx,
81 enum v4l2_buf_type type)
83 struct v4l2_m2m_queue_ctx *q_ctx;
85 q_ctx = get_queue_ctx(m2m_ctx, type);
86 if (!q_ctx)
87 return NULL;
89 return &q_ctx->q;
91 EXPORT_SYMBOL(v4l2_m2m_get_vq);
93 /**
94 * v4l2_m2m_next_buf() - return next buffer from the list of ready buffers
96 void *v4l2_m2m_next_buf(struct v4l2_m2m_queue_ctx *q_ctx)
98 struct v4l2_m2m_buffer *b = NULL;
99 unsigned long flags;
101 spin_lock_irqsave(&q_ctx->rdy_spinlock, flags);
103 if (list_empty(&q_ctx->rdy_queue)) {
104 spin_unlock_irqrestore(&q_ctx->rdy_spinlock, flags);
105 return NULL;
108 b = list_first_entry(&q_ctx->rdy_queue, struct v4l2_m2m_buffer, list);
109 spin_unlock_irqrestore(&q_ctx->rdy_spinlock, flags);
110 return &b->vb;
112 EXPORT_SYMBOL_GPL(v4l2_m2m_next_buf);
115 * v4l2_m2m_buf_remove() - take off a buffer from the list of ready buffers and
116 * return it
118 void *v4l2_m2m_buf_remove(struct v4l2_m2m_queue_ctx *q_ctx)
120 struct v4l2_m2m_buffer *b = NULL;
121 unsigned long flags;
123 spin_lock_irqsave(&q_ctx->rdy_spinlock, flags);
124 if (list_empty(&q_ctx->rdy_queue)) {
125 spin_unlock_irqrestore(&q_ctx->rdy_spinlock, flags);
126 return NULL;
128 b = list_first_entry(&q_ctx->rdy_queue, struct v4l2_m2m_buffer, list);
129 list_del(&b->list);
130 q_ctx->num_rdy--;
131 spin_unlock_irqrestore(&q_ctx->rdy_spinlock, flags);
133 return &b->vb;
135 EXPORT_SYMBOL_GPL(v4l2_m2m_buf_remove);
138 * Scheduling handlers
142 * v4l2_m2m_get_curr_priv() - return driver private data for the currently
143 * running instance or NULL if no instance is running
145 void *v4l2_m2m_get_curr_priv(struct v4l2_m2m_dev *m2m_dev)
147 unsigned long flags;
148 void *ret = NULL;
150 spin_lock_irqsave(&m2m_dev->job_spinlock, flags);
151 if (m2m_dev->curr_ctx)
152 ret = m2m_dev->curr_ctx->priv;
153 spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
155 return ret;
157 EXPORT_SYMBOL(v4l2_m2m_get_curr_priv);
160 * v4l2_m2m_try_run() - select next job to perform and run it if possible
162 * Get next transaction (if present) from the waiting jobs list and run it.
164 static void v4l2_m2m_try_run(struct v4l2_m2m_dev *m2m_dev)
166 unsigned long flags;
168 spin_lock_irqsave(&m2m_dev->job_spinlock, flags);
169 if (NULL != m2m_dev->curr_ctx) {
170 spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
171 dprintk("Another instance is running, won't run now\n");
172 return;
175 if (list_empty(&m2m_dev->job_queue)) {
176 spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
177 dprintk("No job pending\n");
178 return;
181 m2m_dev->curr_ctx = list_first_entry(&m2m_dev->job_queue,
182 struct v4l2_m2m_ctx, queue);
183 m2m_dev->curr_ctx->job_flags |= TRANS_RUNNING;
184 spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
186 m2m_dev->m2m_ops->device_run(m2m_dev->curr_ctx->priv);
190 * v4l2_m2m_try_schedule() - check whether an instance is ready to be added to
191 * the pending job queue and add it if so.
192 * @m2m_ctx: m2m context assigned to the instance to be checked
194 * There are three basic requirements an instance has to meet to be able to run:
195 * 1) at least one source buffer has to be queued,
196 * 2) at least one destination buffer has to be queued,
197 * 3) streaming has to be on.
199 * There may also be additional, custom requirements. In such case the driver
200 * should supply a custom callback (job_ready in v4l2_m2m_ops) that should
201 * return 1 if the instance is ready.
202 * An example of the above could be an instance that requires more than one
203 * src/dst buffer per transaction.
205 static void v4l2_m2m_try_schedule(struct v4l2_m2m_ctx *m2m_ctx)
207 struct v4l2_m2m_dev *m2m_dev;
208 unsigned long flags_job, flags;
210 m2m_dev = m2m_ctx->m2m_dev;
211 dprintk("Trying to schedule a job for m2m_ctx: %p\n", m2m_ctx);
213 if (!m2m_ctx->out_q_ctx.q.streaming
214 || !m2m_ctx->cap_q_ctx.q.streaming) {
215 dprintk("Streaming needs to be on for both queues\n");
216 return;
219 spin_lock_irqsave(&m2m_dev->job_spinlock, flags_job);
220 if (m2m_ctx->job_flags & TRANS_QUEUED) {
221 spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags_job);
222 dprintk("On job queue already\n");
223 return;
226 spin_lock_irqsave(&m2m_ctx->out_q_ctx.rdy_spinlock, flags);
227 if (list_empty(&m2m_ctx->out_q_ctx.rdy_queue)) {
228 spin_unlock_irqrestore(&m2m_ctx->out_q_ctx.rdy_spinlock, flags);
229 spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags_job);
230 dprintk("No input buffers available\n");
231 return;
233 if (list_empty(&m2m_ctx->cap_q_ctx.rdy_queue)) {
234 spin_unlock_irqrestore(&m2m_ctx->out_q_ctx.rdy_spinlock, flags);
235 spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags_job);
236 dprintk("No output buffers available\n");
237 return;
239 spin_unlock_irqrestore(&m2m_ctx->out_q_ctx.rdy_spinlock, flags);
241 if (m2m_dev->m2m_ops->job_ready
242 && (!m2m_dev->m2m_ops->job_ready(m2m_ctx->priv))) {
243 spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags_job);
244 dprintk("Driver not ready\n");
245 return;
248 list_add_tail(&m2m_ctx->queue, &m2m_dev->job_queue);
249 m2m_ctx->job_flags |= TRANS_QUEUED;
251 spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags_job);
253 v4l2_m2m_try_run(m2m_dev);
257 * v4l2_m2m_job_finish() - inform the framework that a job has been finished
258 * and have it clean up
260 * Called by a driver to yield back the device after it has finished with it.
261 * Should be called as soon as possible after reaching a state which allows
262 * other instances to take control of the device.
264 * This function has to be called only after device_run() callback has been
265 * called on the driver. To prevent recursion, it should not be called directly
266 * from the device_run() callback though.
268 void v4l2_m2m_job_finish(struct v4l2_m2m_dev *m2m_dev,
269 struct v4l2_m2m_ctx *m2m_ctx)
271 unsigned long flags;
273 spin_lock_irqsave(&m2m_dev->job_spinlock, flags);
274 if (!m2m_dev->curr_ctx || m2m_dev->curr_ctx != m2m_ctx) {
275 spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
276 dprintk("Called by an instance not currently running\n");
277 return;
280 list_del(&m2m_dev->curr_ctx->queue);
281 m2m_dev->curr_ctx->job_flags &= ~(TRANS_QUEUED | TRANS_RUNNING);
282 wake_up(&m2m_dev->curr_ctx->finished);
283 m2m_dev->curr_ctx = NULL;
285 spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
287 /* This instance might have more buffers ready, but since we do not
288 * allow more than one job on the job_queue per instance, each has
289 * to be scheduled separately after the previous one finishes. */
290 v4l2_m2m_try_schedule(m2m_ctx);
291 v4l2_m2m_try_run(m2m_dev);
293 EXPORT_SYMBOL(v4l2_m2m_job_finish);
296 * v4l2_m2m_reqbufs() - multi-queue-aware REQBUFS multiplexer
298 int v4l2_m2m_reqbufs(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
299 struct v4l2_requestbuffers *reqbufs)
301 struct vb2_queue *vq;
303 vq = v4l2_m2m_get_vq(m2m_ctx, reqbufs->type);
304 return vb2_reqbufs(vq, reqbufs);
306 EXPORT_SYMBOL_GPL(v4l2_m2m_reqbufs);
309 * v4l2_m2m_querybuf() - multi-queue-aware QUERYBUF multiplexer
311 * See v4l2_m2m_mmap() documentation for details.
313 int v4l2_m2m_querybuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
314 struct v4l2_buffer *buf)
316 struct vb2_queue *vq;
317 int ret = 0;
318 unsigned int i;
320 vq = v4l2_m2m_get_vq(m2m_ctx, buf->type);
321 ret = vb2_querybuf(vq, buf);
323 /* Adjust MMAP memory offsets for the CAPTURE queue */
324 if (buf->memory == V4L2_MEMORY_MMAP && !V4L2_TYPE_IS_OUTPUT(vq->type)) {
325 if (V4L2_TYPE_IS_MULTIPLANAR(vq->type)) {
326 for (i = 0; i < buf->length; ++i)
327 buf->m.planes[i].m.mem_offset
328 += DST_QUEUE_OFF_BASE;
329 } else {
330 buf->m.offset += DST_QUEUE_OFF_BASE;
334 return ret;
336 EXPORT_SYMBOL_GPL(v4l2_m2m_querybuf);
339 * v4l2_m2m_qbuf() - enqueue a source or destination buffer, depending on
340 * the type
342 int v4l2_m2m_qbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
343 struct v4l2_buffer *buf)
345 struct vb2_queue *vq;
346 int ret;
348 vq = v4l2_m2m_get_vq(m2m_ctx, buf->type);
349 ret = vb2_qbuf(vq, buf);
350 if (!ret)
351 v4l2_m2m_try_schedule(m2m_ctx);
353 return ret;
355 EXPORT_SYMBOL_GPL(v4l2_m2m_qbuf);
358 * v4l2_m2m_dqbuf() - dequeue a source or destination buffer, depending on
359 * the type
361 int v4l2_m2m_dqbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
362 struct v4l2_buffer *buf)
364 struct vb2_queue *vq;
366 vq = v4l2_m2m_get_vq(m2m_ctx, buf->type);
367 return vb2_dqbuf(vq, buf, file->f_flags & O_NONBLOCK);
369 EXPORT_SYMBOL_GPL(v4l2_m2m_dqbuf);
372 * v4l2_m2m_expbuf() - export a source or destination buffer, depending on
373 * the type
375 int v4l2_m2m_expbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
376 struct v4l2_exportbuffer *eb)
378 struct vb2_queue *vq;
380 vq = v4l2_m2m_get_vq(m2m_ctx, eb->type);
381 return vb2_expbuf(vq, eb);
383 EXPORT_SYMBOL_GPL(v4l2_m2m_expbuf);
385 * v4l2_m2m_streamon() - turn on streaming for a video queue
387 int v4l2_m2m_streamon(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
388 enum v4l2_buf_type type)
390 struct vb2_queue *vq;
391 int ret;
393 vq = v4l2_m2m_get_vq(m2m_ctx, type);
394 ret = vb2_streamon(vq, type);
395 if (!ret)
396 v4l2_m2m_try_schedule(m2m_ctx);
398 return ret;
400 EXPORT_SYMBOL_GPL(v4l2_m2m_streamon);
403 * v4l2_m2m_streamoff() - turn off streaming for a video queue
405 int v4l2_m2m_streamoff(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
406 enum v4l2_buf_type type)
408 struct vb2_queue *vq;
410 vq = v4l2_m2m_get_vq(m2m_ctx, type);
411 return vb2_streamoff(vq, type);
413 EXPORT_SYMBOL_GPL(v4l2_m2m_streamoff);
416 * v4l2_m2m_poll() - poll replacement, for destination buffers only
418 * Call from the driver's poll() function. Will poll both queues. If a buffer
419 * is available to dequeue (with dqbuf) from the source queue, this will
420 * indicate that a non-blocking write can be performed, while read will be
421 * returned in case of the destination queue.
423 unsigned int v4l2_m2m_poll(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
424 struct poll_table_struct *wait)
426 struct video_device *vfd = video_devdata(file);
427 unsigned long req_events = poll_requested_events(wait);
428 struct vb2_queue *src_q, *dst_q;
429 struct vb2_buffer *src_vb = NULL, *dst_vb = NULL;
430 unsigned int rc = 0;
431 unsigned long flags;
433 if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) {
434 struct v4l2_fh *fh = file->private_data;
436 if (v4l2_event_pending(fh))
437 rc = POLLPRI;
438 else if (req_events & POLLPRI)
439 poll_wait(file, &fh->wait, wait);
440 if (!(req_events & (POLLOUT | POLLWRNORM | POLLIN | POLLRDNORM)))
441 return rc;
444 src_q = v4l2_m2m_get_src_vq(m2m_ctx);
445 dst_q = v4l2_m2m_get_dst_vq(m2m_ctx);
448 * There has to be at least one buffer queued on each queued_list, which
449 * means either in driver already or waiting for driver to claim it
450 * and start processing.
452 if ((!src_q->streaming || list_empty(&src_q->queued_list))
453 && (!dst_q->streaming || list_empty(&dst_q->queued_list))) {
454 rc |= POLLERR;
455 goto end;
458 if (m2m_ctx->m2m_dev->m2m_ops->unlock)
459 m2m_ctx->m2m_dev->m2m_ops->unlock(m2m_ctx->priv);
461 poll_wait(file, &src_q->done_wq, wait);
462 poll_wait(file, &dst_q->done_wq, wait);
464 if (m2m_ctx->m2m_dev->m2m_ops->lock)
465 m2m_ctx->m2m_dev->m2m_ops->lock(m2m_ctx->priv);
467 spin_lock_irqsave(&src_q->done_lock, flags);
468 if (!list_empty(&src_q->done_list))
469 src_vb = list_first_entry(&src_q->done_list, struct vb2_buffer,
470 done_entry);
471 if (src_vb && (src_vb->state == VB2_BUF_STATE_DONE
472 || src_vb->state == VB2_BUF_STATE_ERROR))
473 rc |= POLLOUT | POLLWRNORM;
474 spin_unlock_irqrestore(&src_q->done_lock, flags);
476 spin_lock_irqsave(&dst_q->done_lock, flags);
477 if (!list_empty(&dst_q->done_list))
478 dst_vb = list_first_entry(&dst_q->done_list, struct vb2_buffer,
479 done_entry);
480 if (dst_vb && (dst_vb->state == VB2_BUF_STATE_DONE
481 || dst_vb->state == VB2_BUF_STATE_ERROR))
482 rc |= POLLIN | POLLRDNORM;
483 spin_unlock_irqrestore(&dst_q->done_lock, flags);
485 end:
486 return rc;
488 EXPORT_SYMBOL_GPL(v4l2_m2m_poll);
491 * v4l2_m2m_mmap() - source and destination queues-aware mmap multiplexer
493 * Call from driver's mmap() function. Will handle mmap() for both queues
494 * seamlessly for videobuffer, which will receive normal per-queue offsets and
495 * proper videobuf queue pointers. The differentiation is made outside videobuf
496 * by adding a predefined offset to buffers from one of the queues and
497 * subtracting it before passing it back to videobuf. Only drivers (and
498 * thus applications) receive modified offsets.
500 int v4l2_m2m_mmap(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
501 struct vm_area_struct *vma)
503 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
504 struct vb2_queue *vq;
506 if (offset < DST_QUEUE_OFF_BASE) {
507 vq = v4l2_m2m_get_src_vq(m2m_ctx);
508 } else {
509 vq = v4l2_m2m_get_dst_vq(m2m_ctx);
510 vma->vm_pgoff -= (DST_QUEUE_OFF_BASE >> PAGE_SHIFT);
513 return vb2_mmap(vq, vma);
515 EXPORT_SYMBOL(v4l2_m2m_mmap);
518 * v4l2_m2m_init() - initialize per-driver m2m data
520 * Usually called from driver's probe() function.
522 struct v4l2_m2m_dev *v4l2_m2m_init(const struct v4l2_m2m_ops *m2m_ops)
524 struct v4l2_m2m_dev *m2m_dev;
526 if (!m2m_ops || WARN_ON(!m2m_ops->device_run) ||
527 WARN_ON(!m2m_ops->job_abort))
528 return ERR_PTR(-EINVAL);
530 m2m_dev = kzalloc(sizeof *m2m_dev, GFP_KERNEL);
531 if (!m2m_dev)
532 return ERR_PTR(-ENOMEM);
534 m2m_dev->curr_ctx = NULL;
535 m2m_dev->m2m_ops = m2m_ops;
536 INIT_LIST_HEAD(&m2m_dev->job_queue);
537 spin_lock_init(&m2m_dev->job_spinlock);
539 return m2m_dev;
541 EXPORT_SYMBOL_GPL(v4l2_m2m_init);
544 * v4l2_m2m_release() - cleans up and frees a m2m_dev structure
546 * Usually called from driver's remove() function.
548 void v4l2_m2m_release(struct v4l2_m2m_dev *m2m_dev)
550 kfree(m2m_dev);
552 EXPORT_SYMBOL_GPL(v4l2_m2m_release);
555 * v4l2_m2m_ctx_init() - allocate and initialize a m2m context
556 * @priv - driver's instance private data
557 * @m2m_dev - a previously initialized m2m_dev struct
558 * @vq_init - a callback for queue type-specific initialization function to be
559 * used for initializing videobuf_queues
561 * Usually called from driver's open() function.
563 struct v4l2_m2m_ctx *v4l2_m2m_ctx_init(struct v4l2_m2m_dev *m2m_dev,
564 void *drv_priv,
565 int (*queue_init)(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq))
567 struct v4l2_m2m_ctx *m2m_ctx;
568 struct v4l2_m2m_queue_ctx *out_q_ctx, *cap_q_ctx;
569 int ret;
571 m2m_ctx = kzalloc(sizeof *m2m_ctx, GFP_KERNEL);
572 if (!m2m_ctx)
573 return ERR_PTR(-ENOMEM);
575 m2m_ctx->priv = drv_priv;
576 m2m_ctx->m2m_dev = m2m_dev;
577 init_waitqueue_head(&m2m_ctx->finished);
579 out_q_ctx = &m2m_ctx->out_q_ctx;
580 cap_q_ctx = &m2m_ctx->cap_q_ctx;
582 INIT_LIST_HEAD(&out_q_ctx->rdy_queue);
583 INIT_LIST_HEAD(&cap_q_ctx->rdy_queue);
584 spin_lock_init(&out_q_ctx->rdy_spinlock);
585 spin_lock_init(&cap_q_ctx->rdy_spinlock);
587 INIT_LIST_HEAD(&m2m_ctx->queue);
589 ret = queue_init(drv_priv, &out_q_ctx->q, &cap_q_ctx->q);
591 if (ret)
592 goto err;
594 return m2m_ctx;
595 err:
596 kfree(m2m_ctx);
597 return ERR_PTR(ret);
599 EXPORT_SYMBOL_GPL(v4l2_m2m_ctx_init);
602 * v4l2_m2m_ctx_release() - release m2m context
604 * Usually called from driver's release() function.
606 void v4l2_m2m_ctx_release(struct v4l2_m2m_ctx *m2m_ctx)
608 struct v4l2_m2m_dev *m2m_dev;
609 unsigned long flags;
611 m2m_dev = m2m_ctx->m2m_dev;
613 spin_lock_irqsave(&m2m_dev->job_spinlock, flags);
614 if (m2m_ctx->job_flags & TRANS_RUNNING) {
615 spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
616 m2m_dev->m2m_ops->job_abort(m2m_ctx->priv);
617 dprintk("m2m_ctx %p running, will wait to complete", m2m_ctx);
618 wait_event(m2m_ctx->finished, !(m2m_ctx->job_flags & TRANS_RUNNING));
619 } else if (m2m_ctx->job_flags & TRANS_QUEUED) {
620 list_del(&m2m_ctx->queue);
621 m2m_ctx->job_flags &= ~(TRANS_QUEUED | TRANS_RUNNING);
622 spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
623 dprintk("m2m_ctx: %p had been on queue and was removed\n",
624 m2m_ctx);
625 } else {
626 /* Do nothing, was not on queue/running */
627 spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
630 vb2_queue_release(&m2m_ctx->cap_q_ctx.q);
631 vb2_queue_release(&m2m_ctx->out_q_ctx.q);
633 kfree(m2m_ctx);
635 EXPORT_SYMBOL_GPL(v4l2_m2m_ctx_release);
638 * v4l2_m2m_buf_queue() - add a buffer to the proper ready buffers list.
640 * Call from buf_queue(), videobuf_queue_ops callback.
642 void v4l2_m2m_buf_queue(struct v4l2_m2m_ctx *m2m_ctx, struct vb2_buffer *vb)
644 struct v4l2_m2m_buffer *b = container_of(vb, struct v4l2_m2m_buffer, vb);
645 struct v4l2_m2m_queue_ctx *q_ctx;
646 unsigned long flags;
648 q_ctx = get_queue_ctx(m2m_ctx, vb->vb2_queue->type);
649 if (!q_ctx)
650 return;
652 spin_lock_irqsave(&q_ctx->rdy_spinlock, flags);
653 list_add_tail(&b->list, &q_ctx->rdy_queue);
654 q_ctx->num_rdy++;
655 spin_unlock_irqrestore(&q_ctx->rdy_spinlock, flags);
657 EXPORT_SYMBOL_GPL(v4l2_m2m_buf_queue);