From 0553ebe358a795a5366a93b593c742bc68712822 Mon Sep 17 00:00:00 2001 From: Tomasz Lauda Date: Thu, 17 Oct 2019 10:14:05 +0200 Subject: [PATCH 1/2] ipc: rename ipc_get_comp function Renames ipc_get_comp function to ipc_get_comp_by_id. Signed-off-by: Tomasz Lauda --- src/drivers/intel/cavs/idc.c | 4 ++-- src/include/sof/drivers/ipc.h | 2 +- src/ipc/handler.c | 10 ++++----- src/ipc/ipc.c | 22 +++++++++---------- .../src/audio/pipeline/pipeline_mocks.c | 2 +- .../src/audio/pipeline/pipeline_mocks.h | 2 +- tools/testbench/common_test.c | 4 ++-- tools/testbench/testbench.c | 6 ++--- 8 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/drivers/intel/cavs/idc.c b/src/drivers/intel/cavs/idc.c index 7ac49b233248..dae93f792fcd 100644 --- a/src/drivers/intel/cavs/idc.c +++ b/src/drivers/intel/cavs/idc.c @@ -176,7 +176,7 @@ static int idc_pipeline_trigger(uint32_t cmd) dcache_invalidate_region(data, sizeof(*data)); /* check whether component exists */ - pcm_dev = ipc_get_comp(ipc, data->comp_id); + pcm_dev = ipc_get_comp_by_id(ipc, data->comp_id); if (!pcm_dev) return -ENODEV; @@ -246,7 +246,7 @@ static int idc_component_command(uint32_t cmd) data->rhdr.hdr.size - sizeof(*data)); /* check whether component exists */ - comp_dev = ipc_get_comp(ipc, data->comp_id); + comp_dev = ipc_get_comp_by_id(ipc, data->comp_id); if (!comp_dev) return -ENODEV; diff --git a/src/include/sof/drivers/ipc.h b/src/include/sof/drivers/ipc.h index 08b9cf0ec868..ddb95daaa689 100644 --- a/src/include/sof/drivers/ipc.h +++ b/src/include/sof/drivers/ipc.h @@ -224,7 +224,7 @@ int ipc_comp_connect(struct ipc *ipc, /* * Get component by ID. */ -struct ipc_comp_dev *ipc_get_comp(struct ipc *ipc, uint32_t id); +struct ipc_comp_dev *ipc_get_comp_by_id(struct ipc *ipc, uint32_t id); /* * Configure all DAI components attached to DAI. diff --git a/src/ipc/handler.c b/src/ipc/handler.c index f47b54d7a32e..9e264dc50de4 100644 --- a/src/ipc/handler.c +++ b/src/ipc/handler.c @@ -224,7 +224,7 @@ static int ipc_stream_pcm_params(uint32_t stream) trace_ipc("ipc: comp %d -> params", pcm_params.comp_id); /* get the pcm_dev */ - pcm_dev = ipc_get_comp(_ipc, pcm_params.comp_id); + pcm_dev = ipc_get_comp_by_id(_ipc, pcm_params.comp_id); if (pcm_dev == NULL) { trace_ipc_error("ipc: comp %d not found", pcm_params.comp_id); return -ENODEV; @@ -344,7 +344,7 @@ static int ipc_stream_pcm_free(uint32_t header) trace_ipc("ipc: comp %d -> free", free_req.comp_id); /* get the pcm_dev */ - pcm_dev = ipc_get_comp(_ipc, free_req.comp_id); + pcm_dev = ipc_get_comp_by_id(_ipc, free_req.comp_id); if (pcm_dev == NULL) { trace_ipc_error("ipc: comp %d not found", free_req.comp_id); return -ENODEV; @@ -376,7 +376,7 @@ static int ipc_stream_position(uint32_t header) memset(&posn, 0, sizeof(posn)); /* get the pcm_dev */ - pcm_dev = ipc_get_comp(_ipc, stream.comp_id); + pcm_dev = ipc_get_comp_by_id(_ipc, stream.comp_id); if (pcm_dev == NULL) { trace_ipc_error("ipc: comp %d not found", stream.comp_id); return -ENODEV; @@ -455,7 +455,7 @@ static int ipc_stream_trigger(uint32_t header) trace_ipc("ipc: comp %d -> trigger cmd 0x%x", stream.comp_id, ipc_cmd); /* get the pcm_dev */ - pcm_dev = ipc_get_comp(_ipc, stream.comp_id); + pcm_dev = ipc_get_comp_by_id(_ipc, stream.comp_id); if (pcm_dev == NULL) { trace_ipc_error("ipc: comp %d not found", stream.comp_id); return -ENODEV; @@ -842,7 +842,7 @@ static int ipc_comp_value(uint32_t header, uint32_t cmd) trace_ipc("ipc: comp %d -> cmd %d", data.comp_id, data.cmd); /* get the component */ - comp_dev = ipc_get_comp(_ipc, data.comp_id); + comp_dev = ipc_get_comp_by_id(_ipc, data.comp_id); if (!comp_dev) { trace_ipc_error("ipc: comp %d not found", data.comp_id); return -ENODEV; diff --git a/src/ipc/ipc.c b/src/ipc/ipc.c index 908011daa083..3bfb59b906de 100644 --- a/src/ipc/ipc.c +++ b/src/ipc/ipc.c @@ -38,7 +38,7 @@ * more than 1 list may need to be searched for the corresponding component. */ -struct ipc_comp_dev *ipc_get_comp(struct ipc *ipc, uint32_t id) +struct ipc_comp_dev *ipc_get_comp_by_id(struct ipc *ipc, uint32_t id) { struct ipc_comp_dev *icd; struct list_item *clist; @@ -129,7 +129,7 @@ int ipc_comp_new(struct ipc *ipc, struct sof_ipc_comp *comp) int ret = 0; /* check whether component already exists */ - icd = ipc_get_comp(ipc, comp->id); + icd = ipc_get_comp_by_id(ipc, comp->id); if (icd != NULL) { trace_ipc_error("ipc_comp_new() error: comp->id = %u", comp->id); @@ -164,7 +164,7 @@ int ipc_comp_free(struct ipc *ipc, uint32_t comp_id) struct ipc_comp_dev *icd; /* check whether component exists */ - icd = ipc_get_comp(ipc, comp_id); + icd = ipc_get_comp_by_id(ipc, comp_id); if (icd == NULL) return -ENODEV; @@ -196,7 +196,7 @@ int ipc_buffer_new(struct ipc *ipc, struct sof_ipc_buffer *desc) int ret = 0; /* check whether buffer already exists */ - ibd = ipc_get_comp(ipc, desc->comp.id); + ibd = ipc_get_comp_by_id(ipc, desc->comp.id); if (ibd != NULL) { trace_ipc_error("ipc_buffer_new() error: " "buffer already exists, desc->comp.id = %u", @@ -231,7 +231,7 @@ int ipc_buffer_free(struct ipc *ipc, uint32_t buffer_id) struct ipc_comp_dev *ibd; /* check whether buffer exists */ - ibd = ipc_get_comp(ipc, buffer_id); + ibd = ipc_get_comp_by_id(ipc, buffer_id); if (ibd == NULL) return -ENODEV; @@ -250,7 +250,7 @@ int ipc_comp_connect(struct ipc *ipc, struct ipc_comp_dev *icd_sink; /* check whether the components already exist */ - icd_source = ipc_get_comp(ipc, connect->source_id); + icd_source = ipc_get_comp_by_id(ipc, connect->source_id); if (icd_source == NULL) { trace_ipc_error("ipc_comp_connect() error: components already" " exist, connect->source_id = %u", @@ -258,7 +258,7 @@ int ipc_comp_connect(struct ipc *ipc, return -EINVAL; } - icd_sink = ipc_get_comp(ipc, connect->sink_id); + icd_sink = ipc_get_comp_by_id(ipc, connect->sink_id); if (icd_sink == NULL) { trace_ipc_error("ipc_comp_connect() error: components already" " exist, connect->sink_id = %u", @@ -293,7 +293,7 @@ int ipc_pipeline_new(struct ipc *ipc, struct ipc_comp_dev *icd; /* check whether the pipeline already exists */ - ipc_pipe = ipc_get_comp(ipc, pipe_desc->comp_id); + ipc_pipe = ipc_get_comp_by_id(ipc, pipe_desc->comp_id); if (ipc_pipe != NULL) { trace_ipc_error("ipc_pipeline_new() error: pipeline already" " exists, pipe_desc->comp_id = %u", @@ -302,7 +302,7 @@ int ipc_pipeline_new(struct ipc *ipc, } /* find the scheduling component */ - icd = ipc_get_comp(ipc, pipe_desc->sched_id); + icd = ipc_get_comp_by_id(ipc, pipe_desc->sched_id); if (icd == NULL) { trace_ipc_error("ipc_pipeline_new() error: cannot find the " "scheduling component, pipe_desc->sched_id" @@ -345,7 +345,7 @@ int ipc_pipeline_free(struct ipc *ipc, uint32_t comp_id) int ret; /* check whether pipeline exists */ - ipc_pipe = ipc_get_comp(ipc, comp_id); + ipc_pipe = ipc_get_comp_by_id(ipc, comp_id); if (ipc_pipe == NULL) return -ENODEV; @@ -371,7 +371,7 @@ int ipc_pipeline_complete(struct ipc *ipc, uint32_t comp_id) struct ipc_comp_dev *ipc_ppl_sink; /* check whether pipeline exists */ - ipc_pipe = ipc_get_comp(ipc, comp_id); + ipc_pipe = ipc_get_comp_by_id(ipc, comp_id); if (!ipc_pipe) return -EINVAL; diff --git a/test/cmocka/src/audio/pipeline/pipeline_mocks.c b/test/cmocka/src/audio/pipeline/pipeline_mocks.c index 04633c00506e..7c60693d757e 100644 --- a/test/cmocka/src/audio/pipeline/pipeline_mocks.c +++ b/test/cmocka/src/audio/pipeline/pipeline_mocks.c @@ -65,7 +65,7 @@ void cpu_power_down_core(void) { } void notifier_notify(void) { } -struct ipc_comp_dev *ipc_get_comp(struct ipc *ipc, uint32_t id) +struct ipc_comp_dev *ipc_get_comp_by_id(struct ipc *ipc, uint32_t id) { (void)ipc; (void)id; diff --git a/test/cmocka/src/audio/pipeline/pipeline_mocks.h b/test/cmocka/src/audio/pipeline/pipeline_mocks.h index c22a8723254c..2d19d73957c0 100644 --- a/test/cmocka/src/audio/pipeline/pipeline_mocks.h +++ b/test/cmocka/src/audio/pipeline/pipeline_mocks.h @@ -23,7 +23,7 @@ int arch_cpu_is_core_enabled(int id); void cpu_power_down_core(void); -struct ipc_comp_dev *ipc_get_comp(struct ipc *ipc, uint32_t id); +struct ipc_comp_dev *ipc_get_comp_by_id(struct ipc *ipc, uint32_t id); void notifier_notify(void); diff --git a/tools/testbench/common_test.c b/tools/testbench/common_test.c index 1c870029389f..253cf4f04b66 100644 --- a/tools/testbench/common_test.c +++ b/tools/testbench/common_test.c @@ -64,7 +64,7 @@ int tb_pipeline_start(struct ipc *ipc, int nch, } /* Get IPC component device for pipeline */ - pcm_dev = ipc_get_comp(ipc, ipc_pipe->sched_id); + pcm_dev = ipc_get_comp_by_id(ipc, ipc_pipe->sched_id); if (!pcm_dev) { fprintf(stderr, "error: ipc get comp\n"); return -EINVAL; @@ -136,7 +136,7 @@ int tb_pipeline_params(struct ipc *ipc, int nch, } /* get scheduling component device for pipeline*/ - pcm_dev = ipc_get_comp(ipc, ipc_pipe->sched_id); + pcm_dev = ipc_get_comp_by_id(ipc, ipc_pipe->sched_id); if (!pcm_dev) { fprintf(stderr, "error: ipc get comp\n"); return -EINVAL; diff --git a/tools/testbench/testbench.c b/tools/testbench/testbench.c index 0175ae151da9..0f0cdfa153f7 100644 --- a/tools/testbench/testbench.c +++ b/tools/testbench/testbench.c @@ -217,13 +217,13 @@ int main(int argc, char **argv) } /* Get pointers to fileread and filewrite */ - pcm_dev = ipc_get_comp(sof.ipc, fw_id); + pcm_dev = ipc_get_comp_by_id(sof.ipc, fw_id); fwcd = comp_get_drvdata(pcm_dev->cd); - pcm_dev = ipc_get_comp(sof.ipc, fr_id); + pcm_dev = ipc_get_comp_by_id(sof.ipc, fr_id); frcd = comp_get_drvdata(pcm_dev->cd); /* Run pipeline until EOF from fileread */ - pcm_dev = ipc_get_comp(sof.ipc, sched_id); + pcm_dev = ipc_get_comp_by_id(sof.ipc, sched_id); p = pcm_dev->cd->pipeline; ipc_pipe = &p->ipc_pipe; From df72e10ac165e2c87dbd94ad2ed03013b979b988 Mon Sep 17 00:00:00 2001 From: Tomasz Lauda Date: Thu, 17 Oct 2019 10:23:32 +0200 Subject: [PATCH 2/2] ipc: check whether pipeline id is already taken When new pipeline is created we need to also verify whether given pipeline id is already taken. Signed-off-by: Tomasz Lauda --- src/include/sof/drivers/ipc.h | 6 +++ src/ipc/ipc.c | 40 +++++++++++++++++++ .../src/audio/pipeline/pipeline_mocks.c | 10 +++++ .../src/audio/pipeline/pipeline_mocks.h | 3 ++ 4 files changed, 59 insertions(+) diff --git a/src/include/sof/drivers/ipc.h b/src/include/sof/drivers/ipc.h index ddb95daaa689..b9813337d4fd 100644 --- a/src/include/sof/drivers/ipc.h +++ b/src/include/sof/drivers/ipc.h @@ -226,6 +226,12 @@ int ipc_comp_connect(struct ipc *ipc, */ struct ipc_comp_dev *ipc_get_comp_by_id(struct ipc *ipc, uint32_t id); +/* + * Get component by pipeline ID. + */ +struct ipc_comp_dev *ipc_get_comp_by_ppl_id(struct ipc *ipc, uint16_t type, + uint32_t ppl_id); + /* * Configure all DAI components attached to DAI. */ diff --git a/src/ipc/ipc.c b/src/ipc/ipc.c index 3bfb59b906de..8f911937f312 100644 --- a/src/ipc/ipc.c +++ b/src/ipc/ipc.c @@ -66,6 +66,36 @@ struct ipc_comp_dev *ipc_get_comp_by_id(struct ipc *ipc, uint32_t id) return NULL; } +struct ipc_comp_dev *ipc_get_comp_by_ppl_id(struct ipc *ipc, uint16_t type, + uint32_t ppl_id) +{ + struct ipc_comp_dev *icd; + struct list_item *clist; + + list_for_item(clist, &ipc->shared_ctx->comp_list) { + icd = container_of(clist, struct ipc_comp_dev, list); + if (icd->type != type) + continue; + + switch (icd->type) { + case COMP_TYPE_COMPONENT: + if (icd->cd->comp.pipeline_id == ppl_id) + return icd; + break; + case COMP_TYPE_BUFFER: + if (icd->cb->ipc_buffer.comp.pipeline_id == ppl_id) + return icd; + break; + case COMP_TYPE_PIPELINE: + if (icd->pipeline->ipc_pipe.pipeline_id == ppl_id) + return icd; + break; + } + } + + return NULL; +} + static struct ipc_comp_dev *ipc_get_ppl_comp(struct ipc *ipc, uint32_t pipeline_id, int dir) { @@ -301,6 +331,16 @@ int ipc_pipeline_new(struct ipc *ipc, return -EINVAL; } + /* check whether pipeline id is already taken */ + ipc_pipe = ipc_get_comp_by_ppl_id(ipc, COMP_TYPE_PIPELINE, + pipe_desc->pipeline_id); + if (ipc_pipe) { + trace_ipc_error("ipc_pipeline_new() error: pipeline id is " + "already taken, pipe_desc->pipeline_id = %u", + pipe_desc->pipeline_id); + return -EINVAL; + } + /* find the scheduling component */ icd = ipc_get_comp_by_id(ipc, pipe_desc->sched_id); if (icd == NULL) { diff --git a/test/cmocka/src/audio/pipeline/pipeline_mocks.c b/test/cmocka/src/audio/pipeline/pipeline_mocks.c index 7c60693d757e..50d19e2cd0c1 100644 --- a/test/cmocka/src/audio/pipeline/pipeline_mocks.c +++ b/test/cmocka/src/audio/pipeline/pipeline_mocks.c @@ -73,6 +73,16 @@ struct ipc_comp_dev *ipc_get_comp_by_id(struct ipc *ipc, uint32_t id) return NULL; } +struct ipc_comp_dev *ipc_get_comp_by_ppl_id(struct ipc *ipc, uint16_t type, + uint32_t ppl_id) +{ + (void)ipc; + (void)type; + (void)ppl_id; + + return NULL; +} + void heap_trace_all(int force) { (void)force; diff --git a/test/cmocka/src/audio/pipeline/pipeline_mocks.h b/test/cmocka/src/audio/pipeline/pipeline_mocks.h index 2d19d73957c0..795c69ed00a7 100644 --- a/test/cmocka/src/audio/pipeline/pipeline_mocks.h +++ b/test/cmocka/src/audio/pipeline/pipeline_mocks.h @@ -25,6 +25,9 @@ void cpu_power_down_core(void); struct ipc_comp_dev *ipc_get_comp_by_id(struct ipc *ipc, uint32_t id); +struct ipc_comp_dev *ipc_get_comp_by_ppl_id(struct ipc *ipc, uint16_t type, + uint32_t ppl_id); + void notifier_notify(void); void platform_dai_timestamp(struct comp_dev *dai,