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
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.
11 Signal the completion when the last buffer is returned.
13 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
15 .../bcm2835-codec/bcm2835-v4l2-codec.c | 20 ++++++++++++++-----
16 1 file changed, 15 insertions(+), 5 deletions(-)
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);
25 + if (!port->enabled && atomic_read(&port->buffers_with_vpu))
26 complete(&ctx->frame_cmplt);
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);
34 + if (!port->enabled &&
35 + atomic_read(&port->buffers_with_vpu))
36 complete(&ctx->frame_cmplt);
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);
44 + if (!port->enabled && atomic_read(&port->buffers_with_vpu))
45 complete(&ctx->frame_cmplt);
48 @@ -1596,6 +1597,8 @@ static int vidioc_s_fmt(struct bcm2835_c
52 + unsigned int num_buffers;
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));
62 + * Disable will reread the port format, so retain buffer count.
64 + num_buffers = port->current_buffer.num;
66 ret = vchiq_mmal_port_disable(ctx->dev->instance, port);
68 v4l2_err(&ctx->dev->v4l2_dev, "%s: Error disabling port update buffer count, ret %d\n",
71 + port->current_buffer.num = num_buffers;
76 @@ -2787,7 +2798,7 @@ static void bcm2835_codec_flush_buffers(
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",
88 atomic_read(&port->buffers_with_vpu));