linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: benh@kernel.crashing.org
Cc: cjg@cruxppc.org, linuxppc-dev@ozlabs.org
Subject: [PATCH 2/3] ALSA: Fix mapping of DMA buffers
Date: Wed, 18 Jun 2008 12:41:45 +0200	[thread overview]
Message-ID: <s5hy753auty.wl%tiwai@suse.de> (raw)
In-Reply-To: s5h1w2vc9js.wl%tiwai@suse.de

The DMA buffers allocated via dma_alloc_coherent() aren't easily mmappable
for many architectures.  This is a quick fix for some known archs that
don't work properly with the current code.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/core/Kconfig      |    7 +++++++
 sound/core/pcm_native.c |   42 ++++++++++++++++++++++++++++--------------
 2 files changed, 35 insertions(+), 14 deletions(-)

diff --git a/sound/core/Kconfig b/sound/core/Kconfig
index 335d45e..8e4e644 100644
--- a/sound/core/Kconfig
+++ b/sound/core/Kconfig
@@ -174,3 +174,10 @@ config SND_PCM_XRUN_DEBUG
 
 config SND_VMASTER
 	bool
+
+config SND_COHERENT_DMA
+	def_bool y
+	depends on !PPC32 || !NOT_COHERENT_CACHE
+	depends on !ARM
+	depends on !MIPS
+	depends on !PARISC
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 61f5d42..e21ad2f 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -3124,6 +3124,12 @@ static struct vm_operations_struct snd_pcm_vm_ops_data =
 {
 	.open =		snd_pcm_mmap_data_open,
 	.close =	snd_pcm_mmap_data_close,
+};
+
+static struct vm_operations_struct snd_pcm_vm_ops_data_fault =
+{
+	.open =		snd_pcm_mmap_data_open,
+	.close =	snd_pcm_mmap_data_close,
 	.fault =	snd_pcm_mmap_data_fault,
 };
 
@@ -3133,10 +3139,21 @@ 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;
-	area->vm_private_data = substream;
 	area->vm_flags |= VM_RESERVED;
-	atomic_inc(&substream->mmap_count);
+#ifndef CONFIG_SND_COHERENT_DMA
+	if (!substream->ops->page) {
+		switch (substream->dma_buffer.dev.type) {
+		case SNDRV_DMA_TYPE_DEV:
+			return dma_mmap_coherent(substream->dma_buffer.dev.dev,
+						 area,
+						 substream->runtime->dma_area,
+						 substream->runtime->dma_addr,
+						 area->vm_end - area->vm_start);
+		}
+	}
+#endif /* !CONFIG_SND_COHERNT_DMA */
+	/* mmap with fault handler */
+	area->vm_ops = &snd_pcm_vm_ops_data_fault;
 	return 0;
 }
 
@@ -3144,12 +3161,6 @@ static int snd_pcm_default_mmap(struct snd_pcm_substream *substream,
  * mmap the DMA buffer on I/O memory area
  */
 #if SNDRV_PCM_INFO_MMAP_IOMEM
-static struct vm_operations_struct snd_pcm_vm_ops_data_mmio =
-{
-	.open =		snd_pcm_mmap_data_open,
-	.close =	snd_pcm_mmap_data_close,
-};
-
 int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream,
 			   struct vm_area_struct *area)
 {
@@ -3159,8 +3170,6 @@ int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream,
 #ifdef pgprot_noncached
 	area->vm_page_prot = pgprot_noncached(area->vm_page_prot);
 #endif
-	area->vm_ops = &snd_pcm_vm_ops_data_mmio;
-	area->vm_private_data = substream;
 	area->vm_flags |= VM_IO;
 	size = area->vm_end - area->vm_start;
 	offset = area->vm_pgoff << PAGE_SHIFT;
@@ -3168,7 +3177,6 @@ int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream,
 				(substream->runtime->dma_addr + offset) >> PAGE_SHIFT,
 				size, area->vm_page_prot))
 		return -EAGAIN;
-	atomic_inc(&substream->mmap_count);
 	return 0;
 }
 
@@ -3185,6 +3193,7 @@ int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file,
 	long size;
 	unsigned long offset;
 	size_t dma_bytes;
+	int err;
 
 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
 		if (!(area->vm_flags & (VM_WRITE|VM_READ)))
@@ -3210,10 +3219,15 @@ int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file,
 	if (offset > dma_bytes - size)
 		return -EINVAL;
 
+	area->vm_ops = &snd_pcm_vm_ops_data;
+	area->vm_private_data = substream;
 	if (substream->ops->mmap)
-		return substream->ops->mmap(substream, area);
+		err = substream->ops->mmap(substream, area);
 	else
-		return snd_pcm_default_mmap(substream, area);
+		err = snd_pcm_default_mmap(substream, area);
+	if (!err)
+		atomic_inc(&substream->mmap_count);
+	return err;
 }
 
 EXPORT_SYMBOL(snd_pcm_mmap_data);
-- 
1.5.4.5

  parent reply	other threads:[~2008-06-18 10:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-18 10:38 [PATCH 0/3] ALSA fixes for non-coherent ppc32 Takashi Iwai
2008-06-18 10:40 ` [PATCH 1/3] ppc: Add dma_mmap_coherent() for PPC32 Takashi Iwai
2008-06-18 10:41 ` Takashi Iwai [this message]
2008-06-18 10:42 ` [PATCH 3/3] ALSA: Fix SG-buffer DMA with non-coherent architectures Takashi Iwai
2008-07-09  8:31 ` [PATCH 0/3] ALSA fixes for non-coherent ppc32 Gerhard Pircher
2008-07-09  8:55   ` Benjamin Herrenschmidt
2008-07-09 17:31     ` Takashi Iwai
2008-07-09 20:06       ` Benjamin Herrenschmidt
2008-07-09 17:27   ` 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=s5hy753auty.wl%tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=benh@kernel.crashing.org \
    --cc=cjg@cruxppc.org \
    --cc=linuxppc-dev@ozlabs.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).