[PATCH 0/2] Follow-up on "ARM: Fix dma_alloc_coherent() and friends for NOMMU"

STALE3364d

8 messages, 3 authors, 2017-07-03 · open the first message on its own page

[PATCH 0/2] Follow-up on "ARM: Fix dma_alloc_coherent() and friends for NOMMU"

From: Vladimir Murzin <hidden>
Date: 2017-06-28 09:17:32

These two patches are folloups on "[PATCH v6 0/7] ARM: Fix
dma_alloc_coherent() and friends for NOMMU" which has been partly
merged in [1]. PATCH 1/2 is done per Christoph's suggestion [2] to
eliminate duplication in dma-noop.c.  PATCH 2/2 is fixup for ARM's dma
operations for NOMMU due to aforementioned change.

@Benjamin, your Tested-by for ARM bits would be very appretiated!

@Christoph, in case you decide to queue PATCH 1/2, can you put it
before "ARM: NOMMU: Introduce dma operations for noMMU", so transition
to the new dma operations won't break bisectability.

[1] git://git.infradead.org/users/hch/dma-mapping.git for-next
[2] https://www.spinics.net/lists/arm-kernel/msg590587.html

Cc: Steven Miao <redacted>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: Rich Felker <dalias@libc.org>
Cc: Chris Zankel <chris@zankel.net>
Cc: Max Filippov <jcmvbkbc@gmail.com>

Thanks!

Vladimir Murzin (2):
  drivers: dma-mapping: allow dma_common_mmap() for NOMMU
  fixup: ARM: NOMMU: Introduce dma operations for noMMU

 arch/arm/mm/dma-mapping-nommu.c | 18 ------------------
 arch/blackfin/Kconfig           |  1 +
 arch/m32r/Kconfig               |  1 +
 arch/m68k/Kconfig               |  1 +
 arch/microblaze/Kconfig         |  1 +
 arch/sh/Kconfig                 |  1 +
 arch/xtensa/Kconfig             |  1 +
 drivers/base/dma-mapping.c      |  4 ++--
 8 files changed, 8 insertions(+), 20 deletions(-)

-- 
2.0.0

[PATCH 2/2] fixup: ARM: NOMMU: Introduce dma operations for noMMU

From: Vladimir Murzin <hidden>
Date: 2017-06-28 09:17:41

dma_common_mmap() is already available for NOMMU, so there is no point
to carry own version. Moreover, existent implementation relies on
dma-noop provides mmap, but it is not true anymore.

Signed-off-by: Vladimir Murzin <redacted>
---
 arch/arm/mm/dma-mapping-nommu.c | 18 ------------------
 1 file changed, 18 deletions(-)
diff --git a/arch/arm/mm/dma-mapping-nommu.c b/arch/arm/mm/dma-mapping-nommu.c
index 6adc02f..90ee354 100644
--- a/arch/arm/mm/dma-mapping-nommu.c
+++ b/arch/arm/mm/dma-mapping-nommu.c
@@ -71,23 +71,6 @@ static void arm_nommu_dma_free(struct device *dev, size_t size,
 	return;
 }
 
