ASoC: memalloc cleanups
Subsystems (7)
cover ASoC: memalloc cleanups
Hi,
this is a patch series for ASoC to clean up ALSA memory allocation API usages. It's based on my recent API changes found on for-next branch for 5.5 merge, so please give ACK if it's OK, so that I can merge them into my sound git tree.
Basically three things:
* Drop superfluous snd_pcm_sgbuf_ops_page usages
* Drop snd_dma_continuous_data() macro usage for the normal continuous page allocation
* Convert PCM vmalloc buffer allocation with the preallocation API
Takashi
===
Takashi Iwai (8):
ASoC: Remove superfluous snd_dma_continuous_data()
ASoC: rt5514-spi: Convert to the common vmalloc memalloc
ASoC: intel: Drop superfluous snd_pcm_sgbuf_ops_page
ASoC: intel: Avoid non-standard macro usage
ASoC: SOF: Drop superfluous snd_pcm_sgbuf_ops_page
ASoC: rt5677-spi: Convert to the common vmalloc memalloc
ASoC: cros_ec_codec: Convert to the common vmalloc memalloc
ALSA: pcm: Unexport snd_pcm_sgbuf_ops_page
include/sound/pcm.h | 8 -------- sound/core/pcm_local.h | 5 +++++ sound/core/pcm_memory.c | 3 +-- sound/soc/au1x/dma.c | 2 +- sound/soc/codecs/cros_ec_codec.c | 16 ++++++++-------- sound/soc/codecs/rt5514-spi.c | 21 +++++++++++---------- sound/soc/codecs/rt5677-spi.c | 17 ++++++++--------- sound/soc/dwc/dwc-pcm.c | 2 +- sound/soc/intel/haswell/sst-haswell-pcm.c | 12 ------------ sound/soc/intel/skylake/skl-pcm.c | 14 +------------- sound/soc/sh/dma-sh7760.c | 2 +- sound/soc/sof/pcm.c | 12 ------------ 12 files changed, 37 insertions(+), 77 deletions(-)
Signature · 6 lines
2.16.4 _______________________________________________ Alsa-devel mailing list [email protected] https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
PATCH 1/8 ASoC: Remove superfluous snd_dma_continuous_data()
The recent change (commit 08422d2c559d: "ALSA: memalloc: Allow NULL device for SNDRV_DMA_TYPE_CONTINOUS type") made the PCM preallocation helper accepting NULL as the device pointer for the default usage. Drop the snd_dma_continuous_data() usage that became superfluous from the callers.
--- sound/soc/au1x/dma.c | 2 +- sound/soc/dwc/dwc-pcm.c | 2 +- sound/soc/sh/dma-sh7760.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
sound/soc/au1x/dma.c +1 -1
@@ -293,7 +293,7 @@ static int alchemy_pcm_new(struct snd_soc_component *component,struct snd_pcm *pcm = rtd->pcm;snd_pcm_lib_preallocate_pages_for_all (pcm,SNDRV_DMA_TYPE_CONTINUOUS , -snd_dma_continuous_data (GFP_KERNEL ),65536 , (4096 *1024 ) -1 ); +NULL ,65536 , (4096 *1024 ) -1 );return 0 ; }
sound/soc/dwc/dwc-pcm.c +1 -1
@@ -258,7 +258,7 @@ static int dw_pcm_new(struct snd_soc_component *component,snd_pcm_lib_preallocate_pages_for_all (rtd->pcm,SNDRV_DMA_TYPE_CONTINUOUS , -snd_dma_continuous_data (GFP_KERNEL ), size, size); +NULL , size, size);return 0 ; }
sound/soc/sh/dma-sh7760.c +1 -1
@@ -309,7 +309,7 @@ static int camelot_pcm_new(struct snd_soc_component *component,*/ snd_pcm_lib_preallocate_pages_for_all (pcm,SNDRV_DMA_TYPE_CONTINUOUS , -snd_dma_continuous_data (GFP_KERNEL ), +NULL ,DMABRG_PREALLOC_BUFFER ,DMABRG_PREALLOC_BUFFER_MAX );return 0 ;
Signature · 6 lines
2.16.4 _______________________________________________ Alsa-devel mailing list [email protected] https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
PATCH 2/8 ASoC: rt5514-spi: Convert to the common vmalloc memalloc
In reply to Takashi IwaiThe recent change (*) in the ALSA memalloc core allows us to drop the special vmalloc-specific allocation and page handling. This patch coverts to the common code.
(*) 1fe7f397cfe2: ALSA: memalloc: Add vmalloc buffer allocation
support
7e8edae39fd1: ALSA: pcm: Handle special page mapping in the
default mmap handler
Since it requires the specific buffer type (SNDRV_DMA_TYPE_VMALLOC), it's set in the pcm_new ops now.
--- sound/soc/codecs/rt5514-spi.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
sound/soc/codecs/rt5514-spi.c +11 -10
@@ -219,8 +219,7 @@ static int rt5514_spi_hw_params(struct snd_soc_component *component,u8 buf[8 ];mutex_lock (&rt5514_dsp->dma_lock); - ret =snd_pcm_lib_alloc_vmalloc_buffer (substream, -params_buffer_bytes (hw_params)); + ret =snd_pcm_lib_malloc_pages (substream,params_buffer_bytes (hw_params)); rt5514_dsp->substream = substream; rt5514_dsp->dma_offset =0 ;
@@ -246,7 +245,7 @@ static int rt5514_spi_hw_free(struct snd_soc_component *component,cancel_delayed_work_sync (&rt5514_dsp->copy_work); -return snd_pcm_lib_free_vmalloc_buffer (substream); +return snd_pcm_lib_free_pages (substream); } static snd_pcm_uframes_t rt5514_spi_pcm_pointer(
@@ -260,12 +259,6 @@ static snd_pcm_uframes_t rt5514_spi_pcm_pointer(return bytes_to_frames (runtime, rt5514_dsp->dma_offset); } -static struct page *rt5514_spi_pcm_page (struct snd_soc_component *component, -struct snd_pcm_substream *substream, -unsigned long offset) -{ -return snd_pcm_lib_get_vmalloc_page (substream, offset); -}static int rt5514_spi_pcm_probe (struct snd_soc_component *component) {
@@ -298,6 +291,14 @@ static int rt5514_spi_pcm_probe(struct snd_soc_component *component)return 0 ; } +static int rt5514_spi_pcm_new (struct snd_soc_component *component, +struct snd_soc_pcm_runtime *rtd) +{ +snd_pcm_lib_preallocate_pages_for_all (rtd->pcm,SNDRV_DMA_TYPE_VMALLOC , +NULL ,0 ,0 ); +return 0 ; +} +static const struct snd_soc_component_driver rt5514_spi_component = { .name =DRV_NAME , .probe = rt5514_spi_pcm_probe,
@@ -305,7 +306,7 @@ static const struct snd_soc_component_driver rt5514_spi_component = { .hw_params = rt5514_spi_hw_params, .hw_free = rt5514_spi_hw_free, .pointer = rt5514_spi_pcm_pointer, - .page = rt5514_spi_pcm_page, + .pcm_construct = rt5514_spi_pcm_new, };/**
Signature · 6 lines
2.16.4 _______________________________________________ Alsa-devel mailing list [email protected] https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
PATCH 3/8 ASoC: intel: Drop superfluous snd_pcm_sgbuf_ops_page
In reply to Takashi Iwaisnd_pcm_sgbuf_ops_page is no longer needed to be set explicitly to PCM page ops since the recent change in the PCM core (*). Leaving it NULL should work as long as the preallocation has been done properly.
This patch drops the redundant lines.
(*) 7e8edae39fd1: ALSA: pcm: Handle special page mapping in the
default mmap handler
--- sound/soc/intel/haswell/sst-haswell-pcm.c | 12 ------------ sound/soc/intel/skylake/skl-pcm.c | 12 ------------ 2 files changed, 24 deletions(-)
sound/soc/intel/haswell/sst-haswell-pcm.c +0 -12
@@ -796,17 +796,6 @@ static snd_pcm_uframes_t hsw_pcm_pointer(struct snd_soc_component *component,return offset; } -#ifdef CONFIG_SND_DMA_SGBUF -static struct page *hsw_pcm_page (struct snd_soc_component *component, -struct snd_pcm_substream *substream, -unsigned long offset) -{ -return snd_pcm_sgbuf_ops_page (substream, offset); -} -#else -#define hsw_pcm_page NULL -#endif /* CONFIG_SND_DMA_SGBUF */ -static int hsw_pcm_open (struct snd_soc_component *component,struct snd_pcm_substream *substream) {
@@ -1128,7 +1117,6 @@ static const struct snd_soc_component_driver hsw_dai_component = { .hw_free = hsw_pcm_hw_free, .trigger = hsw_pcm_trigger, .pointer = hsw_pcm_pointer, - .page = hsw_pcm_page, .ioctl = snd_soc_pcm_lib_ioctl, .pcm_construct = hsw_pcm_new, .controls = hsw_volume_controls,
sound/soc/intel/skylake/skl-pcm.c +0 -12
@@ -1235,17 +1235,6 @@ static int skl_platform_soc_mmap(struct snd_soc_component *component,return snd_pcm_lib_default_mmap (substream, area); } -#ifdef CONFIG_SND_DMA_SGBUF -static struct page *skl_platform_soc_page (struct snd_soc_component *component, -struct snd_pcm_substream *substream, -unsigned long offset) -{ -return snd_pcm_sgbuf_ops_page (substream, offset); -} -#else -#define skl_platform_soc_page NULL -#endif /* CONFIG_SND_DMA_SGBUF */ -static u64 skl_adjust_codec_delay (struct snd_pcm_substream *substream,u64 nsec) {
@@ -1493,7 +1482,6 @@ static const struct snd_soc_component_driver skl_component = { .pointer = skl_platform_soc_pointer, .get_time_info = skl_platform_soc_get_time_info, .mmap = skl_platform_soc_mmap, - .page = skl_platform_soc_page, .pcm_construct = skl_platform_soc_new, .pcm_destruct = skl_platform_soc_free, .module_get_upon_open = 1, /* increment refcount when a pcm is opened */
Signature · 6 lines
2.16.4 _______________________________________________ Alsa-devel mailing list [email protected] https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
PATCH 4/8 ASoC: intel: Avoid non-standard macro usage
In reply to Takashi IwaiPass the device pointer from the PCI pointer directly, instead of a non-standard macro. The macro didn't give any better readability.
--- sound/soc/intel/skylake/skl-pcm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/intel/skylake/skl-pcm.c +1 -1
@@ -1314,7 +1314,7 @@ static int skl_platform_soc_new(struct snd_soc_component *component, size =MAX_PREALLOC_SIZE ;snd_pcm_lib_preallocate_pages_for_all (pcm,SNDRV_DMA_TYPE_DEV_SG , -snd_dma_pci_data (skl->pci), + &skl->pci->dev, size,MAX_PREALLOC_SIZE ); }
Signature · 6 lines
2.16.4 _______________________________________________ Alsa-devel mailing list [email protected] https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
PATCH 5/8 ASoC: SOF: Drop superfluous snd_pcm_sgbuf_ops_page
In reply to Takashi Iwaisnd_pcm_sgbuf_ops_page is no longer needed to be set explicitly to PCM page ops since the recent change in the PCM core (*). Leaving it NULL should work as long as the preallocation has been done properly.
This patch drops the redundant lines.
(*) 7e8edae39fd1: ALSA: pcm: Handle special page mapping in the
default mmap handler
--- sound/soc/sof/pcm.c | 12 ------------ 1 file changed, 12 deletions(-)
sound/soc/sof/pcm.c +0 -12
@@ -454,17 +454,6 @@ static snd_pcm_uframes_t sof_pcm_pointer(struct snd_soc_component *component,return host; } -#ifdef CONFIG_SND_DMA_SGBUF -static struct page *sof_pcm_page (struct snd_soc_component *component, -struct snd_pcm_substream *substream, -unsigned long offset) -{ -return snd_pcm_sgbuf_ops_page (substream, offset); -} -#else -#define sof_pcm_page NULL -#endif /* CONFIG_SND_DMA_SGBUF */ -static int sof_pcm_open (struct snd_soc_component *component,struct snd_pcm_substream *substream) {
@@ -788,7 +777,6 @@ void snd_sof_new_platform_drv(struct snd_sof_dev *sdev) pd->hw_free = sof_pcm_hw_free; pd->trigger = sof_pcm_trigger; pd->pointer = sof_pcm_pointer; - pd->page = sof_pcm_page;#if IS_ENABLED (CONFIG_SND_SOC_SOF_COMPRESS ) pd->compr_ops = &sof_compressed_ops;
Signature · 6 lines
2.16.4 _______________________________________________ Alsa-devel mailing list [email protected] https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
PATCH 6/8 ASoC: rt5677-spi: Convert to the common vmalloc memalloc
In reply to Takashi IwaiThe recent change (*) in the ALSA memalloc core allows us to drop the special vmalloc-specific allocation and page handling. This patch coverts to the common code.
(*) 1fe7f397cfe2: ALSA: memalloc: Add vmalloc buffer allocation
support
7e8edae39fd1: ALSA: pcm: Handle special page mapping in the
default mmap handler
--- sound/soc/codecs/rt5677-spi.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
sound/soc/codecs/rt5677-spi.c +8 -9
@@ -128,8 +128,7 @@ static int rt5677_spi_hw_params(int ret;mutex_lock (&rt5677_dsp->dma_lock); - ret =snd_pcm_lib_alloc_vmalloc_buffer (substream, -params_buffer_bytes (hw_params)); + ret =snd_pcm_lib_malloc_pages (substream,params_buffer_bytes (hw_params)); rt5677_dsp->substream = substream;mutex_unlock (&rt5677_dsp->dma_lock);
@@ -147,7 +146,7 @@ static int rt5677_spi_hw_free( rt5677_dsp->substream =NULL ;mutex_unlock (&rt5677_dsp->dma_lock); -return snd_pcm_lib_free_vmalloc_buffer (substream); +return snd_pcm_lib_free_pages (substream); } static int rt5677_spi_prepare(
@@ -361,12 +360,12 @@ static void rt5677_spi_copy_work(struct work_struct *work)mutex_unlock (&rt5677_dsp->dma_lock); } -static struct page *rt5677_spi_pcm_page ( -struct snd_soc_component *component, -struct snd_pcm_substream *substream, -unsigned long offset) +static int rt5677_spi_pcm_new (struct snd_soc_component *component, +struct snd_soc_pcm_runtime *rtd) { -return snd_pcm_lib_get_vmalloc_page (substream, offset); +snd_pcm_lib_preallocate_pages_for_all (rtd->pcm,SNDRV_DMA_TYPE_VMALLOC , +NULL ,0 ,0 ); +return 0 ; }static int rt5677_spi_pcm_probe (struct snd_soc_component *component)
@@ -394,7 +393,7 @@ static const struct snd_soc_component_driver rt5677_spi_dai_component = { .hw_free = rt5677_spi_hw_free, .prepare = rt5677_spi_prepare, .pointer = rt5677_spi_pcm_pointer, - .page = rt5677_spi_pcm_page, + .pcm_construct = rt5677_spi_pcm_new, };/* Select a suitable transfer command for the next transfer to ensure
Signature · 6 lines
2.16.4 _______________________________________________ Alsa-devel mailing list [email protected] https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Re: [alsa-devel] [PATCH 6/8] ASoC: rt5677-spi: Convert to the common vmalloc memalloc
Quoted 10 lines · Takashi Iwai
The recent change (*) in the ALSA memalloc core allows us to drop the special vmalloc-specific allocation and page handling. This patch coverts to the common code.
(*)1fe7f397cfe2: ALSA: memalloc: Add vmalloc buffer allocation
support
7e8edae39fd1: ALSA: pcm: Handle special page mapping in the
default mmap handlerSigned-off-by Takashi Iwai <[email protected]>
Passes sanity checks on my end
sound/soc/codecs/rt5677-spi.c
Quoted 7 lines
--- sound/soc/codecs/rt5677-spi.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)sound/soc/codecs/rt5677-spi.c +0
-0
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
PATCH 7/8 ASoC: cros_ec_codec: Convert to the common vmalloc memalloc
In reply to Takashi IwaiThe recent change (*) in the ALSA memalloc core allows us to drop the special vmalloc-specific allocation and page handling. This patch coverts to the common code.
(*) 1fe7f397cfe2: ALSA: memalloc: Add vmalloc buffer allocation
support
7e8edae39fd1: ALSA: pcm: Handle special page mapping in the
default mmap handler
--- sound/soc/codecs/cros_ec_codec.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
sound/soc/codecs/cros_ec_codec.c +8 -8
@@ -918,8 +918,7 @@ static int wov_pcm_hw_params(struct snd_soc_component *component, priv->wov_burst_read = true;mutex_unlock (&priv->wov_dma_lock); -return snd_pcm_lib_alloc_vmalloc_buffer (substream, -params_buffer_bytes (hw_params)); +return snd_pcm_lib_malloc_pages (substream,params_buffer_bytes (hw_params)); } static int wov_pcm_hw_free(struct snd_soc_component *component,
@@ -935,7 +934,7 @@ static int wov_pcm_hw_free(struct snd_soc_component *component,cancel_delayed_work_sync (&priv->wov_copy_work); -return snd_pcm_lib_free_vmalloc_buffer (substream); +return snd_pcm_lib_free_pages (substream); } static snd_pcm_uframes_t wov_pcm_pointer(struct snd_soc_component *component,
@@ -948,11 +947,12 @@ static snd_pcm_uframes_t wov_pcm_pointer(struct snd_soc_component *component,return bytes_to_frames (runtime, priv->wov_dma_offset); } -static struct page *wov_pcm_page (struct snd_soc_component *component, -struct snd_pcm_substream *substream, -unsigned long offset) +static int wov_pcm_new (struct snd_soc_component *component, +struct snd_soc_pcm_runtime *rtd) { -return snd_pcm_lib_get_vmalloc_page (substream, offset); +snd_pcm_lib_preallocate_pages_for_all (rtd->pcm,SNDRV_DMA_TYPE_VMALLOC , +NULL ,0 ,0 ); +return 0 ; }static const struct snd_soc_component_driver wov_component_driver = {
@@ -964,7 +964,7 @@ static const struct snd_soc_component_driver wov_component_driver = { .hw_params = wov_pcm_hw_params, .hw_free = wov_pcm_hw_free, .pointer = wov_pcm_pointer, - .page = wov_pcm_page, + .pcm_construct = wov_pcm_new, };static int cros_ec_codec_platform_probe (struct platform_device *pdev)
Signature · 6 lines
2.16.4 _______________________________________________ Alsa-devel mailing list [email protected] https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
PATCH 8/8 ALSA: pcm: Unexport snd_pcm_sgbuf_ops_page
In reply to Takashi IwaiThe helper is no longer referred after the recent code refactoring. Drop the export for saving some bits and future misuse.
--- include/sound/pcm.h | 8 -------- sound/core/pcm_local.h | 5 +++++ sound/core/pcm_memory.c | 3 +-- 3 files changed, 6 insertions(+), 10 deletions(-)
include/sound/pcm.h +0 -8
@@ -1236,14 +1236,6 @@ static inline int snd_pcm_lib_alloc_vmalloc_32_buffer*/ #define snd_pcm_substream_sgbuf (substream) \ snd_pcm_get_dma_buf(substream)->private_data - -struct page *snd_pcm_sgbuf_ops_page (struct snd_pcm_substream *substream, -unsigned long offset); -#else /* !SND_DMA_SGBUF */ -/* -* fake using a continuous buffer -*/ -#define snd_pcm_sgbuf_ops_page NULL#endif /* SND_DMA_SGBUF */ /**
sound/core/pcm_local.h +5 -0
@@ -67,4 +67,9 @@ static inline void snd_pcm_timer_done(struct snd_pcm_substream *substream) {}void __snd_pcm_xrun (struct snd_pcm_substream *substream);void snd_pcm_group_init (struct snd_pcm_group *group); +#ifdef CONFIG_SND_DMA_SGBUF +struct page *snd_pcm_sgbuf_ops_page (struct snd_pcm_substream *substream, +unsigned long offset); +#endif +#endif /* __SOUND_CORE_PCM_LOCAL_H */
sound/core/pcm_memory.c +1 -2
@@ -255,7 +255,7 @@ void snd_pcm_lib_preallocate_pages_for_all(struct snd_pcm *pcm,EXPORT_SYMBOL (snd_pcm_lib_preallocate_pages_for_all);#ifdef CONFIG_SND_DMA_SGBUF -/** +/* * snd_pcm_sgbuf_ops_page - get the page struct at the given offset * @substream: the pcm substream instance * @offset: the buffer offset
@@ -273,7 +273,6 @@ struct page *snd_pcm_sgbuf_ops_page(struct snd_pcm_substream *substream, unsignereturn NULL ; return sgbuf->page_table[idx]; } -EXPORT_SYMBOL (snd_pcm_sgbuf_ops_page);#endif /* CONFIG_SND_DMA_SGBUF */ /**
Signature · 6 lines
2.16.4 _______________________________________________ Alsa-devel mailing list [email protected] https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 6 lines · Takashi Iwai
Hi,
this is a patch series for ASoC to clean up ALSA memory allocation API usages. It's based on my recent API changes found on for-next branch for 5.5 merge, so please give ACK if it's OK, so that I can merge them into my sound git tree.
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel