Skip to content

Commit

Permalink
ipc: remove buffer_acquire from ipc helpers
Browse files Browse the repository at this point in the history
remove buffer_acquire / release from ipc helpers

this is a continuation of changes
from commit 4a03699

Signed-off-by: Marcin Szkudlinski <[email protected]>
  • Loading branch information
marcinszkudlinski committed Sep 18, 2023
1 parent 047c4a6 commit 80a7136
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 49 deletions.
29 changes: 8 additions & 21 deletions src/ipc/ipc-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ int comp_verify_params(struct comp_dev *dev, uint32_t flag,
struct list_item *clist;
struct comp_buffer *sinkb;
struct comp_buffer *buf;
struct comp_buffer *buf_c;
int dir = dev->direction;

if (!params) {
Expand All @@ -128,22 +127,18 @@ int comp_verify_params(struct comp_dev *dev, uint32_t flag,
struct comp_buffer,
source_list);

buf_c = buffer_acquire(buf);

/* update specific pcm parameter with buffer parameter if
* specific flag is set.
*/
comp_update_params(flag, params, buf_c);
comp_update_params(flag, params, buf);

/* overwrite buffer parameters with modified pcm
* parameters
*/
buffer_set_params(buf_c, params, BUFFER_UPDATE_FORCE);
buffer_set_params(buf, params, BUFFER_UPDATE_FORCE);

/* set component period frames */
component_set_nearest_period_frames(dev, audio_stream_get_rate(&buf_c->stream));

buffer_release(buf_c);
component_set_nearest_period_frames(dev, audio_stream_get_rate(&buf->stream));
} else {
/* for other components we iterate over all downstream buffers
* (for playback) or upstream buffers (for capture).
Expand All @@ -152,19 +147,15 @@ int comp_verify_params(struct comp_dev *dev, uint32_t flag,

list_for_item(clist, buffer_list) {
buf = buffer_from_list(clist, dir);
buf_c = buffer_acquire(buf);
comp_update_params(flag, params, buf_c);
buffer_set_params(buf_c, params, BUFFER_UPDATE_FORCE);
buffer_release(buf_c);
comp_update_params(flag, params, buf);
buffer_set_params(buf, params, BUFFER_UPDATE_FORCE);
}

/* fetch sink buffer in order to calculate period frames */
sinkb = list_first_item(&dev->bsink_list, struct comp_buffer,
source_list);

buf_c = buffer_acquire(sinkb);
component_set_nearest_period_frames(dev, audio_stream_get_rate(&buf_c->stream));
buffer_release(buf_c);
component_set_nearest_period_frames(dev, audio_stream_get_rate(&sinkb->stream));
}

return 0;
Expand Down Expand Up @@ -291,10 +282,8 @@ 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, sink_list);
struct comp_buffer *buffer_c = buffer_acquire(buffer);

buffer_c->sink = NULL;
buffer_release(buffer_c);
buffer->sink = NULL;
/* Also if it isn't shared - we are about to modify uncached data */
dcache_writeback_invalidate_region(uncache_to_cache(buffer),
sizeof(*buffer));
Expand All @@ -304,10 +293,8 @@ 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, source_list);
struct comp_buffer *buffer_c = buffer_acquire(buffer);

buffer_c->source = NULL;
buffer_release(buffer_c);
buffer->source = NULL;
/* Also if it isn't shared - we are about to modify uncached data */
dcache_writeback_invalidate_region(uncache_to_cache(buffer),
sizeof(*buffer));
Expand Down
17 changes: 6 additions & 11 deletions src/ipc/ipc3/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,6 @@ int ipc_buffer_free(struct ipc *ipc, uint32_t buffer_id)
unsigned int core;
bool sink_active = false;
bool source_active = false;
struct comp_buffer *buffer_c;

/* check whether buffer exists */
ibd = ipc_get_buffer_by_id(ipc, buffer_id);
Expand All @@ -498,30 +497,26 @@ int ipc_buffer_free(struct ipc *ipc, uint32_t buffer_id)
if (!cpu_is_me(ibd->core))
return ipc_process_on_core(ibd->core, false);

buffer_c = buffer_acquire(ibd->cb);

/* try to find sink/source components to check if they still exists */
list_for_item(clist, &ipc->comp_list) {
icd = container_of(clist, struct ipc_comp_dev, list);
if (icd->type != COMP_TYPE_COMPONENT)
continue;

/* check comp state if sink and source are valid */
if (buffer_c->sink == icd->cd) {
sink = buffer_c->sink;
if (buffer_c->sink->state != COMP_STATE_READY)
if (ibd->cb->sink == icd->cd) {
sink = ibd->cb->sink;
if (ibd->cb->sink->state != COMP_STATE_READY)
sink_active = true;
}

if (buffer_c->source == icd->cd) {
source = buffer_c->source;
if (buffer_c->source->state != COMP_STATE_READY)
if (ibd->cb->source == icd->cd) {
source = ibd->cb->source;
if (ibd->cb->source->state != COMP_STATE_READY)
source_active = true;
}
}

buffer_release(buffer_c);

/*
* A buffer could be connected to 2 different pipelines. When one pipeline is freed, the
* buffer comp that belongs in this pipeline will need to be freed even when the other
Expand Down
22 changes: 5 additions & 17 deletions src/ipc/ipc4/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,11 @@ static int ipc_pipeline_module_free(uint32_t pipeline_id)

/* free sink buffer allocated by current component in bind function */
list_for_item_safe(list, _list, &icd->cd->bsink_list) {
struct comp_buffer *buffer_c;
struct comp_dev *sink;

buffer = container_of(list, struct comp_buffer, source_list);
pipeline_disconnect(icd->cd, buffer, PPL_CONN_DIR_COMP_TO_BUFFER);
buffer_c = buffer_acquire(buffer);
sink = buffer_c->sink;
buffer_release(buffer_c);
sink = buffer->sink;

/* free the buffer only when the sink module has also been disconnected */
if (!sink)
Expand All @@ -257,14 +254,11 @@ 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) {
struct comp_buffer *buffer_c;
struct comp_dev *source;

buffer = container_of(list, struct comp_buffer, sink_list);
pipeline_disconnect(icd->cd, buffer, PPL_CONN_DIR_BUFFER_TO_COMP);
buffer_c = buffer_acquire(buffer);
source = buffer_c->source;
buffer_release(buffer_c);
source = buffer->source;

/* free the buffer only when the source module has also been disconnected */
if (!source)
Expand Down Expand Up @@ -337,7 +331,6 @@ int ipc_comp_connect(struct ipc *ipc, ipc_pipe_comp_connect *_connect)
{
struct ipc4_module_bind_unbind *bu;
struct comp_buffer *buffer;
struct comp_buffer *buffer_c;
struct comp_dev *source;
struct comp_dev *sink;
struct ipc4_base_module_cfg source_src_cfg;
Expand Down Expand Up @@ -388,10 +381,8 @@ int ipc_comp_connect(struct ipc *ipc, ipc_pipe_comp_connect *_connect)
* OBS of a buffer is IBS of destination component
*/

buffer_c = buffer_acquire(buffer);
source_set_ibs(audio_stream_get_source(&buffer_c->stream), source_src_cfg.obs);
sink_set_obs(audio_stream_get_sink(&buffer_c->stream), sink_src_cfg.ibs);
buffer_release(buffer_c);
source_set_ibs(audio_stream_get_source(&buffer->stream), source_src_cfg.obs);
sink_set_obs(audio_stream_get_sink(&buffer->stream), sink_src_cfg.ibs);

/*
* Connect and bind the buffer to both source and sink components with the interrupts
Expand Down Expand Up @@ -490,10 +481,7 @@ int ipc_comp_disconnect(struct ipc *ipc, ipc_pipe_comp_connect *_connect)
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, source_list);
struct comp_buffer *buf_c = buffer_acquire(buf);
bool found = buf_c->id == buffer_id;

buffer_release(buf_c);
bool found = buf->id == buffer_id;

if (found) {
buffer = buf;
Expand Down

0 comments on commit 80a7136

Please sign in to comment.