From patchwork Mon Nov 7 08:57:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Ujfalusi X-Patchwork-Id: 622268 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 10829C433FE for ; Mon, 7 Nov 2022 08:58:03 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 2910B847; Mon, 7 Nov 2022 09:57:12 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 2910B847 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1667811482; bh=6NOLQiprxbWl7gm5hGQ0fDn+Emygk2yamV9KwTqXbqo=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=gWuAP9bJcLfXPQXDetnhAwARpUFvN8eHPe0dXODcAwGAQlE+byf87NAR46YONZhJt Y+kCqrr6NWQws1hvN8/98D3euS+EcgNhLn6IrmY+zpdQm76t3HftkULOYl4CUlrc4i MEGdcryS5z/UhkoJSYDLAU8Fkw6/ykqT/giX0pxg= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id A4E97F8051D; Mon, 7 Nov 2022 09:56:53 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 73862F804D0; Mon, 7 Nov 2022 09:56:52 +0100 (CET) Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id AAC2AF8025A for ; Mon, 7 Nov 2022 09:56:45 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz AAC2AF8025A Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ahjkaq/M" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667811406; x=1699347406; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6NOLQiprxbWl7gm5hGQ0fDn+Emygk2yamV9KwTqXbqo=; b=ahjkaq/MUIKxshlOJXZyh0pykJ0ovgs45leYsRJ5KjhUmrdXsXyiq2NC Yqz0XzxYXmiRbpA8+1qcqKvJbf8yl3erxaH9zFZEWfnUFk3TMiL05L9cK U9JHfR4UPivEzaiM5kcHWAup1Rl6urLxBYCKxc2xnteXOrWEKJ4XD7WTd hXPblVtsBsBmeFyMAOK8wDlr6LOja1a/9ZQXDpXpw38i/LNOVJZZeSGqh EewPCFuvxHLcTusuHq37zjCRb11R6tgYn06i6P3e9LxRpU8jAciY8wUH3 AG3n4faIhJKM0ksgnuKdpsTzqkv5VuMDRkUAp3qH88hnytEJgwlX2ETCS w==; X-IronPort-AV: E=McAfee;i="6500,9779,10523"; a="372481171" X-IronPort-AV: E=Sophos;i="5.96,143,1665471600"; d="scan'208";a="372481171" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Nov 2022 00:56:43 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10523"; a="635831444" X-IronPort-AV: E=Sophos;i="5.96,143,1665471600"; d="scan'208";a="635831444" Received: from akharade-mobl.ger.corp.intel.com (HELO pujfalus-desk.ger.corp.intel.com) ([10.252.14.37]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Nov 2022 00:56:40 -0800 From: Peter Ujfalusi To: lgirdwood@gmail.com, broonie@kernel.org, chao.song@linux.intel.com Subject: [PATCH 1/3] ASoC: SOF: Add support for parsing the number of sink/source pins Date: Mon, 7 Nov 2022 10:57:04 +0200 Message-Id: <20221107085706.2550-2-peter.ujfalusi@linux.intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221107085706.2550-1-peter.ujfalusi@linux.intel.com> References: <20221107085706.2550-1-peter.ujfalusi@linux.intel.com> MIME-Version: 1.0 Cc: alsa-devel@alsa-project.org, kai.vehmanen@linux.intel.com, pierre-louis.bossart@linux.intel.com, rander.wang@intel.com, ranjani.sridharan@linux.intel.com, yung-chuan.liao@linux.intel.com X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" From: Chao Song Add support for parsing the number of sink/source pins per widget from topology. They will be used to determine the sink/source queue IDs during widget binding. Signed-off-by: Bard Liao Signed-off-by: Chao Song Suggested-by: Ranjani Sridharan Reviewed-by: Pierre-Louis Bossart Reviewed-by: Rander Wang Reviewed-by: Péter Ujfalusi Signed-off-by: Peter Ujfalusi --- include/uapi/sound/sof/tokens.h | 2 ++ sound/soc/sof/sof-audio.h | 15 +++++++++++++++ sound/soc/sof/topology.c | 33 +++++++++++++++++++++++++++++---- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/include/uapi/sound/sof/tokens.h b/include/uapi/sound/sof/tokens.h index 5caf75cadaf8..4f4881850650 100644 --- a/include/uapi/sound/sof/tokens.h +++ b/include/uapi/sound/sof/tokens.h @@ -88,6 +88,8 @@ #define SOF_TKN_COMP_CPC 406 #define SOF_TKN_COMP_IS_PAGES 409 #define SOF_TKN_COMP_NUM_AUDIO_FORMATS 410 +#define SOF_TKN_COMP_NUM_SINK_PINS 411 +#define SOF_TKN_COMP_NUM_SOURCE_PINS 412 /* SSP */ #define SOF_TKN_INTEL_SSP_CLKS_CONTROL 500 diff --git a/sound/soc/sof/sof-audio.h b/sound/soc/sof/sof-audio.h index 4284ea2f3a1f..dfca713f00df 100644 --- a/sound/soc/sof/sof-audio.h +++ b/sound/soc/sof/sof-audio.h @@ -23,6 +23,13 @@ #define SOF_AUDIO_PCM_DRV_NAME "sof-audio-component" +/* + * The ipc4 firmware only supports up to 8 sink or source pins + * per widget, because only 3 bits are used for queue(pin) ID + * in ipc4 protocol. + */ +#define SOF_WIDGET_MAX_NUM_PINS 8 + /* max number of FE PCMs before BEs */ #define SOF_BE_PCM_BASE 16 @@ -387,6 +394,14 @@ struct snd_sof_widget { int num_tuples; struct snd_sof_tuple *tuples; + /* + * The allowed range for num_sink/source_pins is [0, SOF_WIDGET_MAX_NUM_PINS]. + * Widgets may have zero sink or source pins, for example the tone widget has + * zero sink pins. + */ + u32 num_sink_pins; + u32 num_source_pins; + void *private; /* core does not touch this */ }; diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c index 38855dd60617..e839fcdc938b 100644 --- a/sound/soc/sof/topology.c +++ b/sound/soc/sof/topology.c @@ -392,6 +392,13 @@ static const struct sof_topology_token led_tokens[] = { offsetof(struct snd_sof_led_control, direction)}, }; +static const struct sof_topology_token comp_pin_tokens[] = { + {SOF_TKN_COMP_NUM_SINK_PINS, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32, + offsetof(struct snd_sof_widget, num_sink_pins)}, + {SOF_TKN_COMP_NUM_SOURCE_PINS, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32, + offsetof(struct snd_sof_widget, num_source_pins)}, +}; + /** * sof_parse_uuid_tokens - Parse multiple sets of UUID tokens * @scomp: pointer to soc component @@ -1259,6 +1266,7 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index, struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp); const struct sof_ipc_tplg_ops *ipc_tplg_ops = sdev->ipc->ops->tplg; const struct sof_ipc_tplg_widget_ops *widget_ops = ipc_tplg_ops->widget; + struct snd_soc_tplg_private *priv = &tw->priv; struct snd_sof_widget *swidget; struct snd_sof_dai *dai; enum sof_tokens *token_list; @@ -1277,10 +1285,27 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index, swidget->pipeline_id = index; swidget->private = NULL; - dev_dbg(scomp->dev, "tplg: ready widget id %d pipe %d type %d name : %s stream %s\n", - swidget->comp_id, index, swidget->id, tw->name, - strnlen(tw->sname, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) > 0 - ? tw->sname : "none"); + ret = sof_parse_tokens(scomp, swidget, comp_pin_tokens, + ARRAY_SIZE(comp_pin_tokens), priv->array, + le32_to_cpu(priv->size)); + if (ret < 0) { + dev_err(scomp->dev, "failed to parse component pin tokens for %s\n", + w->name); + return ret; + } + + if (swidget->num_sink_pins > SOF_WIDGET_MAX_NUM_PINS || + swidget->num_source_pins > SOF_WIDGET_MAX_NUM_PINS) { + dev_err(scomp->dev, "invalid pins for %s: [sink: %d, src: %d]\n", + swidget->widget->name, swidget->num_sink_pins, swidget->num_source_pins); + return -EINVAL; + } + + dev_dbg(scomp->dev, + "tplg: widget %d (%s) is ready [type: %d, pipe: %d, pins: %d / %d, stream: %s]\n", + swidget->comp_id, w->name, swidget->id, index, + swidget->num_sink_pins, swidget->num_source_pins, + strnlen(w->sname, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) > 0 ? w->sname : "none"); token_list = widget_ops[w->id].token_list; token_list_size = widget_ops[w->id].token_list_size; From patchwork Mon Nov 7 08:57:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Ujfalusi X-Patchwork-Id: 622267 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 362D0C4332F for ; Mon, 7 Nov 2022 08:58:36 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 57B4A86F; Mon, 7 Nov 2022 09:57:44 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 57B4A86F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1667811514; bh=8AdWr6gsw1IbehCj2aqwWLhJNGiYdPitsUyC103G0QU=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=OeV4owiu6WJTApWi/TWGoAWUTN9KCB5n2yTId/gr1DxUD/idO0xwnh9m6zvBP+IQA Wy2D0YNit6/GEU/PvQoighGDfWCeTn22tB2FHSlckhjWKabmtnGwxpPF6gkc/UTqDp LIdQwrdSqKoZrv6GzOzgLphmn0BTni4qI6tLySqc= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id D3298F8055A; Mon, 7 Nov 2022 09:56:57 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 562CAF80557; Mon, 7 Nov 2022 09:56:55 +0100 (CET) Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 7C86DF8024C for ; Mon, 7 Nov 2022 09:56:51 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 7C86DF8024C Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="NvxQyLeV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667811412; x=1699347412; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8AdWr6gsw1IbehCj2aqwWLhJNGiYdPitsUyC103G0QU=; b=NvxQyLeVAaBww2Oi+DJ89tHyipAew2QPaMrQHtZioHTjtzEwOijgDG0W Fdy6DyWd/A1p32up0VviRbiQb7hCvilpzeX5IhRL6LKNZV6pCYlfdK8V9 W+j3F3fuqXV9wFChUMyUuPUL4daNcPtIvSC4rd2fB1z5NCnYsY4A76H80 2jpc3woZD2JgH9cIqiQjhIvPIYiddUzgA5Vj+hsbbof3Cb4c/OAhwXkcU C1zPO9Lz22CmADYmebOnEzl738d5mOFYaiDvmklmveOpazJEwU35/28qn 5fa+OMl4BaS5h2UsN4UJ19j39NmgTCPp1q7BN8hRzsdIrD+pN+TzeNTH8 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10523"; a="372481190" X-IronPort-AV: E=Sophos;i="5.96,143,1665471600"; d="scan'208";a="372481190" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Nov 2022 00:56:49 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10523"; a="635831466" X-IronPort-AV: E=Sophos;i="5.96,143,1665471600"; d="scan'208";a="635831466" Received: from akharade-mobl.ger.corp.intel.com (HELO pujfalus-desk.ger.corp.intel.com) ([10.252.14.37]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Nov 2022 00:56:46 -0800 From: Peter Ujfalusi To: lgirdwood@gmail.com, broonie@kernel.org, chao.song@linux.intel.com Subject: [PATCH 3/3] ASoC: SOF: topology: Add helper to get/put widget queue id Date: Mon, 7 Nov 2022 10:57:06 +0200 Message-Id: <20221107085706.2550-4-peter.ujfalusi@linux.intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221107085706.2550-1-peter.ujfalusi@linux.intel.com> References: <20221107085706.2550-1-peter.ujfalusi@linux.intel.com> MIME-Version: 1.0 Cc: alsa-devel@alsa-project.org, kai.vehmanen@linux.intel.com, pierre-louis.bossart@linux.intel.com, rander.wang@intel.com, ranjani.sridharan@linux.intel.com, yung-chuan.liao@linux.intel.com X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" From: Chao Song Add get/put queue id helper to manage queue id in route setup and route free. The queue allocation rules are: - If widget only has one sink/source pin, zero will be returned as the queue ID directly. - If widget has more than one sink/source pins, and pin binding array is defined in topology, queue ID will be allocated according to the pin binding array. - If widget has more than one sink/sink pins, and pin binding array is not defined, Linux ID allocation will be used to allocate queue ID dynamically. Signed-off-by: Chao Song Signed-off-by: Bard Liao Suggested-by: Ranjani Sridharan Reviewed-by: Pierre-Louis Bossart Reviewed-by: Rander Wang Reviewed-by: Péter Ujfalusi Signed-off-by: Peter Ujfalusi --- sound/soc/sof/ipc4-topology.c | 133 ++++++++++++++++++++++++++++++---- sound/soc/sof/sof-audio.h | 6 ++ sound/soc/sof/topology.c | 5 ++ 3 files changed, 131 insertions(+), 13 deletions(-) diff --git a/sound/soc/sof/ipc4-topology.c b/sound/soc/sof/ipc4-topology.c index ab85dde4303b..92b5f934d20f 100644 --- a/sound/soc/sof/ipc4-topology.c +++ b/sound/soc/sof/ipc4-topology.c @@ -1577,6 +1577,88 @@ static int sof_ipc4_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget return ret; } +static int sof_ipc4_get_queue_id(struct snd_sof_widget *src_widget, + struct snd_sof_widget *sink_widget, bool pin_type) +{ + struct snd_sof_widget *current_swidget; + struct snd_soc_component *scomp; + struct ida *queue_ida; + const char *buddy_name; + char **pin_binding; + u32 num_pins; + int i; + + if (pin_type == SOF_PIN_TYPE_SOURCE) { + current_swidget = src_widget; + pin_binding = src_widget->src_pin_binding; + queue_ida = &src_widget->src_queue_ida; + num_pins = src_widget->num_source_pins; + buddy_name = sink_widget->widget->name; + } else { + current_swidget = sink_widget; + pin_binding = sink_widget->sink_pin_binding; + queue_ida = &sink_widget->sink_queue_ida; + num_pins = sink_widget->num_sink_pins; + buddy_name = src_widget->widget->name; + } + + scomp = current_swidget->scomp; + + if (num_pins < 1) { + dev_err(scomp->dev, "invalid %s num_pins: %d for queue allocation for %s\n", + (pin_type == SOF_PIN_TYPE_SOURCE ? "source" : "sink"), + num_pins, current_swidget->widget->name); + return -EINVAL; + } + + /* If there is only one sink/source pin, queue id must be 0 */ + if (num_pins == 1) + return 0; + + /* Allocate queue ID from pin binding array if it is defined in topology. */ + if (pin_binding) { + for (i = 0; i < num_pins; i++) { + if (!strcmp(pin_binding[i], buddy_name)) + return i; + } + /* + * Fail if no queue ID found from pin binding array, so that we don't + * mixed use pin binding array and ida for queue ID allocation. + */ + dev_err(scomp->dev, "no %s queue id found from pin binding array for %s\n", + (pin_type == SOF_PIN_TYPE_SOURCE ? "source" : "sink"), + current_swidget->widget->name); + return -EINVAL; + } + + /* If no pin binding array specified in topology, use ida to allocate one */ + return ida_alloc_max(queue_ida, num_pins, GFP_KERNEL); +} + +static void sof_ipc4_put_queue_id(struct snd_sof_widget *swidget, int queue_id, + bool pin_type) +{ + struct ida *queue_ida; + char **pin_binding; + int num_pins; + + if (pin_type == SOF_PIN_TYPE_SOURCE) { + pin_binding = swidget->src_pin_binding; + queue_ida = &swidget->src_queue_ida; + num_pins = swidget->num_source_pins; + } else { + pin_binding = swidget->sink_pin_binding; + queue_ida = &swidget->sink_queue_ida; + num_pins = swidget->num_sink_pins; + } + + /* Nothing to free if queue ID is not allocated with ida. */ + if (num_pins == 1 || pin_binding) + return; + + ida_free(queue_ida, queue_id); +} + static int sof_ipc4_route_setup(struct snd_sof_dev *sdev, struct snd_sof_route *sroute) { struct snd_sof_widget *src_widget = sroute->src_widget; @@ -1585,12 +1667,29 @@ static int sof_ipc4_route_setup(struct snd_sof_dev *sdev, struct snd_sof_route * struct sof_ipc4_fw_module *sink_fw_module = sink_widget->module_info; struct sof_ipc4_msg msg = {{ 0 }}; u32 header, extension; - int src_queue = 0; - int dst_queue = 0; int ret; - dev_dbg(sdev->dev, "bind %s -> %s\n", - src_widget->widget->name, sink_widget->widget->name); + sroute->src_queue_id = sof_ipc4_get_queue_id(src_widget, sink_widget, + SOF_PIN_TYPE_SOURCE); + if (sroute->src_queue_id < 0) { + dev_err(sdev->dev, "failed to get queue ID for source widget: %s\n", + src_widget->widget->name); + return sroute->src_queue_id; + } + + sroute->dst_queue_id = sof_ipc4_get_queue_id(src_widget, sink_widget, + SOF_PIN_TYPE_SINK); + if (sroute->dst_queue_id < 0) { + dev_err(sdev->dev, "failed to get queue ID for sink widget: %s\n", + sink_widget->widget->name); + sof_ipc4_put_queue_id(src_widget, sroute->src_queue_id, + SOF_PIN_TYPE_SOURCE); + return sroute->dst_queue_id; + } + + dev_dbg(sdev->dev, "bind %s:%d -> %s:%d\n", + src_widget->widget->name, sroute->src_queue_id, + sink_widget->widget->name, sroute->dst_queue_id); header = src_fw_module->man4_module_entry.id; header |= SOF_IPC4_MOD_INSTANCE(src_widget->instance_id); @@ -1600,17 +1699,23 @@ static int sof_ipc4_route_setup(struct snd_sof_dev *sdev, struct snd_sof_route * extension = sink_fw_module->man4_module_entry.id; extension |= SOF_IPC4_MOD_EXT_DST_MOD_INSTANCE(sink_widget->instance_id); - extension |= SOF_IPC4_MOD_EXT_DST_MOD_QUEUE_ID(dst_queue); - extension |= SOF_IPC4_MOD_EXT_SRC_MOD_QUEUE_ID(src_queue); + extension |= SOF_IPC4_MOD_EXT_DST_MOD_QUEUE_ID(sroute->dst_queue_id); + extension |= SOF_IPC4_MOD_EXT_SRC_MOD_QUEUE_ID(sroute->src_queue_id); msg.primary = header; msg.extension = extension; ret = sof_ipc_tx_message(sdev->ipc, &msg, 0, NULL, 0); - if (ret < 0) + if (ret < 0) { dev_err(sdev->dev, "%s: failed to bind modules %s -> %s\n", __func__, src_widget->widget->name, sink_widget->widget->name); + sof_ipc4_put_queue_id(src_widget, sroute->src_queue_id, + SOF_PIN_TYPE_SOURCE); + sof_ipc4_put_queue_id(sink_widget, sroute->dst_queue_id, + SOF_PIN_TYPE_SINK); + } + return ret; } @@ -1622,12 +1727,11 @@ static int sof_ipc4_route_free(struct snd_sof_dev *sdev, struct snd_sof_route *s struct sof_ipc4_fw_module *sink_fw_module = sink_widget->module_info; struct sof_ipc4_msg msg = {{ 0 }}; u32 header, extension; - int src_queue = 0; - int dst_queue = 0; int ret; - dev_dbg(sdev->dev, "unbind modules %s -> %s\n", - src_widget->widget->name, sink_widget->widget->name); + dev_dbg(sdev->dev, "unbind modules %s:%d -> %s:%d\n", + src_widget->widget->name, sroute->src_queue_id, + sink_widget->widget->name, sroute->dst_queue_id); header = src_fw_module->man4_module_entry.id; header |= SOF_IPC4_MOD_INSTANCE(src_widget->instance_id); @@ -1637,8 +1741,8 @@ static int sof_ipc4_route_free(struct snd_sof_dev *sdev, struct snd_sof_route *s extension = sink_fw_module->man4_module_entry.id; extension |= SOF_IPC4_MOD_EXT_DST_MOD_INSTANCE(sink_widget->instance_id); - extension |= SOF_IPC4_MOD_EXT_DST_MOD_QUEUE_ID(dst_queue); - extension |= SOF_IPC4_MOD_EXT_SRC_MOD_QUEUE_ID(src_queue); + extension |= SOF_IPC4_MOD_EXT_DST_MOD_QUEUE_ID(sroute->dst_queue_id); + extension |= SOF_IPC4_MOD_EXT_SRC_MOD_QUEUE_ID(sroute->src_queue_id); msg.primary = header; msg.extension = extension; @@ -1648,6 +1752,9 @@ static int sof_ipc4_route_free(struct snd_sof_dev *sdev, struct snd_sof_route *s dev_err(sdev->dev, "failed to unbind modules %s -> %s\n", src_widget->widget->name, sink_widget->widget->name); + sof_ipc4_put_queue_id(sink_widget, sroute->dst_queue_id, SOF_PIN_TYPE_SINK); + sof_ipc4_put_queue_id(src_widget, sroute->src_queue_id, SOF_PIN_TYPE_SOURCE); + return ret; } diff --git a/sound/soc/sof/sof-audio.h b/sound/soc/sof/sof-audio.h index efc80a5febc3..1b5b3ea53a6e 100644 --- a/sound/soc/sof/sof-audio.h +++ b/sound/soc/sof/sof-audio.h @@ -422,6 +422,9 @@ struct snd_sof_widget { char **sink_pin_binding; char **src_pin_binding; + struct ida src_queue_ida; + struct ida sink_queue_ida; + void *private; /* core does not touch this */ }; @@ -435,6 +438,9 @@ struct snd_sof_route { struct snd_sof_widget *sink_widget; bool setup; + int src_queue_id; + int dst_queue_id; + void *private; }; diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c index 3b1290d34131..176f64a86c26 100644 --- a/sound/soc/sof/topology.c +++ b/sound/soc/sof/topology.c @@ -1392,6 +1392,8 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index, swidget->id = w->id; swidget->pipeline_id = index; swidget->private = NULL; + ida_init(&swidget->src_queue_ida); + ida_init(&swidget->sink_queue_ida); ret = sof_parse_tokens(scomp, swidget, comp_pin_tokens, ARRAY_SIZE(comp_pin_tokens), priv->array, @@ -1624,6 +1626,9 @@ static int sof_widget_unload(struct snd_soc_component *scomp, if (widget_ops[swidget->id].ipc_free) widget_ops[swidget->id].ipc_free(swidget); + ida_destroy(&swidget->src_queue_ida); + ida_destroy(&swidget->sink_queue_ida); + sof_free_pin_binding(swidget, SOF_PIN_TYPE_SINK); sof_free_pin_binding(swidget, SOF_PIN_TYPE_SOURCE);