From patchwork Wed May 19 10:48:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Codrin Ciubotariu X-Patchwork-Id: 442518 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DFBD7C433B4 for ; Wed, 19 May 2021 10:50:46 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 911706135C for ; Wed, 19 May 2021 10:50:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 911706135C Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=microchip.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org 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 34AD01672; Wed, 19 May 2021 12:49:53 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 34AD01672 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1621421443; bh=kFvbkt+QgKqh1RR/T8GvsLtgxKyaio8KFYLcVIRZ/9s=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=OOPUN1A8a/rU2+WjMW8ALMe/AI5RujQlySJXYe7aqs9v98YGUNTFMiIE/c9J0lkMq lAwnzze3kqC45WBOF5vAN5iIhctP4eLdL1hTurmBDfUSgaAaIQRnSzNiMnj1m8/xDu iRHbN24v48HrqPttksEkplSeFTOJZRxX1sKKef7E= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 9BC13F8016E; Wed, 19 May 2021 12:49:52 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 28502F80246; Wed, 19 May 2021 12:49:50 +0200 (CEST) Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) (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 06C03F80148 for ; Wed, 19 May 2021 12:49:42 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 06C03F80148 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="AQghzPVz" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1621421384; x=1652957384; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kFvbkt+QgKqh1RR/T8GvsLtgxKyaio8KFYLcVIRZ/9s=; b=AQghzPVzIFIQTkHV4R4e+k/BG/cvlKkE5PmXpWmf2DHbWGk8+yEjRnA2 2kQYI5Ll8EHlD0tHtGtRhK3kOzML8hgtmCJyL2kRVRnDpWm3UdiOvLR33 jBqvMEOduepTCrARWqqtY1Ie6eGVVNEipj8fVVlejRtUwE/B7xPrU9ZzO yzwhtwiLUEvDwSzJyGoQnsUoXVWeX9VqveofWxnj8A5HtPZlOQIX86p61 w1AU86zPqIZvd5OxQd0240RAEsa8JjZnbsIeAZGye/ZAGZNCaNnTilRww s2ajchVoaydlmBMxV8IJj0GQC3tPBsO2Cq1SSkn84ELoka1m+rfRukMfY A==; IronPort-SDR: RSbC8ILc3hFXkjAJorW2jJyxxKJEdarEEa7D2fyBRufLeadke1cTeP3zQcddcdlA5IUBkZt8bq oNqznPgk5IHSNfPTLpzEz35S57wP+X3l7EyuMESD8Okma33vAWC/DB/NaO3LP+ubeAds4Ka3y3 vrEJ0vM1SpdglEZDf33GjUPMwiJxC0KnljZRqAKUOW4QPFk7M6bq8bcXMVC9ZHcMx5WGFz4y6L 1HpUTQNe9x4I6nsTOovFi5H1+KhliYenQ7HyFXmW4Iw5hGztZP+M7NEtbetJUBMpvtJHuWkyBw cDw= X-IronPort-AV: E=Sophos;i="5.82,312,1613458800"; d="scan'208";a="118456735" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 19 May 2021 03:49:39 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 19 May 2021 03:49:38 -0700 Received: from rob-ult-m19940.amer.actel.com (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2176.2 via Frontend Transport; Wed, 19 May 2021 03:49:34 -0700 From: Codrin Ciubotariu To: , Subject: [RFC PATCH 1/6] ALSA: core: pcm: Create helpers to allocate/free struct snd_pcm_runtime Date: Wed, 19 May 2021 13:48:37 +0300 Message-ID: <20210519104842.977895-2-codrin.ciubotariu@microchip.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210519104842.977895-1-codrin.ciubotariu@microchip.com> References: <20210519104842.977895-1-codrin.ciubotariu@microchip.com> MIME-Version: 1.0 Cc: lars@metafoo.de, kuninori.morimoto.gx@renesas.com, tiwai@suse.com, pierre-louis.bossart@linux.intel.com, lgirdwood@gmail.com, broonie@kernel.org, joe@perches.com, Codrin Ciubotariu , Cristian.Birsan@microchip.com, nicolas.ferre@microchip.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" Create helpers to be able to reuse code for allocation and freeing of struct snd_pcm_runtime. Signed-off-by: Codrin Ciubotariu --- include/sound/pcm.h | 2 ++ sound/core/pcm.c | 82 +++++++++++++++++++++++++++------------------ 2 files changed, 52 insertions(+), 32 deletions(-) diff --git a/include/sound/pcm.h b/include/sound/pcm.h index 2e1200d17d0c..025b4d2ba0fe 100644 --- a/include/sound/pcm.h +++ b/include/sound/pcm.h @@ -574,6 +574,8 @@ static inline int snd_pcm_suspend_all(struct snd_pcm *pcm) } #endif int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg); +struct snd_pcm_runtime *snd_pcm_runtime_alloc(void); +void snd_pcm_runtime_free(struct snd_pcm_runtime *runtime); int snd_pcm_open_substream(struct snd_pcm *pcm, int stream, struct file *file, struct snd_pcm_substream **rsubstream); void snd_pcm_release_substream(struct snd_pcm_substream *substream); diff --git a/sound/core/pcm.c b/sound/core/pcm.c index b163164a83ec..8ecb14b27460 100644 --- a/sound/core/pcm.c +++ b/sound/core/pcm.c @@ -876,6 +876,53 @@ static int snd_pcm_dev_free(struct snd_device *device) return snd_pcm_free(pcm); } +struct snd_pcm_runtime *snd_pcm_runtime_alloc(void) +{ + struct snd_pcm_runtime *runtime; + size_t size; + + runtime = kzalloc(sizeof(*runtime), GFP_KERNEL); + if (!runtime) + return NULL; + + size = PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status)); + runtime->status = alloc_pages_exact(size, GFP_KERNEL); + if (!runtime->status) { + kfree(runtime); + return NULL; + } + memset(runtime->status, 0, size); + + size = PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control)); + runtime->control = alloc_pages_exact(size, GFP_KERNEL); + if (!runtime->control) { + free_pages_exact(runtime->status, + PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status))); + kfree(runtime); + return NULL; + } + memset(runtime->control, 0, size); + + init_waitqueue_head(&runtime->sleep); + init_waitqueue_head(&runtime->tsleep); + + runtime->status->state = SNDRV_PCM_STATE_OPEN; + + return runtime; +} +EXPORT_SYMBOL_GPL(snd_pcm_runtime_alloc); + +void snd_pcm_runtime_free(struct snd_pcm_runtime *runtime) +{ + free_pages_exact(runtime->status, + PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status))); + free_pages_exact(runtime->control, + PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control))); + kfree(runtime->hw_constraints.rules); + kfree(runtime); +} +EXPORT_SYMBOL_GPL(snd_pcm_runtime_free); + int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream, struct file *file, struct snd_pcm_substream **rsubstream) @@ -885,7 +932,6 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream, struct snd_pcm_runtime *runtime; struct snd_card *card; int prefer_subdevice; - size_t size; if (snd_BUG_ON(!pcm || !rsubstream)) return -ENXIO; @@ -939,33 +985,10 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream, if (substream == NULL) return -EAGAIN; - runtime = kzalloc(sizeof(*runtime), GFP_KERNEL); - if (runtime == NULL) + runtime = snd_pcm_runtime_alloc(); + if (!runtime) return -ENOMEM; - size = PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status)); - runtime->status = alloc_pages_exact(size, GFP_KERNEL); - if (runtime->status == NULL) { - kfree(runtime); - return -ENOMEM; - } - memset(runtime->status, 0, size); - - size = PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control)); - runtime->control = alloc_pages_exact(size, GFP_KERNEL); - if (runtime->control == NULL) { - free_pages_exact(runtime->status, - PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status))); - kfree(runtime); - return -ENOMEM; - } - memset(runtime->control, 0, size); - - init_waitqueue_head(&runtime->sleep); - init_waitqueue_head(&runtime->tsleep); - - runtime->status->state = SNDRV_PCM_STATE_OPEN; - substream->runtime = runtime; substream->private_data = pcm->private_data; substream->ref_count = 1; @@ -985,11 +1008,6 @@ void snd_pcm_detach_substream(struct snd_pcm_substream *substream) runtime = substream->runtime; if (runtime->private_free != NULL) runtime->private_free(runtime); - free_pages_exact(runtime->status, - PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status))); - free_pages_exact(runtime->control, - PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control))); - kfree(runtime->hw_constraints.rules); /* Avoid concurrent access to runtime via PCM timer interface */ if (substream->timer) { spin_lock_irq(&substream->timer->lock); @@ -998,7 +1016,7 @@ void snd_pcm_detach_substream(struct snd_pcm_substream *substream) } else { substream->runtime = NULL; } - kfree(runtime); + snd_pcm_runtime_free(runtime); put_pid(substream->pid); substream->pid = NULL; substream->pstr->substream_opened--; From patchwork Wed May 19 10:48:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Codrin Ciubotariu X-Patchwork-Id: 442517 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B19BFC433B4 for ; Wed, 19 May 2021 10:51:40 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 0E3FA600D4 for ; Wed, 19 May 2021 10:51:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0E3FA600D4 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=microchip.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org 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 9F10A1682; Wed, 19 May 2021 12:50:48 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 9F10A1682 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1621421498; bh=OvmW6tVCbjyO+IvIX2whfPUPyiGN4DEv2pSti3uCZ0w=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=qYA0TJx+c901ALaHwkMybSDMTjA7bHfgD12w9kHsSJvUMjNnRulV65iegtQGl3/ij 6iw869xRpZRlKH0Sok9+x7dfTLX3rj7Z12iuSHj3oRY0XQNwH9CP3fTg6MogwbNZy6 31ENHJexB0EIv/jXIhXr2hubJx6Q6R9I2U78l0ZY= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 363ADF80424; Wed, 19 May 2021 12:49:59 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id EA1DBF8042F; Wed, 19 May 2021 12:49:56 +0200 (CEST) Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) (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 35FFAF8014C for ; Wed, 19 May 2021 12:49:50 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 35FFAF8014C Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="HWqCQ+Rv" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1621421391; x=1652957391; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OvmW6tVCbjyO+IvIX2whfPUPyiGN4DEv2pSti3uCZ0w=; b=HWqCQ+Rvod6jNKqjV3KFZSJ9MB+tUVyl3zWN6NHmMKPxupc3I67xhJ+h GS9pKsybkKesDBdyPjkZRQ6tnvcw4iwQt9kMw5O7zrx0ATLa2aizy7bHX udSCUfKEMO7d+AmnHJk6hbtnL1taAnKQdCUT5L04cxwwVyZPhQMnBybd2 SD7FTohXwWnf6teGZwnIgIHhHXSPrbyYS0+tIuLCWHc7iYgQ5YC9dTuMZ F0lVQiBl+OKTs9RntT/OWpQRUn3Nq1rwzxG1MO/DYlBnIdvDYdkPU/B1y hlQFHzlufqbYfID365F5Cx6QJq4KpFxQawY9BOa9f8lrdItXXuu7Wm8BM w==; IronPort-SDR: 4Rxd1+63VuICe/o5nrpWV3F60GHyMgupHOg+jLGRmvzBc1gDLbKyknOL/X+Vq+ApEbnUEvN9b5 y0E4zH7AIZGW5JsWxMU6MO6ivNSEN7N8OrrvQlF7K7Ok4Sf4hC6upLvYq2feJKx5nEhVD2Lpwh QoD6ot/EeBKB/+KZrg68lXbatln7uvLoyrKnFs5csFhyShJwG3JpXAdoRl5s++q3SImvRgxRj5 HXITP1DS6DyBDlsU3dThzUDXgCCIQOldHTpoDZVz1oUUp0xCa4cvS9nAIXe6V5lwSo/3TZaVth Apc= X-IronPort-AV: E=Sophos;i="5.82,312,1613458800"; d="scan'208";a="56105002" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 19 May 2021 03:49:48 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 19 May 2021 03:49:47 -0700 Received: from rob-ult-m19940.amer.actel.com (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2176.2 via Frontend Transport; Wed, 19 May 2021 03:49:43 -0700 From: Codrin Ciubotariu To: , Subject: [RFC PATCH 3/6] ALSA: pcm: Check for substream->ops before substream->ops->mmap Date: Wed, 19 May 2021 13:48:39 +0300 Message-ID: <20210519104842.977895-4-codrin.ciubotariu@microchip.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210519104842.977895-1-codrin.ciubotariu@microchip.com> References: <20210519104842.977895-1-codrin.ciubotariu@microchip.com> MIME-Version: 1.0 Cc: lars@metafoo.de, kuninori.morimoto.gx@renesas.com, tiwai@suse.com, pierre-louis.bossart@linux.intel.com, lgirdwood@gmail.com, broonie@kernel.org, joe@perches.com, Codrin Ciubotariu , Cristian.Birsan@microchip.com, nicolas.ferre@microchip.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" substreams, like the internal ones, might not have ops set. Check it, before looking at substream->ops->mmap. Signed-off-by: Codrin Ciubotariu --- sound/core/pcm_native.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 54e0eab2a57e..cb0164d55593 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -246,7 +246,7 @@ static bool hw_support_mmap(struct snd_pcm_substream *substream) if (!(substream->runtime->hw.info & SNDRV_PCM_INFO_MMAP)) return false; - if (substream->ops->mmap || + if ((substream->ops && substream->ops->mmap) || (substream->dma_buffer.dev.type != SNDRV_DMA_TYPE_DEV && substream->dma_buffer.dev.type != SNDRV_DMA_TYPE_DEV_UC)) return true; From patchwork Wed May 19 10:48:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Codrin Ciubotariu X-Patchwork-Id: 442516 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01E61C433B4 for ; Wed, 19 May 2021 10:52:52 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 73AAA6135B for ; Wed, 19 May 2021 10:52:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 73AAA6135B Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=microchip.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org 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 E9206168D; Wed, 19 May 2021 12:51:59 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz E9206168D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1621421570; bh=bHk0TRGCIe8ah9IbWKNOCz5WNUTu7v3xCZwfWNzTb/w=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=l59AmdljMKLajuBDJGLoIjXyfxsFRCAieruy4GeehxaCTCaxi32B654+aPcQPPyz5 4VKP3iNhzBRNKunEH0lhNvg5LDC4tgLVRqYVBJREABHBiBCYeOIyrrm9ptIjSwDhmz p6XD4w2SCwWrxaMf2bbtQbT4PQONYCVkgtvuLBVc= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 9C0C2F804AC; Wed, 19 May 2021 12:50:01 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 464C5F8042F; Wed, 19 May 2021 12:49:59 +0200 (CEST) Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (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 DE8C4F80153 for ; Wed, 19 May 2021 12:49:55 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz DE8C4F80153 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="Tvd1e2g+" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1621421397; x=1652957397; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bHk0TRGCIe8ah9IbWKNOCz5WNUTu7v3xCZwfWNzTb/w=; b=Tvd1e2g+p0WMf1fNagu+XiTZl2ycMrzVD6vHbhxXwbIGtkZ2QkRVN4+p ofVpOav1USJjEySliHzEaspWfuvhebJFRyP4jHbCI9jS1FEYwWPrfSLBB 3PMpRBMlep0YGWxQQkjl9yl6b2dfTjFyzWSH8tPrO5qwY3ILAFnxr5OEr Y87dJ1PYzAFNyNyQmx26CtrxEAD5sk5G8ni2UApTopa68NPz8/TW2r5uj wkfYfuXeQzlkTBtodxvpoz+D32vTuDKG8P5korXiiOSN9mDrYCmiTCQUD uBAE9mMxuKYjcT9uZPE4Nz49V1xa//IeroyrqdMaC5G4Egi5pvxcMtmBX A==; IronPort-SDR: cljuQcxyhS5vwA61XVnvbHMXU8VmFpRkdEknuqUwJ3cH8c/IsPYCiRB8o1Lz9DL2UsnoEzQaMT i/+j1+nBmI/UVRuqtBpWROZu5hGXt0nPXIG3GaD82IYk6doSMosskjSrU7Jv3IT520xm2f/0OL +JHYAtfslAKvzB1LPuGx3mds5o3vLIMv8C1lJ1K5mNDHZbdbZI4uS3/Bz8XKQlBTyrFpamWvNC EGSzky41De+g2YrQikYvCoJvGDEaLg9fj2c5h+ZUYJ2cMUBRYsBeOfMNw70fzMWgJ3dEQ3U3/H FVQ= X-IronPort-AV: E=Sophos;i="5.82,312,1613458800"; d="scan'208";a="128651266" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa1.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 19 May 2021 03:49:55 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 19 May 2021 03:49:52 -0700 Received: from rob-ult-m19940.amer.actel.com (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2176.2 via Frontend Transport; Wed, 19 May 2021 03:49:48 -0700 From: Codrin Ciubotariu To: , Subject: [RFC PATCH 4/6] ALSA: pcm: Create function for snd_pcm_runtime initialization Date: Wed, 19 May 2021 13:48:40 +0300 Message-ID: <20210519104842.977895-5-codrin.ciubotariu@microchip.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210519104842.977895-1-codrin.ciubotariu@microchip.com> References: <20210519104842.977895-1-codrin.ciubotariu@microchip.com> MIME-Version: 1.0 Cc: lars@metafoo.de, kuninori.morimoto.gx@renesas.com, tiwai@suse.com, pierre-louis.bossart@linux.intel.com, lgirdwood@gmail.com, broonie@kernel.org, joe@perches.com, Codrin Ciubotariu , Cristian.Birsan@microchip.com, nicolas.ferre@microchip.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" Group the setting of snd_pcm_runtime members in a separate function. This allows for code reutilization. Also, check for substream->ops before substream->ops->copy_user . Signed-off-by: Codrin Ciubotariu --- include/sound/pcm.h | 2 + sound/core/pcm_native.c | 108 ++++++++++++++++++++++------------------ 2 files changed, 61 insertions(+), 49 deletions(-) diff --git a/include/sound/pcm.h b/include/sound/pcm.h index 2907ed2b937f..8e6bd4525c02 100644 --- a/include/sound/pcm.h +++ b/include/sound/pcm.h @@ -576,6 +576,8 @@ static inline int snd_pcm_suspend_all(struct snd_pcm *pcm) int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg); struct snd_pcm_runtime *snd_pcm_runtime_alloc(void); void snd_pcm_runtime_free(struct snd_pcm_runtime *runtime); +void snd_pcm_runtime_set(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params); int snd_pcm_open_substream(struct snd_pcm *pcm, int stream, struct file *file, struct snd_pcm_substream **rsubstream); void snd_pcm_release_substream(struct snd_pcm_substream *substream); diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index cb0164d55593..5b0e7ae2b1e7 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -658,13 +658,69 @@ static int snd_pcm_hw_params_choose(struct snd_pcm_substream *pcm, return 0; } +void snd_pcm_runtime_set(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + unsigned int bits; + snd_pcm_uframes_t frames; + + runtime->access = params_access(params); + runtime->format = params_format(params); + runtime->subformat = params_subformat(params); + runtime->channels = params_channels(params); + runtime->rate = params_rate(params); + runtime->period_size = params_period_size(params); + runtime->periods = params_periods(params); + runtime->buffer_size = params_buffer_size(params); + runtime->info = params->info; + runtime->rate_num = params->rate_num; + runtime->rate_den = params->rate_den; + runtime->no_period_wakeup = + (params->info & SNDRV_PCM_INFO_NO_PERIOD_WAKEUP) && + (params->flags & SNDRV_PCM_HW_PARAMS_NO_PERIOD_WAKEUP); + + bits = snd_pcm_format_physical_width(runtime->format); + runtime->sample_bits = bits; + bits *= runtime->channels; + runtime->frame_bits = bits; + frames = 1; + while (bits % 8 != 0) { + bits *= 2; + frames *= 2; + } + runtime->byte_align = bits / 8; + runtime->min_align = frames; + + /* Default sw params */ + runtime->tstamp_mode = SNDRV_PCM_TSTAMP_NONE; + runtime->period_step = 1; + runtime->control->avail_min = runtime->period_size; + runtime->start_threshold = 1; + runtime->stop_threshold = runtime->buffer_size; + runtime->silence_threshold = 0; + runtime->silence_size = 0; + runtime->boundary = runtime->buffer_size; + while (runtime->boundary * 2 <= LONG_MAX - runtime->buffer_size) + runtime->boundary *= 2; + + /* clear the buffer for avoiding possible kernel info leaks */ + if (runtime->dma_area && + !(substream->ops && substream->ops->copy_user)) { + size_t size = runtime->dma_bytes; + + if (runtime->info & SNDRV_PCM_INFO_MMAP) + size = PAGE_ALIGN(size); + memset(runtime->dma_area, 0, size); + } +} +EXPORT_SYMBOL(snd_pcm_runtime_set); + static int snd_pcm_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { struct snd_pcm_runtime *runtime; int err, usecs; - unsigned int bits; - snd_pcm_uframes_t frames; if (PCM_RUNTIME_CHECK(substream)) return -ENXIO; @@ -715,53 +771,7 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *substream, goto _error; } - runtime->access = params_access(params); - runtime->format = params_format(params); - runtime->subformat = params_subformat(params); - runtime->channels = params_channels(params); - runtime->rate = params_rate(params); - runtime->period_size = params_period_size(params); - runtime->periods = params_periods(params); - runtime->buffer_size = params_buffer_size(params); - runtime->info = params->info; - runtime->rate_num = params->rate_num; - runtime->rate_den = params->rate_den; - runtime->no_period_wakeup = - (params->info & SNDRV_PCM_INFO_NO_PERIOD_WAKEUP) && - (params->flags & SNDRV_PCM_HW_PARAMS_NO_PERIOD_WAKEUP); - - bits = snd_pcm_format_physical_width(runtime->format); - runtime->sample_bits = bits; - bits *= runtime->channels; - runtime->frame_bits = bits; - frames = 1; - while (bits % 8 != 0) { - bits *= 2; - frames *= 2; - } - runtime->byte_align = bits / 8; - runtime->min_align = frames; - - /* Default sw params */ - runtime->tstamp_mode = SNDRV_PCM_TSTAMP_NONE; - runtime->period_step = 1; - runtime->control->avail_min = runtime->period_size; - runtime->start_threshold = 1; - runtime->stop_threshold = runtime->buffer_size; - runtime->silence_threshold = 0; - runtime->silence_size = 0; - runtime->boundary = runtime->buffer_size; - while (runtime->boundary * 2 <= LONG_MAX - runtime->buffer_size) - runtime->boundary *= 2; - - /* clear the buffer for avoiding possible kernel info leaks */ - if (runtime->dma_area && !substream->ops->copy_user) { - size_t size = runtime->dma_bytes; - - if (runtime->info & SNDRV_PCM_INFO_MMAP) - size = PAGE_ALIGN(size); - memset(runtime->dma_area, 0, size); - } + snd_pcm_runtime_set(substream, params); snd_pcm_timer_resolution_change(substream); snd_pcm_set_state(substream, SNDRV_PCM_STATE_SETUP); From patchwork Wed May 19 10:48:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Codrin Ciubotariu X-Patchwork-Id: 442515 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98FB9C433B4 for ; Wed, 19 May 2021 10:53:21 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 1BFA16135C for ; Wed, 19 May 2021 10:53:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1BFA16135C Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=microchip.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org 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 A1EB61693; Wed, 19 May 2021 12:52:29 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz A1EB61693 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1621421599; bh=PjkM+cZ/rv8qW8Nuka2fZ+EwLgMDKLLm6kzp8U5W9ak=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=bHyVDs4UZ7aO2voo7cWTBPvhJKQ9aPpDCifKN9V55dUcoNb+MpQi7XSPiXjWhuOGW vRWskugQ91ZYLwAcetFbU2ufN4kR/5sTHY7iXeAuUxZFOiRwS669/pcV1mPOptXRRp EWwE+nIl3h68zmd7rcdU+aP7dBaMb8vyopgWOxUI= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 27FC1F804C1; Wed, 19 May 2021 12:50:29 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 9174CF804D1; Wed, 19 May 2021 12:50:27 +0200 (CEST) Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (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 1D20AF804C1 for ; Wed, 19 May 2021 12:50:20 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 1D20AF804C1 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="PeCXEXh5" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1621421422; x=1652957422; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PjkM+cZ/rv8qW8Nuka2fZ+EwLgMDKLLm6kzp8U5W9ak=; b=PeCXEXh5uA8bQawKi1O6jul8GJUR/LMXUyWxJ72+g3v/7ivoBCVMrfjX oLqLD2m8jjLmvx+/FasljnQjzzL0vXJOnb2x4t7bq7BEb4i/QXU54ciTF WAtZY5Hep9SMXiRr1uFDmimF1BvN+WdvT/A5RU7UXLd/fPGktOT1R2tEo fg9kEQnR0O+2u9E59baGdwCLoGBQfuQyOkpfnHnPKF9B969ETl7cT6vaZ R2ONges0ClWhUPVNT7YTmKgRBClGrfdypyYgT2hWE6r7eml3g5TlTqfgB srWMnj7mdxYsdKDnylpbaFfT5AJxE0HDgg8SDFeq/1i0k6sFHe4bKCsa9 w==; IronPort-SDR: NuJdV+EzIlfX9fQY425aL8VwN0OzpnrZ/UXxXvFaJmu3LqrXiHCk5bAMr7YRqmR1bEB47YlF3M JHv6AC2NpeDtro379jk1OFiXYPxdnqNmYcN+hWArURW46QfnRDq84prNr9yPBAP4P6CtAsgaZP 5mV1m6l0daItZqwFccUhjHr/g5g9hsKBLNKI/JzEpqs7EgzflRVldawu3Vi2Rz6kLKO34Zvwym n4xUvAiLHP+AgAvTQGSL1B3BBeN5sTHMMEyfk89Q0N62qmYwa1a1z1gm6HgNz/ZWNyRwGtHKfw 07I= X-IronPort-AV: E=Sophos;i="5.82,312,1613458800"; d="scan'208";a="121616328" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 19 May 2021 03:50:19 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 19 May 2021 03:49:57 -0700 Received: from rob-ult-m19940.amer.actel.com (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2176.2 via Frontend Transport; Wed, 19 May 2021 03:49:53 -0700 From: Codrin Ciubotariu To: , Subject: [RFC PATCH 5/6] ASoC: soc-pcm: Create new snd_pcm_runtime for BE DAIs Date: Wed, 19 May 2021 13:48:41 +0300 Message-ID: <20210519104842.977895-6-codrin.ciubotariu@microchip.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210519104842.977895-1-codrin.ciubotariu@microchip.com> References: <20210519104842.977895-1-codrin.ciubotariu@microchip.com> MIME-Version: 1.0 Cc: lars@metafoo.de, kuninori.morimoto.gx@renesas.com, tiwai@suse.com, pierre-louis.bossart@linux.intel.com, lgirdwood@gmail.com, broonie@kernel.org, joe@perches.com, Codrin Ciubotariu , Cristian.Birsan@microchip.com, nicolas.ferre@microchip.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" The BE DAIs are different than the FE DAIs. They have different HW capabilities, different HW constraints and different HW parameters. Also, the buffer used to read/write data from/to user-space to/from FE DAIs has nothing to do with the BE DAIs. For this reason, this patch creates a new snd_pcm_runtime for the BE DAIs. The new structure can be used to better represent the HW capabilities, so the HW parameters are no longer copied from the FE, but created separately. For BE DAIs that need a buffer to move the data to/from the FE DAIs (no dev-to-dev DMA capability), the new snd_pcm_runtime can store the needed parameters to allocate the buffer and set the DMA transfers. Signed-off-by: Codrin Ciubotariu --- sound/soc/soc-pcm.c | 126 +++++++++++++++++++++++++++++++------------- 1 file changed, 90 insertions(+), 36 deletions(-) diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 8659089a87a0..7d95df20541e 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -1134,7 +1134,6 @@ static int dpcm_be_connect(struct snd_soc_pcm_runtime *fe, dpcm->be = be; dpcm->fe = fe; - be->dpcm[stream].runtime = fe->dpcm[stream].runtime; dpcm->state = SND_SOC_DPCM_LINK_STATE_NEW; spin_lock_irqsave(&fe->card->dpcm_lock, flags); list_add(&dpcm->list_be, &fe->dpcm[stream].be_clients); @@ -1150,34 +1149,6 @@ static int dpcm_be_connect(struct snd_soc_pcm_runtime *fe, return 1; } -/* reparent a BE onto another FE */ -static void dpcm_be_reparent(struct snd_soc_pcm_runtime *fe, - struct snd_soc_pcm_runtime *be, int stream) -{ - struct snd_soc_dpcm *dpcm; - struct snd_pcm_substream *fe_substream, *be_substream; - - /* reparent if BE is connected to other FEs */ - if (!be->dpcm[stream].users) - return; - - be_substream = snd_soc_dpcm_get_substream(be, stream); - - for_each_dpcm_fe(be, stream, dpcm) { - if (dpcm->fe == fe) - continue; - - dev_dbg(fe->dev, "reparent %s path %s %s %s\n", - stream ? "capture" : "playback", - dpcm->fe->dai_link->name, - stream ? "<-" : "->", dpcm->be->dai_link->name); - - fe_substream = snd_soc_dpcm_get_substream(dpcm->fe, stream); - be_substream->runtime = fe_substream->runtime; - break; - } -} - /* disconnect a BE and FE */ void dpcm_be_disconnect(struct snd_soc_pcm_runtime *fe, int stream) { @@ -1196,9 +1167,6 @@ void dpcm_be_disconnect(struct snd_soc_pcm_runtime *fe, int stream) stream ? "capture" : "playback", fe->dai_link->name, stream ? "<-" : "->", dpcm->be->dai_link->name); - /* BEs still alive need new FE */ - dpcm_be_reparent(fe, dpcm->be, stream); - dpcm_remove_debugfs_state(dpcm); spin_lock_irqsave(&fe->card->dpcm_lock, flags); @@ -1468,7 +1436,12 @@ void dpcm_be_dai_stop(struct snd_soc_pcm_runtime *fe, int stream, } soc_pcm_close(be_substream); - be_substream->runtime = NULL; + + if (be_substream->runtime) { + snd_pcm_runtime_free(be_substream->runtime); + be_substream->runtime = NULL; + } + be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE; } } @@ -1482,6 +1455,7 @@ int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream) /* only startup BE DAIs that are either sinks or sources to this FE DAI */ for_each_dpcm_be(fe, stream, dpcm) { struct snd_pcm_substream *be_substream; + struct snd_pcm_runtime *runtime; be = dpcm->be; be_substream = snd_soc_dpcm_get_substream(be, stream); @@ -1514,7 +1488,23 @@ int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream) dev_dbg(be->dev, "ASoC: open %s BE %s\n", stream ? "capture" : "playback", be->dai_link->name); - be_substream->runtime = be->dpcm[stream].runtime; + runtime = snd_pcm_runtime_alloc(); + if (!runtime) { + err = -ENOMEM; + goto unwind; + } + + be_substream->runtime = runtime; + + /* initialize the BE constraints */ + err = snd_pcm_hw_constraints_init(be_substream); + if (err < 0) { + dev_err(be->dev, + "dpcm_be_hw_constraints_init failed: %d\n", + err); + goto unwind; + } + err = soc_pcm_open(be_substream); if (err < 0) { be->dpcm[stream].users--; @@ -1527,6 +1517,14 @@ int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream) goto unwind; } + err = snd_pcm_hw_constraints_complete(be_substream); + if (err < 0) { + dev_err(fe->dev, + "snd_pcm_hw_constraints_complete failed: %d\n", + err); + goto unwind; + } + be->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN; count++; } @@ -1897,6 +1895,14 @@ int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int stream) if (ret < 0) goto unwind; + /* apply constrains */ + dpcm->hw_params.rmask = ~0U; + ret = snd_pcm_hw_refine(be_substream, &dpcm->hw_params); + if (ret < 0) { + dev_err(fe->dev, "failed to refine hw parameters: %d\n", ret); + goto unwind; + } + /* copy the fixed-up hw params for BE dai */ memcpy(&be->dpcm[stream].hw_params, &dpcm->hw_params, sizeof(struct snd_pcm_hw_params)); @@ -1918,6 +1924,7 @@ int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int stream) goto unwind; be->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_PARAMS; + snd_pcm_runtime_set(be_substream, &dpcm->hw_params); } return 0; @@ -1949,17 +1956,64 @@ int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int stream) return ret; } +static int dpcm_be_dai_hw_params_init(struct snd_soc_pcm_runtime *fe, int stream) +{ + struct snd_pcm_hw_params *params = &fe->dpcm[stream].hw_params; + int k; + + for (k = SNDRV_PCM_HW_PARAM_FIRST_MASK; + k <= SNDRV_PCM_HW_PARAM_LAST_MASK; k++) + snd_mask_any(hw_param_mask(params, k)); + + for (k = SNDRV_PCM_HW_PARAM_FIRST_INTERVAL; + k <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL; k++) + snd_interval_any(hw_param_interval(params, k)); + + return 0; +} + static int dpcm_fe_dai_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream); int ret, stream = substream->stream; + struct snd_interval *t, *dpcm_t; mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE); - memcpy(&fe->dpcm[stream].hw_params, params, - sizeof(struct snd_pcm_hw_params)); + /* initialize the BE HW params */ + dpcm_be_dai_hw_params_init(fe, stream); + + /* FIXME: a very low period time will make the CPU take too many + * interrupts, which might end up not having enough time to actually + * fill the buffer(s); for now, the BE min period time will be half of + * the FE min period time + */ + t = hw_param_interval(params, SNDRV_PCM_HW_PARAM_PERIOD_TIME); + dpcm_t = hw_param_interval(&fe->dpcm[stream].hw_params, + SNDRV_PCM_HW_PARAM_PERIOD_TIME); + dpcm_t->min = t->min / 2; + + if (fe->dai_link->dpcm_merged_format) { + memcpy(hw_param_interval(&fe->dpcm[stream].hw_params, + SNDRV_PCM_HW_PARAM_FORMAT), + hw_param_interval(params, SNDRV_PCM_HW_PARAM_FORMAT), + sizeof(struct snd_interval)); + } + if (fe->dai_link->dpcm_merged_chan) { + memcpy(hw_param_interval(&fe->dpcm[stream].hw_params, + SNDRV_PCM_HW_PARAM_CHANNELS), + hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS), + sizeof(struct snd_interval)); + } + if (fe->dai_link->dpcm_merged_rate) { + memcpy(hw_param_interval(&fe->dpcm[stream].hw_params, + SNDRV_PCM_HW_PARAM_RATE), + hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE), + sizeof(struct snd_interval)); + } + ret = dpcm_be_dai_hw_params(fe, stream); if (ret < 0) goto out;