-static int arm_nommu_dma_mmap(struct device *dev, struct vm_area_struct *vma,
-			      void *cpu_addr, dma_addr_t dma_addr, size_t size,
-			      unsigned long attrs)
-{
-	const struct dma_map_ops *ops = &dma_noop_ops;
-	int ret;
-
-	if (dma_mmap_from_coherent(dev, vma, cpu_addr, size, &ret))
-		return ret;
-
-	if (attrs & DMA_ATTR_NON_CONSISTENT)
-		return ops->mmap(dev, vma, cpu_addr, dma_addr, size, attrs);
-
-	WARN_ON_ONCE(1);
-	return -ENXIO;
-}
-
 static void __dma_page_cpu_to_dev(phys_addr_t paddr, size_t size,
 				  enum dma_data_direction dir)
 {
@@ -190,7 +173,6 @@ static void arm_nommu_dma_sync_sg_for_cpu(struct device *dev, struct scatterlist
 const struct dma_map_ops arm_nommu_dma_ops = {
 	.alloc			= arm_nommu_dma_alloc,
 	.free			= arm_nommu_dma_free,
-	.mmap			= arm_nommu_dma_mmap,
 	.map_page		= arm_nommu_dma_map_page,
 	.unmap_page		= arm_nommu_dma_unmap_page,
 	.map_sg			= arm_nommu_dma_map_sg,
-- 
2.0.0

[PATCH 1/2] drivers: dma-mapping: allow dma_common_mmap() for NOMMU

From: Vladimir Murzin <hidden>
Date: 2017-06-28 09:17:57

Currently, internals of dma_common_mmap() is compiled out if build is
done for either NOMMU or target which explicitly says it does not
have/want coherent DMA mmap. It turned out that dma_common_mmap() can
be handy in NOMMU setup (at least for ARM).

This patch converts exitent NOMMU targets to use ARCH_NO_COHERENT_DMA_MMAP,
thus when CONFIG_MMU is gone from dma_common_mmap() their behaviour stays
unchanged.

ARM is not converted to ARCH_NO_COHERENT_DMA_MMAP because it 1)
already has mmap callback which can handle (at some extent) NOMMU 2)
already defines dummy pgprot_noncached() for NOMMU build.

c6x and frv stay untouched since they already have ARCH_NO_COHERENT_DMA_MMAP.

Cc: Steven Miao <redacted>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: Rich Felker <dalias@libc.org>
Cc: Chris Zankel <chris@zankel.net>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Vladimir Murzin <redacted>
---
 arch/blackfin/Kconfig      | 1 +
 arch/m32r/Kconfig          | 1 +
 arch/m68k/Kconfig          | 1 +
 arch/microblaze/Kconfig    | 1 +
 arch/sh/Kconfig            | 1 +
 arch/xtensa/Kconfig        | 1 +
 drivers/base/dma-mapping.c | 4 ++--
 7 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/arch/blackfin/Kconfig b/arch/blackfin/Kconfig
index 3c1bd64..89bdb82 100644
--- a/arch/blackfin/Kconfig
+++ b/arch/blackfin/Kconfig
@@ -41,6 +41,7 @@ config BLACKFIN
 	select MODULES_USE_ELF_RELA
 	select HAVE_DEBUG_STACKOVERFLOW
 	select HAVE_NMI
+	select ARCH_NO_COHERENT_DMA_MMAP
 
 config GENERIC_CSUM
 	def_bool y
diff --git a/arch/m32r/Kconfig b/arch/m32r/Kconfig
index 9547446..87cde1e 100644
--- a/arch/m32r/Kconfig
+++ b/arch/m32r/Kconfig
@@ -19,6 +19,7 @@ config M32R
 	select HAVE_DEBUG_STACKOVERFLOW
 	select CPU_NO_EFFICIENT_FFS
 	select DMA_NOOP_OPS
+	select ARCH_NO_COHERENT_DMA_MMAP if !MMU
 
 config SBUS
 	bool
diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig
index d140206..5abb548 100644
--- a/arch/m68k/Kconfig
+++ b/arch/m68k/Kconfig
@@ -2,6 +2,7 @@ config M68K
 	bool
 	default y
 	select ARCH_MIGHT_HAVE_PC_PARPORT if ISA
+	select ARCH_NO_COHERENT_DMA_MMAP if !MMU
 	select HAVE_IDE
 	select HAVE_AOUT if MMU
 	select HAVE_DEBUG_BUGVERBOSE
diff --git a/arch/microblaze/Kconfig b/arch/microblaze/Kconfig
index 85885a5..8ba7b7c 100644
--- a/arch/microblaze/Kconfig
+++ b/arch/microblaze/Kconfig
@@ -2,6 +2,7 @@ config MICROBLAZE
 	def_bool y
 	select ARCH_HAS_GCOV_PROFILE_ALL
 	select ARCH_MIGHT_HAVE_PC_PARPORT
+	select ARCH_NO_COHERENT_DMA_MMAP if !MMU
 	select ARCH_WANT_IPC_PARSE_VERSION
 	select BUILDTIME_EXTABLE_SORT
 	select CLKSRC_OF
diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig
index ee08695..640a859 100644
--- a/arch/sh/Kconfig
+++ b/arch/sh/Kconfig
@@ -2,6 +2,7 @@ config SUPERH
 	def_bool y
 	select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
 	select ARCH_MIGHT_HAVE_PC_PARPORT
+	select ARCH_NO_COHERENT_DMA_MMAP if !MMU
 	select HAVE_PATA_PLATFORM
 	select CLKDEV_LOOKUP
 	select HAVE_IDE if HAS_IOPORT_MAP
diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig
index f4126cf..7ad6d77 100644
--- a/arch/xtensa/Kconfig
+++ b/arch/xtensa/Kconfig
@@ -3,6 +3,7 @@ config ZONE_DMA
 
 config XTENSA
 	def_bool y
+	select ARCH_NO_COHERENT_DMA_MMAP if !MMU
 	select ARCH_WANT_FRAME_POINTERS
 	select ARCH_WANT_IPC_PARSE_VERSION
 	select BUILDTIME_EXTABLE_SORT
diff --git a/drivers/base/dma-mapping.c b/drivers/base/dma-mapping.c
index 10e7c02..ce1e02b 100644
--- a/drivers/base/dma-mapping.c
+++ b/drivers/base/dma-mapping.c
@@ -227,7 +227,7 @@ int dma_common_mmap(struct device *dev, struct vm_area_struct *vma,
 		    void *cpu_addr, dma_addr_t dma_addr, size_t size)
 {
 	int ret = -ENXIO;
-#if defined(CONFIG_MMU) && !defined(CONFIG_ARCH_NO_COHERENT_DMA_MMAP)
+#ifndef CONFIG_ARCH_NO_COHERENT_DMA_MMAP
 	unsigned long user_count = vma_pages(vma);
 	unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT;
 	unsigned long pfn = page_to_pfn(virt_to_page(cpu_addr));
@@ -244,7 +244,7 @@ int dma_common_mmap(struct device *dev, struct vm_area_struct *vma,
 				      user_count << PAGE_SHIFT,
 				      vma->vm_page_prot);
 	}
-#endif	/* CONFIG_MMU && !CONFIG_ARCH_NO_COHERENT_DMA_MMAP */
+#endif	/* !CONFIG_ARCH_NO_COHERENT_DMA_MMAP */
 
 	return ret;
 }
