Skip to contentSkip to conversation

ALSA: Add SoC on-chip internal memory support for DMA buffer allocation

PATCH Superseded Nicolin Chen 4 participants 5 messages Oct 22, 2013 Sound

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 ALSA: Add SoC on-chip internal memory support for DMA buffer allocation

Now it's quite common that an SoC contains its on-chip internal memory. By using this memory space for DMA buffer during audio playback/record, we can shutdown the voltage for external memory to save power.

Thus add new DEV type with iram malloc()/free() and accordingly modify current default mmap() for the iram circumstance.

---
Changelog
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    | 65 ++++++++++++++++++++++++++++++++++++++++++++++++
 sound/core/pcm_native.c  |  6 +++++
 3 files changed, 72 insertions(+)
include/sound/memalloc.h +1 -0
index cf15b82..510aec4 100644
@@ -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
sound/core/memalloc.c +65 -0

89 lines not on this page · raw message

sound/core/pcm_native.c +6 -0
index a68d4c6..513f095 100644
@@ -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)
Signature · 1 line
1.8.4
#1 lore raw

On 10/22/2013 05:00 AM, Nicolin Chen wrote:
[...]

Quoted 8 lines
sound/core/memalloc.c +8 -0
+/**
+ * snd_free_dev_iram - free allocated specific memory from on-chip internal memory
+ * @dev: DMA device pointer
+ * @size: size in bytes of memory to free
+ * @ptr: cpu-view address returned from snd_malloc_dev_iram
+ *
+ * This function requires iram phandle provided via of_node
+ */

