Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug stream debugfs #5154

Open
wants to merge 4 commits into
base: topic/sof-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/sound/sof/ipc4/header.h
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ struct sof_ipc4_notify_resource_data {
#define SOF_IPC4_DEBUG_SLOT_DEBUG_LOG 0x474f4c00 /* byte 0: core ID */
#define SOF_IPC4_DEBUG_SLOT_GDB_STUB 0x42444700
#define SOF_IPC4_DEBUG_SLOT_TELEMETRY 0x4c455400
#define SOF_IPC4_DEBUG_SLOT_DEBUG_STREAM 0x53523134
#define SOF_IPC4_DEBUG_SLOT_BROKEN 0x44414544

/**
Expand Down
2 changes: 1 addition & 1 deletion sound/soc/sof/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ snd-sof-y += ipc3.o ipc3-loader.o ipc3-topology.o ipc3-control.o ipc3-pcm.o\
endif
ifneq ($(CONFIG_SND_SOC_SOF_IPC4),)
snd-sof-y += ipc4.o ipc4-loader.o ipc4-topology.o ipc4-control.o ipc4-pcm.o\
ipc4-mtrace.o ipc4-telemetry.o
ipc4-mtrace.o ipc4-debug-slot-debugfs.o
endif

# SOF client support
Expand Down
91 changes: 91 additions & 0 deletions sound/soc/sof/ipc4-debug-slot-debugfs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
//
// This file is provided under a dual BSD/GPLv2 license. When using or
// redistributing this file, you may do so under either license.
//
// Copyright(c) 2024 Intel Corporation.
//

#include <linux/debugfs.h>
#include <linux/io.h>
#include <linux/pm_runtime.h>
#include <sound/sof/debug.h>
#include <sound/sof/ipc4/header.h>
#include "sof-priv.h"
#include "ops.h"
#include "ipc4-priv.h"

struct debug_slot_fs_ud {
struct snd_sof_dfsentry dfse;
u32 slot_type;
size_t data_offset;
};

static ssize_t sof_debug_slot_debugfs_entry_read(struct file *file, char __user *buffer,
size_t count, loff_t *ppos)
{
struct debug_slot_fs_ud *ud = file->private_data;
struct snd_sof_dfsentry *dfse = &ud->dfse;
struct snd_sof_dev *sdev = dfse->sdev;
size_t doffset = ud->data_offset;
u32 type = ud->slot_type;
loff_t pos = *ppos;
size_t size_ret;
u32 offset;
u8 *buf;

if (pos < 0)
return -EINVAL;
if (pos + doffset >= SOF_IPC4_DEBUG_SLOT_SIZE || !count)
return 0;
if (count > SOF_IPC4_DEBUG_SLOT_SIZE - pos - doffset)
count = SOF_IPC4_DEBUG_SLOT_SIZE - pos - doffset;

offset = sof_ipc4_find_debug_slot_offset_by_type(sdev, type);
if (!offset)
return -EFAULT;

buf = kzalloc(SOF_IPC4_DEBUG_SLOT_SIZE - doffset, GFP_KERNEL);
if (!buf)
return -ENOMEM;

sof_mailbox_read(sdev, offset + doffset, buf, SOF_IPC4_DEBUG_SLOT_SIZE - doffset);
size_ret = copy_to_user(buffer, buf + pos, count);
if (size_ret) {
kfree(buf);
return -EFAULT;
}

*ppos = pos + count;
kfree(buf);

return count;
}

static const struct file_operations sof_debug_stream_fops = {
.open = simple_open,
.read = sof_debug_slot_debugfs_entry_read,
.llseek = default_llseek,
};

void sof_ipc4_create_debug_slot_debugfs_node(struct snd_sof_dev *sdev, u32 slot_type,
size_t data_offset, const char *name)
{
struct debug_slot_fs_ud *ud;

ud = devm_kzalloc(sdev->dev, sizeof(*ud), GFP_KERNEL);
if (!ud)
return;

ud->dfse.type = SOF_DFSENTRY_TYPE_IOMEM;
ud->dfse.size = SOF_IPC4_DEBUG_SLOT_SIZE;
ud->dfse.access_type = SOF_DEBUGFS_ACCESS_ALWAYS;
ud->dfse.sdev = sdev;

ud->slot_type = slot_type;
ud->data_offset = data_offset;

list_add(&ud->dfse.list, &sdev->dfsentry_list);

debugfs_create_file(name, 0444, sdev->debugfs_root, ud, &sof_debug_stream_fops);
}
2 changes: 2 additions & 0 deletions sound/soc/sof/ipc4-priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,6 @@ void sof_ipc4_update_cpc_from_manifest(struct snd_sof_dev *sdev,
size_t sof_ipc4_find_debug_slot_offset_by_type(struct snd_sof_dev *sdev,
u32 slot_type);

void sof_ipc4_create_debug_slot_debugfs_node(struct snd_sof_dev *sdev, u32 slot_type,
size_t data_offset, const char *name);
#endif
95 changes: 0 additions & 95 deletions sound/soc/sof/ipc4-telemetry.c

This file was deleted.

73 changes: 0 additions & 73 deletions sound/soc/sof/ipc4-telemetry.h

This file was deleted.

7 changes: 6 additions & 1 deletion sound/soc/sof/ipc4.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,12 @@ static int ipc4_fw_ready(struct snd_sof_dev *sdev, struct sof_ipc4_msg *ipc4_msg
if (!sdev->first_boot)
return 0;

sof_ipc4_create_exception_debugfs_node(sdev);
/* sizeof(u32)is for skiping the first separator magic number */
sof_ipc4_create_debug_slot_debugfs_node(sdev, SOF_IPC4_DEBUG_SLOT_TELEMETRY,
sizeof(u32), "exception");

sof_ipc4_create_debug_slot_debugfs_node(sdev, SOF_IPC4_DEBUG_SLOT_DEBUG_STREAM,
0, "debug_stream");

return sof_ipc4_init_msg_memory(sdev);
}
Expand Down
Loading