aboutsummaryrefslogtreecommitdiffstats
path: root/sound/core
diff options
context:
space:
mode:
authorNicolin Chen <b42378@freescale.com>2013-10-22 23:47:43 -0400
committerTakashi Iwai <tiwai@suse.de>2013-10-24 03:20:47 -0400
commit055032142c42d2821c4aa617915292d6a08d56fc (patch)
treece10032a40379b482eda19f8b04f8924a1625195 /sound/core
parent861e66d3418a90f57b31a50110fc70b23569c551 (diff)
ALSA: Add SoC on-chip internal ram support for DMA buffer allocation
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@freescale.com> Reviewed-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/core')
-rw-r--r--sound/core/memalloc.c52
-rw-r--r--sound/core/pcm_native.c6
2 files changed, 58 insertions, 0 deletions
diff --git a/sound/core/memalloc.c b/sound/core/memalloc.c
index bdf826f4fe0c..18c1d4759ccb 100644
--- a/sound/core/memalloc.c
+++ b/sound/core/memalloc.c
@@ -30,6 +30,7 @@
30#include <linux/seq_file.h> 30#include <linux/seq_file.h>
31#include <asm/uaccess.h> 31#include <asm/uaccess.h>
32#include <linux/dma-mapping.h> 32#include <linux/dma-mapping.h>
33#include <linux/genalloc.h>
33#include <linux/moduleparam.h> 34#include <linux/moduleparam.h>
34#include <linux/mutex.h> 35#include <linux/mutex.h>
35#include <sound/memalloc.h> 36#include <sound/memalloc.h>
@@ -157,6 +158,46 @@ static void snd_free_dev_pages(struct device *dev, size_t size, void *ptr,
157 dec_snd_pages(pg); 158 dec_snd_pages(pg);
158 dma_free_coherent(dev, PAGE_SIZE << pg, ptr, dma); 159 dma_free_coherent(dev, PAGE_SIZE << pg, ptr, dma);
159} 160}
161
162/**
163 * snd_malloc_dev_iram - allocate memory from on-chip internal ram
164 * @dmab: buffer allocation record to store the allocated data
165 * @size: number of bytes to allocate from the iram
166 *
167 * This function requires iram phandle provided via of_node
168 */
169void snd_malloc_dev_iram(struct snd_dma_buffer *dmab, size_t size)
170{
171 struct device *dev = dmab->dev.dev;
172 struct gen_pool *pool = NULL;
173
174 if (dev->of_node)
175 pool = of_get_named_gen_pool(dev->of_node, "iram", 0);
176
177 if (!pool)
178 return;
179
180 /* Assign the pool into private_data field */
181 dmab->private_data = pool;
182
183 dmab->area = (void *)gen_pool_alloc(pool, size);
184 if (!dmab->area)
185 return;
186
187 dmab->addr = gen_pool_virt_to_phys(pool, (unsigned long)dmab->area);
188}
189
190/**
191 * snd_free_dev_iram - free allocated specific memory from on-chip internal ram
192 * @dmab: buffer allocation record to store the allocated data
193 */
194void snd_free_dev_iram(struct snd_dma_buffer *dmab)
195{
196 struct gen_pool *pool = dmab->private_data;
197
198 if (pool && dmab->area)
199 gen_pool_free(pool, (unsigned long)dmab->area, dmab->bytes);
200}
160#endif /* CONFIG_HAS_DMA */ 201#endif /* CONFIG_HAS_DMA */
161 202
162/* 203/*
@@ -197,6 +238,14 @@ int snd_dma_alloc_pages(int type, struct device *device, size_t size,
197 dmab->addr = 0; 238 dmab->addr = 0;
198 break; 239 break;
199#ifdef CONFIG_HAS_DMA 240#ifdef CONFIG_HAS_DMA
241 case SNDRV_DMA_TYPE_DEV_IRAM:
242 snd_malloc_dev_iram(dmab, size);
243 if (dmab->area)
244 break;
245 /* Internal memory might have limited size and no enough space,
246 * so if we fail to malloc, try to fetch memory traditionally.
247 */
248 dmab->dev.type = SNDRV_DMA_TYPE_DEV;
200 case SNDRV_DMA_TYPE_DEV: 249 case SNDRV_DMA_TYPE_DEV:
201 dmab->area = snd_malloc_dev_pages(device, size, &dmab->addr); 250 dmab->area = snd_malloc_dev_pages(device, size, &dmab->addr);
202 break; 251 break;
@@ -269,6 +318,9 @@ void snd_dma_free_pages(struct snd_dma_buffer *dmab)
269 snd_free_pages(dmab->area, dmab->bytes); 318 snd_free_pages(dmab->area, dmab->bytes);
270 break; 319 break;
271#ifdef CONFIG_HAS_DMA 320#ifdef CONFIG_HAS_DMA
321 case SNDRV_DMA_TYPE_DEV_IRAM:
322 snd_free_dev_iram(dmab);
323 break;
272 case SNDRV_DMA_TYPE_DEV: 324 case SNDRV_DMA_TYPE_DEV:
273 snd_free_dev_pages(dmab->dev.dev, dmab->bytes, dmab->area, dmab->addr); 325 snd_free_dev_pages(dmab->dev.dev, dmab->bytes, dmab->area, dmab->addr);
274 break; 326 break;
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index a68d4c6d702c..513f0954d92e 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -3199,6 +3199,12 @@ int snd_pcm_lib_default_mmap(struct snd_pcm_substream *substream,
3199 struct vm_area_struct *area) 3199 struct vm_area_struct *area)
3200{ 3200{
3201 area->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP; 3201 area->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
3202 if (substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV_IRAM) {
3203 area->vm_page_prot = pgprot_writecombine(area->vm_page_prot);
3204 return remap_pfn_range(area, area->vm_start,
3205 substream->dma_buffer.addr >> PAGE_SHIFT,
3206 area->vm_end - area->vm_start, area->vm_page_prot);
3207 }
3202#ifdef ARCH_HAS_DMA_MMAP_COHERENT 3208#ifdef ARCH_HAS_DMA_MMAP_COHERENT
3203 if (!substream->ops->page && 3209 if (!substream->ops->page &&
3204 substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV) 3210 substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV)