Skip to content

ASoC: SOF: topology: make the topology parser IPC agnostic - #3287

Merged
plbossart merged 31 commits into
thesofproject:topic/sof-devfrom
ranj063:topic/ipc_agnostic_topology
Dec 13, 2021
Merged

plbossart merged 31 commits into
thesofproject:topic/sof-devfrom
ranj063:topic/ipc_agnostic_topology

Conversation

@ranj063

@ranj063 ranj063 commented Nov 22, 2021 •

Copy link
Copy Markdown
Collaborator

Make the topology parser IPC agnostic so that when new IPC versions are introduced, we can reuse the same parser and add
support for the new IPC structures.

The basic idea is that when parsing topology, we parse the tuple array and store them as token/value pairs in the appropriate objects. For example, in the case of the host component, we store it as part of struct snd_sof_widget. Once, the tuple arrays are all parsed, we can build the IPC structs for the respective component whenever needed based on the IPC version in use. In this PR currently, it is done in the topology complete op.

Introduce IPC ops and set the ops based on the IPC version. This PR includes all the required topology related ops for IPC3

@ranj063 ranj063 changed the title ASoC: SOF: topology: make the topology parser IPC agnostic [RFC] ASoC: SOF: topology: make the topology parser IPC agnostic Nov 22, 2021
@ranj063
ranj063 force-pushed the topic/ipc_agnostic_topology branch from 7f2fc7e to e10fc65 Compare November 22, 2021 01:18
@ranj063
ranj063 force-pushed the topic/ipc_agnostic_topology branch from e10fc65 to 77c0a9e Compare November 22, 2021 06:07

@lgirdwood lgirdwood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack, good idea - the topology ABI is the constant so code reuse is preferred and possible here.

@ujfalusi ujfalusi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't pretend I understand fully what this does in practice, the return value from int to u32 for the get_tokens are distracting a bit.

Comment thread sound/soc/sof/topology.c Outdated
memcpy(dst, velem->uuid, UUID_SIZE);

return 0;
return *dst;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original int return was meant to support failure, no?
I don't see why changing it to u32 is good and how one should interpret the first 32bits of a UUID as u32 as return value...

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ujfalusi UUID is a special case. we'll have to find a way to handle it differently. This PR is not complete yet, it is only a reference. @bardliao is working on extending it for all cases. I will close this one once he posts his

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as for returning u32, I need the value from find_format() , so I had to return it and couldnt do it for just one token as it is an op. Ideally we should add a new op say get_token_new to all tokens and eventually replace get_token(). Again something @bardliao is working on.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ranj063, what was wrong with the pointer+offset+size? If you don't want it to be put into the ipc struct, then:

struct snd_sof_tuple my_tuple;

if (token->type == SND_SOC_TPLG_TUPLE_TYPE_STRING) {
	my_tuple.token = token->token;
	token->get_token(elem, &my_tuple.value, 0, sizeof(my_tuple.value));
}

@ranj063
ranj063 force-pushed the topic/ipc_agnostic_topology branch from 77c0a9e to f6697d4 Compare November 23, 2021 00:26
Comment thread sound/soc/sof/topology.c Outdated
continue;

/* matched - get value */
value = tokens[j].get_token(elem, NULL, 0, tokens[j].size);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to dereference badly at or just above NULL...

@ujfalusi ujfalusi Nov 23, 2021 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it does not as it is going to use get_token_comp_format_new() which ignores the object, offset and size

Comment thread sound/soc/sof/topology.c Outdated
{SOF_TKN_COMP_FORMAT,
SND_SOC_TPLG_TUPLE_TYPE_STRING, get_token_comp_format_new,
offsetof(struct sof_ipc_comp_config, frame_fmt), 0},
};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me see if I understand this right:
Currently we take the information from the topology and directly update a given ipc struct directly based on the sof_topology_token.

