Received: from milmhbs1.lsil.com (147.145.21.209) by coscas01.lsi.com
 (172.21.36.60) with Microsoft SMTP Server id 8.1.393.1; Thu, 26 Nov 2009
 08:14:34 -0700
Received: from mail2.lsil.com (mail2.lsil.com [147.145.40.22])	by
 milmhbs1.lsil.com (8.12.11/8.12.11) with ESMTP id nAQFEYF7020525	for
 <andy.sharp@lsi.com>; Thu, 26 Nov 2009 07:14:34 -0800
Received: from psmtp.com (na3sys009amx252.postini.com [74.125.149.136])	by
 mail2.lsil.com (8.12.11/8.12.11) with SMTP id nAQFASgE006650	for
 <andy.sharp@lsi.com>; Thu, 26 Nov 2009 07:10:28 -0800 (PST)
Received: from source ([78.24.191.182]) by na3sys009amx252.postini.com
 ([74.125.148.14]) with SMTP;	Thu, 26 Nov 2009 09:14:33 CST
Received: from localhost.localdomain ([127.0.0.1]:39856 "EHLO
        eddie.linux-mips.org" rhost-flags-OK-OK-OK-FAIL)        by
 eddie.linux-mips.org with ESMTP id S1492899AbZKZPO3 (ORCPT
        <rfc822;andy.sharp@lsi.com>); Thu, 26 Nov 2009 16:14:29 +0100
Received: with ECARTIS (v1.0.0; list linux-mips); Thu, 26 Nov 2009 16:14:11
 +0100 (CET)
Received: from cantor2.suse.de ([195.135.220.15]:36324 "EHLO mx2.suse.de"
        rhost-flags-OK-OK-OK-OK) by eddie.linux-mips.org with ESMTP        id
 S1493715AbZKZPNo (ORCPT <rfc822;linux-mips@linux-mips.org>);        Thu, 26
 Nov 2009 16:13:44 +0100
Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.221.2])
        by mx2.suse.de (Postfix) with ESMTP id F17C3867E2;        Thu, 26 Nov
 2009 16:13:43 +0100 (CET)
From: Takashi Iwai <tiwai@suse.de>
To: "alsa-devel@alsa-project.org" <alsa-devel@alsa-project.org>
CC: Ralf Baechle <ralf@linux-mips.org>, Wu Zhangjin <wuzhangjin@gmail.com>,
	Thomas Bogendoerfer <tsbogend@alpha.franken.de>, "linux-mips@linux-mips.org"
	<linux-mips@linux-mips.org>, Benjamin Herrenschmidt
	<benh@kernel.crashing.org>, Kumar Gala <galak@gate.crashing.org>, Becky Bruce
	<beckyb@kernel.crashing.org>, Takashi Iwai <tiwai@suse.de>
Sender: "linux-mips-bounce@linux-mips.org" <linux-mips-bounce@linux-mips.org>
Date: Thu, 26 Nov 2009 08:13:04 -0700
Subject: [PATCH 1/5] ALSA: pcm - Use dma_mmap_coherent() if available
Thread-Topic: [PATCH 1/5] ALSA: pcm - Use dma_mmap_coherent() if available
Thread-Index: AcpuqylfZK0xnIsoQHCD1EnjNctFdA==
Message-ID: <1259248388-20095-2-git-send-email-tiwai@suse.de>
References: <1259248388-20095-1-git-send-email-tiwai@suse.de>
In-Reply-To: <1259248388-20095-1-git-send-email-tiwai@suse.de>
Accept-Language: en-US
Content-Language: en-US
X-MS-Exchange-Organization-AuthAs: Anonymous
X-MS-Exchange-Organization-AuthSource: coscas01.lsi.com
X-MS-Has-Attach:
X-Auto-Response-Suppress: All
X-MS-TNEF-Correlator:
x-scanned-by: MIMEDefang 2.39
errors-to: linux-mips-bounce@linux-mips.org
x-pstn-levels: (S:99.90000/99.90000 CV:99.9000 FC:95.5390 LC:95.5390
 R:95.9108 P:95.9108 M:97.0282 C:98.6951 )
x-pstn-settings: 3 (1.0000:1.0000) s cv gt3 gt2 gt1 r p m c 
x-pstn-addresses: from <tiwai@suse.de> [22/1] 
x-pstn-neptune: 0/0/0.00/0
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0

