1212#include <kernel/header.h>
1313#include <tplg_parser/tokens.h>
1414#include <tplg_parser/topology.h>
15+ #include <module/ipc4/base-config.h>
1516#include <stdio.h>
1617#include <stdlib.h>
1718
@@ -330,10 +331,90 @@ int tb_match_audio_format(struct testbench_prm *tp, struct tplg_comp_info *comp_
330331 return 0 ;
331332}
332333
334+ static int tb_set_pin_formats (struct tplg_comp_info * comp_info ,
335+ struct ipc4_base_module_cfg * base_cfg ,
336+ struct ipc4_base_module_cfg_ext * base_cfg_ext ,
337+ enum tb_pin_type pin_type )
338+ {
339+ struct sof_ipc4_pin_format * formats_array ;
340+ struct sof_ipc4_pin_format * pin_format_item ;
341+ struct sof_ipc4_pin_format * pin_format ;
342+ struct sof_ipc4_pin_format * base_cfg_ext_pin_formats =
343+ (struct sof_ipc4_pin_format * )base_cfg_ext -> pin_formats ;
344+ int format_list_count ;
345+ int num_pins ;
346+ int i , j ;
347+ int pin_format_offset = 0 ;
348+
349+ switch (pin_type ) {
350+ case TB_PIN_TYPE_INPUT :
351+ num_pins = base_cfg_ext -> nb_input_pins ;
352+ formats_array = comp_info -> available_fmt .input_pin_fmts ;
353+ format_list_count = comp_info -> available_fmt .num_input_formats ;
354+ break ;
355+ case TB_PIN_TYPE_OUTPUT :
356+ num_pins = base_cfg_ext -> nb_output_pins ;
357+ pin_format_offset = base_cfg_ext -> nb_input_pins ;
358+ formats_array = comp_info -> available_fmt .output_pin_fmts ;
359+ format_list_count = comp_info -> available_fmt .num_output_formats ;
360+ break ;
361+ default :
362+ fprintf (stderr , "Error: Illegal pin type %d for %s\n" , pin_type , comp_info -> name );
363+ }
364+
365+ for (i = pin_format_offset ; i < num_pins + pin_format_offset ; i ++ ) {
366+ pin_format = & base_cfg_ext_pin_formats [i ];
367+
368+ if (i == pin_format_offset ) {
369+ if (pin_type == TB_PIN_TYPE_INPUT ) {
370+ pin_format -> buffer_size = base_cfg -> ibs ;
371+ /* Note: Copy "struct ipc4_audio_format" to
372+ * "struct sof_ipc4_pin_format". They are same
373+ * but separate definitions. The last member fmt_cfg
374+ * is defined with bitfields for channels_count, valid_bit_depth,
375+ * s_type, reservedin ipc4_audio_format.
376+ */
377+ memcpy (& pin_format -> audio_fmt , & base_cfg -> audio_fmt ,
378+ sizeof (pin_format -> audio_fmt ));
379+ } else {
380+ pin_format -> buffer_size = base_cfg -> obs ;
381+ /* TODO: Using workaround, need to find out how to do this. This
382+ * is copied kernel function sof_ipc4_process_set_pin_formats()
383+ * from process->output_format. It's set in
384+ * sof_ipc4_prepare_process_module().
385+ */
386+ memcpy (& pin_format -> audio_fmt , & base_cfg -> audio_fmt ,
387+ sizeof (pin_format -> audio_fmt ));
388+ }
389+ continue ;
390+ }
391+
392+ for (j = 0 ; j < format_list_count ; j ++ ) {
393+ pin_format_item = & formats_array [j ];
394+ if (pin_format_item -> pin_index == i - pin_format_offset ) {
395+ * pin_format = * pin_format_item ;
396+ break ;
397+ }
398+ }
399+
400+ if (j == format_list_count ) {
401+ fprintf (stderr , "%s pin %d format not found for %s\n" ,
402+ (pin_type == TB_PIN_TYPE_INPUT ) ? "input" : "output" ,
403+ i - pin_format_offset , comp_info -> name );
404+ return - EINVAL ;
405+ }
406+ }
407+
408+ return 0 ;
409+ }
410+
333411int tb_set_up_widget_base_config (struct testbench_prm * tp , struct tplg_comp_info * comp_info )
334412{
335413 char * config_name = tp -> config [0 ].name ;
414+ struct ipc4_base_module_cfg * base_cfg ;
415+ struct ipc4_base_module_cfg_ext * base_cfg_ext ;
336416 struct tb_config * config ;
417+ struct tplg_pins_info * pins = & comp_info -> pins_info ;
337418 bool config_found = false;
338419 int ret , i ;
339420
@@ -359,6 +440,21 @@ int tb_set_up_widget_base_config(struct testbench_prm *tp, struct tplg_comp_info
359440 /* copy the basecfg into the ipc payload */
360441 memcpy (comp_info -> ipc_payload , & comp_info -> basecfg , sizeof (struct ipc4_base_module_cfg ));
361442
443+ /* Copy ext config for process type */
444+ if (comp_info -> module_id == TB_PROCESS_MODULE_ID ) {
445+ base_cfg = comp_info -> ipc_payload ;
446+ base_cfg_ext = comp_info -> ipc_payload + sizeof (* base_cfg );
447+ base_cfg_ext -> nb_input_pins = pins -> num_input_pins ;
448+ base_cfg_ext -> nb_output_pins = pins -> num_output_pins ;
449+ ret = tb_set_pin_formats (comp_info , base_cfg , base_cfg_ext , TB_PIN_TYPE_INPUT );
450+ if (ret )
451+ return ret ;
452+
453+ ret = tb_set_pin_formats (comp_info , base_cfg , base_cfg_ext , TB_PIN_TYPE_OUTPUT );
454+ if (ret )
455+ return ret ;
456+ }
457+
362458 return 0 ;
363459}
364460
@@ -824,6 +920,9 @@ int tb_new_process(struct testbench_prm *tp)
824920 struct tplg_context * ctx = & tp -> tplg ;
825921 struct tplg_comp_info * comp_info = ctx -> current_comp_info ;
826922 struct snd_soc_tplg_ctl_hdr * tplg_ctl ;
923+ struct tplg_pins_info * pins = & comp_info -> pins_info ;
924+ size_t ext_size ;
925+ size_t uuid_offset ;
827926 int ret ;
828927
829928 ret = tplg_parse_widget_audio_formats (ctx );
@@ -834,8 +933,14 @@ int tb_new_process(struct testbench_prm *tp)
834933 if (!tplg_ctl )
835934 return - ENOMEM ;
836935
936+ /* Ext config size */
937+ ext_size = ipc4_calc_base_module_cfg_ext_size (pins -> num_input_pins , pins -> num_output_pins );
938+
837939 /* use base config variant with uuid */
838- comp_info -> ipc_size = sizeof (struct ipc4_base_module_cfg ) + sizeof (struct sof_uuid );
940+ comp_info -> ipc_size = sizeof (struct ipc4_base_module_cfg );
941+ comp_info -> ipc_size += ext_size ;
942+ uuid_offset = comp_info -> ipc_size ;
943+ comp_info -> ipc_size += sizeof (struct sof_uuid );
839944 comp_info -> ipc_payload = calloc (comp_info -> ipc_size , 1 );
840945 if (!comp_info -> ipc_payload ) {
841946 ret = ENOMEM ;
@@ -857,8 +962,7 @@ int tb_new_process(struct testbench_prm *tp)
857962 tb_setup_widget_ipc_msg (comp_info );
858963
859964 /* copy uuid to the end of the payload */
860- memcpy (comp_info -> ipc_payload + sizeof (struct ipc4_base_module_cfg ), & comp_info -> uuid ,
861- sizeof (struct sof_uuid ));
965+ memcpy (comp_info -> ipc_payload + uuid_offset , & comp_info -> uuid , sizeof (struct sof_uuid ));
862966
863967 /* TODO: drop tplg_ctl to avoid memory leak. Need to store and handle this
864968 * to support controls.
0 commit comments