16 #include <linux/module.h>
17 #include <linux/sched.h>
18 #include <linux/slab.h>
33 #define dprintk(fmt, arg...) \
36 printk(KERN_DEBUG "%s: " fmt, __func__, ## arg);\
41 #define TRANS_QUEUED (1 << 0)
43 #define TRANS_RUNNING (1 << 1)
49 #define DST_QUEUE_OFF_BASE (1 << 30)
85 q_ctx = get_queue_ctx(m2m_ctx, type);
164 static void v4l2_m2m_try_run(
struct v4l2_m2m_dev *m2m_dev)
171 dprintk(
"Another instance is running, won't run now\n");
205 static void v4l2_m2m_try_schedule(
struct v4l2_m2m_ctx *m2m_ctx)
208 unsigned long flags_job,
flags;
211 dprintk(
"Trying to schedule a job for m2m_ctx: %p\n", m2m_ctx);
215 dprintk(
"Streaming needs to be on for both queues\n");
221 spin_unlock_irqrestore(&m2m_dev->
job_spinlock, flags_job);
222 dprintk(
"On job queue already\n");
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");
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");
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);
251 spin_unlock_irqrestore(&m2m_dev->
job_spinlock, flags_job);
253 v4l2_m2m_try_run(m2m_dev);
276 dprintk(
"Called by an instance not currently running\n");
290 v4l2_m2m_try_schedule(m2m_ctx);
291 v4l2_m2m_try_run(m2m_dev);
326 for (i = 0; i < buf->
length; ++
i)
351 v4l2_m2m_try_schedule(m2m_ctx);
383 v4l2_m2m_try_schedule(m2m_ctx);
414 unsigned long req_events = poll_requested_events(wait);
426 poll_wait(file, &fh->
wait, wait);
431 src_q = v4l2_m2m_get_src_vq(m2m_ctx);
432 dst_q = v4l2_m2m_get_dst_vq(m2m_ctx);
445 if (m2m_ctx->
m2m_dev->m2m_ops->unlock)
448 poll_wait(file, &src_q->
done_wq, wait);
449 poll_wait(file, &dst_q->
done_wq, wait);
451 if (m2m_ctx->
m2m_dev->m2m_ops->lock)
461 spin_unlock_irqrestore(&src_q->
done_lock, flags);
470 spin_unlock_irqrestore(&dst_q->
done_lock, flags);
494 vq = v4l2_m2m_get_src_vq(m2m_ctx);
496 vq = v4l2_m2m_get_dst_vq(m2m_ctx);
519 m2m_dev = kzalloc(
sizeof *m2m_dev,
GFP_KERNEL);
560 m2m_ctx = kzalloc(
sizeof *m2m_ctx,
GFP_KERNEL);
564 m2m_ctx->
priv = drv_priv;
576 INIT_LIST_HEAD(&m2m_ctx->
queue);
578 ret = queue_init(drv_priv, &out_q_ctx->
q, &cap_q_ctx->
q);
606 dprintk(
"m2m_ctx %p running, will wait to complete", m2m_ctx);
612 dprintk(
"m2m_ctx: %p had been on queue and was removed\n",
637 q_ctx = get_queue_ctx(m2m_ctx, vb->
vb2_queue->type);