debug.c (6e9548cdb30e5d6724236dd7b89a79a270751485) debug.c (cac0b0887e5304bddfda91a4a7106f9328c31318)
1// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2//
3// This file is provided under a dual BSD/GPLv2 license. When using or
4// redistributing this file, you may do so under either license.
5//
6// Copyright(c) 2018 Intel Corporation. All rights reserved.
7//
8// Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>

--- 220 unchanged lines hidden (view full) ---

229 debugfs_create_file(name, mode, sdev->debugfs_root, dfse, fops);
230 /* add to dfsentry list */
231 list_add(&dfse->list, &sdev->dfsentry_list);
232
233 return 0;
234}
235#endif
236
1// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2//
3// This file is provided under a dual BSD/GPLv2 license. When using or
4// redistributing this file, you may do so under either license.
5//
6// Copyright(c) 2018 Intel Corporation. All rights reserved.
7//
8// Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>

--- 220 unchanged lines hidden (view full) ---

229 debugfs_create_file(name, mode, sdev->debugfs_root, dfse, fops);
230 /* add to dfsentry list */
231 list_add(&dfse->list, &sdev->dfsentry_list);
232
233 return 0;
234}
235#endif
236
237
238#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_IPC_MSG_INJECTOR)
239static ssize_t msg_inject_read(struct file *file, char __user *buffer,
240 size_t count, loff_t *ppos)
241{
242 struct snd_sof_dfsentry *dfse = file->private_data;
243 struct sof_ipc_reply *rhdr = dfse->msg_inject_rx;
244
245 if (!rhdr->hdr.size || !count || *ppos)
246 return 0;
247
248 if (count > rhdr->hdr.size)
249 count = rhdr->hdr.size;
250
251 if (copy_to_user(buffer, dfse->msg_inject_rx, count))
252 return -EFAULT;
253
254 *ppos += count;
255 return count;
256}
257
258static ssize_t msg_inject_write(struct file *file, const char __user *buffer,
259 size_t count, loff_t *ppos)
260{
261 struct snd_sof_dfsentry *dfse = file->private_data;
262 struct snd_sof_dev *sdev = dfse->sdev;
263 struct sof_ipc_cmd_hdr *hdr = dfse->msg_inject_tx;
264 size_t size;
265 int ret, err;
266
267 if (*ppos)
268 return 0;
269
270 size = simple_write_to_buffer(dfse->msg_inject_tx, SOF_IPC_MSG_MAX_SIZE,
271 ppos, buffer, count);
272 if (size != count)
273 return size > 0 ? -EFAULT : size;
274
275 ret = pm_runtime_get_sync(sdev->dev);
276 if (ret < 0 && ret != -EACCES) {
277 dev_err_ratelimited(sdev->dev, "%s: DSP resume failed: %d\n",
278 __func__, ret);
279 pm_runtime_put_noidle(sdev->dev);
280 goto out;
281 }
282
283 /* send the message */
284 memset(dfse->msg_inject_rx, 0, SOF_IPC_MSG_MAX_SIZE);
285 ret = sof_ipc_tx_message(sdev->ipc, hdr->cmd, dfse->msg_inject_tx, count,
286 dfse->msg_inject_rx, SOF_IPC_MSG_MAX_SIZE);
287
288 pm_runtime_mark_last_busy(sdev->dev);
289 err = pm_runtime_put_autosuspend(sdev->dev);
290 if (err < 0)
291 dev_err_ratelimited(sdev->dev, "%s: DSP idle failed: %d\n",
292 __func__, err);
293
294 /* return size if test is successful */
295 if (ret >= 0)
296 ret = size;
297
298out:
299 return ret;
300}
301
302static const struct file_operations msg_inject_fops = {
303 .open = simple_open,
304 .read = msg_inject_read,
305 .write = msg_inject_write,
306 .llseek = default_llseek,
307};
308
309static int snd_sof_debugfs_msg_inject_item(struct snd_sof_dev *sdev,
310 const char *name, mode_t mode,
311 const struct file_operations *fops)
312{
313 struct snd_sof_dfsentry *dfse;
314
315 dfse = devm_kzalloc(sdev->dev, sizeof(*dfse), GFP_KERNEL);
316 if (!dfse)
317 return -ENOMEM;
318
319 /* pre allocate the tx and rx buffers */
320 dfse->msg_inject_tx = devm_kzalloc(sdev->dev, SOF_IPC_MSG_MAX_SIZE, GFP_KERNEL);
321 dfse->msg_inject_rx = devm_kzalloc(sdev->dev, SOF_IPC_MSG_MAX_SIZE, GFP_KERNEL);
322 if (!dfse->msg_inject_tx || !dfse->msg_inject_rx)
323 return -ENOMEM;
324
325 dfse->type = SOF_DFSENTRY_TYPE_BUF;
326 dfse->sdev = sdev;
327
328 debugfs_create_file(name, mode, sdev->debugfs_root, dfse, fops);
329 /* add to dfsentry list */
330 list_add(&dfse->list, &sdev->dfsentry_list);
331
332 return 0;
333}
334#endif
335
336static ssize_t sof_dfsentry_write(struct file *file, const char __user *buffer,
337 size_t count, loff_t *ppos)
338{
339 size_t size;
340 char *string;
341 int ret;
342
343 string = kzalloc(count+1, GFP_KERNEL);

--- 330 unchanged lines hidden (view full) ---

674 if (err < 0)
675 return err;
676 err = snd_sof_debugfs_probe_item(sdev, "probe_points_remove",
677 0200, &probe_points_remove_fops);
678 if (err < 0)
679 return err;
680#endif
681
237static ssize_t sof_dfsentry_write(struct file *file, const char __user *buffer,
238 size_t count, loff_t *ppos)
239{
240 size_t size;
241 char *string;
242 int ret;
243
244 string = kzalloc(count+1, GFP_KERNEL);

--- 330 unchanged lines hidden (view full) ---

575 if (err < 0)
576 return err;
577 err = snd_sof_debugfs_probe_item(sdev, "probe_points_remove",
578 0200, &probe_points_remove_fops);
579 if (err < 0)
580 return err;
581#endif
582
682#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_IPC_MSG_INJECTOR)
683 err = snd_sof_debugfs_msg_inject_item(sdev, "ipc_msg_inject", 0644,
684 &msg_inject_fops);
685
686 /* errors are only due to memory allocation, not debugfs */
687 if (err < 0)
688 return err;
689#endif
690
691 return 0;
692}
693EXPORT_SYMBOL_GPL(snd_sof_dbg_init);
694
695void snd_sof_free_debug(struct snd_sof_dev *sdev)
696{
697 debugfs_remove_recursive(sdev->debugfs_root);
698}

--- 85 unchanged lines hidden ---
583 return 0;
584}
585EXPORT_SYMBOL_GPL(snd_sof_dbg_init);
586
587void snd_sof_free_debug(struct snd_sof_dev *sdev)
588{
589 debugfs_remove_recursive(sdev->debugfs_root);
590}

--- 85 unchanged lines hidden ---