@@ -1317,6 +1317,26 @@ sof_ipc4_update_resource_usage(struct snd_sof_dev *sdev, struct snd_sof_widget *
13171317 pipeline = pipe_widget -> private ;
13181318 pipeline -> mem_usage += total ;
13191319
1320+ /*
1321+ * If this is not a Data Processing module instance, add the
1322+ * required heap sizes to the sum of all modules instance's
1323+ * belonging to same pipeline and find the maximun stack
1324+ * requirement of all module instances belonging to the same
1325+ * pipeline.
1326+ */
1327+ if (swidget -> comp_domain != SOF_COMP_DOMAIN_DP ) {
1328+ pipe_widget -> heap_bytes += swidget -> heap_bytes ;
1329+ pipe_widget -> lifetime_bytes += swidget -> lifetime_bytes ;
1330+ pipe_widget -> shared_bytes += swidget -> shared_bytes ;
1331+ if (pipe_widget -> stack_bytes < swidget -> stack_bytes )
1332+ pipe_widget -> stack_bytes = swidget -> stack_bytes ;
1333+
1334+ dev_dbg (sdev -> dev , "%s mem reqs to %s lifetime %u heap %u shared %u stack %u" ,
1335+ swidget -> widget -> name , pipe_widget -> widget -> name ,
1336+ pipe_widget -> lifetime_bytes , pipe_widget -> heap_bytes ,
1337+ pipe_widget -> shared_bytes , pipe_widget -> stack_bytes );
1338+ }
1339+
13201340 /* Update base_config->cpc from the module manifest */
13211341 sof_ipc4_update_cpc_from_manifest (sdev , fw_module , base_config );
13221342
@@ -2997,11 +3017,11 @@ static int sof_ipc4_control_setup(struct snd_sof_dev *sdev, struct snd_sof_contr
29973017 return 0 ;
29983018}
29993019
3000- static int sof_ipc4_widget_setup_msg_payload (struct snd_sof_dev * sdev ,
3001- struct snd_sof_widget * swidget ,
3002- struct sof_ipc4_msg * msg ,
3003- void * ipc_data , u32 ipc_size ,
3004- void * * new_data )
3020+ static int sof_ipc4_widget_mod_init_msg_payload (struct snd_sof_dev * sdev ,
3021+ struct snd_sof_widget * swidget ,
3022+ struct sof_ipc4_msg * msg ,
3023+ void * ipc_data , u32 ipc_size ,
3024+ void * * new_data )
30053025{
30063026 struct sof_ipc4_mod_init_ext_dp_memory_data * dp_mem_data ;
30073027 struct sof_ipc4_module_init_ext_init * ext_init ;
@@ -3025,13 +3045,14 @@ static int sof_ipc4_widget_setup_msg_payload(struct snd_sof_dev *sdev,
30253045
30263046 /* Add ext_init first and set objects array flag to 1 */
30273047 ext_init = (struct sof_ipc4_module_init_ext_init * )payload ;
3028- ext_init -> word0 |= SOF_IPC4_MOD_INIT_EXT_OBJ_ARRAY_MASK ;
30293048 ext_pos = DIV_ROUND_UP (sizeof (* ext_init ), sizeof (u32 ));
30303049
30313050 /* Add object array objects after ext_init */
30323051
30333052 /* Add memory_data if comp_domain indicates DP */
30343053 if (swidget -> comp_domain == SOF_COMP_DOMAIN_DP ) {
3054+ ext_init -> word0 |= SOF_IPC4_MOD_INIT_EXT_OBJ_ARRAY_MASK ;
3055+
30353056 hdr = (struct sof_ipc4_module_init_ext_object * )& payload [ext_pos ];
30363057 hdr -> header = SOF_IPC4_MOD_INIT_EXT_OBJ_LAST_MASK |
30373058 SOF_IPC4_MOD_INIT_EXT_OBJ_ID (SOF_IPC4_MOD_INIT_DATA_ID_DP_DATA ) |
@@ -3044,7 +3065,6 @@ static int sof_ipc4_widget_setup_msg_payload(struct snd_sof_dev *sdev,
30443065 dp_mem_data -> heap_bytes = swidget -> heap_bytes ;
30453066 ext_pos += DIV_ROUND_UP (sizeof (* dp_mem_data ), sizeof (u32 ));
30463067 }
3047-
30483068 /* If another array object is added, remember clear previous OBJ_LAST bit */
30493069
30503070 /* Calculate final size and check that it fits to max payload size */
@@ -3068,6 +3088,57 @@ static int sof_ipc4_widget_setup_msg_payload(struct snd_sof_dev *sdev,
30683088 return new_size ;
30693089}
30703090
3091+ static int sof_ipc4_widget_pipe_create_msg_payload (struct snd_sof_dev * sdev ,
3092+ struct snd_sof_widget * swidget ,
3093+ struct sof_ipc4_msg * msg ,
3094+ void * * new_data )
3095+ {
3096+ struct sof_ipc4_glb_pipe_ext_obj_memory_data * mem_data ;
3097+ struct sof_ipc4_glb_pipe_payload * payload_hdr ;
3098+ struct sof_ipc4_glb_pipe_ext_object * obj ;
3099+ u32 * payload ;
3100+ u32 ext_pos ;
3101+
3102+ payload = kzalloc (sdev -> ipc -> max_payload_size , GFP_KERNEL );
3103+ if (!payload )
3104+ return - ENOMEM ;
3105+
3106+ /* Add sof_ipc4_glb_pipe_payload and set array bit to 1 */
3107+ payload_hdr = (struct sof_ipc4_glb_pipe_payload * )payload ;
3108+ payload_hdr -> word0 |= SOF_IPC4_GLB_PIPE_EXT_OBJ_ARRAY_MASK ;
3109+ ext_pos = DIV_ROUND_UP (sizeof (* payload_hdr ), sizeof (u32 ));
3110+
3111+ obj = (struct sof_ipc4_glb_pipe_ext_object * )& payload [ext_pos ];
3112+ /* Add object array objects after payload_hdr */
3113+ obj -> header = SOF_IPC4_GLB_PIPE_EXT_OBJ_LAST_MASK |
3114+ SOF_IPC4_GLB_PIPE_EXT_OBJ_ID (SOF_IPC4_GLB_PIPE_DATA_ID_MEM_DATA ) |
3115+ SOF_IPC4_GLB_PIPE_EXT_OBJ_WORDS (DIV_ROUND_UP (sizeof (* mem_data ),
3116+ sizeof (u32 )));
3117+ ext_pos += DIV_ROUND_UP (sizeof (* obj ), sizeof (u32 ));
3118+ mem_data = (struct sof_ipc4_glb_pipe_ext_obj_memory_data * )& payload [ext_pos ];
3119+ mem_data -> domain_id = swidget -> domain_id ;
3120+ mem_data -> stack_bytes = swidget -> stack_bytes ;
3121+ mem_data -> heap_bytes = swidget -> heap_bytes ;
3122+ mem_data -> lifetime_bytes = swidget -> lifetime_bytes ;
3123+ mem_data -> shared_bytes = swidget -> shared_bytes ;
3124+ ext_pos += DIV_ROUND_UP (sizeof (* mem_data ), sizeof (u32 ));
3125+
3126+ /* If another array object is added, remember clear previous OBJ_LAST bit */
3127+
3128+ /* Put total payload size in words to the payload header */
3129+ payload_hdr -> word0 |= SOF_IPC4_GLB_PIPE_PAYLOAD_WORDS (ext_pos );
3130+ * new_data = payload ;
3131+
3132+ /* Update msg extension bits according to the payload changes */
3133+ msg -> extension |= SOF_IPC4_GLB_PIPE_PAYLOAD_MASK ;
3134+
3135+ dev_dbg (sdev -> dev , "payload word0 %#x domain_id %u stack_bytes %u heap_bytes %u" ,
3136+ payload_hdr -> word0 , mem_data -> domain_id , mem_data -> stack_bytes ,
3137+ mem_data -> heap_bytes );
3138+
3139+ return ext_pos * sizeof (int32_t );
3140+ }
3141+
30713142static int sof_ipc4_widget_setup (struct snd_sof_dev * sdev , struct snd_sof_widget * swidget )
30723143{
30733144 struct snd_sof_widget * pipe_widget = swidget -> spipe -> pipe_widget ;
@@ -3221,8 +3292,8 @@ static int sof_ipc4_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget
32213292 swidget -> widget -> name , swidget -> pipeline_id , module_id ,
32223293 swidget -> instance_id , swidget -> core );
32233294
3224- ret = sof_ipc4_widget_setup_msg_payload (sdev , swidget , msg , ipc_data , ipc_size ,
3225- & ext_data );
3295+ ret = sof_ipc4_widget_mod_init_msg_payload (sdev , swidget , msg , ipc_data , ipc_size ,
3296+ & ext_data );
32263297 if (ret < 0 )
32273298 goto fail ;
32283299
@@ -3234,6 +3305,17 @@ static int sof_ipc4_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget
32343305 dev_dbg (sdev -> dev , "Create pipeline %s (pipe %d) - instance %d, core %d\n" ,
32353306 swidget -> widget -> name , swidget -> pipeline_id ,
32363307 swidget -> instance_id , swidget -> core );
3308+
3309+ msg -> extension &= ~SOF_IPC4_GLB_PIPE_PAYLOAD_MASK ;
3310+ ret = sof_ipc4_widget_pipe_create_msg_payload (sdev , swidget , msg ,
3311+ & ext_data );
3312+ if (ret < 0 )
3313+ goto fail ;
3314+
3315+ if (ret > 0 ) {
3316+ ipc_size = ret ;
3317+ ipc_data = ext_data ;
3318+ }
32373319 }
32383320
32393321 msg -> data_size = ipc_size ;
0 commit comments