ALSA: memalloc: Add vmalloc buffer allocation support
This patch adds the vmalloc buffer support to ALSA memalloc core. A new type, SNDRV_DMA_TYPE_VMALLOC was added. The vmalloc buffer has been already supported in the PCM via a few own helper functions, but the user sometimes get confused and misuse them. With this patch, the whole buffer management is integrated into the memalloc core, so they can be used in a sole common way. Link: https://lore.kernel.org/r/20191105080138.1260-3-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
08422d2c55
commit
1fe7f397cf
|
@ -44,6 +44,7 @@ struct snd_dma_device {
|
||||||
#else
|
#else
|
||||||
#define SNDRV_DMA_TYPE_DEV_IRAM SNDRV_DMA_TYPE_DEV
|
#define SNDRV_DMA_TYPE_DEV_IRAM SNDRV_DMA_TYPE_DEV
|
||||||
#endif
|
#endif
|
||||||
|
#define SNDRV_DMA_TYPE_VMALLOC 7 /* vmalloc'ed buffer */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* info for buffer allocation
|
* info for buffer allocation
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <linux/mm.h>
|
#include <linux/mm.h>
|
||||||
#include <linux/dma-mapping.h>
|
#include <linux/dma-mapping.h>
|
||||||
#include <linux/genalloc.h>
|
#include <linux/genalloc.h>
|
||||||
|
#include <linux/vmalloc.h>
|
||||||
#ifdef CONFIG_X86
|
#ifdef CONFIG_X86
|
||||||
#include <asm/set_memory.h>
|
#include <asm/set_memory.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -99,10 +100,11 @@ static void snd_free_dev_iram(struct snd_dma_buffer *dmab)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static inline gfp_t snd_mem_get_gfp_flags(const struct device *dev)
|
static inline gfp_t snd_mem_get_gfp_flags(const struct device *dev,
|
||||||
|
gfp_t default_gfp)
|
||||||
{
|
{
|
||||||
if (!dev)
|
if (!dev)
|
||||||
return GFP_KERNEL;
|
return default_gfp;
|
||||||
else
|
else
|
||||||
return (__force gfp_t)(unsigned long)dev;
|
return (__force gfp_t)(unsigned long)dev;
|
||||||
}
|
}
|
||||||
|
@ -123,6 +125,8 @@ static inline gfp_t snd_mem_get_gfp_flags(const struct device *dev)
|
||||||
int snd_dma_alloc_pages(int type, struct device *device, size_t size,
|
int snd_dma_alloc_pages(int type, struct device *device, size_t size,
|
||||||
struct snd_dma_buffer *dmab)
|
struct snd_dma_buffer *dmab)
|
||||||
{
|
{
|
||||||
|
gfp_t gfp;
|
||||||
|
|
||||||
if (WARN_ON(!size))
|
if (WARN_ON(!size))
|
||||||
return -ENXIO;
|
return -ENXIO;
|
||||||
if (WARN_ON(!dmab))
|
if (WARN_ON(!dmab))
|
||||||
|
@ -133,8 +137,13 @@ int snd_dma_alloc_pages(int type, struct device *device, size_t size,
|
||||||
dmab->bytes = 0;
|
dmab->bytes = 0;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SNDRV_DMA_TYPE_CONTINUOUS:
|
case SNDRV_DMA_TYPE_CONTINUOUS:
|
||||||
dmab->area = alloc_pages_exact(size,
|
gfp = snd_mem_get_gfp_flags(device, GFP_KERNEL);
|
||||||
snd_mem_get_gfp_flags(device));
|
dmab->area = alloc_pages_exact(size, gfp);
|
||||||
|
dmab->addr = 0;
|
||||||
|
break;
|
||||||
|
case SNDRV_DMA_TYPE_VMALLOC:
|
||||||
|
gfp = snd_mem_get_gfp_flags(device, GFP_KERNEL | __GFP_HIGHMEM);
|
||||||
|
dmab->area = __vmalloc(size, gfp, PAGE_KERNEL);
|
||||||
dmab->addr = 0;
|
dmab->addr = 0;
|
||||||
break;
|
break;
|
||||||
#ifdef CONFIG_HAS_DMA
|
#ifdef CONFIG_HAS_DMA
|
||||||
|
@ -220,6 +229,9 @@ void snd_dma_free_pages(struct snd_dma_buffer *dmab)
|
||||||
case SNDRV_DMA_TYPE_CONTINUOUS:
|
case SNDRV_DMA_TYPE_CONTINUOUS:
|
||||||
free_pages_exact(dmab->area, dmab->bytes);
|
free_pages_exact(dmab->area, dmab->bytes);
|
||||||
break;
|
break;
|
||||||
|
case SNDRV_DMA_TYPE_VMALLOC:
|
||||||
|
vfree(dmab->area);
|
||||||
|
break;
|
||||||
#ifdef CONFIG_HAS_DMA
|
#ifdef CONFIG_HAS_DMA
|
||||||
#ifdef CONFIG_GENERIC_ALLOCATOR
|
#ifdef CONFIG_GENERIC_ALLOCATOR
|
||||||
case SNDRV_DMA_TYPE_DEV_IRAM:
|
case SNDRV_DMA_TYPE_DEV_IRAM:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user