diff --git a/src/audio/copier/copier.c b/src/audio/copier/copier.c index 57e3a3a4f397..8179e5561561 100644 --- a/src/audio/copier/copier.c +++ b/src/audio/copier/copier.c @@ -1067,20 +1067,22 @@ static int copier_bind(struct processing_module *mod, void *data) const uint32_t src_queue_id = bu->extension.r.src_queue; struct copier_data *cd = module_get_private_data(mod); struct comp_dev *dev = mod->dev; - struct list_item *list; if (dev->ipc_config.id != src_id) return 0; /* Another component is a data producer */ /* update sink format */ - list_for_item(list, &dev->bsink_list) { - struct comp_buffer *buffer = container_of(list, struct comp_buffer, Xsource_list); + struct comp_buffer *buffer = comp_dev_get_first_data_consumer(dev); + + while (buffer) { uint32_t id = IPC4_SRC_QUEUE_ID(buf_get_id(buffer)); if (src_queue_id == id) { ipc4_update_buffer_format(buffer, &cd->out_fmt[id]); return 0; } + + buffer = comp_dev_get_next_data_consumer(dev, buffer); } comp_err(dev, "No sink buffer found for src_queue = %u", src_queue_id); diff --git a/src/audio/kpb.c b/src/audio/kpb.c index b0be935bd9d0..1c69ce104d8f 100644 --- a/src/audio/kpb.c +++ b/src/audio/kpb.c @@ -328,7 +328,6 @@ static int kpb_bind(struct comp_dev *dev, void *data) { struct comp_data *kpb = comp_get_drvdata(dev); struct ipc4_module_bind_unbind *bu; - struct list_item *blist; int buf_id; int ret = 0; @@ -343,9 +342,9 @@ static int kpb_bind(struct comp_dev *dev, void *data) * (Detector/MicSel has one input pin). To properly connect KPB sink * with Detector source we're looking for buffer with id=0. */ + struct comp_buffer *sink = comp_dev_get_first_data_consumer(dev); - list_for_item(blist, &dev->bsink_list) { - struct comp_buffer *sink = container_of(blist, struct comp_buffer, Xsource_list); + while (sink) { int sink_buf_id; if (!sink->Xsink) { @@ -361,6 +360,8 @@ static int kpb_bind(struct comp_dev *dev, void *data) else kpb->host_sink = sink; } + + sink = comp_dev_get_next_data_consumer(dev, sink); } return ret; @@ -858,10 +859,9 @@ static int kpb_prepare(struct comp_dev *dev) * NOTE! We assume here that channel selector component device * is connected to the KPB sinks as well as host device. */ - struct list_item *blist; + struct comp_buffer *sink = comp_dev_get_first_data_consumer(dev); - list_for_item(blist, &dev->bsink_list) { - struct comp_buffer *sink = container_of(blist, struct comp_buffer, Xsource_list); + while (sink) { enum sof_comp_type type; if (!sink->Xsink) { @@ -882,6 +882,8 @@ static int kpb_prepare(struct comp_dev *dev) default: break; } + + sink = comp_dev_get_next_data_consumer(dev, sink); } #else /* Update number of sel_sink channels. diff --git a/src/audio/module_adapter/module_adapter.c b/src/audio/module_adapter/module_adapter.c index d7f12a01a25c..55bd89f36c42 100644 --- a/src/audio/module_adapter/module_adapter.c +++ b/src/audio/module_adapter/module_adapter.c @@ -630,7 +630,7 @@ static void module_adapter_process_output(struct comp_dev *dev) if (i == j) { struct comp_buffer *source; - sink = container_of(blist, struct comp_buffer, Xsource_list); + sink = container_of(blist, struct comp_buffer, Xsource_list); //msz ??? source = container_of(_blist, struct comp_buffer, Xsink_list); module_copy_samples(dev, source, sink, @@ -785,7 +785,6 @@ static int module_adapter_audio_stream_type_copy(struct comp_dev *dev) struct comp_buffer *sources[PLATFORM_MAX_STREAMS]; struct comp_buffer *sinks[PLATFORM_MAX_STREAMS]; struct processing_module *mod = comp_mod(dev); - struct list_item *blist; uint32_t num_input_buffers, num_output_buffers; int ret, i = 0; @@ -797,11 +796,12 @@ static int module_adapter_audio_stream_type_copy(struct comp_dev *dev) return module_adapter_audio_stream_copy_1to1(dev); /* acquire all sink and source buffers */ - list_for_item(blist, &dev->bsink_list) { - struct comp_buffer *sink; + struct comp_buffer *sink = comp_dev_get_first_data_consumer(dev); - sink = container_of(blist, struct comp_buffer, Xsource_list); + while (sink) { sinks[i++] = sink; + + sink = comp_dev_get_next_data_consumer(dev, sink); } num_output_buffers = i; if (num_output_buffers > mod->max_sinks) { @@ -810,6 +810,8 @@ 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; @@ -910,16 +912,16 @@ static int module_adapter_copy_ring_buffers(struct comp_dev *dev) * DP module processing itself will take place in DP thread * This is an adapter, to be removed when pipeline2.0 is ready */ - struct processing_module *mod = comp_mod(dev); + struct comp_buffer *buffer; struct list_item *blist; + struct processing_module *mod = comp_mod(dev); int err; list_for_item(blist, &dev->bsource_list) { /* input - we need to copy data from audio_stream (as source) * to ring_buffer (as sink) */ - struct comp_buffer *buffer = - container_of(blist, struct comp_buffer, Xsink_list); + buffer = container_of(blist, struct comp_buffer, Xsink_list); err = audio_buffer_sync_secondary_buffer(&buffer->audio_buffer, UINT_MAX); if (err) { @@ -931,7 +933,8 @@ static int module_adapter_copy_ring_buffers(struct comp_dev *dev) if (mod->dp_startup_delay) return 0; - list_for_item(blist, &dev->bsink_list) { + buffer = comp_dev_get_first_data_consumer(dev); + while(buffer) { /* output - we need to copy data from ring_buffer (as source) * to audio_stream (as sink) * @@ -944,8 +947,6 @@ static int module_adapter_copy_ring_buffers(struct comp_dev *dev) * * FIX: copy only the following module's IBS in each LL cycle */ - struct comp_buffer *buffer = - container_of(blist, struct comp_buffer, Xsource_list); struct sof_source *following_mod_data_source = audio_buffer_get_source(&buffer->audio_buffer); @@ -957,6 +958,8 @@ static int module_adapter_copy_ring_buffers(struct comp_dev *dev) comp_err(dev, "DP to LL copy error status: %d", err); return err; } + + buffer = comp_dev_get_next_data_consumer(dev, buffer); } return 0; } diff --git a/src/audio/module_adapter/module_adapter_ipc3.c b/src/audio/module_adapter/module_adapter_ipc3.c index d29c4e905201..7cd5f22180db 100644 --- a/src/audio/module_adapter/module_adapter_ipc3.c +++ b/src/audio/module_adapter/module_adapter_ipc3.c @@ -320,17 +320,18 @@ int module_adapter_cmd(struct comp_dev *dev, int cmd, void *data, int max_data_s int module_adapter_sink_src_prepare(struct comp_dev *dev) { struct processing_module *mod = comp_mod(dev); - struct list_item *blist; int ret; int i; /* acquire all sink and source buffers, get handlers to sink/source API */ i = 0; - list_for_item(blist, &dev->bsink_list) { - struct comp_buffer *sink_buffer = - container_of(blist, struct comp_buffer, Xsource_list); + struct comp_buffer *sink_buffer = comp_dev_get_first_data_consumer(dev); + + while (sink_buffer) { mod->sinks[i] = audio_buffer_get_sink(&sink_buffer->audio_buffer); i++; + + sink_buffer = comp_dev_get_next_data_consumer(dev, sink_buffer); } mod->num_of_sinks = i; diff --git a/src/audio/module_adapter/module_adapter_ipc4.c b/src/audio/module_adapter/module_adapter_ipc4.c index 7870a214f7af..afbebe5cd8f3 100644 --- a/src/audio/module_adapter/module_adapter_ipc4.c +++ b/src/audio/module_adapter/module_adapter_ipc4.c @@ -192,11 +192,13 @@ static bool module_adapter_multi_sink_source_prepare(struct comp_dev *dev) /* acquire all sink and source buffers, get handlers to sink/source API */ i = 0; - list_for_item(blist, &dev->bsink_list) { - struct comp_buffer *sink_buffer = - container_of(blist, struct comp_buffer, Xsource_list); + struct comp_buffer *sink_buffer = comp_dev_get_first_data_consumer(dev); + + while (sink_buffer) { mod->sinks[i] = audio_buffer_get_sink(&sink_buffer->audio_buffer); i++; + + sink_buffer = comp_dev_get_next_data_consumer(dev, sink_buffer); } mod->num_of_sinks = i; diff --git a/src/audio/mux/mux.c b/src/audio/mux/mux.c index 5658dd4a6a0d..904e396f6408 100644 --- a/src/audio/mux/mux.c +++ b/src/audio/mux/mux.c @@ -233,7 +233,6 @@ static int demux_process(struct processing_module *mod, { struct comp_data *cd = module_get_private_data(mod); struct comp_dev *dev = mod->dev; - struct list_item *clist; struct comp_buffer *sink; struct audio_stream *sinks_stream[MUX_MAX_STREAMS] = { NULL }; struct mux_look_up *look_ups[MUX_MAX_STREAMS] = { NULL }; @@ -245,8 +244,8 @@ static int demux_process(struct processing_module *mod, comp_dbg(dev, "demux_process()"); /* align sink streams with their respective configurations */ - list_for_item(clist, &dev->bsink_list) { - sink = container_of(clist, struct comp_buffer, Xsource_list); + sink = comp_dev_get_first_data_consumer(dev); + while (sink) { if (sink->Xsink->state == dev->state) { i = get_stream_index(dev, cd, buffer_pipeline_id(sink)); /* return if index wrong */ @@ -257,6 +256,8 @@ static int demux_process(struct processing_module *mod, look_ups[i] = get_lookup_table(dev, cd, buffer_pipeline_id(sink)); sinks_stream[i] = &sink->stream; } + + sink = comp_dev_get_next_data_consumer(dev, sink); } /* if there are no sinks active, then sinks[] is also empty */ @@ -449,7 +450,7 @@ static int demux_trigger(struct processing_module *mod, int cmd) */ if (cmd == COMP_TRIGGER_PRE_START) { list_for_item(li, &mod->dev->bsink_list) { - b = container_of(li, struct comp_buffer, Xsource_list); + b = container_of(li, struct comp_buffer, Xsource_list); //msz ????? if (b->Xsink->pipeline != mod->dev->pipeline) audio_stream_set_overrun(&b->stream, true); } diff --git a/src/ipc/ipc-helper.c b/src/ipc/ipc-helper.c index e6542d31faf0..bdf9760b1d63 100644 --- a/src/ipc/ipc-helper.c +++ b/src/ipc/ipc-helper.c @@ -314,8 +314,7 @@ int ipc_comp_free(struct ipc *ipc, uint32_t comp_id) } list_for_item_safe(clist, tmp, &icd->cd->bsink_list) { - struct comp_buffer *buffer = container_of(clist, struct comp_buffer, Xsource_list); - + struct comp_buffer *buffer = container_of(clist, struct comp_buffer, Xsource_list); //msz ??? buffer->Xsource = NULL; /* Also if it isn't shared - we are about to modify uncached data */ dcache_writeback_invalidate_region(uncache_to_cache(buffer), diff --git a/src/ipc/ipc3/handler.c b/src/ipc/ipc3/handler.c index f62072d97ee4..631886a14957 100644 --- a/src/ipc/ipc3/handler.c +++ b/src/ipc/ipc3/handler.c @@ -135,19 +135,14 @@ struct ipc_cmd_hdr *mailbox_validate(void) /* check if a pipeline is hostless when walking downstream */ static bool is_hostless_downstream(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 downstream */ - list_for_item(clist, ¤t->bsink_list) { - struct comp_buffer *buffer; - - buffer = container_of(clist, struct comp_buffer, Xsource_list); - + struct comp_buffer *buffer = comp_dev_get_first_data_consumer(dev); + while (buffer) { /* don't go downstream if this component is not connected */ if (!buffer->Xsink) continue; @@ -160,6 +155,8 @@ static bool is_hostless_downstream(struct comp_dev *current) /* return if there's a host comp downstream */ if (!is_hostless_downstream(buffer->Xsink)) return false; + + buffer = comp_dev_get_next_data_consumer(dev, sink); } return true; diff --git a/src/ipc/ipc4/helper.c b/src/ipc/ipc4/helper.c index 1aff7500067e..07057d0f1dd4 100644 --- a/src/ipc/ipc4/helper.c +++ b/src/ipc/ipc4/helper.c @@ -277,6 +277,7 @@ static inline int ipc_comp_free_remote(struct comp_dev *dev) return idc_send_msg(&msg, IDC_BLOCKING); } +__attribute__((optimize("-O0"))) static int ipc_pipeline_module_free(uint32_t pipeline_id) { struct ipc *ipc = ipc_get(); @@ -286,19 +287,24 @@ 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; + struct comp_buffer *buffer = comp_dev_get_first_data_consumer(icd->cd); /* free sink buffer allocated by current component in bind function */ - list_for_item_safe(list, _list, &icd->cd->bsink_list) { + while (buffer) { + /* save next buffer pointer, as the buffer will be removed from list */ + struct comp_buffer *next_buffer = + comp_dev_get_next_data_consumer(icd->cd, buffer); + struct comp_dev *sink; - buffer = container_of(list, struct comp_buffer, Xsource_list); pipeline_disconnect(icd->cd, buffer, PPL_CONN_DIR_COMP_TO_BUFFER); sink = buffer->Xsink; /* free the buffer only when the sink module has also been disconnected */ if (!sink) buffer_free(buffer); + + buffer = next_buffer; } /* free source buffer allocated by current component in bind function */ @@ -697,14 +703,17 @@ int ipc_comp_disconnect(struct ipc *ipc, ipc_pipe_comp_connect *_connect) return ipc4_process_on_core(src->ipc_config.core, false); buffer_id = IPC4_COMP_ID(bu->extension.r.src_queue, bu->extension.r.dst_queue); - list_for_item(sink_list, &src->bsink_list) { - struct comp_buffer *buf = container_of(sink_list, struct comp_buffer, Xsource_list); + struct comp_buffer *buf = comp_dev_get_first_data_consumer(src); + + while (buf) { bool found = buf_get_id(buf) == buffer_id; if (found) { buffer = buf; break; } + + buf = comp_dev_get_next_data_consumer(src, buf); } if (!buffer) diff --git a/src/probe/probe.c b/src/probe/probe.c index 9b9e6a285a99..3d31d6108d0c 100644 --- a/src/probe/probe.c +++ b/src/probe/probe.c @@ -1075,12 +1075,14 @@ static struct comp_buffer *ipc4_get_buffer(struct ipc_comp_dev *dev, probe_point } break; case PROBE_TYPE_OUTPUT: - list_for_item(sink_list, &dev->cd->bsink_list) { - buf = container_of(sink_list, struct comp_buffer, Xsource_list); + buf = comp_dev_get_first_data_consumer(dev->cd); + while(buf) { queue_id = IPC4_SINK_QUEUE_ID(buf_get_id(buf)); if (queue_id == probe_point.fields.index) return buf; + + buf = comp_dev_get_next_data_consumer(dev->cd, buf); } } diff --git a/test/cmocka/src/util.h b/test/cmocka/src/util.h index 2ec364ab161f..9d0e1cdef0cd 100644 --- a/test/cmocka/src/util.h +++ b/test/cmocka/src/util.h @@ -29,7 +29,7 @@ static inline struct comp_buffer *create_test_sink(struct comp_dev *dev, /* set bsink list */ if (dev) - list_item_append(&buffer->Xsource_list, &dev->bsink_list); + list_item_append(&buffer->Xsource_list, &dev->bsink_list); //msz /* alloc sink and set default parameters */ buffer->Xsink = calloc(1, sizeof(struct comp_dev));