Add and implement gen_pool_dma_alloc()
Subsystems (10)
cover Add and implement gen_pool_dma_alloc()
Previously, we don't have a specific gen_pool_alloc() for DMA usage; Instead, we need to use gen_pool_virt_to_phys() to convert the addr returned from gen_pool_alloc(). So each implementation of this has duplicated code. Thus add new helper function -- gen_pool_dma_alloc().
After gen_pool_dma_alloc() is introduced, we can replace the original combination of gen_pool_alloc()+gen_pool_virt_to_phys() with this new helper function. Thus this patch implement the helper function to all the current drivers which use gen_pool_virt_to_phys().
!!-------------------important------------------!!
The later 7 patches need all related driver owner to test. We can here define a simple rule:
1, If one driver owner or maintainer doesn't like the mofication
to his/her driver, just let me know. I would drop that patch.
2, If there's a bug and issue found after patch-testing, please
reply the mail so that I can fix and refine the patch.
3, If one driver owner or maintainer is too busy and doesn't have
bandwidth to test the patch, I would drop that patch from this series. We can reimplement it till there's someone test it.
!!-------------------current progress-----------!!
lib/genalloc: [Okay]
ARM: davinci: [Untested]
dma: mmp_tdma: [Untested]
[media] coda: [Untested]
uio: uio_pruss: [Untested]
ALSA: memalloc: [Tested] by Nicolin Chen with i.MX6Q SabreSD
ASoC: davinci: [Untested]
ASoC: pxa: use [Untested]
Nicolin Chen (8):
lib/genalloc: add a helper function for DMA buffer allocation
ARM: davinci: use gen_pool_dma_alloc() to sram.c
dma: mmp_tdma: use gen_pool_dma_alloc() to allocate descriptor [media] coda: use gen_pool_dma_alloc() to allocate iram buffer
uio: uio_pruss: use gen_pool_dma_alloc() to allocate sram memory
ALSA: memalloc: use gen_pool_dma_alloc() to allocate iram buffer
ASoC: davinci: use gen_pool_dma_alloc() in davinci-pcm.c
ASoC: pxa: use gen_pool_dma_alloc() to allocate dma buffer
arch/arm/mach-davinci/sram.c | 9 +-------- drivers/dma/mmp_tdma.c | 7 +------ drivers/media/platform/coda.c | 5 ++--- drivers/uio/uio_pruss.c | 6 ++---- include/linux/genalloc.h | 2 ++ lib/genalloc.c | 28 ++++++++++++++++++++++++++++ sound/core/memalloc.c | 6 +----- sound/soc/davinci/davinci-pcm.c | 3 +-- sound/soc/pxa/mmp-pcm.c | 3 +-- 9 files changed, 39 insertions(+), 30 deletions(-)
Signature · 1 line
1.8.4
PATCH RESEND 1/8 lib/genalloc: add a helper function for DMA buffer allocation
When using pool space for DMA buffer, there might be duplicated calling of gen_pool_alloc() and gen_pool_virt_to_phys() in each implementation.
Thus it's better to add a simple helper function, a compatible one to the common dma_alloc_coherent(), to save some code.
--- include/linux/genalloc.h | 2 ++ lib/genalloc.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+)
include/linux/genalloc.h +2 -0
@@ -94,6 +94,8 @@ static inline int gen_pool_add(struct gen_pool *pool, unsigned long addr, }extern void gen_pool_destroy (struct gen_pool *);extern unsigned long gen_pool_alloc (struct gen_pool *,size_t ); +extern void *gen_pool_dma_alloc (struct gen_pool *pool,size_t size, +dma_addr_t *dma);extern void gen_pool_free (struct gen_pool *,unsigned long ,size_t );extern void gen_pool_for_each_chunk (struct gen_pool *,void (*)(struct gen_pool *,struct gen_pool_chunk *,void *),void *);
lib/genalloc.c +28 -0
@@ -313,6 +313,34 @@ retry:EXPORT_SYMBOL (gen_pool_alloc);/** +* gen_pool_dma_alloc - allocate special memory from the pool for DMA usage +* @pool: pool to allocate from +* @size: number of bytes to allocate from the pool +* @dma: dma-view physical address +* +* Allocate the requested number of bytes from the specified pool. +* Uses the pool allocation function (with first-fit algorithm by default). +* Can not be used in NMI handler on architectures without +* NMI-safe cmpxchg implementation. +*/ +void *gen_pool_dma_alloc (struct gen_pool *pool,size_t size,dma_addr_t *dma) +{ +unsigned long vaddr; + +if (!pool) +return NULL ; + + vaddr =gen_pool_alloc (pool, size); +if (!vaddr) +return NULL ; + + *dma =gen_pool_virt_to_phys (pool, vaddr); + +return (void *)vaddr; +} +EXPORT_SYMBOL (gen_pool_dma_alloc); + +/** * gen_pool_free - free allocated special memory back to the pool * @pool: pool to free to * @addr: starting address of memory to free back to pool
Signature · 1 line
1.8.4
PATCH RESEND 2/8 ARM: davinci: use gen_pool_dma_alloc() to sram.c
In reply to Nicolin ChenSince gen_pool_dma_alloc() is introduced, we implement it to simplify code.
--- arch/arm/mach-davinci/sram.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
arch/arm/mach-davinci/sram.c +1 -8
@@ -25,7 +25,6 @@ struct gen_pool *sram_get_gen_pool(void)void *sram_alloc (size_t len,dma_addr_t *dma) { -unsigned long vaddr;dma_addr_t dma_base = davinci_soc_info.sram_dma;if (dma)
@@ -33,13 +32,7 @@ void *sram_alloc(size_t len, dma_addr_t *dma)if (!sram_pool || (dma && !dma_base))return NULL ; - vaddr =gen_pool_alloc (sram_pool, len); -if (!vaddr) -return NULL ; - -if (dma) - *dma =gen_pool_virt_to_phys (sram_pool, vaddr); -return (void *)vaddr; +return gen_pool_dma_alloc (sram_pool, len, dma); }EXPORT_SYMBOL (sram_alloc);
Signature · 1 line
1.8.4
PATCH RESEND 3/8 dma: mmp_tdma: use gen_pool_dma_alloc() to allocate descriptor
In reply to Nicolin ChenSince gen_pool_dma_alloc() is introduced, we implement it to simplify code.
--- drivers/dma/mmp_tdma.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/dma/mmp_tdma.c +1 -6
@@ -378,12 +378,7 @@ struct mmp_tdma_desc *mmp_tdma_alloc_descriptor(struct mmp_tdma_chan *tdmac)if (!gpool)return NULL ; - tdmac->desc_arr = (void *)gen_pool_alloc (gpool, size); -if (!tdmac->desc_arr) -return NULL ; - - tdmac->desc_arr_phys =gen_pool_virt_to_phys (gpool, - (unsigned long )tdmac->desc_arr); + tdmac->desc_arr =gen_pool_dma_alloc (gpool, size, &tdmac->desc_arr_phys);return tdmac->desc_arr; }
Signature · 1 line
1.8.4
PATCH RESEND 4/8 coda: use gen_pool_dma_alloc() to allocate iram buffer
In reply to Nicolin ChenSince gen_pool_dma_alloc() is introduced, we implement it to simplify code.
--- drivers/media/platform/coda.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/media/platform/coda.c +2 -3
@@ -3298,13 +3298,12 @@ static int coda_probe(struct platform_device *pdev) dev->iram_size =CODA7_IRAM_SIZE ;break ; } - dev->iram_vaddr =gen_pool_alloc (dev->iram_pool, dev->iram_size); + dev->iram_vaddr = (unsigned long )gen_pool_dma_alloc (dev->iram_pool, + dev->iram_size, (dma_addr_t *)&dev->iram_paddr);if (!dev->iram_vaddr) {dev_err (&pdev->dev,"unable to alloc iram\n" );return -ENOMEM ; } - dev->iram_paddr =gen_pool_virt_to_phys (dev->iram_pool, - dev->iram_vaddr);platform_set_drvdata (pdev, dev);
Signature · 1 line
1.8.4
PATCH RESEND 5/8 uio: uio_pruss: use gen_pool_dma_alloc() to allocate sram memory
In reply to Nicolin ChenSince gen_pool_dma_alloc() is introduced, we implement it to simplify code.
--- drivers/uio/uio_pruss.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/uio/uio_pruss.c +2 -4
@@ -158,14 +158,12 @@ static int pruss_probe(struct platform_device *dev)if (pdata->sram_pool) { gdev->sram_pool = pdata->sram_pool; gdev->sram_vaddr = -gen_pool_alloc (gdev->sram_pool, sram_pool_sz); + (unsigned long )gen_pool_dma_alloc (gdev->sram_pool, + sram_pool_sz, &gdev->sram_paddr);if (!gdev->sram_vaddr) {dev_err (&dev->dev,"Could not allocate SRAM pool\n" ); goto out_free; } - gdev->sram_paddr = -gen_pool_virt_to_phys (gdev->sram_pool, - gdev->sram_vaddr); } gdev->ddr_vaddr = dma_alloc_coherent(&dev->dev, extram_pool_sz,
Signature · 1 line
1.8.4
PATCH RESEND 6/8 ALSA: memalloc: use gen_pool_dma_alloc() to allocate iram buffer
In reply to Nicolin ChenSince gen_pool_dma_alloc() is introduced, we implement it to simplify code.
--- sound/core/memalloc.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
sound/core/memalloc.c +1 -5
@@ -184,11 +184,7 @@ static void snd_malloc_dev_iram(struct snd_dma_buffer *dmab, size_t size)/* 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); + dmab->area =gen_pool_dma_alloc (pool, size, &dmab->addr); }/**
Signature · 1 line
1.8.4
PATCH RESEND 7/8 ASoC: davinci: use gen_pool_dma_alloc() in davinci-pcm.c
In reply to Nicolin ChenSince gen_pool_dma_alloc() is introduced, we implement it to simplify code.
--- sound/soc/davinci/davinci-pcm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
sound/soc/davinci/davinci-pcm.c +1 -2
@@ -267,10 +267,9 @@ static int allocate_sram(struct snd_pcm_substream *substream,return 0 ; ppcm->period_bytes_max = size; - iram_virt = (void *)gen_pool_alloc (sram_pool, size); + iram_virt =gen_pool_dma_alloc (sram_pool, size, &iram_phys);if (!iram_virt) goto exit1; - iram_phys =gen_pool_virt_to_phys (sram_pool, (unsigned )iram_virt); iram_dma =kzalloc (sizeof (*iram_dma),GFP_KERNEL );if (!iram_dma) goto exit2;
Signature · 1 line
1.8.4
PATCH RESEND 8/8 ASoC: pxa: use gen_pool_dma_alloc() to allocate dma buffer
In reply to Nicolin ChenSince gen_pool_dma_alloc() is introduced, we implement it to simplify code.
--- sound/soc/pxa/mmp-pcm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
sound/soc/pxa/mmp-pcm.c +1 -2
@@ -201,10 +201,9 @@ static int mmp_pcm_preallocate_dma_buffer(struct snd_pcm_substream *substream,if (!gpool)return -ENOMEM ; - buf->area = (unsigned char *)gen_pool_alloc (gpool, size); + buf->area =gen_pool_dma_alloc (gpool, size, &buf->addr);if (!buf->area)return -ENOMEM ; - buf->addr =gen_pool_virt_to_phys (gpool, (unsigned long )buf->area); buf->bytes = size;return 0 ; }
Signature · 1 line
1.8.4
Re: [PATCH][RESEND 7/8] ASoC: davinci: use gen_pool_dma_alloc() in davinci-pcm.c
In reply to Nicolin ChenQuoted 1 line · Nicolin Chen
Since
gen_pool_dma_alloc()is introduced, we implement it to simplify code.
Re: [PATCH][RESEND 8/8] ASoC: pxa: use gen_pool_dma_alloc() to allocate dma buffer
In reply to Nicolin ChenQuoted 1 line · Nicolin Chen
Since
gen_pool_dma_alloc()is introduced, we implement it to simplify code.
Re: [PATCH][RESEND 6/8] ALSA: memalloc: use gen_pool_dma_alloc() to allocate iram buffer
In reply to Nicolin ChenAt Fri, 1 Nov 2013 19:48:19 +0800,
Quoted 4 lines · Nicolin Chen
Since
gen_pool_dma_alloc()is introduced, we implement it to simplify code.Signed-off-by Nicolin Chen <[email protected]>
Quoted 25 lines
--- sound/core/memalloc.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)sound/core/memalloc.c +1
-5@@ -184,11 +184,7 @@ static void snd_malloc_dev_iram(struct snd_dma_buffer *dmab, size_t size)/* 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); + dmab->area =gen_pool_dma_alloc (pool, size, &dmab->addr); }/** Signature · 1 line
1.8.4
Re: [PATCH][RESEND 3/8] dma: mmp_tdma: use gen_pool_dma_alloc() to allocate descriptor
In reply to Nicolin ChenQuoted 1 line · Nicolin Chen
Since
gen_pool_dma_alloc()is introduced, we implement it to simplify code.
--
~Vinod
Re: [PATCH][RESEND 5/8] uio: uio_pruss: use gen_pool_dma_alloc() to allocate sram memory
In reply to Nicolin ChenQuoted 4 lines · Nicolin Chen
Since
gen_pool_dma_alloc()is introduced, we implement it to simplify code.Signed-off-by Nicolin Chen <[email protected]>---