From: Paul Mundt <lethal@linux-sh.org>
To: Takashi Iwai <tiwai@suse.de>
Cc: Pawel MOLL <pawel.moll@st.com>,
alsa-devel@alsa-project.org, linux-sh@vger.kernel.org
Subject: Re: [alsa-devel] Audio buffer mmap-ing on sh arch vs. cache aliasing problem
Date: Sun, 21 Sep 2008 10:13:10 +0900 [thread overview]
Message-ID: <20080921011310.GB2522@linux-sh.org> (raw)
In-Reply-To: <s5h63owgdk1.wl%tiwai@suse.de>
On Tue, Sep 16, 2008 at 08:18:06PM +0200, Takashi Iwai wrote:
> At Thu, 04 Sep 2008 12:23:54 +0100,
> Pawel MOLL wrote:
> > As a quick-and-dirty work-around I have modified
> > snd_pcm_alloc_vmalloc_buffer() to allocate always 12kB more and then use
> > 16k-aligned pointer:
> >
> > static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs, size_t size)
> > {
> > struct snd_pcm_runtime *runtime = subs->runtime;
> > if (runtime->dma_addr) {
> > if (runtime->dma_bytes >= size)
> > return 0; /* already large enough */
> > vfree((void *)runtime->dma_addr);
> > }
> > runtime->dma_addr = (unsigned long)vmalloc(size + 12 * 1024);
> > if (!runtime->dma_addr)
> > return -ENOMEM;
> > runtime->dma_area = (void *)ALIGN(runtime->dma_addr, 16 * 1024);
> > runtime->dma_bytes = size;
> > return 0;
> > }
> >
> > Of course it cannot be regarded as anything more as a hack. And
> > definitely not as a solution... So my question is:
> >
> > Any idea how the "proper solution" should look like? I see no obvious
> > method to get an arch-independent "mmap-compliant" buffer. This problem
> > was found on a sh arch, using an USB Audio Class device, however out
> > there some other architectures are suffering from this MMU "feature" as
> > well (ie. see http://docs.hp.com/en/B3906-90006/ch07s09.html) and
> > possibly other drivers could behave "wrongly" (quoted as the driver is
> > actually innocent...)
>
> Currently, it's PITA on Linux to get a non-cached mmap properly in a
> generic way. Especially together with coherent memory allocations,
> there is no API for that. But, in the case of usb-audio, the problem
> is the vmaloc'ed intermediate buffer, and this could be a bit easier.
>
> One thing we can try is a patch like below. But, I'm not sure whether
> this is correct over all architectures, too. At best, a generic API
> would be helpful for such a thing...
>
pgprot_noncached() is the closest you will get to a generic API, but it's
true that not every architecture implements it. Given that, you will have
to toss up an #ifdef pgprot_noncached() around it, as seems to already be
the case for snd_pcm_lib_mmap_iomem(). Any sane platform that has
problems in this regard will have to define pgprot_noncached(), and
that's already true for things like /dev/mem today.
WARNING: multiple messages have this Message-ID (diff)
From: Paul Mundt <lethal@linux-sh.org>
To: Takashi Iwai <tiwai@suse.de>
Cc: Pawel MOLL <pawel.moll@st.com>,
alsa-devel@alsa-project.org, linux-sh@vger.kernel.org
Subject: Re: [alsa-devel] Audio buffer mmap-ing on sh arch vs. cache aliasing problem
Date: Sun, 21 Sep 2008 01:13:10 +0000 [thread overview]
Message-ID: <20080921011310.GB2522@linux-sh.org> (raw)
In-Reply-To: <s5h63owgdk1.wl%tiwai@suse.de>
On Tue, Sep 16, 2008 at 08:18:06PM +0200, Takashi Iwai wrote:
> At Thu, 04 Sep 2008 12:23:54 +0100,
> Pawel MOLL wrote:
> > As a quick-and-dirty work-around I have modified
> > snd_pcm_alloc_vmalloc_buffer() to allocate always 12kB more and then use
> > 16k-aligned pointer:
> >
> > static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs, size_t size)
> > {
> > struct snd_pcm_runtime *runtime = subs->runtime;
> > if (runtime->dma_addr) {
> > if (runtime->dma_bytes >= size)
> > return 0; /* already large enough */
> > vfree((void *)runtime->dma_addr);
> > }
> > runtime->dma_addr = (unsigned long)vmalloc(size + 12 * 1024);
> > if (!runtime->dma_addr)
> > return -ENOMEM;
> > runtime->dma_area = (void *)ALIGN(runtime->dma_addr, 16 * 1024);
> > runtime->dma_bytes = size;
> > return 0;
> > }
> >
> > Of course it cannot be regarded as anything more as a hack. And
> > definitely not as a solution... So my question is:
> >
> > Any idea how the "proper solution" should look like? I see no obvious
> > method to get an arch-independent "mmap-compliant" buffer. This problem
> > was found on a sh arch, using an USB Audio Class device, however out
> > there some other architectures are suffering from this MMU "feature" as
> > well (ie. see http://docs.hp.com/en/B3906-90006/ch07s09.html) and
> > possibly other drivers could behave "wrongly" (quoted as the driver is
> > actually innocent...)
>
> Currently, it's PITA on Linux to get a non-cached mmap properly in a
> generic way. Especially together with coherent memory allocations,
> there is no API for that. But, in the case of usb-audio, the problem
> is the vmaloc'ed intermediate buffer, and this could be a bit easier.
>
> One thing we can try is a patch like below. But, I'm not sure whether
> this is correct over all architectures, too. At best, a generic API
> would be helpful for such a thing...
>
pgprot_noncached() is the closest you will get to a generic API, but it's
true that not every architecture implements it. Given that, you will have
to toss up an #ifdef pgprot_noncached() around it, as seems to already be
the case for snd_pcm_lib_mmap_iomem(). Any sane platform that has
problems in this regard will have to define pgprot_noncached(), and
that's already true for things like /dev/mem today.
next prev parent reply other threads:[~2008-09-21 1:13 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-04 11:23 Audio buffer mmap-ing on sh arch vs. cache aliasing problem Pawel MOLL
2008-09-04 11:23 ` Pawel MOLL
2008-09-16 18:18 ` [alsa-devel] " Takashi Iwai
2008-09-16 18:18 ` Takashi Iwai
2008-09-21 1:13 ` Paul Mundt [this message]
2008-09-21 1:13 ` Paul Mundt
2008-09-25 14:55 ` Pawel MOLL
2008-09-25 14:55 ` [alsa-devel] Audio buffer mmap-ing on sh arch vs. cache Pawel MOLL
2008-09-26 10:04 ` [alsa-devel] Audio buffer mmap-ing on sh arch vs. cache aliasing problem Takashi Iwai
2008-09-26 10:04 ` Takashi Iwai
2008-09-26 10:30 ` Paul Mundt
2008-09-26 10:30 ` [alsa-devel] " Paul Mundt
2008-09-26 11:04 ` Takashi Iwai
2008-09-26 11:04 ` Takashi Iwai
2008-09-26 11:25 ` Pawel MOLL
2008-09-26 11:25 ` [alsa-devel] Audio buffer mmap-ing on sh arch vs Pawel MOLL
2008-09-26 12:38 ` Audio buffer mmap-ing on sh arch vs. cache aliasing problem Takashi Iwai
2008-09-26 12:38 ` [alsa-devel] " Takashi Iwai
2010-01-15 0:04 ` Paul Mundt
2010-01-15 0:04 ` Paul Mundt
2010-01-16 10:05 ` Takashi Iwai
2010-01-16 10:05 ` Takashi Iwai
2010-01-16 10:20 ` Paul Mundt
2010-01-16 10:20 ` Paul Mundt
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=20080921011310.GB2522@linux-sh.org \
--to=lethal@linux-sh.org \
--cc=alsa-devel@alsa-project.org \
--cc=linux-sh@vger.kernel.org \
--cc=pawel.moll@st.com \
--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.