-- 
2.0.0

Re: [PATCH 0/2] Follow-up on "ARM: Fix dma_alloc_coherent() and friends for NOMMU"

From: Christoph Hellwig <hch@lst.de>
Date: 2017-06-28 13:52:50

Thanks Vlad,

these look fine to me.  I'll wait another day or two for comments
(especially if other nommu archs actually want this code), and
if nothing shows up will apply them.

Re: [PATCH 0/2] Follow-up on "ARM: Fix dma_alloc_coherent() and friends for NOMMU"

From: Benjamin Gaignard <hidden>
Date: 2017-06-30 11:38:07

2017-06-28 11:16 GMT+02:00 Vladimir Murzin [off-list ref]:
These two patches are folloups on "[PATCH v6 0/7] ARM: Fix
dma_alloc_coherent() and friends for NOMMU" which has been partly
merged in [1]. PATCH 1/2 is done per Christoph's suggestion [2] to
eliminate duplication in dma-noop.c.  PATCH 2/2 is fixup for ARM's dma
operations for NOMMU due to aforementioned change.

@Benjamin, your Tested-by for ARM bits would be very appretiated!
I have been able to test on stm32f4 with drm/kms drivers which is
calling dma_alloc_coherent
and modetest doing mmap and it is working fine.

tested-by: Benjamin Gaignard <redacted>
@Christoph, in case you decide to queue PATCH 1/2, can you put it
before "ARM: NOMMU: Introduce dma operations for noMMU", so transition
to the new dma operations won't break bisectability.

[1] git://git.infradead.org/users/hch/dma-mapping.git for-next
[2] https://www.spinics.net/lists/arm-kernel/msg590587.html

Cc: Steven Miao <redacted>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: Rich Felker <dalias@libc.org>
Cc: Chris Zankel <chris@zankel.net>
Cc: Max Filippov <jcmvbkbc@gmail.com>

Thanks!

