Repository navigation
Conversation
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>
There was a problem hiding this comment.
🟡 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); |
| 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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


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:
ALSA: compress: allow O_RDWR open on playback streams for MAP_SHARED mmap: WhenCONFIG_SND_COMPRESS_ACCEL=y,O_RDWRselectsSND_COMPRESS_ACCEL, causing playback-only compress devices opened withO_RDWRto failsnd_compr_open()whileO_WRONLYfails VFSmmap(..., MAP_SHARED)(-EACCES). AllowO_RDWRopen on playback-only compress devices sommap(PROT_READ | PROT_WRITE, MAP_SHARED)works cleanly.ASoC: SOF: ipc4-compress: allow raw PCM/BESPOKE streams without decoder widget: Allowsof_ipc4_compr_set_params()to proceed whensof_ipc4_compr_get_module()returnsNULLforSND_AUDIOCODEC_PCM/SND_AUDIOCODEC_BESPOKEstreams.(Includes the 3 base
mmap/SNDRV_COMPRESS_ACKcommits from #5966 ontopic/sof-devfor standalone CI/testing.)Hardware Verification
/dev/snd/comprC0D55) at 200 Hz and 1 kHz concurrently with 4-ch and 6-ch PCM playback (zero XRUNs, zero kernel errors).