With this change we first take the topology information and convert it to an array of tuples.
Then we update the given ipc struct using the tuples array and the sof_topology_token.
So if you want to support another type of ipc struct to update you would need another sof_topology_token struct to encode the offsets needed to be updated and also to have different sets of parameters?

Do we win anything apart from the intermediate step as I think we would be able to achieve this without introducing the tuples and just feed different sets of sof_topology_token to the topology parsing?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the intermediate step is to speed things up. Parsing is a one time thing and can be done once at boot. If you were to parse the tokens and then set up the IPC struct in hw_params, we'd have latency concerns no?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only parsed at boot time, no? We set up the ipc struct once, no?
What I'm trying to say is that we can already do this w/o tuples:

static const struct sof_topology_token ipc3_volume_tokens[] = {
	{SOF_TKN_VOLUME_RAMP_STEP_TYPE, SND_SOC_TPLG_TUPLE_TYPE_WORD,
		get_token_u32, offsetof(struct sof_ipc3_comp_volume, ramp), 0},
	{SOF_TKN_VOLUME_RAMP_STEP_MS,
		SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
		offsetof(struct sof_ipc3_comp_volume, initial_ramp), 0},
};

static const struct sof_topology_token ipc4_volume_tokens[] = {
	{SOF_TKN_VOLUME_RAMP_STEP_TYPE, SND_SOC_TPLG_TUPLE_TYPE_WORD,
		get_token_u32, offsetof(struct sof_ipc4_comp_volume, ramp), 0},
	{SOF_TKN_VOLUME_RAMP_STEP_MS,
		SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
		offsetof(struct sof_ipc4_comp_volume, initial_ramp), 0},
	{SOF_TKN_VOLUME_RAMP_STEP_MS,
		SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
		offsetof(struct sof_ipc4_comp_volume, mute_ramp), 0},
};

...
struct sof_ipc3_comp_volume *ipc3_volume;
struct sof_ipc4_comp_volume *ipc4_volume;

if (sof_is_ipc3(sdev))
	ret = sof_parse_tokens(scomp, ipc3_volume, ipc3_volume_tokens,
			ARRAY_SIZE(ipc3_volume_tokens), private->array,
			le32_to_cpu(private->size));
else
	ret = sof_parse_tokens(scomp, ipc4_volume, ipc4_volume_tokens,
			ARRAY_SIZE(ipc4_volume_tokens), private->array,
			le32_to_cpu(private->size));

Obviously not this exact way, but even if we have the tuples in between we need to have similar branching.
Atm we can do this way:
if (ipc3) convert the topology to ipc3 IPC struct
else convert the topology to ipc4 IPC struct

With the tuples in the middle:
convert the topology to tuples
if (ipc3) convert the tuples to ipc3 IPC struct
else convert the tuples to ipc4 IPC struct

Am I missing something?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ujfalusi I'm not sure I'm following you. Basically, if you make the parser IPC agnostic, it dont need to split up ipc3 tokens and ipc4 tokens. You could if you want to but you can still do without the if (sof_is_ipc3(sdev)).

ret = sof_parse_tokens(scomp, ipc3_volume, ipc3_volume_tokens,
			ARRAY_SIZE(ipc3_volume_tokens), private->array,
			le32_to_cpu(private->size));

ret = sof_parse_tokens(scomp, ipc4_volume, ipc4_volume_tokens,
			ARRAY_SIZE(ipc4_volume_tokens), private->array,
			le32_to_cpu(private->size));

Ideally a ipc3 based tplg would have ipc3 tokens only and ipc4 tplg would contain ipc4 tokens and then ipc struct builder would choose whatever tokens it need based on ipc version.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ranj063, but can you be certain that there is no overlap between IPCx and IPCy namespaces/ids?
Ideally at the end we could be able to even select if we want to support IPC4 in the kernel (imx might want to do that to reduce the size).

