Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions src/audio/dai-legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -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;
}
}

Expand Down
51 changes: 33 additions & 18 deletions src/audio/dai-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <rtos/cache.h>
#include <rtos/init.h>
#include <sof/lib/dai.h>
#include <sof/lib/notifier.h>
#include <sof/lib/uuid.h>
#include <sof/lib/dma.h>
#include <sof/lib/memory.h>
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand All @@ -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() */
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/include/sof/lib/dai-legacy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/include/sof/lib/dai-zephyr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 */
Expand Down
1 change: 0 additions & 1 deletion src/include/sof/lib/notifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/lib/dai.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading