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
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 | 140 ++++++++++--------
12 1 file changed, 78 insertions(+), 62 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 @@ -378,7 +389,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 @@ -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;
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 @@ -563,8 +575,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 @@ -835,39 +847,42 @@ 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 + 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);
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;
142 - pr_debug("setting port info port %p\n", port);
143 + pr_dbg_lvl(1, debug, "setting port info port %p\n", port);
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;
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);
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);
162 - pr_debug("received port info\n");
163 + pr_dbg_lvl(1, debug, "received port info\n");
164 dump_port_info(port);
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);
173 vchiq_release_message(instance->vchiq_instance, instance->service_handle, rmsg_handle);
175 @@ -1087,9 +1102,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;
179 - pr_debug("Component handle:0x%x in:%d out:%d clock:%d\n",
181 - component->inputs, component->outputs, component->clocks);
182 + pr_dbg_lvl(2, debug, "Component handle:0x%x in:%d out:%d clock:%d\n",
184 + component->inputs, component->outputs, component->clocks);
187 vchiq_release_message(instance->vchiq_instance, instance->service_handle, rmsg_handle);
188 @@ -1258,10 +1273,9 @@ static int port_action_port(struct vchiq
190 ret = -rmsg->u.port_action_reply.status;
192 - pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)\n",
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);
201 vchiq_release_message(instance->vchiq_instance, instance->service_handle, rmsg_handle);
202 @@ -1305,11 +1319,11 @@ static int port_action_handle(struct vch
204 ret = -rmsg->u.port_action_reply.status;
206 - pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d) connect component:0x%x connect port:%d\n",
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);
218 vchiq_release_message(instance->vchiq_instance, instance->service_handle, rmsg_handle);
219 @@ -1348,9 +1362,9 @@ static int port_parameter_set(struct vch
221 ret = -rmsg->u.port_parameter_set_reply.status;
223 - pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n",
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,
231 vchiq_release_message(instance->vchiq_instance, instance->service_handle, rmsg_handle);
232 @@ -1408,8 +1422,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;
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,
243 vchiq_release_message(instance->vchiq_instance, instance->service_handle, rmsg_handle);
244 @@ -1666,7 +1681,7 @@ int vchiq_mmal_port_connect_tunnel(struc
246 /* do not make new connection */
248 - pr_debug("not making new connection\n");
249 + pr_dbg_lvl(3, debug, "not making new connection\n");
253 @@ -1684,14 +1699,14 @@ int vchiq_mmal_port_connect_tunnel(struc
255 ret = port_info_set(instance, dst);
257 - pr_debug("setting port info failed\n");
258 + pr_dbg_lvl(1, debug, "setting port info failed\n");
262 /* read what has actually been set */
263 ret = port_info_get(instance, dst);
265 - pr_debug("read back port info failed\n");
266 + pr_dbg_lvl(1, debug, "read back port info failed\n");
270 @@ -1700,9 +1715,9 @@ int vchiq_mmal_port_connect_tunnel(struc
271 MMAL_MSG_PORT_ACTION_TYPE_CONNECT,
272 dst->component->handle, dst->handle);
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);
282 src->connected = dst;
283 @@ -1727,7 +1742,8 @@ int vchiq_mmal_submit_buffer(struct vchi
284 * videobuf2 won't let us have the dmabuf there.
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);
293 @@ -1743,8 +1759,8 @@ int vchiq_mmal_submit_buffer(struct vchi
294 vc_sm_cma_free(buffer->vcsm_handle);
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);
303 ret = buffer_from_host(instance, port, buffer);
304 @@ -1783,8 +1799,8 @@ int mmal_vchi_buffer_cleanup(struct mmal
305 if (buf->vcsm_handle) {
308 - pr_debug("%s: vc_sm_cma_free on handle %p\n", __func__,
310 + pr_dbg_lvl(2, debug, "%s: vc_sm_cma_free on handle %p\n", __func__,
312 ret = vc_sm_cma_free(buf->vcsm_handle);
314 pr_err("%s: vcsm_free failed, ret %d\n", __func__, ret);