Anyways, since lot have changed since this comment (and this is in a wrong place now), I'll try to remember and come back to this.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ujfalusi i've lost track of this conversation. So while the TOKEN IDs are common for different IPC versions, what token arrays they pertain to is IPC-specific. For ex: SOF_PCM_TOKENS could point to pcm_tokens[] in ipc3 and copier_tokens[] in ipc4.

@ranj063 ranj063 changed the title [RFC] ASoC: SOF: topology: make the topology parser IPC agnostic [TEST] [DO NOT REVIEW] ASoC: SOF: topology: make the topology parser IPC agnostic Nov 30, 2021
@ranj063
ranj063 force-pushed the topic/ipc_agnostic_topology branch 4 times, most recently from 5301fc3 to 6bb6d21 Compare November 30, 2021 07:44
@ranj063
ranj063 force-pushed the topic/ipc_agnostic_topology branch from 6bb6d21 to 3b3260b Compare November 30, 2021 07:49
Comment thread sound/soc/sof/topology.c Resolved
Comment thread sound/soc/sof/core.c Resolved
Comment thread sound/soc/sof/sof-audio.h Resolved
Add 2 new fields to snd_sof_widget to store an array of tuples
defined by struct snd_sof_tuple and the number of tuples. When the
topology gets parsed, the tuples associated with a widget will be stored
in this array and will be used to construct the IPC structure
depending on the IPC version.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Introduce a new struct for DAI links to save the DAI link information
parsed from topology. Also add a list of dai_links to struct snd_sof_dev
that will be populated during topology parsing.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Modify the signature for sof_parse_uuid_tokens(),
sof_parse_word_tokens() and sof_parse_string_tokens() to reorder the
arguments to be more intuitive and rename the count arg to num_tokens.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Rename the priv_size arg to array_size and clarify the arguments in the
comments.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Rename the count and priv_size arguments in sof_parse_tokens() and add
comments to clarify the arguments.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Remove the comp_dai and dai_config members of struct snd_sof_dai and
replace it with a void *private field. Introduce a new struct
sof_dai_private_data that will contain the pointer to these two fields.
The topology parser will populate this structure and save it as part of
the "private" member in snd_sof_dai. Change all users of these fields to
use the private member instead.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
In preparation for supporting a new IPC version that will be introduced
in the SOF firmware, add a new set of ops that will be version specific.

For now, the IPC ops contain only the topology-related ops for setting
up widgets and pipeline connections. It will be expanded later to also
abstract the IPC-specific items in the component driver and DAI driver.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Add a helper function for processing tuple arrays and populating the
IPC structure objects based on the token ID passed.

Introduce a new enum representing token ID for the tokens
currently used in the topology parse and a new struct sof_token_info
to store the information about a token set. Finally, expose the struct
snd_sof_topology token as it will be used by IPC-specific code.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Add the IPC ops including the topology-related IPC ops for the current
version (IPC3, named after the current SOF firmware ABI major version 3.0)
of IPC supported by the SOF firmware and set it as default. The topology
IPC ops and the widget ops within the topology IPC ops are both
mandatory.

With the introduction of IPC3 ops, we define the list of tokens pertaining
to the AIF_IN/AIF_OUT widgets. Then these tokens are parsed during
topology parsing and saved as part of the swidget tuples array. Once
topology parsing is complete, these tokens will be applied to create the
IPC structure for the host component based on the topology widget_setup
op in ipc3_tplg_ops.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Define the list of tokens pertaining to the scheduler widgets, parse and
save them as part of the swidget tuples array. Once topology parsing is
complete, these tokens will be applied to create the IPC structure for the
pipeline component based on the topology widget_setup op in ipc3_tplg_ops.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Define the list of tokens pertaining to the buffer widgets, parse and
save them as part of the swidget tuples array. Once topology parsing is
complete, these tokens will be applied to create the IPC structure for the
buffer component based on the topology widget_setup op in ipc3_tplg_ops.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
return ret;

/* now load process specific data and send IPC */
return sof_process_load(scomp, swidget, find_process_comp_type(config.type));

