From 01f03d2b8fed9906bb6b1a644de522c7ddb8b3c0 Mon Sep 17 00:00:00 2001 From: Ievgen Ganakov Date: Fri, 8 Sep 2023 12:17:20 +0200 Subject: [PATCH] copier: store gateway config in copier_data Calculate actual size of copier module gateway config. Copy and store it in copier_data. It needs to be available even after copier is created e.g. during SET_PIPELINE_STATE IPC when dai_config_dma_channel() is called second time and DMA config is used to assing dma_channel_id value. Signed-off-by: Ievgen Ganakov --- src/audio/copier/copier.c | 34 +++++++++++++++++++++++++++++++++- src/include/ipc4/copier.h | 3 ++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/audio/copier/copier.c b/src/audio/copier/copier.c index 0bb2306d2a6e..e53ca18b8282 100644 --- a/src/audio/copier/copier.c +++ b/src/audio/copier/copier.c @@ -64,6 +64,8 @@ static int copier_init(struct processing_module *mod) struct module_data *md = &mod->priv; struct ipc4_copier_module_cfg *copier = (struct ipc4_copier_module_cfg *)md->cfg.init_data; struct comp_ipc_config *config = &dev->ipc_config; + void *gtw_cfg; + size_t gtw_cfg_size; int i, ret = 0; cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); @@ -78,7 +80,33 @@ static int copier_init(struct processing_module *mod) */ if (memcpy_s(&cd->config, sizeof(cd->config), copier, sizeof(*copier)) < 0) { ret = -EINVAL; - goto error; + goto error_cd; + } + + /* Allocate memory and store gateway_cfg in runtime. Gateway cfg has to + * be kept even after copier is created e.g. during SET_PIPELINE_STATE + * IPC when dai_config_dma_channel() is called second time and DMA + * config is used to assign dma_channel_id value. + */ + if (copier->gtw_cfg.config_length) { + gtw_cfg_size = copier->gtw_cfg.config_length << 2; + gtw_cfg = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + gtw_cfg_size); + if (!gtw_cfg) { + ret = -ENOMEM; + goto error_cd; + } + + ret = memcpy_s(gtw_cfg, gtw_cfg_size, &copier->gtw_cfg.config_data, + gtw_cfg_size); + if (ret < 0) { + comp_err(dev, "Unable to copy gateway config from copier blob"); + goto error; + } + + cd->gtw_cfg = gtw_cfg; + } else { + cd->gtw_cfg = NULL; } for (i = 0; i < IPC4_COPIER_MODULE_OUTPUT_PINS_COUNT; i++) @@ -146,6 +174,8 @@ static int copier_init(struct processing_module *mod) dev->state = COMP_STATE_READY; return 0; error: + rfree(gtw_cfg); +error_cd: rfree(cd); return ret; } @@ -170,6 +200,8 @@ static int copier_free(struct processing_module *mod) break; } + if (cd) + rfree(cd->gtw_cfg); rfree(cd); return 0; diff --git a/src/include/ipc4/copier.h b/src/include/ipc4/copier.h index 23953d6aca97..ab27d3faf956 100644 --- a/src/include/ipc4/copier.h +++ b/src/include/ipc4/copier.h @@ -155,7 +155,7 @@ struct ipc4_copier_module_cfg { /* audio format for output pin 0 */ struct ipc4_audio_format out_fmt; uint32_t copier_feature_mask; - struct ipc4_copier_gateway_cfg gtw_cfg; + struct ipc4_copier_gateway_cfg gtw_cfg; } __attribute__((packed, aligned(4))); enum ipc4_copier_module_config_params { @@ -242,6 +242,7 @@ struct copier_data { * from the IPC data. */ struct ipc4_copier_module_cfg config; + void *gtw_cfg; struct comp_dev *endpoint[IPC4_COPIER_MODULE_OUTPUT_PINS_COUNT]; struct comp_buffer *endpoint_buffer[IPC4_COPIER_MODULE_OUTPUT_PINS_COUNT]; uint32_t endpoint_num;