kernel: bump 5.4 to 5.4.36
[openwrt/staging/wigyori.git] / target / linux / bcm27xx / patches-5.4 / 950-0500-media-v4l2-mem2mem-add-stateless_-try_-decoder_cmd-i.patch
1 From 1decb017f990ea61ab421e316bf1af3a5199b73a Mon Sep 17 00:00:00 2001
2 From: Jernej Skrabec <jernej.skrabec@siol.net>
3 Date: Fri, 11 Oct 2019 06:32:43 -0300
4 Subject: [PATCH] media: v4l2-mem2mem: add stateless_(try_)decoder_cmd
5 ioctl helpers
6
7 Commit bef41d93aac64b54c3008ca6170bec54f85784f5 upstream.
8
9 These helpers are used by stateless codecs when they support multiple
10 slices per frame and hold capture buffer flag is set. It's expected that
11 all such codecs will use this code.
12
13 Signed-off-by: Jernej Skrabec <jernej.skrabec@siol.net>
14 Co-developed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
15 Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
16 Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
17 ---
18 drivers/media/v4l2-core/v4l2-mem2mem.c | 53 ++++++++++++++++++++++++++
19 include/media/v4l2-mem2mem.h | 4 ++
20 2 files changed, 57 insertions(+)
21
22 --- a/drivers/media/v4l2-core/v4l2-mem2mem.c
23 +++ b/drivers/media/v4l2-core/v4l2-mem2mem.c
24 @@ -1218,6 +1218,59 @@ int v4l2_m2m_ioctl_try_decoder_cmd(struc
25 }
26 EXPORT_SYMBOL_GPL(v4l2_m2m_ioctl_try_decoder_cmd);
27
28 +int v4l2_m2m_ioctl_stateless_try_decoder_cmd(struct file *file, void *fh,
29 + struct v4l2_decoder_cmd *dc)
30 +{
31 + if (dc->cmd != V4L2_DEC_CMD_FLUSH)
32 + return -EINVAL;
33 +
34 + dc->flags = 0;
35 +
36 + return 0;
37 +}
38 +EXPORT_SYMBOL_GPL(v4l2_m2m_ioctl_stateless_try_decoder_cmd);
39 +
40 +int v4l2_m2m_ioctl_stateless_decoder_cmd(struct file *file, void *priv,
41 + struct v4l2_decoder_cmd *dc)
42 +{
43 + struct v4l2_fh *fh = file->private_data;
44 + struct vb2_v4l2_buffer *out_vb, *cap_vb;
45 + struct v4l2_m2m_dev *m2m_dev = fh->m2m_ctx->m2m_dev;
46 + unsigned long flags;
47 + int ret;
48 +
49 + ret = v4l2_m2m_ioctl_stateless_try_decoder_cmd(file, priv, dc);
50 + if (ret < 0)
51 + return ret;
52 +
53 + spin_lock_irqsave(&m2m_dev->job_spinlock, flags);
54 + out_vb = v4l2_m2m_last_src_buf(fh->m2m_ctx);
55 + cap_vb = v4l2_m2m_last_dst_buf(fh->m2m_ctx);
56 +
57 + /*
58 + * If there is an out buffer pending, then clear any HOLD flag.
59 + *
60 + * By clearing this flag we ensure that when this output
61 + * buffer is processed any held capture buffer will be released.
62 + */
63 + if (out_vb) {
64 + out_vb->flags &= ~V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF;
65 + } else if (cap_vb && cap_vb->is_held) {
66 + /*
67 + * If there were no output buffers, but there is a
68 + * capture buffer that is held, then release that
69 + * buffer.
70 + */
71 + cap_vb->is_held = false;
72 + v4l2_m2m_dst_buf_remove(fh->m2m_ctx);
73 + v4l2_m2m_buf_done(cap_vb, VB2_BUF_STATE_DONE);
74 + }
75 + spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
76 +
77 + return 0;
78 +}
79 +EXPORT_SYMBOL_GPL(v4l2_m2m_ioctl_stateless_decoder_cmd);
80 +
81 /*
82 * v4l2_file_operations helpers. It is assumed here same lock is used
83 * for the output and the capture buffer queue.
84 --- a/include/media/v4l2-mem2mem.h
85 +++ b/include/media/v4l2-mem2mem.h
86 @@ -701,6 +701,10 @@ int v4l2_m2m_ioctl_try_encoder_cmd(struc
87 struct v4l2_encoder_cmd *ec);
88 int v4l2_m2m_ioctl_try_decoder_cmd(struct file *file, void *fh,
89 struct v4l2_decoder_cmd *dc);
90 +int v4l2_m2m_ioctl_stateless_try_decoder_cmd(struct file *file, void *fh,
91 + struct v4l2_decoder_cmd *dc);
92 +int v4l2_m2m_ioctl_stateless_decoder_cmd(struct file *file, void *priv,
93 + struct v4l2_decoder_cmd *dc);
94 int v4l2_m2m_fop_mmap(struct file *file, struct vm_area_struct *vma);
95 __poll_t v4l2_m2m_fop_poll(struct file *file, poll_table *wait);
96