@ujfalusi ujfalusi Dec 10, 2021 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would sof_process_load() do if we don't find the type and find_process_comp_type() returns SOF_COMP_NONE?
Unlikely if not impossible or it is just fine?

@ujfalusi ujfalusi Dec 10, 2021 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, it is copy-paste so it worked, just asking.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose it would fail widget setup because the component doesn't exist.

ujfalusi
ujfalusi previously approved these changes Dec 10, 2021

@ujfalusi ujfalusi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ranj063, nice work!
From my side this looks fine, I can not see anything which would prevent me to approve it.

Comment thread sound/soc/sof/ipc3-topology.c Resolved
Define the list of tokens pertaining to the pga type widgets, parse and
save them as part of the swidget tuples array. Once topology parsing is
complete, these tokens will be applied to create the IPC structure for the
pga component based on the topology widget_setup op in ipc3_tplg_ops.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Define the list of tokens pertaining to the mixer widgets, parse and
save them as part of the swidget tuples array. Once topology parsing is
complete, these tokens will be applied to create the IPC structure for the
mixer component based on the topology widget_setup op in ipc3_tplg_ops.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Define the list of tokens pertaining to the mux/demux widgets, parse and
save them as part of the swidget tuples array. Once topology parsing is
complete, these tokens will be applied to create the IPC structure for the
mux/demux component based on the topology widget_setup op in ipc3_tplg_ops.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Define the list of tokens pertaining to the src widgets, parse and
save them as part of the swidget tuples array. Once topology parsing is
complete, these tokens will be applied to create the IPC structure for the
src component based on the topology widget_setup op in ipc3_tplg_ops.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Define the list of tokens pertaining to the asrc widgets, parse and
save them as part of the swidget tuples array. Once topology parsing is
complete, these tokens will be applied to create the IPC structure for the
asrc component based on the topology widget_setup op in ipc3_tplg_ops.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Define the list of tokens pertaining to the siggen widgets, parse and
save them as part of the swidget tuples array. Once topology parsing is
complete, these tokens will be applied to create the IPC structure for the
tone component based on the topology widget_setup op in ipc3_tplg_ops.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Define the list of tokens pertaining to effect type widgets, parse and
save them as part of the swidget tuples array. Once topology parsing is
complete, these tokens will be applied to create the IPC structure for the
process component based on the topology widget_setup op in ipc3_tplg_ops.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Define and set the route_setup op for IPC3 topology ops and use it for
setting up routes.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Define the list of tokens pertaining to the dai_in/out widgets, parse and
save them as part of the swidget tuples array. Once topology parsing is
complete, these tokens will be applied to create the IPC structure for the
DAI component based on the topology widget_setup op in ipc3_tplg_ops.

DAI link parsing is also made IPC agnostic by parsing the list of tokens
associated with all DAI types. The config will be applied to the
respective DAI widgets during topology complete.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Make the control parser in topology IPC agnostic by introducing 2 new
topology IPC ops, control_setup and control_free. These ops handle
setting up/freeing the control data in the IPC format based on the IPC
version.

Along with this, modify the struct snd_sof_control to remove the
IPC-specific field, control_data and replace it with the void pointer to
ipc_control_data. Also, add a few new fields to store all the
information parsed from topology.

Finally, define and set the control setup/free ops for IPC3.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Make widget binding in the topology parser IPC agnostic by introducing a
new op, bind_event, in struct ipc_tplg_widget_ops. Also set the op
for all widget types in the IPC3 topology ops.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Add a new topology IPC op, pipeline_complete in struct ipc_tplg_ops
and set the op for IPC3. Replace the calls to
snd_sof_complete_pipeline() with the calls to the topology IPC
pipeline_complete op.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
@ranj063

ranj063 commented Dec 13, 2021

Copy link
Copy Markdown
Collaborator Author

SOFCI TEST

@bardliao bardliao left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ranj063 LGTM

@ujfalusi ujfalusi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding back my ack...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants