bcm27xx: add support for linux v5.15
[openwrt/staging/chunkeey.git] / target / linux / bcm27xx / patches-5.15 / 950-0511-staging-bcm2835_codec-Correct-flushing-code-for-refc.patch
1 From cd850cb03a564c948db4db8cac672284c55cefc3 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Wed, 22 Sep 2021 16:42:49 +0100
4 Subject: [PATCH] staging: bcm2835_codec: Correct flushing code for
5 refcounting
6
7 Completions don't reference count, so setting the completion
8 on the first buffer returned and then not reinitialising it
9 means that the flush function doesn't behave as intended.
10
11 Signal the completion when the last buffer is returned.
12
13 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
14 ---
15 .../bcm2835-codec/bcm2835-v4l2-codec.c | 20 ++++++++++++++-----
16 1 file changed, 15 insertions(+), 5 deletions(-)
17
18 --- a/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c
19 +++ b/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c
20 @@ -934,7 +934,7 @@ static void ip_buffer_cb(struct vchiq_mm
21 v4l2_dbg(2, debug, &ctx->dev->v4l2_dev, "%s: done %d input buffers\n",
22 __func__, ctx->num_ip_buffers);
23
24 - if (!port->enabled)
25 + if (!port->enabled && atomic_read(&port->buffers_with_vpu))
26 complete(&ctx->frame_cmplt);
27 }
28
29 @@ -1135,7 +1135,8 @@ static void op_buffer_cb(struct vchiq_mm
30 __func__, mmal_buf->mmal_flags);
31 if (!(mmal_buf->mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS)) {
32 vb2_buffer_done(&vb2->vb2_buf, VB2_BUF_STATE_QUEUED);
33 - if (!port->enabled)
34 + if (!port->enabled &&
35 + atomic_read(&port->buffers_with_vpu))
36 complete(&ctx->frame_cmplt);
37 return;
38 }
39 @@ -1178,7 +1179,7 @@ static void op_buffer_cb(struct vchiq_mm
40 v4l2_dbg(2, debug, &ctx->dev->v4l2_dev, "%s: done %d output buffers\n",
41 __func__, ctx->num_op_buffers);
42
43 - if (!port->enabled)
44 + if (!port->enabled && atomic_read(&port->buffers_with_vpu))
45 complete(&ctx->frame_cmplt);
46 }
47
48 @@ -1596,6 +1597,8 @@ static int vidioc_s_fmt(struct bcm2835_c
49 return 0;
50
51 if (port->enabled) {
52 + unsigned int num_buffers;
53 +
54 /*
55 * This should only ever happen with DECODE and the MMAL output
56 * port that has been enabled for resolution changed events.
57 @@ -1606,10 +1609,18 @@ static int vidioc_s_fmt(struct bcm2835_c
58 f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ||
59 atomic_read(&port->buffers_with_vpu));
60
61 + /*
62 + * Disable will reread the port format, so retain buffer count.
63 + */
64 + num_buffers = port->current_buffer.num;
65 +
66 ret = vchiq_mmal_port_disable(ctx->dev->instance, port);
67 if (ret)
68 v4l2_err(&ctx->dev->v4l2_dev, "%s: Error disabling port update buffer count, ret %d\n",
69 __func__, ret);
70 +
71 + port->current_buffer.num = num_buffers;
72 +
73 reenable_port = true;
74 }
75
76 @@ -2787,7 +2798,7 @@ static void bcm2835_codec_flush_buffers(
77 {
78 int ret;
79
80 - while (atomic_read(&port->buffers_with_vpu)) {
81 + if (atomic_read(&port->buffers_with_vpu)) {
82 v4l2_dbg(1, debug, &ctx->dev->v4l2_dev, "%s: Waiting for buffers to be returned - %d outstanding\n",
83 __func__, atomic_read(&port->buffers_with_vpu));
84 ret = wait_for_completion_timeout(&ctx->frame_cmplt,
85 @@ -2796,7 +2807,6 @@ static void bcm2835_codec_flush_buffers(
86 v4l2_err(&ctx->dev->v4l2_dev, "%s: Timeout waiting for buffers to be returned - %d outstanding\n",
87 __func__,
88 atomic_read(&port->buffers_with_vpu));
89 - break;
90 }
91 }
92 }