Skip to content

ALSA: compress: mmap playback O_RDWR and SOF raw metadata stream support - #6071

Draft
lgirdwood wants to merge 5 commits into
thesofproject:topic/sof-devfrom
lgirdwood:topic/compress-mmap-metadata
Draft

lgirdwood wants to merge 5 commits into
thesofproject:topic/sof-devfrom
lgirdwood:topic/compress-mmap-metadata

Conversation

@lgirdwood

Copy link
Copy Markdown
Member

Extends the ALSA compress mmap series (#5966) so compressed playback host-copier pipelines can stream raw/bespoke DMA metadata rings directly into an SOF DSP module's secondary input pin without requiring a codec widget:

  1. ALSA: compress: allow O_RDWR open on playback streams for MAP_SHARED mmap: When CONFIG_SND_COMPRESS_ACCEL=y, O_RDWR selects SND_COMPRESS_ACCEL, causing playback-only compress devices opened with O_RDWR to fail snd_compr_open() while O_WRONLY fails VFS mmap(..., MAP_SHARED) (-EACCES). Allow O_RDWR open on playback-only compress devices so mmap(PROT_READ | PROT_WRITE, MAP_SHARED) works cleanly.
  2. ASoC: SOF: ipc4-compress: allow raw PCM/BESPOKE streams without decoder widget: Allow sof_ipc4_compr_set_params() to proceed when sof_ipc4_compr_get_module() returns NULL for SND_AUDIOCODEC_PCM / SND_AUDIOCODEC_BESPOKE streams.

(Includes the 3 base mmap / SNDRV_COMPRESS_ACK commits from #5966 on topic/sof-dev for standalone CI/testing.)

Hardware Verification

  • Verified on Intel WCL-U RVP (Ladybird, RT722 SoundWire) alongside the SOF Resonance Audio dual-pin DMA pose feed (/dev/snd/comprC0D55) at 200 Hz and 1 kHz concurrently with 4-ch and 6-ch PCM playback (zero XRUNs, zero kernel errors).

Support mapping the compressed DMA buffer to user space by implementing
snd_compr_mmap(). If the driver provides stream->ops->mmap, delegate to
it; otherwise fallback to snd_dma_buffer_mmap() on runtime->dma_buffer_p.

Introduce the SNDRV_COMPRESS_ACK ioctl (_IOW('C', 0x24, __u64)) to allow
user space to acknowledge written bytes when operating in mmap mode.
This callback directly mirrors the regular ALSA PCM mmap flow: in ALSA
PCM, user space writes to the mmap buffer and commits frames via
snd_pcm_mmap_commit(), which advances appl_ptr and invokes
substream->ops->ack(substream) via pcm_lib_apply_appl_ptr().

Similarly, for compressed streams, SNDRV_COMPRESS_ACK informs the driver
of committed bytes, validates the byte count against available buffer space,
updates runtime->total_bytes_available (analogous to advancing appl_ptr),
invokes the optional stream->ops->ack(stream, bytes) driver hook,
transitions state from SETUP to PREPARED on initial commit, and wakes up
waiters on runtime->sleep.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Add snd_soc_component_compr_mmap() to iterate over runtime components and
invoke component->driver->compress_ops->mmap() when defined.

Hook up soc_compr_mmap() in soc_compr_ops and soc_compr_dyn_ops so that
user-space mmap requests on compressed ALSA devices are routed to the
underlying ASoC component drivers.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Implement sof_ipc4_compr_mmap() to map the runtime DMA buffer
(runtime->dma_buffer_p or &stream->dma_buffer) into user space via
snd_dma_buffer_mmap().

Implement sof_ipc4_compr_ack() callback and align
SOF_IPC4_COMPR_MIN_FRAGMENT_SIZE to 128 bytes to match Intel HDA/ACE
DMA burst hardware boundaries.

For SOF on Intel HDA and ACE platforms, the host-to-DSP transfer is
driven autonomously by hardware DMA stream descriptors from host DRAM
without requiring per-block register writes or mailbox doorbells, exactly
as in standard SOF PCM where ops->ack is a no-op / NULL. The callback is
implemented as a no-op here to fulfill the struct snd_compress_ops
interface, maintain symmetry with platforms requiring doorbells/cache
flushing, and permit future platform-specific notifications.

Register .mmap and .ack in sof_ipc4_compressed_ops.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
…mmap

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
…er widget

Skip looking up or requiring a decoder/encoder process module during
sof_ipc4_compr_set_params() when codec.id is SND_AUDIOCODEC_PCM or
SND_AUDIOCODEC_BESPOKE and no codec widget is present in the pipeline.

This allows compressed playback host-copier pipelines to stream raw or
metadata payloads (such as Resonance Audio spatial pose rings) directly
into an effect module's secondary input pin without instantiating an
unnecessary codec widget.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical issues remain in capture accounting, playback read direction checks, and mmap locking, risking incorrect buffer state, DMA corruption, deadlocks, and access to freed memory.

5 open issues
What changed in this PR

Extends ALSA compressed-stream mmap support through ASoC and SOF, enabling playback DMA rings to carry raw metadata without a decoder widget.

Changes:

  • Allows O_RDWR opens on playback devices and adds mmap buffer access with SNDRV_COMPRESS_ACK.
  • Routes mmap callbacks through ASoC to SOF’s DMA buffers.
  • Supports decoder-free PCM/BESPOKE streams and lowers SOF’s minimum fragment size to 128 bytes.
File Description
sound/​soc/​sof/​ipc4-compress.c Adds DMA mmap and ACK callbacks, decoder-free streams, and callback guards.
sound/​soc/​soc-compress.c Wires mmap into static and dynamic compress operations.
sound/​soc/​soc-component.c Adds component-level compress mmap dispatch.
sound/​core/​compress_offload.c Implements playback O_RDWR support, mmap dispatch, and ACK handling.
include/​uapi/​sound/​compress_offload.h Defines the SNDRV_COMPRESS_ACK ioctl.
include/​sound/​soc-component.h Declares the component mmap helper.

Review effort: Balanced

Comment on lines +119 to +121
if ((f->f_flags & O_ACCMODE) == O_RDWR &&
compr->direction == SND_COMPRESS_PLAYBACK) {
dirn = SND_COMPRESS_PLAYBACK;
Comment on lines +359 to +361
stream->runtime->total_bytes_available += bytes;

if (stream->runtime->state == SNDRV_PCM_STATE_SETUP) {
Comment on lines +520 to +524
if (stream->ops->mmap)
return stream->ops->mmap(stream, vma);

if (runtime->dma_buffer_p)
return snd_dma_buffer_mmap(runtime->dma_buffer_p, vma);
Comment thread sound/soc/soc-component.c
struct snd_soc_component *component;
int i, ret = -ENXIO;

snd_soc_dpcm_mutex_lock(rtd);
Comment on lines +340 to +347
switch (stream->runtime->state) {
case SNDRV_PCM_STATE_SETUP:
case SNDRV_PCM_STATE_PREPARED:
case SNDRV_PCM_STATE_RUNNING:
break;
default:
return -EBADFD;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants