skl-debug.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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-sst-dsp.h"
  19. #include "skl-sst-ipc.h"
  20. #include "skl-tplg-interface.h"
  21. #include "skl-topology.h"
  22. #include "../common/sst-dsp-priv.h"
  23. #define MOD_BUF PAGE_SIZE
  24. #define FW_REG_BUF PAGE_SIZE
  25. #define FW_REG_SIZE 0x60
  26. struct skl_debug {
  27. struct skl *skl;
  28. struct device *dev;
  29. struct dentry *fs;
  30. struct dentry *modules;
  31. u8 fw_read_buff[FW_REG_BUF];
  32. };
  33. static ssize_t skl_print_pins(struct skl_module_pin *m_pin, char *buf,
  34. int max_pin, ssize_t size, bool direction)
  35. {
  36. int i;
  37. ssize_t ret = 0;
  38. for (i = 0; i < max_pin; i++)
  39. ret += snprintf(buf + size, MOD_BUF - size,
  40. "%s %d\n\tModule %d\n\tInstance %d\n\t"
  41. "In-used %s\n\tType %s\n"
  42. "\tState %d\n\tIndex %d\n",
  43. direction ? "Input Pin:" : "Output Pin:",
  44. i, m_pin[i].id.module_id,
  45. m_pin[i].id.instance_id,
  46. m_pin[i].in_use ? "Used" : "Unused",
  47. m_pin[i].is_dynamic ? "Dynamic" : "Static",
  48. m_pin[i].pin_state, i);
  49. return ret;
  50. }
  51. static ssize_t skl_print_fmt(struct skl_module_fmt *fmt, char *buf,
  52. ssize_t size, bool direction)
  53. {
  54. return snprintf(buf + size, MOD_BUF - size,
  55. "%s\n\tCh %d\n\tFreq %d\n\tBit depth %d\n\t"
  56. "Valid bit depth %d\n\tCh config %#x\n\tInterleaving %d\n\t"
  57. "Sample Type %d\n\tCh Map %#x\n",
  58. direction ? "Input Format:" : "Output Format:",
  59. fmt->channels, fmt->s_freq, fmt->bit_depth,
  60. fmt->valid_bit_depth, fmt->ch_cfg,
  61. fmt->interleaving_style, fmt->sample_type,
  62. fmt->ch_map);
  63. }
  64. static ssize_t module_read(struct file *file, char __user *user_buf,
  65. size_t count, loff_t *ppos)
  66. {
  67. struct skl_module_cfg *mconfig = file->private_data;
  68. char *buf;
  69. ssize_t ret;
  70. buf = kzalloc(MOD_BUF, GFP_KERNEL);
  71. if (!buf)
  72. return -ENOMEM;
  73. ret = snprintf(buf, MOD_BUF, "Module:\n\tUUID %pUL\n\tModule id %d\n"
  74. "\tInstance id %d\n\tPvt_id %d\n", mconfig->guid,
  75. mconfig->id.module_id, mconfig->id.instance_id,
  76. mconfig->id.pvt_id);
  77. ret += snprintf(buf + ret, MOD_BUF - ret,
  78. "Resources:\n\tMCPS %#x\n\tIBS %#x\n\tOBS %#x\t\n",
  79. mconfig->mcps, mconfig->ibs, mconfig->obs);
  80. ret += snprintf(buf + ret, MOD_BUF - ret,
  81. "Module data:\n\tCore %d\n\tIn queue %d\n\t"
  82. "Out queue %d\n\tType %s\n",
  83. mconfig->core_id, mconfig->max_in_queue,
  84. mconfig->max_out_queue,
  85. mconfig->is_loadable ? "loadable" : "inbuilt");
  86. ret += skl_print_fmt(mconfig->in_fmt, buf, ret, true);
  87. ret += skl_print_fmt(mconfig->out_fmt, buf, ret, false);
  88. ret += snprintf(buf + ret, MOD_BUF - ret,
  89. "Fixup:\n\tParams %#x\n\tConverter %#x\n",
  90. mconfig->params_fixup, mconfig->converter);
  91. ret += snprintf(buf + ret, MOD_BUF - ret,
  92. "Module Gateway:\n\tType %#x\n\tVbus %#x\n\tHW conn %#x\n\tSlot %#x\n",
  93. mconfig->dev_type, mconfig->vbus_id,
  94. mconfig->hw_conn_type, mconfig->time_slot);
  95. ret += snprintf(buf + ret, MOD_BUF - ret,
  96. "Pipeline:\n\tID %d\n\tPriority %d\n\tConn Type %d\n\t"
  97. "Pages %#x\n", mconfig->pipe->ppl_id,
  98. mconfig->pipe->pipe_priority, mconfig->pipe->conn_type,
  99. mconfig->pipe->memory_pages);
  100. ret += snprintf(buf + ret, MOD_BUF - ret,
  101. "\tParams:\n\t\tHost DMA %d\n\t\tLink DMA %d\n",
  102. mconfig->pipe->p_params->host_dma_id,
  103. mconfig->pipe->p_params->link_dma_id);
  104. ret += snprintf(buf + ret, MOD_BUF - ret,
  105. "\tPCM params:\n\t\tCh %d\n\t\tFreq %d\n\t\tFormat %d\n",
  106. mconfig->pipe->p_params->ch,
  107. mconfig->pipe->p_params->s_freq,
  108. mconfig->pipe->p_params->s_fmt);
  109. ret += snprintf(buf + ret, MOD_BUF - ret,
  110. "\tLink %#x\n\tStream %#x\n",
  111. mconfig->pipe->p_params->linktype,
  112. mconfig->pipe->p_params->stream);
  113. ret += snprintf(buf + ret, MOD_BUF - ret,
  114. "\tState %d\n\tPassthru %s\n",
  115. mconfig->pipe->state,
  116. mconfig->pipe->passthru ? "true" : "false");
  117. ret += skl_print_pins(mconfig->m_in_pin, buf,
  118. mconfig->max_in_queue, ret, true);
  119. ret += skl_print_pins(mconfig->m_out_pin, buf,
  120. mconfig->max_out_queue, ret, false);
  121. ret += snprintf(buf + ret, MOD_BUF - ret,
  122. "Other:\n\tDomain %d\n\tHomogenous Input %s\n\t"
  123. "Homogenous Output %s\n\tIn Queue Mask %d\n\t"
  124. "Out Queue Mask %d\n\tDMA ID %d\n\tMem Pages %d\n\t"
  125. "Module Type %d\n\tModule State %d\n",
  126. mconfig->domain,
  127. mconfig->homogenous_inputs ? "true" : "false",
  128. mconfig->homogenous_outputs ? "true" : "false",
  129. mconfig->in_queue_mask, mconfig->out_queue_mask,
  130. mconfig->dma_id, mconfig->mem_pages, mconfig->m_state,
  131. mconfig->m_type);
  132. ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
  133. kfree(buf);
  134. return ret;
  135. }
  136. static const struct file_operations mcfg_fops = {
  137. .open = simple_open,
  138. .read = module_read,
  139. .llseek = default_llseek,
  140. };
  141. void skl_debug_init_module(struct skl_debug *d,
  142. struct snd_soc_dapm_widget *w,
  143. struct skl_module_cfg *mconfig)
  144. {
  145. if (!debugfs_create_file(w->name, 0444,
  146. d->modules, mconfig,
  147. &mcfg_fops))
  148. dev_err(d->dev, "%s: module debugfs init failed\n", w->name);
  149. }
  150. static ssize_t fw_softreg_read(struct file *file, char __user *user_buf,
  151. size_t count, loff_t *ppos)
  152. {
  153. struct skl_debug *d = file->private_data;
  154. struct sst_dsp *sst = d->skl->skl_sst->dsp;
  155. size_t w0_stat_sz = sst->addr.w0_stat_sz;
  156. void __iomem *in_base = sst->mailbox.in_base;
  157. void __iomem *fw_reg_addr;
  158. unsigned int offset;
  159. char *tmp;
  160. ssize_t ret = 0;
  161. tmp = kzalloc(FW_REG_BUF, GFP_KERNEL);
  162. if (!tmp)
  163. return -ENOMEM;
  164. fw_reg_addr = in_base - w0_stat_sz;
  165. memset(d->fw_read_buff, 0, FW_REG_BUF);
  166. if (w0_stat_sz > 0)
  167. __iowrite32_copy(d->fw_read_buff, fw_reg_addr, w0_stat_sz >> 2);
  168. for (offset = 0; offset < FW_REG_SIZE; offset += 16) {
  169. ret += snprintf(tmp + ret, FW_REG_BUF - ret, "%#.4x: ", offset);
  170. hex_dump_to_buffer(d->fw_read_buff + offset, 16, 16, 4,
  171. tmp + ret, FW_REG_BUF - ret, 0);
  172. ret += strlen(tmp + ret);
  173. /* print newline for each offset */
  174. if (FW_REG_BUF - ret > 0)
  175. tmp[ret++] = '\n';
  176. }
  177. ret = simple_read_from_buffer(user_buf, count, ppos, tmp, ret);
  178. kfree(tmp);
  179. return ret;
  180. }
  181. static const struct file_operations soft_regs_ctrl_fops = {
  182. .open = simple_open,
  183. .read = fw_softreg_read,
  184. .llseek = default_llseek,
  185. };
  186. struct skl_debug *skl_debugfs_init(struct skl *skl)
  187. {
  188. struct skl_debug *d;
  189. d = devm_kzalloc(&skl->pci->dev, sizeof(*d), GFP_KERNEL);
  190. if (!d)
  191. return NULL;
  192. /* create the debugfs dir with platform component's debugfs as parent */
  193. d->fs = debugfs_create_dir("dsp",
  194. skl->platform->component.debugfs_root);
  195. if (IS_ERR(d->fs) || !d->fs) {
  196. dev_err(&skl->pci->dev, "debugfs root creation failed\n");
  197. return NULL;
  198. }
  199. d->skl = skl;
  200. d->dev = &skl->pci->dev;
  201. /* now create the module dir */
  202. d->modules = debugfs_create_dir("modules", d->fs);
  203. if (IS_ERR(d->modules) || !d->modules) {
  204. dev_err(&skl->pci->dev, "modules debugfs create failed\n");
  205. goto err;
  206. }
  207. if (!debugfs_create_file("fw_soft_regs_rd", 0444, d->fs, d,
  208. &soft_regs_ctrl_fops)) {
  209. dev_err(d->dev, "fw soft regs control debugfs init failed\n");
  210. goto err;
  211. }
  212. return d;
  213. err:
  214. debugfs_remove_recursive(d->fs);
  215. return NULL;
  216. }
  217. void skl_debugfs_exit(struct skl_debug *d)
  218. {
  219. debugfs_remove_recursive(d->fs);
  220. kfree(d);
  221. }