Vladimir Murzin (2):
  drivers: dma-mapping: allow dma_common_mmap() for NOMMU
  fixup: ARM: NOMMU: Introduce dma operations for noMMU

 arch/arm/mm/dma-mapping-nommu.c | 18 ------------------
 arch/blackfin/Kconfig           |  1 +
 arch/m32r/Kconfig               |  1 +
 arch/m68k/Kconfig               |  1 +
 arch/microblaze/Kconfig         |  1 +
 arch/sh/Kconfig                 |  1 +
 arch/xtensa/Kconfig             |  1 +
 drivers/base/dma-mapping.c      |  4 ++--
 8 files changed, 8 insertions(+), 20 deletions(-)

--
2.0.0


-- 
Benjamin Gaignard

Graphic Study Group

Linaro.org ? Open source software for ARM SoCs

Follow Linaro: Facebook | Twitter | Blog

Re: [PATCH 0/2] Follow-up on "ARM: Fix dma_alloc_coherent() and friends for NOMMU"

From: Vladimir Murzin <hidden>
Date: 2017-06-30 11:59:45

On 30/06/17 12:36, Benjamin Gaignard wrote:
2017-06-28 11:16 GMT+02:00 Vladimir Murzin [off-list ref]:
quoted
These two patches are folloups on "[PATCH v6 0/7] ARM: Fix
dma_alloc_coherent() and friends for NOMMU" which has been partly
merged in [1]. PATCH 1/2 is done per Christoph's suggestion [2] to
eliminate duplication in dma-noop.c.  PATCH 2/2 is fixup for ARM's dma
operations for NOMMU due to aforementioned change.

@Benjamin, your Tested-by for ARM bits would be very appretiated!
I have been able to test on stm32f4 with drm/kms drivers which is
calling dma_alloc_coherent
and modetest doing mmap and it is working fine.

tested-by: Benjamin Gaignard <redacted>
Great thanks!

Vladimir
quoted
@Christoph, in case you decide to queue PATCH 1/2, can you put it
before "ARM: NOMMU: Introduce dma operations for noMMU", so transition
to the new dma operations won't break bisectability.

[1] git://git.infradead.org/users/hch/dma-mapping.git for-next
[2] https://www.spinics.net/lists/arm-kernel/msg590587.html

Cc: Steven Miao <redacted>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: Rich Felker <dalias@libc.org>
Cc: Chris Zankel <chris@zankel.net>
Cc: Max Filippov <jcmvbkbc@gmail.com>

Thanks!

Vladimir Murzin (2):
  drivers: dma-mapping: allow dma_common_mmap() for NOMMU
  fixup: ARM: NOMMU: Introduce dma operations for noMMU

 arch/arm/mm/dma-mapping-nommu.c | 18 ------------------
 arch/blackfin/Kconfig           |  1 +
 arch/m32r/Kconfig               |  1 +
 arch/m68k/Kconfig               |  1 +
 arch/microblaze/Kconfig         |  1 +
 arch/sh/Kconfig                 |  1 +
 arch/xtensa/Kconfig             |  1 +
 drivers/base/dma-mapping.c      |  4 ++--
 8 files changed, 8 insertions(+), 20 deletions(-)

--
2.0.0

Re: [PATCH 0/2] Follow-up on "ARM: Fix dma_alloc_coherent() and friends for NOMMU"

From: Vladimir Murzin <hidden>
Date: 2017-07-03 08:50:14

On 28/06/17 14:52, Christoph Hellwig wrote:
Thanks Vlad,

these look fine to me.  I'll wait another day or two for comments
(especially if other nommu archs actually want this code), and
if nothing shows up will apply them.
Gentle remainder to make sure this follow-up is not lost ;)

Cheers
Vladimir

Re: [PATCH 0/2] Follow-up on "ARM: Fix dma_alloc_coherent() and friends for NOMMU"

From: Vladimir Murzin <hidden>
Date: 2017-07-03 08:54:11

On 03/07/17 09:49, Vladimir Murzin wrote:
On 28/06/17 14:52, Christoph Hellwig wrote:
quoted
Thanks Vlad,

these look fine to me.  I'll wait another day or two for comments
(especially if other nommu archs actually want this code), and
if nothing shows up will apply them.
Gentle remainder to make sure this follow-up is not lost ;)
I should have checked the dma-mapping repo first. I see it was applied two
days ago..

Thanks a lot!.. and sorry for the noise!

Vladimir
Cheers
Vladimir

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help