Skip to content

Commit

Permalink
copier: keep variable size copier module config in copier_data
Browse files Browse the repository at this point in the history
Extend the feature of keeping the copier module config in copier_data
to the whole ipc4_copier_module_cfg structure, including its variable
size part gtw_cfg.config_data[]. This eliminates the need to store
config_data in separate gtw_cfg field.

Signed-off-by: Tomasz Lissowski <[email protected]>
  • Loading branch information
tlissows committed Jul 19, 2024
1 parent d629e52 commit a0a5279
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 77 deletions.
66 changes: 20 additions & 46 deletions src/audio/copier/copier.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,51 +62,27 @@ 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 = NULL;
size_t gtw_cfg_size;
size_t copier_cfg_size;
int i, ret = 0;

cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd));
if (!cd)
return -ENOMEM;

md->private = cd;
/*
* Don't copy the config_data[] variable size array, we don't need to
* store it, it's only used during IPC processing, besides we haven't
* allocated space for it, so don't "fix" this!
*/
if (memcpy_s(&cd->config, sizeof(cd->config), copier, sizeof(*copier)) < 0) {
ret = -EINVAL;
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 = rmalloc(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) {
comp_err(dev, "Unable to copy gateway config from copier blob");
goto error;
}
copier_cfg_size = sizeof(*copier) + copier->gtw_cfg.config_length * sizeof(uint32_t);

cd->gtw_cfg = gtw_cfg;
cd->config = rmalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, copier_cfg_size);
if (!cd->config) {
ret = -ENOMEM;
goto error;
}

memcpy(cd->config, copier, copier_cfg_size);

for (i = 0; i < IPC4_COPIER_MODULE_OUTPUT_PINS_COUNT; i++)
cd->out_fmt[i] = cd->config.out_fmt;
cd->out_fmt[i] = cd->config->out_fmt;

ipc_pipe = ipc_get_comp_by_ppl_id(ipc, COMP_TYPE_PIPELINE,
config->pipeline_id,
Expand Down Expand Up @@ -174,8 +150,7 @@ static int copier_init(struct processing_module *mod)
dev->state = COMP_STATE_READY;
return 0;
error:
rfree(gtw_cfg);
error_cd:
rfree(cd->config);
rfree(cd);
return ret;
}
Expand All @@ -200,8 +175,7 @@ static int copier_free(struct processing_module *mod)
break;
}

if (cd)
rfree(cd->gtw_cfg);
rfree(cd->config);
rfree(cd);

return 0;
Expand Down Expand Up @@ -244,12 +218,12 @@ static int copier_prepare(struct processing_module *mod,
/* set up format conversion function for pin 0, for other pins (if any)
* format is set in IPC4_COPIER_MODULE_CFG_PARAM_SET_SINK_FORMAT handler
*/
cd->converter[0] = get_converter_func(&cd->config.base.audio_fmt,
&cd->config.out_fmt, ipc4_gtw_none,
cd->converter[0] = get_converter_func(&cd->config->base.audio_fmt,
&cd->config->out_fmt, ipc4_gtw_none,
ipc4_bidirection, DUMMY_CHMAP);
if (!cd->converter[0]) {
comp_err(dev, "can't support for in format %d, out format %d",
cd->config.base.audio_fmt.depth, cd->config.out_fmt.depth);
cd->config->base.audio_fmt.depth, cd->config->out_fmt.depth);
return -EINVAL;
}
}
Expand Down Expand Up @@ -674,7 +648,7 @@ static int copier_set_sink_fmt(struct comp_dev *dev, const void *data,
return -EINVAL;
}

