@@ -1310,6 +1310,25 @@ sof_ipc4_update_resource_usage(struct snd_sof_dev *sdev, struct snd_sof_widget *
13101310 pipeline = pipe_widget -> private ;
13111311 pipeline -> mem_usage += total ;
13121312
1313+ /*
1314+ * If this is not a Data Processing module instance, add the
1315+ * required heap sizes to the sum of all modules instance's
1316+ * belonging to same pipeline and find the maximun stack
1317+ * requirement of all module instances belonging to the same
1318+ * pipeline.
1319+ */
1320+ if (swidget -> comp_domain != SOF_COMP_DOMAIN_DP ) {
1321+ pipe_widget -> heap_bytes += swidget -> heap_bytes ;
1322+ pipe_widget -> static_bytes += swidget -> static_bytes ;
1323+ if (pipe_widget -> stack_bytes < swidget -> stack_bytes )
1324+ pipe_widget -> stack_bytes = swidget -> stack_bytes ;
1325+
1326+ dev_dbg (sdev -> dev , "%s mem reqs to %s heap %u stack %u static %u" ,
1327+ swidget -> widget -> name , pipe_widget -> widget -> name ,
1328+ pipe_widget -> heap_bytes , pipe_widget -> stack_bytes ,
1329+ pipe_widget -> static_bytes );
1330+ }
1331+
13131332 /* Update base_config->cpc from the module manifest */
13141333 sof_ipc4_update_cpc_from_manifest (sdev , fw_module , base_config );
13151334
@@ -2953,11 +2972,11 @@ static int sof_ipc4_control_setup(struct snd_sof_dev *sdev, struct snd_sof_contr
29532972 return 0 ;
29542973}
29552974
2956- static int sof_ipc4_widget_setup_msg_payload (struct snd_sof_dev * sdev ,
2957- struct snd_sof_widget * swidget ,
2958- struct sof_ipc4_msg * msg ,
2959- void * ipc_data , u32 ipc_size ,
2960- void * * new_data )
2975+ static int sof_ipc4_widget_mod_init_msg_payload (struct snd_sof_dev * sdev ,
2976+ struct snd_sof_widget * swidget ,
2977+ struct sof_ipc4_msg * msg ,
2978+ void * ipc_data , u32 ipc_size ,
2979+ void * * new_data )
29612980{
29622981 struct sof_ipc4_mod_init_ext_dp_memory_data * dp_mem_data ;
29632982 struct sof_ipc4_module_init_ext_init * ext_init ;
@@ -2981,13 +3000,14 @@ static int sof_ipc4_widget_setup_msg_payload(struct snd_sof_dev *sdev,
29813000
29823001 /* Add ext_init first and set objects array flag to 1 */
29833002 ext_init = (struct sof_ipc4_module_init_ext_init * )payload ;
2984- ext_init -> word0 |= SOF_IPC4_MOD_INIT_EXT_OBJ_ARRAY_MASK ;
29853003 ext_pos = DIV_ROUND_UP (sizeof (* ext_init ), sizeof (u32 ));
29863004
29873005 /* Add object array objects after ext_init */
29883006
29893007 /* Add memory_data if comp_domain indicates DP */
29903008 if (swidget -> comp_domain == SOF_COMP_DOMAIN_DP ) {
3009+ ext_init -> word0 |= SOF_IPC4_MOD_INIT_EXT_OBJ_ARRAY_MASK ;
3010+
29913011 hdr = (struct sof_ipc4_module_init_ext_object * )& payload [ext_pos ];
29923012 hdr -> header = SOF_IPC4_MOD_INIT_EXT_OBJ_LAST_MASK |
29933013 SOF_IPC4_MOD_INIT_EXT_OBJ_ID (SOF_IPC4_MOD_INIT_DATA_ID_DP_DATA ) |
@@ -3000,7 +3020,6 @@ static int sof_ipc4_widget_setup_msg_payload(struct snd_sof_dev *sdev,
30003020 dp_mem_data -> heap_bytes = swidget -> heap_bytes ;
30013021 ext_pos += DIV_ROUND_UP (sizeof (* dp_mem_data ), sizeof (u32 ));
30023022 }
3003-
30043023 /* If another array object is added, remember clear previous OBJ_LAST bit */
30053024
30063025 /* Calculate final size and check that it fits to max payload size */
@@ -3024,6 +3043,56 @@ static int sof_ipc4_widget_setup_msg_payload(struct snd_sof_dev *sdev,
30243043 return new_size ;
30253044}
30263045
3046+ static int sof_ipc4_widget_pipe_create_msg_payload (struct snd_sof_dev * sdev ,
3047+ struct snd_sof_widget * swidget ,
3048+ struct sof_ipc4_msg * msg ,
3049+ void * * new_data )
3050+ {
3051+ struct sof_ipc4_glb_pipe_ext_obj_memory_data * mem_data ;
3052+ struct sof_ipc4_glb_pipe_payload * payload_hdr ;
3053+ struct sof_ipc4_glb_pipe_ext_object * obj ;
3054+ u32 * payload ;
3055+ u32 ext_pos ;
3056+
3057+ payload = kzalloc (sdev -> ipc -> max_payload_size , GFP_KERNEL );
3058+ if (!payload )
3059+ return - ENOMEM ;
3060+
3061+ /* Add sof_ipc4_glb_pipe_payload and set array bit to 1 */
3062+ payload_hdr = (struct sof_ipc4_glb_pipe_payload * )payload ;
3063+ payload_hdr -> word0 |= SOF_IPC4_GLB_PIPE_EXT_OBJ_ARRAY_MASK ;
3064+ ext_pos = DIV_ROUND_UP (sizeof (* payload_hdr ), sizeof (u32 ));
3065+
3066+ obj = (struct sof_ipc4_glb_pipe_ext_object * )& payload [ext_pos ];
3067+ /* Add object array objects after payload_hdr */
3068+ obj -> header = SOF_IPC4_GLB_PIPE_EXT_OBJ_LAST_MASK |
3069+ SOF_IPC4_GLB_PIPE_EXT_OBJ_ID (SOF_IPC4_GLB_PIPE_DATA_ID_MEM_DATA ) |
3070+ SOF_IPC4_GLB_PIPE_EXT_OBJ_WORDS (DIV_ROUND_UP (sizeof (* mem_data ),
3071+ sizeof (u32 )));
3072+ ext_pos += DIV_ROUND_UP (sizeof (* obj ), sizeof (u32 ));
3073+ mem_data = (struct sof_ipc4_glb_pipe_ext_obj_memory_data * )& payload [ext_pos ];
3074+ mem_data -> domain_id = swidget -> domain_id ;
3075+ mem_data -> stack_bytes = swidget -> stack_bytes ;
3076+ mem_data -> heap_bytes = swidget -> heap_bytes ;
3077+ mem_data -> static_bytes = swidget -> static_bytes ;
3078+ ext_pos += DIV_ROUND_UP (sizeof (* mem_data ), sizeof (u32 ));
3079+
3080+ /* If another array object is added, remember clear previous OBJ_LAST bit */
3081+
3082+ /* Put total payload size in words to the payload header */
3083+ payload_hdr -> word0 |= SOF_IPC4_GLB_PIPE_PAYLOAD_WORDS (ext_pos );
3084+ * new_data = payload ;
3085+
3086+ /* Update msg extension bits according to the payload changes */
3087+ msg -> extension |= SOF_IPC4_GLB_PIPE_PAYLOAD_MASK ;
3088+
3089+ dev_dbg (sdev -> dev , "payload word0 %#x domain_id %u stack_bytes %u heap_bytes %u" ,
3090+ payload_hdr -> word0 , mem_data -> domain_id , mem_data -> stack_bytes ,
3091+ mem_data -> heap_bytes );
3092+
3093+ return ext_pos * sizeof (int32_t );
3094+ }
3095+
30273096static int sof_ipc4_widget_setup (struct snd_sof_dev * sdev , struct snd_sof_widget * swidget )
30283097{
30293098 struct snd_sof_widget * pipe_widget = swidget -> spipe -> pipe_widget ;
@@ -3177,8 +3246,8 @@ static int sof_ipc4_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget
31773246 swidget -> widget -> name , swidget -> pipeline_id , module_id ,
31783247 swidget -> instance_id , swidget -> core );
31793248
3180- ret = sof_ipc4_widget_setup_msg_payload (sdev , swidget , msg , ipc_data , ipc_size ,
3181- & ext_data );
3249+ ret = sof_ipc4_widget_mod_init_msg_payload (sdev , swidget , msg , ipc_data , ipc_size ,
3250+ & ext_data );
31823251 if (ret < 0 )
31833252 goto fail ;
31843253
@@ -3190,6 +3259,17 @@ static int sof_ipc4_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget
31903259 dev_dbg (sdev -> dev , "Create pipeline %s (pipe %d) - instance %d, core %d\n" ,
31913260 swidget -> widget -> name , swidget -> pipeline_id ,
31923261 swidget -> instance_id , swidget -> core );
3262+
3263+ msg -> extension &= ~SOF_IPC4_GLB_PIPE_PAYLOAD_MASK ;
3264+ ret = sof_ipc4_widget_pipe_create_msg_payload (sdev , swidget , msg ,
3265+ & ext_data );
3266+ if (ret < 0 )
3267+ goto fail ;
3268+
3269+ if (ret > 0 ) {
3270+ ipc_size = ret ;
3271+ ipc_data = ext_data ;
3272+ }
31933273 }
31943274
31953275 msg -> data_size = ipc_size ;
0 commit comments