Skip to content
Closed
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
2 changes: 1 addition & 1 deletion src/audio/copier/copier.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static int mic_privacy_configure(struct processing_module *mod, struct copier_da
cd->mic_priv = mic_priv_data;

ret = notifier_register(cd->mic_priv, NULL, NOTIFIER_ID_MIC_PRIVACY_STATE_CHANGE,
mic_privacy_event, 0);
mic_privacy_event);

if (ret != 0)
mod_free(mod, mic_priv_data);
Expand Down
16 changes: 12 additions & 4 deletions src/audio/copier/copier_dai.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,13 +415,21 @@ __cold void copier_dai_free(struct processing_module *mod)
assert_can_be_cold();

for (int i = 0; i < cd->endpoint_num; i++) {
dai_common_free(cd->dd[i]);
mod_free(mod, cd->dd[i]->gain_data);
mod_free(mod, cd->dd[i]);
if (cd->dd[i]) {
if (cd->dd[i]->gain_data) {
mod_free(mod, cd->dd[i]->gain_data);
cd->dd[i]->gain_data = NULL;
}
dai_common_free(cd->dd[i]);
mod_free(mod, cd->dd[i]);
cd->dd[i] = NULL;
}
}
/* only dai have multi endpoint case */
if (cd->multi_endpoint_buffer)
if (cd->multi_endpoint_buffer) {
buffer_free(cd->multi_endpoint_buffer);
cd->multi_endpoint_buffer = NULL;
}
}

int copier_dai_prepare(struct comp_dev *dev, struct copier_data *cd)
Expand Down
6 changes: 2 additions & 4 deletions src/audio/dai-legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ int dai_assign_group(struct dai_data *dd, struct comp_dev *dev, uint32_t group_i
group_id, dd->group->num_dais);

/* Register for the atomic trigger event */
notifier_register(dev, dd->group, NOTIFIER_ID_DAI_TRIGGER,
dai_atomic_trigger, 0);
notifier_register(dev, dd->group, NOTIFIER_ID_DAI_TRIGGER, dai_atomic_trigger);

return 0;
}
Expand Down Expand Up @@ -635,8 +634,7 @@ int dai_common_config_prepare(struct dai_data *dd, struct comp_dev *dev)
dd->chan->index);

/* setup callback */
notifier_register(dev, dd->chan, NOTIFIER_ID_DMA_COPY,
dai_dma_cb, 0);
notifier_register(dev, dd->chan, NOTIFIER_ID_DMA_COPY, dai_dma_cb);

return 0;
}
Expand Down
33 changes: 26 additions & 7 deletions src/audio/dai-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ __cold int dai_assign_group(struct dai_data *dd, struct comp_dev *dev, uint32_t
group_id, dd->group->num_dais);

/* Register for the atomic trigger event */
notifier_register(dev, dd->group, NOTIFIER_ID_DAI_TRIGGER,
dai_atomic_trigger, 0);
notifier_register(dev, dd->group, NOTIFIER_ID_DAI_TRIGGER, dai_atomic_trigger);

return 0;
}
Expand Down Expand Up @@ -682,25 +681,40 @@ __cold void dai_common_free(struct dai_data *dd)
{
assert_can_be_cold();

if (!dd)
return;

#ifdef CONFIG_SOF_TELEMETRY_IO_PERFORMANCE_MEASUREMENTS
io_perf_monitor_release_slot(dd->io_perf_dai_byte_count);
#endif

if (dd->group)
if (dd->group) {
dai_group_put(dd->group);
dd->group = NULL;
}

if (dd->chan_index >= 0) {
sof_dma_release_channel(dd->dma, dd->chan_index);
if (dd->dma)
sof_dma_release_channel(dd->dma, dd->chan_index);
dd->chan_index = -EINVAL;
}

sof_dma_put(dd->dma);
if (dd->dma) {
sof_dma_put(dd->dma);
dd->dma = NULL;
}

dai_release_llp_slot(dd);

dai_put(dd->dai);
if (dd->dai) {
dai_put(dd->dai);
dd->dai = NULL;
}

sof_heap_free(dd->alloc_ctx.heap, dd->dai_spec_config);
if (dd->dai_spec_config) {
sof_heap_free(dd->alloc_ctx.heap, dd->dai_spec_config);
dd->dai_spec_config = NULL;
}
}

__cold static void dai_free(struct comp_dev *dev)
Expand All @@ -709,6 +723,11 @@ __cold static void dai_free(struct comp_dev *dev)

assert_can_be_cold();

if (!dd) {
comp_free_device(dev);
return;
}

if (dd->group)
notifier_unregister(dev, dd->group, NOTIFIER_ID_DAI_TRIGGER);

Expand Down
3 changes: 1 addition & 2 deletions src/audio/host-legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -876,8 +876,7 @@ int host_common_params(struct host_data *hd, struct comp_dev *dev,

if (err >= 0)
/* set up callback */
notifier_register(dev, hd->chan, NOTIFIER_ID_DMA_COPY,
cb ? : host_dma_cb, 0);
notifier_register(dev, hd->chan, NOTIFIER_ID_DMA_COPY, cb ? : host_dma_cb);

return err;
}
Expand Down
2 changes: 1 addition & 1 deletion src/audio/host-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ static int host_get_status(struct comp_dev *dev, struct host_data *hd, struct dm
}

/* Minimum time between 2 consecutive "no bytes to copy" messages in milliseconds */
#define SOF_MIN_NO_BYTES_INTERVAL_MS 20
#define SOF_MIN_NO_BYTES_INTERVAL_MS 1000

static inline bool host_handle_eos(struct host_data *hd, struct comp_dev *dev,
uint32_t avail_samples)
Expand Down
2 changes: 1 addition & 1 deletion src/audio/kpb.c
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ static int kpb_prepare(struct comp_dev *dev)
#else
/* Register KPB for notification */
ret = notifier_register(dev, NULL, NOTIFIER_ID_KPB_CLIENT_EVT,
kpb_event_handler, 0);
kpb_event_handler);
#endif /* CONFIG_AMS */

if (ret < 0) {
Expand Down
7 changes: 6 additions & 1 deletion src/audio/pipeline/pipeline-params.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,13 @@ static int pipeline_comp_prepare(struct comp_dev *current,
}

err = comp_prepare(current);
if (err < 0 || err == PPL_STATUS_PATH_STOP)
if (err < 0 || err == PPL_STATUS_PATH_STOP) {
if (err < 0) {
pipe_err(current->pipeline, "comp_prepare for comp 0x%x failed %d",
dev_comp_id(current), err);
}
return err;
}

return pipeline_for_each_comp(current, ctx, dir);
}
Expand Down
1 change: 1 addition & 0 deletions src/debug/debug_stream/debug_stream_text_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <sof/common.h>
#include <zephyr/logging/log.h>
#include <zephyr/arch/exception.h>
#include <zephyr/llext/symbol.h>

#include <user/debug_stream_text_msg.h>

Expand Down
2 changes: 1 addition & 1 deletion src/drivers/dw/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ static struct dma_chan_data *dw_dma_channel_get(struct dma *dma,
atomic_add(&dma->num_channels_busy, 1);
#if !CONFIG_DMA_HW_LLI
notifier_register(&dma->chan[i], &dma->chan[i],
NOTIFIER_ID_DMA_IRQ, dw_dma_chan_reload_lli_cb, 0);
NOTIFIER_ID_DMA_IRQ, dw_dma_chan_reload_lli_cb);
#endif

/* return channel */
Expand Down
3 changes: 3 additions & 0 deletions src/include/sof/lib/agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ static inline void sa_set_panic_on_delay(bool enabled)
{
struct sa *sa = sof_get()->sa;

if (!sa)
return;

if (enabled)
atomic_add(&sa->panic_cnt, 1);
else
Expand Down
6 changes: 1 addition & 5 deletions src/include/sof/lib/notifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
#define NOTIFIER_TARGET_CORE_LOCAL NOTIFIER_TARGET_CORE_MASK(cpu_get_id())
#define NOTIFIER_TARGET_CORE_ALL_MASK 0xFFFFFFFF

/** \brief Notifier flags. */
#define NOTIFIER_FLAG_AGGREGATE BIT(0)

enum notify_id {
NOTIFIER_ID_CPU_FREQ = 0, /* struct clock_notify_data * */
NOTIFIER_ID_SSP_FREQ, /* struct clock_notify_data * */
Expand Down Expand Up @@ -71,10 +68,9 @@ typedef void (*notifier_callback_t)(void *receiver_data, enum notify_id event_ty
* some specific notifier_event() calls when not NULL.
* @param event_type list of callbacks to be added to
* @param callback callback function
* @param flags see NOTIFIER_FLAG_* above
*/
int notifier_register(void *receiver_data, void *caller_id_filter, enum notify_id event_type,
notifier_callback_t callback, uint32_t flags);
notifier_callback_t callback);

/** Unregister all callbacks matching that arguments tuple. NULL acts
* as a wildcard.
Expand Down
6 changes: 6 additions & 0 deletions src/lib/dai.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,9 @@ void dai_put(struct dai *dai)
int ret;
struct k_heap *heap = NULL;

if (!dai)
return;

#ifdef CONFIG_SOF_USERSPACE_LL
heap = zephyr_ll_user_heap();
#endif
Expand Down Expand Up @@ -443,6 +446,9 @@ void dai_put(struct dai *dai)
int ret;
k_spinlock_key_t key;

if (!dai)
return;

key = k_spin_lock(&dai->lock);
if (--dai->sref == 0) {
ret = dai_remove(dai);
Expand Down
3 changes: 3 additions & 0 deletions src/lib/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ void z_impl_sof_dma_put(struct sof_dma *dma)
{
k_spinlock_key_t key;

if (!dma)
return;

key = k_spin_lock(&dma->lock);
if (--dma->sref == 0) {
sof_heap_free(dma->heap, dma->chan);
Expand Down
16 changes: 2 additions & 14 deletions src/lib/notifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ struct callback_handle {
};

int notifier_register(void *receiver, void *caller, enum notify_id type,
void (*cb)(void *arg, enum notify_id type, void *data),
uint32_t flags)
void (*cb)(void *arg, enum notify_id type, void *data))
{
struct notify *notify = *arch_notify_get();
struct callback_handle *handle;
Expand All @@ -49,18 +48,7 @@ int notifier_register(void *receiver, void *caller, enum notify_id type,

key = k_spin_lock(&notify->lock);

/* Find already registered event of this type */
if (flags & NOTIFIER_FLAG_AGGREGATE &&
!list_is_empty(&notify->list[type])) {
handle = container_of((&notify->list[type])->next,
struct callback_handle, list);
handle->num_registrations++;

goto out;
}

handle = rzalloc(SOF_MEM_FLAG_USER,
sizeof(*handle));
handle = rzalloc(SOF_MEM_FLAG_USER, sizeof(*handle));

if (!handle) {
tr_err(&nt_tr, "callback handle allocation failed.");
Expand Down
7 changes: 7 additions & 0 deletions src/platform/intel/cavs/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <rtos/wait.h>
#include <sof/platform.h>
#include <sof/schedule/edf_schedule.h>
#include <sof/schedule/dp_schedule.h>
#include <sof/schedule/ll_schedule.h>
#include <sof/schedule/ll_schedule_domain.h>
#include <sof/trace/trace.h>
Expand Down Expand Up @@ -122,6 +123,12 @@ int platform_init(struct sof *sof)
sof->platform_timer_domain = timer_domain_init(sof->platform_timer, 0);
scheduler_init_ll(sof->platform_timer_domain);

#if CONFIG_ZEPHYR_DP_SCHEDULER
ret = scheduler_dp_init();
if (ret < 0)
return ret;
#endif

/* init the system agent */
trace_point(TRACE_BOOT_PLATFORM_AGENT);
sa_init(sof, CONFIG_SYSTICK_PERIOD);
Expand Down
3 changes: 1 addition & 2 deletions src/schedule/dma_single_chan_domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ static int dma_single_chan_domain_register(struct ll_schedule_domain *domain,

/* register for source change notifications */
if (register_needed)
notifier_register(domain, NULL, NOTIFIER_ID_DMA_DOMAIN_CHANGE,
dma_domain_changed, 0);
notifier_register(domain, NULL, NOTIFIER_ID_DMA_DOMAIN_CHANGE, dma_domain_changed);

dma_domain->owner = channel->core;

Expand Down
3 changes: 1 addition & 2 deletions src/schedule/ll_schedule_xtos.c
Original file line number Diff line number Diff line change
Expand Up @@ -795,8 +795,7 @@ int scheduler_init_ll(struct ll_schedule_domain *domain)
sch->domain = domain;

/* notification of clock changes */
notifier_register(sch, NULL, NOTIFIER_CLK_CHANGE_ID(domain->clk),
ll_scheduler_notify, 0);
notifier_register(sch, NULL, NOTIFIER_CLK_CHANGE_ID(domain->clk), ll_scheduler_notify);

scheduler_init(domain->type, &schedule_ll_ops, sch);

Expand Down
9 changes: 5 additions & 4 deletions src/schedule/zephyr_dp_schedule.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,30 @@ SOF_DEFINE_REG_UUID(dp_sched);

DECLARE_TR_CTX(dp_tr, SOF_UUID(dp_sched_uuid), LOG_LEVEL_INFO);

#define DP_LOCK_INIT(i, _) Z_SEM_INITIALIZER(dp_lock[i], 1, 1)
/* k_mutex, not k_sem: priority inheritance keeps a preempted DP holder from stalling LL */
#define DP_LOCK_INIT(i, _) Z_MUTEX_INITIALIZER(dp_lock[i])
#define DP_LOCK_INIT_LIST LISTIFY(CONFIG_MP_MAX_NUM_CPUS, DP_LOCK_INIT, (,))

/* User threads don't need access to this array. Access is performed from
* the kernel space via a syscall. Array must be placed in special section
* to be qualified as initialized by the gen_kobject_list.py script.
*/
static
STRUCT_SECTION_ITERABLE_ARRAY(k_sem, dp_lock, CONFIG_MP_MAX_NUM_CPUS) = { DP_LOCK_INIT_LIST };
STRUCT_SECTION_ITERABLE_ARRAY(k_mutex, dp_lock, CONFIG_MP_MAX_NUM_CPUS) = { DP_LOCK_INIT_LIST };

/* Each per-core instance of DP scheduler has separate structures; hence, locks are per-core.
*
* TODO: consider using cpu_get_id() instead of supplying core as a parameter.
*/
unsigned int scheduler_dp_lock(uint16_t core)
{
k_sem_take(&dp_lock[core], K_FOREVER);
k_mutex_lock(&dp_lock[core], K_FOREVER);
return core;
}

void scheduler_dp_unlock(unsigned int key)
{
k_sem_give(&dp_lock[key]);
k_mutex_unlock(&dp_lock[key]);
}

void scheduler_dp_grant(k_tid_t thread_id, uint16_t core)
Expand Down
2 changes: 1 addition & 1 deletion test/cmocka/src/notifier_mocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void notifier_event(const void *caller, enum notify_id type, uint32_t core_mask,
}

int notifier_register(void *receiver, void *caller, enum notify_id type,
void (*cb)(void *arg, enum notify_id type, void *data), uint32_t flags)
void (*cb)(void *arg, enum notify_id type, void *data))
{
struct notify *notify = *arch_notify_get();
struct callback_handle *handle;
Expand Down
Loading
Loading