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
7 Adds a module parameter "debug" to enable various logging levels.
9 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
11 .../vc04_services/vchiq-mmal/mmal-vchiq.c | 156 ++++++++++--------
12 1 file changed, 85 insertions(+), 71 deletions(-)
14 --- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
15 +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
19 #include "vc-sm-cma/vc_sm_knl.h"
21 +#define pr_dbg_lvl(__level, __debug, __fmt, __arg...) \
23 + if (__debug >= (__level)) \
24 + printk(KERN_DEBUG __fmt, ##__arg); \
27 +static unsigned int debug;
28 +module_param(debug, uint, 0644);
29 +MODULE_PARM_DESC(debug, "activates debug info (0-3)");
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
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);
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;
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);
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;
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);
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
74 static void dump_port_info(struct vchiq_mmal_port *port)
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,
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);
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);
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);
93 - pr_debug("elementary stream: type:%d encoding:0x%x variant:0x%x\n",
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);
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);
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);
109 + pr_dbg_lvl(3, debug, "elementary stream: type:%d encoding:0x%x variant:0x%x\n",
111 + port->format.encoding, port->format.encoding_variant);
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);
118 if (port->format.type == MMAL_ES_TYPE_VIDEO) {
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);
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);
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);
148 @@ -903,7 +916,7 @@ static int port_info_set(struct vchiq_mm
149 struct mmal_msg *rmsg;
150 struct vchiq_header *rmsg_handle;
152 - pr_debug("setting port info port %p\n", port);
153 + pr_dbg_lvl(1, debug, "setting port info port %p\n", port);
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;
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);
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);
172 - pr_debug("received port info\n");
173 + pr_dbg_lvl(1, debug, "received port info\n");
174 dump_port_info(port);
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);
183 vchiq_release_message(instance->service_handle, rmsg_handle);
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;
189 - pr_debug("Component handle:0x%x in:%d out:%d clock:%d\n",
191 - component->inputs, component->outputs, component->clocks);
192 + pr_dbg_lvl(2, debug, "Component handle:0x%x in:%d out:%d clock:%d\n",
194 + component->inputs, component->outputs, component->clocks);
197 vchiq_release_message(instance->service_handle, rmsg_handle);
198 @@ -1259,10 +1272,9 @@ static int port_action_port(struct vchiq
200 ret = -rmsg->u.port_action_reply.status;
202 - pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)\n",
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);
211 vchiq_release_message(instance->service_handle, rmsg_handle);
212 @@ -1306,11 +1318,11 @@ static int port_action_handle(struct vch
214 ret = -rmsg->u.port_action_reply.status;
216 - pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d) connect component:0x%x connect port:%d\n",
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);
228 vchiq_release_message(instance->service_handle, rmsg_handle);
229 @@ -1349,9 +1361,9 @@ static int port_parameter_set(struct vch
231 ret = -rmsg->u.port_parameter_set_reply.status;
233 - pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n",
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,
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;
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,
253 vchiq_release_message(instance->service_handle, rmsg_handle);
254 @@ -1667,7 +1680,7 @@ int vchiq_mmal_port_connect_tunnel(struc
256 /* do not make new connection */
258 - pr_debug("not making new connection\n");
259 + pr_dbg_lvl(3, debug, "not making new connection\n");
263 @@ -1685,14 +1698,14 @@ int vchiq_mmal_port_connect_tunnel(struc
265 ret = port_info_set(instance, dst);
267 - pr_debug("setting port info failed\n");
268 + pr_dbg_lvl(1, debug, "setting port info failed\n");
272 /* read what has actually been set */
273 ret = port_info_get(instance, dst);
275 - pr_debug("read back port info failed\n");
276 + pr_dbg_lvl(1, debug, "read back port info failed\n");
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);
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);
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.
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);
303 @@ -1744,8 +1758,8 @@ int vchiq_mmal_submit_buffer(struct vchi
304 vc_sm_cma_free(buffer->vcsm_handle);
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);
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) {
318 - pr_debug("%s: vc_sm_cma_free on handle %p\n", __func__,
320 + pr_dbg_lvl(2, debug, "%s: vc_sm_cma_free on handle %p\n", __func__,
322 ret = vc_sm_cma_free(buf->vcsm_handle);
324 pr_err("%s: vcsm_free failed, ret %d\n", __func__, ret);