ALSA/DRM: vmalloc PCM buffer helper cleanup
Subsystems (4)
cover ALSA/DRM: vmalloc PCM buffer helper cleanup
Hi,
we still keep the legacy vmalloc ALSA PCM helper API since there is only a single user of it, namely, the DRM dw-hdmi bridge driver. In the past, I attempted to change the buffer management of the driver, but due to the lack of testing, it failed to get merged:
https://lore.kernel.org/[email protected]
So, this is a second try after some years of gap: now the relevant code snippet is moved from ALSA core to dw-hdmi driver itself, and the API functions are dropped. There should be no functional changes in the driver.
If DRM people don't mind and give an ack, I can take the change for dw-hdmi code together with ALSA core code drop via sound tree for 6.12.
thanks,
Takashi
===
Takashi Iwai (2):
drm/bridge: dw-hdmi: Move vmalloc PCM buffer management into the
driver
ALSA: pcm: Drop PCM vmalloc buffer helpers
.../drm/bridge/synopsys/dw-hdmi-ahb-audio.c | 30 ++++++++-- include/sound/pcm.h | 42 ------------- sound/core/pcm_memory.c | 59 ------------------- 3 files changed, 26 insertions(+), 105 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/2 drm/bridge: dw-hdmi: Move vmalloc PCM buffer management into the driver
The dw-hdmi drm bridge driver is the only one who still uses the ALSA vmalloc helper API functions. A previous attempt to change the way of buffer management wasn't taken for this legacy stuff, as we had little chance for test and some risk of major breaking.
Instead, this patch moves the vmalloc buffer stuff into the dw-hdmi driver code itself, so that we can drop them from ALSA core code afterwards.
There should be no functional changes.
--- .../drm/bridge/synopsys/dw-hdmi-ahb-audio.c | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-)
drivers/gpu/drm/bridge/synopsys/dw-hdmi-ahb-audio.c +26 -4
@@ -8,6 +8,7 @@#include <linux/interrupt.h> #include <linux/module.h> #include <linux/platform_device.h> +#include <linux/vmalloc.h> #include <drm/bridge/dw_hdmi.h> #include <drm/drm_edid.h>
@@ -388,15 +389,36 @@ static int dw_hdmi_close(struct snd_pcm_substream *substream)static int dw_hdmi_hw_free (struct snd_pcm_substream *substream) { -return snd_pcm_lib_free_vmalloc_buffer (substream); +struct snd_pcm_runtime *runtime = substream->runtime; + +vfree (runtime->dma_area); + runtime->dma_area =NULL ; +return 0 ; }static int dw_hdmi_hw_params (struct snd_pcm_substream *substream,struct snd_pcm_hw_params *params) { +struct snd_pcm_runtime *runtime = substream->runtime; +size_t size =params_buffer_bytes (params); +/* Allocate the PCM runtime buffer, which is exposed to userspace. */ -return snd_pcm_lib_alloc_vmalloc_buffer (substream, -params_buffer_bytes (params)); +if (runtime->dma_area) { +if (runtime->dma_bytes >= size) +return 0 ;/* already large enough */ +vfree (runtime->dma_area); + } + runtime->dma_area =vzalloc (size); +if (!runtime->dma_area) +return -ENOMEM ; + runtime->dma_bytes = size; +return 1 ; +} + +static struct page *dw_hdmi_get_page (struct snd_pcm_substream *substream, +unsigned long offset) +{ +return vmalloc_to_page (substream->runtime->dma_area + offset); }static int dw_hdmi_prepare (struct snd_pcm_substream *substream)
@@ -515,7 +537,7 @@ static const struct snd_pcm_ops snd_dw_hdmi_ops = { .prepare = dw_hdmi_prepare, .trigger = dw_hdmi_trigger, .pointer = dw_hdmi_pointer, - .page = snd_pcm_lib_get_vmalloc_page, + .page = dw_hdmi_get_page, };static int snd_dw_hdmi_probe (struct platform_device *pdev)
Signature · 1 line
2.43.0
Re: [PATCH 1/2] drm/bridge: dw-hdmi: Move vmalloc PCM buffer management into the driver
Quoted 69 lines · Takashi Iwai
The dw-hdmi drm bridge driver is the only one who still uses the ALSA vmalloc helper API functions. A previous attempt to change the way of buffer management wasn't taken for this legacy stuff, as we had little chance for test and some risk of major breaking.
Instead, this patch moves the vmalloc buffer stuff into the dw-hdmi driver code itself, so that we can drop them from ALSA core code afterwards.There should be no functional changes.
Signed-off-by Takashi Iwai <[email protected]>--- .../drm/bridge/synopsys/dw-hdmi-ahb-audio.c | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-)drivers/gpu/drm/bridge/synopsys/dw-hdmi-ahb-audio.c +25
-3@@ -8,6 +8,7 @@#include <linux/interrupt.h> #include <linux/module.h> #include <linux/platform_device.h> +#include <linux/vmalloc.h> #include <drm/bridge/dw_hdmi.h> #include <drm/drm_edid.h> @@ -388,15 +389,36 @@ static int dw_hdmi_close(struct snd_pcm_substream *substream)static int dw_hdmi_hw_free (struct snd_pcm_substream *substream) { -return snd_pcm_lib_free_vmalloc_buffer (substream); +struct snd_pcm_runtime *runtime = substream->runtime; + +vfree (runtime->dma_area); + runtime->dma_area =NULL ; +return 0 ; }static int dw_hdmi_hw_params (struct snd_pcm_substream *substream,struct snd_pcm_hw_params *params) { +struct snd_pcm_runtime *runtime = substream->runtime; +size_t size =params_buffer_bytes (params); +/* Allocate the PCM runtime buffer, which is exposed to userspace. */ -return snd_pcm_lib_alloc_vmalloc_buffer (substream, -params_buffer_bytes (params)); +if (runtime->dma_area) { +if (runtime->dma_bytes >= size) +return 0 ;/* already large enough */ +vfree (runtime->dma_area); + } + runtime->dma_area =vzalloc (size); +if (!runtime->dma_area) +return -ENOMEM ; + runtime->dma_bytes = size; +return 1 ; +} + +static struct page *dw_hdmi_get_page (struct snd_pcm_substream *substream, +unsigned long offset) +{ +return vmalloc_to_page (substream->runtime->dma_area + offset); }static int dw_hdmi_prepare (struct snd_pcm_substream *substream)
drivers/gpu/drm/bridge/synopsys/dw-hdmi-ahb-audio.c static const struct snd_pcm_ops snd_dw_hdmi_ops = { · line 543
Quoted 8 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi-ahb-audio.c +1
-1@@ -515,7 +537,7 @@ static const struct snd_pcm_ops snd_dw_hdmi_ops = { .prepare = dw_hdmi_prepare, .trigger = dw_hdmi_trigger, .pointer = dw_hdmi_pointer, - .page = snd_pcm_lib_get_vmalloc_page, + .page = dw_hdmi_get_page, };static int snd_dw_hdmi_probe (struct platform_device *pdev)
PATCH 2/2 ALSA: pcm: Drop PCM vmalloc buffer helpers
In reply to Takashi IwaiAs the last-standing user of PCM vmalloc buffer helper API took its own buffer management, we can finally drop those API functions, which were leftover after reorganization of ALSA memalloc code.
--- include/sound/pcm.h | 42 ----------------------------- sound/core/pcm_memory.c | 59 ----------------------------------------- 2 files changed, 101 deletions(-)
include/sound/pcm.h +0 -42
@@ -1355,48 +1355,6 @@ snd_pcm_set_fixed_buffer_all(struct snd_pcm *pcm, int type,return snd_pcm_set_managed_buffer_all (pcm, type, data, size,0 ); } -int _snd_pcm_lib_alloc_vmalloc_buffer (struct snd_pcm_substream *substream, -size_t size,gfp_t gfp_flags); -int snd_pcm_lib_free_vmalloc_buffer (struct snd_pcm_substream *substream); -struct page *snd_pcm_lib_get_vmalloc_page (struct snd_pcm_substream *substream, -unsigned long offset); -/** -* snd_pcm_lib_alloc_vmalloc_buffer - allocate virtual DMA buffer -* @substream: the substream to allocate the buffer to -* @size: the requested buffer size, in bytes -* -* Allocates the PCM substream buffer using vmalloc(), i.e., the memory is -* contiguous in kernel virtual space, but not in physical memory. Use this -* if the buffer is accessed by kernel code but not by device DMA. -* -* Return: 1 if the buffer was changed, 0 if not changed, or a negative error -* code. -*/ -static inline int snd_pcm_lib_alloc_vmalloc_buffer - (struct snd_pcm_substream *substream,size_t size) -{ -return _snd_pcm_lib_alloc_vmalloc_buffer (substream, size, -GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO); -} - -/** -* snd_pcm_lib_alloc_vmalloc_32_buffer - allocate 32-bit-addressable buffer -* @substream: the substream to allocate the buffer to -* @size: the requested buffer size, in bytes -* -* This function works like snd_pcm_lib_alloc_vmalloc_buffer(), but uses -* vmalloc_32(), i.e., the pages are allocated from 32-bit-addressable memory. -* -* Return: 1 if the buffer was changed, 0 if not changed, or a negative error -* code. -*/ -static inline int snd_pcm_lib_alloc_vmalloc_32_buffer - (struct snd_pcm_substream *substream,size_t size) -{ -return _snd_pcm_lib_alloc_vmalloc_buffer (substream, size, -GFP_KERNEL |GFP_DMA32 | __GFP_ZERO); -} -#define snd_pcm_get_dma_buf (substream) ((substream)->runtime->dma_buffer_p)/**
sound/core/pcm_memory.c +0 -59
68 lines not on this page · raw message
Signature · 1 line
2.43.0
Quoted 9 lines · Takashi Iwai
Hi,
we still keep the legacy vmalloc ALSA PCM helper API since there is only a single user of it, namely, the DRM dw-hdmi bridge driver. In the past, I attempted to change the buffer management of the driver, but due to the lack of testing, it failed to get merged:
https://lore.kernel.org/[email protected]
Quoted 8 lines
So, this is a second try after some years of gap: now the relevant code snippet is moved from ALSA core to dw-hdmi driver itself, and the API functions are dropped. There should be no functional changes in the driver.
If DRM people don't mind and give an ack, I can take the change for dw-hdmi code together with ALSA core code drop via sound tree for 6.12.
Gentle ping to any DRM reviewers. It's merely a safe clean up, so if you don't mind, I'd like to take for 6.12.
thanks,
Takashi
Quoted 21 lines
thanks,
Takashi
===
Takashi Iwai (2):
drm/bridge: dw-hdmi: Move vmalloc PCM buffer management into the
driver
ALSA: pcm: Drop PCM vmalloc buffer helpers.../drm/bridge/synopsys/dw-hdmi-ahb-audio.c | 30 ++++++++-- include/sound/pcm.h | 42 ------------- sound/core/pcm_memory.c | 59 ------------------- 3 files changed, 26 insertions(+), 105 deletions(-)Signature · 1 line
2.43.0
Quoted 17 lines · Takashi Iwai
Quoted 14 lines · Takashi Iwai
Hi,
we still keep the legacy vmalloc ALSA PCM helper API since there is only a single user of it, namely, the DRM dw-hdmi bridge driver. In the past, I attempted to change the buffer management of the driver, but due to the lack of testing, it failed to get merged:
https://lore.kernel.org/[email protected]So, this is a second try after some years of gap: now the relevant code snippet is moved from ALSA core to dw-hdmi driver itself, and the API functions are dropped. There should be no functional changes in the driver.
Quoted 6 lines
Quoted 3 lines
If DRM people don't mind and give an ack, I can take the change for dw-hdmi code together with ALSA core code drop via sound tree for 6.12.
Gentle ping to any DRM reviewers. It's merely a safe clean up, so if you don't mind, I'd like to take for 6.12.
Now merged to for-next branch of sound.git tree.
Takashi