blob: a15aa2ffa681082f2b142184e4e0bdeb243efbfe [file] [log] [blame]
David Brazdil0f672f62019-12-10 10:32:29 +00001// SPDX-License-Identifier: GPL-2.0-only
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002/*
3 * skl-debug.c - Debugfs for skl driver
4 *
5 * Copyright (C) 2016-17 Intel Corp
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00006 */
7
8#include <linux/pci.h>
9#include <linux/debugfs.h>
10#include <uapi/sound/skl-tplg-interface.h>
11#include "skl.h"
12#include "skl-sst-dsp.h"
13#include "skl-sst-ipc.h"
14#include "skl-topology.h"
15#include "../common/sst-dsp.h"
16#include "../common/sst-dsp-priv.h"
17
18#define MOD_BUF PAGE_SIZE
19#define FW_REG_BUF PAGE_SIZE
20#define FW_REG_SIZE 0x60
21
22struct skl_debug {
David Brazdil0f672f62019-12-10 10:32:29 +000023 struct skl_dev *skl;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000024 struct device *dev;
25
26 struct dentry *fs;
27 struct dentry *modules;
28 u8 fw_read_buff[FW_REG_BUF];
29};
30
31static ssize_t skl_print_pins(struct skl_module_pin *m_pin, char *buf,
32 int max_pin, ssize_t size, bool direction)
33{
34 int i;
35 ssize_t ret = 0;
36
Olivier Deprez0e641232021-09-23 10:07:05 +020037 for (i = 0; i < max_pin; i++) {
38 ret += scnprintf(buf + size, MOD_BUF - size,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000039 "%s %d\n\tModule %d\n\tInstance %d\n\t"
40 "In-used %s\n\tType %s\n"
41 "\tState %d\n\tIndex %d\n",
42 direction ? "Input Pin:" : "Output Pin:",
43 i, m_pin[i].id.module_id,
44 m_pin[i].id.instance_id,
45 m_pin[i].in_use ? "Used" : "Unused",
46 m_pin[i].is_dynamic ? "Dynamic" : "Static",
47 m_pin[i].pin_state, i);
Olivier Deprez0e641232021-09-23 10:07:05 +020048 size += ret;
49 }
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000050 return ret;
51}
52
53static ssize_t skl_print_fmt(struct skl_module_fmt *fmt, char *buf,
54 ssize_t size, bool direction)
55{
Olivier Deprez0e641232021-09-23 10:07:05 +020056 return scnprintf(buf + size, MOD_BUF - size,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000057 "%s\n\tCh %d\n\tFreq %d\n\tBit depth %d\n\t"
58 "Valid bit depth %d\n\tCh config %#x\n\tInterleaving %d\n\t"
59 "Sample Type %d\n\tCh Map %#x\n",
60 direction ? "Input Format:" : "Output Format:",
61 fmt->channels, fmt->s_freq, fmt->bit_depth,
62 fmt->valid_bit_depth, fmt->ch_cfg,
63 fmt->interleaving_style, fmt->sample_type,
64 fmt->ch_map);
65}
66
67static ssize_t module_read(struct file *file, char __user *user_buf,
68 size_t count, loff_t *ppos)
69{
70 struct skl_module_cfg *mconfig = file->private_data;
David Brazdil0f672f62019-12-10 10:32:29 +000071 struct skl_module *module = mconfig->module;
72 struct skl_module_res *res = &module->resources[mconfig->res_idx];
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000073 char *buf;
74 ssize_t ret;
75
76 buf = kzalloc(MOD_BUF, GFP_KERNEL);
77 if (!buf)
78 return -ENOMEM;
79
Olivier Deprez0e641232021-09-23 10:07:05 +020080 ret = scnprintf(buf, MOD_BUF, "Module:\n\tUUID %pUL\n\tModule id %d\n"
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000081 "\tInstance id %d\n\tPvt_id %d\n", mconfig->guid,
82 mconfig->id.module_id, mconfig->id.instance_id,
83 mconfig->id.pvt_id);
84
Olivier Deprez0e641232021-09-23 10:07:05 +020085 ret += scnprintf(buf + ret, MOD_BUF - ret,
David Brazdil0f672f62019-12-10 10:32:29 +000086 "Resources:\n\tCPC %#x\n\tIBS %#x\n\tOBS %#x\t\n",
87 res->cpc, res->ibs, res->obs);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000088
Olivier Deprez0e641232021-09-23 10:07:05 +020089 ret += scnprintf(buf + ret, MOD_BUF - ret,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000090 "Module data:\n\tCore %d\n\tIn queue %d\n\t"
91 "Out queue %d\n\tType %s\n",
92 mconfig->core_id, mconfig->max_in_queue,
93 mconfig->max_out_queue,
94 mconfig->is_loadable ? "loadable" : "inbuilt");
95
96 ret += skl_print_fmt(mconfig->in_fmt, buf, ret, true);
97 ret += skl_print_fmt(mconfig->out_fmt, buf, ret, false);
98
Olivier Deprez0e641232021-09-23 10:07:05 +020099 ret += scnprintf(buf + ret, MOD_BUF - ret,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000100 "Fixup:\n\tParams %#x\n\tConverter %#x\n",
101 mconfig->params_fixup, mconfig->converter);
102
Olivier Deprez0e641232021-09-23 10:07:05 +0200103 ret += scnprintf(buf + ret, MOD_BUF - ret,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000104 "Module Gateway:\n\tType %#x\n\tVbus %#x\n\tHW conn %#x\n\tSlot %#x\n",
105 mconfig->dev_type, mconfig->vbus_id,
106 mconfig->hw_conn_type, mconfig->time_slot);
107
Olivier Deprez0e641232021-09-23 10:07:05 +0200108 ret += scnprintf(buf + ret, MOD_BUF - ret,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000109 "Pipeline:\n\tID %d\n\tPriority %d\n\tConn Type %d\n\t"
110 "Pages %#x\n", mconfig->pipe->ppl_id,
111 mconfig->pipe->pipe_priority, mconfig->pipe->conn_type,
112 mconfig->pipe->memory_pages);
113
Olivier Deprez0e641232021-09-23 10:07:05 +0200114 ret += scnprintf(buf + ret, MOD_BUF - ret,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000115 "\tParams:\n\t\tHost DMA %d\n\t\tLink DMA %d\n",
116 mconfig->pipe->p_params->host_dma_id,
117 mconfig->pipe->p_params->link_dma_id);
118
Olivier Deprez0e641232021-09-23 10:07:05 +0200119 ret += scnprintf(buf + ret, MOD_BUF - ret,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000120 "\tPCM params:\n\t\tCh %d\n\t\tFreq %d\n\t\tFormat %d\n",
121 mconfig->pipe->p_params->ch,
122 mconfig->pipe->p_params->s_freq,
123 mconfig->pipe->p_params->s_fmt);
124
Olivier Deprez0e641232021-09-23 10:07:05 +0200125 ret += scnprintf(buf + ret, MOD_BUF - ret,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000126 "\tLink %#x\n\tStream %#x\n",
127 mconfig->pipe->p_params->linktype,
128 mconfig->pipe->p_params->stream);
129
Olivier Deprez0e641232021-09-23 10:07:05 +0200130 ret += scnprintf(buf + ret, MOD_BUF - ret,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000131 "\tState %d\n\tPassthru %s\n",
132 mconfig->pipe->state,
133 mconfig->pipe->passthru ? "true" : "false");
134
135 ret += skl_print_pins(mconfig->m_in_pin, buf,
136 mconfig->max_in_queue, ret, true);
137 ret += skl_print_pins(mconfig->m_out_pin, buf,
138 mconfig->max_out_queue, ret, false);
139
Olivier Deprez0e641232021-09-23 10:07:05 +0200140 ret += scnprintf(buf + ret, MOD_BUF - ret,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000141 "Other:\n\tDomain %d\n\tHomogeneous Input %s\n\t"
142 "Homogeneous Output %s\n\tIn Queue Mask %d\n\t"
143 "Out Queue Mask %d\n\tDMA ID %d\n\tMem Pages %d\n\t"
144 "Module Type %d\n\tModule State %d\n",
145 mconfig->domain,
146 mconfig->homogenous_inputs ? "true" : "false",
147 mconfig->homogenous_outputs ? "true" : "false",
148 mconfig->in_queue_mask, mconfig->out_queue_mask,
149 mconfig->dma_id, mconfig->mem_pages, mconfig->m_state,
150 mconfig->m_type);
151
152 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
153
154 kfree(buf);
155 return ret;
156}
157
158static const struct file_operations mcfg_fops = {
159 .open = simple_open,
160 .read = module_read,
161 .llseek = default_llseek,
162};
163
164
165void skl_debug_init_module(struct skl_debug *d,
166 struct snd_soc_dapm_widget *w,
167 struct skl_module_cfg *mconfig)
168{
David Brazdil0f672f62019-12-10 10:32:29 +0000169 debugfs_create_file(w->name, 0444, d->modules, mconfig,
170 &mcfg_fops);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000171}
172
173static ssize_t fw_softreg_read(struct file *file, char __user *user_buf,
174 size_t count, loff_t *ppos)
175{
176 struct skl_debug *d = file->private_data;
David Brazdil0f672f62019-12-10 10:32:29 +0000177 struct sst_dsp *sst = d->skl->dsp;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000178 size_t w0_stat_sz = sst->addr.w0_stat_sz;
179 void __iomem *in_base = sst->mailbox.in_base;
180 void __iomem *fw_reg_addr;
181 unsigned int offset;
182 char *tmp;
183 ssize_t ret = 0;
184
185 tmp = kzalloc(FW_REG_BUF, GFP_KERNEL);
186 if (!tmp)
187 return -ENOMEM;
188
189 fw_reg_addr = in_base - w0_stat_sz;
190 memset(d->fw_read_buff, 0, FW_REG_BUF);
191
192 if (w0_stat_sz > 0)
David Brazdil0f672f62019-12-10 10:32:29 +0000193 __ioread32_copy(d->fw_read_buff, fw_reg_addr, w0_stat_sz >> 2);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000194
195 for (offset = 0; offset < FW_REG_SIZE; offset += 16) {
Olivier Deprez0e641232021-09-23 10:07:05 +0200196 ret += scnprintf(tmp + ret, FW_REG_BUF - ret, "%#.4x: ", offset);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000197 hex_dump_to_buffer(d->fw_read_buff + offset, 16, 16, 4,
198 tmp + ret, FW_REG_BUF - ret, 0);
199 ret += strlen(tmp + ret);
200
201 /* print newline for each offset */
202 if (FW_REG_BUF - ret > 0)
203 tmp[ret++] = '\n';
204 }
205
206 ret = simple_read_from_buffer(user_buf, count, ppos, tmp, ret);
207 kfree(tmp);
208
209 return ret;
210}
211
212static const struct file_operations soft_regs_ctrl_fops = {
213 .open = simple_open,
214 .read = fw_softreg_read,
215 .llseek = default_llseek,
216};
217
David Brazdil0f672f62019-12-10 10:32:29 +0000218struct skl_debug *skl_debugfs_init(struct skl_dev *skl)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000219{
220 struct skl_debug *d;
221
222 d = devm_kzalloc(&skl->pci->dev, sizeof(*d), GFP_KERNEL);
223 if (!d)
224 return NULL;
225
226 /* create the debugfs dir with platform component's debugfs as parent */
David Brazdil0f672f62019-12-10 10:32:29 +0000227 d->fs = debugfs_create_dir("dsp", skl->component->debugfs_root);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000228
229 d->skl = skl;
230 d->dev = &skl->pci->dev;
231
232 /* now create the module dir */
233 d->modules = debugfs_create_dir("modules", d->fs);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000234
David Brazdil0f672f62019-12-10 10:32:29 +0000235 debugfs_create_file("fw_soft_regs_rd", 0444, d->fs, d,
236 &soft_regs_ctrl_fops);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000237
238 return d;
David Brazdil0f672f62019-12-10 10:32:29 +0000239}
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000240
David Brazdil0f672f62019-12-10 10:32:29 +0000241void skl_debugfs_exit(struct skl_dev *skl)
242{
243 struct skl_debug *d = skl->debugfs;
244
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000245 debugfs_remove_recursive(d->fs);
David Brazdil0f672f62019-12-10 10:32:29 +0000246
247 d = NULL;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000248}