Skip to content

Commit 1dc00a6

Browse files
committed
ASoC: SOF: Intel: Fix pipeline state transitions for aggregate DAIs
For aggregate DAIs (num_cpus > 1) the pre_trigger/post_trigger callbacks send pipeline state IPCs per-DAI without considering that multiple DAIs may share the same pipeline. This causes premature state transitions where the pipeline goes RUNNING before all link DMAs have started, or individual DAIs send redundant IPCs for shared pipelines. Fix this by checking the HDA stream running state in post_trigger: - START/PAUSE_RELEASE: defer RUNNING IPC until all DAIs sharing the same pipeline have their link DMA streams running - STOP/SUSPEND/PAUSE_PUSH: use pipeline state dedup so the PAUSED IPC is sent once regardless of how many DAIs share the pipeline The running-state check naturally handles all aggregate topologies: shared pipelines, independent pipelines, and mixed cases without requiring per-pipeline counters. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
1 parent 2240389 commit 1dc00a6

1 file changed

Lines changed: 59 additions & 1 deletion

File tree

sound/soc/sof/intel/hda-dai-ops.c

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,39 @@ static struct hdac_ext_link *sdw_get_hlink(struct snd_sof_dev *sdev,
356356
return hdac_bus_eml_sdw_get_hlink(bus);
357357
}
358358

359+
/*
360+
* Check if all CPU DAIs sharing the same pipeline (spipe) have their link
361+
* DMA streams running. Used to gate pipeline state transitions for aggregate
362+
* DAIs: the RUNNING IPC is deferred until the last DAI's link DMA has started.
363+
*/
364+
static bool hda_ipc4_all_spipe_dmas_running(struct snd_pcm_substream *substream,
365+
struct snd_sof_pipeline *target_spipe)
366+
{
367+
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
368+
struct snd_soc_dai *dai;
369+
int i;
370+
371+
for_each_rtd_cpu_dais(rtd, i, dai) {
372+
struct snd_soc_dapm_widget *w;
373+
struct snd_sof_widget *sw;
374+
struct hdac_ext_stream *hext_stream;
375+
376+
w = snd_soc_dai_get_widget(dai, substream->stream);
377+
if (!w)
378+
continue;
379+
380+
sw = w->dobj.private;
381+
if (!sw || sw->spipe != target_spipe)
382+
continue;
383+
384+
hext_stream = snd_soc_dai_get_dma_data(dai, substream);
385+
if (!hext_stream || !hext_stream->hstream.running)
386+
return false;
387+
}
388+
389+
return true;
390+
}
391+
359392
static int hda_ipc4_pre_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *cpu_dai,
360393
struct snd_pcm_substream *substream, int cmd)
361394
{
@@ -383,13 +416,22 @@ static int hda_ipc4_pre_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *cp
383416
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
384417
case SNDRV_PCM_TRIGGER_SUSPEND:
385418
case SNDRV_PCM_TRIGGER_STOP:
419+
/*
420+
* For aggregate DAIs with shared pipelines, the state check
421+
* deduplicates: the first DAI sends the IPC, subsequent DAIs
422+
* sharing the same pipeline see it already paused and skip.
423+
* For aggregate DAIs with different pipelines, each DAI pauses
424+
* its own pipeline independently.
425+
*/
426+
if (pipeline->state == SOF_IPC4_PIPE_PAUSED)
427+
break;
428+
386429
ret = sof_ipc4_set_pipeline_state(sdev, pipe_widget->instance_id,
387430
SOF_IPC4_PIPE_PAUSED);
388431
if (ret < 0)
389432
return ret;
390433

391434
pipeline->state = SOF_IPC4_PIPE_PAUSED;
392-
393435
break;
394436
default:
395437
dev_err(sdev->dev, "unknown trigger command %d\n", cmd);
@@ -436,11 +478,13 @@ static int hda_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *cpu_dai,
436478
static int hda_ipc4_post_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *cpu_dai,
437479
struct snd_pcm_substream *substream, int cmd)
438480
{
481+
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
439482
struct sof_ipc4_fw_data *ipc4_data = sdev->private;
440483
struct snd_sof_widget *pipe_widget;
441484
struct sof_ipc4_pipeline *pipeline;
442485
struct snd_sof_widget *swidget;
443486
struct snd_soc_dapm_widget *w;
487+
int num_cpus = rtd->dai_link->num_cpus;
444488
int ret = 0;
445489

446490
w = snd_soc_dai_get_widget(cpu_dai, substream->stream);
@@ -455,6 +499,16 @@ static int hda_ipc4_post_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *c
455499

456500
switch (cmd) {
457501
case SNDRV_PCM_TRIGGER_START:
502+
/*
503+
* For aggregated DAIs (num_cpus > 1), defer pipeline RUNNING
504+
* IPC until all CPU DAIs sharing this pipeline have started
505+
* their link DMAs via hda_trigger(). The running state of each
506+
* DAI's HDA stream naturally tracks completion.
507+
*/
508+
if (num_cpus > 1 &&
509+
!hda_ipc4_all_spipe_dmas_running(substream, swidget->spipe))
510+
break;
511+
458512
if (pipeline->state != SOF_IPC4_PIPE_PAUSED) {
459513
ret = sof_ipc4_set_pipeline_state(sdev, pipe_widget->instance_id,
460514
SOF_IPC4_PIPE_PAUSED);
@@ -473,6 +527,10 @@ static int hda_ipc4_post_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *c
473527
swidget->spipe->started_count++;
474528
break;
475529
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
530+
if (num_cpus > 1 &&
531+
!hda_ipc4_all_spipe_dmas_running(substream, swidget->spipe))
532+
break;
533+
476534
ret = sof_ipc4_set_pipeline_state(sdev, pipe_widget->instance_id,
477535
SOF_IPC4_PIPE_RUNNING);
478536
if (ret < 0)

0 commit comments

Comments
 (0)