Linux MIPS Architecture development
 help / color / mirror / Atom feed
* [PATCH 16/16] alsa sound support for mips
@ 2007-04-04 14:38 zhangfx
  0 siblings, 0 replies; 5+ messages in thread
From: zhangfx @ 2007-04-04 14:38 UTC (permalink / raw)
  To: linux-mips@linux-mips.org

[-- Attachment #1: Type: text/plain, Size: 2108 bytes --]


Signed-off-by: Fuxin Zhang <zhangfx@lemote.com>
---
 sound/core/pcm_native.c |   10 ++++++++++
 sound/core/sgbuf.c      |    9 +++++++++
 2 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 3e276fc..9005bac 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -3145,7 +3145,11 @@ static struct page *snd_pcm_mmap_data_nopage(struct vm_area_struct *area,
 			return NOPAGE_OOM; /* XXX: is this really due to OOM? */
 	} else {
 		vaddr = runtime->dma_area + offset;
+#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)
+		page = virt_to_page(CAC_ADDR(vaddr));
+#else
 		page = virt_to_page(vaddr);
+#endif
 	}
 	get_page(page);
 	if (type)
@@ -3261,6 +3265,12 @@ static int snd_pcm_mmap(struct file *file, struct vm_area_struct *area)
 	substream = pcm_file->substream;
 	snd_assert(substream != NULL, return -ENXIO);
 
+#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)
+	/* all mmap using uncached mode */
+	area->vm_page_prot = pgprot_noncached(area->vm_page_prot);
+	area->vm_flags |= ( VM_RESERVED | VM_IO);
+#endif
+
 	offset = area->vm_pgoff << PAGE_SHIFT;
 	switch (offset) {
 	case SNDRV_PCM_MMAP_OFFSET_STATUS:
diff --git a/sound/core/sgbuf.c b/sound/core/sgbuf.c
index cefd228..535f0bc 100644
--- a/sound/core/sgbuf.c
+++ b/sound/core/sgbuf.c
@@ -91,12 +91,21 @@ void *snd_malloc_sgbuf_pages(struct device *device,
 		}
 		sgbuf->table[i].buf = tmpb.area;
 		sgbuf->table[i].addr = tmpb.addr;
+#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)
+		sgbuf->page_table[i] = virt_to_page(CAC_ADDR(tmpb.area));
+#else
 		sgbuf->page_table[i] = virt_to_page(tmpb.area);
+#endif
 		sgbuf->pages++;
 	}
 
 	sgbuf->size = size;
+#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)
+	/* maybe we should use uncached accelerated mode */
+	dmab->area = vmap(sgbuf->page_table, sgbuf->pages, VM_MAP | VM_IO, pgprot_noncached(PAGE_KERNEL));
+#else
 	dmab->area = vmap(sgbuf->page_table, sgbuf->pages, VM_MAP, PAGE_KERNEL);
+#endif
 	if (! dmab->area)
 		goto _failed;
 	return dmab->area;
-- 
1.4.4.4



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

* [PATCH 16/16] alsa sound support for mips
  2007-04-15 15:26                             ` [PATCH 15/16] work around for more than 256MB memory support tiansm
@ 2007-04-15 15:26                               ` tiansm
  2007-04-18 13:54                                 ` Ralf Baechle
  0 siblings, 1 reply; 5+ messages in thread
From: tiansm @ 2007-04-15 15:26 UTC (permalink / raw)
  To: linux-mips; +Cc: Fuxin Zhang

From: Fuxin Zhang <zhangfx@lemote.com>

Signed-off-by: Fuxin Zhang <zhangfx@lemote.com>
---
 sound/core/pcm_native.c |   10 ++++++++++
 sound/core/sgbuf.c      |    9 +++++++++
 2 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 3e276fc..9005bac 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -3145,7 +3145,11 @@ static struct page *snd_pcm_mmap_data_nopage(struct vm_area_struct *area,
 			return NOPAGE_OOM; /* XXX: is this really due to OOM? */
 	} else {
 		vaddr = runtime->dma_area + offset;
+#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)
+		page = virt_to_page(CAC_ADDR(vaddr));
+#else
 		page = virt_to_page(vaddr);
+#endif
 	}
 	get_page(page);
 	if (type)
@@ -3261,6 +3265,12 @@ static int snd_pcm_mmap(struct file *file, struct vm_area_struct *area)
 	substream = pcm_file->substream;
 	snd_assert(substream != NULL, return -ENXIO);
 
+#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)
+	/* all mmap using uncached mode */
+	area->vm_page_prot = pgprot_noncached(area->vm_page_prot);
+	area->vm_flags |= ( VM_RESERVED | VM_IO);
+#endif
+
 	offset = area->vm_pgoff << PAGE_SHIFT;
 	switch (offset) {
 	case SNDRV_PCM_MMAP_OFFSET_STATUS:
diff --git a/sound/core/sgbuf.c b/sound/core/sgbuf.c
index cefd228..535f0bc 100644
--- a/sound/core/sgbuf.c
+++ b/sound/core/sgbuf.c
@@ -91,12 +91,21 @@ void *snd_malloc_sgbuf_pages(struct device *device,
 		}
 		sgbuf->table[i].buf = tmpb.area;
 		sgbuf->table[i].addr = tmpb.addr;
+#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)
+		sgbuf->page_table[i] = virt_to_page(CAC_ADDR(tmpb.area));
+#else
 		sgbuf->page_table[i] = virt_to_page(tmpb.area);
+#endif
 		sgbuf->pages++;
 	}
 
 	sgbuf->size = size;
+#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)
+	/* maybe we should use uncached accelerated mode */
+	dmab->area = vmap(sgbuf->page_table, sgbuf->pages, VM_MAP | VM_IO, pgprot_noncached(PAGE_KERNEL));
+#else
 	dmab->area = vmap(sgbuf->page_table, sgbuf->pages, VM_MAP, PAGE_KERNEL);
+#endif
 	if (! dmab->area)
 		goto _failed;
 	return dmab->area;
-- 
1.4.4.1

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

* Re: [PATCH 16/16] alsa sound support for mips
  2007-04-15 15:26                               ` [PATCH 16/16] alsa sound support for mips tiansm
@ 2007-04-18 13:54                                 ` Ralf Baechle
  2007-04-18 14:13                                   ` Fuxin Zhang
  0 siblings, 1 reply; 5+ messages in thread
From: Ralf Baechle @ 2007-04-18 13:54 UTC (permalink / raw)
  To: tiansm, perex, alsa-devel, linux-kernel; +Cc: linux-mips, Fuxin Zhang

On Sun, Apr 15, 2007 at 11:26:05PM +0800, tiansm@lemote.com wrote:

(Adding a few more people to the cc'list)

>  sound/core/pcm_native.c |   10 ++++++++++
>  sound/core/sgbuf.c      |    9 +++++++++
>  2 files changed, 19 insertions(+), 0 deletions(-)
> 
> diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
> index 3e276fc..9005bac 100644
> --- a/sound/core/pcm_native.c
> +++ b/sound/core/pcm_native.c
> @@ -3145,7 +3145,11 @@ static struct page *snd_pcm_mmap_data_nopage(struct vm_area_struct *area,
>  			return NOPAGE_OOM; /* XXX: is this really due to OOM? */
>  	} else {
>  		vaddr = runtime->dma_area + offset;
> +#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)

Please use CONFIG_MIPS instead of __mips__ in #if / #ifdefs.

The question if #ifdefing is the right approach to solve this problem is
something else but I think no, ....

> +		page = virt_to_page(CAC_ADDR(vaddr));
> +#else
>  		page = virt_to_page(vaddr);
> +#endif

So this is needed because the MIPS virt_to_page is returning a unsuitable
value if vaddress is not a KSEG0 (64-bit: cached XKPHYS) address which is
what GFP allocations and the slab will return.  So now we have to deciede
if

 a) the MIPS __pa() should be changed to handle uncached addresses.
 b) the sound code here is simply broken.

Some drivers seem to allocate runtime->dma_area from vmalloc, so this
whole area in the sound code is looking like built on quicksand ...

>  	}
>  	get_page(page);
>  	if (type)
> @@ -3261,6 +3265,12 @@ static int snd_pcm_mmap(struct file *file, struct vm_area_struct *area)
>  	substream = pcm_file->substream;
>  	snd_assert(substream != NULL, return -ENXIO);
>  
> +#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)
> +	/* all mmap using uncached mode */
> +	area->vm_page_prot = pgprot_noncached(area->vm_page_prot);
> +	area->vm_flags |= ( VM_RESERVED | VM_IO);

