alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v7] ALSA: Add SoC on-chip internal ram support for DMA buffer allocation
@ 2013-10-23  3:47 Nicolin Chen
  2013-10-23 15:02 ` Lars-Peter Clausen
  2013-10-24  7:22 ` Takashi Iwai
  0 siblings, 2 replies; 7+ messages in thread
From: Nicolin Chen @ 2013-10-23  3:47 UTC (permalink / raw)
  To: lars, broonie, lgirdwood, tiwai, perex; +Cc: alsa-devel

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>
---
Changelog
v6->v7:
 * Assigned pool to private_data field and accordingly refined helper functions.
v5->v6:
 * Dropped remaining OF dependency bacause no need to add them:
   of_node doesn't care about OF; of_get_named_gen_pool() returns NULL if !OF.
v4->v5:
 * Minimized the OF dependency.
v3->v4:
 * Appropriately placed '#ifdef CONFIG_OF'
 * Tested by adding '#undef CONFIG_OF' to modified files, and passed compiling.
v2->v3:
 * Moved iram specific mmap procedure out of ifdef ARCH_HAS_DMA_MMAP_COHERENT
v1->v2:
 * Added of_node check
 * Dropped noops and unused physical addr in snd_free_dev_iram()

---
 include/sound/memalloc.h |  1 +
 sound/core/memalloc.c    | 52 ++++++++++++++++++++++++++++++++++++++++++++++++
 sound/core/pcm_native.c  |  6 ++++++
 3 files changed, 59 insertions(+)

diff --git a/include/sound/memalloc.h b/include/sound/memalloc.h
index cf15b82..510aec4 100644
--- a/include/sound/memalloc.h
+++ b/include/sound/memalloc.h
@@ -52,6 +52,7 @@ struct snd_dma_device {
 #else
 #define SNDRV_DMA_TYPE_DEV_SG	SNDRV_DMA_TYPE_DEV /* no SG-buf support */
 #endif
+#define SNDRV_DMA_TYPE_DEV_IRAM		4	/* generic device iram-buffer */
 
 /*
  * info for buffer allocation
diff --git a/sound/core/memalloc.c b/sound/core/memalloc.c
index bdf826f..18c1d47 100644
--- a/sound/core/memalloc.c
+++ b/sound/core/memalloc.c
@@ -30,6 +30,7 @@
 #include <linux/seq_file.h>
 #include <asm/uaccess.h>
 #include <linux/dma-mapping.h>
+#include <linux/genalloc.h>
 #include <linux/moduleparam.h>
 #include <linux/mutex.h>
 #include <sound/memalloc.h>
@@ -157,6 +158,46 @@ static void snd_free_dev_pages(struct device *dev, size_t size, void *ptr,
 	dec_snd_pages(pg);
 	dma_free_coherent(dev, PAGE_SIZE << pg, ptr, dma);
 }
+
+/**
+ * snd_malloc_dev_iram - allocate memory from on-chip internal ram
+ * @dmab: buffer allocation record to store the allocated data
+ * @size: number of bytes to allocate from the iram
+ *
+ * This function requires iram phandle provided via of_node
+ */
+void snd_malloc_dev_iram(struct snd_dma_buffer *dmab, size_t size)
+{
+	struct device *dev = dmab->dev.dev;
+	struct gen_pool *pool = NULL;
+
+	if (dev->of_node)
+		pool = of_get_named_gen_pool(dev->of_node, "iram", 0);
+
+	if (!pool)
+		return;
+
+	/* Assign the pool into private_data field */
+	dmab->private_data = pool;
+
+	dmab->area = (void *)gen_pool_alloc(pool, size);
+	if (!dmab->area)
+		return;
+
+	dmab->addr = gen_pool_virt_to_phys(pool, (unsigned long)dmab->area);
+}
+
+/**
+ * snd_free_dev_iram - free allocated specific memory from on-chip internal ram
+ * @dmab: buffer allocation record to store the allocated data
+ */
+void snd_free_dev_iram(struct snd_dma_buffer *dmab)
+{
+	struct gen_pool *pool = dmab->private_data;
+
+	if (pool && dmab->area)
+		gen_pool_free(pool, (unsigned long)dmab->area, dmab->bytes);
+}
 #endif /* CONFIG_HAS_DMA */
 
 /*
@@ -197,6 +238,14 @@ int snd_dma_alloc_pages(int type, struct device *device, size_t size,
 		dmab->addr = 0;
 		break;
 #ifdef CONFIG_HAS_DMA
+	case SNDRV_DMA_TYPE_DEV_IRAM:
+		snd_malloc_dev_iram(dmab, size);
+		if (dmab->area)
+			break;
+		/* Internal memory might have limited size and no enough space,
+		 * so if we fail to malloc, try to fetch memory traditionally.
+		 */
+		dmab->dev.type = SNDRV_DMA_TYPE_DEV;
 	case SNDRV_DMA_TYPE_DEV:
 		dmab->area = snd_malloc_dev_pages(device, size, &dmab->addr);
 		break;
@@ -269,6 +318,9 @@ void snd_dma_free_pages(struct snd_dma_buffer *dmab)
 		snd_free_pages(dmab->area, dmab->bytes);
 		break;
 #ifdef CONFIG_HAS_DMA
+	case SNDRV_DMA_TYPE_DEV_IRAM:
+		snd_free_dev_iram(dmab);
+		break;
 	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 a68d4c6..513f095 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,
 			     struct vm_area_struct *area)
 {
 	area->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
+	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);
+	}
 #ifdef ARCH_HAS_DMA_MMAP_COHERENT
 	if (!substream->ops->page &&
 	    substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV)
