sof icon indicating copy to clipboard operation
sof copied to clipboard

[FEATURE] topology2: enable string concatenation for parameter passing

Open lyakh opened this issue 2 years ago • 3 comments

Is your feature request related to a problem? Please describe. When including topology2 configuration files into a top-level file, where those included files don't only define classes but also instantiate objects, names in the included and in the including files have to match, which currently can only be achieved by hard-coding. Included files should be using parameters passed to them instead, which is unsupported ATM. See https://github.com/thesofproject/sof/pull/6981/commits/e8f170e79aae8183aee8652e55d9b8d0a7e09ea9#diff-3a76b3b9be741be592ab3e43fb13a010876f407a73bb8113c6f3851e84f5bd98R29 for examples of such hard-coding, e.g.

Object.PCM.pcm.210 {
	name "Port0 Aux Playback"
	id 210

Describe the solution you'd like With topology1 / m4 we could pass parameters and then compose names by simply using parameters in strings like

define(`PIPELINE_ID', $2)
define(`N_BUFFER', `BUF'PIPELINE_ID`.'$1)

which would concatenate the string "BUF" with the value of the variable PIPELINE_ID which was set from the second parameter, a character '.' and the first parameter. That would then generate a string like "BUF20.1" for pipeline 20 and buffer ID 1. Topology2 uses the alsaconf language which doesn't support this kind of string manipulation. To concatenate strings there something like

{
    @func concat
    strings [ "a1" "b2" "c3" ]
}

is used.

Describe alternatives you've considered On the one hand alsaconf already has a way to concatenate strings described above - using @func concat, so supposedly we should use it too. OTOH I'm not even sure this is feasible in our case, but defining an additional string concatenation method for alsaconf seems wrong too.

lyakh avatar Jan 23 '23 14:01 lyakh

@lyakh fix posted upstream: https://github.com/alsa-project/alsa-utils/pull/188

This fix doesnt use string concat but rather the compiler takes care of making sure that the objects in the included file have unique instance ID's

ranj063 avatar Jan 24 '23 16:01 ranj063

@lyakh fix posted upstream: alsa-project/alsa-utils#188

This fix doesnt use string concat but rather the compiler takes care of making sure that the objects in the included file have unique instance ID's

@ranj063 Thanks! Yes, that should solve this specific problem, but what about others? E.g. look at https://github.com/thesofproject/sof/blob/231622fa010c6d4807567d217b0a8cf7e6c6d371/tools/topology/topology2/cavs-nocodec.conf#L46-L47 and https://github.com/thesofproject/sof/blob/231622fa010c6d4807567d217b0a8cf7e6c6d371/tools/topology/topology2/cavs-nocodec.conf#L55-L56 - shouldn't cases like that be created with concatenation too?

lyakh avatar Jan 25 '23 07:01 lyakh

So @lyakh you are looking for something like device-tree p-handle? A possibility to tag a topology object instance and refer to that tag in other parts of the topology, without need to refer to automatically assigned object names?

jsarha avatar Feb 13 '25 12:02 jsarha