diff --git a/src/audio/buffers/audio_buffer.c b/src/audio/buffers/audio_buffer.c index 1ecf8472dd65..0b0b22a191fe 100644 --- a/src/audio/buffers/audio_buffer.c +++ b/src/audio/buffers/audio_buffer.c @@ -24,8 +24,16 @@ int audio_buffer_attach_secondary_buffer(struct sof_audio_buffer *buffer, bool at_input, struct sof_audio_buffer *secondary_buffer) { +#ifdef CONFIG_DP_TO_DP_BIND + /* check per-side: allow attaching on both sides (needed for DP-to-DP) */ + if (at_input && buffer->secondary_buffer_sink) + return -EINVAL; + if (!at_input && buffer->secondary_buffer_source) + return -EINVAL; +#else if (buffer->secondary_buffer_sink || buffer->secondary_buffer_source) return -EINVAL; +#endif /* secondary buffer must share audio params with the primary buffer */ secondary_buffer->audio_stream_params = buffer->audio_stream_params; @@ -48,6 +56,19 @@ int audio_buffer_sync_secondary_buffer(struct sof_audio_buffer *buffer, size_t l struct sof_source *data_src; struct sof_sink *data_dst; +#ifdef CONFIG_DP_TO_DP_BIND + if (buffer->secondary_buffer_sink && + buffer->secondary_buffer_sink == buffer->secondary_buffer_source) { + /* + * DP-to-DP case: a single shared ring_buffer is attached on both sides. + * The source DP writes directly to the ring_buffer sink API, and the + * sink DP reads directly from the ring_buffer source API. + * No copying is needed during the LL cycle. + */ + return 0; + } +#endif + if (buffer->secondary_buffer_sink) { /* * audio_buffer sink API is shadowed, that means there's a secondary_buffer @@ -95,7 +116,12 @@ void audio_buffer_free(struct sof_audio_buffer *buffer) CORE_CHECK_STRUCT(buffer); #if CONFIG_PIPELINE_2_0 audio_buffer_free(buffer->secondary_buffer_sink); +#ifdef CONFIG_DP_TO_DP_BIND + if (buffer->secondary_buffer_source != buffer->secondary_buffer_sink) + audio_buffer_free(buffer->secondary_buffer_source); +#else audio_buffer_free(buffer->secondary_buffer_source); +#endif #endif /* CONFIG_PIPELINE_2_0 */ /* "virtual destructor": free the buffer internals and buffer memory */ buffer->ops->free(buffer); @@ -203,18 +229,14 @@ uint32_t audio_buffer_sink_get_lft(struct sof_sink *sink) return us_in_buffer; /* - * TODO, Currently there's no DP to DP connection - * >>> the code below is never accessible and won't work because of cache incoherence <<< - * - * to make DP to DP connection possible: + * NOTE: DP-to-DP connections are now supported via a single shared ring_buffer + * attached as secondary buffer on both sides of a comp_buffer. * - * 1) module data must be ALWAYS located in non cached memory alias, allowing - * cross core access to params like period (needed below) and calling - * module_get_deadline for the next module, regardless of cores the modules are - * running on - * 2) comp_buffer must be removed from all pipeline code, replaced with a generic abstract - * class audio_buffer - allowing using comp_buffer and ring_buffer without current - * "hybrid buffer" solution + * Future improvements: + * 1) module data should be in non-cached memory alias for reliable + * cross-core access to params like period and deadlines + * 2) comp_buffer should be replaced with generic audio_buffer + * throughout pipeline code (Pipeline 2.0) */ } diff --git a/src/audio/buffers/ring_buffer.c b/src/audio/buffers/ring_buffer.c index fde594d32424..1a6ada30d874 100644 --- a/src/audio/buffers/ring_buffer.c +++ b/src/audio/buffers/ring_buffer.c @@ -88,7 +88,6 @@ static inline void ring_buffer_writeback_shared(struct ring_buffer *ring_buffer, dcache_writeback_region(ptr, size); } - /** * @brief remove the queue from the list, free memory */ @@ -105,6 +104,16 @@ __cold static void ring_buffer_free(struct sof_audio_buffer *audio_buffer) sof_ctx_free(alloc, (__sparse_force void *)ring_buffer->_data_buffer); sof_ctx_free(alloc, ring_buffer); + +#ifdef CONFIG_DP_TO_DP_BIND + /* + * When CONFIG_DP_TO_DP_BIND is enabled, ipc4_comp_connect() takes an extra vregion + * reference for each ring_buffer created from a module vregion. The alloc ctx of a DP + * module lives inside its vregion and is freed by the last vregion_put(). + */ + if (alloc && alloc->vreg) + vregion_put(alloc->vreg); +#endif } static void ring_buffer_reset(struct sof_audio_buffer *audio_buffer) diff --git a/src/audio/copier/copier_dai.c b/src/audio/copier/copier_dai.c index 508972b4773c..a4c88554c4a6 100644 --- a/src/audio/copier/copier_dai.c +++ b/src/audio/copier/copier_dai.c @@ -424,13 +424,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) diff --git a/src/audio/dai-zephyr.c b/src/audio/dai-zephyr.c index 2cbdfe998a2c..197bc73e4e21 100644 --- a/src/audio/dai-zephyr.c +++ b/src/audio/dai-zephyr.c @@ -794,22 +794,36 @@ __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 telemetry_unregister_dai(dd); - if (dd->group) + if (dd->group) { dai_group_put(dd->group); + dd->group = NULL; + } dai_dma_release_channel(dd); - 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; + } #if CONFIG_UAOL_INTEL_ADSP uaol_free(dd); @@ -822,6 +836,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); diff --git a/src/audio/host-zephyr.c b/src/audio/host-zephyr.c index de55b8d073ac..238e3d4bd09a 100644 --- a/src/audio/host-zephyr.c +++ b/src/audio/host-zephyr.c @@ -415,7 +415,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) diff --git a/src/audio/module_adapter/module_adapter.c b/src/audio/module_adapter/module_adapter.c index 1257d15978b9..a5112bca75ec 100644 --- a/src/audio/module_adapter/module_adapter.c +++ b/src/audio/module_adapter/module_adapter.c @@ -422,12 +422,21 @@ static void module_adapter_calculate_dp_period(struct comp_dev *dev) unsigned int period = UINT32_MAX; for (int i = 0; i < mod->num_of_sinks; i++) { + unsigned int frame_bytes = sink_get_frame_bytes(mod->sinks[i]); + unsigned int rate = sink_get_rate(mod->sinks[i]); + + /* Skip virtual/event-only detect sinks with no audio format so WoV + * pipelines prepare without dividing by zero (period comes from + * source or dev->period during INIT -> PREPARE). + */ + if (!frame_bytes || !rate) + continue; + /* calculate time required the module to provide OBS data portion - a period * use 64bit integers to avoid overflows */ unsigned int sink_period = 1000000ULL * sink_get_min_free_space(mod->sinks[i]) / - (sink_get_frame_bytes(mod->sinks[i]) * - sink_get_rate(mod->sinks[i])); + (frame_bytes * rate); /* note the minimal period for the module */ if (period > sink_period) period = sink_period; @@ -493,6 +502,12 @@ int module_adapter_prepare(struct comp_dev *dev) * Second example is a module with variable data rate on output (like MPEG encoder) */ if (mod->dev->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_DP) { + /* legacy comp_driver consumers don't set their input buffer params at bind */ + comp_dev_for_each_consumer(dev, sink) { + if (!audio_stream_get_rate(&sink->stream) && mod->stream_params) + buffer_set_params(sink, mod->stream_params, BUFFER_UPDATE_FORCE); + } + /* calculate DP period if a module didn't */ if (!dev->period) module_adapter_calculate_dp_period(dev); @@ -604,7 +619,7 @@ static int module_adapter_copy_ring_buffers(struct comp_dev *dev) /* input - we need to copy data from audio_stream (as source) * to ring_buffer (as sink) */ - err = audio_buffer_sync_secondary_buffer(&buffer->audio_buffer, UINT_MAX); + err = audio_buffer_sync_secondary_buffer(&buffer->audio_buffer, SIZE_MAX); if (err) { comp_err(dev, "LL to DP copy error status: %d", err); diff --git a/src/audio/pipeline/pipeline-params.c b/src/audio/pipeline/pipeline-params.c index 8a2166b19769..1e40a16174a3 100644 --- a/src/audio/pipeline/pipeline-params.c +++ b/src/audio/pipeline/pipeline-params.c @@ -285,8 +285,13 @@ static int pipeline_comp_prepare(struct comp_dev *current, return err; 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); } diff --git a/src/audio/pipeline/pipeline-schedule.c b/src/audio/pipeline/pipeline-schedule.c index 63b9fd979088..f4d60bbe2a42 100644 --- a/src/audio/pipeline/pipeline-schedule.c +++ b/src/audio/pipeline/pipeline-schedule.c @@ -56,9 +56,10 @@ SOF_DEFINE_REG_UUID(dp_task); #endif /* CONFIG_ZEPHYR_DP_SCHEDULER */ -static void pipeline_schedule_cancel(struct pipeline *p) +void pipeline_schedule_cancel(struct pipeline *p) { - schedule_task_cancel(p->pipe_task); + if (p->pipe_task) + schedule_task_cancel(p->pipe_task); /* enable system agent panic, when there are no longer * DMA driven pipelines @@ -655,7 +656,7 @@ void pipeline_schedule_copy(struct pipeline *p, uint64_t start) * when we attempt to start B, we don't need to schedule pipeline C - * it's already running. */ - if (task_is_active(p->pipe_task)) + if (!p->pipe_task || task_is_active(p->pipe_task)) return; if (p->sched_next && task_is_active(p->sched_next->pipe_task)) diff --git a/src/include/sof/audio/audio_buffer.h b/src/include/sof/audio/audio_buffer.h index f16a50ccd43d..3f9bca2be124 100644 --- a/src/include/sof/audio/audio_buffer.h +++ b/src/include/sof/audio/audio_buffer.h @@ -368,9 +368,16 @@ void audio_buffer_reset(struct sof_audio_buffer *buffer) if (buffer->secondary_buffer_sink && buffer->secondary_buffer_sink->ops->reset) buffer->secondary_buffer_sink->ops->reset(buffer->secondary_buffer_sink); +#ifdef CONFIG_DP_TO_DP_BIND + if (buffer->secondary_buffer_source && + buffer->secondary_buffer_source != buffer->secondary_buffer_sink && + buffer->secondary_buffer_source->ops->reset) + buffer->secondary_buffer_source->ops->reset(buffer->secondary_buffer_source); +#else if (buffer->secondary_buffer_source && buffer->secondary_buffer_source->ops->reset) buffer->secondary_buffer_source->ops->reset(buffer->secondary_buffer_source); #endif +#endif } /* Audio-buffer wrappers for the source-sink API */ diff --git a/src/include/sof/audio/pipeline.h b/src/include/sof/audio/pipeline.h index 9409eaec0236..4068845b61e7 100644 --- a/src/include/sof/audio/pipeline.h +++ b/src/include/sof/audio/pipeline.h @@ -421,6 +421,7 @@ int pipeline_comp_dp_task_init(struct comp_dev *comp); * \param[in] start Pipeline start time in microseconds. */ void pipeline_schedule_copy(struct pipeline *p, uint64_t start); +void pipeline_schedule_cancel(struct pipeline *p); /** * \brief Triggers pipeline's scheduling component. diff --git a/src/include/sof/lib/agent.h b/src/include/sof/lib/agent.h index 6aaa740761f2..793181eaf624 100644 --- a/src/include/sof/lib/agent.h +++ b/src/include/sof/lib/agent.h @@ -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 diff --git a/src/include/sof/schedule/zephyr_dp_schedule.h b/src/include/sof/schedule/zephyr_dp_schedule.h index 94685b3cb2de..29e10aca963f 100644 --- a/src/include/sof/schedule/zephyr_dp_schedule.h +++ b/src/include/sof/schedule/zephyr_dp_schedule.h @@ -130,7 +130,7 @@ struct scheduler_dp_task_memory { #endif /* CONFIG_SOF_USERSPACE_APPLICATION */ /** @brief Per-core DP scheduler locks, see scheduler_dp_lock(). */ -extern struct k_sem dp_lock[CONFIG_MP_MAX_NUM_CPUS]; +extern struct k_mutex dp_lock[CONFIG_MP_MAX_NUM_CPUS]; /** * @brief DP scheduler ops, see struct scheduler_ops. diff --git a/src/ipc/ipc-helper.c b/src/ipc/ipc-helper.c index c8e82587edf7..9e0514c6d651 100644 --- a/src/ipc/ipc-helper.c +++ b/src/ipc/ipc-helper.c @@ -316,7 +316,14 @@ __cold int ipc_comp_free(struct ipc *ipc, uint32_t comp_id) if (!cpu_is_me(icd->core)) return ipc_process_on_core(icd->core, false); - /* check state */ + /* check state: if not ready, stop and reset to release resources before freeing */ + if (icd->cd->state != COMP_STATE_READY) { + if (icd->cd->state == COMP_STATE_ACTIVE) + comp_trigger(icd->cd, COMP_TRIGGER_STOP); + comp_reset(icd->cd); + comp_set_state(icd->cd, COMP_TRIGGER_RESET); + } + if (icd->cd->state != COMP_STATE_READY) { tr_err(&ipc_tr, "comp id: 0x%x state is %d cannot be freed", comp_id, icd->cd->state); diff --git a/src/ipc/ipc4/handler-user.c b/src/ipc/ipc4/handler-user.c index cf5d4bb84df2..c013a9432cce 100644 --- a/src/ipc/ipc4/handler-user.c +++ b/src/ipc/ipc4/handler-user.c @@ -115,16 +115,41 @@ static int ipc4_pcm_params(struct ipc_comp_dev *pcm_dev) return err; } +static struct comp_dev *pipeline_get_endpoint_comp(struct ipc_comp_dev *ppl_icd) +{ + if (!ppl_icd || !ppl_icd->pipeline) + return NULL; + + struct pipeline *p = ppl_icd->pipeline; + + if (p->source_comp && p->source_comp->direction == SOF_IPC_STREAM_PLAYBACK) + return p->source_comp; + + if (p->sink_comp) + return p->sink_comp; + + return p->source_comp; +} + +static bool pipeline_is_endpoint(struct pipeline *p) +{ + return (p->source_comp && (dev_comp_type(p->source_comp) == SOF_COMP_HOST || + dev_comp_type(p->source_comp) == SOF_COMP_DAI)) || + (p->sink_comp && (dev_comp_type(p->sink_comp) == SOF_COMP_HOST || + dev_comp_type(p->sink_comp) == SOF_COMP_DAI)); +} + static struct ipc_comp_dev *pipeline_get_host_dev(struct ipc_comp_dev *ppl_icd) { struct ipc_comp_dev *host_dev; struct ipc *ipc = ipc_get(); int host_id; - if (!ppl_icd->pipeline->source_comp || !ppl_icd->pipeline->sink_comp) { - ipc_cmd_err(&ipc_tr, "pipeline %d: source/sink comp freed", ppl_icd->id); + if (!ppl_icd || !ppl_icd->pipeline) + return NULL; + + if (!ppl_icd->pipeline->source_comp || !ppl_icd->pipeline->sink_comp) return NULL; - } /* If the source component's direction is not set but the sink's direction is, * this block will copy the direction from the sink to the source component and @@ -154,8 +179,8 @@ static struct ipc_comp_dev *pipeline_get_host_dev(struct ipc_comp_dev *ppl_icd) host_id = ppl_icd->pipeline->sink_comp->ipc_config.id; host_dev = ipc_get_comp_by_id(ipc, host_id); - if (!host_dev) - ipc_cmd_err(&ipc_tr, "comp host with ID %d not found", host_id); + if (!host_dev || dev_comp_type(host_dev->cd) != SOF_COMP_HOST) + return NULL; return host_dev; } @@ -210,20 +235,57 @@ int ipc4_pipeline_prepare(struct ipc_comp_dev *ppl_icd, uint32_t cmd) /* init params when pipeline is complete or reset */ switch (status) { + case COMP_STATE_INIT: + tr_dbg(&ipc_tr, "pipeline %d: running from init", ppl_icd->id); + ret = ipc4_pipeline_complete(ipc, ppl_icd->id, cmd); + if (ret < 0) + return IPC4_INVALID_REQUEST; + host = pipeline_get_host_dev(ppl_icd); + if (host) { + ret = ipc4_pcm_params(host); + if (ret < 0) + tr_err(&ipc_tr, "pipeline %d: ipc4_pcm_params failed %d", ppl_icd->id, ret); + } else { + struct comp_dev *cd = pipeline_get_endpoint_comp(ppl_icd); + + if (cd && cd->pipeline) { + ret = pipeline_prepare(cd->pipeline, cd); + if (ret < 0) + tr_err(&ipc_tr, "pipeline %d: prepare failed %d", ppl_icd->id, ret); + else + ret = 0; + } + } + break; case COMP_STATE_ACTIVE: case COMP_STATE_PAUSED: + case COMP_STATE_PREPARE: + case COMP_STATE_PRE_ACTIVE: + case COMP_STATE_SUSPEND: /* No action needed */ break; case COMP_STATE_READY: host = pipeline_get_host_dev(ppl_icd); - if (!host) - return IPC4_INVALID_RESOURCE_ID; - - tr_dbg(&ipc_tr, "pipeline %d: set params", ppl_icd->id); - ret = ipc4_pcm_params(host); + if (host) { + tr_info(&ipc_tr, "pipeline %d: set params host comp 0x%x", ppl_icd->id, host->id); + ret = ipc4_pcm_params(host); + if (ret < 0) { + tr_err(&ipc_tr, "pipeline %d: ipc4_pcm_params failed %d", ppl_icd->id, ret); + } + } else { + struct comp_dev *cd = pipeline_get_endpoint_comp(ppl_icd); + + if (cd && cd->pipeline) { + ret = pipeline_prepare(cd->pipeline, cd); + if (ret < 0) + tr_err(&ipc_tr, "pipeline %d: prepare failed %d", ppl_icd->id, ret); + else + ret = 0; + } + } break; default: - ipc_cmd_err(&ipc_tr, + tr_err(&ipc_tr, "pipeline %d: Invalid state for RUNNING: %d", ppl_icd->id, status); return IPC4_INVALID_REQUEST; @@ -238,6 +300,9 @@ int ipc4_pipeline_prepare(struct ipc_comp_dev *ppl_icd, uint32_t cmd) case COMP_STATE_READY: case COMP_STATE_ACTIVE: case COMP_STATE_PAUSED: + case COMP_STATE_PREPARE: + case COMP_STATE_PRE_ACTIVE: + case COMP_STATE_SUSPEND: /* No action needed */ break; default: @@ -282,12 +347,13 @@ int ipc4_pipeline_prepare(struct ipc_comp_dev *ppl_icd, uint32_t cmd) pipeline_set_eos(ppl_icd->pipeline, false); - return ret; + return 0; } int ipc4_pipeline_trigger(struct ipc_comp_dev *ppl_icd, uint32_t cmd, bool *delayed) { struct ipc_comp_dev *host; + struct comp_dev *trigger_cd = NULL; int status; int ret; @@ -298,19 +364,24 @@ int ipc4_pipeline_trigger(struct ipc_comp_dev *ppl_icd, uint32_t cmd, bool *dela if (status == COMP_STATE_INIT) return 0; - host = pipeline_get_host_dev(ppl_icd); - if (!host) + trigger_cd = pipeline_get_endpoint_comp(ppl_icd); + if (!trigger_cd) return IPC4_INVALID_RESOURCE_ID; + host = pipeline_get_host_dev(ppl_icd); + switch (cmd) { case SOF_IPC4_PIPELINE_STATE_RUNNING: /* init params when pipeline is complete or reset */ switch (status) { case COMP_STATE_ACTIVE: + case COMP_STATE_PRE_ACTIVE: /* nothing to do if the pipeline is already running */ return 0; + case COMP_STATE_INIT: case COMP_STATE_READY: case COMP_STATE_PREPARE: + case COMP_STATE_SUSPEND: cmd = COMP_TRIGGER_PRE_START; break; case COMP_STATE_PAUSED: @@ -327,6 +398,9 @@ int ipc4_pipeline_trigger(struct ipc_comp_dev *ppl_icd, uint32_t cmd, bool *dela switch (status) { case COMP_STATE_ACTIVE: case COMP_STATE_PAUSED: + case COMP_STATE_PREPARE: + case COMP_STATE_PRE_ACTIVE: + case COMP_STATE_SUSPEND: cmd = COMP_TRIGGER_STOP; break; default: @@ -338,6 +412,7 @@ int ipc4_pipeline_trigger(struct ipc_comp_dev *ppl_icd, uint32_t cmd, bool *dela case COMP_STATE_INIT: case COMP_STATE_READY: case COMP_STATE_PAUSED: + case COMP_STATE_SUSPEND: return 0; default: cmd = COMP_TRIGGER_PAUSE; @@ -363,8 +438,51 @@ int ipc4_pipeline_trigger(struct ipc_comp_dev *ppl_icd, uint32_t cmd, bool *dela */ dbg_path_hot_confirm(); - /* trigger the component */ - ret = pipeline_trigger(host->cd->pipeline, host->cd, cmd); + bool is_endpoint = pipeline_is_endpoint(trigger_cd->pipeline); + + if (!is_endpoint) { + /* + * Hostless internal pipelines (e.g. background keyword detection or internal + * processing chains feeding arbiters or modules without a host or DAI copier) + * have no host DMA or DAI hardware to delay IPC replies. + * Execute the trigger and reset synchronously inline. + */ + ret = pipeline_trigger_run(trigger_cd->pipeline, trigger_cd, cmd); + if (ret < 0) { + ipc_cmd_err(&ipc_tr, "pipeline %d: trigger cmd %d failed with: %d", + ppl_icd->id, cmd, ret); + return IPC4_PIPELINE_STATE_NOT_SET; + } + + switch (cmd) { + case COMP_TRIGGER_PRE_START: + case COMP_TRIGGER_START: + case COMP_TRIGGER_PRE_RELEASE: + case COMP_TRIGGER_RELEASE: + trigger_cd->pipeline->status = COMP_STATE_ACTIVE; + pipeline_schedule_copy(trigger_cd->pipeline, 0); + break; + case COMP_TRIGGER_PAUSE: + pipeline_schedule_cancel(trigger_cd->pipeline); + trigger_cd->pipeline->status = COMP_STATE_PAUSED; + break; + case COMP_TRIGGER_STOP: + pipeline_schedule_cancel(trigger_cd->pipeline); + trigger_cd->pipeline->status = COMP_STATE_READY; + ret = pipeline_reset(trigger_cd->pipeline, trigger_cd); + if (ret < 0 && ret != PPL_STATUS_PATH_STOP) + return IPC4_INVALID_REQUEST; + break; + default: + break; + } + + *delayed = false; + return 0; + } + + /* trigger the endpoint component (host or DAI) */ + ret = pipeline_trigger(trigger_cd->pipeline, trigger_cd, cmd); if (ret < 0) { ipc_cmd_err(&ipc_tr, "pipeline %d: trigger cmd %d failed with: %d", ppl_icd->id, cmd, ret); @@ -381,9 +499,15 @@ int ipc4_pipeline_trigger(struct ipc_comp_dev *ppl_icd, uint32_t cmd, bool *dela * Otherwise, the pipeline will be reset after the STOP trigger * has finished executing in the pipeline task. */ - ret = pipeline_reset(host->cd->pipeline, host->cd); - if (ret < 0) + struct comp_dev *reset_cd = host ? host->cd : trigger_cd; + + ret = pipeline_reset(reset_cd->pipeline, reset_cd); + if (ret < 0 && ret != PPL_STATUS_PATH_STOP) ret = IPC4_INVALID_REQUEST; + else + ret = 0; + } else { + ret = 0; } return ret; diff --git a/src/ipc/ipc4/helper.c b/src/ipc/ipc4/helper.c index 6bf259695403..b5dbf7beb06e 100644 --- a/src/ipc/ipc4/helper.c +++ b/src/ipc/ipc4/helper.c @@ -772,18 +772,22 @@ __cold int ipc4_comp_connect(struct ipc *ipc, const struct ipc4_module_bind_unbi struct mod_alloc_ctx *alloc; #if CONFIG_ZEPHYR_DP_SCHEDULER - if (source->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_DP && - sink->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_DP) { + bool src_is_dp = source->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_DP; + bool sink_is_dp = sink->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_DP; +#ifdef CONFIG_DP_TO_DP_BIND + bool dp_to_dp = src_is_dp && sink_is_dp; +#else + if (src_is_dp && sink_is_dp) { tr_err(&ipc_tr, "DP to DP binding is not supported: can't bind %x to %x", src_id, sink_id); return IPC4_INVALID_REQUEST; } - +#endif struct comp_dev *dp; - if (sink->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_DP) + if (sink_is_dp) dp = sink; - else if (source->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_DP) + else if (src_is_dp) dp = source; else dp = NULL; @@ -874,8 +878,8 @@ __cold int ipc4_comp_connect(struct ipc *ipc, const struct ipc4_module_bind_unbi * * size = 2*max(obs of source module, ibs of destination module) * (obs and ibs is single buffer size) - * in case of DP -> LL - * size = 2*ibs of destination (LL) module. DP queue will handle obs of DP module + * in case of DP -> LL or DP -> DP + * size = 2*ibs of destination module. DP queue will handle obs of DP module */ if (source->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_LL) buf_size = MAX(ibs, obs) * 2; @@ -910,12 +914,15 @@ __cold int ipc4_comp_connect(struct ipc *ipc, const struct ipc4_module_bind_unbi #if CONFIG_ZEPHYR_DP_SCHEDULER struct ring_buffer *ring_buffer = NULL; - if (sink->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_DP || - source->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_DP) { + if (src_is_dp || sink_is_dp) { struct processing_module *srcmod = comp_mod(source); - struct module_data *src_module_data = &srcmod->priv; + struct module_data *src_module_data = srcmod ? &srcmod->priv : NULL; struct processing_module *dstmod = comp_mod(sink); - struct module_data *dst_module_data = &dstmod->priv; + struct module_data *dst_module_data = dstmod ? &dstmod->priv : NULL; + uint32_t dst_in_buff_size = dst_module_data ? dst_module_data->mpd.in_buff_size : 0; + uint32_t src_out_buff_size = src_module_data ? src_module_data->mpd.out_buff_size : 0; + bool is_shared = audio_buffer_is_shared(&buffer->audio_buffer); + uint32_t buf_id = buf_get_id(buffer); /* * Handle cases where the size of the ring buffer depends on the @@ -925,18 +932,41 @@ __cold int ipc4_comp_connect(struct ipc *ipc, const struct ipc4_module_bind_unbi * is only for the ring buffer. The size of intermediate buffer created above is * unchanged. */ - ring_buffer = ring_buffer_create(dp, MAX(ibs, dst_module_data->mpd.in_buff_size), - MAX(obs, src_module_data->mpd.out_buff_size), - audio_buffer_is_shared(&buffer->audio_buffer), - buf_get_id(buffer)); + ring_buffer = ring_buffer_create(dp, MAX(ibs, dst_in_buff_size), + MAX(obs, src_out_buff_size), + is_shared, buf_id); if (!ring_buffer) { buffer_free(buffer); return IPC4_OUT_OF_MEMORY; } - /* data destination module needs to use ring_buffer */ - audio_buffer_attach_secondary_buffer(&buffer->audio_buffer, dp == source, - &ring_buffer->audio_buffer); +#ifdef CONFIG_DP_TO_DP_BIND + /* + * Keep the DP module vregion alive for the lifetime of this ring_buffer + * (dropped in ring_buffer_free()) since source and sink DP modules can be + * torn down independently. + */ + if (ring_buffer->audio_buffer.alloc) + vregion_get(ring_buffer->audio_buffer.alloc->vreg); + + if (dp_to_dp) { + /* + * DP-to-DP binding: both source and sink are DP modules. + * A single shared ring_buffer is attached on both sides + * of the comp_buffer, so source DP writes directly to it + * and sink DP reads directly from it without copying. + */ + audio_buffer_attach_secondary_buffer(&buffer->audio_buffer, true, + &ring_buffer->audio_buffer); + audio_buffer_attach_secondary_buffer(&buffer->audio_buffer, false, + &ring_buffer->audio_buffer); + } else +#endif + { + /* data destination module needs to use ring_buffer */ + audio_buffer_attach_secondary_buffer(&buffer->audio_buffer, dp == source, + &ring_buffer->audio_buffer); + } } #endif /* CONFIG_ZEPHYR_DP_SCHEDULER */ diff --git a/src/kernel/audio/intel_uaol-kernel.c b/src/kernel/audio/intel_uaol-kernel.c index 788bf49893ec..99aa2942d93d 100644 --- a/src/kernel/audio/intel_uaol-kernel.c +++ b/src/kernel/audio/intel_uaol-kernel.c @@ -37,6 +37,7 @@ __cold void tlv_value_set_uaol_caps(struct sof_tlv *tuple, uint32_t type) struct uaol_capabilities dev_cap; struct ipc4_uaol_capabilities *caps = (struct ipc4_uaol_capabilities *)tuple->value; size_t caps_size = offsetof(struct ipc4_uaol_capabilities, link_caps[dev_count]); + size_t link_count = 0; size_t i; int ret; @@ -44,19 +45,27 @@ __cold void tlv_value_set_uaol_caps(struct sof_tlv *tuple, uint32_t type) memset(caps, 0, caps_size); - caps->link_count = dev_count; + /* Only advertise links that answered. uaol_get_capabilities() fails when + * the host has not offloaded link control to the DSP (UAOLCTL.OFLEN), in + * which case the link's segment registers are not readable here. + */ for (i = 0; i < dev_count; i++) { ret = uaol_get_capabilities(uaol_devs[i], &dev_cap); if (ret) continue; - caps->link_caps[i].input_streams_supported = dev_cap.input_streams; - caps->link_caps[i].output_streams_supported = dev_cap.output_streams; - caps->link_caps[i].bidirectional_streams_supported = dev_cap.bidirectional_streams; - caps->link_caps[i].max_tx_fifo_size = dev_cap.max_tx_fifo_size; - caps->link_caps[i].max_rx_fifo_size = dev_cap.max_rx_fifo_size; + caps->link_caps[link_count].input_streams_supported = dev_cap.input_streams; + caps->link_caps[link_count].output_streams_supported = dev_cap.output_streams; + caps->link_caps[link_count].bidirectional_streams_supported = + dev_cap.bidirectional_streams; + caps->link_caps[link_count].max_tx_fifo_size = dev_cap.max_tx_fifo_size; + caps->link_caps[link_count].max_rx_fifo_size = dev_cap.max_rx_fifo_size; + link_count++; } + caps->link_count = link_count; + caps_size = offsetof(struct ipc4_uaol_capabilities, link_caps[link_count]); + tlv_value_set(tuple, type, caps_size, caps); } #endif /* !CONFIG_SOF_OS_LINUX_COMPAT_PRIORITY */ diff --git a/src/kernel/lib/dai-kernel.c b/src/kernel/lib/dai-kernel.c index e12cabe8141e..cc1711aee0fe 100644 --- a/src/kernel/lib/dai-kernel.c +++ b/src/kernel/lib/dai-kernel.c @@ -263,6 +263,9 @@ __cold void dai_put(struct dai *dai) assert_can_be_cold(); + if (!dai) + return; + #ifdef CONFIG_SOF_USERSPACE_LL heap = zephyr_ll_user_heap(); #endif @@ -335,6 +338,9 @@ __cold void dai_put(struct dai *dai) assert_can_be_cold(); + if (!dai) + return; + key = k_spin_lock(&dai->lock); if (--dai->sref == 0) { ret = dai_remove(dai); diff --git a/src/kernel/lib/dma-kernel.c b/src/kernel/lib/dma-kernel.c index 32e76a433395..03270c20e698 100644 --- a/src/kernel/lib/dma-kernel.c +++ b/src/kernel/lib/dma-kernel.c @@ -178,6 +178,9 @@ __cold void z_impl_sof_dma_put(struct sof_dma *dma) assert_can_be_cold(); + if (!dma) + return; + key = k_spin_lock(dma_lock(dma)); if (*dma_sref(dma) <= 0) { tr_err(&dma_tr, "dma_put(), dma = %p not in use", dma); diff --git a/src/kernel/schedule/zephyr_dp_schedule-kernel.c b/src/kernel/schedule/zephyr_dp_schedule-kernel.c index 81e5dad1a3a7..2f495c1c0be2 100644 --- a/src/kernel/schedule/zephyr_dp_schedule-kernel.c +++ b/src/kernel/schedule/zephyr_dp_schedule-kernel.c @@ -43,14 +43,15 @@ DECLARE_TR_CTX(dp_tr, SOF_UUID(dp_sched_uuid), LOG_LEVEL_INFO); * src/schedule/zephyr_dp_schedule.c */ -#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. */ -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 }; void scheduler_dp_grant(k_tid_t thread_id, uint16_t core) { diff --git a/src/lib/notifier.c b/src/lib/notifier.c index cbc9ff5cd7f8..c6e5a08b45cb 100644 --- a/src/lib/notifier.c +++ b/src/lib/notifier.c @@ -172,7 +172,10 @@ void notifier_event(const void *caller, enum notify_id type, uint32_t core_mask, dcache_writeback_region((__sparse_force void __sparse_cache *) notify_data->data, data_size); - idc_send_msg(¬ify_msg, IDC_NON_BLOCKING); + /* Wait for completion: back-to-back events to the same core would + * otherwise reuse a queued IDC work item and overwrite notify_data. + */ + idc_send_msg(¬ify_msg, IDC_BLOCKING); } } } diff --git a/src/schedule/zephyr_dp_schedule.c b/src/schedule/zephyr_dp_schedule.c index 38d228d4b609..ae0580b9b695 100644 --- a/src/schedule/zephyr_dp_schedule.c +++ b/src/schedule/zephyr_dp_schedule.c @@ -41,13 +41,13 @@ extern struct tr_ctx dp_tr; */ 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]); } #if CONFIG_SOF_USERSPACE_APPLICATION && CONFIG_SOF_USERSPACE_LL diff --git a/tools/sof_ri_info/sof_ri_info.py b/tools/sof_ri_info/sof_ri_info.py index 3b09ffb1ec40..25141a666ace 100755 --- a/tools/sof_ri_info/sof_ri_info.py +++ b/tools/sof_ri_info/sof_ri_info.py @@ -738,6 +738,56 @@ 0x63, 0x04, 0xaf, 0x24, 0x45, 0x87, 0xf4, 0x96, 0x55, 0xd1, 0x7d, 0xc6, 0x0d, 0x79, 0x12, 0xa9]) +PTL_INTEL_DEBUG_KEY = bytes([ + 0x65, 0x24, 0xe8, 0x0a, 0x41, 0xc8, 0xed, 0xa2, + 0x92, 0x59, 0x20, 0x13, 0x3f, 0xcd, 0x11, 0x8b, + 0x7e, 0xdb, 0x8d, 0xf5, 0x69, 0xd9, 0x36, 0x2c, + 0x6c, 0x34, 0xba, 0xec, 0xce, 0x3e, 0xcb, 0xaa, + 0x52, 0x58, 0xef, 0x6b, 0x92, 0xe7, 0x8f, 0x8b, + 0x36, 0x8b, 0xa0, 0xc4, 0x61, 0x62, 0x13, 0x8c, + 0xcc, 0x2a, 0x75, 0xab, 0x59, 0xab, 0xf0, 0xf1, + 0x28, 0xd7, 0xdc, 0x42, 0xa8, 0xb1, 0xa0, 0x1f, + 0x95, 0x02, 0xaa, 0x30, 0x41, 0xe3, 0x9d, 0xf5, + 0x0c, 0x74, 0x3b, 0x72, 0x22, 0x98, 0x45, 0x50, + 0xec, 0x09, 0x04, 0x45, 0x22, 0x62, 0xc1, 0xce, + 0xb6, 0x4d, 0x1b, 0xac, 0xe2, 0xa2, 0xf1, 0x62, + 0x25, 0x60, 0xc0, 0x12, 0x08, 0x7a, 0x4e, 0x11, + 0x18, 0x81, 0xc8, 0xf6, 0xfa, 0xb0, 0x76, 0x7e, + 0xeb, 0x1c, 0xc3, 0x00, 0xf3, 0x1d, 0x5e, 0xc3, + 0x9c, 0x89, 0x74, 0xad, 0x17, 0xa8, 0x0a, 0x7e, + 0x33, 0xa4, 0x46, 0x1d, 0xcd, 0xac, 0xe2, 0xb2, + 0x34, 0xc2, 0x53, 0x03, 0x72, 0x18, 0x49, 0x22, + 0x9f, 0x51, 0xac, 0x65, 0x79, 0xf7, 0x02, 0x0f, + 0xea, 0xfd, 0x33, 0x5f, 0x3c, 0x7a, 0x0e, 0xd0, + 0x71, 0x85, 0x76, 0xcd, 0x7e, 0x3e, 0x85, 0xa4, + 0xc9, 0x88, 0x7d, 0xb8, 0x68, 0x00, 0xe1, 0x49, + 0xc4, 0x4f, 0xe7, 0xf4, 0x19, 0x1a, 0x88, 0xa2, + 0x89, 0xaa, 0xcc, 0xd6, 0xdd, 0x99, 0xfb, 0x54, + 0x89, 0x14, 0xe7, 0xc5, 0x4b, 0x43, 0x35, 0x50, + 0x77, 0xc8, 0xd6, 0x45, 0xd6, 0x09, 0xae, 0x31, + 0xa7, 0x30, 0x0b, 0xfa, 0xa5, 0x5d, 0xc0, 0x88, + 0x80, 0x50, 0xa5, 0x7f, 0x7c, 0xd7, 0xf6, 0x19, + 0x11, 0x49, 0xb1, 0x31, 0x6b, 0x23, 0x03, 0x82, + 0x6b, 0x42, 0x3a, 0x91, 0xd7, 0x86, 0x13, 0xa1, + 0xf0, 0x09, 0x95, 0xa4, 0xd1, 0xac, 0xd6, 0x3e, + 0xb3, 0x48, 0xe0, 0xc8, 0xdb, 0x4e, 0x91, 0xcb, + 0x1f, 0xd0, 0x5d, 0xec, 0x09, 0xb8, 0x5e, 0x8b, + 0xeb, 0x74, 0xf0, 0x2e, 0xa0, 0x98, 0x2c, 0x06, + 0x35, 0x85, 0xec, 0x6f, 0x8f, 0xfa, 0xb8, 0x0c, + 0x2a, 0x47, 0xc5, 0x4d, 0x15, 0xea, 0x7c, 0x04, + 0x96, 0x21, 0x41, 0x38, 0x1e, 0x3f, 0x7c, 0x96, + 0x61, 0x12, 0x5d, 0x50, 0x90, 0x18, 0x5e, 0xe6, + 0xd2, 0x30, 0x53, 0xdb, 0xc3, 0x0f, 0xef, 0x28, + 0xf6, 0x6f, 0xaf, 0x03, 0xc0, 0xca, 0x6b, 0x3b, + 0x4f, 0xa8, 0x82, 0xae, 0x4e, 0x0f, 0x9b, 0x08, + 0x8d, 0x8f, 0x43, 0xed, 0x48, 0x8e, 0xe6, 0xa1, + 0x7e, 0xb3, 0x2e, 0x37, 0x2e, 0x48, 0x95, 0xd4, + 0x1d, 0xa6, 0xfe, 0x22, 0x9f, 0x9a, 0x02, 0xa9, + 0xd9, 0xfc, 0x23, 0x71, 0x02, 0x48, 0x24, 0x6b, + 0xe7, 0xc1, 0x6c, 0x20, 0x9f, 0xdf, 0x8d, 0xc1, + 0x65, 0xe4, 0x34, 0xc3, 0x02, 0x33, 0x29, 0xe9, + 0x30, 0x32, 0xd1, 0x2f, 0xc4, 0xfd, 0x61, 0xca]) + KNOWN_KEYS = {APL_INTEL_PROD_KEY : 'APL Intel prod key', CNL_INTEL_PROD_KEY : 'CNL Intel prod key', ICL_INTEL_PROD_KEY : 'ICL Intel prod key', @@ -750,6 +800,7 @@ LNL_INTEL_PROD_KEY : 'LNL Intel prod key', ARL_S_INTEL_PROD_KEY : 'ARL-S Intel prod key', PTL_INTEL_PROD_KEY : 'PTL Intel prod key', + PTL_INTEL_DEBUG_KEY : 'PTL Intel debug key', NVL_INTEL_PROD_KEY : 'NVL Intel prod key', NVL_S_INTEL_PROD_KEY : 'NVL-S Intel prod key', COMMUNITY_KEY : 'Community key', diff --git a/zephyr/Kconfig b/zephyr/Kconfig index 148374c533a8..76a01ac44458 100644 --- a/zephyr/Kconfig +++ b/zephyr/Kconfig @@ -321,6 +321,15 @@ config ZEPHYR_DP_SCHEDULER_MIN_STACK_SIZE ext_init payload. If the stack size requested in the IPC is smaller than this, then the value defined here takes over. +config DP_TO_DP_BIND + bool "Support DP to DP component binding" + default y + depends on ZEPHYR_DP_SCHEDULER + help + Enable binding between two Data Processing (DP) scheduled components. + This allows connecting DP modules together (e.g. DP source to DP sink) + via intermediate buffering. + config CROSS_CORE_STREAM bool "Enable cross-core connected pipelines" default y if IPC_MAJOR_4 diff --git a/zephyr/edf_schedule.c b/zephyr/edf_schedule.c index 3578b3dd6c7d..005c70196832 100644 --- a/zephyr/edf_schedule.c +++ b/zephyr/edf_schedule.c @@ -87,6 +87,7 @@ static int schedule_edf_task_running(void *data, struct task *task) static int schedule_edf_task_free(void *data, struct task *task) { + k_work_cancel_delayable(&task->z_delayed_work); task->state = SOF_TASK_STATE_FREE; task->ops.run = NULL; task->data = NULL;