mbox series

[00/15] ALSA: Improved WC memory handling

Message ID 20210802072815.13551-1-tiwai@suse.de
Headers show
Series ALSA: Improved WC memory handling | expand

Message

Takashi Iwai Aug. 2, 2021, 7:28 a.m. UTC
Hi,

this is a patchset to enhance the ALSA memory allocation helper to
support the allocation of WC pages more generically as well as
supporting the fixed size buffer allocation.  It allows us to reduce
lots of redundant code in various ASoC drivers that still haven't used
the standard preallocation.

Takashi

===

Takashi Iwai (15):
  ALSA: memalloc: Minor refactoring
  ALSA: memalloc: Correctly name as WC
  ALSA: pcm: Allow exact buffer preallocation
  ALSA: memalloc: Support WC allocation on all architectures
  ALSA: pxa2xx: Use managed PCM buffer allocation
  ASoC: bcm: Use managed PCM buffer allocation
  ASoC: fsl: imx-pcm-fiq: Use managed buffer allocation
  ASoC: fsl: imx-pcm-rpmsg: Use managed buffer allocation
  ASoC: tegra: Use managed buffer allocation
  ASoC: fsl_asrc_dma: Use managed buffer allocation
  ASoC: fsl_dma: Use managed buffer allocation
  ASoC: mpc5200: Use managed buffer allocation
  ASoC: qcom: lpass: Use managed buffer allocation
  ASoC: qcom: qdsp6: Use managed buffer allocation
  ASoC: sprd: Use managed buffer allocation

 include/sound/memalloc.h             |  6 +-
 include/sound/pcm.h                  | 47 ++++++++++++--
 include/sound/pxa2xx-lib.h           | 13 +---
 sound/arm/pxa2xx-ac97.c              | 18 ++----
 sound/arm/pxa2xx-pcm-lib.c           | 90 ++------------------------
 sound/core/memalloc.c                | 94 +++++++++++++++++-----------
 sound/core/memalloc_local.h          |  2 +-
 sound/core/pcm_memory.c              | 67 +++++++++++++++-----
 sound/core/sgbuf.c                   | 21 ++++---
 sound/pci/hda/hda_controller.c       |  2 +-
 sound/pci/hda/hda_intel.c            |  2 +-
 sound/pci/intel8x0.c                 |  2 +-
 sound/soc/bcm/bcm63xx-pcm-whistler.c | 82 ++----------------------
 sound/soc/fsl/fsl_asrc_dma.c         | 47 +-------------
 sound/soc/fsl/fsl_dma.c              | 50 +--------------
 sound/soc/fsl/imx-pcm-fiq.c          | 75 +---------------------
 sound/soc/fsl/imx-pcm-rpmsg.c        | 89 +-------------------------
 sound/soc/fsl/mpc5200_dma.c          | 63 +------------------
 sound/soc/pxa/pxa-ssp.c              |  3 -
 sound/soc/pxa/pxa2xx-ac97.c          |  3 -
 sound/soc/pxa/pxa2xx-i2s.c           |  3 -
 sound/soc/pxa/pxa2xx-pcm.c           |  3 -
 sound/soc/qcom/lpass-platform.c      | 60 +-----------------
 sound/soc/qcom/qdsp6/q6asm-dai.c     | 63 +------------------
 sound/soc/sprd/sprd-pcm-dma.c        | 67 +-------------------
 sound/soc/tegra/tegra210_admaif.c    |  6 --
 sound/soc/tegra/tegra_pcm.c          | 93 +--------------------------
 sound/soc/tegra/tegra_pcm.h          |  7 ---
 sound/x86/intel_hdmi_audio.c         |  2 +-
 29 files changed, 209 insertions(+), 871 deletions(-)

===

Cc: Banajit Goswami <bgoswami@codeaurora.org>
Cc: Daniel Mack <daniel@zonque.org>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Haojian Zhuang <haojian.zhuang@gmail.com>
Cc: Nicolin Chen <nicoleotsuka@gmail.com>
Cc: Robert Jarzmik <robert.jarzmik@free.fr>
Cc: Shengjiu Wang <shengjiu.wang@gmail.com>
Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: Xiubo Li <Xiubo.Lee@gmail.com>

Comments

Srinivas Kandagatla Aug. 3, 2021, 9:46 a.m. UTC | #1
On 02/08/2021 08:28, Takashi Iwai wrote:
> This patch simplifies the buffer pre-allocation code of qcom qdsp6
> driver with the standard managed buffer helper.  It uses the newly
> introduced fixed-size buffer allocation helper.
> 
> Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> Cc: Banajit Goswami <bgoswami@codeaurora.org>
> Signed-off-by: Takashi Iwai <tiwai@suse.de>

