Skip to content

Commit 0a3144d

Browse files
author
Jyri Sarha
committed
component: module_adapter: Add module_ext_init_decode() and call it
Add module_ext_init_decode() for struct ipc4_module_init_ext_init payload decoding. The function goes decodes ext_init and following object array payload. The only recognized object so far is struct sof_ipc4_mod_init_ext_dp_memory_data. The possibly found stack and heap size requirements are copied to struct module_config, but no other functionality is added. This first version ignores rtos_domain and gna_used flags, and fails if their associated data is found in the message payload. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent 23c69b2 commit 0a3144d

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

src/audio/module_adapter/module_adapter_ipc4.c

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,54 @@
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, uint32_t *size)
31+
{
32+
const struct ipc4_module_init_ext_init *ext_init =
33+
(const struct ipc4_module_init_ext_init *)data;
34+
bool last_object = !ext_init->data_obj_array;
35+
const struct ipc4_module_init_ext_object *obj;
36+
37+
/* TODO: Handle ext_init->gna_used and ext_init->rtos_domain here */
38+
/* Get the first obj struct right after ext_init struct */
39+
obj = (const struct ipc4_module_init_ext_object *)(ext_init + 1);
40+
while (!last_object) {
41+
switch (obj->object_id) {
42+
case IPC4_MOD_INIT_DATA_ID_DP_DATA:
43+
/* Get dp_data struct that follows the obj struct */
44+
const struct ipc4_module_init_ext_obj_dp_data *dp_data =
45+
(const struct ipc4_module_init_ext_obj_dp_data *)(obj + 1);
46+
47+
dst->domain_id = dp_data->domain_id;
48+
dst->stack_bytes = dp_data->stack_bytes;
49+
dst->heap_bytes = dp_data->heap_bytes;
50+
comp_info(dev, "init_ext_obj_dp_data domain %u stack %u heap %u",
51+
dp_data->domain_id, dp_data->stack_bytes, dp_data->heap_bytes);
52+
break;
53+
default:
54+
comp_info(dev, "Unknown ext init object id %u of %u words",
55+
obj->object_id, obj->object_words);
56+
}
57+
/* Read the last object flag from obj header */
58+
last_object = obj->last_object;
59+
/* Move obj struct + object_words forward to next obj struct */
60+
obj = (const struct ipc4_module_init_ext_object *)
61+
(((uint32_t *) (obj + 1)) + obj->object_words);
62+
if ((unsigned char *)obj - data > *size) {
63+
comp_err(dev, "ext init object array overflow, %u > %u",
64+
(unsigned char *)obj - data, *size);
65+
return NULL;
66+
}
67+
}
68+
69+
/* Remove decoded ext_init payload from the size */
70+
*size -= (unsigned char *) obj - data;
71+
72+
/* return remaining payload */
73+
return (const struct ipc4_base_module_extended_cfg *)obj;
74+
}
75+
2876
/*
2977
* \module adapter data initialize.
3078
* \param[in] dev - device.
@@ -39,11 +87,18 @@ int module_adapter_init_data(struct comp_dev *dev,
3987
const struct comp_ipc_config *config,
4088
const void *spec)
4189
{
90+
const struct ipc4_base_module_extended_cfg *cfg;
4291
const struct ipc_config_process *args = spec;
43-
const struct ipc4_base_module_extended_cfg *cfg = (void *)args->data;
4492
size_t cfgsz = args->size;
4593

4694
assert(dev->drv->type == SOF_COMP_MODULE_ADAPTER);
95+
if (config->ipc_extended_init)
96+
cfg = module_ext_init_decode(dev, dst, args->data, &cfgsz);
97+
else
98+
cfg = (const struct ipc4_base_module_extended_cfg *)args->data;
99+
100+
if (cfg == NULL)
101+
return -EINVAL;
47102
if (cfgsz < sizeof(cfg->base_cfg))
48103
return -EINVAL;
49104

0 commit comments

Comments
 (0)