-- 
1.8.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v7] ALSA: Add SoC on-chip internal ram support for DMA buffer allocation
  2013-10-23  3:47 [PATCH v7] ALSA: Add SoC on-chip internal ram support for DMA buffer allocation Nicolin Chen
@ 2013-10-23 15:02 ` Lars-Peter Clausen
  2013-10-24  7:22 ` Takashi Iwai
  1 sibling, 0 replies; 7+ messages in thread
From: Lars-Peter Clausen @ 2013-10-23 15:02 UTC (permalink / raw)
  To: Nicolin Chen; +Cc: tiwai, alsa-devel, broonie, lgirdwood

On 10/23/2013 05:47 AM, 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@freescale.com>

Looks good to me.

Reviewed-by: Lars-Peter Clausen <lars@metafoo.de>

> ---
> Changelog
> v6->v7:
>  * Assigned pool to private_data field and accordingly refined helper functions.
> v5->v6:
>  * Dropped remaining OF dependency bacause no need to add them:
>    of_node doesn't care about OF; of_get_named_gen_pool() returns NULL if !OF.
> v4->v5:
>  * Minimized the OF dependency.
> v3->v4:
>  * Appropriately placed '#ifdef CONFIG_OF'
>  * Tested by adding '#undef CONFIG_OF' to modified files, and passed compiling.
> v2->v3:
>  * Moved iram specific mmap procedure out of ifdef ARCH_HAS_DMA_MMAP_COHERENT
> v1->v2:
>  * Added of_node check
>  * Dropped noops and unused physical addr in snd_free_dev_iram()
> 
> ---
>  include/sound/memalloc.h |  1 +
>  sound/core/memalloc.c    | 52 ++++++++++++++++++++++++++++++++++++++++++++++++
>  sound/core/pcm_native.c  |  6 ++++++
>  3 files changed, 59 insertions(+)
> 
> diff --git a/include/sound/memalloc.h b/include/sound/memalloc.h
> index cf15b82..510aec4 100644
> --- a/include/sound/memalloc.h
> +++ b/include/sound/memalloc.h
> @@ -52,6 +52,7 @@ struct snd_dma_device {
>  #else
>  #define SNDRV_DMA_TYPE_DEV_SG	SNDRV_DMA_TYPE_DEV /* no SG-buf support */
>  #endif
> +#define SNDRV_DMA_TYPE_DEV_IRAM		4	/* generic device iram-buffer */
>  
>  /*
>   * info for buffer allocation
> diff --git a/sound/core/memalloc.c b/sound/core/memalloc.c
> index bdf826f..18c1d47 100644
> --- a/sound/core/memalloc.c
> +++ b/sound/core/memalloc.c
> @@ -30,6 +30,7 @@
>  #include <linux/seq_file.h>
>  #include <asm/uaccess.h>
>  #include <linux/dma-mapping.h>
> +#include <linux/genalloc.h>
>  #include <linux/moduleparam.h>
>  #include <linux/mutex.h>
>  #include <sound/memalloc.h>
> @@ -157,6 +158,46 @@ static void snd_free_dev_pages(struct device *dev, size_t size, void *ptr,
>  	dec_snd_pages(pg);
>  	dma_free_coherent(dev, PAGE_SIZE << pg, ptr, dma);
>  }
> +
> +/**
> + * snd_malloc_dev_iram - allocate memory from on-chip internal ram
> + * @dmab: buffer allocation record to store the allocated data
> + * @size: number of bytes to allocate from the iram
> + *
> + * This function requires iram phandle provided via of_node
> + */
> +void snd_malloc_dev_iram(struct snd_dma_buffer *dmab, size_t size)
> +{
> +	struct device *dev = dmab->dev.dev;
> +	struct gen_pool *pool = NULL;
> +
> +	if (dev->of_node)
> +		pool = of_get_named_gen_pool(dev->of_node, "iram", 0);
> +
> +	if (!pool)
> +		return;
> +
> +	/* Assign the pool into private_data field */
> +	dmab->private_data = pool;
> +
> +	dmab->area = (void *)gen_pool_alloc(pool, size);
> +	if (!dmab->area)
> +		return;
> +
> +	dmab->addr = gen_pool_virt_to_phys(pool, (unsigned long)dmab->area);
> +}
> +
> +/**
> + * snd_free_dev_iram - free allocated specific memory from on-chip internal ram
> + * @dmab: buffer allocation record to store the allocated data
> + */
> +void snd_free_dev_iram(struct snd_dma_buffer *dmab)
> +{
> +	struct gen_pool *pool = dmab->private_data;
> +
> +	if (pool && dmab->area)
> +		gen_pool_free(pool, (unsigned long)dmab->area, dmab->bytes);
> +}
>  #endif /* CONFIG_HAS_DMA */
>  
>  /*
> @@ -197,6 +238,14 @@ int snd_dma_alloc_pages(int type, struct device *device, size_t size,
>  		dmab->addr = 0;
>  		break;
>  #ifdef CONFIG_HAS_DMA
> +	case SNDRV_DMA_TYPE_DEV_IRAM:
> +		snd_malloc_dev_iram(dmab, size);
> +		if (dmab->area)
> +			break;
> +		/* Internal memory might have limited size and no enough space,
> +		 * so if we fail to malloc, try to fetch memory traditionally.
> +		 */
> +		dmab->dev.type = SNDRV_DMA_TYPE_DEV;
>  	case SNDRV_DMA_TYPE_DEV:
>  		dmab->area = snd_malloc_dev_pages(device, size, &dmab->addr);
>  		break;
> @@ -269,6 +318,9 @@ void snd_dma_free_pages(struct snd_dma_buffer *dmab)
>  		snd_free_pages(dmab->area, dmab->bytes);
>  		break;
>  #ifdef CONFIG_HAS_DMA
> +	case SNDRV_DMA_TYPE_DEV_IRAM:
> +		snd_free_dev_iram(dmab);
> +		break;
>  	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 a68d4c6..513f095 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,
>  			     struct vm_area_struct *area)
>  {
>  	area->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
> +	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);
> +	}
>  #ifdef ARCH_HAS_DMA_MMAP_COHERENT
>  	if (!substream->ops->page &&
>  	    substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV)
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v7] ALSA: Add SoC on-chip internal ram support for DMA buffer allocation
  2013-10-23  3:47 [PATCH v7] ALSA: Add SoC on-chip internal ram support for DMA buffer allocation Nicolin Chen
  2013-10-23 15:02 ` Lars-Peter Clausen
@ 2013-10-24  7:22 ` Takashi Iwai
  2013-10-24  8:05   ` Nicolin Chen
  2013-10-24 12:38   ` Takashi Iwai
  1 sibling, 2 replies; 7+ messages in thread
