linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* dma_mmap_coherent / ARCH_HAS_DMA_MMAP_COHERENT
@ 2012-12-16 16:03 Geert Uytterhoeven
  2012-12-28 19:23 ` [PATCH/RFC 0/4] " Geert Uytterhoeven
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Geert Uytterhoeven @ 2012-12-16 16:03 UTC (permalink / raw)
  To: Linux-Arch; +Cc: linux-media, alsa-devel, linux-kernel

drivers/media/v4l2-core/videobuf2-dma-contig.c: In function ‘vb2_dc_mmap’:
drivers/media/v4l2-core/videobuf2-dma-contig.c:204: error: implicit
declaration of function ‘dma_mmap_coherent’
drivers/media/v4l2-core/videobuf2-dma-contig.c: In function
‘vb2_dc_get_base_sgt’:
drivers/media/v4l2-core/videobuf2-dma-contig.c:387: error: implicit
declaration of function ‘dma_get_sgtable’
make[6]: *** [drivers/media/v4l2-core/videobuf2-dma-contig.o] Error 1
make[6]: Target `__build' not remade because of errors.
make[5]: *** [drivers/media/v4l2-core] Error 2

Both dma_mmap_coherent() and dma_get_sgtable() are defined in
include/asm-generic/dma-mapping-common.h only, which is included by
<asm/dma-mapping.h> on alpha, arm, arm64, hexagon, ia64, microblaze, mips,
openrisc, powerpc, s390, sh, sparc, tile, unicore32, x86.
Should the remaining architectures include this, too?
Should it be moved to <linux/dma-mapping.h>?

Furthermore, there's ARCH_HAS_DMA_MMAP_COHERENT, which is defined
by powerpc only:
arch/powerpc/include/asm/dma-mapping.h:#define ARCH_HAS_DMA_MMAP_COHERENT

and handled in some fishy way in sound/core/pcm_native.c:

#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
 */
int snd_pcm_lib_default_mmap(struct snd_pcm_substream *substream,
                             struct vm_area_struct *area)
{
        area->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
#ifdef ARCH_HAS_DMA_MMAP_COHERENT
        if (!substream->ops->page &&
            substream->dma_buffer.dev.type == 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);
#elif defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT)
        if (substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV &&
            !plat_device_is_coherent(substream->dma_buffer.dev.dev))
                area->vm_page_prot = pgprot_noncached(area->vm_page_prot);
#endif /* ARCH_HAS_DMA_MMAP_COHERENT */
        /* mmap with fault handler */
        area->vm_ops = &snd_pcm_vm_ops_data_fault;
        return 0;
}
EXPORT_SYMBOL_GPL(snd_pcm_lib_default_mmap);

What's up here?

Thx!

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* [PATCH/RFC 0/4] Re: dma_mmap_coherent / ARCH_HAS_DMA_MMAP_COHERENT
  2012-12-16 16:03 dma_mmap_coherent / ARCH_HAS_DMA_MMAP_COHERENT Geert Uytterhoeven
@ 2012-12-28 19:23 ` Geert Uytterhoeven
  2013-01-02 14:39   ` Marek Szyprowski
  2012-12-28 19:23 ` [PATCH 1/4] m68k: Sort out !CONFIG_MMU_SUN3 vs. CONFIG_HAS_DMA Geert Uytterhoeven
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Geert Uytterhoeven @ 2012-12-28 19:23 UTC (permalink / raw)
  To: linux-arch, Marek Szyprowski, linux-kernel, linux-media; +Cc: linux-m68k

On Sun, Dec 16, 2012 at 5:03 PM, Geert Uytterhoeven <geert@linux-m68k.org>
wrote:
> drivers/media/v4l2-core/videobuf2-dma-contig.c: In function ‘vb2_dc_mmap’:
> drivers/media/v4l2-core/videobuf2-dma-contig.c:204: error: implicit declaration of function ‘dma_mmap_coherent’
> drivers/media/v4l2-core/videobuf2-dma-contig.c: In function ‘vb2_dc_get_base_sgt’:
> drivers/media/v4l2-core/videobuf2-dma-contig.c:387: error: implicit declaration of function ‘dma_get_sgtable’
> make[6]: *** [drivers/media/v4l2-core/videobuf2-dma-contig.o] Error 1
> make[6]: Target `__build' not remade because of errors.
> make[5]: *** [drivers/media/v4l2-core] Error 2
>
> Both dma_mmap_coherent() and dma_get_sgtable() are defined in
> include/asm-generic/dma-mapping-common.h only, which is included by
> <asm/dma-mapping.h> on alpha, arm, arm64, hexagon, ia64, microblaze, mips,
> openrisc, powerpc, s390, sh, sparc, tile, unicore32, x86.
> Should the remaining architectures include this, too?
> Should it be moved to <linux/dma-mapping.h>?

