skl-debug.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * skl-debug.c - Debugfs for skl driver
  3. *
  4. * Copyright (C) 2016-17 Intel Corp
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; version 2 of the License.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. */
  15. #include <linux/pci.h>
  16. #include <linux/debugfs.h>
  17. #include "skl.h"
  18. #include "skl-tplg-interface.h"
  19. #include "skl-topology.h"
  20. #define MOD_BUF PAGE_SIZE
  21. struct skl_debug {
  22. struct skl *skl;
  23. struct device *dev;
  24. struct dentry *fs;
  25. struct dentry *modules;
  26. };
  27. static ssize_t skl_print_pins(struct skl_module_pin *m_pin, char *buf,
  28. int max_pin, ssize_t size, bool direction)
  29. {
  30. int i;
  31. ssize_t ret = 0;
  32. for (i = 0; i < max_pin; i++)
  33. ret += snprintf(buf + size, MOD_BUF - size,
  34. "%s %d\n\tModule %d\n\tInstance %d\n\t"
  35. "In-used %s\n\tType %s\n"
  36. "\tState %d\n\tIndex %d\n",
  37. direction ? "Input Pin:" : "Output Pin:",
  38. i, m_pin[i].id.module_id,
  39. m_pin[i].id.instance_id,
  40. m_pin[i].in_use ? "Used" : "Unused",
  41. m_pin[i].is_dynamic ? "Dynamic" : "Static",
  42. m_pin[i].pin_state, i);
  43. return ret;
  44. }
  45. static ssize_t skl_print_fmt(struct skl_module_fmt *fmt, char *buf,
  46. ssize_t size, bool direction)
  47. {
  48. return snprintf(buf + size, MOD_BUF - size,
  49. "%s\n\tCh %d\n\tFreq %d\n\tBit depth %d\n\t"
  50. "Valid bit depth %d\n\tCh config %#x\n\tInterleaving %d\n\t"
  51. "Sample Type %d\n\tCh Map %#x\n",
  52. direction ? "Input Format:" : "Output Format:",
  53. fmt->channels, fmt->s_freq, fmt->bit_depth,
  54. fmt->valid_bit_depth, fmt->ch_cfg,
  55. fmt->interleaving_style, fmt->sample_type,
  56. fmt->ch_map);
  57. }
  58. static ssize_t module_read(struct file *file, char __user *user_buf,
  59. size_t count, loff_t *ppos)
  60. {
  61. struct skl_module_cfg *mconfig = file->private_data;
  62. char *buf;
  63. ssize_t ret;
  64. buf = kzalloc(MOD_BUF, GFP_KERNEL);
  65. if (!buf)
  66. return -ENOMEM;
  67. ret = snprintf(buf, MOD_BUF, "Module:\n\tUUID %pUL\n\tModule id %d\n"
  68. "\tInstance id %d\n\tPvt_id %d\n", mconfig->guid,
  69. mconfig->id.module_id, mconfig->id.instance_id,
  70. mconfig->id.pvt_id);
  71. ret += snprintf(buf + ret, MOD_BUF - ret,
  72. "Resources:\n\tMCPS %#x\n\tIBS %#x\n\tOBS %#x\t\n",
  73. mconfig->mcps, mconfig->ibs, mconfig->obs);
  74. ret += snprintf(buf + ret, MOD_BUF - ret,
  75. "Module data:\n\tCore %d\n\tIn queue %d\n\t"
  76. "Out queue %d\n\tType %s\n",
  77. mconfig->core_id, mconfig->max_in_queue,
  78. mconfig->max_out_queue,
  79. mconfig->is_loadable ? "loadable" : "inbuilt");
  80. ret += skl_print_fmt(mconfig->in_fmt, buf, ret, true);
  81. ret += skl_print_fmt(mconfig->out_fmt, buf, ret, false);
  82. ret += snprintf(buf + ret, MOD_BUF - ret,
  83. "Fixup:\n\tParams %#x\n\tConverter %#x\n",
  84. mconfig->params_fixup, mconfig->converter);
  85. ret += snprintf(buf + ret, MOD_BUF - ret,
  86. "Module Gateway:\n\tType %#x\n\tVbus %#x\n\tHW conn %#x\n\tSlot %#x\n",
  87. mconfig->dev_type, mconfig->vbus_id,
  88. mconfig->hw_conn_type, mconfig->time_slot);
  89. ret += snprintf(buf + ret, MOD_BUF - ret,
  90. "Pipeline:\n\tID %d\n\tPriority %d\n\tConn Type %d\n\t"
  91. "Pages %#x\n", mconfig->pipe->ppl_id,
  92. mconfig->pipe->pipe_priority, mconfig->pipe->conn_type,
  93. mconfig->pipe->memory_pages);
  94. ret += snprintf(buf + ret, MOD_BUF - ret,
  95. "\tParams:\n\t\tHost DMA %d\n\t\tLink DMA %d\n",
  96. mconfig->pipe->p_params->host_dma_id,
  97. mconfig->pipe->p_params->link_dma_id);
  98. ret += snprintf(buf + ret, MOD_BUF - ret,
  99. "\tPCM params:\n\t\tCh %d\n\t\tFreq %d\n\t\tFormat %d\n",
  100. mconfig->pipe->p_params->ch,
  101. mconfig->pipe->p_params->s_freq,
  102. mconfig->pipe->p_params->s_fmt);
  103. ret += snprintf(buf + ret, MOD_BUF - ret,
  104. "\tLink %#x\n\tStream %#x\n",
  105. mconfig->pipe->p_params->linktype,
  106. mconfig->pipe->p_params->stream);
  107. ret += snprintf(buf + ret, MOD_BUF - ret,
  108. "\tState %d\n\tPassthru %s\n",
  109. mconfig->pipe->state,
  110. mconfig->pipe->passthru ? "true" : "false");
  111. ret += skl_print_pins(mconfig->m_in_pin, buf,
  112. mconfig->max_in_queue, ret, true);
  113. ret += skl_print_pins(mconfig->m_out_pin, buf,
  114. mconfig->max_out_queue, ret, false);
  115. ret += snprintf(buf + ret, MOD_BUF - ret,
  116. "Other:\n\tDomain %d\n\tHomogenous Input %s\n\t"
  117. "Homogenous Output %s\n\tIn Queue Mask %d\n\t"
  118. "Out Queue Mask %d\n\tDMA ID %d\n\tMem Pages %d\n\t"
  119. "Module Type %d\n\tModule State %d\n",
  120. mconfig->domain,
  121. mconfig->homogenous_inputs ? "true" : "false",
  122. mconfig->homogenous_outputs ? "true" : "false",
  123. mconfig->in_queue_mask, mconfig->out_queue_mask,
  124. mconfig->dma_id, mconfig->mem_pages, mconfig->m_state,
  125. mconfig->m_type);
  126. ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
  127. kfree(buf);
  128. return ret;
  129. }
  130. static const struct file_operations mcfg_fops = {
  131. .open = simple_open,
  132. .read = module_read,
  133. .llseek = default_llseek,
  134. };
  135. void skl_debug_init_module(struct skl_debug *d,
  136. struct snd_soc_dapm_widget *w,
  137. struct skl_module_cfg *mconfig)
  138. {
  139. if (!debugfs_create_file(w->name, 0444,
  140. d->modules, mconfig,
  141. &mcfg_fops))
  142. dev_err(d->dev, "%s: module debugfs init failed\n", w->name);
  143. }
  144. struct skl_debug *skl_debugfs_init(struct skl *skl)
  145. {
  146. struct skl_debug *d;
  147. d = devm_kzalloc(&skl->pci->dev, sizeof(*d), GFP_KERNEL);
  148. if (!d)
  149. return NULL;
  150. /* create the debugfs dir with platform component's debugfs as parent */
  151. d->fs = debugfs_create_dir("dsp",
  152. skl->platform->component.debugfs_root);
  153. if (IS_ERR(d->fs) || !d->fs) {
  154. dev_err(&skl->pci->dev, "debugfs root creation failed\n");
  155. return NULL;
  156. }
  157. d->skl = skl;
  158. d->dev = &skl->pci->dev;
  159. /* now create the module dir */
  160. d->modules = debugfs_create_dir("modules", d->fs);
  161. if (IS_ERR(d->modules) || !d->modules) {
  162. dev_err(&skl->pci->dev, "modules debugfs create failed\n");
  163. goto err;
  164. }
  165. return d;
  166. err:
  167. debugfs_remove_recursive(d->fs);
  168. return NULL;
  169. }
  170. void skl_debugfs_exit(struct skl_debug *d)
  171. {
  172. debugfs_remove_recursive(d->fs);
  173. kfree(d);
  174. }