Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7727c82

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 <[email protected]>
1 parent 1c33ef6 commit 7727c82

File tree

4 files changed

+77
-46
lines changed

4 files changed

+77
-46
lines changed

src/audio/module_adapter/module_adapter.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static void module_adapter_mem_free(struct processing_module *mod)
9898
* \brief Create a module adapter component.
9999
* \param[in] drv - component driver pointer.
100100
* \param[in] config - component ipc descriptor pointer.
101-
* \param[in] spec - passdowned data from driver.
101+
* \param[in] const_spec - passdowned data from driver.
102102
* \param[in] mod_priv - Pointer to private data for processing module.
103103
*
104104
* \return: a pointer to newly created module adapter component on success. NULL on error.
@@ -107,12 +107,21 @@ static void module_adapter_mem_free(struct processing_module *mod)
107107
* the create method.
108108
*/
109109
struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
110-
const struct comp_ipc_config *config, const void *spec,
110+
const struct comp_ipc_config *config,
111+
const void *const_spec,
111112
void *mod_priv)
112113
{
113114
int ret;
114115
struct module_config *dst;
115116
const struct module_interface *const interface = drv->adapter_ops;
117+
/*
118+
* The const_spec is only couple of stack frames up in the stack so
119+
* casting would be an option too, and it would save couple of
120+
* words from stack,
121+
*/
122+
struct ipc_config_process spec =
123+
*((struct ipc_config_process *) const_spec);
124+
struct module_ext_init_data ext_data = { 0 };
116125

117126
comp_cl_dbg(drv, "start");
118127

@@ -121,21 +130,27 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
121130
(size_t)drv, (size_t)config);
122131
return NULL;
123132
}
133+
if (config->ipc_extended_init) {
134+
ret = module_ext_init_decode(drv, &ext_data, &spec);
135+
if (ret != 0)
136+
return NULL;
137+
}
124138

125139
struct processing_module *mod = module_adapter_mem_alloc(drv, config);
126140

127141
if (!mod)
128142
return NULL;
129143

130144
dst = &mod->priv.cfg;
145+
dst->ext_data = &ext_data;
131146

132147
module_set_private_data(mod, mod_priv);
133148

134149
struct comp_dev *dev = mod->dev;
135150

136151
list_init(&mod->raw_data_buffers_list);
137152

138-
ret = module_adapter_init_data(dev, dst, config, spec);
153+
ret = module_adapter_init_data(dev, dst, config, &spec);
139154
if (ret) {
140155
comp_err(dev, "%d: module init data failed",
141156
ret);
@@ -207,6 +222,7 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
207222
component_set_nearest_period_frames(dev, params.rate);
208223
#endif
209224

225+
dst->ext_data = NULL;
210226
comp_dbg(dev, "done");
211227
return dev;
212228

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
@@ -411,6 +411,17 @@ void module_update_buffer_position(struct input_stream_buffer *input_buffers,
411411
struct output_stream_buffer *output_buffers,
412412
uint32_t frames);
413413

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

0 commit comments

Comments
 (0)