1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
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.
6 // Copyright(c) 2018-2023 Intel Corporation. All rights reserved.
9 #include <linux/debugfs.h>
11 #include <linux/pm_runtime.h>
12 #include <sound/sof/debug.h>
13 #include <sound/sof/ipc4/header.h>
16 #include "ipc4-telemetry.h"
17 #include "ipc4-priv.h"
19 static void __iomem *sof_ipc4_query_exception_address(struct snd_sof_dev *sdev)
21 u32 type = SOF_IPC4_DEBUG_SLOT_TELEMETRY;
22 size_t telemetry_slot_offset;
25 telemetry_slot_offset = sof_ipc4_find_debug_slot_offset_by_type(sdev, type);
26 if (!telemetry_slot_offset)
29 /* skip the first separator magic number */
30 offset = telemetry_slot_offset + sizeof(u32);
32 return sdev->bar[sdev->mailbox_bar] + offset;
35 static ssize_t sof_telemetry_entry_read(struct file *file, char __user *buffer,
36 size_t count, loff_t *ppos)
38 struct snd_sof_dfsentry *dfse = file->private_data;
39 struct snd_sof_dev *sdev = dfse->sdev;
40 void __iomem *io_addr;
47 /* skip the first separator magic number */
48 if (pos >= SOF_IPC4_DEBUG_SLOT_SIZE - 4 || !count)
50 if (count > SOF_IPC4_DEBUG_SLOT_SIZE - 4 - pos)
51 count = SOF_IPC4_DEBUG_SLOT_SIZE - 4 - pos;
53 io_addr = sof_ipc4_query_exception_address(sdev);
57 buf = kzalloc(SOF_IPC4_DEBUG_SLOT_SIZE - 4, GFP_KERNEL);
61 memcpy_fromio(buf, io_addr, SOF_IPC4_DEBUG_SLOT_SIZE - 4);
62 size_ret = copy_to_user(buffer, buf + pos, count);
74 static const struct file_operations sof_telemetry_fops = {
76 .read = sof_telemetry_entry_read,
79 void sof_ipc4_create_exception_debugfs_node(struct snd_sof_dev *sdev)
81 struct snd_sof_dfsentry *dfse;
83 dfse = devm_kzalloc(sdev->dev, sizeof(*dfse), GFP_KERNEL);
87 dfse->type = SOF_DFSENTRY_TYPE_IOMEM;
88 dfse->size = SOF_IPC4_DEBUG_SLOT_SIZE - 4;
89 dfse->access_type = SOF_DEBUGFS_ACCESS_ALWAYS;
92 list_add(&dfse->list, &sdev->dfsentry_list);
94 debugfs_create_file("exception", 0444, sdev->debugfs_root, dfse, &sof_telemetry_fops);