From 04ff3cb6b417c66e77a7de3d522cc345118d4583 Mon Sep 17 00:00:00 2001 From: Marcin Szkudlinski Date: Thu, 12 Sep 2024 12:50:55 +0200 Subject: [PATCH] manual change xsink --- src/audio/mixer/mixer.c | 18 +++++++----- src/audio/module_adapter/module_adapter.c | 29 +++++++++---------- .../module_adapter/module_adapter_ipc3.c | 20 ++++++------- .../module_adapter/module_adapter_ipc4.c | 9 +++--- src/audio/mux/mux.c | 20 ++++++++----- src/audio/mux/mux_ipc4.c | 8 ++--- src/audio/smart_amp/smart_amp.c | 8 ++--- src/ipc/ipc-helper.c | 2 +- src/ipc/ipc3/handler.c | 10 +++---- src/ipc/ipc4/helper.c | 13 +++++++-- src/probe/probe.c | 8 +++-- src/samples/audio/smart_amp_test_ipc3.c | 9 +++--- 12 files changed, 85 insertions(+), 69 deletions(-) diff --git a/src/audio/mixer/mixer.c b/src/audio/mixer/mixer.c index d750635277d8..e13462d9c54c 100644 --- a/src/audio/mixer/mixer.c +++ b/src/audio/mixer/mixer.c @@ -163,15 +163,15 @@ static int mixer_reset(struct processing_module *mod) { struct mixer_data *md = module_get_private_data(mod); struct comp_dev *dev = mod->dev; - struct list_item *blist; int dir = dev->pipeline->source_comp->direction; comp_dbg(dev, "mixer_reset()"); if (dir == SOF_IPC_STREAM_PLAYBACK) { - list_for_item(blist, &dev->bsource_list) { + struct comp_buffer *source = comp_dev_get_first_data_producer(dev); + + while(source) { /* FIXME: this is racy and implicitly protected by serialised IPCs */ - struct comp_buffer *source = container_of(blist, struct comp_buffer, Xsink_list); bool stop = false; if (source->Xsource && source->Xsource->state > COMP_STATE_READY) @@ -181,6 +181,8 @@ static int mixer_reset(struct processing_module *mod) if (stop) /* should not reset the downstream components */ return PPL_STATUS_PATH_STOP; + + source = comp_dev_get_next_data_producer(dev, source); } } @@ -213,15 +215,15 @@ static int mixer_prepare(struct processing_module *mod, struct mixer_data *md = module_get_private_data(mod); struct comp_dev *dev = mod->dev; struct comp_buffer *sink; - struct list_item *blist; sink = comp_dev_get_first_data_consumer(dev); md->mix_func = mixer_get_processing_function(dev, sink); mixer_set_frame_alignment(&sink->stream); /* check each mixer source state */ - list_for_item(blist, &dev->bsource_list) { - struct comp_buffer *source; + struct comp_buffer *source = comp_dev_get_first_data_producer(dev); + + while(source) { bool stop; /* @@ -232,7 +234,6 @@ static int mixer_prepare(struct processing_module *mod, * preparing the mixer, so they shouldn't touch it until we're * done. */ - source = container_of(blist, struct comp_buffer, Xsink_list); mixer_set_frame_alignment(&source->stream); stop = source->Xsource && (source->Xsource->state == COMP_STATE_PAUSED || source->Xsource->state == COMP_STATE_ACTIVE); @@ -240,6 +241,9 @@ static int mixer_prepare(struct processing_module *mod, /* only prepare downstream if we have no active sources */ if (stop) return PPL_STATUS_PATH_STOP; + + + source = comp_dev_get_next_data_producer(dev, source); } /* prepare downstream */ diff --git a/src/audio/module_adapter/module_adapter.c b/src/audio/module_adapter/module_adapter.c index 9e8c24cb620c..b2ab604cd6ee 100644 --- a/src/audio/module_adapter/module_adapter.c +++ b/src/audio/module_adapter/module_adapter.c @@ -390,7 +390,7 @@ int module_adapter_prepare(struct comp_dev *dev) } } else { list_for_item(blist, &mod->sink_buffer_list) { - struct comp_buffer *buffer = container_of(blist, struct comp_buffer, Xsink_list); + struct comp_buffer *buffer = container_of(blist, struct comp_buffer, Xsink_list); //msz ??? ret = buffer_set_size(buffer, buff_size, 0); if (ret < 0) { @@ -410,7 +410,7 @@ int module_adapter_prepare(struct comp_dev *dev) free: list_for_item_safe(blist, _blist, &mod->sink_buffer_list) { - struct comp_buffer *buffer = container_of(blist, struct comp_buffer, Xsink_list); + struct comp_buffer *buffer = container_of(blist, struct comp_buffer, Xsink_list); //msz ?? uint32_t flags; irq_local_disable(flags); @@ -609,7 +609,7 @@ static void module_adapter_process_output(struct comp_dev *dev) if (mod->output_buffers[i].size > 0) { struct comp_buffer *buffer; - buffer = container_of(blist, struct comp_buffer, Xsink_list); + buffer = container_of(blist, struct comp_buffer, Xsink_list); //msz ca_copy_from_module_to_sink(&buffer->stream, mod->output_buffers[i].data, mod->output_buffers[i].size); @@ -629,7 +629,7 @@ static void module_adapter_process_output(struct comp_dev *dev) struct comp_buffer *source; sink = container_of(blist, struct comp_buffer, Xsource_list); //msz ??? - source = container_of(_blist, struct comp_buffer, Xsink_list); + source = container_of(_blist, struct comp_buffer, Xsink_list); //msz module_copy_samples(dev, source, sink, mod->output_buffers[i].size); @@ -808,13 +808,11 @@ static int module_adapter_audio_stream_type_copy(struct comp_dev *dev) } i = 0; - struct list_item *blist; - - list_for_item(blist, &dev->bsource_list) { - struct comp_buffer *source; - - source = container_of(blist, struct comp_buffer, Xsink_list); + struct comp_buffer *source = comp_dev_get_first_data_producer(dev); + while(source) { sources[i++] = source; + + source = comp_dev_get_next_data_producer(dev, source); } num_input_buffers = i; if (num_input_buffers > mod->max_sources) { @@ -911,21 +909,22 @@ static int module_adapter_copy_ring_buffers(struct comp_dev *dev) * This is an adapter, to be removed when pipeline2.0 is ready */ struct comp_buffer *buffer; - struct list_item *blist; struct processing_module *mod = comp_mod(dev); int err; - list_for_item(blist, &dev->bsource_list) { + buffer = comp_dev_get_first_data_producer(dev); + while(buffer) { /* input - we need to copy data from audio_stream (as source) * to ring_buffer (as sink) */ - buffer = container_of(blist, struct comp_buffer, Xsink_list); err = audio_buffer_sync_secondary_buffer(&buffer->audio_buffer, UINT_MAX); if (err) { comp_err(dev, "LL to DP copy error status: %d", err); return err; } + + buffer = comp_dev_get_next_data_producer(dev, buffer); } if (mod->dp_startup_delay) @@ -1182,7 +1181,7 @@ int module_adapter_reset(struct comp_dev *dev) mod->total_data_produced = 0; list_for_item(blist, &mod->sink_buffer_list) { - struct comp_buffer *buffer = container_of(blist, struct comp_buffer, Xsink_list); + struct comp_buffer *buffer = container_of(blist, struct comp_buffer, Xsink_list); //msz??? buffer_zero(buffer); } @@ -1208,7 +1207,7 @@ void module_adapter_free(struct comp_dev *dev) comp_err(dev, "module_adapter_free(): failed with error: %d", ret); list_for_item_safe(blist, _blist, &mod->sink_buffer_list) { - struct comp_buffer *buffer = container_of(blist, struct comp_buffer, Xsink_list); + struct comp_buffer *buffer = container_of(blist, struct comp_buffer, Xsink_list); //msz uint32_t flags; irq_local_disable(flags); diff --git a/src/audio/module_adapter/module_adapter_ipc3.c b/src/audio/module_adapter/module_adapter_ipc3.c index 5a71740474c4..5b3b8f168ae5 100644 --- a/src/audio/module_adapter/module_adapter_ipc3.c +++ b/src/audio/module_adapter/module_adapter_ipc3.c @@ -131,11 +131,12 @@ void module_adapter_set_params(struct processing_module *mod, struct sof_ipc_str static int module_source_status_count(struct comp_dev *dev, uint32_t status) { - struct list_item *blist; int count = 0; /* count source with state == status */ - list_for_item(blist, &dev->bsource_list) { + struct comp_buffer *source = comp_dev_get_first_data_producer(dev); + + while(source) { /* * FIXME: this is racy, state can be changed by another core. * This is implicitly protected by serialised IPCs. Even when @@ -143,10 +144,10 @@ static int module_source_status_count(struct comp_dev *dev, uint32_t status) * not be sent until the thread has processed and replied to the * current one. */ - struct comp_buffer *source = container_of(blist, struct comp_buffer, Xsink_list); - if (source->Xsource && source->Xsource->state == status) count++; + + source = comp_dev_get_next_data_producer(dev, source); } return count; @@ -335,15 +336,14 @@ int module_adapter_sink_src_prepare(struct comp_dev *dev) } mod->num_of_sinks = i; - i = 0; - struct list_item *blist; - - list_for_item(blist, &dev->bsource_list) { - struct comp_buffer *source_buffer = - container_of(blist, struct comp_buffer, Xsink_list); + struct comp_buffer *source_buffer = comp_dev_get_first_data_producer(dev); + i = 0; + while(source_buffer) { mod->sources[i] = audio_buffer_get_source(&source_buffer->audio_buffer); i++; + + source_buffer = comp_dev_get_next_data_producer(dev, source_buffer); } mod->num_of_sources = i; diff --git a/src/audio/module_adapter/module_adapter_ipc4.c b/src/audio/module_adapter/module_adapter_ipc4.c index a528ca9ae3ff..c5d5f84d7a21 100644 --- a/src/audio/module_adapter/module_adapter_ipc4.c +++ b/src/audio/module_adapter/module_adapter_ipc4.c @@ -187,7 +187,6 @@ EXPORT_SYMBOL(module_adapter_get_attribute); static bool module_adapter_multi_sink_source_prepare(struct comp_dev *dev) { struct processing_module *mod = comp_mod(dev); - struct list_item *blist; int i; /* acquire all sink and source buffers, get handlers to sink/source API */ @@ -202,13 +201,15 @@ static bool module_adapter_multi_sink_source_prepare(struct comp_dev *dev) } mod->num_of_sinks = i; + i = 0; - list_for_item(blist, &dev->bsource_list) { - struct comp_buffer *source_buffer = - container_of(blist, struct comp_buffer, Xsink_list); + struct comp_buffer *source_buffer = comp_dev_get_first_data_producer(dev); + while(source_buffer) { mod->sources[i] = audio_buffer_get_source(&source_buffer->audio_buffer); i++; + + source_buffer = comp_dev_get_next_data_producer(dev, source_buffer); } mod->num_of_sources = i; diff --git a/src/audio/mux/mux.c b/src/audio/mux/mux.c index 6f6661e61740..8afec1bb1a51 100644 --- a/src/audio/mux/mux.c +++ b/src/audio/mux/mux.c @@ -292,7 +292,6 @@ static int mux_process(struct processing_module *mod, struct comp_data *cd = module_get_private_data(mod); struct comp_dev *dev = mod->dev; struct comp_buffer *source; - struct list_item *clist; const struct audio_stream *sources_stream[MUX_MAX_STREAMS] = { NULL }; int frames = 0; int sink_bytes; @@ -303,8 +302,8 @@ static int mux_process(struct processing_module *mod, /* align source streams with their respective configurations */ j = 0; - list_for_item(clist, &dev->bsource_list) { - source = container_of(clist, struct comp_buffer, Xsink_list); + source = comp_dev_get_first_data_producer(dev); + while(source) { if (source->Xsource->state == dev->state) { if (frames) frames = MIN(frames, input_buffers[j].size); @@ -320,6 +319,8 @@ static int mux_process(struct processing_module *mod, sources_stream[i] = &source->stream; } j++; + + source = comp_dev_get_next_data_producer(dev, source); } /* check if there are any sources active */ @@ -335,11 +336,13 @@ static int mux_process(struct processing_module *mod, /* Update consumed and produced */ j = 0; - list_for_item(clist, &dev->bsource_list) { - source = container_of(clist, struct comp_buffer, Xsink_list); + source = comp_dev_get_first_data_producer(dev); + while(source) { if (source->Xsource->state == dev->state) mod->input_buffers[j].consumed = source_bytes; j++; + + source = comp_dev_get_next_data_producer(dev, source); } mod->output_buffers[0].size = sink_bytes; return 0; @@ -347,7 +350,6 @@ static int mux_process(struct processing_module *mod, static int mux_reset(struct processing_module *mod) { - struct list_item *blist; struct comp_data *cd = module_get_private_data(mod); struct comp_dev *dev = mod->dev; int dir = dev->pipeline->source_comp->direction; @@ -355,14 +357,16 @@ static int mux_reset(struct processing_module *mod) comp_dbg(dev, "mux_reset()"); if (dir == SOF_IPC_STREAM_PLAYBACK) { - list_for_item(blist, &dev->bsource_list) { - struct comp_buffer *source = container_of(blist, struct comp_buffer, Xsink_list); + struct comp_buffer *source = comp_dev_get_first_data_producer(dev); + while(source) { int state = source->Xsource->state; /* only mux the sources with the same state with mux */ if (state > COMP_STATE_READY) /* should not reset the downstream components */ return PPL_STATUS_PATH_STOP; + + source = comp_dev_get_next_data_producer(dev, source); } } diff --git a/src/audio/mux/mux_ipc4.c b/src/audio/mux/mux_ipc4.c index 0be3a8fe9474..a844bcb5c89e 100644 --- a/src/audio/mux/mux_ipc4.c +++ b/src/audio/mux/mux_ipc4.c @@ -74,7 +74,6 @@ static void set_mux_params(struct processing_module *mod) struct comp_data *cd = module_get_private_data(mod); struct comp_dev *dev = mod->dev; struct comp_buffer *sink, *source; - struct list_item *source_list; int j; params->direction = dev->direction; @@ -106,9 +105,8 @@ static void set_mux_params(struct processing_module *mod) if (!list_is_empty(&dev->bsource_list)) { struct ipc4_audio_format *audio_fmt; - list_for_item(source_list, &dev->bsource_list) - { - source = container_of(source_list, struct comp_buffer, Xsink_list); + source = comp_dev_get_first_data_producer(dev); + while(source) { j = buf_get_id(source); cd->config.streams[j].pipeline_id = buffer_pipeline_id(source); if (j == BASE_CFG_QUEUED_ID) @@ -117,6 +115,8 @@ static void set_mux_params(struct processing_module *mod) audio_fmt = &cd->md.reference_format; ipc4_update_buffer_format(source, audio_fmt); + + source = comp_dev_get_next_data_producer(dev, source); } } diff --git a/src/audio/smart_amp/smart_amp.c b/src/audio/smart_amp/smart_amp.c index e48ba00823b0..bb0474b3a17d 100644 --- a/src/audio/smart_amp/smart_amp.c +++ b/src/audio/smart_amp/smart_amp.c @@ -731,7 +731,6 @@ static int smart_amp_resolve_mod_fmt(struct comp_dev *dev, uint32_t least_req_de static int smart_amp_prepare(struct comp_dev *dev) { struct smart_amp_data *sad = comp_get_drvdata(dev); - struct list_item *blist; uint16_t ff_src_fmt, fb_src_fmt, resolved_mod_fmt; uint32_t least_req_depth; uint32_t rate; @@ -744,13 +743,14 @@ static int smart_amp_prepare(struct comp_dev *dev) return ret; /* searching for stream and feedback source buffers */ - list_for_item(blist, &dev->bsource_list) { - struct comp_buffer *source_buffer = container_of(blist, struct comp_buffer, Xsink_list); - + struct comp_buffer *source_buffer = comp_dev_get_first_data_producer(dev); + while(source_buffer) { if (source_buffer->Xsource->ipc_config.type == SOF_COMP_DEMUX) sad->feedback_buf = source_buffer; else sad->source_buf = source_buffer; + + source_buffer = comp_dev_get_next_data_producer(dev, source_buffer); } /* sink buffer */ diff --git a/src/ipc/ipc-helper.c b/src/ipc/ipc-helper.c index 8fa54eeaf562..cdab7bb3099f 100644 --- a/src/ipc/ipc-helper.c +++ b/src/ipc/ipc-helper.c @@ -301,7 +301,7 @@ int ipc_comp_free(struct ipc *ipc, uint32_t comp_id) irq_local_disable(flags); list_for_item_safe(clist, tmp, &icd->cd->bsource_list) { - struct comp_buffer *buffer = container_of(clist, struct comp_buffer, Xsink_list); + struct comp_buffer *buffer = container_of(clist, struct comp_buffer, Xsink_list); //msz ?? buffer->Xsink = NULL; /* Also if it isn't shared - we are about to modify uncached data */ diff --git a/src/ipc/ipc3/handler.c b/src/ipc/ipc3/handler.c index ce17f2ec39d2..dad0dcd17927 100644 --- a/src/ipc/ipc3/handler.c +++ b/src/ipc/ipc3/handler.c @@ -165,19 +165,15 @@ static bool is_hostless_downstream(struct comp_dev *current) /* check if a pipeline is hostless when walking upstream */ static bool is_hostless_upstream(struct comp_dev *current) { - struct list_item *clist; - /* check if current is a HOST comp */ if (current->ipc_config.type == SOF_COMP_HOST || current->ipc_config.type == SOF_COMP_SG_HOST) return false; /* check if the pipeline has a HOST comp upstream */ - list_for_item(clist, ¤t->bsource_list) { - struct comp_buffer *buffer; - - buffer = container_of(clist, struct comp_buffer, Xsink_list); + struct comp_buffer *buffer = comp_dev_get_first_data_producer(current); + while(buffer) { /* don't go upstream if this component is not connected */ if (!buffer->Xsource) continue; @@ -190,6 +186,8 @@ static bool is_hostless_upstream(struct comp_dev *current) /* return if there is a host comp upstream */ if (!is_hostless_upstream(buffer->Xsource)) return false; + + buffer = comp_dev_get_next_data_producer(current, buffer); } return true; diff --git a/src/ipc/ipc4/helper.c b/src/ipc/ipc4/helper.c index d236802baf2e..176cbdb5c5be 100644 --- a/src/ipc/ipc4/helper.c +++ b/src/ipc/ipc4/helper.c @@ -286,7 +286,6 @@ static int ipc_pipeline_module_free(uint32_t pipeline_id) icd = ipc_get_comp_by_ppl_id(ipc, COMP_TYPE_COMPONENT, pipeline_id, IPC_COMP_ALL); while (icd) { - struct list_item *list, *_list; struct comp_buffer *buffer = comp_dev_get_first_data_consumer(icd->cd); /* free sink buffer allocated by current component in bind function */ @@ -308,16 +307,24 @@ static int ipc_pipeline_module_free(uint32_t pipeline_id) } /* free source buffer allocated by current component in bind function */ - list_for_item_safe(list, _list, &icd->cd->bsource_list) { + buffer = comp_dev_get_first_data_producer(icd->cd); + + while (buffer) { + /* save next buffer pointer, as the buffer will be removed from list */ + struct comp_buffer *next_buffer = + comp_dev_get_next_data_producer(icd->cd, buffer); + struct comp_dev *source; - buffer = container_of(list, struct comp_buffer, Xsink_list); pipeline_disconnect(icd->cd, buffer, PPL_CONN_DIR_BUFFER_TO_COMP); source = buffer->Xsource; /* free the buffer only when the source module has also been disconnected */ if (!source) buffer_free(buffer); + + + buffer = next_buffer; } if (!cpu_is_me(icd->core)) diff --git a/src/probe/probe.c b/src/probe/probe.c index c9c88ec9933b..0986c90bc9fc 100644 --- a/src/probe/probe.c +++ b/src/probe/probe.c @@ -1061,17 +1061,19 @@ static bool probe_purpose_needs_ext_dma(uint32_t purpose) static struct comp_buffer *ipc4_get_buffer(struct ipc_comp_dev *dev, probe_point_id_t probe_point) { struct comp_buffer *buf; - struct list_item *source_list; unsigned int queue_id; switch (probe_point.fields.type) { case PROBE_TYPE_INPUT: - list_for_item(source_list, &dev->cd->bsource_list) { - buf = container_of(source_list, struct comp_buffer, Xsink_list); + buf = comp_dev_get_first_data_producer(dev->cd); + while(buf) + { queue_id = IPC4_SRC_QUEUE_ID(buf_get_id(buf)); if (queue_id == probe_point.fields.index) return buf; + + buf = comp_dev_get_next_data_producer(dev->cd, buf); } break; case PROBE_TYPE_OUTPUT: diff --git a/src/samples/audio/smart_amp_test_ipc3.c b/src/samples/audio/smart_amp_test_ipc3.c index 1d649a6d8e26..db37b69988c5 100644 --- a/src/samples/audio/smart_amp_test_ipc3.c +++ b/src/samples/audio/smart_amp_test_ipc3.c @@ -487,7 +487,6 @@ static int smart_amp_prepare(struct comp_dev *dev) { struct smart_amp_data *sad = comp_get_drvdata(dev); struct comp_buffer *source_buffer; - struct list_item *blist; int ret; comp_info(dev, "smart_amp_prepare()"); @@ -500,14 +499,16 @@ static int smart_amp_prepare(struct comp_dev *dev) return PPL_STATUS_PATH_STOP; /* searching for stream and feedback source buffers */ - list_for_item(blist, &dev->bsource_list) { - source_buffer = container_of(blist, struct comp_buffer, Xsink_list); - + source_buffer = comp_dev_get_first_data_producer(dev); + while(source_buffer) + { /* FIXME: how often can this loop be run? */ if (source_buffer->Xsource->ipc_config.type == SOF_COMP_DEMUX) sad->feedback_buf = source_buffer; else sad->source_buf = source_buffer; + + source_buffer = comp_dev_get_next_data_producer(dev, source_buffer); } sad->sink_buf = comp_dev_get_first_data_consumer(dev);