From: Songmao Tian <tiansm@lemote.com>
To: Takashi Iwai <tiwai@suse.de>
Cc: linux-mips@linux-mips.org, Atsushi Nemoto <anemo@mba.ocn.ne.jp>,
alsa-devel@alsa-project.org, Dajie Tan <jiankemeng@gmail.com>,
greg@kroah.com
Subject: Re: ALSA on MIPS platform
Date: Fri, 03 Aug 2007 23:57:07 +0800 [thread overview]
Message-ID: <46B35053.8050307@lemote.com> (raw)
In-Reply-To: <s5habt8ra5l.wl%tiwai@suse.de>
Takashi Iwai wrote:
> At Fri, 03 Aug 2007 21:50:36 +0800,
> Songmao Tian wrote:
>
>> Atsushi Nemoto wrote:
>>
>>> On Wed, 01 Aug 2007 15:56:48 +0800, Songmao Tian <tiansm@lemote.com> wrote:
>>>
>>>
>>>> The problem is clear:
>>>> 1. dma_alloc_noncoherent() return a non-cached address, and
>>>> virt_to_page() need a cached logical addr (Have I named it right?)
>>>> 2. mmaped dam buffer should be non-cached.
>>>>
>>>> We have a ugly patch, but we want to solve the problem cleanly, so can
>>>> anyone show me the way?
>>>>
>>>>
>>> virt_to_page() is used in many place in mm so making it robust might
>>> affect performance. IMHO virt_to_page() seems too low-level as DMA
>>> API.
>>>
>>> If something like dma_virt_to_page(dev, cpu_addr) which can take a cpu
>>> address returned by dma_xxx APIs was defined, MIPS can implement it
>>> appropriately.
>>>
>>> And then pgprot_noncached issues still exist...
>>>
>>> ---
>>> Atsushi Nemoto
>>>
>>>
>>>
>>>
>>>
>> I agree, and I am investigating to implement a dma_map_coherent, but It
>> seems dma_map_coherent doesn't solve all the problem and will change a
>> lot of code:(
>>
>
> It won't be that much. You'll need to change snd_pcm_default_mmap()
> in sound/core/pcm_native.c to call dma_mmap_coherent() directly
> instead of nopage ops. But, this won't work with SG-buffers, which
> requires some more additional works.
>
>
> Takashi
> _______________________________________________
> Alsa-devel mailing list
> Alsa-devel@alsa-project.org
> http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
>
>
>
I have no idea if the patch can work, the idea is not very clear now.
And I use vt686b ac97 sound driver, the driver use sgbuf, so I will
write a test program tomorrow. Good sleep...:)
And if any of you can take some time look into the patch, and give some
review will be appreciated:)
diff --git a/arch/mips/mm/dma-default.c b/arch/mips/mm/dma-default.c
index 76903c7..f088a6b 100644
--- a/arch/mips/mm/dma-default.c
+++ b/arch/mips/mm/dma-default.c
@@ -369,3 +369,23 @@ void dma_cache_sync(struct device *dev, void
*vaddr, size_t size,
}
EXPORT_SYMBOL(dma_cache_sync);
+
+static int dma_mmap(struct device *dev, struct vm_area_struct *vma,
+ void *cpu_addr, dma_addr_t dma_addr, size_t size)
+{
+ if (remap_pfn_range(vma, vma->vm_start,
+ PFN_DOWN(virt_to_phys(CAC_ADDR(cpu_addr))) +
vma->vm_pgoff,
+ vma->vm_end - vma->vm_start,
+ vma->vm_page_prot))
+ return -EAGAIN;
+ return 0;
+}
+
+int dma_mmap_coherent(struct device *dev, struct vm_area_struct *vma,
+ void *cpu_addr, dma_addr_t dma_addr, size_t size)
+{
+ vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+ return dma_mmap(dev, vma, cpu_addr, dma_addr, size);
+}
+EXPORT_SYMBOL(dma_mmap_coherent);
+
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 59b29cd..af82a3b 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -3152,6 +3152,8 @@ static struct vm_operations_struct
snd_pcm_vm_ops_data =
.close = snd_pcm_mmap_data_close,
.nopage = snd_pcm_mmap_data_nopage,
};
+int dma_mmap_coherent(struct device *dev, struct vm_area_struct *vma,
+ void *cpu_addr, dma_addr_t dma_addr, size_t size);
/*
* mmap the DMA buffer on RAM
@@ -3159,9 +3161,10 @@ static struct vm_operations_struct
snd_pcm_vm_ops_data =
static int snd_pcm_default_mmap(struct snd_pcm_substream *substream,
struct vm_area_struct *area)
{
- area->vm_ops = &snd_pcm_vm_ops_data;
+ struct snd_pcm_runtime *runtime = substream->runtime;
area->vm_private_data = substream;
- area->vm_flags |= VM_RESERVED;
+ dma_mmap_coherent(NULL, area, runtime->dma_area,
+ runtime->dma_addr, runtime->dma_bytes);
atomic_inc(&substream->mmap_count);
return 0;
}
WARNING: multiple messages have this Message-ID (diff)
From: Songmao Tian <tiansm@lemote.com>
To: Takashi Iwai <tiwai@suse.de>
Cc: linux-mips@linux-mips.org, Atsushi Nemoto <anemo@mba.ocn.ne.jp>,
alsa-devel@alsa-project.org, Dajie Tan <jiankemeng@gmail.com>,
greg@kroah.com
Subject: Re: [alsa-devel] ALSA on MIPS platform
Date: Fri, 03 Aug 2007 23:57:07 +0800 [thread overview]
Message-ID: <46B35053.8050307@lemote.com> (raw)
In-Reply-To: <s5habt8ra5l.wl%tiwai@suse.de>
Takashi Iwai wrote:
> At Fri, 03 Aug 2007 21:50:36 +0800,
> Songmao Tian wrote:
>
>> Atsushi Nemoto wrote:
>>
>>> On Wed, 01 Aug 2007 15:56:48 +0800, Songmao Tian <tiansm@lemote.com> wrote:
>>>
>>>
>>>> The problem is clear:
>>>> 1. dma_alloc_noncoherent() return a non-cached address, and
>>>> virt_to_page() need a cached logical addr (Have I named it right?)
>>>> 2. mmaped dam buffer should be non-cached.
>>>>
>>>> We have a ugly patch, but we want to solve the problem cleanly, so can
>>>> anyone show me the way?
>>>>
>>>>
>>> virt_to_page() is used in many place in mm so making it robust might
>>> affect performance. IMHO virt_to_page() seems too low-level as DMA
>>> API.
>>>
>>> If something like dma_virt_to_page(dev, cpu_addr) which can take a cpu
>>> address returned by dma_xxx APIs was defined, MIPS can implement it
>>> appropriately.
>>>
>>> And then pgprot_noncached issues still exist...
>>>
>>> ---
>>> Atsushi Nemoto
>>>
>>>
>>>
>>>
>>>
>> I agree, and I am investigating to implement a dma_map_coherent, but It
>> seems dma_map_coherent doesn't solve all the problem and will change a
>> lot of code:(
>>
>
> It won't be that much. You'll need to change snd_pcm_default_mmap()
> in sound/core/pcm_native.c to call dma_mmap_coherent() directly
> instead of nopage ops. But, this won't work with SG-buffers, which
> requires some more additional works.
>
>
> Takashi
> _______________________________________________
> Alsa-devel mailing list
> Alsa-devel@alsa-project.org
> http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
>
>
>
I have no idea if the patch can work, the idea is not very clear now.
And I use vt686b ac97 sound driver, the driver use sgbuf, so I will
write a test program tomorrow. Good sleep...:)
And if any of you can take some time look into the patch, and give some
review will be appreciated:)
diff --git a/arch/mips/mm/dma-default.c b/arch/mips/mm/dma-default.c
index 76903c7..f088a6b 100644
--- a/arch/mips/mm/dma-default.c
+++ b/arch/mips/mm/dma-default.c
@@ -369,3 +369,23 @@ void dma_cache_sync(struct device *dev, void
*vaddr, size_t size,
}
EXPORT_SYMBOL(dma_cache_sync);
+
+static int dma_mmap(struct device *dev, struct vm_area_struct *vma,
+ void *cpu_addr, dma_addr_t dma_addr, size_t size)
+{
+ if (remap_pfn_range(vma, vma->vm_start,
+ PFN_DOWN(virt_to_phys(CAC_ADDR(cpu_addr))) +
vma->vm_pgoff,
+ vma->vm_end - vma->vm_start,
+ vma->vm_page_prot))
+ return -EAGAIN;
+ return 0;
+}
+
+int dma_mmap_coherent(struct device *dev, struct vm_area_struct *vma,
+ void *cpu_addr, dma_addr_t dma_addr, size_t size)
+{
+ vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+ return dma_mmap(dev, vma, cpu_addr, dma_addr, size);
+}
+EXPORT_SYMBOL(dma_mmap_coherent);
+
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 59b29cd..af82a3b 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -3152,6 +3152,8 @@ static struct vm_operations_struct
snd_pcm_vm_ops_data =
.close = snd_pcm_mmap_data_close,
.nopage = snd_pcm_mmap_data_nopage,
};
+int dma_mmap_coherent(struct device *dev, struct vm_area_struct *vma,
+ void *cpu_addr, dma_addr_t dma_addr, size_t size);
/*
* mmap the DMA buffer on RAM
@@ -3159,9 +3161,10 @@ static struct vm_operations_struct
snd_pcm_vm_ops_data =
static int snd_pcm_default_mmap(struct snd_pcm_substream *substream,
struct vm_area_struct *area)
{
- area->vm_ops = &snd_pcm_vm_ops_data;
+ struct snd_pcm_runtime *runtime = substream->runtime;
area->vm_private_data = substream;
- area->vm_flags |= VM_RESERVED;
+ dma_mmap_coherent(NULL, area, runtime->dma_area,
+ runtime->dma_addr, runtime->dma_bytes);
atomic_inc(&substream->mmap_count);
return 0;
}
next prev parent reply other threads:[~2007-08-03 15:57 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-01 7:56 ALSA on MIPS platform Songmao Tian
2007-08-02 14:56 ` Atsushi Nemoto
2007-08-03 13:50 ` Songmao Tian
2007-08-03 13:50 ` Songmao Tian
2007-08-03 13:59 ` Takashi Iwai
2007-08-03 13:59 ` [alsa-devel] " Takashi Iwai
2007-08-03 15:57 ` Songmao Tian [this message]
2007-08-03 15:57 ` Songmao Tian
2007-08-06 12:17 ` Takashi Iwai
2007-08-06 12:17 ` [alsa-devel] " Takashi Iwai
2007-08-07 5:53 ` Dajie Tan
2007-08-07 6:18 ` Dajie Tan
2007-08-07 14:01 ` Atsushi Nemoto
2007-08-07 17:54 ` Ralf Baechle
2007-08-07 17:54 ` Ralf Baechle
2007-08-07 18:41 ` Takashi Iwai
2007-08-07 18:41 ` Takashi Iwai
2007-08-08 11:58 ` Ralf Baechle
2007-08-08 11:58 ` Ralf Baechle
2007-08-08 12:40 ` Maciej W. Rozycki
2007-08-08 12:57 ` Takashi Iwai
2007-08-08 12:57 ` Takashi Iwai
2007-08-09 1:24 ` Songmao Tian
2007-08-09 1:24 ` Songmao Tian
2007-08-08 0:40 ` Songmao Tian
2007-08-08 0:40 ` [alsa-devel] " Songmao Tian
-- strict thread matches above, loose matches on Subject: below --
2006-01-25 14:50 Atsushi Nemoto
2006-01-25 19:03 ` Takashi Iwai
2006-01-26 15:29 ` Atsushi Nemoto
2006-01-26 16:02 ` Takashi Iwai
2006-01-26 19:19 ` Hugh Dickins
2006-01-27 15:45 ` Atsushi Nemoto
2006-01-27 15:49 ` Martin Michlmayr
2006-01-27 16:01 ` Takashi Iwai
2006-01-27 15:57 ` Takashi Iwai
2006-01-30 9:56 ` Atsushi Nemoto
2006-01-30 10:18 ` Takashi Iwai
2006-01-30 10:38 ` Atsushi Nemoto
2006-01-30 12:25 ` Ralf Baechle
2006-01-30 15:46 ` Martin Michlmayr
2006-01-30 15:52 ` Takashi Iwai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=46B35053.8050307@lemote.com \
--to=tiansm@lemote.com \
--cc=alsa-devel@alsa-project.org \
--cc=anemo@mba.ocn.ne.jp \
--cc=greg@kroah.com \
--cc=jiankemeng@gmail.com \
--cc=linux-mips@linux-mips.org \
--cc=tiwai@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.