From: Takashi Iwai @ 2013-10-24  7:22 UTC (permalink / raw)
  To: Nicolin Chen; +Cc: broonie, lars, lgirdwood, alsa-devel

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@freescale.com>

Thanks, now applied with ack by Lars.


Takashi

> ---
> Changelog
> v6->v7:
>  * Assigned pool to private_data field and accordingly refined helper functions.
> v5->v6:
>  * Dropped remaining OF dependency bacause no need to add them:
>    of_node doesn't care about OF; of_get_named_gen_pool() returns NULL if !OF.
> v4->v5:
>  * Minimized the OF dependency.
> v3->v4:
>  * Appropriately placed '#ifdef CONFIG_OF'
>  * Tested by adding '#undef CONFIG_OF' to modified files, and passed compiling.
> v2->v3:
>  * Moved iram specific mmap procedure out of ifdef ARCH_HAS_DMA_MMAP_COHERENT
> v1->v2:
>  * Added of_node check
>  * Dropped noops and unused physical addr in snd_free_dev_iram()
> 
> ---
>  include/sound/memalloc.h |  1 +
>  sound/core/memalloc.c    | 52 ++++++++++++++++++++++++++++++++++++++++++++++++
>  sound/core/pcm_native.c  |  6 ++++++
>  3 files changed, 59 insertions(+)
> 
> diff --git a/include/sound/memalloc.h b/include/sound/memalloc.h
> index cf15b82..510aec4 100644
> --- a/include/sound/memalloc.h
> +++ b/include/sound/memalloc.h
> @@ -52,6 +52,7 @@ struct snd_dma_device {
>  #else
>  #define SNDRV_DMA_TYPE_DEV_SG	SNDRV_DMA_TYPE_DEV /* no SG-buf support */
>  #endif
> +#define SNDRV_DMA_TYPE_DEV_IRAM		4	/* generic device iram-buffer */
>  
>  /*
>   * info for buffer allocation
> diff --git a/sound/core/memalloc.c b/sound/core/memalloc.c
> index bdf826f..18c1d47 100644
> --- a/sound/core/memalloc.c
> +++ b/sound/core/memalloc.c
> @@ -30,6 +30,7 @@
>  #include <linux/seq_file.h>
>  #include <asm/uaccess.h>
>  #include <linux/dma-mapping.h>
> +#include <linux/genalloc.h>
>  #include <linux/moduleparam.h>
>  #include <linux/mutex.h>
>  #include <sound/memalloc.h>
> @@ -157,6 +158,46 @@ static void snd_free_dev_pages(struct device *dev, size_t size, void *ptr,
>  	dec_snd_pages(pg);
>  	dma_free_coherent(dev, PAGE_SIZE << pg, ptr, dma);
>  }
> +
> +/**
> + * snd_malloc_dev_iram - allocate memory from on-chip internal ram
> + * @dmab: buffer allocation record to store the allocated data
> + * @size: number of bytes to allocate from the iram
> + *
> + * This function requires iram phandle provided via of_node
> + */
> +void snd_malloc_dev_iram(struct snd_dma_buffer *dmab, size_t size)
> +{
> +	struct device *dev = dmab->dev.dev;
> +	struct gen_pool *pool = NULL;
> +
> +	if (dev->of_node)
> +		pool = of_get_named_gen_pool(dev->of_node, "iram", 0);
> +
> +	if (!pool)
> +		return;
> +
> +	/* Assign the pool into private_data field */
> +	dmab->private_data = pool;
> +
> +	dmab->area = (void *)gen_pool_alloc(pool, size);
> +	if (!dmab->area)
> +		return;
> +
> +	dmab->addr = gen_pool_virt_to_phys(pool, (unsigned long)dmab->area);
> +}
> +
> +/**
> + * snd_free_dev_iram - free allocated specific memory from on-chip internal ram
> + * @dmab: buffer allocation record to store the allocated data
> + */
> +void snd_free_dev_iram(struct snd_dma_buffer *dmab)
> +{
> +	struct gen_pool *pool = dmab->private_data;
> +
> +	if (pool && dmab->area)
> +		gen_pool_free(pool, (unsigned long)dmab->area, dmab->bytes);
> +}
>  #endif /* CONFIG_HAS_DMA */
>  
>  /*
> @@ -197,6 +238,14 @@ int snd_dma_alloc_pages(int type, struct device *device, size_t size,
>  		dmab->addr = 0;
>  		break;
>  #ifdef CONFIG_HAS_DMA
> +	case SNDRV_DMA_TYPE_DEV_IRAM:
> +		snd_malloc_dev_iram(dmab, size);
> +		if (dmab->area)
> +			break;
> +		/* Internal memory might have limited size and no enough space,
> +		 * so if we fail to malloc, try to fetch memory traditionally.
> +		 */
> +		dmab->dev.type = SNDRV_DMA_TYPE_DEV;
>  	case SNDRV_DMA_TYPE_DEV:
>  		dmab->area = snd_malloc_dev_pages(device, size, &dmab->addr);
>  		break;
> @@ -269,6 +318,9 @@ void snd_dma_free_pages(struct snd_dma_buffer *dmab)
>  		snd_free_pages(dmab->area, dmab->bytes);
>  		break;
>  #ifdef CONFIG_HAS_DMA
> +	case SNDRV_DMA_TYPE_DEV_IRAM:
> +		snd_free_dev_iram(dmab);
> +		break;
>  	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 a68d4c6..513f095 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,
>  			     struct vm_area_struct *area)
>  {
>  	area->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
> +	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);
> +	}
>  #ifdef ARCH_HAS_DMA_MMAP_COHERENT
>  	if (!substream->ops->page &&
>  	    substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV)
> -- 
> 1.8.4
> 
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v7] ALSA: Add SoC on-chip internal ram support for DMA buffer allocation
  2013-10-24  7:22 ` Takashi Iwai
@ 2013-10-24  8:05   ` Nicolin Chen
  2013-10-24  9:15     ` Takashi Iwai
  2013-10-24 12:38   ` Takashi Iwai
  1 sibling, 1 reply; 7+ messages in thread
