skl-debug.c 6.8 KB

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