sound/core/memalloc.c static void snd_free_dev_pages(struct device *dev, size_t size, void *ptr, · line 210

Quoted 10 lines
sound/core/memalloc.c +10 -0
+void snd_free_dev_iram(struct device *dev, size_t size, void *ptr)
+{
+	struct gen_pool *pool = NULL;
+
+	if (!dev->of_node)
+		return;
+
+	pool = of_get_named_gen_pool(dev->of_node, "iram", 0);
+	if (!pool)
+		return;

I've had a closer look at the other SNDRV_DMA_TYPE implementations and I think a better way to handle this is to assign the pool to the snd_dma_buffer's private_data field and then use it here instead of looking the pool up again. This will also make it easier to use a non-OF lookup scheme.

Quoted 6 lines
sound/core/memalloc.c +3 -0
+
+	gen_pool_free(pool, (unsigned long)ptr, size);
+}
 #endif /* CONFIG_HAS_DMA */
 
 /*
#2 lore raw
Quoted 29 lines · Lars-Peter Clausen

On 10/22/2013 05:00 AM, Nicolin Chen wrote:
[...]

Quoted 2 lines

+/**
+ * snd_free_dev_iram - free allocated specific memory from on-chip

internal memory

Quoted 6 lines

+ * @dev: DMA device pointer
+ * @size: size in bytes of memory to free
+ * @ptr: cpu-view address returned from snd_malloc_dev_iram
+ *
+ * This function requires iram phandle provided via of_node
+ */

sound/core/memalloc.c static void snd_free_dev_pages(struct device *dev, size_t size, void *ptr, · line 210

Quoted 10 lines
sound/core/memalloc.c +10 -0
+void snd_free_dev_iram(struct device *dev, size_t size, void *ptr)
+{
+     struct gen_pool *pool = NULL;
+
+     if (!dev->of_node)
+             return;
+
+     pool = of_get_named_gen_pool(dev->of_node, "iram", 0);
+     if (!pool)
+             return;

I've had a closer look at the other SNDRV_DMA_TYPE implementations and I think a better way to handle this is to assign the pool to the snd_dma_buffer's private_data field and then use it here instead of looking the pool up again. This will also make it easier to use a non-OF lookup scheme.

Quoted 1 line

By saving the pool to pdata during the allocating? Hmm..that should be

nicer.

Quoted 1 line

Just need to change the parameter "struct device *" to "struct gen_pool

*" directly

Quoted 17 lines

I'll see what I can do to refine it. Thank you for the suggestion.

Nicolin Chen

sound/core/memalloc.c static void snd_free_dev_pages(struct device *dev, size_t size, void *ptr, · line 216

Quoted 6 lines
sound/core/memalloc.c +3 -0
+
+     gen_pool_free(pool, (unsigned long)ptr, size);
+}
 #endif /* CONFIG_HAS_DMA */
 
 /*

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#3 lore raw

At Tue, 22 Oct 2013 20:49:49 +0800,

Quoted 32 lines · Nicole Otsuka
Quoted 28 lines · Lars-Peter Clausen

On 10/22/2013 05:00 AM, Nicolin Chen wrote:
[...]

Quoted 2 lines

+/**
+ * snd_free_dev_iram - free allocated specific memory from on-chip

internal memory

Quoted 6 lines

+ * @dev: DMA device pointer
+ * @size: size in bytes of memory to free
+ * @ptr: cpu-view address returned from snd_malloc_dev_iram
+ *
+ * This function requires iram phandle provided via of_node
+ */

sound/core/memalloc.c static void snd_free_dev_pages(struct device *dev, size_t size, void *ptr, · line 210

Quoted 10 lines
sound/core/memalloc.c +10 -0
+void snd_free_dev_iram(struct device *dev, size_t size, void *ptr)
+{
+     struct gen_pool *pool = NULL;
+
+     if (!dev->of_node)
+             return;
+
+     pool = of_get_named_gen_pool(dev->of_node, "iram", 0);
+     if (!pool)
+             return;

I've had a closer look at the other SNDRV_DMA_TYPE implementations and I think a better way to handle this is to assign the pool to the snd_dma_buffer's private_data field and then use it here instead of looking the pool up again. This will also make it easier to use a non-OF lookup scheme.

Quoted 5 lines
Quoted 1 line

By saving the pool to pdata during the allocating? Hmm..that should be

nicer.

Quoted 1 line

Just need to change the parameter "struct device *" to "struct gen_pool

*" directly

Quoted 1 line

I'll see what I can do to refine it. Thank you for the suggestion.

I guess Lars meant to use simply snd_dma_buffer.private_data field for storing the pool pointer in snd_malloc_dev_iram(), and use this pointer instead of calling of_get_named_gen_pool() again in snd_free_dev_iram().

Takashi

#4 lore raw
Quoted 41 lines · Takashi Iwai

At Tue, 22 Oct 2013 20:49:49 +0800,

Quoted 2 lines · Nicole Otsuka

On Tue, Oct 22, 2013 at 8:06 PM, Lars-Peter Clausen <[email protected]>

Quoted 16 lines · wrote:
Quoted 16 lines · Nicolin Chen

[...]

Quoted 2 lines

+/**
+ * snd_free_dev_iram - free allocated specific memory from on-chip

internal memory

Quoted 10 lines

+ * @dev: DMA device pointer
+ * @size: size in bytes of memory to free
+ * @ptr: cpu-view address returned from snd_malloc_dev_iram
+ *
+ * This function requires iram phandle provided via of_node
+ */

sound/core/memalloc.c +4 -0
+void snd_free_dev_iram(struct device *dev, size_t size, void *ptr)
+{
+     struct gen_pool *pool = NULL;
+
Quoted 8 lines
Quoted 8 lines

sound/core/memalloc.c static void snd_free_dev_pages(struct device *dev, size_t size, void *ptr, · line 210

Quoted 6 lines
sound/core/memalloc.c +6 -0
+     if (!dev->of_node)
+             return;
+
+     pool = of_get_named_gen_pool(dev->of_node, "iram", 0);
+     if (!pool)
+             return;

I've had a closer look at the other SNDRV_DMA_TYPE implementations and

I

Quoted 2 lines
Quoted 2 lines

think a better way to handle this is to assign the pool to the snd_dma_buffer's private_data field and then use it here instead of

looking

Quoted 8 lines
Quoted 5 lines

the pool up again. This will also make it easier to use a non-OF lookup scheme.

By saving the pool to pdata during the allocating? Hmm..that should be

nicer.

Quoted 1 line

Just need to change the parameter "struct device *" to "struct gen_pool

*" directly

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

I'll see what I can do to refine it. Thank you for the suggestion.

I guess Lars meant to use simply snd_dma_buffer.private_data field for storing the pool pointer in snd_malloc_dev_iram(), and use this pointer instead of calling of_get_named_gen_pool() again in snd_free_dev_iram().

Oh, thank you for the explain.

I'll try to refine it tomorrow.

Nicolin Chen

Quoted 3 lines
Quoted 2 lines

Takashi