Skip to contentSkip to conversation

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

PATCH Superseded Nicolin Chen 3 participants 7 messages Oct 16, 2013 – Oct 17, 2013 Sound

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 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
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 |  5 ++++
 sound/core/memalloc.c    | 71 ++++++++++++++++++++++++++++++++++++++++++++++++
 sound/core/pcm_native.c  |  7 +++++
 3 files changed, 83 insertions(+)
include/sound/memalloc.h +5 -0
index cf15b82..b53443e 100644
@@ -52,6 +52,11 @@ struct snd_dma_device {
 #else
 #define SNDRV_DMA_TYPE_DEV_SG	SNDRV_DMA_TYPE_DEV /* no SG-buf support */
 #endif
+#ifdef CONFIG_OF
+#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
sound/core/memalloc.c +71 -0

95 lines not on this page · raw message

sound/core/pcm_native.c +7 -0
index a68d4c6..74de2a3 100644
@@ -3199,6 +3199,13 @@ 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 &&
+			SNDRV_DMA_TYPE_DEV_IRAM != SNDRV_DMA_TYPE_DEV) {
+		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

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

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

Can you refactor these ifdefs so they just protect this OF specific code and just have the allocation fail otherwise please? That way the OF dependency is minimised - we should be able to support this on other platforms in the future and the rest of the code will be the same.

Also is iram the best name? It makes me think of the dedicated fast instruction RAM that some processors have. sram perhaps (for static RAM)?

#2 lore raw

Okay, I will try to refine it tomorrow.

Thank you for the comments.

Sent by Android device.

Mark Brown <[email protected]> wrote:

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

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

Can you refactor these ifdefs so they just protect this OF specific code and just have the allocation fail otherwise please? That way the OF dependency is minimised - we should be able to support this on other platforms in the future and the rest of the code will be the same.

Also is iram the best name? It makes me think of the dedicated fast instruction RAM that some processors have. sram perhaps (for static RAM)?

#3 lore raw
In reply to Mark Brown
Quoted 14 lines · Mark Brown

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

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

Can you refactor these ifdefs so they just protect this OF specific code and just have the allocation fail otherwise please? That way the OF dependency is minimised - we should be able to support this on other platforms in the future and the rest of the code will be the same.

Quoted 3 lines

Also is iram the best name? It makes me think of the dedicated fast instruction RAM that some processors have. sram perhaps (for static RAM)?

Using IRAM (internal SRAM) for this seems to be quite popular (grep IRAM arch/arm -r). Existing devicetree bindings also seem to use the 'iram' property to refer to the on-chip SRAM (Documentation/devicetree/bindings/media/coda.txt). It's probably a good idea to stay consistent with the existing bindings.

- Lars

#4 lore raw
Quoted 11 lines · Lars-Peter Clausen
Quoted 3 lines · Mark Brown

Also is iram the best name? It makes me think of the dedicated fast instruction RAM that some processors have. sram perhaps (for static RAM)?

Using IRAM (internal SRAM) for this seems to be quite popular (grep IRAM arch/arm -r). Existing devicetree bindings also seem to use the 'iram' property to refer to the on-chip SRAM (Documentation/devicetree/bindings/media/coda.txt). It's probably a good idea to stay consistent with the existing bindings.

Oh, I wonder when that changed - it always used to get called SRAM (or TCM when that was what was used).

#5 lore raw
Quoted 7 lines · Mark Brown
Quoted 5 lines · Lars-Peter Clausen
Quoted 3 lines · Mark Brown

Also is iram the best name? It makes me think of the dedicated fast instruction RAM that some processors have. sram perhaps (for static RAM)?

Quoted 8 lines
Quoted 5 lines

Using IRAM (internal SRAM) for this seems to be quite popular (grep IRAM arch/arm -r). Existing devicetree bindings also seem to use the 'iram' property to refer to the on-chip SRAM (Documentation/devicetree/bindings/media/coda.txt). It's probably a good idea to stay consistent with the existing bindings.

Oh, I wonder when that changed - it always used to get called SRAM (or TCM when that was what was used).

Do I still need to change the name to SRAM? I think both name make sense to me. I use IRAM just because using different name for phandle and macro/functions might confuse people when reviewing the patch. But it looks like IRAM is still not the perfect choice.

Looking forward to your reply,
Nicolin Chen

#6 lore raw
Quoted 4 lines · Nicolin Chen

Do I still need to change the name to SRAM? I think both name make sense to me. I use IRAM just because using different name for phandle and macro/functions might confuse people when reviewing the patch. But it looks like IRAM is still not the perfect choice.

No, IRAM is fine if that is actually used these days.