|
| 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 | +} |
0 commit comments