From 387ab6e050093598fd8a987bc6320ebdba7d305f Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Sat, 21 Nov 2026 12:39:56 +0000 Subject: [PATCH 1/2] dai: trigger a DAI group by walking its DAIs instead of the notifier The last DAI of a group to receive a trigger command triggered the whole group with a NOTIFIER_ID_DAI_TRIGGER event on the local core, which every DAI of the group registered for. The notifier is not usable from user space, and Phase 5 of the kernel / user-space partition removes it. Keep the DAIs of a group in a list in the group instead. A DAI joins it when it is assigned to the group and leaves it when it is freed, and the last DAI to receive the command walks the list. The list is in the same order as the notifier list, and the group still returns the error of the last trigger. This also fixes two problems with IPC4, where the DAI is a copier and dai_assign_group() gets the copier device: - the notifier callback took the DAI data from comp_get_drvdata(), which is the module and not the DAI data for a copier; - copier_dai_free() did not unregister from the notifier. The walk uses the DAI data of each member and its component, and dai_common_free() removes the DAI from the group. irq_local_disable() is privileged in user-space LL builds, so there the group trigger takes the LL scheduler lock, as the copier does for its channel map update. It is re-entrant, so this is safe if the caller holds it. The other builds keep the IRQ lock. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- src/audio/dai-legacy.c | 36 +++++++++++----------- src/audio/dai-zephyr.c | 51 +++++++++++++++++++++----------- src/include/sof/lib/dai-legacy.h | 5 ++-- src/include/sof/lib/dai-zephyr.h | 5 ++-- src/lib/dai.c | 1 + 5 files changed, 59 insertions(+), 39 deletions(-) diff --git a/src/audio/dai-legacy.c b/src/audio/dai-legacy.c index 73f8704de36c..1b537ec18ac8 100644 --- a/src/audio/dai-legacy.c +++ b/src/audio/dai-legacy.c @@ -44,14 +44,20 @@ SOF_DEFINE_REG_UUID(dai); static int dai_comp_trigger_internal(struct dai_data *dd, struct comp_dev *dev, int cmd); -static void dai_atomic_trigger(void *arg, enum notify_id type, void *data) +/* Trigger all DAIs of a group, called by the last DAI to receive the command */ +static int dai_group_trigger(struct dai_group *group, int cmd) { - struct comp_dev *dev = arg; - struct dai_data *dd = comp_get_drvdata(dev); - struct dai_group *group = dd->group; + struct list_item *item; + int ret = 0; + + /* return the error of the last trigger */ + list_for_item(item, &group->dais) { + struct dai_data *dd = container_of(item, struct dai_data, group_item); + + ret = dai_comp_trigger_internal(dd, dd->dai_dev, cmd); + } - /* Atomic context set by the last DAI to receive trigger command */ - group->trigger_ret = dai_comp_trigger_internal(dd, dev, group->trigger_cmd); + return ret; } /* Assign DAI to a group */ @@ -78,8 +84,9 @@ int dai_assign_group(struct dai_data *dd, struct comp_dev *dev, uint32_t group_i comp_dbg(dev, "group %d num %d", group_id, dd->group->num_dais); - /* Register for the atomic trigger event */ - notifier_register(dev, dd->group, NOTIFIER_ID_DAI_TRIGGER, dai_atomic_trigger); + /* The group trigger walks the DAIs by their data */ + dd->dai_dev = dev; + list_item_prepend(&dd->group_item, &dd->group->dais); return 0; } @@ -215,8 +222,10 @@ static struct comp_dev *dai_new(const struct comp_driver *drv, void dai_common_free(struct dai_data *dd) { - if (dd->group) + if (dd->group) { + list_item_del(&dd->group_item); dai_group_put(dd->group); + } if (dd->chan) { dd->chan->dev_data = NULL; @@ -237,9 +246,6 @@ static void dai_free(struct comp_dev *dev) { struct dai_data *dd = comp_get_drvdata(dev); - if (dd->group) - notifier_unregister(dev, dd->group, NOTIFIER_ID_DAI_TRIGGER); - if (dd->chan) notifier_unregister(dev, dd->chan, NOTIFIER_ID_DMA_COPY); @@ -873,12 +879,8 @@ int dai_common_trigger(struct dai_data *dd, struct comp_dev *dev, int cmd) */ irq_local_disable(irq_flags); - notifier_event(group, NOTIFIER_ID_DAI_TRIGGER, - BIT(cpu_get_id()), NULL, 0); + ret = dai_group_trigger(group, cmd); irq_local_enable(irq_flags); - - /* return error of last trigger */ - ret = group->trigger_ret; } } diff --git a/src/audio/dai-zephyr.c b/src/audio/dai-zephyr.c index 2cbdfe998a2c..22fea2e80dbf 100644 --- a/src/audio/dai-zephyr.c +++ b/src/audio/dai-zephyr.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -73,14 +72,20 @@ SOF_DEFINE_REG_UUID(dai); static int dai_comp_trigger_internal(struct dai_data *dd, struct comp_dev *dev, int cmd); -static void dai_atomic_trigger(void *arg, enum notify_id type, void *data) +/* Trigger all DAIs of a group, called by the last DAI to receive the command */ +static int dai_group_trigger(struct dai_group *group, int cmd) { - struct comp_dev *dev = arg; - struct dai_data *dd = comp_get_drvdata(dev); - struct dai_group *group = dd->group; + struct list_item *item; + int ret = 0; + + /* return the error of the last trigger */ + list_for_item(item, &group->dais) { + struct dai_data *dd = container_of(item, struct dai_data, group_item); + + ret = dai_comp_trigger_internal(dd, dd->dai_dev, cmd); + } - /* Atomic context set by the last DAI to receive trigger command */ - group->trigger_ret = dai_comp_trigger_internal(dd, dev, group->trigger_cmd); + return ret; } /* Assign DAI to a group */ @@ -109,8 +114,9 @@ __cold int dai_assign_group(struct dai_data *dd, struct comp_dev *dev, uint32_t comp_dbg(dev, "group %d num %d", group_id, dd->group->num_dais); - /* Register for the atomic trigger event */ - notifier_register(dev, dd->group, NOTIFIER_ID_DAI_TRIGGER, dai_atomic_trigger); + /* The group trigger walks the DAIs by their data */ + dd->dai_dev = dev; + list_item_prepend(&dd->group_item, &dd->group->dais); return 0; } @@ -799,8 +805,10 @@ __cold void dai_common_free(struct dai_data *dd) #endif telemetry_unregister_dai(dd); - if (dd->group) + if (dd->group) { + list_item_del(&dd->group_item); dai_group_put(dd->group); + } dai_dma_release_channel(dd); sof_dma_put(dd->dma); @@ -822,9 +830,6 @@ __cold static void dai_free(struct comp_dev *dev) assert_can_be_cold(); - if (dd->group) - notifier_unregister(dev, dd->group, NOTIFIER_ID_DAI_TRIGGER); - dai_common_free(dd); /* heap is NULL to match what is passed in dai_new() */ @@ -1636,7 +1641,9 @@ static int dai_comp_trigger_internal(struct dai_data *dd, struct comp_dev *dev, int dai_common_trigger(struct dai_data *dd, struct comp_dev *dev, int cmd) { struct dai_group *group = dd->group; +#ifndef CONFIG_SOF_USERSPACE_LL uint32_t irq_flags; +#endif int ret = 0; /* DAI not in a group, use normal trigger */ @@ -1675,13 +1682,21 @@ int dai_common_trigger(struct dai_data *dd, struct comp_dev *dev, int cmd) * synchronously. */ + /* In user-space builds irq_local_disable() is + * privileged, use the LL scheduler lock instead + * (re-entrant, so safe if the caller holds it). + */ +#ifdef CONFIG_SOF_USERSPACE_LL + user_ll_lock_sched(dev->ipc_config.core); +#else irq_local_disable(irq_flags); - notifier_event(group, NOTIFIER_ID_DAI_TRIGGER, - NOTIFIER_TARGET_CORE_LOCAL, NULL, 0); +#endif + ret = dai_group_trigger(group, cmd); +#ifdef CONFIG_SOF_USERSPACE_LL + user_ll_unlock_sched(dev->ipc_config.core); +#else irq_local_enable(irq_flags); - - /* return error of last trigger */ - ret = group->trigger_ret; +#endif } } diff --git a/src/include/sof/lib/dai-legacy.h b/src/include/sof/lib/dai-legacy.h index 4e050e6b87c8..5c28b198dc37 100644 --- a/src/include/sof/lib/dai-legacy.h +++ b/src/include/sof/lib/dai-legacy.h @@ -182,6 +182,7 @@ struct dai_data { struct dai *dai; struct dma *dma; struct dai_group *group; /* NULL if no group assigned */ + struct list_item group_item; /* in group->dais */ int xrun; /* true if we are doing xrun recovery */ pcm_converter_func process; /* processing function */ @@ -363,9 +364,9 @@ struct dai_group { int trigger_cmd; /** - * Last trigger error + * DAIs in this group, linked by struct dai_data::group_item */ - int trigger_ret; + struct list_item dais; /** * Group list diff --git a/src/include/sof/lib/dai-zephyr.h b/src/include/sof/lib/dai-zephyr.h index 69a7d965483e..91da81147ef7 100644 --- a/src/include/sof/lib/dai-zephyr.h +++ b/src/include/sof/lib/dai-zephyr.h @@ -92,9 +92,9 @@ struct dai_group { int trigger_cmd; /** - * Last trigger error + * DAIs in this group, linked by struct dai_data::group_item */ - int trigger_ret; + struct list_item dais; /** * Group list @@ -152,6 +152,7 @@ struct dai_data { struct dai *dai; struct sof_dma *dma; struct dai_group *group; /* NULL if no group assigned */ + struct list_item group_item; /* in group->dais */ int xrun; /* true if we are doing xrun recovery */ pcm_converter_func process; /* processing function */ diff --git a/src/lib/dai.c b/src/lib/dai.c index 5b196c75eb8f..718f207f6583 100644 --- a/src/lib/dai.c +++ b/src/lib/dai.c @@ -106,6 +106,7 @@ __cold static struct dai_group *dai_group_alloc(void) return NULL; } + list_init(&group->dais); list_item_prepend(&group->list, dai_groups); return group; From db9aea9c71acbb2299e997b17d76e1ab32caee80 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Sat, 21 Nov 2026 12:40:03 +0000 Subject: [PATCH 2/2] notifier: remove NOTIFIER_ID_DAI_TRIGGER DAI groups no longer use the notifier: the last DAI to receive a trigger command walks the DAIs of its group. Remove the event ID. The IDs after it are renumbered. They are internal to the firmware. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- src/include/sof/lib/notifier.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/include/sof/lib/notifier.h b/src/include/sof/lib/notifier.h index e5413a512cb4..07fdffb15aa4 100644 --- a/src/include/sof/lib/notifier.h +++ b/src/include/sof/lib/notifier.h @@ -26,7 +26,6 @@ enum notify_id { NOTIFIER_ID_DMA_DOMAIN_CHANGE, /* struct dma_chan_data * */ NOTIFIER_ID_DMA_COPY, /* struct dma_cb_data* */ NOTIFIER_ID_DMA_IRQ, /* struct dma_chan_data * */ - NOTIFIER_ID_DAI_TRIGGER, /* struct dai_group * */ NOTIFIER_ID_MIC_PRIVACY_STATE_CHANGE, /* struct mic_privacy_settings * */ NOTIFIER_ID_VAD, /* int * (WEBRTC_VAD_SPEECH / WEBRTC_VAD_SILENCE) */ NOTIFIER_ID_COUNT