VM_RESERVED will prevent the buffer from being freed.  I assume that is
another workaround for some kernel subsystem blowing up when being fed a
pointer to an uncached RAM address?  This smells like a memory leak.

> +#endif
> +
>  	offset = area->vm_pgoff << PAGE_SHIFT;
>  	switch (offset) {
>  	case SNDRV_PCM_MMAP_OFFSET_STATUS:
> diff --git a/sound/core/sgbuf.c b/sound/core/sgbuf.c
> index cefd228..535f0bc 100644
> --- a/sound/core/sgbuf.c
> +++ b/sound/core/sgbuf.c
> @@ -91,12 +91,21 @@ void *snd_malloc_sgbuf_pages(struct device *device,
>  		}
>  		sgbuf->table[i].buf = tmpb.area;
>  		sgbuf->table[i].addr = tmpb.addr;
> +#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)
> +		sgbuf->page_table[i] = virt_to_page(CAC_ADDR(tmpb.area));

VM_RESERVED will prevent the buffer from being freed.  I assume that is
another workaround for some kernel subsystem blowing up when being fed a
pointer to an uncached RAM address?  This smells like a memory leak.

> +#else
>  		sgbuf->page_table[i] = virt_to_page(tmpb.area);
> +#endif
>  		sgbuf->pages++;
>  	}
>  
>  	sgbuf->size = size;
> +#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)
> +	/* maybe we should use uncached accelerated mode */
> +	dmab->area = vmap(sgbuf->page_table, sgbuf->pages, VM_MAP | VM_IO, pgprot_noncached(PAGE_KERNEL));
> +#else
>  	dmab->area = vmap(sgbuf->page_table, sgbuf->pages, VM_MAP, PAGE_KERNEL);
> +#endif