if (memcmp(&cd->config.base.audio_fmt, &sink_fmt->source_fmt,
if (memcmp(&cd->config->base.audio_fmt, &sink_fmt->source_fmt,
sizeof(sink_fmt->source_fmt))) {
comp_err(dev, "error: source fmt should be equal to input fmt");
return -EINVAL;
Expand Down Expand Up @@ -719,10 +693,10 @@ static int set_attenuation(struct comp_dev *dev, uint32_t data_offset, const cha
return -EINVAL;
}

audio_stream_fmt_conversion(cd->config.out_fmt.depth,
cd->config.out_fmt.valid_bit_depth,
audio_stream_fmt_conversion(cd->config->out_fmt.depth,
cd->config->out_fmt.valid_bit_depth,
&frame_fmt, &valid_fmt,
cd->config.out_fmt.s_type);
cd->config->out_fmt.s_type);

if (frame_fmt < SOF_IPC_FRAME_S24_4LE) {
comp_err(dev, "frame_fmt %d isn't supported by attenuation",
Expand All @@ -741,8 +715,8 @@ static int set_chmap(struct comp_dev *dev, const void *data, size_t data_size)
struct processing_module *mod = comp_mod(dev);
struct copier_data *cd = module_get_private_data(mod);
enum ipc4_direction_type dir;
struct ipc4_audio_format in_fmt = cd->config.base.audio_fmt;
struct ipc4_audio_format out_fmt = cd->config.out_fmt;
struct ipc4_audio_format in_fmt = cd->config->base.audio_fmt;
struct ipc4_audio_format out_fmt = cd->config->out_fmt;
pcm_converter_func process;
pcm_converter_func converters[IPC4_COPIER_MODULE_OUTPUT_PINS_COUNT];
int i;
Expand Down
9 changes: 2 additions & 7 deletions src/audio/copier/copier.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,8 @@ struct ipc4_data_segment_enabled {
} __attribute__((packed, aligned(4)));

struct copier_data {
/*
* struct ipc4_copier_module_cfg actually has variable size, but we
* don't need the variable size array at the end, we won't be copying it
* from the IPC data.
*/
struct ipc4_copier_module_cfg config;
void *gtw_cfg;
/* Contains the whole config copied from IPC data (incl. variable size gateway cfg). */
struct ipc4_copier_module_cfg *config;
enum ipc4_gateway_type gtw_type;
struct comp_dev *endpoint[IPC4_COPIER_MODULE_OUTPUT_PINS_COUNT];
struct comp_buffer *endpoint_buffer[IPC4_COPIER_MODULE_OUTPUT_PINS_COUNT];
Expand Down
16 changes: 8 additions & 8 deletions src/audio/copier/copier_dai.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static int copier_alh_assign_dai_index(struct comp_dev *dev,
size_t alh_cfg_size, dma_config_length;
int i, dai_num, ret;

if (!cd->config.gtw_cfg.config_length) {
if (!cd->config->gtw_cfg.config_length) {
comp_err(mod->dev, "No gateway config found in blob!");
return -EINVAL;
}
Expand All @@ -88,7 +88,7 @@ static int copier_alh_assign_dai_index(struct comp_dev *dev,
/* We use DAI_INTEL_HDA for ACE 2.0 platforms */
alh_cfg_size = get_alh_config_size(alh_blob);
dma_config = (uint8_t *)gtw_cfg_data + alh_cfg_size;
dma_config_length = (cd->config.gtw_cfg.config_length << 2) - alh_cfg_size;
dma_config_length = (cd->config->gtw_cfg.config_length << 2) - alh_cfg_size;

/* Here we check node_id if we need to use FW aggregation,
* in other words do we need to create multiple dai or not
Expand Down Expand Up @@ -266,7 +266,7 @@ int copier_dai_create(struct comp_dev *dev, struct copier_data *cd,
dai.type = SOF_DAI_INTEL_SSP;
dai.is_config_blob = true;
cd->gtw_type = ipc4_gtw_ssp;
ret = ipc4_find_dma_config(&dai, (uint8_t *)cd->gtw_cfg,
ret = ipc4_find_dma_config(&dai, (uint8_t *)copier->gtw_cfg.config_data,
copier->gtw_cfg.config_length * 4);
if (ret != 0) {
comp_err(dev, "No ssp dma_config found in blob!");
Expand All @@ -285,16 +285,16 @@ int copier_dai_create(struct comp_dev *dev, struct copier_data *cd,
dai.is_config_blob = true;
cd->gtw_type = ipc4_gtw_alh;
#endif /* ACE_VERSION > ACE_VERSION_1_5 */
ret = copier_alh_assign_dai_index(dev, cd->gtw_cfg, node_id,
&dai, dai_index, &dai_count);
ret = copier_alh_assign_dai_index(dev, (void *)copier->gtw_cfg.config_data,
node_id, &dai, dai_index, &dai_count);
if (ret)
return ret;
break;
case ipc4_dmic_link_input_class:
dai.type = SOF_DAI_INTEL_DMIC;
dai.is_config_blob = true;
cd->gtw_type = ipc4_gtw_dmic;
ret = ipc4_find_dma_config(&dai, (uint8_t *)cd->gtw_cfg,
ret = ipc4_find_dma_config(&dai, (uint8_t *)copier->gtw_cfg.config_data,
copier->gtw_cfg.config_length * 4);
if (ret != 0) {
comp_err(dev, "No dmic dma_config found in blob!");
Expand Down Expand Up @@ -510,8 +510,8 @@ int copier_dai_params(struct copier_data *cd, struct comp_dev *dev,
int j, ret;

if (cd->endpoint_num == 1) {
struct ipc4_audio_format in_fmt = cd->config.base.audio_fmt;
struct ipc4_audio_format out_fmt = cd->config.out_fmt;
struct ipc4_audio_format in_fmt = cd->config->base.audio_fmt;
struct ipc4_audio_format out_fmt = cd->config->out_fmt;
enum ipc4_direction_type dir;

ret = dai_common_params(cd->dd[0], dev, params);
Expand Down
16 changes: 8 additions & 8 deletions src/audio/copier/copier_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ void copier_update_params(struct copier_data *cd, struct comp_dev *dev,

memset(params, 0, sizeof(*params));
params->direction = cd->direction;
params->channels = cd->config.base.audio_fmt.channels_count;
params->rate = cd->config.base.audio_fmt.sampling_frequency;
params->sample_container_bytes = cd->config.base.audio_fmt.depth / 8;
params->sample_valid_bytes = cd->config.base.audio_fmt.valid_bit_depth / 8;
params->channels = cd->config->base.audio_fmt.channels_count;
params->rate = cd->config->base.audio_fmt.sampling_frequency;
params->sample_container_bytes = cd->config->base.audio_fmt.depth / 8;
params->sample_valid_bytes = cd->config->base.audio_fmt.valid_bit_depth / 8;

params->stream_tag = cd->config.gtw_cfg.node_id.f.v_index + 1;
params->stream_tag = cd->config->gtw_cfg.node_id.f.v_index + 1;
params->frame_fmt = dev->ipc_config.frame_fmt;
params->buffer_fmt = cd->config.base.audio_fmt.interleaving_style;
params->buffer.size = cd->config.base.ibs;
params->buffer_fmt = cd->config->base.audio_fmt.interleaving_style;
params->buffer.size = cd->config->base.ibs;

/* disable ipc3 stream position */
params->no_stream_position = 1;
Expand All @@ -100,7 +100,7 @@ void copier_update_params(struct copier_data *cd, struct comp_dev *dev,
if (dev->ipc_config.type == SOF_COMP_DAI &&
(cd->endpoint_num > 1 || params->direction == SOF_IPC_STREAM_CAPTURE))
break;
params->buffer.size = cd->config.base.obs;
params->buffer.size = cd->config->base.obs;
params->sample_container_bytes = cd->out_fmt->depth / 8;
params->sample_valid_bytes = cd->out_fmt->valid_bit_depth / 8;
break;
Expand Down
2 changes: 1 addition & 1 deletion src/audio/copier/copier_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static int init_pipeline_reg(struct comp_dev *dev)
struct ipc4_pipeline_registers pipe_reg;
uint32_t gateway_id;

gateway_id = cd->config.gtw_cfg.node_id.f.v_index;
gateway_id = cd->config->gtw_cfg.node_id.f.v_index;
if (gateway_id >= IPC4_MAX_PIPELINE_REG_SLOTS) {
comp_err(dev, "gateway_id %u out of array bounds.", gateway_id);
return -EINVAL;
Expand Down
9 changes: 2 additions & 7 deletions src/ipc/ipc4/dai.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,10 @@ int dai_config_dma_channel(struct dai_data *dd, struct comp_dev *dev, const void
copier_cfg->gtw_cfg.node_id.f.dma_type == ipc4_alh_link_input_class) {
struct processing_module *mod = comp_mod(dev);
struct copier_data *cd = module_get_private_data(mod);

if (!cd->gtw_cfg) {
comp_err(dev, "No gateway config found!");
return DMA_CHAN_INVALID;
}
const struct sof_alh_configuration_blob *alh_blob =
(void *)&cd->config->gtw_cfg.config_data;

channel = DMA_CHAN_INVALID;
const struct sof_alh_configuration_blob *alh_blob = cd->gtw_cfg;

for (int i = 0; i < alh_blob->alh_cfg.count; i++) {
if (dai->host_dma_config[i]->stream_id == dai->dai_index) {
channel = dai->host_dma_config[i]->dma_channel_id;
Expand Down

0 comments on commit a0a5279

Please sign in to comment.