From: Nicolin Chen @ 2013-10-24  8:05 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: broonie, lars, lgirdwood, alsa-devel

On Thu, Oct 24, 2013 at 09:22:49AM +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@freescale.com>
> 
> Thanks, now applied with ack by Lars.
> 
> 
> Takashi

Thank you. And Iwai-san, could you please tell me in which repo and branch
could I cherry-pick this patch?

I tried some in git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git
but failed to locate the patch.

Thank you,
Nicolin Chen

> 
> > ---
> > Changelog
> > v6->v7:
> >  * Assigned pool to private_data field and accordingly refined helper functions.
> > v5->v6:
> >  * Dropped remaining OF dependency bacause no need to add them:
> >    of_node doesn't care about OF; of_get_named_gen_pool() returns NULL if !OF.
> > v4->v5:
> >  * Minimized the OF dependency.
> > v3->v4:
> >  * Appropriately placed '#ifdef CONFIG_OF'
> >  * Tested by adding '#undef CONFIG_OF' to modified files, and passed compiling.
> > v2->v3:
> >  * Moved iram specific mmap procedure out of ifdef ARCH_HAS_DMA_MMAP_COHERENT
> > v1->v2:
> >  * Added of_node check
> >  * Dropped noops and unused physical addr in snd_free_dev_iram()
> > 
> > ---
> >  include/sound/memalloc.h |  1 +
> >  sound/core/memalloc.c    | 52 ++++++++++++++++++++++++++++++++++++++++++++++++
> >  sound/core/pcm_native.c  |  6 ++++++
> >  3 files changed, 59 insertions(+)
> > 
> > diff --git a/include/sound/memalloc.h b/include/sound/memalloc.h
> > index cf15b82..510aec4 100644
> > --- a/include/sound/memalloc.h
> > +++ b/include/sound/memalloc.h
> > @@ -52,6 +52,7 @@ struct snd_dma_device {
> >  #else
> >  #define SNDRV_DMA_TYPE_DEV_SG	SNDRV_DMA_TYPE_DEV /* no SG-buf support */
> >  #endif
> > +#define SNDRV_DMA_TYPE_DEV_IRAM		4	/* generic device iram-buffer */
> >  
> >  /*
> >   * info for buffer allocation
> > diff --git a/sound/core/memalloc.c b/sound/core/memalloc.c
> > index bdf826f..18c1d47 100644
> > --- a/sound/core/memalloc.c
> > +++ b/sound/core/memalloc.c
> > @@ -30,6 +30,7 @@
> >  #include <linux/seq_file.h>
> >  #include <asm/uaccess.h>
> >  #include <linux/dma-mapping.h>
> > +#include <linux/genalloc.h>
> >  #include <linux/moduleparam.h>
> >  #include <linux/mutex.h>
> >  #include <sound/memalloc.h>
> > @@ -157,6 +158,46 @@ static void snd_free_dev_pages(struct device *dev, size_t size, void *ptr,
> >  	dec_snd_pages(pg);
> >  	dma_free_coherent(dev, PAGE_SIZE << pg, ptr, dma);
> >  }
> > +
> > +/**
> > + * snd_malloc_dev_iram - allocate memory from on-chip internal ram
> > + * @dmab: buffer allocation record to store the allocated data
> > + * @size: number of bytes to allocate from the iram
> > + *
> > + * This function requires iram phandle provided via of_node
> > + */
> > +void snd_malloc_dev_iram(struct snd_dma_buffer *dmab, size_t size)
> > +{
> > +	struct device *dev = dmab->dev.dev;
> > +	struct gen_pool *pool = NULL;
> > +
> > +	if (dev->of_node)
> > +		pool = of_get_named_gen_pool(dev->of_node, "iram", 0);
> > +
> > +	if (!pool)
> > +		return;
> > +
> > +	/* Assign the pool into private_data field */
> > +	dmab->private_data = pool;
> > +
> > +	dmab->area = (void *)gen_pool_alloc(pool, size);
> > +	if (!dmab->area)
> > +		return;
> > +
> > +	dmab->addr = gen_pool_virt_to_phys(pool, (unsigned long)dmab->area);
> > +}
> > +
> > +/**
> > + * snd_free_dev_iram - free allocated specific memory from on-chip internal ram
> > + * @dmab: buffer allocation record to store the allocated data
> > + */
> > +void snd_free_dev_iram(struct snd_dma_buffer *dmab)
> > +{
> > +	struct gen_pool *pool = dmab->private_data;
> > +
> > +	if (pool && dmab->area)
> > +		gen_pool_free(pool, (unsigned long)dmab->area, dmab->bytes);
> > +}
> >  #endif /* CONFIG_HAS_DMA */
> >  
> >  /*
> > @@ -197,6 +238,14 @@ int snd_dma_alloc_pages(int type, struct device *device, size_t size,
> >  		dmab->addr = 0;
> >  		break;
> >  #ifdef CONFIG_HAS_DMA
> > +	case SNDRV_DMA_TYPE_DEV_IRAM:
> > +		snd_malloc_dev_iram(dmab, size);
> > +		if (dmab->area)
> > +			break;
> > +		/* Internal memory might have limited size and no enough space,
> > +		 * so if we fail to malloc, try to fetch memory traditionally.
> > +		 */
> > +		dmab->dev.type = SNDRV_DMA_TYPE_DEV;
> >  	case SNDRV_DMA_TYPE_DEV:
> >  		dmab->area = snd_malloc_dev_pages(device, size, &dmab->addr);
> >  		break;
> > @@ -269,6 +318,9 @@ void snd_dma_free_pages(struct snd_dma_buffer *dmab)
> >  		snd_free_pages(dmab->area, dmab->bytes);
> >  		break;
> >  #ifdef CONFIG_HAS_DMA
> > +	case SNDRV_DMA_TYPE_DEV_IRAM:
> > +		snd_free_dev_iram(dmab);
> > +		break;
> >  	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 a68d4c6..513f095 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,
> >  			     struct vm_area_struct *area)
> >  {
> >  	area->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
> > +	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);
> > +	}
> >  #ifdef ARCH_HAS_DMA_MMAP_COHERENT
> >  	if (!substream->ops->page &&
> >  	    substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV)
> > -- 
> > 1.8.4
> > 
> > 
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v7] ALSA: Add SoC on-chip internal ram support for DMA buffer allocation
  2013-10-24  9:15     ` Takashi Iwai
@ 2013-10-24  8:54       ` Nicolin Chen
  0 siblings, 0 replies; 7+ messages in thread
