1 From 13e015450812772f21c874dd310abe3379b87bb5 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.org>
3 Date: Thu, 28 Jun 2018 15:57:25 +0100
4 Subject: [PATCH 404/454] staging: bcm2835_camera: Ensure all buffers are
7 With the recent change to match MMAL and V4L2 buffers there
8 is a need to wait for all MMAL buffers to be returned during
11 Fixes: 9384167 "staging: bcm2835-camera: Remove V4L2/MMAL buffer remapping"
12 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
14 .../bcm2835-camera/bcm2835-camera.c | 16 ++++++++++++++++
15 .../vc04_services/bcm2835-camera/mmal-vchiq.c | 4 ++++
16 .../vc04_services/bcm2835-camera/mmal-vchiq.h | 3 +++
17 3 files changed, 23 insertions(+)
19 --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
20 +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
21 @@ -615,6 +615,7 @@ static void stop_streaming(struct vb2_qu
23 unsigned long timeout;
24 struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
25 + struct vchiq_mmal_port *port = dev->capture.port;
27 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
29 @@ -658,6 +659,21 @@ static void stop_streaming(struct vb2_qu
33 + /* wait for all buffers to be returned */
34 + while (atomic_read(&port->buffers_with_vpu)) {
35 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
36 + "%s: Waiting for buffers to be returned - %d outstanding\n",
37 + __func__, atomic_read(&port->buffers_with_vpu));
38 + ret = wait_for_completion_timeout(&dev->capture.frame_cmplt,
41 + v4l2_err(&dev->v4l2_dev, "%s: Timeout waiting for buffers to be returned - %d outstanding\n",
43 + atomic_read(&port->buffers_with_vpu));
48 if (disable_camera(dev) < 0)
49 v4l2_err(&dev->v4l2_dev, "Failed to disable camera\n");
51 --- a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
52 +++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
53 @@ -318,6 +318,8 @@ static void buffer_work_cb(struct work_s
54 struct mmal_msg_context *msg_context =
55 container_of(work, struct mmal_msg_context, u.bulk.work);
57 + atomic_dec(&msg_context->u.bulk.port->buffers_with_vpu);
59 msg_context->u.bulk.port->buffer_cb(msg_context->u.bulk.instance,
60 msg_context->u.bulk.port,
61 msg_context->u.bulk.status,
62 @@ -461,6 +463,8 @@ buffer_from_host(struct vchiq_mmal_insta
63 INIT_WORK(&msg_context->u.bulk.buffer_to_host_work,
64 buffer_to_host_work_cb);
66 + atomic_inc(&port->buffers_with_vpu);
68 /* prep the buffer from host message */
69 memset(&m, 0xbc, sizeof(m)); /* just to make debug clearer */
71 --- a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.h
72 +++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.h
73 @@ -75,6 +75,9 @@ struct vchiq_mmal_port {
74 struct list_head buffers;
75 /* lock to serialise adding and removing buffers from list */
78 + /* Count of buffers the VPU has yet to return */
79 + atomic_t buffers_with_vpu;
80 /* callback on buffer completion */
81 vchiq_mmal_buffer_cb buffer_cb;
82 /* callback context */