Skip to content

Commit 6702302

Browse files
author
Jyri Sarha
committed
ASoC: SOF: ipc4: Add sof_ipc4_create_debug_slot_debugfs_node()
Adds sof_ipc4_create_debug_slot_debugfs_node() -function for mapping a SOF Intel ipc4 debug window slot as debugfs file. The actual slot is specified with slot_type parameter. The alternatives are defined in include/sound/sof/ipc4/header.h and the slot is found with sof_ipc4_find_debug_slot_offset_by_type(). It also takes the data_offset parameter that specifies where the payload data in the slot begins. The portion that is mapped to the debugfs file is everything after the offset. The last parameter is the name of the file. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent b751bb2 commit 6702302

3 files changed

Lines changed: 94 additions & 1 deletion

File tree

sound/soc/sof/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ snd-sof-y += ipc3.o ipc3-loader.o ipc3-topology.o ipc3-control.o ipc3-pcm.o\
1111
endif
1212
ifneq ($(CONFIG_SND_SOC_SOF_IPC4),)
1313
snd-sof-y += ipc4.o ipc4-loader.o ipc4-topology.o ipc4-control.o ipc4-pcm.o\
14-
ipc4-mtrace.o ipc4-telemetry.o
14+
ipc4-mtrace.o ipc4-telemetry.o ipc4-debug-slot-debugfs.o
1515
endif
1616

1717
# SOF client support
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2+
//
3+
// This file is provided under a dual BSD/GPLv2 license. When using or
4+
// redistributing this file, you may do so under either license.
5+
//
6+
// Copyright(c) 2024 Intel Corporation.
7+
//
8+
9+
#include <linux/debugfs.h>
10+
#include <linux/io.h>
11+
#include <linux/pm_runtime.h>
12+
#include <sound/sof/debug.h>
13+
#include <sound/sof/ipc4/header.h>
14+
#include "sof-priv.h"
15+
#include "ops.h"
16+
#include "ipc4-priv.h"
17+
18+
struct debug_slot_fs_ud {
19+
struct snd_sof_dfsentry dfse;
20+
u32 slot_type;
21+
size_t data_offset;
22+
};
23+
24+
static ssize_t sof_debug_slot_debugfs_entry_read(struct file *file, char __user *buffer,
25+
size_t count, loff_t *ppos)
26+
{
27+
struct debug_slot_fs_ud *ud = file->private_data;
28+
struct snd_sof_dfsentry *dfse = &ud->dfse;
29+
struct snd_sof_dev *sdev = dfse->sdev;
30+
size_t doffset = ud->data_offset;
31+
u32 type = ud->slot_type;
32+
loff_t pos = *ppos;
33+
size_t size_ret;
34+
u32 offset;
35+
u8 *buf;
36+
37+
if (pos < 0)
38+
return -EINVAL;
39+
if (pos + doffset >= SOF_IPC4_DEBUG_SLOT_SIZE || !count)
40+
return 0;
41+
if (count > SOF_IPC4_DEBUG_SLOT_SIZE - pos - doffset)
42+
count = SOF_IPC4_DEBUG_SLOT_SIZE - pos - doffset;
43+
44+
offset = sof_ipc4_find_debug_slot_offset_by_type(sdev, type);
45+
if (!offset)
46+
return -EFAULT;
47+
48+
buf = kzalloc(SOF_IPC4_DEBUG_SLOT_SIZE - doffset, GFP_KERNEL);
49+
if (!buf)
50+
return -ENOMEM;
51+
52+
sof_mailbox_read(sdev, offset + doffset, buf, SOF_IPC4_DEBUG_SLOT_SIZE - doffset);
53+
size_ret = copy_to_user(buffer, buf + pos, count);
54+
if (size_ret) {
55+
kfree(buf);
56+
return -EFAULT;
57+
}
58+
59+
*ppos = pos + count;
60+
kfree(buf);
61+
62+
return count;
63+
}
64+
65+
static const struct file_operations sof_debug_stream_fops = {
66+
.open = simple_open,
67+
.read = sof_debug_slot_debugfs_entry_read,
68+
.llseek = default_llseek,
69+
};
70+
71+
void sof_ipc4_create_debug_slot_debugfs_node(struct snd_sof_dev *sdev, u32 slot_type,
72+
size_t data_offset, const char *name)
73+
{
74+
struct debug_slot_fs_ud *ud;
75+
76+
ud = devm_kzalloc(sdev->dev, sizeof(*ud), GFP_KERNEL);
77+
if (!ud)
78+
return;
79+
80+
ud->dfse.type = SOF_DFSENTRY_TYPE_IOMEM;
81+
ud->dfse.size = SOF_IPC4_DEBUG_SLOT_SIZE;
82+
ud->dfse.access_type = SOF_DEBUGFS_ACCESS_ALWAYS;
83+
ud->dfse.sdev = sdev;
84+
85+
ud->slot_type = slot_type;
86+
ud->data_offset = data_offset;
87+
88+
list_add(&ud->dfse.list, &sdev->dfsentry_list);
89+
90+
debugfs_create_file(name, 0444, sdev->debugfs_root, ud, &sof_debug_stream_fops);
91+
}

sound/soc/sof/ipc4-priv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,6 @@ void sof_ipc4_update_cpc_from_manifest(struct snd_sof_dev *sdev,
118118
size_t sof_ipc4_find_debug_slot_offset_by_type(struct snd_sof_dev *sdev,
119119
u32 slot_type);
120120

121+
void sof_ipc4_create_debug_slot_debugfs_node(struct snd_sof_dev *sdev, u32 slot_type,
122+
size_t data_offset, const char *name);
121123
#endif

0 commit comments

Comments
 (0)