[PATCH 07/28] ALSA: Support nonatomic dmaengine PCMs

From: James Calligeros

Date: Sun Sep 20 2026 - 00:58:02 EST


From: Martin Povišer <povik+lin@xxxxxxxxxxx>

Add support for nonatomic dmaengine PCMs.

Signed-off-by: Martin Povišer <povik+lin@xxxxxxxxxxx>
Signed-off-by: James Calligeros <jcalligeros99@xxxxxxxxx>
---
sound/core/pcm_dmaengine.c | 32 ++++++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/sound/core/pcm_dmaengine.c b/sound/core/pcm_dmaengine.c
index e59b561b849d..839ff2711f5e 100644
--- a/sound/core/pcm_dmaengine.c
+++ b/sound/core/pcm_dmaengine.c
@@ -22,6 +22,8 @@
struct dmaengine_pcm_runtime_data {
struct dma_chan *dma_chan;
dma_cookie_t cookie;
+ struct work_struct complete_wq; /* for nonatomic PCM */
+ struct snd_pcm_substream *substream;

unsigned int pos;
};
@@ -147,6 +149,24 @@ static void dmaengine_pcm_dma_complete(void *arg)
snd_pcm_period_elapsed(substream);
}

+static void dmaengine_pcm_dma_complete_nonatomic(struct work_struct *wq)
+{
+ struct dmaengine_pcm_runtime_data *prtd = container_of(wq,
+ struct dmaengine_pcm_runtime_data,
+ complete_wq);
+ struct snd_pcm_substream *substream = prtd->substream;
+
+ dmaengine_pcm_dma_complete(substream);
+}
+
+static void dmaengine_pcm_dma_complete_nonatomic_callback(void *arg)
+{
+ struct snd_pcm_substream *substream = arg;
+ struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
+
+ schedule_work(&prtd->complete_wq);
+}
+
static int dmaengine_pcm_prepare_and_submit(struct snd_pcm_substream *substream)
{
struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
@@ -169,7 +189,11 @@ static int dmaengine_pcm_prepare_and_submit(struct snd_pcm_substream *substream)
if (!desc)
return -ENOMEM;

- desc->callback = dmaengine_pcm_dma_complete;
+ if (substream->pcm->nonatomic)
+ desc->callback = dmaengine_pcm_dma_complete_nonatomic_callback;
+ else
+ desc->callback = dmaengine_pcm_dma_complete;
+
desc->callback_param = substream;
prtd->cookie = dmaengine_submit(desc);

@@ -322,6 +346,10 @@ int snd_dmaengine_pcm_open(struct snd_pcm_substream *substream,
if (!prtd)
return -ENOMEM;

+ if (substream->pcm->nonatomic)
+ INIT_WORK(&prtd->complete_wq, dmaengine_pcm_dma_complete_nonatomic);
+
+ prtd->substream = substream;
prtd->dma_chan = chan;

substream->runtime->private_data = prtd;
@@ -361,6 +389,8 @@ static void __snd_dmaengine_pcm_close(struct snd_pcm_substream *substream,
*/
dmaengine_terminate_async(prtd->dma_chan);
dmaengine_synchronize(prtd->dma_chan);
+ if (substream->pcm->nonatomic)
+ flush_work(&prtd->complete_wq);
if (release_channel)
dma_release_channel(prtd->dma_chan);
kfree(prtd);

--
2.55.0