Skip to content

Commit 2ef7ab4

Browse files
author
Jyri Sarha
committed
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 <jyri.sarha@linux.intel.com>
1 parent c843171 commit 2ef7ab4

File tree

4 files changed

+81
-47
lines changed

4 files changed

+81
-47
lines changed

src/audio/module_adapter/module_adapter.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ static void module_adapter_mem_free(struct processing_module *mod)
158158
* \brief Create a module adapter component.
159159
* \param[in] drv - component driver pointer.
160160
* \param[in] config - component ipc descriptor pointer.
161-
* \param[in] spec - passdowned data from driver.
161+
* \param[in] const_spec - passdowned data from driver.
162162
* \param[in] mod_priv - Pointer to private data for processing module.
163163
*
164164
* \return: a pointer to newly created module adapter component on success. NULL on error.
@@ -167,12 +167,16 @@ static void module_adapter_mem_free(struct processing_module *mod)
167167
* the create method.
168168
*/
169169
struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
170-
const struct comp_ipc_config *config, const void *spec,
171-
void *mod_priv, struct userspace_context *user_ctx)
170+
const struct comp_ipc_config *config,
171+
const void *const_spec, void *mod_priv,
172+
struct userspace_context *user_ctx)
172173
{
173174
int ret;
174175
struct module_config *dst;
175176
const struct module_interface *const interface = drv->adapter_ops;
177+
struct ipc_config_process spec =
178+
*((const struct ipc_config_process *) const_spec);
179+
struct module_ext_init_data ext_data = { 0 };
176180

177181
comp_cl_dbg(drv, "start");
178182

@@ -181,6 +185,11 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
181185
(size_t)drv, (size_t)config);
182186
return NULL;
183187
}
188+
if (config->ipc_extended_init) {
189+
ret = module_ext_init_decode(drv, &ext_data, &spec);
190+
if (ret != 0)
191+
return NULL;
192+
}
184193

185194
struct processing_module *mod = module_adapter_mem_alloc(drv, config);
186195

@@ -204,7 +213,15 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
204213
#endif /* CONFIG_USERSPACE */
205214

206215
dst = &mod->priv.cfg;
207-
ret = module_adapter_init_data(dev, dst, config, spec);
216+
/*
217+
* NOTE: dst->ext_data points to stack variable and contains
218+
* pointers to IPC payload mailbox, so its only valid in
219+
* functions that called from this function. This why
220+
* the pointer is set NULL before the this function
221+
* exits.
222+
*/
223+
dst->ext_data = &ext_data;
224+
ret = module_adapter_init_data(dev, dst, config, &spec);
208225
if (ret) {
209226
comp_err(dev, "%d: module init data failed",
210227
ret);
@@ -270,6 +287,7 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
270287
component_set_nearest_period_frames(dev, params.rate);
271288
#endif
272289

290+
dst->ext_data = NULL;
273291
comp_dbg(dev, "done");
274292
return dev;
275293

@@ -279,6 +297,7 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
279297
schedule_task_free(dev->task);
280298
#endif
281299
module_adapter_mem_free(mod);
300+
dst->ext_data = NULL;
282301

283302
return NULL;
284303
}

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: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@
2323
#define module_get_private_data(mod) ((mod)->priv.private)
2424
#define module_set_private_data(mod, data) ((mod)->priv.private = data)
2525

26+
#if CONFIG_IPC_MAJOR_4
27+
/**
28+
* \struct module_ext_init_data
29+
* \brief Container for found ext init object pointers
30+
* This struct contains pointers that point to IPC payload directly. The
31+
* module should store what it needs in its init() callback as the data
32+
* is not valid after that.
33+
*/
34+
struct ipc4_module_init_ext_obj_dp_data;
35+
struct module_ext_init_data {
36+
const struct ipc4_module_init_ext_obj_dp_data *dp_data;
37+
};
38+
#endif
39+
2640
/**
2741
* \struct module_config
2842
* \brief Module config container, used for both config types.
@@ -38,11 +52,7 @@ struct module_config {
3852
uint8_t nb_output_pins;
3953
struct ipc4_input_pin_format *input_pins;
4054
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 */
55+
struct module_ext_init_data *ext_data; /**< IPC payload pointers, NULL after init() */
4656
#endif
4757
};
4858

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,17 @@ void module_update_buffer_position(struct input_stream_buffer *input_buffers,
413413
struct output_stream_buffer *output_buffers,
414414
uint32_t frames);
415415

416+
#if CONFIG_IPC_MAJOR_4
417+
int module_ext_init_decode(const struct comp_driver *drv, struct module_ext_init_data *ext_data,
418+
struct ipc_config_process *spec);
419+
#else
420+
static inline
421+
int module_ext_init_decode(const struct comp_driver *drv, struct module_ext_init_data *ext_data,
422+
struct ipc_config_process *spec)
423+
{
424+
return 0;
425+
}
426+
#endif
416427
int module_adapter_init_data(struct comp_dev *dev,
417428
struct module_config *dst,
418429
const struct comp_ipc_config *config,

0 commit comments

Comments
 (0)