@@ -3102,28 +3102,41 @@ static int sof_ipc4_control_setup(struct snd_sof_dev *sdev, struct snd_sof_contr
31023102 return 0 ;
31033103}
31043104
3105+ static void sof_ipc4_add_init_ext_dp_memory_data (struct snd_sof_dev * sdev ,
3106+ struct snd_sof_widget * swidget ,
3107+ u32 * payload , u32 * ext_pos ,
3108+ struct sof_ipc4_module_init_ext_object * * hdr )
3109+ {
3110+ /* Add memory_data if comp_domain indicates DP */
3111+ if (swidget -> comp_domain == SOF_COMP_DOMAIN_DP ) {
3112+ struct sof_ipc4_mod_init_ext_dp_memory_data * dp_mem_data ;
3113+
3114+ * hdr = (struct sof_ipc4_module_init_ext_object * )& payload [* ext_pos ];
3115+ (* hdr )-> header =
3116+ SOF_IPC4_MOD_INIT_EXT_OBJ_ID (SOF_IPC4_MOD_INIT_DATA_ID_DP_DATA ) |
3117+ SOF_IPC4_MOD_INIT_EXT_OBJ_WORDS (DIV_ROUND_UP (sizeof (* dp_mem_data ),
3118+ sizeof (u32 )));
3119+ * ext_pos += DIV_ROUND_UP (sizeof (* * hdr ), sizeof (u32 ));
3120+ dp_mem_data = (struct sof_ipc4_mod_init_ext_dp_memory_data * )& payload [* ext_pos ];
3121+ dp_mem_data -> domain_id = swidget -> domain_id ;
3122+ dp_mem_data -> stack_bytes = swidget -> stack_bytes ;
3123+ dp_mem_data -> heap_bytes = swidget -> heap_bytes ;
3124+ * ext_pos += DIV_ROUND_UP (sizeof (* dp_mem_data ), sizeof (u32 ));
3125+ }
3126+ }
3127+
31053128static int sof_ipc4_widget_mod_init_msg_payload (struct snd_sof_dev * sdev ,
31063129 struct snd_sof_widget * swidget ,
31073130 struct sof_ipc4_msg * msg ,
31083131 void * ipc_data , u32 ipc_size ,
31093132 void * * new_data )
31103133{
3111- struct sof_ipc4_mod_init_ext_dp_memory_data * dp_mem_data ;
31123134 struct sof_ipc4_module_init_ext_init * ext_init ;
3113- struct sof_ipc4_module_init_ext_object * hdr ;
3135+ struct sof_ipc4_module_init_ext_object * hdr = NULL ;
31143136 int new_size ;
31153137 u32 * payload ;
31163138 u32 ext_pos ;
31173139
3118- /* For the moment the only reason for adding init_ext_init payload is DP
3119- * memory data. If both stack and heap size are 0 (= use default), then
3120- * there is no need for init_ext_init payload.
3121- */
3122- if (swidget -> comp_domain != SOF_COMP_DOMAIN_DP ) {
3123- msg -> extension &= ~SOF_IPC4_MOD_EXT_EXTENDED_INIT_MASK ;
3124- return 0 ;
3125- }
3126-
31273140 payload = kzalloc (sdev -> ipc -> max_payload_size , GFP_KERNEL );
31283141 if (!payload )
31293142 return - ENOMEM ;
@@ -3134,23 +3147,22 @@ static int sof_ipc4_widget_mod_init_msg_payload(struct snd_sof_dev *sdev,
31343147
31353148 /* Add object array objects after ext_init */
31363149
3137- /* Add memory_data if comp_domain indicates DP */
3138- if (swidget -> comp_domain == SOF_COMP_DOMAIN_DP ) {
3139- ext_init -> word0 |= SOF_IPC4_MOD_INIT_EXT_OBJ_ARRAY_MASK ;
3150+ sof_ipc4_add_init_ext_dp_memory_data (sdev , swidget , payload , & ext_pos , & hdr );
31403151
3141- hdr = (struct sof_ipc4_module_init_ext_object * )& payload [ext_pos ];
3142- hdr -> header = SOF_IPC4_MOD_INIT_EXT_OBJ_LAST_MASK |
3143- SOF_IPC4_MOD_INIT_EXT_OBJ_ID (SOF_IPC4_MOD_INIT_DATA_ID_DP_DATA ) |
3144- SOF_IPC4_MOD_INIT_EXT_OBJ_WORDS (DIV_ROUND_UP (sizeof (* dp_mem_data ),
3145- sizeof (u32 )));
3146- ext_pos += DIV_ROUND_UP (sizeof (* hdr ), sizeof (u32 ));
3147- dp_mem_data = (struct sof_ipc4_mod_init_ext_dp_memory_data * )& payload [ext_pos ];
3148- dp_mem_data -> domain_id = swidget -> domain_id ;
3149- dp_mem_data -> stack_bytes = swidget -> stack_bytes ;
3150- dp_mem_data -> heap_bytes = swidget -> heap_bytes ;
3151- ext_pos += DIV_ROUND_UP (sizeof (* dp_mem_data ), sizeof (u32 ));
3152+ /* Add following object array items here */
3153+
3154+ if (!hdr ) {
3155+ /*
3156+ * NOTE: Remove this early bail out, when struct
3157+ * sof_ipc4_module_init_ext_init alone has some
3158+ * function.
3159+ */
3160+ kfree (payload );
3161+ return 0 ;
31523162 }
3153- /* If another array object is added, remember clear previous OBJ_LAST bit */
3163+
3164+ ext_init -> word0 |= SOF_IPC4_MOD_INIT_EXT_OBJ_ARRAY_MASK ;
3165+ hdr -> header |= SOF_IPC4_MOD_INIT_EXT_OBJ_LAST_MASK ;
31543166
31553167 /* Calculate final size and check that it fits to max payload size */
31563168 new_size = ext_pos * sizeof (u32 ) + ipc_size ;
0 commit comments