Skip to content

Commit 83af640

Browse files
author
Jyri Sarha
committed
ASoC: SOF: ipc4-topology: Add payload to pipeline create messages
Start adding payloads to pipeline create messages. The payload contains information for payload specific memory configuration. All non DP module instances within the same pipeline share the same memory attributes and access the same resources. The new logic sums interim, lifetime, and shared heap memory 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 idea is to pass common memory configuration for all the Low Latency modules in the pipeline in pipeline create message payload. The Data Processing module instances will still have an individual memory configuration in struct sof_ipc4_mod_init_ext_dp_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 <jyri.sarha@linux.intel.com>
1 parent 9d06525 commit 83af640

File tree

1 file changed

+111
-10
lines changed

1 file changed

+111
-10
lines changed

sound/soc/sof/ipc4-topology.c

Lines changed: 111 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,26 @@ sof_ipc4_update_resource_usage(struct snd_sof_dev *sdev, struct snd_sof_widget *
13361336
pipeline = pipe_widget->private;
13371337
pipeline->mem_usage += total;
13381338

1339+
/*
1340+
* If this is not a Data Processing module instance, add the
1341+
* required heap sizes to the sum of all modules instance's
1342+
* belonging to same pipeline and find the maximum stack
1343+
* requirement of all module instances belonging to the same
1344+
* pipeline.
1345+
*/
1346+
if (swidget->comp_domain != SOF_COMP_DOMAIN_DP) {
1347+
pipe_widget->interim_bytes += swidget->interim_bytes;
1348+
pipe_widget->lifetime_bytes += swidget->lifetime_bytes;
1349+
pipe_widget->shared_bytes += swidget->shared_bytes;
1350+
if (pipe_widget->stack_bytes < swidget->stack_bytes)
1351+
pipe_widget->stack_bytes = swidget->stack_bytes;
1352+
1353+
dev_dbg(sdev->dev, "%s mem reqs to %s lifetime %u heap %u shared %u stack %u",
1354+
swidget->widget->name, pipe_widget->widget->name,
1355+
pipe_widget->lifetime_bytes, pipe_widget->interim_bytes,
1356+
pipe_widget->shared_bytes, pipe_widget->stack_bytes);
1357+
}
1358+
13391359
/* Update base_config->cpc from the module manifest */
13401360
sof_ipc4_update_cpc_from_manifest(sdev, fw_module, base_config);
13411361

@@ -3044,11 +3064,11 @@ static int sof_ipc4_control_setup(struct snd_sof_dev *sdev, struct snd_sof_contr
30443064
return 0;
30453065
}
30463066

3047-
static int sof_ipc4_widget_setup_msg_payload(struct snd_sof_dev *sdev,
3048-
struct snd_sof_widget *swidget,
3049-
struct sof_ipc4_msg *msg,
3050-
void *ipc_data, u32 ipc_size,
3051-
void **new_data)
3067+
static int sof_ipc4_widget_mod_init_msg_payload(struct snd_sof_dev *sdev,
3068+
struct snd_sof_widget *swidget,
3069+
struct sof_ipc4_msg *msg,
3070+
void *ipc_data, u32 ipc_size,
3071+
void **new_data)
30523072
{
30533073
struct sof_ipc4_mod_init_ext_dp_memory_data *dp_mem_data;
30543074
struct sof_ipc4_module_init_ext_init *ext_init;
@@ -3072,13 +3092,14 @@ static int sof_ipc4_widget_setup_msg_payload(struct snd_sof_dev *sdev,
30723092

30733093
/* Add ext_init first and set objects array flag to 1 */
30743094
ext_init = (struct sof_ipc4_module_init_ext_init *)payload;
3075-
ext_init->word0 |= SOF_IPC4_MOD_INIT_EXT_OBJ_ARRAY_MASK;
30763095
ext_pos = DIV_ROUND_UP(sizeof(*ext_init), sizeof(u32));
30773096

30783097
/* Add object array objects after ext_init */
30793098

30803099
/* Add memory_data if comp_domain indicates DP */
30813100
if (swidget->comp_domain == SOF_COMP_DOMAIN_DP) {
3101+
ext_init->word0 |= SOF_IPC4_MOD_INIT_EXT_OBJ_ARRAY_MASK;
3102+
30823103
hdr = (struct sof_ipc4_module_init_ext_object *)&payload[ext_pos];
30833104
hdr->header = SOF_IPC4_MOD_INIT_EXT_OBJ_LAST_MASK |
30843105
SOF_IPC4_MOD_INIT_EXT_OBJ_ID(SOF_IPC4_MOD_INIT_DATA_ID_DP_DATA) |
@@ -3088,10 +3109,9 @@ static int sof_ipc4_widget_setup_msg_payload(struct snd_sof_dev *sdev,
30883109
dp_mem_data = (struct sof_ipc4_mod_init_ext_dp_memory_data *)&payload[ext_pos];
30893110
dp_mem_data->domain_id = swidget->domain_id;
30903111
dp_mem_data->stack_bytes = swidget->stack_bytes;
3091-
dp_mem_data->heap_bytes = swidget->heap_bytes;
3112+
dp_mem_data->heap_bytes = swidget->interim_bytes;
30923113
ext_pos += DIV_ROUND_UP(sizeof(*dp_mem_data), sizeof(u32));
30933114
}
3094-
30953115
/* If another array object is added, remember clear previous OBJ_LAST bit */
30963116

30973117
/* Calculate final size and check that it fits to max payload size */
@@ -3115,6 +3135,76 @@ static int sof_ipc4_widget_setup_msg_payload(struct snd_sof_dev *sdev,
31153135
return new_size;
31163136
}
31173137

3138+
static void sof_ipc4_widget_pipe_ext_obj_memory_data(struct snd_sof_dev *sdev,
3139+
struct snd_sof_widget *swidget,
3140+
u32 *payload, u32 *ext_pos,
3141+
struct sof_ipc4_glb_pipe_ext_object **hdr)
3142+
{
3143+
struct sof_ipc4_glb_pipe_ext_obj_memory_data *mem_data;
3144+
3145+
*hdr = (struct sof_ipc4_glb_pipe_ext_object *)&payload[*ext_pos];
3146+
(*hdr)->header =
3147+
SOF_IPC4_GLB_PIPE_EXT_OBJ_ID(SOF_IPC4_GLB_PIPE_DATA_ID_MEM_DATA) |
3148+
SOF_IPC4_GLB_PIPE_EXT_OBJ_WORDS(DIV_ROUND_UP(sizeof(*mem_data),
3149+
sizeof(u32)));
3150+
*ext_pos += DIV_ROUND_UP(sizeof(**hdr), sizeof(u32));
3151+
mem_data = (struct sof_ipc4_glb_pipe_ext_obj_memory_data *)&payload[*ext_pos];
3152+
mem_data->domain_id = swidget->domain_id;
3153+
mem_data->stack_bytes = swidget->stack_bytes;
3154+
mem_data->interim_heap_bytes = swidget->interim_bytes;
3155+
mem_data->lifetime_heap_bytes = swidget->lifetime_bytes;
3156+
mem_data->shared_bytes = swidget->shared_bytes;
3157+
*ext_pos += DIV_ROUND_UP(sizeof(*mem_data), sizeof(u32));
3158+
3159+
dev_dbg(sdev->dev,
3160+
"%s; domain_id %u stack %u interim %u lifetime %u shared %u bytes",
3161+
swidget->widget->name, mem_data->domain_id, mem_data->stack_bytes,
3162+
mem_data->interim_heap_bytes, mem_data->lifetime_heap_bytes,
3163+
mem_data->shared_bytes);
3164+
}
3165+
3166+
static int sof_ipc4_widget_pipe_create_msg_payload(struct snd_sof_dev *sdev,
3167+
struct snd_sof_widget *swidget,
3168+
struct sof_ipc4_msg *msg,
3169+
void **new_data)
3170+
{
3171+
struct sof_ipc4_glb_pipe_payload *payload_hdr;
3172+
struct sof_ipc4_glb_pipe_ext_object *hdr = NULL;
3173+
u32 *payload;
3174+
u32 ext_pos;
3175+
3176+
payload = kzalloc(sdev->ipc->max_payload_size, GFP_KERNEL);
3177+
if (!payload)
3178+
return -ENOMEM;
3179+
3180+
/* Add sof_ipc4_glb_pipe_payload and set array bit to 1 */
3181+
payload_hdr = (struct sof_ipc4_glb_pipe_payload *)payload;
3182+
payload_hdr->word0 |= SOF_IPC4_GLB_PIPE_EXT_OBJ_ARRAY_MASK;
3183+
ext_pos = DIV_ROUND_UP(sizeof(*payload_hdr), sizeof(u32));
3184+
3185+
sof_ipc4_widget_pipe_ext_obj_memory_data(sdev, swidget, payload, &ext_pos, &hdr);
3186+
/* Add following array objects here */
3187+
3188+
if (!hdr) {
3189+
kfree(payload);
3190+
return 0;
3191+
}
3192+
/* Mark end of object array */
3193+
hdr->header |= SOF_IPC4_GLB_PIPE_EXT_OBJ_LAST_MASK;
3194+
3195+
/* Put total payload size in words to the payload header */
3196+
payload_hdr->word0 |= SOF_IPC4_GLB_PIPE_PAYLOAD_WORDS(ext_pos);
3197+
*new_data = payload;
3198+
3199+
/* Update msg extension bits according to the payload changes */
3200+
msg->extension |= SOF_IPC4_GLB_PIPE_PAYLOAD_MASK;
3201+
3202+
dev_dbg(sdev->dev, "%s: payload word0 %#x", swidget->widget->name,
3203+
payload_hdr->word0);
3204+
3205+
return ext_pos * sizeof(int32_t);
3206+
}
3207+
31183208
static int sof_ipc4_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
31193209
{
31203210
struct snd_sof_widget *pipe_widget = swidget->spipe->pipe_widget;
@@ -3268,8 +3358,8 @@ static int sof_ipc4_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget
32683358
swidget->widget->name, swidget->pipeline_id, module_id,
32693359
swidget->instance_id, swidget->core);
32703360

3271-
ret = sof_ipc4_widget_setup_msg_payload(sdev, swidget, msg, ipc_data, ipc_size,
3272-
&ext_data);
3361+
ret = sof_ipc4_widget_mod_init_msg_payload(sdev, swidget, msg, ipc_data, ipc_size,
3362+
&ext_data);
32733363
if (ret < 0)
32743364
goto fail;
32753365

@@ -3281,6 +3371,17 @@ static int sof_ipc4_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget
32813371
dev_dbg(sdev->dev, "Create pipeline %s (pipe %d) - instance %d, core %d\n",
32823372
swidget->widget->name, swidget->pipeline_id,
32833373
swidget->instance_id, swidget->core);
3374+
3375+
msg->extension &= ~SOF_IPC4_GLB_PIPE_PAYLOAD_MASK;
3376+
ret = sof_ipc4_widget_pipe_create_msg_payload(sdev, swidget, msg,
3377+
&ext_data);
3378+
if (ret < 0)
3379+
goto fail;
3380+
3381+
if (ret > 0) {
3382+
ipc_size = ret;
3383+
ipc_data = ext_data;
3384+
}
32843385
}
32853386

32863387
msg->data_size = ipc_size;

0 commit comments

Comments
 (0)