@@ -111,42 +111,65 @@ __cold static inline unsigned char *ipc4_get_comp_new_data(void)
111111}
112112#endif
113113
114- /* Only called from ipc4_init_module_instance(), which is __cold */
115- __cold struct comp_dev * comp_new_ipc4 ( const struct ipc4_module_init_instance * module_init )
114+ __cold static int ipc4_comp_new_config ( struct comp_ipc_config * ipc_config ,
115+ const struct ipc4_module_init_instance * module_init )
116116{
117- struct comp_ipc_config ipc_config ;
118- const struct comp_driver * drv ;
119- struct comp_dev * dev ;
120- uint32_t comp_id ;
121- unsigned char * data ;
117+ uint32_t comp_id = IPC4_COMP_ID (module_init -> primary .r .module_id ,
118+ module_init -> primary .r .instance_id );
122119
123120 assert_can_be_cold ();
124121
125- comp_id = IPC4_COMP_ID (module_init -> primary .r .module_id ,
126- module_init -> primary .r .instance_id );
127-
128122 if (ipc4_get_comp_dev (comp_id )) {
129123 tr_err (& ipc_tr , "comp 0x%x exists" , comp_id );
130- return NULL ;
124+ return - EEXIST ;
131125 }
132126
133127 if (module_init -> extension .r .core_id >= CONFIG_CORE_COUNT ) {
134128 tr_err (& ipc_tr , "ipc: comp->core = %u" , (uint32_t )module_init -> extension .r .core_id );
135- return NULL ;
129+ return - EINVAL ;
136130 }
137131
138- memset (& ipc_config , 0 , sizeof (ipc_config ));
139- ipc_config . id = comp_id ;
140- ipc_config . pipeline_id = module_init -> extension .r .ppl_instance_id ;
141- ipc_config . core = module_init -> extension .r .core_id ;
142- ipc_config . ipc_config_size = module_init -> extension .r .param_block_size * sizeof (uint32_t );
143- ipc_config . ipc_extended_init = module_init -> extension .r .extended_init ;
144- if (ipc_config . ipc_config_size > MAILBOX_HOSTBOX_SIZE ) {
132+ memset (ipc_config , 0 , sizeof (* ipc_config ));
133+ ipc_config -> id = comp_id ;
134+ ipc_config -> pipeline_id = module_init -> extension .r .ppl_instance_id ;
135+ ipc_config -> core = module_init -> extension .r .core_id ;
136+ ipc_config -> ipc_config_size = module_init -> extension .r .param_block_size * sizeof (uint32_t );
137+ ipc_config -> ipc_extended_init = module_init -> extension .r .extended_init ;
138+ if (ipc_config -> ipc_config_size > MAILBOX_HOSTBOX_SIZE ) {
145139 tr_err (& ipc_tr , "IPC payload size %u too big for the message window" ,
146- ipc_config .ipc_config_size );
147- return NULL ;
140+ ipc_config -> ipc_config_size );
141+ return - ENOSPC ;
142+ }
143+
144+ if (!module_init -> extension .r .proc_domain ) {
145+ ipc_config -> proc_domain = COMP_PROCESSING_DOMAIN_LL ;
146+ } else if (IS_ENABLED (CONFIG_ZEPHYR_DP_SCHEDULER )) {
147+ ipc_config -> proc_domain = COMP_PROCESSING_DOMAIN_DP ;
148+ } else {
149+ tr_err (& ipc_tr , "ipc: DP scheduling is disabled, cannot create comp 0x%x" , comp_id );
150+ return - EINVAL ;
148151 }
149152
153+ return 0 ;
154+ }
155+
156+ /* Only called from ipc4_init_module_instance(), which is __cold */
157+ __cold struct comp_dev * comp_new_ipc4 (const struct ipc4_module_init_instance * module_init )
158+ {
159+ struct comp_ipc_config ipc_config ;
160+ const struct comp_driver * drv ;
161+ struct comp_dev * dev ;
162+ unsigned char * data ;
163+ uint32_t comp_id = IPC4_COMP_ID (module_init -> primary .r .module_id ,
164+ module_init -> primary .r .instance_id );
165+
166+ assert_can_be_cold ();
167+
168+ int ret = ipc4_comp_new_config (& ipc_config , module_init );
169+
170+ if (ret < 0 )
171+ return NULL ;
172+
150173 /* Reject a module naming a non-existent parent pipeline: otherwise
151174 * dev->pipeline stays NULL and a later init path (e.g. the copier)
152175 * dereferences it. IPC4_INVALID_PIPELINE_ID is exempt - it marks base FW
@@ -160,6 +183,7 @@ __cold struct comp_dev *comp_new_ipc4(const struct ipc4_module_init_instance *mo
160183 (uint32_t )ipc_config .pipeline_id );
161184 return NULL ;
162185 }
186+
163187#ifdef CONFIG_DCACHE_LINE_SIZE
164188 if (!IS_ENABLED (CONFIG_LIBRARY ))
165189 sys_cache_data_invd_range ((__sparse_force void __sparse_cache * )
@@ -177,17 +201,6 @@ __cold struct comp_dev *comp_new_ipc4(const struct ipc4_module_init_instance *mo
177201 if (!drv )
178202 return NULL ;
179203
180- if (!module_init -> extension .r .proc_domain ) {
181- ipc_config .proc_domain = COMP_PROCESSING_DOMAIN_LL ;
182- } else if (IS_ENABLED (CONFIG_ZEPHYR_DP_SCHEDULER )) {
183- ipc_config .proc_domain = COMP_PROCESSING_DOMAIN_DP ;
184- } else {
185- tr_err (& ipc_tr ,
186- "ipc: DP scheduling is disabled, cannot create comp 0x%x" ,
187- comp_id );
188- return NULL ;
189- }
190-
191204 if (drv -> type == SOF_COMP_MODULE_ADAPTER ) {
192205 const struct ipc_config_process spec = {
193206 .data = data ,
@@ -240,43 +253,19 @@ __cold struct comp_dev *comp_new_ipc4_user(struct ipc4_message_request *ipc4,
240253 struct ipc4_module_init_instance module_init ;
241254 struct comp_ipc_config ipc_config ;
242255 struct comp_dev * dev ;
243- uint32_t comp_id ;
244256 unsigned char * data ;
245- int ret ;
246257
247258 assert_can_be_cold ();
248259
249- ret = memcpy_s (& module_init , sizeof (module_init ), ipc4 , sizeof (* ipc4 ));
250- if (ret < 0 )
251- return NULL ;
252-
253- comp_id = IPC4_COMP_ID (module_init .primary .r .module_id ,
254- module_init .primary .r .instance_id );
260+ int ret = memcpy_s (& module_init , sizeof (module_init ), ipc4 , sizeof (* ipc4 ));
255261
256- if (ipc4_get_comp_dev (comp_id )) {
257- tr_err (& ipc_tr , "comp 0x%x exists" , comp_id );
262+ if (ret < 0 )
258263 return NULL ;
259- }
260264
261- if (module_init .extension .r .core_id >= CONFIG_CORE_COUNT ) {
262- tr_err (& ipc_tr , "ipc: comp->core = %u" ,
263- (uint32_t )module_init .extension .r .core_id );
265+ ret = ipc4_comp_new_config (& ipc_config , & module_init );
266+ if (ret < 0 )
264267 return NULL ;
265- }
266268
267- memset (& ipc_config , 0 , sizeof (ipc_config ));
268- ipc_config .id = comp_id ;
269- ipc_config .pipeline_id = module_init .extension .r .ppl_instance_id ;
270- ipc_config .core = module_init .extension .r .core_id ;
271- ipc_config .ipc_config_size =
272- module_init .extension .r .param_block_size * sizeof (uint32_t );
273- ipc_config .ipc_extended_init = module_init .extension .r .extended_init ;
274- if (ipc_config .ipc_config_size > MAILBOX_HOSTBOX_SIZE ) {
275- tr_err (& ipc_tr ,
276- "IPC payload size %u too big for the message window" ,
277- ipc_config .ipc_config_size );
278- return NULL ;
279- }
280269#ifdef CONFIG_DCACHE_LINE_SIZE
281270 if (!IS_ENABLED (CONFIG_LIBRARY ))
282271 sys_cache_data_invd_range (
@@ -286,15 +275,6 @@ __cold struct comp_dev *comp_new_ipc4_user(struct ipc4_message_request *ipc4,
286275#endif
287276 data = ipc4_get_comp_new_data ();
288277
289- if (!module_init .extension .r .proc_domain ) {
290- ipc_config .proc_domain = COMP_PROCESSING_DOMAIN_LL ;
291- } else if (IS_ENABLED (CONFIG_ZEPHYR_DP_SCHEDULER )) {
292- ipc_config .proc_domain = COMP_PROCESSING_DOMAIN_DP ;
293- } else {
294- tr_err (& ipc_tr , "ipc: DP scheduling is disabled, cannot create comp 0x%x" , comp_id );
295- return NULL ;
296- }
297-
298278 if (drv -> type == SOF_COMP_MODULE_ADAPTER ) {
299279 const struct ipc_config_process spec = {
300280 .data = data ,
0 commit comments