I would suggest to get rid of this ifdef with a new arch-specific function
like vmap_io_buffer which will do whatever a platform seems fit for this
case?

>  	if (! dmab->area)
>  		goto _failed;
>  	return dmab->area;

  Ralf

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

* Re: [PATCH 16/16] alsa sound support for mips
  2007-04-18 13:54                                 ` Ralf Baechle
@ 2007-04-18 14:13                                   ` Fuxin Zhang
  2007-04-20  9:39                                     ` Atsushi Nemoto
  0 siblings, 1 reply; 5+ messages in thread
From: Fuxin Zhang @ 2007-04-18 14:13 UTC (permalink / raw)
  To: Ralf Baechle
  Cc: tiansm, perex, alsa-devel, linux-kernel, linux-mips, Fuxin Zhang


>>  		vaddr = runtime->dma_area + offset;
>> +#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)
>>     
>
> Please use CONFIG_MIPS instead of __mips__ in #if / #ifdefs.
>
> The question if #ifdefing is the right approach to solve this problem is
> something else but I think no, ....
>   
I would agree that it is quite ugly, but changing virt_to_page for it 
does not seem right either.
>   
>> +		page = virt_to_page(CAC_ADDR(vaddr));
>> +#else
>>  		page = virt_to_page(vaddr);
>> +#endif
>>     
>
> So this is needed because the MIPS virt_to_page is returning a unsuitable
> value if vaddress is not a KSEG0 (64-bit: cached XKPHYS) address which is
> what GFP allocations and the slab will return.  So now we have to deciede
> if
>
>  a) the MIPS __pa() should be changed to handle uncached addresses.
>  b) the sound code here is simply broken.
>
> Some drivers seem to allocate runtime->dma_area from vmalloc, so this
> whole area in the sound code is looking like built on quicksand ...
>   
>> +#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)
>> +	/* all mmap using uncached mode */
>> +	area->vm_page_prot = pgprot_noncached(area->vm_page_prot);
>> +	area->vm_flags |= ( VM_RESERVED | VM_IO);
>>     
>
> VM_RESERVED will prevent the buffer from being freed.  I assume that is
> another workaround for some kernel subsystem blowing up when being fed a
> pointer to an uncached RAM address?  This smells like a memory leak.
>
>   
Oh, VM_RESERVED should be a memory leak problem, we can remove it.
I don't remember any case of other subsystem's problem, just did not 
think much
to add those flags.
>> +#endif
>> +
>>  	offset = area->vm_pgoff << PAGE_SHIFT;
>>  	switch (offset) {
>>  	case SNDRV_PCM_MMAP_OFFSET_STATUS:
>> diff --git a/sound/core/sgbuf.c b/sound/core/sgbuf.c
>> index cefd228..535f0bc 100644
>> --- a/sound/core/sgbuf.c
>> +++ b/sound/core/sgbuf.c
>> @@ -91,12 +91,21 @@ void *snd_malloc_sgbuf_pages(struct device *device,
>>  		}
>>  		sgbuf->table[i].buf = tmpb.area;
>>  		sgbuf->table[i].addr = tmpb.addr;
>> +#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)
>> +		sgbuf->page_table[i] = virt_to_page(CAC_ADDR(tmpb.area));
>>     
>
> VM_RESERVED will prevent the buffer from being freed.  I assume that is
> another workaround for some kernel subsystem blowing up when being fed a
> pointer to an uncached RAM address?  This smells like a memory leak.
>
>   
>> +#else
>>  		sgbuf->page_table[i] = virt_to_page(tmpb.area);
>> +#endif
>>  		sgbuf->pages++;
>>  	}
>>  
>>  	sgbuf->size = size;
>> +#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)
>> +	/* maybe we should use uncached accelerated mode */
>> +	dmab->area = vmap(sgbuf->page_table, sgbuf->pages, VM_MAP | VM_IO, pgprot_noncached(PAGE_KERNEL));
>> +#else
>>  	dmab->area = vmap(sgbuf->page_table, sgbuf->pages, VM_MAP, PAGE_KERNEL);
>> +#endif
>>     
>
> I would suggest to get rid of this ifdef with a new arch-specific function
> like vmap_io_buffer which will do whatever a platform seems fit for this
> case?
>   
I think arch-specific function is the correct way, but don't know what 
the alsa gods think.
>   
>>  	if (! dmab->area)
>>  		goto _failed;
>>  	return dmab->area;
>>     
>
>   Ralf
>
>
>
>
>   

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

* Re: [PATCH 16/16] alsa sound support for mips
  2007-04-18 14:13                                   ` Fuxin Zhang
@ 2007-04-20  9:39                                     ` Atsushi Nemoto
  0 siblings, 0 replies; 5+ messages in thread
From: Atsushi Nemoto @ 2007-04-20  9:39 UTC (permalink / raw)
  To: fxzhang; +Cc: ralf, tiansm, perex, alsa-devel, linux-kernel, linux-mips,
	zhangfx

On Wed, 18 Apr 2007 22:13:02 +0800, Fuxin Zhang <fxzhang@ict.ac.cn> wrote:
> >> +#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)
> >> +	/* all mmap using uncached mode */
> >> +	area->vm_page_prot = pgprot_noncached(area->vm_page_prot);
> >> +	area->vm_flags |= ( VM_RESERVED | VM_IO);
> >>     
> >
> > VM_RESERVED will prevent the buffer from being freed.  I assume that is
> > another workaround for some kernel subsystem blowing up when being fed a
> > pointer to an uncached RAM address?  This smells like a memory leak.
> >
> >   
> Oh, VM_RESERVED should be a memory leak problem, we can remove it.
> I don't remember any case of other subsystem's problem, just did not 
> think much
> to add those flags.

I think pgprot_noncached() is needed because user mapping for a DMA
buffer (runtime->dma_area) should be uncache.  If so, doing this in
snd_pcm_mmap() looks a bit suspicious.  It seems snd_pcm_mmap_data()
is a place to do such an adjustment.  But for now, both
snd_pcm_mmap_status() and snd_pcm_mmap_control() returns -ENXIO for
MIPS so this is not a real problem.

And I wonder if VM_IO is really needed.  The area is a DMA buffer,
_not_ a memory mapped IO area, isn't it?

> > I would suggest to get rid of this ifdef with a new arch-specific function
> > like vmap_io_buffer which will do whatever a platform seems fit for this
> > case?
> >   
> I think arch-specific function is the correct way, but don't know what 
> the alsa gods think.

JFYI, there were some discussions on this topic a while ago:

http://lkml.org/lkml/2006/1/25/117

and I'v seen MIPS version of dma_mmap_coherent(), etc. somewhere...

---
Atsushi Nemoto

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

end of thread, other threads:[~2007-04-20  9:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-04 14:38 [PATCH 16/16] alsa sound support for mips zhangfx
  -- strict thread matches above, loose matches on Subject: below --
2007-04-15 15:25 lemote-fulong patch update tiansm
2007-04-15 15:25 ` [PATCH 1/16] new files for lemote fulong mini-PC support tiansm
2007-04-15 15:25   ` [PATCH 2/16] arch related Makefile update for lemote fulong mini-PC tiansm
2007-04-15 15:25     ` [PATCH 3/16] Kconfig " tiansm
2007-04-15 15:25       ` [PATCH 4/16] TO_PHYS_MASK for loongson2 tiansm
2007-04-15 15:25         ` [PATCH 5/16] add MACH_GROUP_LEMOTE & MACH_LEMOTE_FULONG tiansm
2007-04-15 15:25           ` [PATCH 6/16] define Hit_Invalidate_I to Index_Invalidate_I for loongson2 tiansm
2007-04-15 15:25             ` [PATCH 7/16] add Loongson processor definitions tiansm
2007-04-15 15:25               ` [PATCH 8/16] define MODULE_PROC_FAMILY for Loongson2 tiansm
2007-04-15 15:25                 ` [PATCH 9/16] add serial port definition for lemote fulong tiansm
2007-04-15 15:25                   ` [PATCH 10/16] make cpu_probe recognize Loongson2 tiansm
2007-04-15 15:26                     ` [PATCH 11/16] add Loongson support to /proc/cpuinfo tiansm
2007-04-15 15:26                       ` [PATCH 12/16] cheat for support of more than 256MB memory tiansm
2007-04-15 15:26                         ` [PATCH 13/16] define MODULE_PROC_FAMILY for Loongson2 tiansm
2007-04-15 15:26                           ` [PATCH 14/16] tlb handling support for Loongson2 processor tiansm
2007-04-15 15:26                             ` [PATCH 15/16] work around for more than 256MB memory support tiansm
2007-04-15 15:26                               ` [PATCH 16/16] alsa sound support for mips tiansm
2007-04-18 13:54                                 ` Ralf Baechle
2007-04-18 14:13                                   ` Fuxin Zhang
2007-04-20  9:39                                     ` Atsushi Nemoto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox