c933bcc7a2c0c9f149c9209822d6ae99362d23a0
[openwrt/staging/jow.git] /
1 From f36097b9766ff3f61c21d1fd29e75ddd3844a533 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.org>
3 Date: Thu, 10 May 2018 12:42:08 -0700
4 Subject: [PATCH 368/454] staging: bcm2835-camera: Allocate context once per
5 buffer
6
7 commit 96b7e81ab6b74e7cefdac0d7a90b746ef7f8597d upstream.
8
9 The struct mmal_msg_context was being allocated for every message
10 being sent to the VPU, and freed when it came back. Whilst that is
11 required behaviour for some messages (mainly the synchronous ones), it
12 is wasteful for the video buffers that make up the majority of the
13 traffic.
14
15 Add to the buffer_init/cleanup hooks that it allocates/frees the
16 msg_context required.
17
18 v2: changes by anholt from the downstream tree: clean up indentation,
19 pass an error value through, forward-declare the struct so we have
20 less void *
21
22 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
23 Signed-off-by: Eric Anholt <eric@anholt.net>
24 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
25 ---
26 .../bcm2835-camera/bcm2835-camera.c | 30 +++++++++++++--
27 .../bcm2835-camera/mmal-common.h | 4 ++
28 .../vc04_services/bcm2835-camera/mmal-vchiq.c | 38 ++++++++++++++-----
29 .../vc04_services/bcm2835-camera/mmal-vchiq.h | 3 ++
30 4 files changed, 62 insertions(+), 13 deletions(-)
31
32 --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
33 +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
34 @@ -280,6 +280,20 @@ static int queue_setup(struct vb2_queue
35 return 0;
36 }
37
38 +static int buffer_init(struct vb2_buffer *vb)
39 +{
40 + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
41 + struct vb2_v4l2_buffer *vb2 = to_vb2_v4l2_buffer(vb);
42 + struct mmal_buffer *buf = container_of(vb2, struct mmal_buffer, vb);
43 +
44 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p, vb %p\n",
45 + __func__, dev, vb);
46 + buf->buffer = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
47 + buf->buffer_size = vb2_plane_size(&buf->vb.vb2_buf, 0);
48 +
49 + return mmal_vchi_buffer_init(dev->instance, buf);
50 +}
51 +
52 static int buffer_prepare(struct vb2_buffer *vb)
53 {
54 struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
55 @@ -302,6 +316,17 @@ static int buffer_prepare(struct vb2_buf
56 return 0;
57 }
58
59 +static void buffer_cleanup(struct vb2_buffer *vb)
60 +{
61 + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
62 + struct vb2_v4l2_buffer *vb2 = to_vb2_v4l2_buffer(vb);
63 + struct mmal_buffer *buf = container_of(vb2, struct mmal_buffer, vb);
64 +
65 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p, vb %p\n",
66 + __func__, dev, vb);
67 + mmal_vchi_buffer_cleanup(buf);
68 +}
69 +
70 static inline bool is_capturing(struct bm2835_mmal_dev *dev)
71 {
72 return dev->capture.camera_port ==
73 @@ -497,9 +522,6 @@ static void buffer_queue(struct vb2_buff
74 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
75 "%s: dev:%p buf:%p\n", __func__, dev, buf);
76
77 - buf->buffer = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
78 - buf->buffer_size = vb2_plane_size(&buf->vb.vb2_buf, 0);
79 -
80 ret = vchiq_mmal_submit_buffer(dev->instance, dev->capture.port, buf);
81 if (ret < 0)
82 v4l2_err(&dev->v4l2_dev, "%s: error submitting buffer\n",
83 @@ -665,7 +687,9 @@ static void bm2835_mmal_unlock(struct vb
84
85 static const struct vb2_ops bm2835_mmal_video_qops = {
86 .queue_setup = queue_setup,
87 + .buf_init = buffer_init,
88 .buf_prepare = buffer_prepare,
89 + .buf_cleanup = buffer_cleanup,
90 .buf_queue = buffer_queue,
91 .start_streaming = start_streaming,
92 .stop_streaming = stop_streaming,
93 --- a/drivers/staging/vc04_services/bcm2835-camera/mmal-common.h
94 +++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-common.h
95 @@ -22,6 +22,8 @@
96 /** Special value signalling that time is not known */
97 #define MMAL_TIME_UNKNOWN (1LL<<63)
98
99 +struct mmal_msg_context;
100 +
101 /* mapping between v4l and mmal video modes */
102 struct mmal_fmt {
103 char *name;
104 @@ -46,6 +48,8 @@ struct mmal_buffer {
105
106 void *buffer; /* buffer pointer */
107 unsigned long buffer_size; /* size of allocated buffer */
108 +
109 + struct mmal_msg_context *msg_context;
110 };
111
112 /* */
113 --- a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
114 +++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
115 @@ -324,8 +324,6 @@ static void buffer_work_cb(struct work_s
116 msg_context->u.bulk.dts,
117 msg_context->u.bulk.pts);
118
119 - /* release message context */
120 - release_msg_context(msg_context);
121 }
122
123 /* enqueue a bulk receive for a given message context */
124 @@ -506,11 +504,13 @@ buffer_from_host(struct vchiq_mmal_insta
125 return -EINTR;
126
127 /* get context */
128 - msg_context = get_msg_context(instance);
129 - if (IS_ERR(msg_context)) {
130 - ret = PTR_ERR(msg_context);
131 + if (!buf->msg_context) {
132 + pr_err("%s: msg_context not allocated, buf %p\n", __func__,
133 + buf);
134 + ret = -EINVAL;
135 goto unlock;
136 }
137 + msg_context = buf->msg_context;
138
139 /* store bulk message context for when data arrives */
140 msg_context->u.bulk.instance = instance;
141 @@ -560,11 +560,6 @@ buffer_from_host(struct vchiq_mmal_insta
142 sizeof(struct mmal_msg_header) +
143 sizeof(m.u.buffer_from_host));
144
145 - if (ret != 0) {
146 - release_msg_context(msg_context);
147 - /* todo: is this correct error value? */
148 - }
149 -
150 vchi_service_release(instance->handle);
151
152 unlock:
153 @@ -1779,6 +1774,29 @@ int vchiq_mmal_submit_buffer(struct vchi
154
155 return 0;
156 }
157 +
158 +int mmal_vchi_buffer_init(struct vchiq_mmal_instance *instance,
159 + struct mmal_buffer *buf)
160 +{
161 + struct mmal_msg_context *msg_context = get_msg_context(instance);
162 +
163 + if (IS_ERR(msg_context))
164 + return (PTR_ERR(msg_context));
165 +
166 + buf->msg_context = msg_context;
167 + return 0;
168 +}
169 +
170 +int mmal_vchi_buffer_cleanup(struct mmal_buffer *buf)
171 +{
172 + struct mmal_msg_context *msg_context = buf->msg_context;
173 +
174 + if (msg_context)
175 + release_msg_context(msg_context);
176 + buf->msg_context = NULL;
177 +
178 + return 0;
179 +}
180
181 /* Initialise a mmal component and its ports
182 *
183 --- a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.h
184 +++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.h
185 @@ -171,4 +171,7 @@ int vchiq_mmal_submit_buffer(struct vchi
186 struct vchiq_mmal_port *port,
187 struct mmal_buffer *buf);
188
189 +int mmal_vchi_buffer_init(struct vchiq_mmal_instance *instance,
190 + struct mmal_buffer *buf);
191 +int mmal_vchi_buffer_cleanup(struct mmal_buffer *buf);
192 #endif /* MMAL_VCHIQ_H */