Tested this on DragonBoard DB845c with WSA Playback

Tested-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>

> ---
>   sound/soc/qcom/qdsp6/q6asm-dai.c | 63 ++------------------------------
>   1 file changed, 3 insertions(+), 60 deletions(-)
> 
> diff --git a/sound/soc/qcom/qdsp6/q6asm-dai.c b/sound/soc/qcom/qdsp6/q6asm-dai.c
> index 5ff56a735419..46f365528d50 100644
> --- a/sound/soc/qcom/qdsp6/q6asm-dai.c
> +++ b/sound/soc/qcom/qdsp6/q6asm-dai.c
> @@ -429,8 +429,6 @@ static int q6asm_dai_open(struct snd_soc_component *component,
>   	else
>   		prtd->phys = substream->dma_buffer.addr | (pdata->sid << 32);
>   
> -	snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
> -
>   	return 0;
>   }
>   
> @@ -470,18 +468,6 @@ static snd_pcm_uframes_t q6asm_dai_pointer(struct snd_soc_component *component,
>   	return bytes_to_frames(runtime, (prtd->pcm_irq_pos));
>   }
>   
> -static int q6asm_dai_mmap(struct snd_soc_component *component,
> -			  struct snd_pcm_substream *substream,
> -			  struct vm_area_struct *vma)
> -{
> -	struct snd_pcm_runtime *runtime = substream->runtime;
> -	struct device *dev = component->dev;
> -
> -	return dma_mmap_coherent(dev, vma,
> -			runtime->dma_area, runtime->dma_addr,
> -			runtime->dma_bytes);
> -}
> -
>   static int q6asm_dai_hw_params(struct snd_soc_component *component,
>   			       struct snd_pcm_substream *substream,
>   			       struct snd_pcm_hw_params *params)
> @@ -1185,52 +1171,11 @@ static const struct snd_compress_ops q6asm_dai_compress_ops = {
>   static int q6asm_dai_pcm_new(struct snd_soc_component *component,
>   			     struct snd_soc_pcm_runtime *rtd)
>   {
> -	struct snd_pcm_substream *psubstream, *csubstream;
>   	struct snd_pcm *pcm = rtd->pcm;
> -	struct device *dev;
> -	int size, ret;
> -
> -	dev = component->dev;
> -	size = q6asm_dai_hardware_playback.buffer_bytes_max;
> -	psubstream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
> -	if (psubstream) {
> -		ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, dev, size,
> -					  &psubstream->dma_buffer);
> -		if (ret) {
> -			dev_err(dev, "Cannot allocate buffer(s)\n");
> -			return ret;
> -		}
> -	}
> +	size_t size = q6asm_dai_hardware_playback.buffer_bytes_max;
>   
> -	csubstream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
> -	if (csubstream) {
> -		ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, dev, size,
> -					  &csubstream->dma_buffer);
> -		if (ret) {
> -			dev_err(dev, "Cannot allocate buffer(s)\n");
> -			if (psubstream)
> -				snd_dma_free_pages(&psubstream->dma_buffer);
> -			return ret;
> -		}
> -	}
> -
> -	return 0;
> -}
> -
> -static void q6asm_dai_pcm_free(struct snd_soc_component *component,
> -			       struct snd_pcm *pcm)
> -{
> -	struct snd_pcm_substream *substream;
> -	int i;
> -
> -	for (i = 0; i < ARRAY_SIZE(pcm->streams); i++) {
> -		substream = pcm->streams[i].substream;
> -		if (substream) {
> -			snd_dma_free_pages(&substream->dma_buffer);
> -			substream->dma_buffer.area = NULL;
> -			substream->dma_buffer.addr = 0;
> -		}
> -	}
> +	return snd_pcm_set_fixed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
> +					    component->dev, size);
>   }
>   
>   static const struct snd_soc_dapm_widget q6asm_dapm_widgets[] = {
> @@ -1260,9 +1205,7 @@ static const struct snd_soc_component_driver q6asm_fe_dai_component = {
>   	.prepare	= q6asm_dai_prepare,
>   	.trigger	= q6asm_dai_trigger,
>   	.pointer	= q6asm_dai_pointer,
> -	.mmap		= q6asm_dai_mmap,
>   	.pcm_construct	= q6asm_dai_pcm_new,
> -	.pcm_destruct	= q6asm_dai_pcm_free,
>   	.compress_ops	= &q6asm_dai_compress_ops,
>   	.dapm_widgets	= q6asm_dapm_widgets,
>   	.num_dapm_widgets = ARRAY_SIZE(q6asm_dapm_widgets),
>