sound/soc/sof/stream-ipc.c
Source file repositories/reference/linux-study-clean/sound/soc/sof/stream-ipc.c
File Facts
- System
- Linux kernel
- Corpus path
sound/soc/sof/stream-ipc.c- Extension
.c- Size
- 3350 bytes
- Lines
- 132
- Domain
- Driver Families
- Bucket
- sound/soc
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/device.hlinux/export.hlinux/module.hlinux/types.hsound/pcm.hsound/sof/stream.hops.hsof-priv.hsof-audio.h
Detected Declarations
struct sof_streamfunction sof_ipc_msg_datafunction sof_set_stream_data_offsetfunction sof_stream_pcm_openfunction sof_stream_pcm_closeexport sof_ipc_msg_dataexport sof_set_stream_data_offsetexport sof_stream_pcm_openexport sof_stream_pcm_close
Annotated Snippet
struct sof_stream {
size_t posn_offset;
};
/* Mailbox-based Generic IPC implementation */
int sof_ipc_msg_data(struct snd_sof_dev *sdev,
struct snd_sof_pcm_stream *sps,
void *p, size_t sz)
{
if (!sps || !sdev->stream_box.size) {
snd_sof_dsp_mailbox_read(sdev, sdev->dsp_box.offset, p, sz);
} else {
size_t posn_offset;
if (sps->substream) {
struct sof_stream *stream = sps->substream->runtime->private_data;
/* The stream might already be closed */
if (!stream)
return -ESTRPIPE;
posn_offset = stream->posn_offset;
} else if (sps->cstream) {
struct sof_compr_stream *sstream = sps->cstream->runtime->private_data;
if (!sstream)
return -ESTRPIPE;
posn_offset = sstream->posn_offset;
} else {
dev_err(sdev->dev, "%s: No stream opened\n", __func__);
return -EINVAL;
}
snd_sof_dsp_mailbox_read(sdev, posn_offset, p, sz);
}
return 0;
}
EXPORT_SYMBOL(sof_ipc_msg_data);
int sof_set_stream_data_offset(struct snd_sof_dev *sdev,
struct snd_sof_pcm_stream *sps,
size_t posn_offset)
{
/* check if offset is overflow or it is not aligned */
if (posn_offset > sdev->stream_box.size ||
posn_offset % sizeof(struct sof_ipc_stream_posn) != 0)
return -EINVAL;
posn_offset += sdev->stream_box.offset;
if (sps->substream) {
struct sof_stream *stream = sps->substream->runtime->private_data;
stream->posn_offset = posn_offset;
dev_dbg(sdev->dev, "pcm: stream dir %d, posn mailbox offset is %zu",
sps->substream->stream, posn_offset);
} else if (sps->cstream) {
struct sof_compr_stream *sstream = sps->cstream->runtime->private_data;
sstream->posn_offset = posn_offset;
dev_dbg(sdev->dev, "compr: stream dir %d, posn mailbox offset is %zu",
sps->cstream->direction, posn_offset);
} else {
dev_err(sdev->dev, "No stream opened");
return -EINVAL;
}
return 0;
}
EXPORT_SYMBOL(sof_set_stream_data_offset);
int sof_stream_pcm_open(struct snd_sof_dev *sdev,
struct snd_pcm_substream *substream)
{
struct sof_stream *stream = kmalloc_obj(*stream);
if (!stream)
return -ENOMEM;
/* binding pcm substream to hda stream */
substream->runtime->private_data = stream;
/* align to DMA minimum transfer size */
snd_pcm_hw_constraint_step(substream->runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 4);
/* avoid circular buffer wrap in middle of period */
Annotation
- Immediate include surface: `linux/device.h`, `linux/export.h`, `linux/module.h`, `linux/types.h`, `sound/pcm.h`, `sound/sof/stream.h`, `ops.h`, `sof-priv.h`.
- Detected declarations: `struct sof_stream`, `function sof_ipc_msg_data`, `function sof_set_stream_data_offset`, `function sof_stream_pcm_open`, `function sof_stream_pcm_close`, `export sof_ipc_msg_data`, `export sof_set_stream_data_offset`, `export sof_stream_pcm_open`, `export sof_stream_pcm_close`.
- Atlas domain: Driver Families / sound/soc.
- Implementation status: integration implementation candidate.
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.