Skip to content

Commit 77790ce

Browse files
Jyri Sarhalgirdwood
authored andcommitted
component: module_adapter: Move module_ext_init_decode()-call earlier
Move module_ext_init_decode()-call earlier in call chain so that struct ipc4_module_init_ext_obj_dp_data is available when module_adapter_mem_alloc() is called. That is, if the struct ipc4_module_init_ext_object is present in the struct ipc4_module_init_ext_init payload. To accomplish this I needed to redesign how module_ext_init_decode() works and how its called a bit. Signed-off-by: Jyri Sarha <[email protected]>
1 parent a912871 commit 77790ce

File tree

4 files changed

+90
-49
lines changed

4 files changed

+90
-49
lines changed

src/audio/module_adapter/module_adapter.c

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ static void module_adapter_mem_free(struct processing_module *mod)
187187
* \brief Create a module adapter component.
188188
* \param[in] drv - component driver pointer.
189189
* \param[in] config - component ipc descriptor pointer.
190-
* \param[in] spec - passdowned data from driver.
190+
* \param[in] const_spec - passdowned data from driver.
191191
* \param[in] mod_priv - Pointer to private data for processing module.
192192
*
193193
* \return: a pointer to newly created module adapter component on success. NULL on error.
@@ -196,20 +196,32 @@ static void module_adapter_mem_free(struct processing_module *mod)
196196
* the create method.
197197
*/
198198
struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
199-
const struct comp_ipc_config *config, const void *spec,
200-
void *mod_priv, struct userspace_context *user_ctx)
199+
const struct comp_ipc_config *config,
200+
const void *const_spec, void *mod_priv,
201+
struct userspace_context *user_ctx)
201202
{
202203
int ret;
203204
struct module_config *dst;
204205
const struct module_interface *const interface = drv->adapter_ops;
205-
206+
struct ipc_config_process spec =
207+
*((const struct ipc_config_process *) const_spec);
208+
#if CONFIG_IPC_MAJOR_4
209+
struct module_ext_init_data ext_data = { 0 };
210+
#endif
206211
comp_cl_dbg(drv, "start");
207212

208213
if (!config) {
209214
comp_cl_err(drv, "wrong input params! drv = %zx config = %zx",
210215
(size_t)drv, (size_t)config);
211216
return NULL;
212217
}
218+
#if CONFIG_IPC_MAJOR_4
219+
if (config->ipc_extended_init) {
220+
ret = module_ext_init_decode(drv, &ext_data, &spec);
221+
if (ret != 0)
222+
return NULL;
223+
}
224+
#endif
213225

214226
struct processing_module *mod = module_adapter_mem_alloc(drv, config);
215227

@@ -233,7 +245,17 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
233245
#endif /* CONFIG_USERSPACE */
234246

235247
dst = &mod->priv.cfg;
236-
ret = module_adapter_init_data(dev, dst, config, spec);
248+
/*
249+
* NOTE: dst->ext_data points to stack variable and contains
250+
* pointers to IPC payload mailbox, so its only valid in
251+
* functions that called from this function. This why
252+
* the pointer is set NULL before the this function
253+
* exits.
254+
*/
255+
#if CONFIG_IPC_MAJOR_4
256+
dst->ext_data = &ext_data;
257+
#endif
258+
ret = module_adapter_init_data(dev, dst, config, &spec);
237259
if (ret) {
238260
comp_err(dev, "%d: module init data failed",
239261
ret);
@@ -299,6 +321,9 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
299321
component_set_nearest_period_frames(dev, params.rate);
300322
#endif
301323

324+
#if CONFIG_IPC_MAJOR_4
325+
dst->ext_data = NULL;
326+
#endif
302327
comp_dbg(dev, "done");
303328
return dev;
304329

@@ -308,6 +333,9 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
308333
schedule_task_free(dev->task);
309334
#endif
310335
module_adapter_mem_free(mod);
336+
#if CONFIG_IPC_MAJOR_4
337+
dst->ext_data = NULL;
338+
#endif
311339

312340
return NULL;
313341
}

src/audio/module_adapter/module_adapter_ipc4.c

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@
2525

2626
LOG_MODULE_DECLARE(module_adapter, CONFIG_SOF_LOG_LEVEL);
2727

28-
static const struct ipc4_base_module_extended_cfg *
29-
module_ext_init_decode(struct comp_dev *dev, struct module_config *dst,
30-
const unsigned char *data, size_t *size)
28+
int module_ext_init_decode(const struct comp_driver *drv, struct module_ext_init_data *ext_data,
29+
struct ipc_config_process *spec)
3130
{
3231
const struct ipc4_module_init_ext_init *ext_init =
33-
(const struct ipc4_module_init_ext_init *)data;
32+
(const struct ipc4_module_init_ext_init *)spec->data;
3433
bool last_object = !ext_init->data_obj_array;
3534
const struct ipc4_module_init_ext_object *obj;
3635

37-
if (*size < sizeof(ext_init)) {
38-
comp_err(dev, "Size too small for ext init %zu < %zu",
39-
*size, sizeof(ext_init));
40-
return NULL;
36+
assert(drv->type == SOF_COMP_MODULE_ADAPTER);
37+
if (spec->size < sizeof(ext_init)) {
38+
comp_cl_err(drv, "Size too small for ext init %zu < %zu",
39+
spec->size, sizeof(ext_init));
40+
return -EINVAL;
4141
}
4242
/* TODO: Handle ext_init->gna_used and ext_init->rtos_domain here */
4343
/* Get the first obj struct right after ext_init struct */
@@ -46,18 +46,18 @@ module_ext_init_decode(struct comp_dev *dev, struct module_config *dst,
4646
const struct ipc4_module_init_ext_object *next_obj;
4747

4848
/* Check if there is space for the object header */
49-
if ((unsigned char *)(obj + 1) - data > *size) {
50-
comp_err(dev, "ext init obj overflow, %u > %zu",
51-
(unsigned char *)(obj + 1) - data, *size);
52-
return NULL;
49+
if ((unsigned char *)(obj + 1) - spec->data > spec->size) {
50+
comp_cl_err(drv, "ext init obj overflow, %u > %zu",
51+
(unsigned char *)(obj + 1) - spec->data, spec->size);
52+
return -EINVAL;
5353
}
5454
/* Calculate would be next object position and check if current object fits */
5555
next_obj = (const struct ipc4_module_init_ext_object *)
5656
(((uint32_t *) (obj + 1)) + obj->object_words);
57-
if ((unsigned char *)next_obj - data > *size) {
58-
comp_err(dev, "ext init object array overflow, %u > %zu",
59-
(unsigned char *)obj - data, *size);
60-
return NULL;
57+
if ((unsigned char *)next_obj - spec->data > spec->size) {
58+
comp_cl_err(drv, "ext init object array overflow, %u > %zu",
59+
(unsigned char *)obj - spec->data, spec->size);
60+
return -EINVAL;
6161
}
6262
switch (obj->object_id) {
6363
case IPC4_MOD_INIT_DATA_ID_DP_DATA:
@@ -67,37 +67,34 @@ module_ext_init_decode(struct comp_dev *dev, struct module_config *dst,
6767
(const struct ipc4_module_init_ext_obj_dp_data *)(obj + 1);
6868

6969
if (obj->object_words * sizeof(uint32_t) < sizeof(*dp_data)) {
70-
comp_warn(dev, "dp_data object too small %zu < %zu",
71-
obj->object_words * sizeof(uint32_t), sizeof(*dp_data));
70+
comp_cl_warn(drv, "dp_data object too small %zu < %zu",
71+
obj->object_words * sizeof(uint32_t),
72+
sizeof(*dp_data));
7273
break;
7374
}
74-
dst->domain_id = dp_data->domain_id;
75-
dst->stack_bytes = dp_data->stack_bytes;
76-
dst->interim_heap_bytes = dp_data->interim_heap_bytes;
77-
dst->lifetime_heap_bytes = dp_data->interim_heap_bytes;
78-
dst->shared_bytes = dp_data->shared_bytes;
79-
comp_info(dev,
80-
"init_ext_obj_dp_data domain %u stack %u interim %u lifetime %u shared %u",
81-
dp_data->domain_id, dp_data->stack_bytes,
82-
dp_data->interim_heap_bytes, dp_data->lifetime_heap_bytes,
83-
dp_data->shared_bytes);
75+
ext_data->dp_data = dp_data;
76+
comp_cl_info(drv,
77+
"init_ext_obj_dp_data domain %u stack %u interim %u lifetime %u shared %u",
78+
dp_data->domain_id, dp_data->stack_bytes,
79+
dp_data->interim_heap_bytes, dp_data->lifetime_heap_bytes,
80+
dp_data->shared_bytes);
8481
break;
8582
}
8683
default:
87-
comp_info(dev, "Unknown ext init object id %u of %u words",
88-
obj->object_id, obj->object_words);
84+
comp_cl_info(drv, "Unknown ext init object id %u of %u words",
85+
obj->object_id, obj->object_words);
8986
}
9087
/* Read the last object flag from obj header */
9188
last_object = obj->last_object;
9289
/* Move to next object */
9390
obj = next_obj;
9491
}
9592

96-
/* Remove decoded ext_init payload from the size */
97-
*size -= (unsigned char *) obj - data;
93+
/* Remove decoded ext_init payload from spec */
94+
spec->size -= (unsigned char *)obj - spec->data;
95+
spec->data = (const unsigned char *)obj;
9896

99-
/* return remaining payload */
100-
return (const struct ipc4_base_module_extended_cfg *)obj;
97+
return 0;
10198
}
10299

103100
/*
@@ -119,10 +116,7 @@ int module_adapter_init_data(struct comp_dev *dev,
119116
size_t cfgsz = args->size;
120117

121118
assert(dev->drv->type == SOF_COMP_MODULE_ADAPTER);
122-
if (config->ipc_extended_init)
123-
cfg = module_ext_init_decode(dev, dst, args->data, &cfgsz);
124-
else
125-
cfg = (const struct ipc4_base_module_extended_cfg *)args->data;
119+
cfg = (const struct ipc4_base_module_extended_cfg *)args->data;
126120

127121
if (cfg == NULL)
128122
return -EINVAL;

src/include/module/module/base.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@
2323
#define module_get_private_data(mod) ((mod)->priv.private)
2424
#define module_set_private_data(mod, data) ((mod)->priv.private = data)
2525

26+
/**
27+
* \struct module_ext_init_data
28+
* \brief Container for found ext init object pointers
29+
* This struct contains pointers that point to IPC payload directly. The
30+
* module should store what it needs in its init() callback as the data
31+
* is not valid after that.
32+
*/
33+
struct ipc4_module_init_ext_obj_dp_data;
34+
struct module_ext_init_data {
35+
const struct ipc4_module_init_ext_obj_dp_data *dp_data;
36+
};
37+
2638
/**
2739
* \struct module_config
2840
* \brief Module config container, used for both config types.
@@ -38,11 +50,7 @@ struct module_config {
3850
uint8_t nb_output_pins;
3951
struct ipc4_input_pin_format *input_pins;
4052
struct ipc4_output_pin_format *output_pins;
41-
uint32_t domain_id; /* userspace domain ID */
42-
uint32_t stack_bytes; /* stack size in bytes */
43-
uint32_t interim_heap_bytes; /* interim heap size in bytes */
44-
uint32_t lifetime_heap_bytes; /* lifetime heap size in bytes */
45-
uint32_t shared_bytes; /* shared size in bytes */
53+
struct module_ext_init_data *ext_data; /**< IPC payload pointers, NULL after init() */
4654
#endif
4755
};
4856

src/include/sof/audio/module_adapter/module/generic.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,18 @@ int module_adapter_ts_get_op(struct comp_dev *dev, struct timestamp_data *tsd);
431431
void module_update_buffer_position(struct input_stream_buffer *input_buffers,
432432
struct output_stream_buffer *output_buffers,
433433
uint32_t frames);
434-
434+
struct module_ext_init_data;
435+
#if CONFIG_IPC_MAJOR_4
436+
int module_ext_init_decode(const struct comp_driver *drv, struct module_ext_init_data *ext_data,
437+
struct ipc_config_process *spec);
438+
#else
439+
static inline
440+
int module_ext_init_decode(const struct comp_driver *drv, struct module_ext_init_data *ext_data,
441+
struct ipc_config_process *spec)
442+
{
443+
return 0;
444+
}
445+
#endif
435446
int module_adapter_init_data(struct comp_dev *dev,
436447
struct module_config *dst,
437448
const struct comp_ipc_config *config,

0 commit comments

Comments
 (0)