Skip to content

Commit 672baba

Browse files
author
Jyri Sarha
committed
ASoC: SOF: IPC4: Simple debugfs file for debug-stream debug window slot
The "debug-stream" debugfs file simply maps the debug-stream debug slot as a debugfs file. The decoding is left to user-space tools. For details on the debug-stream encodeing, see src/debug/debug_stream/debug_stream_slot.h in SOF sources [1]. [1] https://github.com/thesofproject/sof Signed-off-by: Jyri Sarha <[email protected]>
1 parent af0b041 commit 672baba

File tree

4 files changed

+98
-1
lines changed

4 files changed

+98
-1
lines changed

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-stream.o
1515
endif
1616

1717
# SOF client support

sound/soc/sof/ipc4-debug-stream.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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. All rights reserved.
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-debug-stream.h"
17+
#include "ipc4-priv.h"
18+
19+
static ssize_t sof_debug_stream_entry_read(struct file *file, char __user *buffer,
20+
size_t count, loff_t *ppos)
21+
{
22+
struct snd_sof_dfsentry *dfse = file->private_data;
23+
struct snd_sof_dev *sdev = dfse->sdev;
24+
u32 type = SOF_IPC4_DEBUG_SLOT_DEBUG_STREAM;
25+
loff_t pos = *ppos;
26+
size_t size_ret;
27+
u32 offset;
28+
u8 *buf;
29+
30+
if (pos < 0)
31+
return -EINVAL;
32+
if (pos >= SOF_IPC4_DEBUG_SLOT_SIZE || !count)
33+
return 0;
34+
if (count > SOF_IPC4_DEBUG_SLOT_SIZE - pos)
35+
count = SOF_IPC4_DEBUG_SLOT_SIZE - pos;
36+
37+
offset = sof_ipc4_find_debug_slot_offset_by_type(sdev, type);
38+
if (!offset)
39+
return -EFAULT;
40+
41+
buf = kzalloc(SOF_IPC4_DEBUG_SLOT_SIZE, GFP_KERNEL);
42+
if (!buf)
43+
return -ENOMEM;
44+
45+
sof_mailbox_read(sdev, offset, buf, SOF_IPC4_DEBUG_SLOT_SIZE);
46+
size_ret = copy_to_user(buffer, buf + pos, count);
47+
if (size_ret) {
48+
kfree(buf);
49+
return -EFAULT;
50+
}
51+
52+
*ppos = pos + count;
53+
kfree(buf);
54+
55+
return count;
56+
}
57+
58+
static const struct file_operations sof_debug_stream_fops = {
59+
.open = simple_open,
60+
.read = sof_debug_stream_entry_read,
61+
.llseek = default_llseek,
62+
};
63+
64+
void sof_ipc4_create_debug_stream_debugfs_node(struct snd_sof_dev *sdev)
65+
{
66+
struct snd_sof_dfsentry *dfse;
67+
68+
dfse = devm_kzalloc(sdev->dev, sizeof(*dfse), GFP_KERNEL);
69+
if (!dfse)
70+
return;
71+
72+
dfse->type = SOF_DFSENTRY_TYPE_IOMEM;
73+
dfse->size = SOF_IPC4_DEBUG_SLOT_SIZE;
74+
dfse->access_type = SOF_DEBUGFS_ACCESS_ALWAYS;
75+
dfse->sdev = sdev;
76+
77+
list_add(&dfse->list, &sdev->dfsentry_list);
78+
79+
debugfs_create_file("debug_stream", 0444, sdev->debugfs_root, dfse, &sof_debug_stream_fops);
80+
}

sound/soc/sof/ipc4-debug-stream.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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. All rights reserved.
7+
*/
8+
9+
#ifndef __SOUND_SOC_SOF_IPC4_DEBUG_STREAM_H
10+
#define __SOUND_SOC_SOF_IPC4_DEBUG_STREAM_H
11+
12+
void sof_ipc4_create_debug_stream_debugfs_node(struct snd_sof_dev *sdev);
13+
14+
#endif

sound/soc/sof/ipc4.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "ipc4-fw-reg.h"
1717
#include "ipc4-priv.h"
1818
#include "ipc4-telemetry.h"
19+
#include "ipc4-debug-stream.h"
1920
#include "ops.h"
2021

2122
static const struct sof_ipc4_fw_status {
@@ -582,6 +583,8 @@ static int ipc4_fw_ready(struct snd_sof_dev *sdev, struct sof_ipc4_msg *ipc4_msg
582583

583584
sof_ipc4_create_exception_debugfs_node(sdev);
584585

586+
sof_ipc4_create_debug_stream_debugfs_node(sdev);
587+
585588
return sof_ipc4_init_msg_memory(sdev);
586589
}
587590

0 commit comments

Comments
 (0)