sound/soc/sof/ipc3-dtrace.c
Source file repositories/reference/linux-study-clean/sound/soc/sof/ipc3-dtrace.c
File Facts
- System
- Linux kernel
- Corpus path
sound/soc/sof/ipc3-dtrace.c- Extension
.c- Size
- 17137 bytes
- Lines
- 670
- Domain
- Driver Families
- Bucket
- sound/soc
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/debugfs.hlinux/sched/signal.hsof-priv.hsof-audio.hops.hsof-utils.hipc3-priv.h
Detected Declarations
struct sof_dtrace_privenum sof_dtrace_statefunction trace_pos_update_expectedfunction trace_filter_append_elemfunction trace_filter_parse_entryfunction trace_filter_parsefunction ipc3_trace_update_filterfunction dfsentry_trace_filter_writefunction debugfs_create_trace_filterfunction sof_dtrace_set_host_offsetfunction sof_dtrace_availfunction sof_wait_dtrace_availfunction dfsentry_dtrace_readfunction dfsentry_dtrace_releasefunction debugfs_create_dtracefunction ipc3_dtrace_enablefunction ipc3_dtrace_initfunction ipc3_dtrace_posn_updatefunction ipc3_dtrace_fw_crashedfunction ipc3_dtrace_releasefunction ipc3_dtrace_suspendfunction ipc3_dtrace_resumefunction ipc3_dtrace_free
Annotated Snippet
static const struct file_operations sof_dfs_trace_filter_fops = {
.open = simple_open,
.write = dfsentry_trace_filter_write,
.llseek = default_llseek,
};
static int debugfs_create_trace_filter(struct snd_sof_dev *sdev)
{
struct snd_sof_dfsentry *dfse;
dfse = devm_kzalloc(sdev->dev, sizeof(*dfse), GFP_KERNEL);
if (!dfse)
return -ENOMEM;
dfse->sdev = sdev;
dfse->type = SOF_DFSENTRY_TYPE_BUF;
debugfs_create_file("filter", 0200, sdev->debugfs_root, dfse,
&sof_dfs_trace_filter_fops);
/* add to dfsentry list */
list_add(&dfse->list, &sdev->dfsentry_list);
return 0;
}
static bool sof_dtrace_set_host_offset(struct sof_dtrace_priv *priv, u32 new_offset)
{
u32 host_offset = READ_ONCE(priv->host_offset);
if (host_offset != new_offset) {
/* This is a bit paranoid and unlikely that it is needed */
u32 ret = cmpxchg(&priv->host_offset, host_offset, new_offset);
if (ret == host_offset)
return true;
}
return false;
}
static size_t sof_dtrace_avail(struct snd_sof_dev *sdev,
loff_t pos, size_t buffer_size)
{
struct sof_dtrace_priv *priv = sdev->fw_trace_data;
loff_t host_offset = READ_ONCE(priv->host_offset);
/*
* If host offset is less than local pos, it means write pointer of
* host DMA buffer has been wrapped. We should output the trace data
* at the end of host DMA buffer at first.
*/
if (host_offset < pos)
return buffer_size - pos;
/* If there is available trace data now, it is unnecessary to wait. */
if (host_offset > pos)
return host_offset - pos;
return 0;
}
static size_t sof_wait_dtrace_avail(struct snd_sof_dev *sdev, loff_t pos,
size_t buffer_size)
{
size_t ret = sof_dtrace_avail(sdev, pos, buffer_size);
struct sof_dtrace_priv *priv = sdev->fw_trace_data;
wait_queue_entry_t wait;
/* data immediately available */
if (ret)
return ret;
if (priv->dtrace_draining && !trace_pos_update_expected(priv)) {
/*
* tracing has ended and all traces have been
* read by client, return EOF
*/
priv->dtrace_draining = false;
return 0;
}
/* wait for available trace data from FW */
init_waitqueue_entry(&wait, current);
set_current_state(TASK_INTERRUPTIBLE);
add_wait_queue(&priv->trace_sleep, &wait);
if (!signal_pending(current)) {
/* set timeout to max value, no error code */
schedule_timeout(MAX_SCHEDULE_TIMEOUT);
}
Annotation
- Immediate include surface: `linux/debugfs.h`, `linux/sched/signal.h`, `sof-priv.h`, `sof-audio.h`, `ops.h`, `sof-utils.h`, `ipc3-priv.h`.
- Detected declarations: `struct sof_dtrace_priv`, `enum sof_dtrace_state`, `function trace_pos_update_expected`, `function trace_filter_append_elem`, `function trace_filter_parse_entry`, `function trace_filter_parse`, `function ipc3_trace_update_filter`, `function dfsentry_trace_filter_write`, `function debugfs_create_trace_filter`, `function sof_dtrace_set_host_offset`.
- Atlas domain: Driver Families / sound/soc.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.