[alsa-devel] [PATCH v7] ALSA: Add SoC on-chip internal ram support for DMA buffer allocation

Takashi Iwai tiwai at suse.de
Thu Oct 24 14:38:40 CEST 2013


At Thu, 24 Oct 2013 09:22:49 +0200,
Takashi Iwai wrote:
> 
> At Wed, 23 Oct 2013 11:47:43 +0800,
> Nicolin Chen wrote:
> > 
> > Now it's quite common that an SoC contains its on-chip internal RAM.
> > By using this RAM space for DMA buffer during audio playback/record,
> > we can shutdown the voltage for external RAM to save power.
> > 
> > So add new DEV type with iram malloc()/free() and accordingly modify
> > current default mmap() for the iram circumstance.
> > 
> > Signed-off-by: Nicolin Chen <b42378 at freescale.com>
> 
> Thanks, now applied with ack by Lars.

Unfortunately it resulted in the missing symbols on x86, so I ended up
adding ifdefs as below.


Takashi

---
From: Takashi Iwai <tiwai at suse.de>
Subject: [PATCH] ALSA: Add ifdef CONFIG_GENERIC_ALLOCATOR for SNDRV_DMA_TYPE_IRAM code

It turned out that we can't use gen_pool_*() functions on archs
without CONFIG_GENERIC_ALLOCATOR (resulting in missing symbols), since
linux/genalloc.h doesn't provide dummy functions for all.  We'd be
able to fix linux/genalloc.h size, but I take an easier path for
now...

Reported-by: Fengguang Wu <fengguang.wu at intel.com>
Signed-off-by: Takashi Iwai <tiwai at suse.de>
---
 include/sound/memalloc.h | 4 ++++
 sound/core/memalloc.c    | 4 ++++
 sound/core/pcm_native.c  | 2 ++
 3 files changed, 10 insertions(+)

diff --git a/include/sound/memalloc.h b/include/sound/memalloc.h
index 510aec4..af99839 100644
--- a/include/sound/memalloc.h
+++ b/include/sound/memalloc.h
@@ -52,7 +52,11 @@ struct snd_dma_device {
 #else
 #define SNDRV_DMA_TYPE_DEV_SG	SNDRV_DMA_TYPE_DEV /* no SG-buf support */
 #endif
+#ifdef CONFIG_GENERIC_ALLOCATOR
 #define SNDRV_DMA_TYPE_DEV_IRAM		4	/* generic device iram-buffer */
+#else
+#define SNDRV_DMA_TYPE_DEV_IRAM	SNDRV_DMA_TYPE_DEV
+#endif
 
 /*
  * info for buffer allocation
diff --git a/sound/core/memalloc.c b/sound/core/memalloc.c
index 18c1d47..51a7921 100644
--- a/sound/core/memalloc.c
+++ b/sound/core/memalloc.c
@@ -238,6 +238,7 @@ int snd_dma_alloc_pages(int type, struct device *device, size_t size,
 		dmab->addr = 0;
 		break;
 #ifdef CONFIG_HAS_DMA
+#ifdef CONFIG_GENERIC_ALLOCATOR
 	case SNDRV_DMA_TYPE_DEV_IRAM:
 		snd_malloc_dev_iram(dmab, size);
 		if (dmab->area)
@@ -246,6 +247,7 @@ int snd_dma_alloc_pages(int type, struct device *device, size_t size,
 		 * so if we fail to malloc, try to fetch memory traditionally.
 		 */
 		dmab->dev.type = SNDRV_DMA_TYPE_DEV;
+#endif /* CONFIG_GENERIC_ALLOCATOR */
 	case SNDRV_DMA_TYPE_DEV:
 		dmab->area = snd_malloc_dev_pages(device, size, &dmab->addr);
 		break;
@@ -318,9 +320,11 @@ void snd_dma_free_pages(struct snd_dma_buffer *dmab)
 		snd_free_pages(dmab->area, dmab->bytes);
 		break;
 #ifdef CONFIG_HAS_DMA
+#ifdef CONFIG_GENERIC_ALLOCATOR
 	case SNDRV_DMA_TYPE_DEV_IRAM:
 		snd_free_dev_iram(dmab);
 		break;
+#endif /* CONFIG_GENERIC_ALLOCATOR */
 	case SNDRV_DMA_TYPE_DEV:
 		snd_free_dev_pages(dmab->dev.dev, dmab->bytes, dmab->area, dmab->addr);
 		break;
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 513f095..b71be57 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -3199,12 +3199,14 @@ int snd_pcm_lib_default_mmap(struct snd_pcm_substream *substream,
 			     struct vm_area_struct *area)
 {
 	area->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
+#ifdef CONFIG_GENERIC_ALLOCATOR
 	if (substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV_IRAM) {
 		area->vm_page_prot = pgprot_writecombine(area->vm_page_prot);
 		return remap_pfn_range(area, area->vm_start,
 				substream->dma_buffer.addr >> PAGE_SHIFT,
 				area->vm_end - area->vm_start, area->vm_page_prot);
 	}
+#endif /* CONFIG_GENERIC_ALLOCATOR */
 #ifdef ARCH_HAS_DMA_MMAP_COHERENT
 	if (!substream->ops->page &&
 	    substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV)
-- 
1.8.4



More information about the Alsa-devel mailing list