I came up with an RFC-solution for this in [PATCH/RFC 3/4]
("avr32/bfin/c6x/cris/frv/m68k/mn10300/parisc/xtensa: Add dummy get_dma_ops()")
and [PATCH/RFC 4/4] ("common: dma-mapping: Move dma_common_*() to
<linux/dma-mapping.h>") of this series.

> Furthermore, there's ARCH_HAS_DMA_MMAP_COHERENT, which is defined
> by powerpc only:
> arch/powerpc/include/asm/dma-mapping.h:#define ARCH_HAS_DMA_MMAP_COHERENT
>
> and handled in some fishy way in sound/core/pcm_native.c:
>
> #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
>  */
> int snd_pcm_lib_default_mmap(struct snd_pcm_substream *substream,
>                              struct vm_area_struct *area)
> {
>         area->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
> #ifdef ARCH_HAS_DMA_MMAP_COHERENT
>         if (!substream->ops->page &&
>             substream->dma_buffer.dev.type == 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);
> #elif defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT)
>         if (substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV &&
>             !plat_device_is_coherent(substream->dma_buffer.dev.dev))
>                 area->vm_page_prot = pgprot_noncached(area->vm_page_prot);
> #endif /* ARCH_HAS_DMA_MMAP_COHERENT */
>         /* mmap with fault handler */
>         area->vm_ops = &snd_pcm_vm_ops_data_fault;
>         return 0;
> }
> EXPORT_SYMBOL_GPL(snd_pcm_lib_default_mmap);
>
> What's up here?

Probably an easy solution here is to kill ARCH_HAS_DMA_MMAP_COHERENT and
change the code to

    #if defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT)
	    if (substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV &&
		!plat_device_is_coherent(substream->dma_buffer.dev.dev))
		    area->vm_page_prot = pgprot_noncached(area->vm_page_prot);
    #else
	    if (!substream->ops->page &&
		substream->dma_buffer.dev.type == 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

but obviously I don't like the test for CONFIG_MIPS in generic code...

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds


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

* [PATCH 1/4] m68k: Sort out !CONFIG_MMU_SUN3 vs. CONFIG_HAS_DMA
  2012-12-16 16:03 dma_mmap_coherent / ARCH_HAS_DMA_MMAP_COHERENT Geert Uytterhoeven
  2012-12-28 19:23 ` [PATCH/RFC 0/4] " Geert Uytterhoeven
@ 2012-12-28 19:23 ` Geert Uytterhoeven
  2012-12-28 19:23 ` [PATCH 2/4] score: Remove unneeded <asm/dma-mapping.h> Geert Uytterhoeven
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Geert Uytterhoeven @ 2012-12-28 19:23 UTC (permalink / raw)
  To: linux-arch, Marek Szyprowski, linux-kernel, linux-media
  Cc: linux-m68k, Geert Uytterhoeven

In two places, we check !CONFIG_MMU_SUN3 while we should check
CONFIG_HAS_DMA instead.
While fixing this, the check in <asm/dma-mapping.h> became redundant
(<linux/dma-mapping.h> already handles this case), so just remove it.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
 arch/m68k/include/asm/dma-mapping.h |    5 -----
 arch/m68k/kernel/Makefile           |    4 +---
 2 files changed, 1 insertions(+), 8 deletions(-)

diff --git a/arch/m68k/include/asm/dma-mapping.h b/arch/m68k/include/asm/dma-mapping.h
index 3e6b844..c68cdb4 100644
--- a/arch/m68k/include/asm/dma-mapping.h
+++ b/arch/m68k/include/asm/dma-mapping.h
@@ -5,7 +5,6 @@
 
 struct scatterlist;
 
-#ifndef CONFIG_MMU_SUN3
 static inline int dma_supported(struct device *dev, u64 mask)
 {
 	return 1;
@@ -111,8 +110,4 @@ static inline int dma_mapping_error(struct device *dev, dma_addr_t handle)
 	return 0;
 }
 
-#else
-#include <asm-generic/dma-mapping-broken.h>
-#endif
-
 #endif  /* _M68K_DMA_MAPPING_H */
diff --git a/arch/m68k/kernel/Makefile b/arch/m68k/kernel/Makefile
index 068ad49..655347d 100644
--- a/arch/m68k/kernel/Makefile
+++ b/arch/m68k/kernel/Makefile
@@ -20,7 +20,5 @@ obj-$(CONFIG_MMU_MOTOROLA) += ints.o vectors.o
 obj-$(CONFIG_MMU_SUN3) += ints.o vectors.o
 obj-$(CONFIG_PCI) += pcibios.o
 
-ifndef CONFIG_MMU_SUN3
-obj-y	+= dma.o
-endif
+obj-$(CONFIG_HAS_DMA)	+= dma.o
 
-- 
1.7.0.4


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

* [PATCH 2/4] score: Remove unneeded <asm/dma-mapping.h>
  2012-12-16 16:03 dma_mmap_coherent / ARCH_HAS_DMA_MMAP_COHERENT Geert Uytterhoeven
  2012-12-28 19:23 ` [PATCH/RFC 0/4] " Geert Uytterhoeven
  2012-12-28 19:23 ` [PATCH 1/4] m68k: Sort out !CONFIG_MMU_SUN3 vs. CONFIG_HAS_DMA Geert Uytterhoeven
@ 2012-12-28 19:23 ` Geert Uytterhoeven
  2012-12-28 19:23 ` [PATCH/RFC 3/4] avr32/bfin/c6x/cris/frv/m68k/mn10300/parisc/xtensa: Add dummy get_dma_ops() Geert Uytterhoeven
  2012-12-28 19:23 ` [PATCH/RFC 4/4] common: dma-mapping: Move dma_common_*() to <linux/dma-mapping.h> Geert Uytterhoeven
  4 siblings, 0 replies; 10+ messages in thread
From: Geert Uytterhoeven @ 2012-12-28 19:23 UTC (permalink / raw)
  To: linux-arch, Marek Szyprowski, linux-kernel, linux-media
  Cc: linux-m68k, Geert Uytterhoeven, Chen Liqin, Lennox Wu

It just includes <asm-generic/dma-mapping-broken.h>, which is already
handled by <linux/dma-mapping.h> for the !CONFIG_HAS_DMA case (score sets
CONFIG_NO_DMA=y).

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Chen Liqin <liqin.chen@sunplusct.com>
Cc: Lennox Wu <lennox.wu@gmail.com>
---
 arch/score/include/asm/dma-mapping.h |    6 ------
 1 files changed, 0 insertions(+), 6 deletions(-)
 delete mode 100644 arch/score/include/asm/dma-mapping.h

diff --git a/arch/score/include/asm/dma-mapping.h b/arch/score/include/asm/dma-mapping.h
deleted file mode 100644
index f9c0193..0000000
--- a/arch/score/include/asm/dma-mapping.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef _ASM_SCORE_DMA_MAPPING_H
-#define _ASM_SCORE_DMA_MAPPING_H
-
-#include <asm-generic/dma-mapping-broken.h>
-
-#endif /* _ASM_SCORE_DMA_MAPPING_H */
-- 
1.7.0.4


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

* [PATCH/RFC 3/4] avr32/bfin/c6x/cris/frv/m68k/mn10300/parisc/xtensa: Add dummy get_dma_ops()
  2012-12-16 16:03 dma_mmap_coherent / ARCH_HAS_DMA_MMAP_COHERENT Geert Uytterhoeven
                   ` (2 preceding siblings ...)
  2012-12-28 19:23 ` [PATCH 2/4] score: Remove unneeded <asm/dma-mapping.h> Geert Uytterhoeven
@ 2012-12-28 19:23 ` Geert Uytterhoeven
  2012-12-28 19:23 ` [PATCH/RFC 4/4] common: dma-mapping: Move dma_common_*() to <linux/dma-mapping.h> Geert Uytterhoeven
  4 siblings, 0 replies; 10+ messages in thread
From: Geert Uytterhoeven @ 2012-12-28 19:23 UTC (permalink / raw)
  To: linux-arch, Marek Szyprowski, linux-kernel, linux-media
  Cc: linux-m68k, Geert Uytterhoeven

Provide dummy versions of get_dma_ops(), as dma_mmap_attrs() and
dma_get_sgtable_attrs() (will) need these

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
 arch/avr32/include/asm/dma-mapping.h    |    8 ++++++++
 arch/blackfin/include/asm/dma-mapping.h |    8 ++++++++
 arch/c6x/include/asm/dma-mapping.h      |    8 ++++++++
 arch/cris/include/asm/dma-mapping.h     |    8 ++++++++
 arch/frv/include/asm/dma-mapping.h      |    8 ++++++++
 arch/m68k/include/asm/dma-mapping.h     |    8 ++++++++
 arch/mn10300/include/asm/dma-mapping.h  |    8 ++++++++
 arch/parisc/include/asm/dma-mapping.h   |    8 ++++++++
 arch/xtensa/include/asm/dma-mapping.h   |    8 ++++++++
 9 files changed, 72 insertions(+), 0 deletions(-)

diff --git a/arch/avr32/include/asm/dma-mapping.h b/arch/avr32/include/asm/dma-mapping.h
index aaf5199..de55309 100644
--- a/arch/avr32/include/asm/dma-mapping.h
+++ b/arch/avr32/include/asm/dma-mapping.h
@@ -8,6 +8,14 @@
 #include <asm/cacheflush.h>
 #include <asm/io.h>
 
+/*
+ *  Dummy to make dma_mmap_attrs()/dma_get_sgtable_attrs() happy
+ */
+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
+{
+	return NULL;
+}
+
 extern void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
 	int direction);
 
diff --git a/arch/blackfin/include/asm/dma-mapping.h b/arch/blackfin/include/asm/dma-mapping.h
index bbf4610..a2778b3 100644
--- a/arch/blackfin/include/asm/dma-mapping.h
+++ b/arch/blackfin/include/asm/dma-mapping.h
@@ -10,6 +10,14 @@
 #include <asm/cacheflush.h>
 struct scatterlist;
 
+/*
+ *  Dummy to make dma_mmap_attrs()/dma_get_sgtable_attrs() happy
+ */
+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
+{
+	return NULL;
+}
+
 void *dma_alloc_coherent(struct device *dev, size_t size,
 			 dma_addr_t *dma_handle, gfp_t gfp);
 void dma_free_coherent(struct device *dev, size_t size, void *vaddr,
diff --git a/arch/c6x/include/asm/dma-mapping.h b/arch/c6x/include/asm/dma-mapping.h
index 3c69406..5ae2f81 100644
--- a/arch/c6x/include/asm/dma-mapping.h
+++ b/arch/c6x/include/asm/dma-mapping.h
@@ -17,6 +17,14 @@
 
 #define dma_supported(d, m)	1
 
+/*
+ *  Dummy to make dma_mmap_attrs()/dma_get_sgtable_attrs() happy
+ */
+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
+{
+	return NULL;
+}
+
 static inline int dma_set_mask(struct device *dev, u64 dma_mask)
 {
 	if (!dev->dma_mask || !dma_supported(dev, dma_mask))
diff --git a/arch/cris/include/asm/dma-mapping.h b/arch/cris/include/asm/dma-mapping.h
index 8588b2c..05a55aa 100644
--- a/arch/cris/include/asm/dma-mapping.h
+++ b/arch/cris/include/asm/dma-mapping.h
@@ -10,6 +10,14 @@
 #include <asm/io.h>
 #include <asm/scatterlist.h>
 
+/*
+ *  Dummy to make dma_mmap_attrs()/dma_get_sgtable_attrs() happy
+ */
+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
+{
+	return NULL;
+}
+
 #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
 
diff --git a/arch/frv/include/asm/dma-mapping.h b/arch/frv/include/asm/dma-mapping.h
index dfb8110..862e9b8 100644
--- a/arch/frv/include/asm/dma-mapping.h
+++ b/arch/frv/include/asm/dma-mapping.h
@@ -12,6 +12,14 @@
  * following DMA API should work.
  */
 
+/*
+ *  Dummy to make dma_mmap_attrs()/dma_get_sgtable_attrs() happy
+ */
+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
+{
+	return NULL;
+}
+
 #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
 
diff --git a/arch/m68k/include/asm/dma-mapping.h b/arch/m68k/include/asm/dma-mapping.h
index c68cdb4..d8977f5 100644
--- a/arch/m68k/include/asm/dma-mapping.h
+++ b/arch/m68k/include/asm/dma-mapping.h
@@ -5,6 +5,14 @@
 
 struct scatterlist;
 
+/*
+ *  Dummy to make dma_mmap_attrs()/dma_get_sgtable_attrs() happy
+ */
+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
+{
+	return NULL;
+}
+
 static inline int dma_supported(struct device *dev, u64 mask)
 {
 	return 1;
diff --git a/arch/mn10300/include/asm/dma-mapping.h b/arch/mn10300/include/asm/dma-mapping.h
index c1be439..b0cea53 100644
--- a/arch/mn10300/include/asm/dma-mapping.h
+++ b/arch/mn10300/include/asm/dma-mapping.h
@@ -22,6 +22,14 @@
  * following DMA API should work.
  */
 
+/*
+ *  Dummy to make dma_mmap_attrs()/dma_get_sgtable_attrs() happy
+ */
+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
+{
+	return NULL;
+}
+
 extern void *dma_alloc_coherent(struct device *dev, size_t size,
 				dma_addr_t *dma_handle, int flag);
 
diff --git a/arch/parisc/include/asm/dma-mapping.h b/arch/parisc/include/asm/dma-mapping.h
index 467bbd5..cdd450f 100644
--- a/arch/parisc/include/asm/dma-mapping.h
+++ b/arch/parisc/include/asm/dma-mapping.h
@@ -46,6 +46,14 @@ extern struct hppa_dma_ops pcx_dma_ops;
 
 extern struct hppa_dma_ops *hppa_dma_ops;
 
+/*
+ *  Dummy to make dma_mmap_attrs()/dma_get_sgtable_attrs() happy
+ */
+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
+{
+	return NULL;
+}
+
 static inline void *
 dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
 		   gfp_t flag)
diff --git a/arch/xtensa/include/asm/dma-mapping.h b/arch/xtensa/include/asm/dma-mapping.h
index 4acb5fe..0061c2d 100644
--- a/arch/xtensa/include/asm/dma-mapping.h
+++ b/arch/xtensa/include/asm/dma-mapping.h
@@ -26,6 +26,14 @@ extern void *consistent_alloc(int, size_t, dma_addr_t, unsigned long);
 extern void consistent_free(void*, size_t, dma_addr_t);
 extern void consistent_sync(void*, size_t, int);
 
+/*
+ *  Dummy to make dma_mmap_attrs()/dma_get_sgtable_attrs() happy
+ */
+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
+{
+	return NULL;
+}
+
 #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
 
-- 
1.7.0.4


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

* [PATCH/RFC 4/4] common: dma-mapping: Move dma_common_*() to <linux/dma-mapping.h>
  2012-12-16 16:03 dma_mmap_coherent / ARCH_HAS_DMA_MMAP_COHERENT Geert Uytterhoeven
                   ` (3 preceding siblings ...)
  2012-12-28 19:23 ` [PATCH/RFC 3/4] avr32/bfin/c6x/cris/frv/m68k/mn10300/parisc/xtensa: Add dummy get_dma_ops() Geert Uytterhoeven
@ 2012-12-28 19:23 ` Geert Uytterhoeven
  2012-12-29  0:09   ` Mauro Carvalho Chehab
  2013-01-02 14:22   ` Marek Szyprowski
  4 siblings, 2 replies; 10+ messages in thread
From: Geert Uytterhoeven @ 2012-12-28 19:23 UTC (permalink / raw)
  To: linux-arch, Marek Szyprowski, linux-kernel, linux-media
  Cc: linux-m68k, Geert Uytterhoeven

dma_common_mmap() and dma_common_get_sgtable() are defined in
drivers/base/dma-mapping.c, and always compiled if CONFIG_HAS_DMA=y.

However, their forward declarations and the inline functions defined on top
of them (dma_mmap_attrs(), dma_mmap_coherent(), dma_mmap_writecombine(),
dma_get_sgtable_attrs()), dma_get_sgtable()) are in
<asm-generic/dma-mapping-common.h>, which is not included by all
architectures supporting CONFIG_HAS_DMA=y.  There exist no alternative
implementations.

Hence for e.g. m68k allmodconfig, I get:

drivers/media/v4l2-core/videobuf2-dma-contig.c: In function ‘vb2_dc_mmap’:
drivers/media/v4l2-core/videobuf2-dma-contig.c:204: error: implicit declaration of function ‘dma_mmap_coherent’
drivers/media/v4l2-core/videobuf2-dma-contig.c: In function ‘vb2_dc_get_base_sgt’:
drivers/media/v4l2-core/videobuf2-dma-contig.c:387: error: implicit declaration of function ‘dma_get_sgtable’

To fix this
  - Move the forward declarations and inline definitions to
    <linux/dma-mapping.h>, so all CONFIG_HAS_DMA=y architectures can use
    them,
  - Replace the hard "BUG_ON(!ops)" checks for dma_map_ops by soft checks,
    so architectures can fall back to the common code by returning NULL
    from their get_dma_ops(). Note that there are no "BUG_ON(!ops)" checks
    in other functions in <asm-generic/dma-mapping-common.h>,
  - Make "struct dma_map_ops *ops" const while we're at it.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
 include/asm-generic/dma-mapping-common.h |   55 ------------------------------
 include/linux/dma-mapping.h              |   54 +++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 55 deletions(-)

diff --git a/include/asm-generic/dma-mapping-common.h b/include/asm-generic/dma-mapping-common.h
index de8bf89..2e248d8 100644
--- a/include/asm-generic/dma-mapping-common.h
+++ b/include/asm-generic/dma-mapping-common.h
@@ -176,59 +176,4 @@ dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
 #define dma_map_sg(d, s, n, r) dma_map_sg_attrs(d, s, n, r, NULL)
 #define dma_unmap_sg(d, s, n, r) dma_unmap_sg_attrs(d, s, n, r, NULL)
 
-extern int dma_common_mmap(struct device *dev, struct vm_area_struct *vma,
-			   void *cpu_addr, dma_addr_t dma_addr, size_t size);
-
-/**
- * dma_mmap_attrs - map a coherent DMA allocation into user space
- * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
- * @vma: vm_area_struct describing requested user mapping
- * @cpu_addr: kernel CPU-view address returned from dma_alloc_attrs
- * @handle: device-view address returned from dma_alloc_attrs
- * @size: size of memory originally requested in dma_alloc_attrs
- * @attrs: attributes of mapping properties requested in dma_alloc_attrs
- *
- * Map a coherent DMA buffer previously allocated by dma_alloc_attrs
- * into user space.  The coherent DMA buffer must not be freed by the
- * driver until the user space mapping has been released.
- */
-static inline int
-dma_mmap_attrs(struct device *dev, struct vm_area_struct *vma, void *cpu_addr,
-	       dma_addr_t dma_addr, size_t size, struct dma_attrs *attrs)
-{
-	struct dma_map_ops *ops = get_dma_ops(dev);
-	BUG_ON(!ops);
-	if (ops->mmap)
-		return ops->mmap(dev, vma, cpu_addr, dma_addr, size, attrs);
-	return dma_common_mmap(dev, vma, cpu_addr, dma_addr, size);
-}
-
-#define dma_mmap_coherent(d, v, c, h, s) dma_mmap_attrs(d, v, c, h, s, NULL)
-
-static inline int dma_mmap_writecombine(struct device *dev, struct vm_area_struct *vma,
-		      void *cpu_addr, dma_addr_t dma_addr, size_t size)
-{
-	DEFINE_DMA_ATTRS(attrs);
-	dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs);
-	return dma_mmap_attrs(dev, vma, cpu_addr, dma_addr, size, &attrs);
-}
-
-int
-dma_common_get_sgtable(struct device *dev, struct sg_table *sgt,
-		       void *cpu_addr, dma_addr_t dma_addr, size_t size);
-
-static inline int
-dma_get_sgtable_attrs(struct device *dev, struct sg_table *sgt, void *cpu_addr,
-		      dma_addr_t dma_addr, size_t size, struct dma_attrs *attrs)
-{
-	struct dma_map_ops *ops = get_dma_ops(dev);
-	BUG_ON(!ops);
-	if (ops->get_sgtable)
-		return ops->get_sgtable(dev, sgt, cpu_addr, dma_addr, size,
-					attrs);
-	return dma_common_get_sgtable(dev, sgt, cpu_addr, dma_addr, size);
-}
-
-#define dma_get_sgtable(d, t, v, h, s) dma_get_sgtable_attrs(d, t, v, h, s, NULL)
-
 #endif
diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
index 94af418..4b47150 100644
--- a/include/linux/dma-mapping.h
+++ b/include/linux/dma-mapping.h
@@ -74,6 +74,60 @@ static inline int is_device_dma_capable(struct device *dev)
 
 #ifdef CONFIG_HAS_DMA
 #include <asm/dma-mapping.h>
+
+extern int dma_common_mmap(struct device *dev, struct vm_area_struct *vma,
+			   void *cpu_addr, dma_addr_t dma_addr, size_t size);
+
+/**
+ * dma_mmap_attrs - map a coherent DMA allocation into user space
+ * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
+ * @vma: vm_area_struct describing requested user mapping
+ * @cpu_addr: kernel CPU-view address returned from dma_alloc_attrs
+ * @handle: device-view address returned from dma_alloc_attrs
+ * @size: size of memory originally requested in dma_alloc_attrs
+ * @attrs: attributes of mapping properties requested in dma_alloc_attrs
+ *
+ * Map a coherent DMA buffer previously allocated by dma_alloc_attrs
+ * into user space.  The coherent DMA buffer must not be freed by the
+ * driver until the user space mapping has been released.
+ */
+static inline int
+dma_mmap_attrs(struct device *dev, struct vm_area_struct *vma, void *cpu_addr,
+	       dma_addr_t dma_addr, size_t size, struct dma_attrs *attrs)
+{
+	const struct dma_map_ops *ops = get_dma_ops(dev);
+	if (ops && ops->mmap)
+		return ops->mmap(dev, vma, cpu_addr, dma_addr, size, attrs);
+	return dma_common_mmap(dev, vma, cpu_addr, dma_addr, size);
+}
+
+#define dma_mmap_coherent(d, v, c, h, s) dma_mmap_attrs(d, v, c, h, s, NULL)
+
+static inline int dma_mmap_writecombine(struct device *dev, struct vm_area_struct *vma,
+		      void *cpu_addr, dma_addr_t dma_addr, size_t size)
+{
+	DEFINE_DMA_ATTRS(attrs);
+	dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs);
+	return dma_mmap_attrs(dev, vma, cpu_addr, dma_addr, size, &attrs);
+}
+
+int
+dma_common_get_sgtable(struct device *dev, struct sg_table *sgt,
+		       void *cpu_addr, dma_addr_t dma_addr, size_t size);
+
+static inline int
+dma_get_sgtable_attrs(struct device *dev, struct sg_table *sgt, void *cpu_addr,
+		      dma_addr_t dma_addr, size_t size, struct dma_attrs *attrs)
+{
+	const struct dma_map_ops *ops = get_dma_ops(dev);
+	if (ops && ops->get_sgtable)
+		return ops->get_sgtable(dev, sgt, cpu_addr, dma_addr, size,
+					attrs);
+	return dma_common_get_sgtable(dev, sgt, cpu_addr, dma_addr, size);
+}
+
+#define dma_get_sgtable(d, t, v, h, s) dma_get_sgtable_attrs(d, t, v, h, s, NULL)
+
 #else
 #include <asm-generic/dma-mapping-broken.h>
 #endif
-- 
1.7.0.4


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

* Re: [PATCH/RFC 4/4] common: dma-mapping: Move dma_common_*() to <linux/dma-mapping.h>
  2012-12-28 19:23 ` [PATCH/RFC 4/4] common: dma-mapping: Move dma_common_*() to <linux/dma-mapping.h> Geert Uytterhoeven
@ 2012-12-29  0:09   ` Mauro Carvalho Chehab
  2013-01-02 14:22   ` Marek Szyprowski
  1 sibling, 0 replies; 10+ messages in thread
From: Mauro Carvalho Chehab @ 2012-12-29  0:09 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: linux-arch, Marek Szyprowski, linux-kernel, linux-media, linux-m68k

Em Fri, 28 Dec 2012 20:23:34 +0100
Geert Uytterhoeven <geert@linux-m68k.org> escreveu:

> dma_common_mmap() and dma_common_get_sgtable() are defined in
> drivers/base/dma-mapping.c, and always compiled if CONFIG_HAS_DMA=y.
> 
> However, their forward declarations and the inline functions defined on top
> of them (dma_mmap_attrs(), dma_mmap_coherent(), dma_mmap_writecombine(),
> dma_get_sgtable_attrs()), dma_get_sgtable()) are in
> <asm-generic/dma-mapping-common.h>, which is not included by all
> architectures supporting CONFIG_HAS_DMA=y.  There exist no alternative
> implementations.
> 
> Hence for e.g. m68k allmodconfig, I get:
> 
> drivers/media/v4l2-core/videobuf2-dma-contig.c: In function ‘vb2_dc_mmap’:
> drivers/media/v4l2-core/videobuf2-dma-contig.c:204: error: implicit declaration of function ‘dma_mmap_coherent’
> drivers/media/v4l2-core/videobuf2-dma-contig.c: In function ‘vb2_dc_get_base_sgt’:
> drivers/media/v4l2-core/videobuf2-dma-contig.c:387: error: implicit declaration of function ‘dma_get_sgtable’
> 
> To fix this
>   - Move the forward declarations and inline definitions to
>     <linux/dma-mapping.h>, so all CONFIG_HAS_DMA=y architectures can use
>     them,
>   - Replace the hard "BUG_ON(!ops)" checks for dma_map_ops by soft checks,
>     so architectures can fall back to the common code by returning NULL
>     from their get_dma_ops(). Note that there are no "BUG_ON(!ops)" checks
>     in other functions in <asm-generic/dma-mapping-common.h>,
>   - Make "struct dma_map_ops *ops" const while we're at it.
> 
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>

>From my side:

Acked-by: Mauro Carvalho Chehab <mchehab@redhat.com>

> ---
>  include/asm-generic/dma-mapping-common.h |   55 ------------------------------
>  include/linux/dma-mapping.h              |   54 +++++++++++++++++++++++++++++
>  2 files changed, 54 insertions(+), 55 deletions(-)
> 
> diff --git a/include/asm-generic/dma-mapping-common.h b/include/asm-generic/dma-mapping-common.h
> index de8bf89..2e248d8 100644
> --- a/include/asm-generic/dma-mapping-common.h
> +++ b/include/asm-generic/dma-mapping-common.h
> @@ -176,59 +176,4 @@ dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
>  #define dma_map_sg(d, s, n, r) dma_map_sg_attrs(d, s, n, r, NULL)
>  #define dma_unmap_sg(d, s, n, r) dma_unmap_sg_attrs(d, s, n, r, NULL)
>  
> -extern int dma_common_mmap(struct device *dev, struct vm_area_struct *vma,
> -			   void *cpu_addr, dma_addr_t dma_addr, size_t size);
> -
> -/**
> - * dma_mmap_attrs - map a coherent DMA allocation into user space
> - * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
> - * @vma: vm_area_struct describing requested user mapping
> - * @cpu_addr: kernel CPU-view address returned from dma_alloc_attrs
> - * @handle: device-view address returned from dma_alloc_attrs
> - * @size: size of memory originally requested in dma_alloc_attrs
> - * @attrs: attributes of mapping properties requested in dma_alloc_attrs
> - *
> - * Map a coherent DMA buffer previously allocated by dma_alloc_attrs
> - * into user space.  The coherent DMA buffer must not be freed by the
> - * driver until the user space mapping has been released.
> - */
> -static inline int
> -dma_mmap_attrs(struct device *dev, struct vm_area_struct *vma, void *cpu_addr,
> -	       dma_addr_t dma_addr, size_t size, struct dma_attrs *attrs)
> -{
> -	struct dma_map_ops *ops = get_dma_ops(dev);
> -	BUG_ON(!ops);
> -	if (ops->mmap)
> -		return ops->mmap(dev, vma, cpu_addr, dma_addr, size, attrs);
> -	return dma_common_mmap(dev, vma, cpu_addr, dma_addr, size);
> -}
> -
> -#define dma_mmap_coherent(d, v, c, h, s) dma_mmap_attrs(d, v, c, h, s, NULL)
> -
> -static inline int dma_mmap_writecombine(struct device *dev, struct vm_area_struct *vma,
> -		      void *cpu_addr, dma_addr_t dma_addr, size_t size)
> -{
> -	DEFINE_DMA_ATTRS(attrs);
> -	dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs);
> -	return dma_mmap_attrs(dev, vma, cpu_addr, dma_addr, size, &attrs);
> -}
> -
> -int
> -dma_common_get_sgtable(struct device *dev, struct sg_table *sgt,
> -		       void *cpu_addr, dma_addr_t dma_addr, size_t size);
> -
> -static inline int
> -dma_get_sgtable_attrs(struct device *dev, struct sg_table *sgt, void *cpu_addr,
> -		      dma_addr_t dma_addr, size_t size, struct dma_attrs *attrs)
> -{
> -	struct dma_map_ops *ops = get_dma_ops(dev);
> -	BUG_ON(!ops);
> -	if (ops->get_sgtable)
> -		return ops->get_sgtable(dev, sgt, cpu_addr, dma_addr, size,
> -					attrs);
> -	return dma_common_get_sgtable(dev, sgt, cpu_addr, dma_addr, size);
> -}
> -
> -#define dma_get_sgtable(d, t, v, h, s) dma_get_sgtable_attrs(d, t, v, h, s, NULL)
> -
>  #endif
> diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
> index 94af418..4b47150 100644
> --- a/include/linux/dma-mapping.h
> +++ b/include/linux/dma-mapping.h
> @@ -74,6 +74,60 @@ static inline int is_device_dma_capable(struct device *dev)
>  
>  #ifdef CONFIG_HAS_DMA
>  #include <asm/dma-mapping.h>
> +
> +extern int dma_common_mmap(struct device *dev, struct vm_area_struct *vma,
> +			   void *cpu_addr, dma_addr_t dma_addr, size_t size);
> +
> +/**
> + * dma_mmap_attrs - map a coherent DMA allocation into user space
> + * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
> + * @vma: vm_area_struct describing requested user mapping
> + * @cpu_addr: kernel CPU-view address returned from dma_alloc_attrs
> + * @handle: device-view address returned from dma_alloc_attrs
> + * @size: size of memory originally requested in dma_alloc_attrs
> + * @attrs: attributes of mapping properties requested in dma_alloc_attrs
> + *
> + * Map a coherent DMA buffer previously allocated by dma_alloc_attrs
> + * into user space.  The coherent DMA buffer must not be freed by the
> + * driver until the user space mapping has been released.
> + */
> +static inline int
> +dma_mmap_attrs(struct device *dev, struct vm_area_struct *vma, void *cpu_addr,
> +	       dma_addr_t dma_addr, size_t size, struct dma_attrs *attrs)
> +{
> +	const struct dma_map_ops *ops = get_dma_ops(dev);
> +	if (ops && ops->mmap)
> +		return ops->mmap(dev, vma, cpu_addr, dma_addr, size, attrs);
> +	return dma_common_mmap(dev, vma, cpu_addr, dma_addr, size);
> +}
> +
> +#define dma_mmap_coherent(d, v, c, h, s) dma_mmap_attrs(d, v, c, h, s, NULL)
> +
> +static inline int dma_mmap_writecombine(struct device *dev, struct vm_area_struct *vma,
> +		      void *cpu_addr, dma_addr_t dma_addr, size_t size)
> +{
> +	DEFINE_DMA_ATTRS(attrs);
> +	dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs);
> +	return dma_mmap_attrs(dev, vma, cpu_addr, dma_addr, size, &attrs);
> +}
> +
> +int
> +dma_common_get_sgtable(struct device *dev, struct sg_table *sgt,
> +		       void *cpu_addr, dma_addr_t dma_addr, size_t size);
> +
> +static inline int
> +dma_get_sgtable_attrs(struct device *dev, struct sg_table *sgt, void *cpu_addr,
> +		      dma_addr_t dma_addr, size_t size, struct dma_attrs *attrs)
> +{
> +	const struct dma_map_ops *ops = get_dma_ops(dev);
> +	if (ops && ops->get_sgtable)
> +		return ops->get_sgtable(dev, sgt, cpu_addr, dma_addr, size,
> +					attrs);
> +	return dma_common_get_sgtable(dev, sgt, cpu_addr, dma_addr, size);
> +}
> +
> +#define dma_get_sgtable(d, t, v, h, s) dma_get_sgtable_attrs(d, t, v, h, s, NULL)
> +
>  #else
>  #include <asm-generic/dma-mapping-broken.h>
>  #endif


