31162b3ce4e3eef6f369e2c87d96f753da0b29fb
[openwrt/staging/blogic.git] /
1 From 63d550818a9470a88fa5dbe1b05bd8839ab40ab0 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 | 140 ++++++++++--------
12 1 file changed, 78 insertions(+), 62 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 @@ -378,7 +389,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 @@ -546,11 +558,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 @@ -563,8 +575,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 @@ -835,39 +847,42 @@ 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 + pr_dbg_lvl(3, debug,
122 + "es video format: width:%d height:%d colourspace:0x%x\n",
123 port->es.video.width, port->es.video.height,
124 port->es.video.color_space);
125
126 - pr_debug(" : crop xywh %d,%d,%d,%d\n",
127 + pr_dbg_lvl(3, debug,
128 + " : crop xywh %d,%d,%d,%d\n",
129 port->es.video.crop.x,
130 port->es.video.crop.y,
131 port->es.video.crop.width, port->es.video.crop.height);
132 - pr_debug(" : framerate %d/%d aspect %d/%d\n",
133 + pr_dbg_lvl(3, debug,
134 + " : framerate %d/%d aspect %d/%d\n",
135 port->es.video.frame_rate.numerator,
136 port->es.video.frame_rate.denominator,
137 port->es.video.par.numerator, port->es.video.par.denominator);
138 @@ -901,7 +916,7 @@ static int port_info_set(struct vchiq_mm
139 struct mmal_msg *rmsg;
140 struct vchiq_header *rmsg_handle;
141
142 - pr_debug("setting port info port %p\n", port);
143 + pr_dbg_lvl(1, debug, "setting port info port %p\n", port);
144 if (!port)
145 return -1;
146 dump_port_info(port);
147 @@ -944,8 +959,8 @@ static int port_info_set(struct vchiq_mm
148 /* return operation status */
149 ret = -rmsg->u.port_info_get_reply.status;
150
151 - pr_debug("%s:result:%d component:0x%x port:%d\n", __func__, ret,
152 - port->component->handle, port->handle);
153 + pr_dbg_lvl(1, debug, "%s:result:%d component:0x%x port:%d\n", __func__,
154 + ret, port->component->handle, port->handle);
155
156 release_msg:
157 vchiq_release_message(instance->vchiq_instance, instance->service_handle, rmsg_handle);
158 @@ -1035,13 +1050,13 @@ static int port_info_get(struct vchiq_mm
159 rmsg->u.port_info_get_reply.extradata,
160 port->format.extradata_size);
161
162 - pr_debug("received port info\n");
163 + pr_dbg_lvl(1, debug, "received port info\n");
164 dump_port_info(port);
165
166 release_msg:
167
168 - pr_debug("%s:result:%d component:0x%x port:%d\n",
169 - __func__, ret, port->component->handle, port->handle);
170 + pr_dbg_lvl(1, debug, "%s:result:%d component:0x%x port:%d\n",
171 + __func__, ret, port->component->handle, port->handle);
172
173 vchiq_release_message(instance->vchiq_instance, instance->service_handle, rmsg_handle);
174
175 @@ -1086,9 +1101,9 @@ static int create_component(struct vchiq
176 component->outputs = rmsg->u.component_create_reply.output_num;
177 component->clocks = rmsg->u.component_create_reply.clock_num;
178
179 - pr_debug("Component handle:0x%x in:%d out:%d clock:%d\n",
180 - component->handle,
181 - component->inputs, component->outputs, component->clocks);
182 + pr_dbg_lvl(2, debug, "Component handle:0x%x in:%d out:%d clock:%d\n",
183 + component->handle,
184 + component->inputs, component->outputs, component->clocks);
185
186 release_msg:
187 vchiq_release_message(instance->vchiq_instance, instance->service_handle, rmsg_handle);
188 @@ -1257,10 +1272,9 @@ static int port_action_port(struct vchiq
189
190 ret = -rmsg->u.port_action_reply.status;
191
192 - pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)\n",
193 - __func__,
194 - ret, port->component->handle, port->handle,
195 - port_action_type_names[action_type], action_type);
196 + pr_dbg_lvl(2, debug, "%s:result:%d component:0x%x port:%d action:%s(%d)\n",
197 + __func__, ret, port->component->handle, port->handle,
198 + port_action_type_names[action_type], action_type);
199
200 release_msg:
201 vchiq_release_message(instance->vchiq_instance, instance->service_handle, rmsg_handle);
202 @@ -1304,11 +1318,11 @@ static int port_action_handle(struct vch
203
204 ret = -rmsg->u.port_action_reply.status;
205
206 - pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d) connect component:0x%x connect port:%d\n",
207 - __func__,
208 - ret, port->component->handle, port->handle,
209 - port_action_type_names[action_type],
210 - action_type, connect_component_handle, connect_port_handle);
211 + pr_dbg_lvl(2, debug,
212 + "%s:result:%d component:0x%x port:%d action:%s(%d) connect component:0x%x connect port:%d\n",
213 + __func__, ret, port->component->handle, port->handle,
214 + port_action_type_names[action_type],
215 + action_type, connect_component_handle, connect_port_handle);
216
217 release_msg:
218 vchiq_release_message(instance->vchiq_instance, instance->service_handle, rmsg_handle);
219 @@ -1347,9 +1361,9 @@ static int port_parameter_set(struct vch
220
221 ret = -rmsg->u.port_parameter_set_reply.status;
222
223 - pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n",
224 - __func__,
225 - ret, port->component->handle, port->handle, parameter_id);
226 + pr_dbg_lvl(1, debug, "%s:result:%d component:0x%x port:%d parameter:%d\n",
227 + __func__, ret, port->component->handle, port->handle,
228 + parameter_id);
229
230 release_msg:
231 vchiq_release_message(instance->vchiq_instance, instance->service_handle, rmsg_handle);
232 @@ -1407,8 +1421,9 @@ static int port_parameter_get(struct vch
233 /* Always report the size of the returned parameter to the caller */
234 *value_size = rmsg->u.port_parameter_get_reply.size;
235
236 - pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n", __func__,
237 - ret, port->component->handle, port->handle, parameter_id);
238 + pr_dbg_lvl(1, debug, "%s:result:%d component:0x%x port:%d parameter:%d\n",
239 + __func__, ret, port->component->handle, port->handle,
240 + parameter_id);
241
242 release_msg:
243 vchiq_release_message(instance->vchiq_instance, instance->service_handle, rmsg_handle);
244 @@ -1665,7 +1680,7 @@ int vchiq_mmal_port_connect_tunnel(struc
245 if (!dst) {
246 /* do not make new connection */
247 ret = 0;
248 - pr_debug("not making new connection\n");
249 + pr_dbg_lvl(3, debug, "not making new connection\n");
250 goto release_unlock;
251 }
252
253 @@ -1683,14 +1698,14 @@ int vchiq_mmal_port_connect_tunnel(struc
254 /* set new format */
255 ret = port_info_set(instance, dst);
256 if (ret) {
257 - pr_debug("setting port info failed\n");
258 + pr_dbg_lvl(1, debug, "setting port info failed\n");
259 goto release_unlock;
260 }
261
262 /* read what has actually been set */
263 ret = port_info_get(instance, dst);
264 if (ret) {
265 - pr_debug("read back port info failed\n");
266 + pr_dbg_lvl(1, debug, "read back port info failed\n");
267 goto release_unlock;
268 }
269
270 @@ -1699,9 +1714,9 @@ int vchiq_mmal_port_connect_tunnel(struc
271 MMAL_MSG_PORT_ACTION_TYPE_CONNECT,
272 dst->component->handle, dst->handle);
273 if (ret < 0) {
274 - pr_debug("connecting port %d:%d to %d:%d failed\n",
275 - src->component->handle, src->handle,
276 - dst->component->handle, dst->handle);
277 + pr_dbg_lvl(2, debug, "connecting port %d:%d to %d:%d failed\n",
278 + src->component->handle, src->handle,
279 + dst->component->handle, dst->handle);
280 goto release_unlock;
281 }
282 src->connected = dst;
283 @@ -1726,7 +1741,8 @@ int vchiq_mmal_submit_buffer(struct vchi
284 * videobuf2 won't let us have the dmabuf there.
285 */
286 if (port->zero_copy && buffer->dma_buf && !buffer->vcsm_handle) {
287 - pr_debug("%s: import dmabuf %p\n", __func__, buffer->dma_buf);
288 + pr_dbg_lvl(2, debug, "%s: import dmabuf %p\n",
289 + __func__, buffer->dma_buf);
290 ret = vc_sm_cma_import_dmabuf(buffer->dma_buf,
291 &buffer->vcsm_handle);
292 if (ret) {
293 @@ -1742,8 +1758,8 @@ int vchiq_mmal_submit_buffer(struct vchi
294 vc_sm_cma_free(buffer->vcsm_handle);
295 return ret;
296 }
297 - pr_debug("%s: import dmabuf %p - got vc handle %08X\n",
298 - __func__, buffer->dma_buf, buffer->vc_handle);
299 + pr_dbg_lvl(2, debug, "%s: import dmabuf %p - got vc handle %08X\n",
300 + __func__, buffer->dma_buf, buffer->vc_handle);
301 }
302
303 ret = buffer_from_host(instance, port, buffer);
304 @@ -1782,8 +1798,8 @@ int mmal_vchi_buffer_cleanup(struct mmal
305 if (buf->vcsm_handle) {
306 int ret;
307
308 - pr_debug("%s: vc_sm_cma_free on handle %p\n", __func__,
309 - buf->vcsm_handle);
310 + pr_dbg_lvl(2, debug, "%s: vc_sm_cma_free on handle %p\n", __func__,
311 + buf->vcsm_handle);
312 ret = vc_sm_cma_free(buf->vcsm_handle);
313 if (ret)
314 pr_err("%s: vcsm_free failed, ret %d\n", __func__, ret);