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