From 3a17d0c4b2d7fc9bd729f17aaf08af0ecb9a9dc9 Mon Sep 17 00:00:00 2001 From: Ranjani Sridharan Date: Sun, 21 Nov 2021 17:02:35 -0800 Subject: [PATCH 1/8] ASoC: SOF: topology: make the topology parser IPC agnostic 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. This PR is only to showcase how we can achieve this. It doesnt implement the feature fully but only for the host component. 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. But it can be moved further out to the pcm_params() for the dynamic pipeline case when the widgets are actually set up. Signed-off-by: Ranjani Sridharan --- sound/soc/sof/Makefile | 3 +- sound/soc/sof/ipc3-topology.c | 96 ++++++++++ sound/soc/sof/sof-audio.h | 41 +++- sound/soc/sof/topology.c | 341 +++++++++++++++++++++++++++------- 4 files changed, 408 insertions(+), 73 deletions(-) create mode 100644 sound/soc/sof/ipc3-topology.c diff --git a/sound/soc/sof/Makefile b/sound/soc/sof/Makefile index 6f76927e0a1c2f..4a823c79abaf90 100644 --- a/sound/soc/sof/Makefile +++ b/sound/soc/sof/Makefile @@ -1,7 +1,8 @@ # SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) snd-sof-objs := core.o ops.o loader.o ipc.o pcm.o pm.o debug.o topology.o\ - control.o trace.o utils.o sof-audio.o stream-ipc.o ipc4.o + control.o trace.o utils.o sof-audio.o stream-ipc.o ipc4.o\ + ipc3-topology.o snd-sof-$(CONFIG_SND_SOC_SOF_DEBUG_PROBES) += sof-probes.o snd-sof-$(CONFIG_SND_SOC_SOF_COMPRESS) += compress.o diff --git a/sound/soc/sof/ipc3-topology.c b/sound/soc/sof/ipc3-topology.c new file mode 100644 index 00000000000000..8fd1c46f0f27d7 --- /dev/null +++ b/sound/soc/sof/ipc3-topology.c @@ -0,0 +1,96 @@ +// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) +// +// This file is provided under a dual BSD/GPLv2 license. When using or +// redistributing this file, you may do so under either license. +// +// Copyright(c) 2021 Intel Corporation. All rights reserved. +// +// + +#include +#include "sof-priv.h" +#include "sof-audio.h" +#include "ops.h" + +/* + * update the IPC struct based on the tuple array. + */ +static void sof_update_ipc_object(void *object, const struct sof_topology_token *tokens, int count, + int num_tuples, struct snd_sof_tuple *tuples, + size_t object_size, int num_sets) +{ + int i,j; + int num_tokens_matched = 0; + int offset = 0; + + for (i = 0; i < count; i++) { + for (j = 0; j < num_tuples; j++) { + if (tokens[i].token == tuples[j].token) { + switch (tokens[i].type) { + case SND_SOC_TPLG_TUPLE_TYPE_WORD: + { + u32 *val = (u32 *)((u8 *)object + tokens[i].offset + + offset); + + *val = tuples[j].value; + break; + } + case SND_SOC_TPLG_TUPLE_TYPE_SHORT: + case SND_SOC_TPLG_TUPLE_TYPE_BOOL: + { + u16 *val = (u16 *)((u8 *)object + tokens[i].offset + + offset); + + *val = (u16) tuples[j].value; + break; + } + default: + break; + } + + num_tokens_matched++; + if (!(num_tokens_matched % count)) { + if (num_sets == 1) + return; + + offset += object_size; + } + } + } + } +} + +int sof_widget_update_ipc_comp_host(struct snd_soc_component *scomp, + struct snd_sof_widget *swidget) +{ + struct sof_ipc_comp_host *host; + size_t ipc_size = sizeof(*host); + + host = (struct sof_ipc_comp_host *) + sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id); + if (!host) + return -ENOMEM; + + /* configure host comp IPC message */ + host->comp.type = SOF_COMP_HOST; + if (swidget->id == snd_soc_dapm_aif_out) + host->direction = SOF_IPC_STREAM_CAPTURE; + else + host->direction = SOF_IPC_STREAM_PLAYBACK; + host->config.hdr.size = sizeof(host->config); + + /* update pcm_tokens */ + sof_update_ipc_object(host, pcm_tokens, pcm_token_size, swidget->num_tuples, + swidget->tuples, sizeof(*host), 1); + + /* update comp_tokens */ + sof_update_ipc_object(&host->config, comp_tokens_new, comp_token_size, swidget->num_tuples, + swidget->tuples, sizeof(host->config), 1); + + dev_dbg(scomp->dev, "loaded host %s\n", swidget->widget->name); + sof_dbg_comp_config(scomp, &host->config); + + swidget->private = host; + + return 0; +} diff --git a/sound/soc/sof/sof-audio.h b/sound/soc/sof/sof-audio.h index f3009e6b91a10b..cbf0bd31962b5b 100644 --- a/sound/soc/sof/sof-audio.h +++ b/sound/soc/sof/sof-audio.h @@ -19,6 +19,7 @@ #include #include #include +#include #include "sof-priv.h" #define SOF_AUDIO_PCM_DRV_NAME "sof-audio-component" @@ -30,6 +31,31 @@ #define WIDGET_IS_DAI(id) ((id) == snd_soc_dapm_dai_in || (id) == snd_soc_dapm_dai_out) +struct snd_sof_widget; +struct sof_ipc_comp *sof_comp_alloc(struct snd_sof_widget *swidget, size_t *ipc_size, int index); + +/* + * Topology Token Parsing. + * New tokens should be added to headers and parsing tables below. + */ + +struct sof_topology_token { + u32 token; + u32 type; + u32 (*get_token)(void *elem, void *object, u32 offset, u32 size); + u32 offset; + u32 size; +}; + +struct snd_sof_tuple { + u32 token; + u32 value; +}; + +extern const struct sof_topology_token pcm_tokens[]; +extern int pcm_token_size, comp_token_size; +extern const struct sof_topology_token comp_tokens_new[]; + /* PCM stream, mapped to FW component */ struct snd_sof_pcm_stream { u32 comp_id; @@ -55,6 +81,8 @@ struct snd_sof_pcm { struct list_head list; /* list in sdev pcm list */ struct snd_pcm_hw_params params[2]; bool prepared[2]; /* PCM_PARAMS set successfully */ + int num_tuples; + struct snd_sof_tuple *tuples; }; struct snd_sof_led_control { @@ -82,9 +110,10 @@ struct snd_sof_control { /* if true, the control's data needs to be updated from Firmware */ bool comp_data_dirty; -}; -struct snd_sof_widget; + int num_tuples; + struct snd_sof_tuple *tuples; +}; /* ASoC SOF DAPM widget */ struct snd_sof_widget { @@ -95,6 +124,7 @@ struct snd_sof_widget { int use_count; /* use_count will be protected by the PCM mutex held by the core */ int core; int id; + int num_tuples; /* * Flag indicating if the widget should be set up dynamically when a PCM is opened. @@ -113,6 +143,8 @@ struct snd_sof_widget { /* extended data for UUID components */ struct sof_ipc_comp_ext comp_ext; + struct snd_sof_tuple *tuples; + void *private; /* core does not touch this */ }; @@ -133,6 +165,7 @@ struct snd_sof_route { struct snd_sof_dai { struct snd_soc_component *scomp; const char *name; + int num_tuples; struct sof_ipc_comp_dai comp_dai; int number_configs; @@ -140,6 +173,7 @@ struct snd_sof_dai { bool configured; /* DAI configured during BE hw_params */ struct sof_ipc_dai_config *dai_config; struct list_head list; /* list in sdev dai list */ + struct snd_sof_tuple *tuples; }; /* @@ -264,4 +298,7 @@ int sof_pcm_dsp_pcm_free(struct snd_pcm_substream *substream, struct snd_sof_dev struct snd_sof_pcm *spcm); int sof_pcm_stream_free(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream, struct snd_sof_pcm *spcm, int dir, bool free_widget_list); +int sof_widget_update_ipc_comp_host(struct snd_soc_component *scomp, + struct snd_sof_widget *swidget); +void sof_dbg_comp_config(struct snd_soc_component *scomp, struct sof_ipc_comp_config *config); #endif diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c index e72dcae5e7ee7a..1281e1bd33c3b1 100644 --- a/sound/soc/sof/topology.c +++ b/sound/soc/sof/topology.c @@ -465,73 +465,67 @@ static enum sof_comp_type find_process_comp_type(enum sof_ipc_process_type type) return SOF_COMP_NONE; } -/* - * Topology Token Parsing. - * New tokens should be added to headers and parsing tables below. - */ - -struct sof_topology_token { - u32 token; - u32 type; - int (*get_token)(void *elem, void *object, u32 offset, u32 size); - u32 offset; - u32 size; -}; - -static int get_token_u32(void *elem, void *object, u32 offset, u32 size) +u32 get_token_u32(void *elem, void *object, u32 offset, u32 size) { struct snd_soc_tplg_vendor_value_elem *velem = elem; u32 *val = (u32 *)((u8 *)object + offset); *val = le32_to_cpu(velem->value); - return 0; + return *val; } -static int get_token_u16(void *elem, void *object, u32 offset, u32 size) +static u32 get_token_u16(void *elem, void *object, u32 offset, u32 size) { struct snd_soc_tplg_vendor_value_elem *velem = elem; u16 *val = (u16 *)((u8 *)object + offset); *val = (u16)le32_to_cpu(velem->value); - return 0; + return *val; } -static int get_token_uuid(void *elem, void *object, u32 offset, u32 size) +static u32 get_token_uuid(void *elem, void *object, u32 offset, u32 size) { struct snd_soc_tplg_vendor_uuid_elem *velem = elem; u8 *dst = (u8 *)object + offset; memcpy(dst, velem->uuid, UUID_SIZE); - return 0; + return *dst; } -static int get_token_comp_format(void *elem, void *object, u32 offset, u32 size) +u32 get_token_comp_format(void *elem, void *object, u32 offset, u32 size) { struct snd_soc_tplg_vendor_string_elem *velem = elem; u32 *val = (u32 *)((u8 *)object + offset); *val = find_format(velem->string); - return 0; + return *val; +} + +u32 get_token_comp_format_new(void *elem, void *object, u32 offset, u32 size) +{ + struct snd_soc_tplg_vendor_string_elem *velem = elem; + + return find_format(velem->string); } -static int get_token_dai_type(void *elem, void *object, u32 offset, u32 size) +static u32 get_token_dai_type(void *elem, void *object, u32 offset, u32 size) { struct snd_soc_tplg_vendor_string_elem *velem = elem; u32 *val = (u32 *)((u8 *)object + offset); *val = find_dai(velem->string); - return 0; + return *val; } -static int get_token_process_type(void *elem, void *object, u32 offset, +static u32 get_token_process_type(void *elem, void *object, u32 offset, u32 size) { struct snd_soc_tplg_vendor_string_elem *velem = elem; u32 *val = (u32 *)((u8 *)object + offset); *val = find_process(velem->string); - return 0; + return *val; } /* Buffers */ @@ -625,11 +619,13 @@ static const struct sof_topology_token process_tokens[] = { }; /* PCM */ -static const struct sof_topology_token pcm_tokens[] = { +const struct sof_topology_token pcm_tokens[] = { {SOF_TKN_PCM_DMAC_CONFIG, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32, - offsetof(struct sof_ipc_comp_host, dmac_config), 0}, + offsetof(struct sof_ipc_comp_host, dmac_config), 0}, }; +int pcm_token_size = ARRAY_SIZE(pcm_tokens); + /* PCM */ static const struct sof_topology_token stream_tokens[] = { {SOF_TKN_STREAM_PLAYBACK_COMPATIBLE_D0I3, @@ -641,18 +637,33 @@ static const struct sof_topology_token stream_tokens[] = { }; /* Generic components */ -static const struct sof_topology_token comp_tokens[] = { +const struct sof_topology_token comp_tokens[] = { {SOF_TKN_COMP_PERIOD_SINK_COUNT, - SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32, - offsetof(struct sof_ipc_comp_config, periods_sink), 0}, + SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32, + offsetof(struct sof_ipc_comp_config, periods_sink), 0}, {SOF_TKN_COMP_PERIOD_SOURCE_COUNT, - SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32, - offsetof(struct sof_ipc_comp_config, periods_source), 0}, + SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32, + offsetof(struct sof_ipc_comp_config, periods_source), 0}, {SOF_TKN_COMP_FORMAT, - SND_SOC_TPLG_TUPLE_TYPE_STRING, get_token_comp_format, - offsetof(struct sof_ipc_comp_config, frame_fmt), 0}, + SND_SOC_TPLG_TUPLE_TYPE_STRING, get_token_comp_format, + offsetof(struct sof_ipc_comp_config, frame_fmt), 0}, }; +/* this should replace comp_tokens[] after switch all token parsing */ +const struct sof_topology_token comp_tokens_new[] = { + {SOF_TKN_COMP_PERIOD_SINK_COUNT, + SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32, + offsetof(struct sof_ipc_comp_config, periods_sink), 0}, + {SOF_TKN_COMP_PERIOD_SOURCE_COUNT, + SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32, + offsetof(struct sof_ipc_comp_config, periods_source), 0}, + {SOF_TKN_COMP_FORMAT, + SND_SOC_TPLG_TUPLE_TYPE_STRING, get_token_comp_format_new, + offsetof(struct sof_ipc_comp_config, frame_fmt), 0}, +}; + +int comp_token_size = ARRAY_SIZE(comp_tokens_new); + /* SSP */ static const struct sof_topology_token ssp_tokens[] = { {SOF_TKN_INTEL_SSP_CLKS_CONTROL, @@ -894,6 +905,65 @@ static int sof_parse_string_tokens(struct snd_soc_component *scomp, return found; } +/* this should replace sof_parse_string_tokens() after switch all token parsing */ +static int sof_parse_string_tokens_new(struct snd_soc_component *scomp, + const struct sof_topology_token *tokens, + int count, struct snd_soc_tplg_vendor_array *array, + struct snd_sof_tuple **tuples, int *num_tuples) +{ + struct snd_soc_tplg_vendor_string_elem *elem; + int found = 0; + int i, j; + u32 value; + + /* parse element by element */ + for (i = 0; i < le32_to_cpu(array->num_elems); i++) { + elem = &array->string[i]; + + /* search for token */ + for (j = 0; j < count; j++) { + struct snd_sof_tuple *new_tuples; + + /* match token type */ + if (tokens[j].type != SND_SOC_TPLG_TUPLE_TYPE_STRING) + continue; + + /* match token id */ + if (tokens[j].token != le32_to_cpu(elem->token)) + continue; + + /* matched - get value */ + value = tokens[j].get_token(elem, NULL, 0, tokens[j].size); + + if (!tuples && !num_tuples) + continue; + + /* save token in the tuple array */ + if (!(*num_tuples)) { + new_tuples = devm_kzalloc(scomp->dev, sizeof(struct snd_sof_tuple), + GFP_KERNEL); + if (!new_tuples) + return -ENOMEM; + } else { + new_tuples = devm_krealloc(scomp->dev, *tuples, + sizeof(struct snd_sof_tuple) * + (*num_tuples + 1), + GFP_KERNEL); + if (!new_tuples) + return -ENOMEM; + } + + new_tuples[*num_tuples].token = tokens[j].token; + new_tuples[*num_tuples].value = value; + *tuples = new_tuples; + (*num_tuples)++; + found++; + } + } + + return found; +} + static int sof_parse_word_tokens(struct snd_soc_component *scomp, void *object, const struct sof_topology_token *tokens, @@ -934,6 +1004,65 @@ static int sof_parse_word_tokens(struct snd_soc_component *scomp, return found; } +/* this should replace sof_parse_word_tokens() after switch all token parsing */ +static int sof_parse_word_tokens_new(struct snd_soc_component *scomp, + const struct sof_topology_token *tokens, + int count, + struct snd_soc_tplg_vendor_array *array, + struct snd_sof_tuple **tuples, int *num_tuples) +{ + struct snd_soc_tplg_vendor_value_elem *elem; + int found = 0; + int i, j; + + /* parse element by element */ + for (i = 0; i < le32_to_cpu(array->num_elems); i++) { + elem = &array->value[i]; + + /* search for token */ + for (j = 0; j < count; j++) { + struct snd_sof_tuple *new_tuples; + + /* match token type */ + if (!(tokens[j].type == SND_SOC_TPLG_TUPLE_TYPE_WORD || + tokens[j].type == SND_SOC_TPLG_TUPLE_TYPE_SHORT || + tokens[j].type == SND_SOC_TPLG_TUPLE_TYPE_BYTE || + tokens[j].type == SND_SOC_TPLG_TUPLE_TYPE_BOOL)) + continue; + + /* match token id */ + if (tokens[j].token != le32_to_cpu(elem->token)) + continue; + + if (!tuples && !num_tuples) + continue; + + /* save token in the tuple array */ + if (!(*num_tuples)) { + new_tuples = devm_kzalloc(scomp->dev, sizeof(struct snd_sof_tuple), + GFP_KERNEL); + if (!new_tuples) + return -ENOMEM; + } else { + new_tuples = devm_krealloc(scomp->dev, *tuples, + sizeof(struct snd_sof_tuple) * + (*num_tuples + 1), + GFP_KERNEL); + if (!new_tuples) + return -ENOMEM; + } + + new_tuples[*num_tuples].token = tokens[j].token; + new_tuples[*num_tuples].value = le32_to_cpu(elem->value); + *tuples = new_tuples; + (*num_tuples)++; + found++; + } + } + + return found; +} + /** * sof_parse_token_sets - Parse multiple sets of tokens * @scomp: pointer to soc component @@ -1016,6 +1145,90 @@ static int sof_parse_token_sets(struct snd_soc_component *scomp, return 0; } +/* this should replace sof_parse_token_sets() after all token parsing is switched */ +static int sof_parse_token_sets_new(struct snd_soc_component *scomp, + void *object, const struct sof_topology_token *tokens, + int count, struct snd_soc_tplg_vendor_array *array, + int priv_size, int sets, size_t object_size, + struct snd_sof_tuple **tuples, int *num_tuples) +{ + size_t offset = 0; + int found = 0; + int total = 0; + int asize; + + while (priv_size > 0 && total < count * sets) { + asize = le32_to_cpu(array->size); + + /* validate asize */ + if (asize < 0) { /* FIXME: A zero-size array makes no sense */ + dev_err(scomp->dev, "error: invalid array size 0x%x\n", + asize); + return -EINVAL; + } + + /* make sure there is enough data before parsing */ + priv_size -= asize; + if (priv_size < 0) { + dev_err(scomp->dev, "error: invalid array size 0x%x\n", + asize); + return -EINVAL; + } + + /* call correct parser depending on type */ + switch (le32_to_cpu(array->type)) { + case SND_SOC_TPLG_TUPLE_TYPE_UUID: + found += sof_parse_uuid_tokens(scomp, object, tokens, count, array, + offset); + break; + case SND_SOC_TPLG_TUPLE_TYPE_STRING: + found += sof_parse_string_tokens_new(scomp, tokens, count, array, + tuples, num_tuples); + break; + case SND_SOC_TPLG_TUPLE_TYPE_BOOL: + case SND_SOC_TPLG_TUPLE_TYPE_BYTE: + case SND_SOC_TPLG_TUPLE_TYPE_WORD: + case SND_SOC_TPLG_TUPLE_TYPE_SHORT: + found += sof_parse_word_tokens_new(scomp, tokens, count, array, tuples, + num_tuples); + break; + default: + dev_err(scomp->dev, "error: unknown token type %d\n", + array->type); + return -EINVAL; + } + + /* next array */ + array = (struct snd_soc_tplg_vendor_array *)((u8 *)array + + asize); + + /* move to next target struct */ + if (found >= count) { + offset += object_size; + total += found; + found = 0; + } + } + + return 0; +} + +/* this should replace sof_parse_tokens() after switch all token parsing */ +static int sof_parse_tokens_new(struct snd_soc_component *scomp, void *object, + const struct sof_topology_token *tokens, int count, + struct snd_soc_tplg_vendor_array *array, + int priv_size, struct snd_sof_tuple **tuples, int *num_tuples) +{ + /* + * sof_parse_tokens is used when topology contains only a single set of + * identical tuples arrays. So additional parameters to + * sof_parse_token_sets are sets = 1 (only 1 set) and + * object_size = 0 (irrelevant). + */ + return sof_parse_token_sets_new(scomp, object, tokens, count, array, + priv_size, 1, 0, tuples, num_tuples); +} + static int sof_parse_tokens(struct snd_soc_component *scomp, void *object, const struct sof_topology_token *tokens, @@ -1033,8 +1246,7 @@ static int sof_parse_tokens(struct snd_soc_component *scomp, priv_size, 1, 0); } -static void sof_dbg_comp_config(struct snd_soc_component *scomp, - struct sof_ipc_comp_config *config) +void sof_dbg_comp_config(struct snd_soc_component *scomp, struct sof_ipc_comp_config *config) { dev_dbg(scomp->dev, " config: periods snk %d src %d fmt %d\n", config->periods_sink, config->periods_source, @@ -1436,8 +1648,7 @@ static int sof_connect_dai_widget(struct snd_soc_component *scomp, * * Return: The pointer to the new allocated component, NULL if failed. */ -static struct sof_ipc_comp *sof_comp_alloc(struct snd_sof_widget *swidget, - size_t *ipc_size, int index) +struct sof_ipc_comp *sof_comp_alloc(struct snd_sof_widget *swidget, size_t *ipc_size, int index) { u8 nil_uuid[SOF_UUID_SIZE] = {0}; struct sof_ipc_comp *comp; @@ -1598,47 +1809,25 @@ static int sof_widget_load_pcm(struct snd_soc_component *scomp, int index, struct snd_soc_tplg_dapm_widget *tw) { struct snd_soc_tplg_private *private = &tw->priv; - struct sof_ipc_comp_host *host; - size_t ipc_size = sizeof(*host); int ret; - host = (struct sof_ipc_comp_host *) - sof_comp_alloc(swidget, &ipc_size, index); - if (!host) - return -ENOMEM; - - /* configure host comp IPC message */ - host->comp.type = SOF_COMP_HOST; - host->direction = dir; - host->config.hdr.size = sizeof(host->config); - - ret = sof_parse_tokens(scomp, host, pcm_tokens, - ARRAY_SIZE(pcm_tokens), private->array, - le32_to_cpu(private->size)); + ret = sof_parse_tokens_new(scomp, NULL, pcm_tokens, ARRAY_SIZE(pcm_tokens), private->array, + le32_to_cpu(private->size), &swidget->tuples, + &swidget->num_tuples); if (ret != 0) { - dev_err(scomp->dev, "error: parse host tokens failed %d\n", - private->size); - goto err; + dev_err(scomp->dev, "parsing host tokens failed %d\n", ret); + return ret; } - ret = sof_parse_tokens(scomp, &host->config, comp_tokens, - ARRAY_SIZE(comp_tokens), private->array, - le32_to_cpu(private->size)); + ret = sof_parse_tokens_new(scomp, NULL, comp_tokens_new, ARRAY_SIZE(comp_tokens_new), + private->array, le32_to_cpu(private->size), &swidget->tuples, + &swidget->num_tuples); if (ret != 0) { - dev_err(scomp->dev, "error: parse host.cfg tokens failed %d\n", - le32_to_cpu(private->size)); - goto err; + dev_err(scomp->dev, "parsing host comp tokens failed %d\n", ret); + return ret; } - dev_dbg(scomp->dev, "loaded host %s\n", swidget->widget->name); - sof_dbg_comp_config(scomp, &host->config); - - swidget->private = host; - return 0; -err: - kfree(host); - return ret; } /* @@ -3521,6 +3710,18 @@ static int sof_complete(struct snd_soc_component *scomp) struct snd_sof_widget *swidget, *comp_swidget; int ret; + /* now update all ipc based on the widget tuple array for host components */ + list_for_each_entry(swidget, &sdev->widget_list, list) { + switch (swidget->id) { + case snd_soc_dapm_aif_in: + case snd_soc_dapm_aif_out: + sof_widget_update_ipc_comp_host(scomp, swidget); + break; + default: + break; + } + } + /* set the pipe_widget and apply the dynamic_pipeline_widget_flag */ list_for_each_entry(swidget, &sdev->widget_list, list) { switch (swidget->id) { From 679f4c7ad61a04204bbd1993473c5f36a5d643ba Mon Sep 17 00:00:00 2001 From: Bard Liao Date: Tue, 23 Nov 2021 09:37:33 +0800 Subject: [PATCH 2/8] fixup! ASoC: SOF: topology: make the topology parser IPC agnostic Signed-off-by: Bard Liao --- sound/soc/sof/ipc3-topology.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sound/soc/sof/ipc3-topology.c b/sound/soc/sof/ipc3-topology.c index 8fd1c46f0f27d7..6d9177683e9869 100644 --- a/sound/soc/sof/ipc3-topology.c +++ b/sound/soc/sof/ipc3-topology.c @@ -50,9 +50,10 @@ static void sof_update_ipc_object(void *object, const struct sof_topology_token num_tokens_matched++; if (!(num_tokens_matched % count)) { - if (num_sets == 1) + /* found all required tokens */ + if ((num_tokens_matched / count) == num_sets) return; - + /* move to the next set */ offset += object_size; } } From 09e8714e8910688c99b9fd79f15201e86ca3e91b Mon Sep 17 00:00:00 2001 From: Bard Liao Date: Tue, 23 Nov 2021 19:45:07 +0800 Subject: [PATCH 3/8] fixup: use single line for extern int xxx_token_size We will have many xxx_token_sizes and will exceed 100 characters Signed-off-by: Bard Liao --- sound/soc/sof/sof-audio.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sound/soc/sof/sof-audio.h b/sound/soc/sof/sof-audio.h index cbf0bd31962b5b..de5082b70ad0b2 100644 --- a/sound/soc/sof/sof-audio.h +++ b/sound/soc/sof/sof-audio.h @@ -53,8 +53,9 @@ struct snd_sof_tuple { }; extern const struct sof_topology_token pcm_tokens[]; -extern int pcm_token_size, comp_token_size; extern const struct sof_topology_token comp_tokens_new[]; +extern int pcm_token_size; +extern int comp_token_size; /* PCM stream, mapped to FW component */ struct snd_sof_pcm_stream { From 64850da61efedc9738af66ee3f6dc1e77cb02700 Mon Sep 17 00:00:00 2001 From: Bard Liao Date: Tue, 23 Nov 2021 09:48:39 +0800 Subject: [PATCH 4/8] fixup: ASoC: SOF: toopology: move sof_update_ipc_object to topology.c It is general used by both IPC3 and IPC4. Signed-off-by: Bard Liao --- sound/soc/sof/ipc3-topology.c | 49 ----------------------------------- sound/soc/sof/sof-audio.h | 3 +++ sound/soc/sof/topology.c | 49 +++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 49 deletions(-) diff --git a/sound/soc/sof/ipc3-topology.c b/sound/soc/sof/ipc3-topology.c index 6d9177683e9869..354ed851e4a513 100644 --- a/sound/soc/sof/ipc3-topology.c +++ b/sound/soc/sof/ipc3-topology.c @@ -12,55 +12,6 @@ #include "sof-audio.h" #include "ops.h" -/* - * update the IPC struct based on the tuple array. - */ -static void sof_update_ipc_object(void *object, const struct sof_topology_token *tokens, int count, - int num_tuples, struct snd_sof_tuple *tuples, - size_t object_size, int num_sets) -{ - int i,j; - int num_tokens_matched = 0; - int offset = 0; - - for (i = 0; i < count; i++) { - for (j = 0; j < num_tuples; j++) { - if (tokens[i].token == tuples[j].token) { - switch (tokens[i].type) { - case SND_SOC_TPLG_TUPLE_TYPE_WORD: - { - u32 *val = (u32 *)((u8 *)object + tokens[i].offset + - offset); - - *val = tuples[j].value; - break; - } - case SND_SOC_TPLG_TUPLE_TYPE_SHORT: - case SND_SOC_TPLG_TUPLE_TYPE_BOOL: - { - u16 *val = (u16 *)((u8 *)object + tokens[i].offset + - offset); - - *val = (u16) tuples[j].value; - break; - } - default: - break; - } - - num_tokens_matched++; - if (!(num_tokens_matched % count)) { - /* found all required tokens */ - if ((num_tokens_matched / count) == num_sets) - return; - /* move to the next set */ - offset += object_size; - } - } - } - } -} - int sof_widget_update_ipc_comp_host(struct snd_soc_component *scomp, struct snd_sof_widget *swidget) { diff --git a/sound/soc/sof/sof-audio.h b/sound/soc/sof/sof-audio.h index de5082b70ad0b2..56d78c1b548d77 100644 --- a/sound/soc/sof/sof-audio.h +++ b/sound/soc/sof/sof-audio.h @@ -302,4 +302,7 @@ int sof_pcm_stream_free(struct snd_sof_dev *sdev, struct snd_pcm_substream *subs int sof_widget_update_ipc_comp_host(struct snd_soc_component *scomp, struct snd_sof_widget *swidget); void sof_dbg_comp_config(struct snd_soc_component *scomp, struct sof_ipc_comp_config *config); +void sof_update_ipc_object(void *object, const struct sof_topology_token *tokens, int count, + int num_tuples, struct snd_sof_tuple *tuples, + size_t object_size, int num_sets); #endif diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c index 1281e1bd33c3b1..99b35a47a852cd 100644 --- a/sound/soc/sof/topology.c +++ b/sound/soc/sof/topology.c @@ -1253,6 +1253,55 @@ void sof_dbg_comp_config(struct snd_soc_component *scomp, struct sof_ipc_comp_co config->frame_fmt); } +/* + * update the IPC struct based on the tuple array. + */ +void sof_update_ipc_object(void *object, const struct sof_topology_token *tokens, int count, + int num_tuples, struct snd_sof_tuple *tuples, + size_t object_size, int num_sets) +{ + int i,j; + int num_tokens_matched = 0; + int offset = 0; + + for (i = 0; i < count; i++) { + for (j = 0; j < num_tuples; j++) { + if (tokens[i].token == tuples[j].token) { + switch (tokens[i].type) { + case SND_SOC_TPLG_TUPLE_TYPE_WORD: + { + u32 *val = (u32 *)((u8 *)object + tokens[i].offset + + offset); + + *val = tuples[j].value; + break; + } + case SND_SOC_TPLG_TUPLE_TYPE_SHORT: + case SND_SOC_TPLG_TUPLE_TYPE_BOOL: + { + u16 *val = (u16 *)((u8 *)object + tokens[i].offset + + offset); + + *val = (u16) tuples[j].value; + break; + } + default: + break; + } + + num_tokens_matched++; + if (!(num_tokens_matched % count)) { + /* found all required tokens */ + if ((num_tokens_matched / count) == num_sets) + return; + /* move to the next set */ + offset += object_size; + } + } + } + } +} + /* * Standard Kcontrols. */ From 20425a54ab53a22128c4303e1bd46aa80a8c3ee9 Mon Sep 17 00:00:00 2001 From: Bard Liao Date: Tue, 23 Nov 2021 09:31:12 +0800 Subject: [PATCH 5/8] ASoC: SOF: topology: parse sof_ipc_comp_dai by sof_parse_tokens_new This will be squashed to previous commit. Signed-off-by: Bard Liao --- sound/soc/sof/ipc3-topology.c | 38 ++++++++++++++++++++ sound/soc/sof/sof-audio.h | 4 +++ sound/soc/sof/topology.c | 66 ++++++++++++++++------------------- 3 files changed, 73 insertions(+), 35 deletions(-) diff --git a/sound/soc/sof/ipc3-topology.c b/sound/soc/sof/ipc3-topology.c index 354ed851e4a513..e8ca9ec1735bdf 100644 --- a/sound/soc/sof/ipc3-topology.c +++ b/sound/soc/sof/ipc3-topology.c @@ -46,3 +46,41 @@ int sof_widget_update_ipc_comp_host(struct snd_soc_component *scomp, return 0; } + + +int sof_widget_update_ipc_comp_dai(struct snd_soc_component *scomp, + struct snd_sof_widget *swidget) +{ + struct sof_ipc_comp_dai *comp_dai; + size_t ipc_size = sizeof(*comp_dai); + struct snd_sof_dai *dai = swidget->private; + + comp_dai = (struct sof_ipc_comp_dai *) + sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id); + if (!comp_dai) + return -ENOMEM; + + /* configure dai IPC message */ + comp_dai->comp.type = SOF_COMP_DAI; + comp_dai->config.hdr.size = sizeof(comp_dai->config); + + /* update dai_tokens */ + sof_update_ipc_object(comp_dai, dai_tokens_new, dai_token_size, dai->num_tuples, + dai->tuples, sizeof(*comp_dai), 1); + + /* update comp_tokens */ + sof_update_ipc_object(&comp_dai->config, comp_tokens_new, comp_token_size, dai->num_tuples, + dai->tuples, sizeof(comp_dai->config), 1); + + /* + * copy only the sof_ipc_comp_dai to avoid collapsing + * the snd_sof_dai, the extended data is kept in the + * snd_sof_widget. + */ + memcpy(&dai->comp_dai, comp_dai, sizeof(*comp_dai)); + + dev_dbg(scomp->dev, "%s dai %s: type %d index %d\n", + __func__, swidget->widget->name, comp_dai->type, comp_dai->dai_index); + sof_dbg_comp_config(scomp, &comp_dai->config); + return 0; +} diff --git a/sound/soc/sof/sof-audio.h b/sound/soc/sof/sof-audio.h index 56d78c1b548d77..18e281f0bfff9b 100644 --- a/sound/soc/sof/sof-audio.h +++ b/sound/soc/sof/sof-audio.h @@ -53,9 +53,11 @@ struct snd_sof_tuple { }; extern const struct sof_topology_token pcm_tokens[]; +extern const struct sof_topology_token dai_tokens_new[]; extern const struct sof_topology_token comp_tokens_new[]; extern int pcm_token_size; extern int comp_token_size; +extern int dai_token_size; /* PCM stream, mapped to FW component */ struct snd_sof_pcm_stream { @@ -301,6 +303,8 @@ int sof_pcm_stream_free(struct snd_sof_dev *sdev, struct snd_pcm_substream *subs struct snd_sof_pcm *spcm, int dir, bool free_widget_list); int sof_widget_update_ipc_comp_host(struct snd_soc_component *scomp, struct snd_sof_widget *swidget); +int sof_widget_update_ipc_comp_dai(struct snd_soc_component *scomp, + struct snd_sof_widget *swidget); void sof_dbg_comp_config(struct snd_soc_component *scomp, struct sof_ipc_comp_config *config); void sof_update_ipc_object(void *object, const struct sof_topology_token *tokens, int count, int num_tuples, struct snd_sof_tuple *tuples, diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c index 99b35a47a852cd..d1f9f71bcc1e9c 100644 --- a/sound/soc/sof/topology.c +++ b/sound/soc/sof/topology.c @@ -518,6 +518,13 @@ static u32 get_token_dai_type(void *elem, void *object, u32 offset, u32 size) return *val; } +static u32 get_token_dai_type_new(void *elem, void *object, u32 offset, u32 size) +{ + struct snd_soc_tplg_vendor_string_elem *velem = elem; + + return find_dai(velem->string); +} + static u32 get_token_process_type(void *elem, void *object, u32 offset, u32 size) { @@ -537,7 +544,7 @@ static const struct sof_topology_token buffer_tokens[] = { }; /* DAI */ -static const struct sof_topology_token dai_tokens[] = { +const struct sof_topology_token dai_tokens[] = { {SOF_TKN_DAI_TYPE, SND_SOC_TPLG_TUPLE_TYPE_STRING, get_token_dai_type, offsetof(struct sof_ipc_comp_dai, type), 0}, {SOF_TKN_DAI_INDEX, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32, @@ -546,6 +553,16 @@ static const struct sof_topology_token dai_tokens[] = { offsetof(struct sof_ipc_comp_dai, direction), 0}, }; +const struct sof_topology_token dai_tokens_new[] = { + {SOF_TKN_DAI_TYPE, SND_SOC_TPLG_TUPLE_TYPE_STRING, get_token_dai_type_new, + offsetof(struct sof_ipc_comp_dai, type), 0}, + {SOF_TKN_DAI_INDEX, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32, + offsetof(struct sof_ipc_comp_dai, dai_index), 0}, + {SOF_TKN_DAI_DIRECTION, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32, + offsetof(struct sof_ipc_comp_dai, direction), 0}, +}; +int dai_token_size = ARRAY_SIZE(dai_tokens_new); + /* BE DAI link */ static const struct sof_topology_token dai_link_tokens[] = { {SOF_TKN_DAI_TYPE, SND_SOC_TPLG_TUPLE_TYPE_STRING, get_token_dai_type, @@ -1269,6 +1286,7 @@ void sof_update_ipc_object(void *object, const struct sof_topology_token *tokens if (tokens[i].token == tuples[j].token) { switch (tokens[i].type) { case SND_SOC_TPLG_TUPLE_TYPE_WORD: + case SND_SOC_TPLG_TUPLE_TYPE_STRING: { u32 *val = (u32 *)((u8 *)object + tokens[i].offset + offset); @@ -1736,54 +1754,31 @@ static int sof_widget_load_dai(struct snd_soc_component *scomp, int index, struct snd_sof_dai *dai) { struct snd_soc_tplg_private *private = &tw->priv; - struct sof_ipc_comp_dai *comp_dai; - size_t ipc_size = sizeof(*comp_dai); int ret; - comp_dai = (struct sof_ipc_comp_dai *) - sof_comp_alloc(swidget, &ipc_size, index); - if (!comp_dai) - return -ENOMEM; - - /* configure dai IPC message */ - comp_dai->comp.type = SOF_COMP_DAI; - comp_dai->config.hdr.size = sizeof(comp_dai->config); - - ret = sof_parse_tokens(scomp, comp_dai, dai_tokens, - ARRAY_SIZE(dai_tokens), private->array, - le32_to_cpu(private->size)); + ret = sof_parse_tokens_new(scomp, NULL, dai_tokens_new, + ARRAY_SIZE(dai_tokens_new), private->array, + le32_to_cpu(private->size), &dai->tuples, + &dai->num_tuples); if (ret != 0) { dev_err(scomp->dev, "error: parse dai tokens failed %d\n", le32_to_cpu(private->size)); - goto finish; + return ret; } - ret = sof_parse_tokens(scomp, &comp_dai->config, comp_tokens, - ARRAY_SIZE(comp_tokens), private->array, - le32_to_cpu(private->size)); + ret = sof_parse_tokens_new(scomp, NULL, comp_tokens_new, + ARRAY_SIZE(comp_tokens_new), private->array, + le32_to_cpu(private->size), &dai->tuples, + &dai->num_tuples); if (ret != 0) { dev_err(scomp->dev, "error: parse dai.cfg tokens failed %d\n", private->size); - goto finish; + return ret; } - dev_dbg(scomp->dev, "dai %s: type %d index %d\n", - swidget->widget->name, comp_dai->type, comp_dai->dai_index); - sof_dbg_comp_config(scomp, &comp_dai->config); - - if (dai) { + if (dai) dai->scomp = scomp; - /* - * copy only the sof_ipc_comp_dai to avoid collapsing - * the snd_sof_dai, the extended data is kept in the - * snd_sof_widget. - */ - memcpy(&dai->comp_dai, comp_dai, sizeof(*comp_dai)); - } - -finish: - kfree(comp_dai); return ret; } @@ -2567,6 +2562,7 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index, } list_add(&dai->list, &sdev->dai_list); swidget->private = dai; + sof_widget_update_ipc_comp_dai(scomp, swidget); break; case snd_soc_dapm_mixer: ret = sof_widget_load_mixer(scomp, index, swidget, tw); From 37a483c64bd5d9b4089631ae28687c32beed9df6 Mon Sep 17 00:00:00 2001 From: Bard Liao Date: Tue, 23 Nov 2021 14:52:03 +0800 Subject: [PATCH 6/8] ASoC: SOF: topology: use sof_parse_tokens_new in sof_parse_tokens_new This will be squashed to previous commit. Signed-off-by: Bard Liao --- sound/soc/sof/ipc3-topology.c | 52 ++++++++++++++++++++++++++ sound/soc/sof/sof-audio.h | 8 ++++ sound/soc/sof/topology.c | 69 +++++++++-------------------------- 3 files changed, 78 insertions(+), 51 deletions(-) diff --git a/sound/soc/sof/ipc3-topology.c b/sound/soc/sof/ipc3-topology.c index e8ca9ec1735bdf..1454042b323900 100644 --- a/sound/soc/sof/ipc3-topology.c +++ b/sound/soc/sof/ipc3-topology.c @@ -84,3 +84,55 @@ int sof_widget_update_ipc_comp_dai(struct snd_soc_component *scomp, sof_dbg_comp_config(scomp, &comp_dai->config); return 0; } + +int sof_widget_update_ipc_comp_pipeline(struct snd_soc_component *scomp, + struct snd_sof_widget *swidget) +{ + struct sof_ipc_pipe_new *pipeline; + struct snd_sof_widget *comp_swidget; + size_t ipc_size = sizeof(*pipeline); + + pipeline = (struct sof_ipc_pipe_new *) + sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id); + if (!pipeline) + return -ENOMEM; + + /* configure dai IPC message */ + pipeline->hdr.size = sizeof(*pipeline); + pipeline->hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_PIPE_NEW; + pipeline->pipeline_id = swidget->pipeline_id; + pipeline->comp_id = swidget->comp_id; + + /* component at start of pipeline is our stream id */ + comp_swidget = snd_sof_find_swidget(scomp, swidget->sname);; + + if (!comp_swidget) { + dev_err(scomp->dev, "error: widget %s refers to non existent widget %s\n", + swidget->widget->name, swidget->sname); + return -EINVAL; + } + + pipeline->sched_id = comp_swidget->comp_id; + + sof_update_ipc_object(pipeline, sched_tokens, sched_token_size, swidget->num_tuples, + swidget->tuples, sizeof(*pipeline), 1); + + sof_update_ipc_object(swidget, pipeline_tokens, pipeline_token_size, swidget->num_tuples, + swidget->tuples, sizeof(*swidget), 1); + + if (sof_debug_check_flag(SOF_DBG_DISABLE_MULTICORE)) + pipeline->core = SOF_DSP_PRIMARY_CORE; + + if (sof_debug_check_flag(SOF_DBG_DYNAMIC_PIPELINES_OVERRIDE)) + swidget->dynamic_pipeline_widget = + sof_debug_check_flag(SOF_DBG_DYNAMIC_PIPELINES_ENABLE); + + dev_dbg(scomp->dev, "pipeline %s: period %d pri %d mips %d core %d frames %d dynamic %d\n", + swidget->widget->name, pipeline->period, pipeline->priority, + pipeline->period_mips, pipeline->core, pipeline->frames_per_sched, + swidget->dynamic_pipeline_widget); + + swidget->private = pipeline; + + return 0; +} diff --git a/sound/soc/sof/sof-audio.h b/sound/soc/sof/sof-audio.h index 18e281f0bfff9b..62299d716877c8 100644 --- a/sound/soc/sof/sof-audio.h +++ b/sound/soc/sof/sof-audio.h @@ -54,10 +54,14 @@ struct snd_sof_tuple { extern const struct sof_topology_token pcm_tokens[]; extern const struct sof_topology_token dai_tokens_new[]; +extern const struct sof_topology_token sched_tokens[]; +extern const struct sof_topology_token pipeline_tokens[]; extern const struct sof_topology_token comp_tokens_new[]; extern int pcm_token_size; extern int comp_token_size; extern int dai_token_size; +extern int sched_token_size; +extern int pipeline_token_size; /* PCM stream, mapped to FW component */ struct snd_sof_pcm_stream { @@ -148,6 +152,8 @@ struct snd_sof_widget { struct snd_sof_tuple *tuples; + char sname[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; + void *private; /* core does not touch this */ }; @@ -305,6 +311,8 @@ int sof_widget_update_ipc_comp_host(struct snd_soc_component *scomp, struct snd_sof_widget *swidget); int sof_widget_update_ipc_comp_dai(struct snd_soc_component *scomp, struct snd_sof_widget *swidget); +int sof_widget_update_ipc_comp_pipeline(struct snd_soc_component *scomp, + struct snd_sof_widget *swidget); void sof_dbg_comp_config(struct snd_soc_component *scomp, struct sof_ipc_comp_config *config); void sof_update_ipc_object(void *object, const struct sof_topology_token *tokens, int count, int num_tuples, struct snd_sof_tuple *tuples, diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c index d1f9f71bcc1e9c..2e60b6d5319ee9 100644 --- a/sound/soc/sof/topology.c +++ b/sound/soc/sof/topology.c @@ -572,7 +572,7 @@ static const struct sof_topology_token dai_link_tokens[] = { }; /* scheduling */ -static const struct sof_topology_token sched_tokens[] = { +const struct sof_topology_token sched_tokens[] = { {SOF_TKN_SCHED_PERIOD, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32, offsetof(struct sof_ipc_pipe_new, period), 0}, {SOF_TKN_SCHED_PRIORITY, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32, @@ -586,12 +586,14 @@ static const struct sof_topology_token sched_tokens[] = { {SOF_TKN_SCHED_TIME_DOMAIN, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32, offsetof(struct sof_ipc_pipe_new, time_domain), 0}, }; +int sched_token_size = ARRAY_SIZE(sched_tokens); -static const struct sof_topology_token pipeline_tokens[] = { +const struct sof_topology_token pipeline_tokens[] = { {SOF_TKN_SCHED_DYNAMIC_PIPELINE, SND_SOC_TPLG_TUPLE_TYPE_BOOL, get_token_u16, offsetof(struct snd_sof_widget, dynamic_pipeline_widget), 0}, }; +int pipeline_token_size = ARRAY_SIZE(pipeline_tokens); /* volume */ static const struct sof_topology_token volume_tokens[] = { @@ -1882,70 +1884,32 @@ static int sof_widget_load_pipeline(struct snd_soc_component *scomp, int index, struct snd_soc_tplg_dapm_widget *tw) { struct snd_soc_tplg_private *private = &tw->priv; - struct sof_ipc_pipe_new *pipeline; - struct snd_sof_widget *comp_swidget; int ret; - pipeline = kzalloc(sizeof(*pipeline), GFP_KERNEL); - if (!pipeline) - return -ENOMEM; - - /* configure dai IPC message */ - pipeline->hdr.size = sizeof(*pipeline); - pipeline->hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_PIPE_NEW; - pipeline->pipeline_id = index; - pipeline->comp_id = swidget->comp_id; - - /* component at start of pipeline is our stream id */ - comp_swidget = snd_sof_find_swidget(scomp, tw->sname); - if (!comp_swidget) { - dev_err(scomp->dev, "error: widget %s refers to non existent widget %s\n", - tw->name, tw->sname); - ret = -EINVAL; - goto err; - } - - pipeline->sched_id = comp_swidget->comp_id; + memcpy(swidget->sname, tw->sname, sizeof(tw->sname)); - dev_dbg(scomp->dev, "tplg: pipeline id %d comp %d scheduling comp id %d\n", - pipeline->pipeline_id, pipeline->comp_id, pipeline->sched_id); - - ret = sof_parse_tokens(scomp, pipeline, sched_tokens, - ARRAY_SIZE(sched_tokens), private->array, - le32_to_cpu(private->size)); + ret = sof_parse_tokens_new(scomp, NULL, sched_tokens, + ARRAY_SIZE(sched_tokens), private->array, + le32_to_cpu(private->size), &swidget->tuples, + &swidget->num_tuples); if (ret != 0) { dev_err(scomp->dev, "error: parse pipeline tokens failed %d\n", private->size); - goto err; + return ret; } - ret = sof_parse_tokens(scomp, swidget, pipeline_tokens, - ARRAY_SIZE(pipeline_tokens), private->array, - le32_to_cpu(private->size)); + ret = sof_parse_tokens_new(scomp, NULL, pipeline_tokens, + ARRAY_SIZE(pipeline_tokens), private->array, + le32_to_cpu(private->size), &swidget->tuples, + &swidget->num_tuples); if (ret != 0) { dev_err(scomp->dev, "error: parse dynamic pipeline token failed %d\n", private->size); - goto err; + return ret; } - if (sof_debug_check_flag(SOF_DBG_DISABLE_MULTICORE)) - pipeline->core = SOF_DSP_PRIMARY_CORE; - - if (sof_debug_check_flag(SOF_DBG_DYNAMIC_PIPELINES_OVERRIDE)) - swidget->dynamic_pipeline_widget = - sof_debug_check_flag(SOF_DBG_DYNAMIC_PIPELINES_ENABLE); - - dev_dbg(scomp->dev, "pipeline %s: period %d pri %d mips %d core %d frames %d dynamic %d\n", - swidget->widget->name, pipeline->period, pipeline->priority, - pipeline->period_mips, pipeline->core, pipeline->frames_per_sched, - swidget->dynamic_pipeline_widget); - - swidget->private = pipeline; return 0; -err: - kfree(pipeline); - return ret; } /* @@ -3762,6 +3726,9 @@ static int sof_complete(struct snd_soc_component *scomp) case snd_soc_dapm_aif_out: sof_widget_update_ipc_comp_host(scomp, swidget); break; + case snd_soc_dapm_scheduler: + sof_widget_update_ipc_comp_pipeline(scomp, swidget); + break; default: break; } From b1ee02ec202ed379186cbb82f50a354433942858 Mon Sep 17 00:00:00 2001 From: Bard Liao Date: Tue, 23 Nov 2021 18:45:51 +0800 Subject: [PATCH 7/8] ASoC: SOF: topology: add sof_widget_update_ipc_comp_mixer This will be squashed to previous commit. Signed-off-by: Bard Liao --- sound/soc/sof/ipc3-topology.c | 25 +++++++++++++++++++++++++ sound/soc/sof/sof-audio.h | 2 ++ sound/soc/sof/topology.c | 26 +++++++------------------- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/sound/soc/sof/ipc3-topology.c b/sound/soc/sof/ipc3-topology.c index 1454042b323900..5bb239895287f1 100644 --- a/sound/soc/sof/ipc3-topology.c +++ b/sound/soc/sof/ipc3-topology.c @@ -136,3 +136,28 @@ int sof_widget_update_ipc_comp_pipeline(struct snd_soc_component *scomp, return 0; } + +int sof_widget_update_ipc_comp_mixer(struct snd_soc_component *scomp, + struct snd_sof_widget *swidget) +{ + struct sof_ipc_comp_mixer *mixer; + size_t ipc_size = sizeof(*mixer); + + mixer = (struct sof_ipc_comp_mixer *) + sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id); + if (!mixer) + return -ENOMEM; + + /* configure mixer IPC message */ + mixer->comp.type = SOF_COMP_MIXER; + mixer->config.hdr.size = sizeof(mixer->config); + + sof_update_ipc_object(&mixer->config, comp_tokens_new, comp_token_size, swidget->num_tuples, + swidget->tuples, sizeof(mixer->config), 1); + + sof_dbg_comp_config(scomp, &mixer->config); + + swidget->private = mixer; + + return 0; +} diff --git a/sound/soc/sof/sof-audio.h b/sound/soc/sof/sof-audio.h index 62299d716877c8..50d551226bb91d 100644 --- a/sound/soc/sof/sof-audio.h +++ b/sound/soc/sof/sof-audio.h @@ -313,6 +313,8 @@ int sof_widget_update_ipc_comp_dai(struct snd_soc_component *scomp, struct snd_sof_widget *swidget); int sof_widget_update_ipc_comp_pipeline(struct snd_soc_component *scomp, struct snd_sof_widget *swidget); +int sof_widget_update_ipc_comp_mixer(struct snd_soc_component *scomp, + struct snd_sof_widget *swidget); void sof_dbg_comp_config(struct snd_soc_component *scomp, struct sof_ipc_comp_config *config); void sof_update_ipc_object(void *object, const struct sof_topology_token *tokens, int count, int num_tuples, struct snd_sof_tuple *tuples, diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c index 2e60b6d5319ee9..55daaa34d60811 100644 --- a/sound/soc/sof/topology.c +++ b/sound/soc/sof/topology.c @@ -1921,33 +1921,18 @@ static int sof_widget_load_mixer(struct snd_soc_component *scomp, int index, struct snd_soc_tplg_dapm_widget *tw) { struct snd_soc_tplg_private *private = &tw->priv; - struct sof_ipc_comp_mixer *mixer; - size_t ipc_size = sizeof(*mixer); int ret; - mixer = (struct sof_ipc_comp_mixer *) - sof_comp_alloc(swidget, &ipc_size, index); - if (!mixer) - return -ENOMEM; - - /* configure mixer IPC message */ - mixer->comp.type = SOF_COMP_MIXER; - mixer->config.hdr.size = sizeof(mixer->config); - - ret = sof_parse_tokens(scomp, &mixer->config, comp_tokens, - ARRAY_SIZE(comp_tokens), private->array, - le32_to_cpu(private->size)); + ret = sof_parse_tokens_new(scomp, NULL, comp_tokens, + ARRAY_SIZE(comp_tokens), private->array, + le32_to_cpu(private->size), &swidget->tuples, + &swidget->num_tuples); if (ret != 0) { dev_err(scomp->dev, "error: parse mixer.cfg tokens failed %d\n", private->size); - kfree(mixer); return ret; } - sof_dbg_comp_config(scomp, &mixer->config); - - swidget->private = mixer; - return 0; } @@ -3729,6 +3714,9 @@ static int sof_complete(struct snd_soc_component *scomp) case snd_soc_dapm_scheduler: sof_widget_update_ipc_comp_pipeline(scomp, swidget); break; + case snd_soc_dapm_mixer: + sof_widget_update_ipc_comp_mixer(scomp, swidget); + break; default: break; } From 3d154859da1ef42f4c72ea59897a9a774cbdcda8 Mon Sep 17 00:00:00 2001 From: Bard Liao Date: Tue, 23 Nov 2021 19:41:12 +0800 Subject: [PATCH 8/8] ASoC: SOF: topology: add sof_widget_update_ipc_comp_pga This will be squashed to previous commit. Signed-off-by: Bard Liao --- sound/soc/sof/ipc3-topology.c | 43 +++++++++++++++++++++++++ sound/soc/sof/sof-audio.h | 4 +++ sound/soc/sof/topology.c | 60 ++++++++++------------------------- 3 files changed, 63 insertions(+), 44 deletions(-) diff --git a/sound/soc/sof/ipc3-topology.c b/sound/soc/sof/ipc3-topology.c index 5bb239895287f1..2c44310fae3cc3 100644 --- a/sound/soc/sof/ipc3-topology.c +++ b/sound/soc/sof/ipc3-topology.c @@ -161,3 +161,46 @@ int sof_widget_update_ipc_comp_mixer(struct snd_soc_component *scomp, return 0; } +int sof_widget_update_ipc_comp_pga(struct snd_soc_component *scomp, + struct snd_sof_widget *swidget) +{ + struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp); + struct sof_ipc_comp_volume *volume; + struct snd_sof_control *scontrol; + size_t ipc_size = sizeof(*volume); + int min_step; + int max_step; + + volume = (struct sof_ipc_comp_volume *) + sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id); + if (!volume) + return -ENOMEM; + + /* configure volume IPC message */ + volume->comp.type = SOF_COMP_VOLUME; + volume->config.hdr.size = sizeof(volume->config); + + sof_update_ipc_object(volume, volume_tokens, volume_token_size, swidget->num_tuples, + swidget->tuples, sizeof(*volume), 1); + + sof_update_ipc_object(&volume->config, comp_tokens_new, comp_token_size, swidget->num_tuples, + swidget->tuples, sizeof(volume->config), 1); + + sof_dbg_comp_config(scomp, &volume->config); + + swidget->private = volume; + + list_for_each_entry(scontrol, &sdev->kcontrol_list, list) { + if (scontrol->comp_id == swidget->comp_id && + scontrol->volume_table) { + min_step = scontrol->min_volume_step; + max_step = scontrol->max_volume_step; + volume->min_value = scontrol->volume_table[min_step]; + volume->max_value = scontrol->volume_table[max_step]; + volume->channels = scontrol->num_channels; + break; + } + } + + return 0; +} diff --git a/sound/soc/sof/sof-audio.h b/sound/soc/sof/sof-audio.h index 50d551226bb91d..7c9f9ea2b944ae 100644 --- a/sound/soc/sof/sof-audio.h +++ b/sound/soc/sof/sof-audio.h @@ -56,12 +56,14 @@ extern const struct sof_topology_token pcm_tokens[]; extern const struct sof_topology_token dai_tokens_new[]; extern const struct sof_topology_token sched_tokens[]; extern const struct sof_topology_token pipeline_tokens[]; +extern const struct sof_topology_token volume_tokens[]; extern const struct sof_topology_token comp_tokens_new[]; extern int pcm_token_size; extern int comp_token_size; extern int dai_token_size; extern int sched_token_size; extern int pipeline_token_size; +extern int volume_token_size; /* PCM stream, mapped to FW component */ struct snd_sof_pcm_stream { @@ -315,6 +317,8 @@ int sof_widget_update_ipc_comp_pipeline(struct snd_soc_component *scomp, struct snd_sof_widget *swidget); int sof_widget_update_ipc_comp_mixer(struct snd_soc_component *scomp, struct snd_sof_widget *swidget); +int sof_widget_update_ipc_comp_pga(struct snd_soc_component *scomp, + struct snd_sof_widget *swidget); void sof_dbg_comp_config(struct snd_soc_component *scomp, struct sof_ipc_comp_config *config); void sof_update_ipc_object(void *object, const struct sof_topology_token *tokens, int count, int num_tuples, struct snd_sof_tuple *tuples, diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c index 55daaa34d60811..0bdd4fb5aa9819 100644 --- a/sound/soc/sof/topology.c +++ b/sound/soc/sof/topology.c @@ -596,13 +596,14 @@ const struct sof_topology_token pipeline_tokens[] = { int pipeline_token_size = ARRAY_SIZE(pipeline_tokens); /* volume */ -static const struct sof_topology_token volume_tokens[] = { +const struct sof_topology_token volume_tokens[] = { {SOF_TKN_VOLUME_RAMP_STEP_TYPE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32, offsetof(struct sof_ipc_comp_volume, ramp), 0}, {SOF_TKN_VOLUME_RAMP_STEP_MS, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32, offsetof(struct sof_ipc_comp_volume, initial_ramp), 0}, }; +int volume_token_size = ARRAY_SIZE(volume_tokens); /* SRC */ static const struct sof_topology_token src_tokens[] = { @@ -1982,68 +1983,36 @@ static int sof_widget_load_pga(struct snd_soc_component *scomp, int index, struct snd_sof_widget *swidget, struct snd_soc_tplg_dapm_widget *tw) { - struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp); struct snd_soc_tplg_private *private = &tw->priv; - struct sof_ipc_comp_volume *volume; - struct snd_sof_control *scontrol; - size_t ipc_size = sizeof(*volume); - int min_step; - int max_step; int ret; - volume = (struct sof_ipc_comp_volume *) - sof_comp_alloc(swidget, &ipc_size, index); - if (!volume) - return -ENOMEM; - if (!le32_to_cpu(tw->num_kcontrols)) { dev_err(scomp->dev, "error: invalid kcontrol count %d for volume\n", tw->num_kcontrols); - ret = -EINVAL; - goto err; + return -EINVAL; } - /* configure volume IPC message */ - volume->comp.type = SOF_COMP_VOLUME; - volume->config.hdr.size = sizeof(volume->config); - - ret = sof_parse_tokens(scomp, volume, volume_tokens, - ARRAY_SIZE(volume_tokens), private->array, - le32_to_cpu(private->size)); + ret = sof_parse_tokens_new(scomp, NULL, volume_tokens, + ARRAY_SIZE(volume_tokens), private->array, + le32_to_cpu(private->size), &swidget->tuples, + &swidget->num_tuples); if (ret != 0) { dev_err(scomp->dev, "error: parse volume tokens failed %d\n", private->size); - goto err; + return ret; } - ret = sof_parse_tokens(scomp, &volume->config, comp_tokens, - ARRAY_SIZE(comp_tokens), private->array, - le32_to_cpu(private->size)); + ret = sof_parse_tokens_new(scomp, NULL, comp_tokens_new, + ARRAY_SIZE(comp_tokens_new), private->array, + le32_to_cpu(private->size), &swidget->tuples, + &swidget->num_tuples); if (ret != 0) { dev_err(scomp->dev, "error: parse volume.cfg tokens failed %d\n", le32_to_cpu(private->size)); - goto err; + return ret; } - sof_dbg_comp_config(scomp, &volume->config); - - swidget->private = volume; - - list_for_each_entry(scontrol, &sdev->kcontrol_list, list) { - if (scontrol->comp_id == swidget->comp_id && - scontrol->volume_table) { - min_step = scontrol->min_volume_step; - max_step = scontrol->max_volume_step; - volume->min_value = scontrol->volume_table[min_step]; - volume->max_value = scontrol->volume_table[max_step]; - volume->channels = scontrol->num_channels; - break; - } - } return 0; -err: - kfree(volume); - return ret; } /* @@ -3717,6 +3686,9 @@ static int sof_complete(struct snd_soc_component *scomp) case snd_soc_dapm_mixer: sof_widget_update_ipc_comp_mixer(scomp, swidget); break; + case snd_soc_dapm_pga: + sof_widget_update_ipc_comp_pga(scomp, swidget); + break; default: break; }