Skip to content
Merged
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
78 changes: 40 additions & 38 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);

/* Atomic context set by the last DAI to receive trigger command */
group->trigger_ret = dai_comp_trigger_internal(dd, dev, group->trigger_cmd);
ret = dai_comp_trigger_internal(dd, dd->dai_dev, 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 @@ -851,37 +857,33 @@ int dai_common_trigger(struct dai_data *dd, struct comp_dev *dev, int cmd)
comp_dbg(dev, "begin atomic trigger for group %d",
group->group_id);
group->trigger_cmd = cmd;
group->trigger_counter = group->num_dais - 1;
group->trigger_counter = group->num_dais;
} else if (group->trigger_cmd != cmd) {
/* Already processing a different trigger command */
comp_err(dev, "already processing atomic trigger");
ret = -EAGAIN;
} else {
/* Count down the number of remaining DAIs required
* to receive the trigger command before atomic trigger
* takes place
*/
group->trigger_counter--;
comp_dbg(dev, "trigger counter %d, group %d",
group->trigger_counter, group->group_id);

if (!group->trigger_counter) {
/* The counter has reached 0, which means
* all DAIs have received the same trigger command
* and we may begin the actual trigger process
* synchronously.
*/

irq_local_disable(irq_flags);
notifier_event(group, NOTIFIER_ID_DAI_TRIGGER,
BIT(cpu_get_id()), NULL, 0);
irq_local_enable(irq_flags);

/* return error of last trigger */
ret = group->trigger_ret;
}
return -EAGAIN;
}

/* Count down the number of remaining DAIs required to receive the
* trigger command before the atomic trigger takes place. The first
* DAI counts too, so a group of one DAI triggers at once.
*/
group->trigger_counter--;
comp_dbg(dev, "trigger counter %d, group %d",
group->trigger_counter, group->group_id);

if (group->trigger_counter)
return 0;

/* The counter has reached 0, which means all DAIs have received the
* same trigger command and we may begin the actual trigger process
* synchronously.
*/

irq_local_disable(irq_flags);
ret = dai_group_trigger(group, cmd);
irq_local_enable(irq_flags);

return ret;
}

Expand Down
90 changes: 52 additions & 38 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);

/* Atomic context set by the last DAI to receive trigger command */
group->trigger_ret = dai_comp_trigger_internal(dd, dev, group->trigger_cmd);
ret = dai_comp_trigger_internal(dd, dd->dai_dev, 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 All @@ -1654,36 +1661,43 @@ int dai_common_trigger(struct dai_data *dd, struct comp_dev *dev, int cmd)
comp_dbg(dev, "begin atomic trigger for group %d",
group->group_id);
group->trigger_cmd = cmd;
group->trigger_counter = group->num_dais - 1;
group->trigger_counter = group->num_dais;
} else if (group->trigger_cmd != cmd) {
/* Already processing a different trigger command */
comp_err(dev, "already processing atomic trigger");
ret = -EAGAIN;
} else {
/* Count down the number of remaining DAIs required
* to receive the trigger command before atomic trigger
* takes place
*/
group->trigger_counter--;
comp_dbg(dev, "trigger counter %d, group %d",
group->trigger_counter, group->group_id);

if (!group->trigger_counter) {
/* The counter has reached 0, which means
* all DAIs have received the same trigger command
* and we may begin the actual trigger process
* synchronously.
*/
return -EAGAIN;
}

irq_local_disable(irq_flags);
notifier_event(group, NOTIFIER_ID_DAI_TRIGGER,
NOTIFIER_TARGET_CORE_LOCAL, NULL, 0);
irq_local_enable(irq_flags);
/* Count down the number of remaining DAIs required to receive the
* trigger command before the atomic trigger takes place. The first
* DAI counts too, so a group of one DAI triggers at once.
*/
group->trigger_counter--;
comp_dbg(dev, "trigger counter %d, group %d",
group->trigger_counter, group->group_id);

/* return error of last trigger */
ret = group->trigger_ret;
}
}
if (group->trigger_counter)
return 0;

/* The counter has reached 0, which means all DAIs have received the
* same trigger command and we may begin the actual trigger process
* 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);
#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);
#endif

return ret;
}
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
11 changes: 9 additions & 2 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 Expand Up @@ -154,7 +155,13 @@ __cold void dai_group_put(struct dai_group *group)

group->num_dais--;

/* Mark as unused if there are no more DAIs in this group */
if (!group->num_dais)
/* Mark as unused if there are no more DAIs in this group, and drop
* any trigger that was pending, so that the next group ID that reuses
* it starts from a clean state.
*/
if (!group->num_dais) {
group->group_id = 0;
group->trigger_counter = 0;
group->trigger_cmd = 0;
}
}
Loading
Loading