Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  *  skl-debug.c - Debugfs for skl driver
0004  *
0005  *  Copyright (C) 2016-17 Intel Corp
0006  */
0007 
0008 #include <linux/pci.h>
0009 #include <linux/debugfs.h>
0010 #include <uapi/sound/skl-tplg-interface.h>
0011 #include "skl.h"
0012 #include "skl-sst-dsp.h"
0013 #include "skl-sst-ipc.h"
0014 #include "skl-topology.h"
0015 #include "../common/sst-dsp.h"
0016 #include "../common/sst-dsp-priv.h"
0017 
0018 #define MOD_BUF     PAGE_SIZE
0019 #define FW_REG_BUF  PAGE_SIZE
0020 #define FW_REG_SIZE 0x60
0021 
0022 struct skl_debug {
0023     struct skl_dev *skl;
0024     struct device *dev;
0025 
0026     struct dentry *fs;
0027     struct dentry *modules;
0028     u8 fw_read_buff[FW_REG_BUF];
0029 };
0030 
0031 static ssize_t skl_print_pins(struct skl_module_pin *m_pin, char *buf,
0032                 int max_pin, ssize_t size, bool direction)
0033 {
0034     int i;
0035     ssize_t ret = 0;
0036 
0037     for (i = 0; i < max_pin; i++) {
0038         ret += scnprintf(buf + size, MOD_BUF - size,
0039                 "%s %d\n\tModule %d\n\tInstance %d\n\t"
0040                 "In-used %s\n\tType %s\n"
0041                 "\tState %d\n\tIndex %d\n",
0042                 direction ? "Input Pin:" : "Output Pin:",
0043                 i, m_pin[i].id.module_id,
0044                 m_pin[i].id.instance_id,
0045                 m_pin[i].in_use ? "Used" : "Unused",
0046                 m_pin[i].is_dynamic ? "Dynamic" : "Static",
0047                 m_pin[i].pin_state, i);
0048         size += ret;
0049     }
0050     return ret;
0051 }
0052 
0053 static ssize_t skl_print_fmt(struct skl_module_fmt *fmt, char *buf,
0054                     ssize_t size, bool direction)
0055 {
0056     return scnprintf(buf + size, MOD_BUF - size,
0057             "%s\n\tCh %d\n\tFreq %d\n\tBit depth %d\n\t"
0058             "Valid bit depth %d\n\tCh config %#x\n\tInterleaving %d\n\t"
0059             "Sample Type %d\n\tCh Map %#x\n",
0060             direction ? "Input Format:" : "Output Format:",
0061             fmt->channels, fmt->s_freq, fmt->bit_depth,
0062             fmt->valid_bit_depth, fmt->ch_cfg,
0063             fmt->interleaving_style, fmt->sample_type,
0064             fmt->ch_map);
0065 }
0066 
0067 static ssize_t module_read(struct file *file, char __user *user_buf,
0068                size_t count, loff_t *ppos)
0069 {
0070     struct skl_module_cfg *mconfig = file->private_data;
0071     struct skl_module *module = mconfig->module;
0072     struct skl_module_res *res = &module->resources[mconfig->res_idx];
0073     char *buf;
0074     ssize_t ret;
0075 
0076     buf = kzalloc(MOD_BUF, GFP_KERNEL);
0077     if (!buf)
0078         return -ENOMEM;
0079 
0080     ret = scnprintf(buf, MOD_BUF, "Module:\n\tUUID %pUL\n\tModule id %d\n"
0081             "\tInstance id %d\n\tPvt_id %d\n", mconfig->guid,
0082             mconfig->id.module_id, mconfig->id.instance_id,
0083             mconfig->id.pvt_id);
0084 
0085     ret += scnprintf(buf + ret, MOD_BUF - ret,
0086             "Resources:\n\tCPC %#x\n\tIBS %#x\n\tOBS %#x\t\n",
0087             res->cpc, res->ibs, res->obs);
0088 
0089     ret += scnprintf(buf + ret, MOD_BUF - ret,
0090             "Module data:\n\tCore %d\n\tIn queue %d\n\t"
0091             "Out queue %d\n\tType %s\n",
0092             mconfig->core_id, mconfig->max_in_queue,
0093             mconfig->max_out_queue,
0094             mconfig->is_loadable ? "loadable" : "inbuilt");
0095 
0096     ret += skl_print_fmt(mconfig->in_fmt, buf, ret, true);
0097     ret += skl_print_fmt(mconfig->out_fmt, buf, ret, false);
0098 
0099     ret += scnprintf(buf + ret, MOD_BUF - ret,
0100             "Fixup:\n\tParams %#x\n\tConverter %#x\n",
0101             mconfig->params_fixup, mconfig->converter);
0102 
0103     ret += scnprintf(buf + ret, MOD_BUF - ret,
0104             "Module Gateway:\n\tType %#x\n\tVbus %#x\n\tHW conn %#x\n\tSlot %#x\n",
0105             mconfig->dev_type, mconfig->vbus_id,
0106             mconfig->hw_conn_type, mconfig->time_slot);
0107 
0108     ret += scnprintf(buf + ret, MOD_BUF - ret,
0109             "Pipeline:\n\tID %d\n\tPriority %d\n\tConn Type %d\n\t"
0110             "Pages %#x\n", mconfig->pipe->ppl_id,
0111             mconfig->pipe->pipe_priority, mconfig->pipe->conn_type,
0112             mconfig->pipe->memory_pages);
0113 
0114     ret += scnprintf(buf + ret, MOD_BUF - ret,
0115             "\tParams:\n\t\tHost DMA %d\n\t\tLink DMA %d\n",
0116             mconfig->pipe->p_params->host_dma_id,
0117             mconfig->pipe->p_params->link_dma_id);
0118 
0119     ret += scnprintf(buf + ret, MOD_BUF - ret,
0120             "\tPCM params:\n\t\tCh %d\n\t\tFreq %d\n\t\tFormat %d\n",
0121             mconfig->pipe->p_params->ch,
0122             mconfig->pipe->p_params->s_freq,
0123             mconfig->pipe->p_params->s_fmt);
0124 
0125     ret += scnprintf(buf + ret, MOD_BUF - ret,
0126             "\tLink %#x\n\tStream %#x\n",
0127             mconfig->pipe->p_params->linktype,
0128             mconfig->pipe->p_params->stream);
0129 
0130     ret += scnprintf(buf + ret, MOD_BUF - ret,
0131             "\tState %d\n\tPassthru %s\n",
0132             mconfig->pipe->state,
0133             mconfig->pipe->passthru ? "true" : "false");
0134 
0135     ret += skl_print_pins(mconfig->m_in_pin, buf,
0136             mconfig->max_in_queue, ret, true);
0137     ret += skl_print_pins(mconfig->m_out_pin, buf,
0138             mconfig->max_out_queue, ret, false);
0139 
0140     ret += scnprintf(buf + ret, MOD_BUF - ret,
0141             "Other:\n\tDomain %d\n\tHomogeneous Input %s\n\t"
0142             "Homogeneous Output %s\n\tIn Queue Mask %d\n\t"
0143             "Out Queue Mask %d\n\tDMA ID %d\n\tMem Pages %d\n\t"
0144             "Module Type %d\n\tModule State %d\n",
0145             mconfig->domain,
0146             mconfig->homogenous_inputs ? "true" : "false",
0147             mconfig->homogenous_outputs ? "true" : "false",
0148             mconfig->in_queue_mask, mconfig->out_queue_mask,
0149             mconfig->dma_id, mconfig->mem_pages, mconfig->m_state,
0150             mconfig->m_type);
0151 
0152     ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
0153 
0154     kfree(buf);
0155     return ret;
0156 }
0157 
0158 static const struct file_operations mcfg_fops = {
0159     .open = simple_open,
0160     .read = module_read,
0161     .llseek = default_llseek,
0162 };
0163 
0164 
0165 void skl_debug_init_module(struct skl_debug *d,
0166             struct snd_soc_dapm_widget *w,
0167             struct skl_module_cfg *mconfig)
0168 {
0169     debugfs_create_file(w->name, 0444, d->modules, mconfig,
0170                 &mcfg_fops);
0171 }
0172 
0173 static ssize_t fw_softreg_read(struct file *file, char __user *user_buf,
0174                    size_t count, loff_t *ppos)
0175 {
0176     struct skl_debug *d = file->private_data;
0177     struct sst_dsp *sst = d->skl->dsp;
0178     size_t w0_stat_sz = sst->addr.w0_stat_sz;
0179     void __iomem *in_base = sst->mailbox.in_base;
0180     void __iomem *fw_reg_addr;
0181     unsigned int offset;
0182     char *tmp;
0183     ssize_t ret = 0;
0184 
0185     tmp = kzalloc(FW_REG_BUF, GFP_KERNEL);
0186     if (!tmp)
0187         return -ENOMEM;
0188 
0189     fw_reg_addr = in_base - w0_stat_sz;
0190     memset(d->fw_read_buff, 0, FW_REG_BUF);
0191 
0192     if (w0_stat_sz > 0)
0193         __ioread32_copy(d->fw_read_buff, fw_reg_addr, w0_stat_sz >> 2);
0194 
0195     for (offset = 0; offset < FW_REG_SIZE; offset += 16) {
0196         ret += scnprintf(tmp + ret, FW_REG_BUF - ret, "%#.4x: ", offset);
0197         hex_dump_to_buffer(d->fw_read_buff + offset, 16, 16, 4,
0198                    tmp + ret, FW_REG_BUF - ret, 0);
0199         ret += strlen(tmp + ret);
0200 
0201         /* print newline for each offset */
0202         if (FW_REG_BUF - ret > 0)
0203             tmp[ret++] = '\n';
0204     }
0205 
0206     ret = simple_read_from_buffer(user_buf, count, ppos, tmp, ret);
0207     kfree(tmp);
0208 
0209     return ret;
0210 }
0211 
0212 static const struct file_operations soft_regs_ctrl_fops = {
0213     .open = simple_open,
0214     .read = fw_softreg_read,
0215     .llseek = default_llseek,
0216 };
0217 
0218 struct skl_debug *skl_debugfs_init(struct skl_dev *skl)
0219 {
0220     struct skl_debug *d;
0221 
0222     d = devm_kzalloc(&skl->pci->dev, sizeof(*d), GFP_KERNEL);
0223     if (!d)
0224         return NULL;
0225 
0226     /* create the debugfs dir with platform component's debugfs as parent */
0227     d->fs = debugfs_create_dir("dsp", skl->component->debugfs_root);
0228 
0229     d->skl = skl;
0230     d->dev = &skl->pci->dev;
0231 
0232     /* now create the module dir */
0233     d->modules = debugfs_create_dir("modules", d->fs);
0234 
0235     debugfs_create_file("fw_soft_regs_rd", 0444, d->fs, d,
0236                 &soft_regs_ctrl_fops);
0237 
0238     return d;
0239 }
0240 
0241 void skl_debugfs_exit(struct skl_dev *skl)
0242 {
0243     struct skl_debug *d = skl->debugfs;
0244 
0245     debugfs_remove_recursive(d->fs);
0246 
0247     d = NULL;
0248 }