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