7c9ef959551b8f0d0099c05e6af0117b541d4e3c
[openwrt/staging/wigyori.git] /
1 From 7a46088760f8891e6790a98b82efc1eb386c0d80 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Wed, 15 Sep 2021 17:54:11 +0100
4 Subject: [PATCH] staging/mmal-vchiq: Add module parameter to enable
5 logging.
6
7 Adds a module parameter "debug" to enable various logging levels.
8
9 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
10 ---
11 .../vc04_services/vchiq-mmal/mmal-vchiq.c | 156 ++++++++++--------
12 1 file changed, 85 insertions(+), 71 deletions(-)
13
14 --- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
15 +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
16 @@ -31,6 +31,17 @@
17 #include "mmal-msg.h"
18
19 #include "vc-sm-cma/vc_sm_knl.h"
20 +
21 +#define pr_dbg_lvl(__level, __debug, __fmt, __arg...) \
22 + do { \
23 + if (__debug >= (__level)) \
24 + printk(KERN_DEBUG __fmt, ##__arg); \
25 + } while (0)
26 +
27 +static unsigned int debug;
28 +module_param(debug, uint, 0644);
29 +MODULE_PARM_DESC(debug, "activates debug info (0-3)");
30 +
31 /*
32 * maximum number of components supported.
33 * This matches the maximum permitted by default on the VPU
34 @@ -381,7 +392,8 @@ buffer_from_host(struct vchiq_mmal_insta
35 if (!port->enabled)
36 return -EINVAL;
37
38 - pr_debug("instance:%u buffer:%p\n", instance->service_handle, buf);
39 + pr_dbg_lvl(3, debug, "instance:%u buffer:%p\n",
40 + instance->service_handle, buf);
41
42 /* get context */
43 if (!buf->msg_context) {
44 @@ -549,11 +561,11 @@ static void event_to_host_cb(struct vchi
45 msg_context->u.bulk.pts = MMAL_TIME_UNKNOWN;
46 msg_context->u.bulk.cmd = msg->u.event_to_host.cmd;
47
48 - pr_debug("event component:%u port type:%d num:%d cmd:0x%x length:%d\n",
49 - msg->u.event_to_host.client_component,
50 - msg->u.event_to_host.port_type,
51 - msg->u.event_to_host.port_num,
52 - msg->u.event_to_host.cmd, msg->u.event_to_host.length);
53 + pr_dbg_lvl(3, debug, "event component:%u port type:%d num:%d cmd:0x%x length:%d\n",
54 + msg->u.event_to_host.client_component,
55 + msg->u.event_to_host.port_type,
56 + msg->u.event_to_host.port_num,
57 + msg->u.event_to_host.cmd, msg->u.event_to_host.length);
58 }
59
60 schedule_work(&msg_context->u.bulk.work);
61 @@ -566,8 +578,8 @@ static void buffer_to_host_cb(struct vch
62 struct mmal_msg_context *msg_context;
63 u32 handle;
64
65 - pr_debug("%s: instance:%p msg:%p msg_len:%d\n",
66 - __func__, instance, msg, msg_len);
67 + pr_dbg_lvl(3, debug, "%s: instance:%p msg:%p msg_len:%d\n",
68 + __func__, instance, msg, msg_len);
69
70 if (msg->u.buffer_from_host.drvbuf.magic == MMAL_MAGIC) {
71 handle = msg->u.buffer_from_host.drvbuf.client_context;
72 @@ -837,42 +849,43 @@ static int send_synchronous_mmal_msg(str
73
74 static void dump_port_info(struct vchiq_mmal_port *port)
75 {
76 - pr_debug("port handle:0x%x enabled:%d\n", port->handle, port->enabled);
77 + pr_dbg_lvl(3, debug, "port handle:0x%x enabled:%d\n", port->handle,
78 + port->enabled);
79
80 - pr_debug("buffer minimum num:%d size:%d align:%d\n",
81 - port->minimum_buffer.num,
82 - port->minimum_buffer.size, port->minimum_buffer.alignment);
83 -
84 - pr_debug("buffer recommended num:%d size:%d align:%d\n",
85 - port->recommended_buffer.num,
86 - port->recommended_buffer.size,
87 - port->recommended_buffer.alignment);
88 -
89 - pr_debug("buffer current values num:%d size:%d align:%d\n",
90 - port->current_buffer.num,
91 - port->current_buffer.size, port->current_buffer.alignment);
92 -
93 - pr_debug("elementary stream: type:%d encoding:0x%x variant:0x%x\n",
94 - port->format.type,
95 - port->format.encoding, port->format.encoding_variant);
96 + pr_dbg_lvl(3, debug, "buffer minimum num:%d size:%d align:%d\n",
97 + port->minimum_buffer.num,
98 + port->minimum_buffer.size, port->minimum_buffer.alignment);
99 +
100 + pr_dbg_lvl(3, debug, "buffer recommended num:%d size:%d align:%d\n",
101 + port->recommended_buffer.num,
102 + port->recommended_buffer.size,
103 + port->recommended_buffer.alignment);
104 +
105 + pr_dbg_lvl(3, debug, "buffer current values num:%d size:%d align:%d\n",
106 + port->current_buffer.num,
107 + port->current_buffer.size, port->current_buffer.alignment);
108 +
109 + pr_dbg_lvl(3, debug, "elementary stream: type:%d encoding:0x%x variant:0x%x\n",
110 + port->format.type,
111 + port->format.encoding, port->format.encoding_variant);
112
113 - pr_debug(" bitrate:%d flags:0x%x\n",
114 - port->format.bitrate, port->format.flags);
115 + pr_dbg_lvl(3, debug, " bitrate:%d flags:0x%x\n",
116 + port->format.bitrate, port->format.flags);
117
118 if (port->format.type == MMAL_ES_TYPE_VIDEO) {
119 - pr_debug
120 - ("es video format: width:%d height:%d colourspace:0x%x\n",
121 - port->es.video.width, port->es.video.height,
122 - port->es.video.color_space);
123 -
124 - pr_debug(" : crop xywh %d,%d,%d,%d\n",
125 - port->es.video.crop.x,
126 - port->es.video.crop.y,
127 - port->es.video.crop.width, port->es.video.crop.height);
128 - pr_debug(" : framerate %d/%d aspect %d/%d\n",
129 - port->es.video.frame_rate.num,
130 - port->es.video.frame_rate.den,
131 - port->es.video.par.num, port->es.video.par.den);
132 + pr_dbg_lvl(3, debug,
133 + "es video format: width:%d height:%d colourspace:0x%x\n",
134 + port->es.video.width, port->es.video.height,
135 + port->es.video.color_space);
136 +
137 + pr_dbg_lvl(3, debug, " : crop xywh %d,%d,%d,%d\n",
138 + port->es.video.crop.x,
139 + port->es.video.crop.y,
140 + port->es.video.crop.width, port->es.video.crop.height);
141 + pr_dbg_lvl(3, debug, " : framerate %d/%d aspect %d/%d\n",
142 + port->es.video.frame_rate.num,
143 + port->es.video.frame_rate.den,
144 + port->es.video.par.num, port->es.video.par.den);
145 }
146 }
147
148 @@ -903,7 +916,7 @@ static int port_info_set(struct vchiq_mm
149 struct mmal_msg *rmsg;
150 struct vchiq_header *rmsg_handle;
151
152 - pr_debug("setting port info port %p\n", port);
153 + pr_dbg_lvl(1, debug, "setting port info port %p\n", port);
154 if (!port)
155 return -1;
156 dump_port_info(port);
157 @@ -946,8 +959,8 @@ static int port_info_set(struct vchiq_mm
158 /* return operation status */
159 ret = -rmsg->u.port_info_get_reply.status;
160
161 - pr_debug("%s:result:%d component:0x%x port:%d\n", __func__, ret,
162 - port->component->handle, port->handle);
163 + pr_dbg_lvl(1, debug, "%s:result:%d component:0x%x port:%d\n", __func__,
164 + ret, port->component->handle, port->handle);
165
166 release_msg:
167 vchiq_release_message(instance->service_handle, rmsg_handle);
168 @@ -1037,13 +1050,13 @@ static int port_info_get(struct vchiq_mm
169 rmsg->u.port_info_get_reply.extradata,
170 port->format.extradata_size);
171
172 - pr_debug("received port info\n");
173 + pr_dbg_lvl(1, debug, "received port info\n");
174 dump_port_info(port);
175
176 release_msg:
177
178 - pr_debug("%s:result:%d component:0x%x port:%d\n",
179 - __func__, ret, port->component->handle, port->handle);
180 + pr_dbg_lvl(1, debug, "%s:result:%d component:0x%x port:%d\n",
181 + __func__, ret, port->component->handle, port->handle);
182
183 vchiq_release_message(instance->service_handle, rmsg_handle);
184
185 @@ -1088,9 +1101,9 @@ static int create_component(struct vchiq
186 component->outputs = rmsg->u.component_create_reply.output_num;
187 component->clocks = rmsg->u.component_create_reply.clock_num;
188
189 - pr_debug("Component handle:0x%x in:%d out:%d clock:%d\n",
190 - component->handle,
191 - component->inputs, component->outputs, component->clocks);
192 + pr_dbg_lvl(2, debug, "Component handle:0x%x in:%d out:%d clock:%d\n",
193 + component->handle,
194 + component->inputs, component->outputs, component->clocks);
195
196 release_msg:
197 vchiq_release_message(instance->service_handle, rmsg_handle);
198 @@ -1259,10 +1272,9 @@ static int port_action_port(struct vchiq
199
200 ret = -rmsg->u.port_action_reply.status;
201
202 - pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)\n",
203 - __func__,
204 - ret, port->component->handle, port->handle,
205 - port_action_type_names[action_type], action_type);
206 + pr_dbg_lvl(2, debug, "%s:result:%d component:0x%x port:%d action:%s(%d)\n",
207 + __func__, ret, port->component->handle, port->handle,
208 + port_action_type_names[action_type], action_type);
209
210 release_msg:
211 vchiq_release_message(instance->service_handle, rmsg_handle);
212 @@ -1306,11 +1318,11 @@ static int port_action_handle(struct vch
213
214 ret = -rmsg->u.port_action_reply.status;
215
216 - pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d) connect component:0x%x connect port:%d\n",
217 - __func__,
218 - ret, port->component->handle, port->handle,
219 - port_action_type_names[action_type],
220 - action_type, connect_component_handle, connect_port_handle);
221 + pr_dbg_lvl(2, debug,
222 + "%s:result:%d component:0x%x port:%d action:%s(%d) connect component:0x%x connect port:%d\n",
223 + __func__, ret, port->component->handle, port->handle,
224 + port_action_type_names[action_type],
225 + action_type, connect_component_handle, connect_port_handle);
226
227 release_msg:
228 vchiq_release_message(instance->service_handle, rmsg_handle);
229 @@ -1349,9 +1361,9 @@ static int port_parameter_set(struct vch
230
231 ret = -rmsg->u.port_parameter_set_reply.status;
232
233 - pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n",
234 - __func__,
235 - ret, port->component->handle, port->handle, parameter_id);
236 + pr_dbg_lvl(1, debug, "%s:result:%d component:0x%x port:%d parameter:%d\n",
237 + __func__, ret, port->component->handle, port->handle,
238 + parameter_id);
239
240 release_msg:
241 vchiq_release_message(instance->service_handle, rmsg_handle);
242 @@ -1409,8 +1421,9 @@ static int port_parameter_get(struct vch
243 /* Always report the size of the returned parameter to the caller */
244 *value_size = rmsg->u.port_parameter_get_reply.size;
245
246 - pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n", __func__,
247 - ret, port->component->handle, port->handle, parameter_id);
248 + pr_dbg_lvl(1, debug, "%s:result:%d component:0x%x port:%d parameter:%d\n",
249 + __func__, ret, port->component->handle, port->handle,
250 + parameter_id);
251
252 release_msg:
253 vchiq_release_message(instance->service_handle, rmsg_handle);
254 @@ -1667,7 +1680,7 @@ int vchiq_mmal_port_connect_tunnel(struc
255 if (!dst) {
256 /* do not make new connection */
257 ret = 0;
258 - pr_debug("not making new connection\n");
259 + pr_dbg_lvl(3, debug, "not making new connection\n");
260 goto release_unlock;
261 }
262
263 @@ -1685,14 +1698,14 @@ int vchiq_mmal_port_connect_tunnel(struc
264 /* set new format */
265 ret = port_info_set(instance, dst);
266 if (ret) {
267 - pr_debug("setting port info failed\n");
268 + pr_dbg_lvl(1, debug, "setting port info failed\n");
269 goto release_unlock;
270 }
271
272 /* read what has actually been set */
273 ret = port_info_get(instance, dst);
274 if (ret) {
275 - pr_debug("read back port info failed\n");
276 + pr_dbg_lvl(1, debug, "read back port info failed\n");
277 goto release_unlock;
278 }
279
280 @@ -1701,9 +1714,9 @@ int vchiq_mmal_port_connect_tunnel(struc
281 MMAL_MSG_PORT_ACTION_TYPE_CONNECT,
282 dst->component->handle, dst->handle);
283 if (ret < 0) {
284 - pr_debug("connecting port %d:%d to %d:%d failed\n",
285 - src->component->handle, src->handle,
286 - dst->component->handle, dst->handle);
287 + pr_dbg_lvl(2, debug, "connecting port %d:%d to %d:%d failed\n",
288 + src->component->handle, src->handle,
289 + dst->component->handle, dst->handle);
290 goto release_unlock;
291 }
292 src->connected = dst;
293 @@ -1728,7 +1741,8 @@ int vchiq_mmal_submit_buffer(struct vchi
294 * videobuf2 won't let us have the dmabuf there.
295 */
296 if (port->zero_copy && buffer->dma_buf && !buffer->vcsm_handle) {
297 - pr_debug("%s: import dmabuf %p\n", __func__, buffer->dma_buf);
298 + pr_dbg_lvl(2, debug, "%s: import dmabuf %p\n",
299 + __func__, buffer->dma_buf);
300 ret = vc_sm_cma_import_dmabuf(buffer->dma_buf,
301 &buffer->vcsm_handle);
302 if (ret) {
303 @@ -1744,8 +1758,8 @@ int vchiq_mmal_submit_buffer(struct vchi
304 vc_sm_cma_free(buffer->vcsm_handle);
305 return ret;
306 }
307 - pr_debug("%s: import dmabuf %p - got vc handle %08X\n",
308 - __func__, buffer->dma_buf, buffer->vc_handle);
309 + pr_dbg_lvl(2, debug, "%s: import dmabuf %p - got vc handle %08X\n",
310 + __func__, buffer->dma_buf, buffer->vc_handle);
311 }
312
313 ret = buffer_from_host(instance, port, buffer);
314 @@ -1784,8 +1798,8 @@ int mmal_vchi_buffer_cleanup(struct mmal
315 if (buf->vcsm_handle) {
316 int ret;
317
318 - pr_debug("%s: vc_sm_cma_free on handle %p\n", __func__,
319 - buf->vcsm_handle);
320 + pr_dbg_lvl(2, debug, "%s: vc_sm_cma_free on handle %p\n", __func__,
321 + buf->vcsm_handle);
322 ret = vc_sm_cma_free(buf->vcsm_handle);
323 if (ret)
324 pr_err("%s: vcsm_free failed, ret %d\n", __func__, ret);