Skip to content

Commit e7846fa

Browse files
Jyri Sarhalgirdwood
authored andcommitted
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 5aff799 commit e7846fa

1 file changed

Lines changed: 78 additions & 1 deletion

File tree

src/audio/module_adapter/module_adapter_ipc4.c

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,76 @@
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)
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+
if (*size < sizeof(ext_init)) {
38+
comp_err(dev, "Size too small for ext init %u < %u",
39+
*size, sizeof(ext_init));
40+
return NULL;
41+
}
42+
/* TODO: Handle ext_init->gna_used and ext_init->rtos_domain here */
43+
/* Get the first obj struct right after ext_init struct */
44+
obj = (const struct ipc4_module_init_ext_object *)(ext_init + 1);
45+
while (!last_object) {
46+
const struct ipc4_module_init_ext_object *next_obj;
47+
48+
/* 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 > %u",
51+
(unsigned char *)(obj + 1) - data, *size);
52+
return NULL;
53+
}
54+
/* Calculate would be next object position and check if current object fits */
55+
next_obj = (const struct ipc4_module_init_ext_object *)
56+
(((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 > %u",
59+
(unsigned char *)obj - data, *size);
60+
return NULL;
61+
}
62+
switch (obj->object_id) {
63+
case IPC4_MOD_INIT_DATA_ID_DP_DATA:
64+
{
65+
/* Get dp_data struct that follows the obj struct */
66+
const struct ipc4_module_init_ext_obj_dp_data *dp_data =
67+
(const struct ipc4_module_init_ext_obj_dp_data *)(obj + 1);
68+
69+
if (obj->object_words * sizeof(uint32_t) < sizeof(*dp_data)) {
70+
comp_err(dev, "dp_data object too small %u < %u",
71+
obj->object_words * sizeof(uint32_t), sizeof(*dp_data));
72+
return NULL;
73+
}
74+
dst->domain_id = dp_data->domain_id;
75+
dst->stack_bytes = dp_data->stack_bytes;
76+
dst->heap_bytes = dp_data->heap_bytes;
77+
comp_info(dev, "init_ext_obj_dp_data domain %u stack %u heap %u",
78+
dp_data->domain_id, dp_data->stack_bytes, dp_data->heap_bytes);
79+
break;
80+
}
81+
default:
82+
comp_info(dev, "Unknown ext init object id %u of %u words",
83+
obj->object_id, obj->object_words);
84+
}
85+
/* Read the last object flag from obj header */
86+
last_object = obj->last_object;
87+
/* Move to next object */
88+
obj = next_obj;
89+
}
90+
91+
/* Remove decoded ext_init payload from the size */
92+
*size -= (unsigned char *) obj - data;
93+
94+
/* return remaining payload */
95+
return (const struct ipc4_base_module_extended_cfg *)obj;
96+
}
97+
2898
/*
2999
* \module adapter data initialize.
30100
* \param[in] dev - device.
@@ -39,11 +109,18 @@ int module_adapter_init_data(struct comp_dev *dev,
39109
const struct comp_ipc_config *config,
40110
const void *spec)
41111
{
112+
const struct ipc4_base_module_extended_cfg *cfg;
42113
const struct ipc_config_process *args = spec;
43-
const struct ipc4_base_module_extended_cfg *cfg = (void *)args->data;
44114
size_t cfgsz = args->size;
45115

46116
assert(dev->drv->type == SOF_COMP_MODULE_ADAPTER);
117+
if (config->ipc_extended_init)
118+
cfg = module_ext_init_decode(dev, dst, args->data, &cfgsz);
119+
else
120+
cfg = (const struct ipc4_base_module_extended_cfg *)args->data;
121+
122+
if (cfg == NULL)
123+
return -EINVAL;
47124
if (cfgsz < sizeof(cfg->base_cfg))
48125
return -EINVAL;
49126

0 commit comments

Comments
 (0)