Received: by 10.223.185.116 with SMTP id b49csp3855489wrg; Mon, 19 Feb 2018 07:07:26 -0800 (PST) X-Google-Smtp-Source: AH8x2270VHJ+cxTyo4nlNnY0Qt7AkbKhIDi7IHMU0Udq5zJ4EIfUM4wk5MxJrN1LOcsHrcy526TY X-Received: by 10.99.177.6 with SMTP id r6mr302645pgf.76.1519052846710; Mon, 19 Feb 2018 07:07:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519052846; cv=none; d=google.com; s=arc-20160816; b=RfUxIgGHz0aucHu+KWoi3AvK3+i3MIWFbmixW2xWZ3mOywCO9y4KD8y1bMiH7ocD0b 4X8PV4HEAvvmJmUAbnkH/twekymW6bRtvsvZoeEMW1xn2sTbzsNebKJTY02ver7hFnPE TgBnVM2qkJ7bi9l8Qobj6Jczul064LMNxZt+4YmGLkHwWi47hQ0/HTk+ESPN+M4pzRZu JYmlkUKL/ltVufx+K0CQpW/XscSe2DRWRI1Wz/ghEqPX2eRQ6KUrf9rpa5ZmG1VXh2fM pyLXT76eODj/wbn985TWBqR9n/QlfUFb8Ye0Wxm+i2Jd7u6jUHzEbWxiH+vzL0DlNClY /QMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=Key8s303CJynrNic+2pb/aF+a/GZ1QBBQCMFp0Xz0zI=; b=S6+A5S8Pd3F8r/Qss3IGoTBFEppJdpc/9EqxKW/JLJXWMLJM92iU3zNJM1/0vUviZ8 H6MLSil6vThytY/7zeFJuf9WaPVHDBDgeT2ob09gZlud9hHbi81YEkDpayrg5TVXutpD AiU1E9Ft+jW1+idYTDZQIpTXBvGbWfExA+rtFwuLbc4Ebo84JzQj6GRIyv5bN64ZUhCG Bg7g5ywg/2tcmMvaRFMM4+9eSLulwx/8sjO4c88iaFFw/RgtJcvhQuTqFGTv3c48HG8n 3sW5dUsH9phurwRhjZpWEUYFkRmYNtU2m0sCqGmiXNJ0nsXjLhb04w3qqD7AjawziXF6 SpWQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g2-v6si1856437plm.454.2018.02.19.07.07.11; Mon, 19 Feb 2018 07:07:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752998AbeBSPFq (ORCPT + 99 others); Mon, 19 Feb 2018 10:05:46 -0500 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:3984 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752855AbeBSPFl (ORCPT ); Mon, 19 Feb 2018 10:05:41 -0500 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w1JEwjxb024479; Mon, 19 Feb 2018 16:00:44 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2g6ar0hnqx-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Mon, 19 Feb 2018 16:00:44 +0100 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 8D79343; Mon, 19 Feb 2018 15:00:43 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas23.st.com [10.75.90.46]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 658E0552F; Mon, 19 Feb 2018 15:00:43 +0000 (GMT) Received: from SAFEX1HUBCAS24.st.com (10.75.90.94) by SAFEX1HUBCAS23.st.com (10.75.90.46) with Microsoft SMTP Server (TLS) id 14.3.361.1; Mon, 19 Feb 2018 16:00:43 +0100 Received: from localhost (10.201.23.16) by webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.361.1; Mon, 19 Feb 2018 16:00:42 +0100 From: Olivier Moysan To: , , , , , , , , , , , , , CC: , Subject: [RFC PATCH 2/3] ASoC: dmaengine_pcm: add processing support Date: Mon, 19 Feb 2018 16:00:36 +0100 Message-ID: <1519052437-24011-3-git-send-email-olivier.moysan@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1519052437-24011-1-git-send-email-olivier.moysan@st.com> References: <1519052437-24011-1-git-send-email-olivier.moysan@st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.201.23.16] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-02-19_07:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allow dmaengine client to optionally register a processing callback. This callback is intended to apply processing on samples in buffer copied from/to user space, before/after DMA transfer. Signed-off-by: Olivier Moysan --- include/sound/dmaengine_pcm.h | 3 ++ sound/soc/soc-generic-dmaengine-pcm.c | 62 +++++++++++++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/include/sound/dmaengine_pcm.h b/include/sound/dmaengine_pcm.h index 8a5a840..47ef486 100644 --- a/include/sound/dmaengine_pcm.h +++ b/include/sound/dmaengine_pcm.h @@ -140,6 +140,9 @@ struct snd_dmaengine_pcm_config { struct dma_chan *(*compat_request_channel)( struct snd_soc_pcm_runtime *rtd, struct snd_pcm_substream *substream); + int (*process)(struct snd_pcm_substream *substream, + int channel, unsigned long hwoff, + void *buf, unsigned long bytes); dma_filter_fn compat_filter_fn; struct device *dma_dev; const char *chan_names[SNDRV_PCM_STREAM_LAST + 1]; diff --git a/sound/soc/soc-generic-dmaengine-pcm.c b/sound/soc/soc-generic-dmaengine-pcm.c index c07d5c7..1c1d838 100644 --- a/sound/soc/soc-generic-dmaengine-pcm.c +++ b/sound/soc/soc-generic-dmaengine-pcm.c @@ -340,6 +340,41 @@ static snd_pcm_uframes_t dmaengine_pcm_pointer( return snd_dmaengine_pcm_pointer(substream); } +static int dmaengine_copy_user(struct snd_pcm_substream *substream, + int channel, unsigned long hwoff, + void *buf, unsigned long bytes) +{ + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_soc_component *component = + snd_soc_rtdcom_lookup(rtd, SND_DMAENGINE_PCM_DRV_NAME); + struct snd_pcm_runtime *runtime = substream->runtime; + struct dmaengine_pcm *pcm = soc_component_to_pcm(component); + int (*process)(struct snd_pcm_substream *substream, + int channel, unsigned long hwoff, + void *buf, unsigned long bytes) = pcm->config->process; + bool is_playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; + void *dma_ptr = runtime->dma_area + hwoff + + channel * (runtime->dma_bytes / runtime->channels); + int ret; + + if (is_playback) + if (copy_from_user(dma_ptr, (void __user *)buf, bytes)) + return -EFAULT; + + if (process) { + ret = process(substream, channel, hwoff, + (void __user *)buf, bytes); + if (ret < 0) + return ret; + } + + if (!is_playback) + if (copy_to_user((void __user *)buf, dma_ptr, bytes)) + return -EFAULT; + + return 0; +} + static const struct snd_pcm_ops dmaengine_pcm_ops = { .open = dmaengine_pcm_open, .close = snd_dmaengine_pcm_close, @@ -350,6 +385,17 @@ static snd_pcm_uframes_t dmaengine_pcm_pointer( .pointer = dmaengine_pcm_pointer, }; +static const struct snd_pcm_ops dmaengine_pcm_process_ops = { + .open = dmaengine_pcm_open, + .close = snd_dmaengine_pcm_close, + .ioctl = snd_pcm_lib_ioctl, + .hw_params = dmaengine_pcm_hw_params, + .hw_free = snd_pcm_lib_free_pages, + .trigger = snd_dmaengine_pcm_trigger, + .pointer = dmaengine_pcm_pointer, + .copy_user = dmaengine_copy_user, +}; + static const struct snd_soc_component_driver dmaengine_pcm_component = { .name = SND_DMAENGINE_PCM_DRV_NAME, .probe_order = SND_SOC_COMP_ORDER_LATE, @@ -357,6 +403,13 @@ static snd_pcm_uframes_t dmaengine_pcm_pointer( .pcm_new = dmaengine_pcm_new, }; +static const struct snd_soc_component_driver dmaengine_pcm_component_process = { + .name = SND_DMAENGINE_PCM_DRV_NAME, + .probe_order = SND_SOC_COMP_ORDER_LATE, + .ops = &dmaengine_pcm_process_ops, + .pcm_new = dmaengine_pcm_new, +}; + static const char * const dmaengine_pcm_dma_channel_names[] = { [SNDRV_PCM_STREAM_PLAYBACK] = "tx", [SNDRV_PCM_STREAM_CAPTURE] = "rx", @@ -449,8 +502,13 @@ int snd_dmaengine_pcm_register(struct device *dev, if (ret) goto err_free_dma; - ret = snd_soc_add_component(dev, &pcm->component, - &dmaengine_pcm_component, NULL, 0); + if (config && config->process) + ret = snd_soc_add_component(dev, &pcm->component, + &dmaengine_pcm_component_process, + NULL, 0); + else + ret = snd_soc_add_component(dev, &pcm->component, + &dmaengine_pcm_component, NULL, 0); if (ret) goto err_free_dma; -- 1.9.1