b2d7b8608aea01f2902c1e971ddb99da2212d6ce
[openwrt/staging/jow.git] /
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
5 returned on disable
6
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
9 stop_streaming.
10
11 Fixes: 9384167 "staging: bcm2835-camera: Remove V4L2/MMAL buffer remapping"
12 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
13 ---
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(+)
18
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
22 int ret;
23 unsigned long timeout;
24 struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
25 + struct vchiq_mmal_port *port = dev->capture.port;
26
27 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
28 __func__, dev);
29 @@ -658,6 +659,21 @@ static void stop_streaming(struct vb2_qu
30 ret);
31 }
32
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,
39 + HZ);
40 + if (ret <= 0) {
41 + v4l2_err(&dev->v4l2_dev, "%s: Timeout waiting for buffers to be returned - %d outstanding\n",
42 + __func__,
43 + atomic_read(&port->buffers_with_vpu));
44 + break;
45 + }
46 + }
47 +
48 if (disable_camera(dev) < 0)
49 v4l2_err(&dev->v4l2_dev, "Failed to disable camera\n");
50 }
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);
56
57 + atomic_dec(&msg_context->u.bulk.port->buffers_with_vpu);
58 +
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);
65
66 + atomic_inc(&port->buffers_with_vpu);
67 +
68 /* prep the buffer from host message */
69 memset(&m, 0xbc, sizeof(m)); /* just to make debug clearer */
70
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 */
76 spinlock_t slock;
77 +
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 */