1 From 754a5ed1aa42ce9d5be5f84a5a0888f850b15e00 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 252/703] 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 | 22 ++++++++++++++-----
15 .../vc04_services/bcm2835-camera/mmal-vchiq.c | 4 ++++
16 .../vc04_services/bcm2835-camera/mmal-vchiq.h | 3 +++
17 3 files changed, 23 insertions(+), 6 deletions(-)
19 --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
20 +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
21 @@ -607,6 +607,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 @@ -630,12 +631,6 @@ static void stop_streaming(struct vb2_qu
30 &dev->capture.frame_count,
31 sizeof(dev->capture.frame_count));
33 - /* wait for last frame to complete */
34 - timeout = wait_for_completion_timeout(&dev->capture.frame_cmplt, HZ);
36 - v4l2_err(&dev->v4l2_dev,
37 - "timed out waiting for frame completion\n");
39 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
40 "disabling connection\n");
42 @@ -650,6 +645,21 @@ static void stop_streaming(struct vb2_qu
46 + /* wait for all buffers to be returned */
47 + while (atomic_read(&port->buffers_with_vpu)) {
48 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
49 + "%s: Waiting for buffers to be returned - %d outstanding\n",
50 + __func__, atomic_read(&port->buffers_with_vpu));
51 + timeout = wait_for_completion_timeout(&dev->capture.frame_cmplt,
54 + v4l2_err(&dev->v4l2_dev, "%s: Timeout waiting for buffers to be returned - %d outstanding\n",
56 + atomic_read(&port->buffers_with_vpu));
61 if (disable_camera(dev) < 0)
62 v4l2_err(&dev->v4l2_dev, "Failed to disable camera\n");
64 --- a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
65 +++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
66 @@ -246,6 +246,8 @@ static void buffer_work_cb(struct work_s
67 struct mmal_msg_context *msg_context =
68 container_of(work, struct mmal_msg_context, u.bulk.work);
70 + atomic_dec(&msg_context->u.bulk.port->buffers_with_vpu);
72 msg_context->u.bulk.port->buffer_cb(msg_context->u.bulk.instance,
73 msg_context->u.bulk.port,
74 msg_context->u.bulk.status,
75 @@ -389,6 +391,8 @@ buffer_from_host(struct vchiq_mmal_insta
76 INIT_WORK(&msg_context->u.bulk.buffer_to_host_work,
77 buffer_to_host_work_cb);
79 + atomic_inc(&port->buffers_with_vpu);
81 /* prep the buffer from host message */
82 memset(&m, 0xbc, sizeof(m)); /* just to make debug clearer */
84 --- a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.h
85 +++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.h
86 @@ -72,6 +72,9 @@ struct vchiq_mmal_port {
87 struct list_head buffers;
88 /* lock to serialise adding and removing buffers from list */
91 + /* Count of buffers the VPU has yet to return */
92 + atomic_t buffers_with_vpu;
93 /* callback on buffer completion */
94 vchiq_mmal_buffer_cb buffer_cb;
95 /* callback context */