Use dma_mmap_coherent() for mmapping the buffers allocated via
dma_alloc_coherent() if available.  Currently, only ARM has this function,
so we do temporarily have an ifdef pcm_native.c.  This should be handled
better globally in future.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/core/pcm_native.c |   49 +++++++++++++++++++++++++++++++------------=
---
 1 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index ab73edf..f067c5b 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -26,6 +26,7 @@
 #include <linux/time.h>
 #include <linux/pm_qos_params.h>
 #include <linux/uio.h>
+#include <linux/dma-mapping.h>
 #include <sound/core.h>
 #include <sound/control.h>
 #include <sound/info.h>
@@ -3094,23 +3095,42 @@ static int snd_pcm_mmap_data_fault(struct vm_area_s=
truct *area,
 	return 0;
 }
=20
-static const struct vm_operations_struct snd_pcm_vm_ops_data =3D
-{
+static const struct vm_operations_struct snd_pcm_vm_ops_data =3D {
+	.open =3D		snd_pcm_mmap_data_open,
+	.close =3D	snd_pcm_mmap_data_close,
+};
+
+static const struct vm_operations_struct snd_pcm_vm_ops_data_fault =3D {
 	.open =3D		snd_pcm_mmap_data_open,
 	.close =3D	snd_pcm_mmap_data_close,
 	.fault =3D	snd_pcm_mmap_data_fault,
 };
=20
+#ifndef ARCH_HAS_DMA_MMAP_COHERENT
+/* This should be defined / handled globally! */
+#ifdef CONFIG_ARM
+#define ARCH_HAS_DMA_MMAP_COHERENT
+#endif
+#endif
+
 /*
  * mmap the DMA buffer on RAM
  */
 static int snd_pcm_default_mmap(struct snd_pcm_substream *substream,
 				struct vm_area_struct *area)
 {
-	area->vm_ops =3D &snd_pcm_vm_ops_data;
-	area->vm_private_data =3D substream;
 	area->vm_flags |=3D VM_RESERVED;
-	atomic_inc(&substream->mmap_count);
+#ifdef ARCH_HAS_DMA_MMAP_COHERENT
+	if (!substream->ops->page &&
+	    substream->dma_buffer.dev.type =3D=3D 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 /* ARCH_HAS_DMA_MMAP_COHERENT */
+	/* mmap with fault handler */
+	area->vm_ops =3D &snd_pcm_vm_ops_data_fault;
 	return 0;
 }
=20
@@ -3118,12 +3138,6 @@ static int snd_pcm_default_mmap(struct snd_pcm_subst=
ream *substream,
  * mmap the DMA buffer on I/O memory area
  */
 #if SNDRV_PCM_INFO_MMAP_IOMEM
-static const struct vm_operations_struct snd_pcm_vm_ops_data_mmio =3D
-{
-	.open =3D		snd_pcm_mmap_data_open,
-	.close =3D	snd_pcm_mmap_data_close,
-};
-
 int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream,
 			   struct vm_area_struct *area)
 {
@@ -3133,8 +3147,6 @@ int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *=
substream,
 #ifdef pgprot_noncached
 	area->vm_page_prot =3D pgprot_noncached(area->vm_page_prot);
 #endif
-	area->vm_ops =3D &snd_pcm_vm_ops_data_mmio;
-	area->vm_private_data =3D substream;
 	area->vm_flags |=3D VM_IO;
 	size =3D area->vm_end - area->vm_start;
 	offset =3D area->vm_pgoff << PAGE_SHIFT;
@@ -3142,7 +3154,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;
 }
=20
@@ -3159,6 +3170,7 @@ int snd_pcm_mmap_data(struct snd_pcm_substream *subst=
ream, struct file *file,
 	long size;
 	unsigned long offset;
 	size_t dma_bytes;
+	int err;
=20
 	if (substream->stream =3D=3D SNDRV_PCM_STREAM_PLAYBACK) {
 		if (!(area->vm_flags & (VM_WRITE|VM_READ)))
@@ -3183,10 +3195,15 @@ int snd_pcm_mmap_data(struct snd_pcm_substream *sub=
stream, struct file *file,
 	if (offset > dma_bytes - size)
 		return -EINVAL;
=20
+	area->vm_ops =3D &snd_pcm_vm_ops_data;
+	area->vm_private_data =3D substream;
 	if (substream->ops->mmap)
-		return substream->ops->mmap(substream, area);
+		err =3D substream->ops->mmap(substream, area);
 	else
-		return snd_pcm_default_mmap(substream, area);
+		err =3D snd_pcm_default_mmap(substream, area);
+	if (!err)
+		atomic_inc(&substream->mmap_count);
+	return err;
 }
=20
 EXPORT_SYMBOL(snd_pcm_mmap_data);
--=20
1.6.5.3


