b3c8c2ad0efad6e98a5c1712ddeffbd3a19e3161
[openwrt/staging/thess.git] /
1 From 862ee4fbd8c6b984f920b88908e33951e51134ca Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.org>
3 Date: Mon, 24 Sep 2018 17:33:37 +0100
4 Subject: [PATCH 268/806] staging: mmal-vchiq: Make a mmal_buf struct for
5 passing parameters
6
7 The callback from vchi_mmal to the client was growing lots of extra
8 parameters. Consolidate them into a single struct instead of
9 growing the list further.
10 The struct is associated with the client buffer, therefore there
11 are various changes to setup various containers for the struct,
12 and pass the appropriate members.
13
14 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
15 ---
16 .../bcm2835-camera/bcm2835-camera.c | 62 ++++++++++++-------
17 .../vc04_services/vchiq-mmal/mmal-common.h | 5 ++
18 .../vc04_services/vchiq-mmal/mmal-vchiq.c | 29 ++++++---
19 .../vc04_services/vchiq-mmal/mmal-vchiq.h | 3 +-
20 4 files changed, 64 insertions(+), 35 deletions(-)
21
22 --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
23 +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
24 @@ -72,6 +72,12 @@ static const struct v4l2_fract
25 tpf_max = {.numerator = 1, .denominator = FPS_MIN},
26 tpf_default = {.numerator = 1000, .denominator = 30000};
27
28 +/* Container for MMAL and VB2 buffers*/
29 +struct vb2_mmal_buffer {
30 + struct vb2_v4l2_buffer vb;
31 + struct mmal_buffer mmal;
32 +};
33 +
34 /* video formats */
35 static struct mmal_fmt formats[] = {
36 {
37 @@ -267,14 +273,15 @@ static int buffer_init(struct vb2_buffer
38 {
39 struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
40 struct vb2_v4l2_buffer *vb2 = to_vb2_v4l2_buffer(vb);
41 - struct mmal_buffer *buf = container_of(vb2, struct mmal_buffer, vb);
42 + struct vb2_mmal_buffer *buf =
43 + container_of(vb2, struct vb2_mmal_buffer, vb);
44
45 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p, vb %p\n",
46 __func__, dev, vb);
47 - buf->buffer = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
48 - buf->buffer_size = vb2_plane_size(&buf->vb.vb2_buf, 0);
49 + buf->mmal.buffer = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
50 + buf->mmal.buffer_size = vb2_plane_size(&buf->vb.vb2_buf, 0);
51
52 - return mmal_vchi_buffer_init(dev->instance, buf);
53 + return mmal_vchi_buffer_init(dev->instance, &buf->mmal);
54 }
55
56 static int buffer_prepare(struct vb2_buffer *vb)
57 @@ -303,11 +310,13 @@ static void buffer_cleanup(struct vb2_bu
58 {
59 struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
60 struct vb2_v4l2_buffer *vb2 = to_vb2_v4l2_buffer(vb);
61 - struct mmal_buffer *buf = container_of(vb2, struct mmal_buffer, vb);
62 + struct vb2_mmal_buffer *buf =
63 + container_of(vb2, struct vb2_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 + mmal_vchi_buffer_cleanup(&buf->mmal);
70 }
71
72 static inline bool is_capturing(struct bm2835_mmal_dev *dev)
73 @@ -319,14 +328,16 @@ static inline bool is_capturing(struct b
74 static void buffer_cb(struct vchiq_mmal_instance *instance,
75 struct vchiq_mmal_port *port,
76 int status,
77 - struct mmal_buffer *buf,
78 - unsigned long length, u32 mmal_flags, s64 dts, s64 pts)
79 + struct mmal_buffer *mmal_buf)
80 {
81 struct bm2835_mmal_dev *dev = port->cb_ctx;
82 + struct vb2_mmal_buffer *buf =
83 + container_of(mmal_buf, struct vb2_mmal_buffer, mmal);
84
85 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
86 "%s: status:%d, buf:%p, length:%lu, flags %u, pts %lld\n",
87 - __func__, status, buf, length, mmal_flags, pts);
88 + __func__, status, buf, mmal_buf->length, mmal_buf->mmal_flags,
89 + mmal_buf->pts);
90
91 if (status != 0) {
92 /* error in transfer */
93 @@ -337,7 +348,7 @@ static void buffer_cb(struct vchiq_mmal_
94 return;
95 }
96
97 - if (length == 0) {
98 + if (mmal_buf->length == 0) {
99 /* stream ended */
100 if (dev->capture.frame_count) {
101 /* empty buffer whilst capturing - expected to be an
102 @@ -353,7 +364,8 @@ static void buffer_cb(struct vchiq_mmal_
103 &dev->capture.frame_count,
104 sizeof(dev->capture.frame_count));
105 }
106 - if (vchiq_mmal_submit_buffer(instance, port, buf))
107 + if (vchiq_mmal_submit_buffer(instance, port,
108 + &buf->mmal))
109 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
110 "Failed to return EOS buffer");
111 } else {
112 @@ -382,16 +394,16 @@ static void buffer_cb(struct vchiq_mmal_
113 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
114 "Buffer time set as current time - %lld",
115 buf->vb.vb2_buf.timestamp);
116 - } else if (pts != 0) {
117 + } else if (mmal_buf->pts != 0) {
118 ktime_t timestamp;
119 - s64 runtime_us = pts -
120 + s64 runtime_us = mmal_buf->pts -
121 dev->capture.vc_start_timestamp;
122 timestamp = ktime_add_us(dev->capture.kernel_start_ts,
123 runtime_us);
124 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
125 "Convert start time %llu and %llu with offset %llu to %llu\n",
126 ktime_to_ns(dev->capture.kernel_start_ts),
127 - dev->capture.vc_start_timestamp, pts,
128 + dev->capture.vc_start_timestamp, mmal_buf->pts,
129 ktime_to_ns(timestamp));
130 if (timestamp < dev->capture.last_timestamp) {
131 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
132 @@ -416,15 +428,15 @@ static void buffer_cb(struct vchiq_mmal_
133 dev->capture.last_timestamp = buf->vb.vb2_buf.timestamp;
134 buf->vb.sequence = dev->capture.sequence++;
135
136 - vb2_set_plane_payload(&buf->vb.vb2_buf, 0, length);
137 - if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_KEYFRAME)
138 + vb2_set_plane_payload(&buf->vb.vb2_buf, 0, mmal_buf->length);
139 + if (mmal_buf->mmal_flags & MMAL_BUFFER_HEADER_FLAG_KEYFRAME)
140 buf->vb.flags |= V4L2_BUF_FLAG_KEYFRAME;
141
142 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
143 "Buffer has ts %llu", dev->capture.last_timestamp);
144 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
145
146 - if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS &&
147 + if (mmal_buf->mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS &&
148 is_capturing(dev)) {
149 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
150 "Grab another frame as buffer has EOS");
151 @@ -507,14 +519,16 @@ static void buffer_queue(struct vb2_buff
152 {
153 struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
154 struct vb2_v4l2_buffer *vb2 = to_vb2_v4l2_buffer(vb);
155 - struct mmal_buffer *buf = container_of(vb2, struct mmal_buffer, vb);
156 + struct vb2_mmal_buffer *buf =
157 + container_of(vb2, struct vb2_mmal_buffer, vb);
158 int ret;
159
160 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
161 "%s: dev:%p buf:%p, idx %u\n",
162 __func__, dev, buf, vb2->vb2_buf.index);
163
164 - ret = vchiq_mmal_submit_buffer(dev->instance, dev->capture.port, buf);
165 + ret = vchiq_mmal_submit_buffer(dev->instance, dev->capture.port,
166 + &buf->mmal);
167 if (ret < 0)
168 v4l2_err(&dev->v4l2_dev, "%s: error submitting buffer\n",
169 __func__);
170 @@ -628,7 +642,7 @@ static void stop_streaming(struct vb2_qu
171 dev->capture.frame_count = 0;
172
173 /* ensure a format has actually been set */
174 - if (!dev->capture.port) {
175 + if (!port) {
176 v4l2_err(&dev->v4l2_dev,
177 "no capture port - stream not started?\n");
178 return;
179 @@ -648,11 +662,11 @@ static void stop_streaming(struct vb2_qu
180
181 /* disable the connection from camera to encoder */
182 ret = vchiq_mmal_port_disable(dev->instance, dev->capture.camera_port);
183 - if (!ret && dev->capture.camera_port != dev->capture.port) {
184 + if (!ret && dev->capture.camera_port != port) {
185 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
186 "disabling port\n");
187 - ret = vchiq_mmal_port_disable(dev->instance, dev->capture.port);
188 - } else if (dev->capture.camera_port != dev->capture.port) {
189 + ret = vchiq_mmal_port_disable(dev->instance, port);
190 + } else if (dev->capture.camera_port != port) {
191 v4l2_err(&dev->v4l2_dev, "port_disable failed, error %d\n",
192 ret);
193 }
194 @@ -1954,7 +1968,7 @@ static int bcm2835_mmal_probe(struct pla
195 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
196 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
197 q->drv_priv = dev;
198 - q->buf_struct_size = sizeof(struct mmal_buffer);
199 + q->buf_struct_size = sizeof(struct vb2_mmal_buffer);
200 q->ops = &bm2835_mmal_video_qops;
201 q->mem_ops = &vb2_vmalloc_memops;
202 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
203 --- a/drivers/staging/vc04_services/vchiq-mmal/mmal-common.h
204 +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-common.h
205 @@ -50,6 +50,11 @@ struct mmal_buffer {
206 unsigned long buffer_size; /* size of allocated buffer */
207
208 struct mmal_msg_context *msg_context;
209 +
210 + unsigned long length;
211 + u32 mmal_flags;
212 + s64 dts;
213 + s64 pts;
214 };
215
216 /* */
217 --- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
218 +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
219 @@ -259,17 +259,25 @@ static void buffer_work_cb(struct work_s
220 {
221 struct mmal_msg_context *msg_context =
222 container_of(work, struct mmal_msg_context, u.bulk.work);
223 + struct mmal_buffer *buffer = msg_context->u.bulk.buffer;
224 +
225 + if (!buffer) {
226 + pr_err("%s: ctx: %p, No mmal buffer to pass details\n",
227 + __func__, msg_context);
228 + return;
229 + }
230 +
231 + buffer->length = msg_context->u.bulk.buffer_used;
232 + buffer->mmal_flags = msg_context->u.bulk.mmal_flags;
233 + buffer->dts = msg_context->u.bulk.dts;
234 + buffer->pts = msg_context->u.bulk.pts;
235
236 atomic_dec(&msg_context->u.bulk.port->buffers_with_vpu);
237
238 msg_context->u.bulk.port->buffer_cb(msg_context->u.bulk.instance,
239 msg_context->u.bulk.port,
240 msg_context->u.bulk.status,
241 - msg_context->u.bulk.buffer,
242 - msg_context->u.bulk.buffer_used,
243 - msg_context->u.bulk.mmal_flags,
244 - msg_context->u.bulk.dts,
245 - msg_context->u.bulk.pts);
246 + msg_context->u.bulk.buffer);
247 }
248
249 /* workqueue scheduled callback to handle receiving buffers
250 @@ -1327,11 +1335,14 @@ static int port_disable(struct vchiq_mma
251 mmalbuf = list_entry(buf_head, struct mmal_buffer,
252 list);
253 list_del(buf_head);
254 - if (port->buffer_cb)
255 + if (port->buffer_cb) {
256 + mmalbuf->length = 0;
257 + mmalbuf->mmal_flags = 0;
258 + mmalbuf->dts = MMAL_TIME_UNKNOWN;
259 + mmalbuf->pts = MMAL_TIME_UNKNOWN;
260 port->buffer_cb(instance,
261 - port, 0, mmalbuf, 0, 0,
262 - MMAL_TIME_UNKNOWN,
263 - MMAL_TIME_UNKNOWN);
264 + port, 0, mmalbuf);
265 + }
266 }
267
268 spin_unlock_irqrestore(&port->slock, flags);
269 --- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.h
270 +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.h
271 @@ -44,8 +44,7 @@ struct vchiq_mmal_port;
272 typedef void (*vchiq_mmal_buffer_cb)(
273 struct vchiq_mmal_instance *instance,
274 struct vchiq_mmal_port *port,
275 - int status, struct mmal_buffer *buffer,
276 - unsigned long length, u32 mmal_flags, s64 dts, s64 pts);
277 + int status, struct mmal_buffer *buffer);
278
279 struct vchiq_mmal_port {
280 u32 enabled:1;