Skip to content

Commit c19c8c9

Browse files
committed
WIP: Example code for downstream type conversion
NOT COMPILE TESTED Given we cannot trust our enum field in the IPC as communicator may lie about the component on the other side and the module adapter is obscuring the nature of many of the components we need to move the type casting into the components directly. Here is a breakdown of the general steps to achieve this. 1. report ipc config size for all versions 2. remove type casting in the IPC3 layer 3. on non module adapter components cast the config in a compile time selected shim 4. in the module adapter ipc3 layer, remove type casting again 5. in module adapter components realloc init data and cast over in a compile time enabled shim Signed-off-by: Curtis Malainey <cujomalainey@chromium.org>
1 parent 1cb3aa7 commit c19c8c9

4 files changed

Lines changed: 53 additions & 206 deletions

File tree

src/audio/asrc/asrc.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,8 +860,31 @@ static int asrc_reset(struct processing_module *mod)
860860
return 0;
861861
}
862862

863+
#if CONFIG_IPC_MAJOR_3
864+
static int asrc_init_shim(struct processing_module *mod)
865+
{
866+
struct ipc_config_asrc *ipc_asrc = rballoc(0, SOF_MEM_CAPS_RAM, sizeof(*ipc_asrc));
867+
struct module_data *mod_data = &mod->priv;
868+
const struct sof_ipc_comp_asrc *asrc =
869+
(const struct sof_ipc_comp_asrc *)mod_data->cfg.init_data;
870+
871+
if (!ipc_asrc)
872+
return -ENOMEM;
873+
// TODO size checks
874+
ipc_asrc->source_rate = asrc->source_rate;
875+
ipc_asrc->sink_rate = asrc->sink_rate;
876+
ipc_asrc->asrc_get_asynchronous_mode = asrc->asrc_verify_params;
877+
ipc_asrc->operation_mode = asrc->operation_mode;
878+
879+
rfree(mod_data->cfg.init_data);
880+
mod_data->cfg.init_data = ipc_asrc;
881+
mod_data->cfg.data = ipc_asrc;
882+
return asrc_init(mod);
883+
}
884+
#endif
885+
863886
static const struct module_interface asrc_interface = {
864-
.init = asrc_init,
887+
.init = INIT_IPC_SHIM(asrc_init_shim, asrc_init),
865888
.prepare = asrc_prepare,
866889
.process_audio_stream = asrc_process,
867890
.trigger = asrc_trigger,

src/audio/module_adapter/module_adapter_ipc3.c

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -38,66 +38,9 @@ int module_adapter_init_data(struct comp_dev *dev,
3838
const struct comp_ipc_config *config,
3939
const void *spec)
4040
{
41-
int ret;
42-
43-
const unsigned char *data = NULL;
44-
uint32_t size = 0;
45-
46-
switch (config->type) {
47-
case SOF_COMP_VOLUME:
48-
{
49-
const struct ipc_config_volume *ipc_volume = spec;
50-
51-
size = sizeof(*ipc_volume);
52-
data = spec;
53-
break;
54-
}
55-
case SOF_COMP_SRC:
56-
{
57-
const struct ipc_config_src *ipc_src = spec;
58-
59-
size = sizeof(*ipc_src);
60-
data = spec;
61-
break;
62-
}
63-
case SOF_COMP_ASRC:
64-
{
65-
const struct ipc_config_asrc *ipc_asrc = spec;
66-
67-
size = sizeof(*ipc_asrc);
68-
data = spec;
69-
break;
70-
}
71-
case SOF_COMP_MIXER:
72-
break;
73-
case SOF_COMP_EQ_IIR:
74-
case SOF_COMP_EQ_FIR:
75-
case SOF_COMP_KEYWORD_DETECT:
76-
case SOF_COMP_KPB:
77-
case SOF_COMP_SELECTOR:
78-
case SOF_COMP_DEMUX:
79-
case SOF_COMP_MUX:
80-
case SOF_COMP_DCBLOCK:
81-
case SOF_COMP_SMART_AMP:
82-
case SOF_COMP_MODULE_ADAPTER:
83-
case SOF_COMP_FILEREAD:
84-
case SOF_COMP_FILEWRITE:
85-
case SOF_COMP_NONE:
86-
{
87-
const struct ipc_config_process *ipc_module_adapter = spec;
88-
89-
size = ipc_module_adapter->size;
90-
data = ipc_module_adapter->data;
91-
break;
92-
}
93-
default:
94-
comp_err(dev, "module_adapter_init_data() unsupported comp type %d", config->type);
95-
return -EINVAL;
96-
}
97-
9841
/* Copy initial config */
99-
if (size) {
100-
ret = module_load_config(dev, data, size);
42+
if (config->ipc_config_size) {
43+
ret = module_load_config(dev, spec, config->ipc_config_size);
10144
if (ret < 0) {
10245
comp_err(dev, "module_adapter_init_data() error %d: config loading has failed.",
10346
ret);

src/audio/tone.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,12 +706,36 @@ static int tone_reset(struct comp_dev *dev)
706706
return 0;
707707
}
708708

709+
#if CONFIG_IPC_MAJOR_3
710+
static struct comp_dev *tone_new_shim(const struct comp_driver *drv,
711+
const struct comp_ipc_config *config,
712+
const void *spec)
713+
{
714+
struct sof_ipc_comp_tone *comp = spec;
715+
struct ipc_config_tone tone;
716+
717+
// TODO check size of comp against tone
718+
719+
tone.ampl_mult = tone->ampl_mult;
720+
tone.amplitude = tone->amplitude;
721+
tone.freq_mult = tone->freq_mult;
722+
tone.frequency = tone->frequency;
723+
tone.length = tone->length;
724+
tone.period = tone->period;
725+
tone.ramp_step = tone->ramp_step;
726+
tone.repeats = tone->repeats;
727+
tone.sample_rate = tone->sample_rate;
728+
729+
return tone_new(drv, config, &tone);
730+
}
731+
#endif
732+
709733
static const struct comp_driver comp_tone = {
710734
.type = SOF_COMP_TONE,
711735
.uid = SOF_RT_UUID(tone_uuid),
712736
.tctx = &tone_tr,
713737
.ops = {
714-
.create = tone_new,
738+
.create = INTI_IPC_SHIM(tone_new_shim, tone_new),
715739
.free = tone_free,
716740
.params = tone_params,
717741
#if CONFIG_IPC_MAJOR_3

src/ipc/ipc3/helper.c

Lines changed: 2 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ static void comp_common_builder(struct sof_ipc_comp *comp,
171171
config->pipeline_id = comp->pipeline_id;
172172
config->proc_domain = COMP_PROCESSING_DOMAIN_LL;
173173
config->type = comp->type;
174+
config->ipc_config_size = comp->size;
174175

175176
/* buffers dont have the following data */
176177
if (comp->type != SOF_COMP_BUFFER) {
@@ -182,144 +183,6 @@ static void comp_common_builder(struct sof_ipc_comp *comp,
182183
config->xrun_action = ipc_config->xrun_action;
183184
}
184185
}
185-
/*
186-
* Stores all the "legacy" init IPC data locally.
187-
*/
188-
union ipc_config_specific {
189-
struct ipc_config_host host;
190-
struct ipc_config_dai dai;
191-
struct ipc_config_volume volume;
192-
struct ipc_config_src src;
193-
struct ipc_config_asrc asrc;
194-
struct ipc_config_tone tone;
195-
struct ipc_config_process process;
196-
struct ipc_comp_file file;
197-
} __attribute__((packed, aligned(4)));
198-
199-
/* build component specific data */
200-
static int comp_specific_builder(struct sof_ipc_comp *comp,
201-
union ipc_config_specific *config)
202-
{
203-
#if CONFIG_LIBRARY
204-
struct sof_ipc_comp_file *file = (struct sof_ipc_comp_file *)comp;
205-
#endif
206-
struct sof_ipc_comp_host *host = (struct sof_ipc_comp_host *)comp;
207-
struct sof_ipc_comp_dai *dai = (struct sof_ipc_comp_dai *)comp;
208-
struct sof_ipc_comp_volume *vol = (struct sof_ipc_comp_volume *)comp;
209-
struct sof_ipc_comp_process *proc = (struct sof_ipc_comp_process *)comp;
210-
struct sof_ipc_comp_src *src = (struct sof_ipc_comp_src *)comp;
211-
struct sof_ipc_comp_asrc *asrc = (struct sof_ipc_comp_asrc *)comp;
212-
struct sof_ipc_comp_tone *tone = (struct sof_ipc_comp_tone *)comp;
213-
214-
memset(config, 0, sizeof(*config));
215-
216-
switch (comp->type) {
217-
#if CONFIG_LIBRARY
218-
/* test bench maps host and DAIs to a file */
219-
case SOF_COMP_FILEREAD:
220-
case SOF_COMP_FILEWRITE:
221-
if (IPC_TAIL_IS_SIZE_INVALID(*file))
222-
return -EBADMSG;
223-
224-
config->file.channels = file->channels;
225-
config->file.fn = file->fn;
226-
config->file.frame_fmt = file->frame_fmt;
227-
config->file.mode = file->mode;
228-
config->file.rate = file->rate;
229-
config->file.direction = file->direction;
230-
231-
/* For module_adapter_init_data() ipc_module_adapter compatibility */
232-
config->file.module_header.type = proc->type;
233-
config->file.module_header.size = proc->size;
234-
config->file.module_header.data = (uint8_t *)proc->data -
235-
sizeof(struct ipc_config_process);
236-
break;
237-
#endif
238-
case SOF_COMP_HOST:
239-
case SOF_COMP_SG_HOST:
240-
if (IPC_TAIL_IS_SIZE_INVALID(*host))
241-
return -EBADMSG;
242-
config->host.direction = host->direction;
243-
config->host.no_irq = host->no_irq;
244-
config->host.dmac_config = host->dmac_config;
245-
break;
246-
case SOF_COMP_DAI:
247-
case SOF_COMP_SG_DAI:
248-
if (IPC_TAIL_IS_SIZE_INVALID(*dai))
249-
return -EBADMSG;
250-
config->dai.dai_index = dai->dai_index;
251-
config->dai.direction = dai->direction;
252-
config->dai.type = dai->type;
253-
break;
254-
case SOF_COMP_VOLUME:
255-
if (IPC_TAIL_IS_SIZE_INVALID(*vol))
256-
return -EBADMSG;
257-
config->volume.channels = vol->channels;
258-
config->volume.initial_ramp = vol->initial_ramp;
259-
config->volume.max_value = vol->max_value;
260-
config->volume.min_value = vol->min_value;
261-
config->volume.ramp = vol->ramp;
262-
break;
263-
case SOF_COMP_SRC:
264-
if (IPC_TAIL_IS_SIZE_INVALID(*src))
265-
return -EBADMSG;
266-
config->src.rate_mask = src->rate_mask;
267-
config->src.sink_rate = src->sink_rate;
268-
config->src.source_rate = src->source_rate;
269-
break;
270-
case SOF_COMP_TONE:
271-
if (IPC_TAIL_IS_SIZE_INVALID(*tone))
272-
return -EBADMSG;
273-
config->tone.ampl_mult = tone->ampl_mult;
274-
config->tone.amplitude = tone->amplitude;
275-
config->tone.freq_mult = tone->freq_mult;
276-
config->tone.frequency = tone->frequency;
277-
config->tone.length = tone->length;
278-
config->tone.period = tone->period;
279-
config->tone.ramp_step = tone->ramp_step;
280-
config->tone.repeats = tone->repeats;
281-
config->tone.sample_rate = tone->sample_rate;
282-
break;
283-
case SOF_COMP_ASRC:
284-
if (IPC_TAIL_IS_SIZE_INVALID(*asrc))
285-
return -EBADMSG;
286-
config->asrc.source_rate = asrc->source_rate;
287-
config->asrc.sink_rate = asrc->sink_rate;
288-
config->asrc.asynchronous_mode = asrc->asynchronous_mode;
289-
config->asrc.operation_mode = asrc->operation_mode;
290-
break;
291-
case SOF_COMP_EQ_IIR:
292-
case SOF_COMP_EQ_FIR:
293-
case SOF_COMP_KEYWORD_DETECT:
294-
case SOF_COMP_KPB:
295-
case SOF_COMP_SELECTOR:
296-
case SOF_COMP_DEMUX:
297-
case SOF_COMP_MUX:
298-
case SOF_COMP_DCBLOCK:
299-
case SOF_COMP_SMART_AMP:
300-
case SOF_COMP_MODULE_ADAPTER:
301-
case SOF_COMP_NONE:
302-
if (IPC_TAIL_IS_SIZE_INVALID(*proc))
303-
return -EBADMSG;
304-
305-
if (proc->comp.hdr.size + proc->size > SOF_IPC_MSG_MAX_SIZE)
306-
return -EBADMSG;
307-
308-
config->process.type = proc->type;
309-
config->process.size = proc->size;
310-
#if CONFIG_LIBRARY || UNIT_TEST
311-
config->process.data = proc->data + comp->ext_data_length;
312-
#else
313-
config->process.data = proc->data;
314-
#endif
315-
break;
316-
case SOF_COMP_MIXER:
317-
break;
318-
default:
319-
return -EINVAL;
320-
}
321-
return 0;
322-
}
323186

324187
struct ipc_comp_dev *ipc_get_comp_by_ppl_id(struct ipc *ipc,
325188
uint16_t type, uint32_t ppl_id,
@@ -343,7 +206,6 @@ struct ipc_comp_dev *ipc_get_comp_by_ppl_id(struct ipc *ipc,
343206
struct comp_dev *comp_new(struct sof_ipc_comp *comp)
344207
{
345208
struct comp_ipc_config config;
346-
union ipc_config_specific spec;
347209
struct comp_dev *cdev;
348210
const struct comp_driver *drv;
349211

@@ -361,13 +223,8 @@ struct comp_dev *comp_new(struct sof_ipc_comp *comp)
361223
tr_info(&comp_tr, "comp new %pU type %d id %d.%d",
362224
drv->tctx->uuid_p, comp->type, comp->pipeline_id, comp->id);
363225

364-
/* build the component */
365-
if (comp_specific_builder(comp, &spec) < 0) {
366-
comp_cl_err(drv, "comp_new(): component type not recognized");
367-
return NULL;
368-
}
369226
comp_common_builder(comp, &config);
370-
cdev = drv->ops.create(drv, &config, &spec);
227+
cdev = drv->ops.create(drv, &config, comp);
371228
if (!cdev) {
372229
comp_cl_err(drv, "comp_new(): unable to create the new component");
373230
return NULL;

0 commit comments

Comments
 (0)