Skip to content

Commit c9df7c7

Browse files
author
Jyri Sarha
committed
ASoC: SOF: ipc4-topology: Changes to mod init mem data message logic
Start adding payloads pipeline create messages and to all module init messages, not only to Data Processing module init messages. The idea is that all non DP module instances within the same pipeline share the same memory attributes and access the same heap. The new logic sums heap requirements together and picks the highest stack requirement of all module instances belonging to a pipeline. These pipeline specific attributes are sent as struct sof_ipc4_glb_pipe_payload payload in pipeline's create message. The non Data Processing module instance's setup messages also have their struct sof_ipc4_mod_init_ext_memory_data payloads. The idea is to pass common memory memory configuration for all the Low Latency modules in the pipeline in pipeline create message payload. The modules instances will only get a reference to pipeline specific config. The Data Processing module instances will still have an individual memory configuration in struct sof_ipc4_mod_init_ext_memory_data payloads as before. In their payload everything is as it was before, all attributes are copied directly from their topology attributes. Signed-off-by: Jyri Sarha <[email protected]>
1 parent 9bff797 commit c9df7c7

File tree

1 file changed

+100
-26
lines changed

1 file changed

+100
-26
lines changed

sound/soc/sof/ipc4-topology.c

Lines changed: 100 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,25 @@ sof_ipc4_update_resource_usage(struct snd_sof_dev *sdev, struct snd_sof_widget *
13081308
pipeline = pipe_widget->private;
13091309
pipeline->mem_usage += total;
13101310

1311+
/*
1312+
* If this is not a Data Processing module instance, add the
1313+
* required heap sizes to the sum of all modules instance's
1314+
* belonging to same pipeline and find the maximun stack
1315+
* requirement of all module instances belonging to the same
1316+
* pipeline. Non DP module instances should use pipeline_id as
1317+
* their domain_id.
1318+
*/
1319+
if (swidget->comp_domain != SOF_COMP_DOMAIN_DP) {
1320+
pipe_widget->heap_bytes += swidget->heap_bytes;
1321+
if (pipe_widget->stack_bytes < swidget->stack_bytes)
1322+
pipe_widget->stack_bytes = swidget->stack_bytes;
1323+
1324+
if (swidget->domain_id != 0)
1325+
dev_warn(sdev->dev, "%s is not DP, but domain_id %u was set in topology",
1326+
swidget->widget->name, swidget->domain_id);
1327+
swidget->domain_id = swidget->pipeline_id;
1328+
}
1329+
13111330
/* Update base_config->cpc from the module manifest */
13121331
sof_ipc4_update_cpc_from_manifest(sdev, fw_module, base_config);
13131332

@@ -2951,11 +2970,11 @@ static int sof_ipc4_control_setup(struct snd_sof_dev *sdev, struct snd_sof_contr
29512970
return 0;
29522971
}
29532972

2954-
static int sof_ipc4_widget_setup_msg_payload(struct snd_sof_dev *sdev,
2955-
struct snd_sof_widget *swidget,
2956-
struct sof_ipc4_msg *msg,
2957-
void *ipc_data, u32 ipc_size,
2958-
void **new_data)
2973+
static int sof_ipc4_widget_mod_init_msg_payload(struct snd_sof_dev *sdev,
2974+
struct snd_sof_widget *swidget,
2975+
struct sof_ipc4_msg *msg,
2976+
void *ipc_data, u32 ipc_size,
2977+
void **new_data)
29592978
{
29602979
struct sof_ipc4_mod_init_ext_memory_data *mem_data;
29612980
struct sof_ipc4_module_init_ext_init *ext_init;
@@ -2964,15 +2983,6 @@ static int sof_ipc4_widget_setup_msg_payload(struct snd_sof_dev *sdev,
29642983
u32 *payload;
29652984
u32 ext_pos;
29662985

2967-
/* For the moment the only reason for adding init_ext_init payload is DP
2968-
* memory data. If both stack and heap size are 0 (= use default), then
2969-
* there is no need for init_ext_init payload.
2970-
*/
2971-
if (swidget->comp_domain != SOF_COMP_DOMAIN_DP) {
2972-
msg->extension &= ~SOF_IPC4_MOD_EXT_EXTENDED_INIT_MASK;
2973-
return 0;
2974-
}
2975-
29762986
payload = kzalloc(sdev->ipc->max_payload_size, GFP_KERNEL);
29772987
if (!payload)
29782988
return -ENOMEM;
@@ -2984,20 +2994,24 @@ static int sof_ipc4_widget_setup_msg_payload(struct snd_sof_dev *sdev,
29842994

29852995
/* Add object array objects after ext_init */
29862996

2987-
/* Add memory_data if comp_domain indicates DP */
2988-
if (swidget->comp_domain == SOF_COMP_DOMAIN_DP) {
2989-
hdr = (struct sof_ipc4_module_init_ext_object *)&payload[ext_pos];
2990-
hdr->header = SOF_IPC4_MOD_INIT_EXT_OBJ_LAST_MASK |
2991-
SOF_IPC4_MOD_INIT_EXT_OBJ_ID(SOF_IPC4_MOD_INIT_DATA_ID_MEM_DATA) |
2992-
SOF_IPC4_MOD_INIT_EXT_OBJ_WORDS(DIV_ROUND_UP(sizeof(*mem_data),
2997+
hdr = (struct sof_ipc4_module_init_ext_object *)&payload[ext_pos];
2998+
hdr->header = SOF_IPC4_MOD_INIT_EXT_OBJ_LAST_MASK |
2999+
SOF_IPC4_MOD_INIT_EXT_OBJ_ID(SOF_IPC4_MOD_INIT_DATA_ID_MEM_DATA) |
3000+
SOF_IPC4_MOD_INIT_EXT_OBJ_WORDS(DIV_ROUND_UP(sizeof(*mem_data),
29933001
sizeof(u32)));
2994-
ext_pos += DIV_ROUND_UP(sizeof(*hdr), sizeof(u32));
2995-
mem_data = (struct sof_ipc4_mod_init_ext_memory_data *)&payload[ext_pos];
2996-
mem_data->domain_id = swidget->domain_id;
3002+
ext_pos += DIV_ROUND_UP(sizeof(*hdr), sizeof(u32));
3003+
mem_data = (struct sof_ipc4_mod_init_ext_memory_data *)&payload[ext_pos];
3004+
mem_data->domain_id = swidget->domain_id;
3005+
/*
3006+
* Set stack- and heap sizes only if this is a Data Processing
3007+
* module instance. All Low Latency module instances within
3008+
* same pipeline share the same memory properties.
3009+
*/
3010+
if (swidget->comp_domain == SOF_COMP_DOMAIN_DP) {
29973011
mem_data->stack_bytes = swidget->stack_bytes;
29983012
mem_data->heap_bytes = swidget->heap_bytes;
2999-
ext_pos += DIV_ROUND_UP(sizeof(*mem_data), sizeof(u32));
30003013
}
3014+
ext_pos += DIV_ROUND_UP(sizeof(*mem_data), sizeof(u32));
30013015

30023016
/* If another array object is added, remember clear previous OBJ_LAST bit */
30033017

@@ -3022,6 +3036,55 @@ static int sof_ipc4_widget_setup_msg_payload(struct snd_sof_dev *sdev,
30223036
return new_size;
30233037
}
30243038

3039+
static int sof_ipc4_widget_pipe_create_msg_payload(struct snd_sof_dev *sdev,
3040+
struct snd_sof_widget *swidget,
3041+
struct sof_ipc4_msg *msg,
3042+
void **new_data)
3043+
{
3044+
struct sof_ipc4_glb_pipe_ext_obj_memory_data *mem_data;
3045+
struct sof_ipc4_glb_pipe_payload *payload_hdr;
3046+
struct sof_ipc4_glb_pipe_ext_object *obj;
3047+
u32 *payload;
3048+
u32 ext_pos;
3049+
3050+
payload = kzalloc(sdev->ipc->max_payload_size, GFP_KERNEL);
3051+
if (!payload)
3052+
return -ENOMEM;
3053+
3054+
/* Add sof_ipc4_glb_pipe_payload and set array bit to 1 */
3055+
payload_hdr = (struct sof_ipc4_glb_pipe_payload *)payload;
3056+
payload_hdr->word0 |= SOF_IPC4_GLB_PIPE_EXT_OBJ_ARRAY_MASK;
3057+
ext_pos = DIV_ROUND_UP(sizeof(*payload_hdr), sizeof(u32));
3058+
3059+
obj = (struct sof_ipc4_glb_pipe_ext_object *)&payload[ext_pos];
3060+
/* Add object array objects after payload_hdr */
3061+
obj->header = SOF_IPC4_GLB_PIPE_EXT_OBJ_LAST_MASK |
3062+
SOF_IPC4_GLB_PIPE_EXT_OBJ_ID(SOF_IPC4_GLB_PIPE_DATA_ID_MEM_DATA) |
3063+
SOF_IPC4_GLB_PIPE_EXT_OBJ_WORDS(DIV_ROUND_UP(sizeof(*mem_data),
3064+
sizeof(u32)));
3065+
ext_pos += DIV_ROUND_UP(sizeof(*obj), sizeof(u32));
3066+
mem_data = (struct sof_ipc4_glb_pipe_ext_obj_memory_data *)&payload[ext_pos];
3067+
mem_data->domain_id = swidget->domain_id;
3068+
mem_data->stack_bytes = swidget->stack_bytes;
3069+
mem_data->heap_bytes = swidget->heap_bytes;
3070+
ext_pos += DIV_ROUND_UP(sizeof(*mem_data), sizeof(u32));
3071+
3072+
/* If another array object is added, remember clear previous OBJ_LAST bit */
3073+
3074+
/* Put total payload size in words to the payload header */
3075+
payload_hdr->word0 |= SOF_IPC4_GLB_PIPE_PAYLOAD_WORDS(ext_pos);
3076+
*new_data = payload;
3077+
3078+
/* Update msg extension bits according to the payload changes */
3079+
msg->extension |= SOF_IPC4_GLB_PIPE_PAYLOAD_MASK;
3080+
3081+
dev_dbg(sdev->dev, "payload word0 %#x domain_id %u stack_bytes %u heap_bytes %u",
3082+
payload_hdr->word0, mem_data->domain_id, mem_data->stack_bytes,
3083+
mem_data->heap_bytes);
3084+
3085+
return ext_pos * sizeof(int32_t);
3086+
}
3087+
30253088
static int sof_ipc4_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
30263089
{
30273090
struct snd_sof_widget *pipe_widget = swidget->spipe->pipe_widget;
@@ -3175,8 +3238,8 @@ static int sof_ipc4_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget
31753238
swidget->widget->name, swidget->pipeline_id, module_id,
31763239
swidget->instance_id, swidget->core);
31773240

3178-
ret = sof_ipc4_widget_setup_msg_payload(sdev, swidget, msg, ipc_data, ipc_size,
3179-
&ext_data);
3241+
ret = sof_ipc4_widget_mod_init_msg_payload(sdev, swidget, msg, ipc_data, ipc_size,
3242+
&ext_data);
31803243
if (ret < 0)
31813244
goto fail;
31823245

@@ -3188,6 +3251,17 @@ static int sof_ipc4_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget
31883251
dev_dbg(sdev->dev, "Create pipeline %s (pipe %d) - instance %d, core %d\n",
31893252
swidget->widget->name, swidget->pipeline_id,
31903253
swidget->instance_id, swidget->core);
3254+
3255+
msg->extension &= ~SOF_IPC4_GLB_PIPE_PAYLOAD_MASK;
3256+
ret = sof_ipc4_widget_pipe_create_msg_payload(sdev, swidget, msg,
3257+
&ext_data);
3258+
if (ret < 0)
3259+
goto fail;
3260+
3261+
if (ret > 0) {
3262+
ipc_size = ret;
3263+
ipc_data = ext_data;
3264+
}
31913265
}
31923266

31933267
msg->data_size = ipc_size;

0 commit comments

Comments
 (0)