From: Nicolin Chen @ 2013-10-24  8:54 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: broonie, lars, lgirdwood, alsa-devel

On Thu, Oct 24, 2013 at 11:15:50AM +0200, Takashi Iwai wrote:
> At Thu, 24 Oct 2013 16:05:34 +0800,
> Nicolin Chen wrote:
> > 
> > On Thu, Oct 24, 2013 at 09:22:49AM +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@freescale.com>
> > > 
> > > Thanks, now applied with ack by Lars.
> > > 
> > > 
> > > Takashi
> > 
> > Thank you. And Iwai-san, could you please tell me in which repo and branch
> > could I cherry-pick this patch?
> > 
> > I tried some in git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git
> > but failed to locate the patch.
> 
> It's in for-next branch, and now pushed out.
> (It didn't go out in this morning since the network connection in the
>  hotel wasn't good, and it broke during I worked on it...)

I got it.

Thank you(Arigatougozaimashita)
Nicolin Chen

> 
> 
> Takashi
> 
> > 
> > Thank you,
> > Nicolin Chen
> > 
> > > 
> > > > ---
> > > > Changelog
> > > > v6->v7:
> > > >  * Assigned pool to private_data field and accordingly refined helper functions.
> > > > v5->v6:
> > > >  * Dropped remaining OF dependency bacause no need to add them:
> > > >    of_node doesn't care about OF; of_get_named_gen_pool() returns NULL if !OF.
> > > > v4->v5:
> > > >  * Minimized the OF dependency.
> > > > v3->v4:
> > > >  * Appropriately placed '#ifdef CONFIG_OF'
> > > >  * Tested by adding '#undef CONFIG_OF' to modified files, and passed compiling.
> > > > v2->v3:
> > > >  * Moved iram specific mmap procedure out of ifdef ARCH_HAS_DMA_MMAP_COHERENT
> > > > v1->v2:
> > > >  * Added of_node check
> > > >  * Dropped noops and unused physical addr in snd_free_dev_iram()
> > > > 
> > > > ---
> > > >  include/sound/memalloc.h |  1 +
> > > >  sound/core/memalloc.c    | 52 ++++++++++++++++++++++++++++++++++++++++++++++++
> > > >  sound/core/pcm_native.c  |  6 ++++++
> > > >  3 files changed, 59 insertions(+)
> > > > 
> > > > diff --git a/include/sound/memalloc.h b/include/sound/memalloc.h
> > > > index cf15b82..510aec4 100644
> > > > --- a/include/sound/memalloc.h
> > > > +++ b/include/sound/memalloc.h
> > > > @@ -52,6 +52,7 @@ struct snd_dma_device {
> > > >  #else
> > > >  #define SNDRV_DMA_TYPE_DEV_SG	SNDRV_DMA_TYPE_DEV /* no SG-buf support */
> > > >  #endif
> > > > +#define SNDRV_DMA_TYPE_DEV_IRAM		4	/* generic device iram-buffer */
> > > >  
> > > >  /*
> > > >   * info for buffer allocation
> > > > diff --git a/sound/core/memalloc.c b/sound/core/memalloc.c
> > > > index bdf826f..18c1d47 100644
> > > > --- a/sound/core/memalloc.c
> > > > +++ b/sound/core/memalloc.c
> > > > @@ -30,6 +30,7 @@
> > > >  #include <linux/seq_file.h>
> > > >  #include <asm/uaccess.h>
> > > >  #include <linux/dma-mapping.h>
> > > > +#include <linux/genalloc.h>
> > > >  #include <linux/moduleparam.h>
> > > >  #include <linux/mutex.h>
> > > >  #include <sound/memalloc.h>
> > > > @@ -157,6 +158,46 @@ static void snd_free_dev_pages(struct device *dev, size_t size, void *ptr,
> > > >  	dec_snd_pages(pg);
> > > >  	dma_free_coherent(dev, PAGE_SIZE << pg, ptr, dma);
> > > >  }
> > > > +
> > > > +/**
> > > > + * snd_malloc_dev_iram - allocate memory from on-chip internal ram
> > > > + * @dmab: buffer allocation record to store the allocated data
> > > > + * @size: number of bytes to allocate from the iram
> > > > + *
> > > > + * This function requires iram phandle provided via of_node
> > > > + */
> > > > +void snd_malloc_dev_iram(struct snd_dma_buffer *dmab, size_t size)
> > > > +{
> > > > +	struct device *dev = dmab->dev.dev;
> > > > +	struct gen_pool *pool = NULL;
> > > > +
> > > > +	if (dev->of_node)
> > > > +		pool = of_get_named_gen_pool(dev->of_node, "iram", 0);
> > > > +
> > > > +	if (!pool)
> > > > +		return;
> > > > +
> > > > +	/* Assign the pool into private_data field */
> > > > +	dmab->private_data = pool;
> > > > +
> > > > +	dmab->area = (void *)gen_pool_alloc(pool, size);
> > > > +	if (!dmab->area)
> > > > +		return;
> > > > +
> > > > +	dmab->addr = gen_pool_virt_to_phys(pool, (unsigned long)dmab->area);
> > > > +}
> > > > +
> > > > +/**
> > > > + * snd_free_dev_iram - free allocated specific memory from on-chip internal ram
> > > > + * @dmab: buffer allocation record to store the allocated data
> > > > + */
> > > > +void snd_free_dev_iram(struct snd_dma_buffer *dmab)
> > > > +{
> > > > +	struct gen_pool *pool = dmab->private_data;
> > > > +
> > > > +	if (pool && dmab->area)
> > > > +		gen_pool_free(pool, (unsigned long)dmab->area, dmab->bytes);
> > > > +}
> > > >  #endif /* CONFIG_HAS_DMA */
> > > >  
> > > >  /*
> > > > @@ -197,6 +238,14 @@ int snd_dma_alloc_pages(int type, struct device *device, size_t size,
> > > >  		dmab->addr = 0;
> > > >  		break;
> > > >  #ifdef CONFIG_HAS_DMA
> > > > +	case SNDRV_DMA_TYPE_DEV_IRAM:
> > > > +		snd_malloc_dev_iram(dmab, size);
> > > > +		if (dmab->area)
> > > > +			break;
> > > > +		/* Internal memory might have limited size and no enough space,
> > > > +		 * so if we fail to malloc, try to fetch memory traditionally.
> > > > +		 */
> > > > +		dmab->dev.type = SNDRV_DMA_TYPE_DEV;
> > > >  	case SNDRV_DMA_TYPE_DEV:
> > > >  		dmab->area = snd_malloc_dev_pages(device, size, &dmab->addr);
> > > >  		break;
> > > > @@ -269,6 +318,9 @@ void snd_dma_free_pages(struct snd_dma_buffer *dmab)
> > > >  		snd_free_pages(dmab->area, dmab->bytes);
> > > >  		break;
> > > >  #ifdef CONFIG_HAS_DMA
> > > > +	case SNDRV_DMA_TYPE_DEV_IRAM:
> > > > +		snd_free_dev_iram(dmab);
> > > > +		break;
> > > >  	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 a68d4c6..513f095 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,
> > > >  			     struct vm_area_struct *area)
> > > >  {
> > > >  	area->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
> > > > +	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);
> > > > +	}
> > > >  #ifdef ARCH_HAS_DMA_MMAP_COHERENT
> > > >  	if (!substream->ops->page &&
> > > >  	    substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV)
> > > > -- 
> > > > 1.8.4
> > > > 
> > > > 
> > > 
> > 
> > 
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v7] ALSA: Add SoC on-chip internal ram support for DMA buffer allocation
  2013-10-24  8:05   ` Nicolin Chen
@ 2013-10-24  9:15     ` Takashi Iwai
  2013-10-24  8:54       ` Nicolin Chen
  0 siblings, 1 reply; 7+ messages in thread
From: Takashi Iwai @ 2013-10-24  9:15 UTC (permalink / raw)
  To: Nicolin Chen; +Cc: broonie, lars, lgirdwood, alsa-devel

At Thu, 24 Oct 2013 16:05:34 +0800,
Nicolin Chen wrote:
> 
> On Thu, Oct 24, 2013 at 09:22:49AM +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@freescale.com>
> > 
> > Thanks, now applied with ack by Lars.
> > 
> > 
> > Takashi
> 
> Thank you. And Iwai-san, could you please tell me in which repo and branch
> could I cherry-pick this patch?
> 
> I tried some in git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git
> but failed to locate the patch.

It's in for-next branch, and now pushed out.
(It didn't go out in this morning since the network connection in the
 hotel wasn't good, and it broke during I worked on it...)


Takashi

> 
> Thank you,
> Nicolin Chen
> 
> > 
> > > ---
> > > Changelog
> > > v6->v7:
> > >  * Assigned pool to private_data field and accordingly refined helper functions.
> > > v5->v6:
> > >  * Dropped remaining OF dependency bacause no need to add them:
> > >    of_node doesn't care about OF; of_get_named_gen_pool() returns NULL if !OF.
> > > v4->v5:
> > >  * Minimized the OF dependency.
> > > v3->v4:
> > >  * Appropriately placed '#ifdef CONFIG_OF'
> > >  * Tested by adding '#undef CONFIG_OF' to modified files, and passed compiling.
> > > v2->v3:
> > >  * Moved iram specific mmap procedure out of ifdef ARCH_HAS_DMA_MMAP_COHERENT
> > > v1->v2:
> > >  * Added of_node check
> > >  * Dropped noops and unused physical addr in snd_free_dev_iram()
> > > 
> > > ---
> > >  include/sound/memalloc.h |  1 +
> > >  sound/core/memalloc.c    | 52 ++++++++++++++++++++++++++++++++++++++++++++++++
> > >  sound/core/pcm_native.c  |  6 ++++++
> > >  3 files changed, 59 insertions(+)
> > > 
> > > diff --git a/include/sound/memalloc.h b/include/sound/memalloc.h
> > > index cf15b82..510aec4 100644
> > > --- a/include/sound/memalloc.h
> > > +++ b/include/sound/memalloc.h
> > > @@ -52,6 +52,7 @@ struct snd_dma_device {
> > >  #else
> > >  #define SNDRV_DMA_TYPE_DEV_SG	SNDRV_DMA_TYPE_DEV /* no SG-buf support */
> > >  #endif
> > > +#define SNDRV_DMA_TYPE_DEV_IRAM		4	/* generic device iram-buffer */
> > >  
> > >  /*
> > >   * info for buffer allocation
> > > diff --git a/sound/core/memalloc.c b/sound/core/memalloc.c
> > > index bdf826f..18c1d47 100644
> > > --- a/sound/core/memalloc.c
> > > +++ b/sound/core/memalloc.c
> > > @@ -30,6 +30,7 @@
> > >  #include <linux/seq_file.h>
> > >  #include <asm/uaccess.h>
> > >  #include <linux/dma-mapping.h>
> > > +#include <linux/genalloc.h>
> > >  #include <linux/moduleparam.h>
> > >  #include <linux/mutex.h>
> > >  #include <sound/memalloc.h>
> > > @@ -157,6 +158,46 @@ static void snd_free_dev_pages(struct device *dev, size_t size, void *ptr,
> > >  	dec_snd_pages(pg);
> > >  	dma_free_coherent(dev, PAGE_SIZE << pg, ptr, dma);
> > >  }
> > > +
> > > +/**
> > > + * snd_malloc_dev_iram - allocate memory from on-chip internal ram
> > > + * @dmab: buffer allocation record to store the allocated data
> > > + * @size: number of bytes to allocate from the iram
> > > + *
> > > + * This function requires iram phandle provided via of_node
> > > + */
> > > +void snd_malloc_dev_iram(struct snd_dma_buffer *dmab, size_t size)
> > > +{
> > > +	struct device *dev = dmab->dev.dev;
> > > +	struct gen_pool *pool = NULL;
> > > +
> > > +	if (dev->of_node)
> > > +		pool = of_get_named_gen_pool(dev->of_node, "iram", 0);
> > > +
> > > +	if (!pool)
> > > +		return;
> > > +
> > > +	/* Assign the pool into private_data field */
> > > +	dmab->private_data = pool;
> > > +
> > > +	dmab->area = (void *)gen_pool_alloc(pool, size);
> > > +	if (!dmab->area)
> > > +		return;
> > > +
> > > +	dmab->addr = gen_pool_virt_to_phys(pool, (unsigned long)dmab->area);
> > > +}
> > > +
> > > +/**
> > > + * snd_free_dev_iram - free allocated specific memory from on-chip internal ram
> > > + * @dmab: buffer allocation record to store the allocated data
> > > + */
> > > +void snd_free_dev_iram(struct snd_dma_buffer *dmab)
> > > +{
> > > +	struct gen_pool *pool = dmab->private_data;
> > > +
> > > +	if (pool && dmab->area)
> > > +		gen_pool_free(pool, (unsigned long)dmab->area, dmab->bytes);
> > > +}
> > >  #endif /* CONFIG_HAS_DMA */
> > >  
> > >  /*
> > > @@ -197,6 +238,14 @@ int snd_dma_alloc_pages(int type, struct device *device, size_t size,
> > >  		dmab->addr = 0;
> > >  		break;
> > >  #ifdef CONFIG_HAS_DMA
> > > +	case SNDRV_DMA_TYPE_DEV_IRAM:
> > > +		snd_malloc_dev_iram(dmab, size);
> > > +		if (dmab->area)
> > > +			break;
> > > +		/* Internal memory might have limited size and no enough space,
> > > +		 * so if we fail to malloc, try to fetch memory traditionally.
> > > +		 */
> > > +		dmab->dev.type = SNDRV_DMA_TYPE_DEV;
> > >  	case SNDRV_DMA_TYPE_DEV:
> > >  		dmab->area = snd_malloc_dev_pages(device, size, &dmab->addr);
> > >  		break;
> > > @@ -269,6 +318,9 @@ void snd_dma_free_pages(struct snd_dma_buffer *dmab)
> > >  		snd_free_pages(dmab->area, dmab->bytes);
> > >  		break;
> > >  #ifdef CONFIG_HAS_DMA
> > > +	case SNDRV_DMA_TYPE_DEV_IRAM:
> > > +		snd_free_dev_iram(dmab);
> > > +		break;
> > >  	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 a68d4c6..513f095 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,
> > >  			     struct vm_area_struct *area)
> > >  {
> > >  	area->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
> > > +	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);
> > > +	}
> > >  #ifdef ARCH_HAS_DMA_MMAP_COHERENT
> > >  	if (!substream->ops->page &&
> > >  	    substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV)
> > > -- 
> > > 1.8.4
> > > 
> > > 
> > 
> 
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v7] ALSA: Add SoC on-chip internal ram support for DMA buffer allocation
  2013-10-24  7:22 ` Takashi Iwai
  2013-10-24  8:05   ` Nicolin Chen
@ 2013-10-24 12:38   ` Takashi Iwai
  1 sibling, 0 replies; 7+ messages in thread
From: Takashi Iwai @ 2013-10-24 12:38 UTC (permalink / raw)
  To: Nicolin Chen; +Cc: alsa-devel, broonie, lars, lgirdwood

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@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@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@intel.com>
Signed-off-by: Takashi Iwai <tiwai@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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-10-24 12:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-23  3:47 [PATCH v7] ALSA: Add SoC on-chip internal ram support for DMA buffer allocation Nicolin Chen
2013-10-23 15:02 ` Lars-Peter Clausen
2013-10-24  7:22 ` Takashi Iwai
2013-10-24  8:05   ` Nicolin Chen
2013-10-24  9:15     ` Takashi Iwai
2013-10-24  8:54       ` Nicolin Chen
2013-10-24 12:38   ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).