-- 

Cheers,
Mauro

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

* Re: [PATCH/RFC 4/4] common: dma-mapping: Move dma_common_*() to <linux/dma-mapping.h>
  2012-12-28 19:23 ` [PATCH/RFC 4/4] common: dma-mapping: Move dma_common_*() to <linux/dma-mapping.h> Geert Uytterhoeven
  2012-12-29  0:09   ` Mauro Carvalho Chehab
@ 2013-01-02 14:22   ` Marek Szyprowski
  2013-01-13 10:40     ` Geert Uytterhoeven
  1 sibling, 1 reply; 10+ messages in thread
From: Marek Szyprowski @ 2013-01-02 14:22 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: linux-arch, linux-kernel, linux-media, linux-m68k

Hello,

On 12/28/2012 8:23 PM, Geert Uytterhoeven wrote:
> dma_common_mmap() and dma_common_get_sgtable() are defined in
> drivers/base/dma-mapping.c, and always compiled if CONFIG_HAS_DMA=y.
>
> However, their forward declarations and the inline functions defined on top
> of them (dma_mmap_attrs(), dma_mmap_coherent(), dma_mmap_writecombine(),
> dma_get_sgtable_attrs()), dma_get_sgtable()) are in
> <asm-generic/dma-mapping-common.h>, which is not included by all
> architectures supporting CONFIG_HAS_DMA=y.  There exist no alternative
> implementations.
>
> Hence for e.g. m68k allmodconfig, I get:
>
> drivers/media/v4l2-core/videobuf2-dma-contig.c: In function ‘vb2_dc_mmap’:
> drivers/media/v4l2-core/videobuf2-dma-contig.c:204: error: implicit declaration of function ‘dma_mmap_coherent’
> drivers/media/v4l2-core/videobuf2-dma-contig.c: In function ‘vb2_dc_get_base_sgt’:
> drivers/media/v4l2-core/videobuf2-dma-contig.c:387: error: implicit declaration of function ‘dma_get_sgtable’
>
> To fix this
>    - Move the forward declarations and inline definitions to
>      <linux/dma-mapping.h>, so all CONFIG_HAS_DMA=y architectures can use
>      them,
>    - Replace the hard "BUG_ON(!ops)" checks for dma_map_ops by soft checks,
>      so architectures can fall back to the common code by returning NULL
>      from their get_dma_ops(). Note that there are no "BUG_ON(!ops)" checks
>      in other functions in <asm-generic/dma-mapping-common.h>,
>    - Make "struct dma_map_ops *ops" const while we're at it.

I think that more appropriate way of handling it is to avoid dma_map_ops 
based
calls (those archs probably have some reasons why they don't use it at 
all) and
provide static inline stubs which call dma_common_mmap and 
dma_common_get_sgtable.

It is definitely my fault that I missed the case of non-dma-map-ops 
based archs
while I was adding support for dma_mmap_coherent and dma_get_sgt calls...

 > (snipped)

Best regards
-- 
Marek Szyprowski
Samsung Poland R&D Center



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

* Re: [PATCH/RFC 0/4] Re: dma_mmap_coherent / ARCH_HAS_DMA_MMAP_COHERENT
  2012-12-28 19:23 ` [PATCH/RFC 0/4] " Geert Uytterhoeven
@ 2013-01-02 14:39   ` Marek Szyprowski
  0 siblings, 0 replies; 10+ messages in thread
From: Marek Szyprowski @ 2013-01-02 14:39 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: linux-arch, linux-kernel, linux-media, linux-m68k

Hello,

On 12/28/2012 8:23 PM, Geert Uytterhoeven wrote:
> On Sun, Dec 16, 2012 at 5:03 PM, Geert Uytterhoeven <geert@linux-m68k.org>
> wrote:
> > drivers/media/v4l2-core/videobuf2-dma-contig.c: In function ‘vb2_dc_mmap’:
> > drivers/media/v4l2-core/videobuf2-dma-contig.c:204: error: implicit declaration of function ‘dma_mmap_coherent’
> > drivers/media/v4l2-core/videobuf2-dma-contig.c: In function ‘vb2_dc_get_base_sgt’:
> > drivers/media/v4l2-core/videobuf2-dma-contig.c:387: error: implicit declaration of function ‘dma_get_sgtable’
> > make[6]: *** [drivers/media/v4l2-core/videobuf2-dma-contig.o] Error 1
> > make[6]: Target `__build' not remade because of errors.
> > make[5]: *** [drivers/media/v4l2-core] Error 2
> >
> > Both dma_mmap_coherent() and dma_get_sgtable() are defined in
> > include/asm-generic/dma-mapping-common.h only, which is included by
> > <asm/dma-mapping.h> on alpha, arm, arm64, hexagon, ia64, microblaze, mips,
> > openrisc, powerpc, s390, sh, sparc, tile, unicore32, x86.
> > Should the remaining architectures include this, too?
> > Should it be moved to <linux/dma-mapping.h>?
>
> I came up with an RFC-solution for this in [PATCH/RFC 3/4]
> ("avr32/bfin/c6x/cris/frv/m68k/mn10300/parisc/xtensa: Add dummy get_dma_ops()")
> and [PATCH/RFC 4/4] ("common: dma-mapping: Move dma_common_*() to
> <linux/dma-mapping.h>") of this series.
>
> > Furthermore, there's ARCH_HAS_DMA_MMAP_COHERENT, which is defined
> > by powerpc only:
> > arch/powerpc/include/asm/dma-mapping.h:#define ARCH_HAS_DMA_MMAP_COHERENT
> >
> > and handled in some fishy way in sound/core/pcm_native.c:
> >
> > #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
> >  */
> > int snd_pcm_lib_default_mmap(struct snd_pcm_substream *substream,
> >                              struct vm_area_struct *area)
> > {
> >         area->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
> > #ifdef ARCH_HAS_DMA_MMAP_COHERENT
> >         if (!substream->ops->page &&
> >             substream->dma_buffer.dev.type == 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);
> > #elif defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT)
> >         if (substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV &&
> >             !plat_device_is_coherent(substream->dma_buffer.dev.dev))
> >                 area->vm_page_prot = pgprot_noncached(area->vm_page_prot);
> > #endif /* ARCH_HAS_DMA_MMAP_COHERENT */
> >         /* mmap with fault handler */
> >         area->vm_ops = &snd_pcm_vm_ops_data_fault;
> >         return 0;
> > }
> > EXPORT_SYMBOL_GPL(snd_pcm_lib_default_mmap);
> >
> > What's up here?
>
> Probably an easy solution here is to kill ARCH_HAS_DMA_MMAP_COHERENT and
> change the code to
>
>      #if defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT)
> 	    if (substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV &&
> 		!plat_device_is_coherent(substream->dma_buffer.dev.dev))
> 		    area->vm_page_prot = pgprot_noncached(area->vm_page_prot);
>      #else
> 	    if (!substream->ops->page &&
> 		substream->dma_buffer.dev.type == 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
>
> but obviously I don't like the test for CONFIG_MIPS in generic code...

I think that the best way of handling it would be to move this code to MIPS
specific dma_mmap_coherent() implementation.

Best regards
-- 
Marek Szyprowski
Samsung Poland R&D Center



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

* Re: [PATCH/RFC 4/4] common: dma-mapping: Move dma_common_*() to <linux/dma-mapping.h>
  2013-01-02 14:22   ` Marek Szyprowski
@ 2013-01-13 10:40     ` Geert Uytterhoeven
  0 siblings, 0 replies; 10+ messages in thread
From: Geert Uytterhoeven @ 2013-01-13 10:40 UTC (permalink / raw)
  To: Marek Szyprowski; +Cc: linux-arch, linux-kernel, linux-media, linux-m68k

Hi Marek,

On Wed, Jan 2, 2013 at 3:22 PM, Marek Szyprowski
<m.szyprowski@samsung.com> wrote:
> On 12/28/2012 8:23 PM, Geert Uytterhoeven wrote:
>> dma_common_mmap() and dma_common_get_sgtable() are defined in
>> drivers/base/dma-mapping.c, and always compiled if CONFIG_HAS_DMA=y.
>>
>> However, their forward declarations and the inline functions defined on
>> top
>> of them (dma_mmap_attrs(), dma_mmap_coherent(), dma_mmap_writecombine(),
>> dma_get_sgtable_attrs()), dma_get_sgtable()) are in
>> <asm-generic/dma-mapping-common.h>, which is not included by all
>> architectures supporting CONFIG_HAS_DMA=y.  There exist no alternative
>> implementations.
>>
>> Hence for e.g. m68k allmodconfig, I get:
>>
>> drivers/media/v4l2-core/videobuf2-dma-contig.c: In function ‘vb2_dc_mmap’:
>> drivers/media/v4l2-core/videobuf2-dma-contig.c:204: error: implicit
>> declaration of function ‘dma_mmap_coherent’
>> drivers/media/v4l2-core/videobuf2-dma-contig.c: In function
>> ‘vb2_dc_get_base_sgt’:
>> drivers/media/v4l2-core/videobuf2-dma-contig.c:387: error: implicit
>> declaration of function ‘dma_get_sgtable’
>>
>> To fix this
>>    - Move the forward declarations and inline definitions to
>>      <linux/dma-mapping.h>, so all CONFIG_HAS_DMA=y architectures can use
>>      them,
>>    - Replace the hard "BUG_ON(!ops)" checks for dma_map_ops by soft
>> checks,
>>      so architectures can fall back to the common code by returning NULL
>>      from their get_dma_ops(). Note that there are no "BUG_ON(!ops)"
>> checks
>>      in other functions in <asm-generic/dma-mapping-common.h>,
>>    - Make "struct dma_map_ops *ops" const while we're at it.
>
>
> I think that more appropriate way of handling it is to avoid dma_map_ops
> based
> calls (those archs probably have some reasons why they don't use it at all)
> and
> provide static inline stubs which call dma_common_mmap and
> dma_common_get_sgtable.

OK, I'll do that.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

end of thread, other threads:[~2013-01-13 10:40 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-16 16:03 dma_mmap_coherent / ARCH_HAS_DMA_MMAP_COHERENT Geert Uytterhoeven
2012-12-28 19:23 ` [PATCH/RFC 0/4] " Geert Uytterhoeven
2013-01-02 14:39   ` Marek Szyprowski
2012-12-28 19:23 ` [PATCH 1/4] m68k: Sort out !CONFIG_MMU_SUN3 vs. CONFIG_HAS_DMA Geert Uytterhoeven
2012-12-28 19:23 ` [PATCH 2/4] score: Remove unneeded <asm/dma-mapping.h> Geert Uytterhoeven
2012-12-28 19:23 ` [PATCH/RFC 3/4] avr32/bfin/c6x/cris/frv/m68k/mn10300/parisc/xtensa: Add dummy get_dma_ops() Geert Uytterhoeven
2012-12-28 19:23 ` [PATCH/RFC 4/4] common: dma-mapping: Move dma_common_*() to <linux/dma-mapping.h> Geert Uytterhoeven
2012-12-29  0:09   ` Mauro Carvalho Chehab
2013-01-02 14:22   ` Marek Szyprowski
2013-01-13 10:40     ` Geert Uytterhoeven

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).