Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3990535rdh; Tue, 28 Nov 2023 08:57:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IGlaNIqoGgqbL+zggswD0V6E+uf7/uLR+WE0C4uYkJfwyJseXyOC47Mmy+LGqa+J+n0SWlP X-Received: by 2002:a17:90b:1c07:b0:285:a179:7218 with SMTP id oc7-20020a17090b1c0700b00285a1797218mr11891202pjb.9.1701190619720; Tue, 28 Nov 2023 08:56:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701190619; cv=none; d=google.com; s=arc-20160816; b=aF35QV5wP3Au+G+nI3sM1yW7KNuVK8a+78Q381ftSMEC91AfjaB/6bdXSc5DIRfAMn wO7j8Hrk73dxQOHuUZUJvyaXnqztIJ9yYSc4p0/cknCgIvAXGkTzPLsT5WhZJfyIkJ/u m7mX4/ydAEq4b7Km8lAXCMy4Ao7tORe9WnRbwTDIw/etNPWr1n4MRrOEb2y4+i/XXgFy Cqn3X9PbqN0SJwcZvpY2F9GxBhF4Y85KbMg9ccLWoPq1u+pVaxlgiZErI9qCPMpNeJBj 5oMvX2aODjq68xANMB7wboPyUOt9GkYmKtrwFt1I4TtzgZixHiSG+e8Fe0uAA6JCF4Ek kQvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=idILoaA2JqRIC25Fjf9nyuPXcQlZpZOQtMl2iaoFfrw=; fh=IqnL5DzMSNmqiauLiDoSpi6m1wiRC/TEhzdMHR9QMP8=; b=NITrj5kXipOJONg5jarO0hoEcoD4lsCSedA0zuSznw5wxmstp2RmlFCi2GxM+mGK6q jy9DqO6EFzCEku1MjMVfZH24QicJmvW0sU3gvdpB4Ceisy+/RzVrktx3wzP5HZljxhM0 MZD1hihGQfDdDl3fRtqjW7Phg++xO3GkWXzEVIg4DEbMTerDWsJnWTO2P32UTKdR4El3 Ad/1LYstotWVCvzmgMdztk/P8naRZDwWyRfa+cW7aUAlKdGU8CSfLSIdj7U8d3cBVrC9 2gK1sE0FzHtbarRr36nb+9gRkOavbC09/BHSZVAldtmJXfGwKO4Co2Qr1OMYoHTdkOWe Lwyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Qu1UnCoi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id k89-20020a17090a3ee200b0027ffa51a805si12248014pjc.38.2023.11.28.08.56.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 08:56:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Qu1UnCoi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 175418042592; Tue, 28 Nov 2023 08:56:58 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345078AbjK1Q4r (ORCPT + 99 others); Tue, 28 Nov 2023 11:56:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234903AbjK1Q4o (ORCPT ); Tue, 28 Nov 2023 11:56:44 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8FC110DA for ; Tue, 28 Nov 2023 08:56:49 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-a00191363c1so832940066b.0 for ; Tue, 28 Nov 2023 08:56:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1701190608; x=1701795408; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=idILoaA2JqRIC25Fjf9nyuPXcQlZpZOQtMl2iaoFfrw=; b=Qu1UnCoiW8ID2W7eNHGSEyJckWzOnCMRWQk8EKW/NvJbE1n3vgGOq5UnHTP3o+k2Oy uIrfmYG/0j5zACxTiPoRiIZo/6QqhCSv3u67uhIm1Pdi+hAO5Wx0Tpd96PJkq5/4ZVqr 2X+9Z5nv+Ap2mTVh54FWiDCChEhqzQNm9Z0CDPZYzAjXvA3ScQIUTJmEWtliFPZ0v9zW jDbbh01Ox/Jzg0rkEOgL6t5p+sD6BW8KQ3rGs4ymnZWfTHmQxhOR8uVuua1clfFp9QLe 6wr3l0wSmTMWV0oJpFiNJX5zNPbzvYlsvuBV+iKb6cA2j7RjhodH9VLmH/wf0mprs0Jr kR3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701190608; x=1701795408; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=idILoaA2JqRIC25Fjf9nyuPXcQlZpZOQtMl2iaoFfrw=; b=Ittf55MBciI+APCEK63G/3dA0ni+jZOJPetLwoCve8o1Qvr1DJedsZKql5xQ1pI8yf MBlitqZaV8Z6Inp2NtAaKovKToGxWlhFSEdLxomGUtNLfM92NvempwX9s7EXBBRPWK8p 4FfhgNKP0pxi4857Idn98ckMW8NRui01jgy+LKH/+xIDJHh3ppKbZ+sM7SjZSTOUYgW4 6XC6XytlV/ZQ9lopYHcHT3zNGPg+uJnfwcCKgovNKoyikdG1nqDBOikwYzi3f48sUhQV B+JE/Reh2MGYH8NTrqk8e09hJI+LZQ+UGMDP7+KTXhzw+qwoaLfEJ7R0lovPsV9tD1wK qkIA== X-Gm-Message-State: AOJu0YwB9TPviQ9UM6hirWkU3zF7Xq2+TojfEH9rl2EfxY4R9OV4IFhT Q4XSl42OeTAg93W9KuFFQnwntA== X-Received: by 2002:a17:906:749c:b0:a14:b151:72e4 with SMTP id e28-20020a170906749c00b00a14b15172e4mr1775658ejl.73.1701190608259; Tue, 28 Nov 2023 08:56:48 -0800 (PST) Received: from krzk-bin.. ([178.197.223.109]) by smtp.gmail.com with ESMTPSA id cw18-20020a170906c79200b009bf7a4d591csm7126252ejb.11.2023.11.28.08.56.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 08:56:47 -0800 (PST) From: Krzysztof Kozlowski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Vinod Koul , Bard Liao , Pierre-Louis Bossart , Sanyog Kale , Srinivas Kandagatla , Banajit Goswami , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , linux-arm-msm@vger.kernel.org, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org Cc: Krzysztof Kozlowski Subject: [PATCH 2/2] ASoC: qcom: Move Soundwire runtime stream alloc to soundcards Date: Tue, 28 Nov 2023 17:56:38 +0100 Message-Id: <20231128165638.757665-2-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231128165638.757665-1-krzysztof.kozlowski@linaro.org> References: <20231128165638.757665-1-krzysztof.kozlowski@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 28 Nov 2023 08:56:58 -0800 (PST) Currently the Qualcomm Soundwire controller in its DAI startup op allocates the Soundwire stream runtime. This works fine for existing designs, but has limitations for stream runtimes with multiple controllers, like upcoming Qualcomm X1E80100 SoC with four WSA8840 speakers on two Soundwire controllers. When two Soundwire controllers are added to sound card codecs, Soundwire startup() is called twice, one for each Soundwire controller, and second execution overwrites what was set before. During shutdown() this causes double free. It is expected to have only one Soundwire stream runtime, thus it should be allocated from SoC soundcard context startup(), not from each Soundwire startup(). Such way will properly handle both cases: one and two Soundwire controllers in the stream runtime. Signed-off-by: Krzysztof Kozlowski --- This is an entirely different approach than my previous try here: https://lore.kernel.org/all/20231025144601.268645-1-krzysztof.kozlowski@linaro.org/ --- drivers/soundwire/qcom.c | 33 +-------------------------------- sound/soc/qcom/sc8280xp.c | 13 +++++++++++++ sound/soc/qcom/sm8250.c | 15 ++++++++++++++- 3 files changed, 28 insertions(+), 33 deletions(-) diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c index f42c83c390ff..ac9176f714bf 100644 --- a/drivers/soundwire/qcom.c +++ b/drivers/soundwire/qcom.c @@ -1291,10 +1291,7 @@ static int qcom_swrm_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { struct qcom_swrm_ctrl *ctrl = dev_get_drvdata(dai->dev); - struct snd_soc_pcm_runtime *rtd = substream->private_data; - struct sdw_stream_runtime *sruntime; - struct snd_soc_dai *codec_dai; - int ret, i; + int ret; ret = pm_runtime_get_sync(ctrl->dev); if (ret < 0 && ret != -EACCES) { @@ -1305,33 +1302,7 @@ static int qcom_swrm_startup(struct snd_pcm_substream *substream, return ret; } - sruntime = sdw_alloc_stream(dai->name); - if (!sruntime) { - ret = -ENOMEM; - goto err_alloc; - } - - ctrl->sruntime[dai->id] = sruntime; - - for_each_rtd_codec_dais(rtd, i, codec_dai) { - ret = snd_soc_dai_set_stream(codec_dai, sruntime, - substream->stream); - if (ret < 0 && ret != -ENOTSUPP) { - dev_err(dai->dev, "Failed to set sdw stream on %s\n", - codec_dai->name); - goto err_set_stream; - } - } - return 0; - -err_set_stream: - sdw_release_stream(sruntime); -err_alloc: - pm_runtime_mark_last_busy(ctrl->dev); - pm_runtime_put_autosuspend(ctrl->dev); - - return ret; } static void qcom_swrm_shutdown(struct snd_pcm_substream *substream, @@ -1340,8 +1311,6 @@ static void qcom_swrm_shutdown(struct snd_pcm_substream *substream, struct qcom_swrm_ctrl *ctrl = dev_get_drvdata(dai->dev); swrm_wait_for_wr_fifo_done(ctrl); - sdw_release_stream(ctrl->sruntime[dai->id]); - ctrl->sruntime[dai->id] = NULL; pm_runtime_mark_last_busy(ctrl->dev); pm_runtime_put_autosuspend(ctrl->dev); diff --git a/sound/soc/qcom/sc8280xp.c b/sound/soc/qcom/sc8280xp.c index d93b18f07be5..7c20b25ba3de 100644 --- a/sound/soc/qcom/sc8280xp.c +++ b/sound/soc/qcom/sc8280xp.c @@ -31,6 +31,17 @@ static int sc8280xp_snd_init(struct snd_soc_pcm_runtime *rtd) return qcom_snd_wcd_jack_setup(rtd, &data->jack, &data->jack_setup); } +static void sc8280xp_snd_shutdown(struct snd_pcm_substream *substream) +{ + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); + struct sc8280xp_snd_data *pdata = snd_soc_card_get_drvdata(rtd->card); + struct sdw_stream_runtime *sruntime = pdata->sruntime[cpu_dai->id]; + + pdata->sruntime[cpu_dai->id] = NULL; + sdw_release_stream(sruntime); +} + static int sc8280xp_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params) { @@ -91,6 +102,8 @@ static int sc8280xp_snd_hw_free(struct snd_pcm_substream *substream) } static const struct snd_soc_ops sc8280xp_be_ops = { + .startup = qcom_snd_sdw_startup, + .shutdown = sc8280xp_snd_shutdown, .hw_params = sc8280xp_snd_hw_params, .hw_free = sc8280xp_snd_hw_free, .prepare = sc8280xp_snd_prepare, diff --git a/sound/soc/qcom/sm8250.c b/sound/soc/qcom/sm8250.c index 9cc869fd70ac..f298167c2a23 100644 --- a/sound/soc/qcom/sm8250.c +++ b/sound/soc/qcom/sm8250.c @@ -66,7 +66,19 @@ static int sm8250_snd_startup(struct snd_pcm_substream *substream) default: break; } - return 0; + + return qcom_snd_sdw_startup(substream); +} + +static void sm2450_snd_shutdown(struct snd_pcm_substream *substream) +{ + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); + struct sm8250_snd_data *data = snd_soc_card_get_drvdata(rtd->card); + struct sdw_stream_runtime *sruntime = data->sruntime[cpu_dai->id]; + + data->sruntime[cpu_dai->id] = NULL; + sdw_release_stream(sruntime); } static int sm8250_snd_hw_params(struct snd_pcm_substream *substream, @@ -103,6 +115,7 @@ static int sm8250_snd_hw_free(struct snd_pcm_substream *substream) static const struct snd_soc_ops sm8250_be_ops = { .startup = sm8250_snd_startup, + .shutdown = sm2450_snd_shutdown, .hw_params = sm8250_snd_hw_params, .hw_free = sm8250_snd_hw_free, .prepare = sm8250_snd_prepare, -- 2.34.1