Skip to contentSkip to conversation

fix the non-coherent coldfire dma_alloc_coherent v2

PATCH In review Christoph Hellwig 7 participants 39 messages Oct 16, 2023 – Oct 19, 2023

Subsystems (10)
lore
Share & tools
lore
#0 lore raw

Hi all,

this is the next attempt to not return memory that is not DMA coherent on coldfire/m68knommu. The last one needed more fixups in the fec driver, which this versions includes. On top of that I've also added a few more cleanups to the core DMA allocation code.

Jim: any work to support the set_uncached and remap method for arm32 should probably be based on this, and patch 3 should make that selection a little easier.

Changes since v1:
- sort out the dependency mess in RISCV
- don't even built non-coherent DMA support for coldfire cores without data caches
- apply the fec workarounds to all coldfire platforms with data caches
- add a trivial cleanup for m68k dma.c

#1 lore raw

PATCH 1/12 riscv: RISCV_NONSTANDARD_CACHE_OPS shouldn't depend on RISCV_DMA_NONCOHERENT

RISCV_NONSTANDARD_CACHE_OPS is also used for the pmem cache maintenance helpers, which are built into the kernel unconditionally.

---
 arch/riscv/Kconfig          | 1 -
 drivers/cache/Kconfig       | 2 +-
 drivers/soc/renesas/Kconfig | 2 +-
 3 files changed, 2 insertions(+), 3 deletions(-)
arch/riscv/Kconfig +0 -1
index d607ab0f7c6daf..0ac0b538379718 100644
@@ -277,7 +277,6 @@ config RISCV_DMA_NONCOHERENT
 
 config RISCV_NONSTANDARD_CACHE_OPS
 	bool
-	depends on RISCV_DMA_NONCOHERENT
 	help
 	  This enables function pointer support for non-standard noncoherent
 	  systems to handle cache management.
drivers/cache/Kconfig +1 -1
index a57677f908f3ba..d6e5e3abaad8af 100644
@@ -3,7 +3,7 @@ menu "Cache Drivers"
 
 config AX45MP_L2_CACHE
 	bool "Andes Technology AX45MP L2 Cache controller"
-	depends on RISCV_DMA_NONCOHERENT
+	depends on RISCV
 	select RISCV_NONSTANDARD_CACHE_OPS
 	help
 	  Support for the L2 cache controller on Andes Technology AX45MP platforms.
drivers/soc/renesas/Kconfig +1 -1
index 12040ce116a551..880c544bb2dfda 100644
@@ -335,7 +335,7 @@ config ARCH_R9A07G043
 	bool "RISC-V Platform support for RZ/Five"
 	depends on NONPORTABLE
 	select ARCH_RZG2L
-	select AX45MP_L2_CACHE if RISCV_DMA_NONCOHERENT
+	select AX45MP_L2_CACHE
 	select DMA_GLOBAL_POOL
 	select ERRATA_ANDES if RISCV_SBI
 	select ERRATA_ANDES_CMO if ERRATA_ANDES
Signature · 1 line
2.39.2
#2 lore raw

Re: [PATCH 01/12] riscv: RISCV_NONSTANDARD_CACHE_OPS shouldn't depend on RISCV_DMA_NONCOHERENT

Hey,

Quoted 2 lines · Christoph Hellwig

RISCV_NONSTANDARD_CACHE_OPS is also used for the pmem cache maintenance helpers, which are built into the kernel unconditionally.

You surely have better insight than I do here, but is this actually required?
This patch seems to allow creation of a kernel where the cache maintenance operations could be used for pmem, but would be otherwise unavailable, which seems counter intuitive to me.
Why would someone want to provide the pmem helpers with cache maintenance operations, but not provide them generally?

I also don't really understand what the unconditional nature of the pmem helpers has to do with anything, as this patch does not unconditionally provide any cache management operations, only relax the conditions under which the non-standard cache management operations can be provided.

What am I missing?

Quoted 37 lines
---
 arch/riscv/Kconfig          | 1 -
 drivers/cache/Kconfig       | 2 +-
 drivers/soc/renesas/Kconfig | 2 +-
 3 files changed, 2 insertions(+), 3 deletions(-)
arch/riscv/Kconfig +0 -1
index d607ab0f7c6daf..0ac0b538379718 100644
@@ -277,7 +277,6 @@ config RISCV_DMA_NONCOHERENT
 
 config RISCV_NONSTANDARD_CACHE_OPS
 	bool
-	depends on RISCV_DMA_NONCOHERENT
 	help
 	  This enables function pointer support for non-standard noncoherent
 	  systems to handle cache management.
drivers/cache/Kconfig +1 -1
index a57677f908f3ba..d6e5e3abaad8af 100644
@@ -3,7 +3,7 @@ menu "Cache Drivers"
 
 config AX45MP_L2_CACHE
 	bool "Andes Technology AX45MP L2 Cache controller"
-	depends on RISCV_DMA_NONCOHERENT
+	depends on RISCV
 	select RISCV_NONSTANDARD_CACHE_OPS
 	help
 	  Support for the L2 cache controller on Andes Technology AX45MP platforms.
drivers/soc/renesas/Kconfig +0 -0
index 12040ce116a551..880c544bb2dfda 100644

drivers/soc/renesas/Kconfig config ARCH_R9A07G043 · line 338

Quoted 4 lines
drivers/soc/renesas/Kconfig +0 -1
@@ -335,7 +335,7 @@ config ARCH_R9A07G043
 	bool "RISC-V Platform support for RZ/Five"
 	depends on NONPORTABLE
 	select ARCH_RZG2L
-	select AX45MP_L2_CACHE if RISCV_DMA_NONCOHERENT

FWIW, this one is already gone in linux-next, as part of fixing some randconfig issues.

Cheers,
Conor.

Quoted 7 lines
drivers/soc/renesas/Kconfig +1 -0
+	select AX45MP_L2_CACHE
 	select DMA_GLOBAL_POOL
 	select ERRATA_ANDES if RISCV_SBI
 	select ERRATA_ANDES_CMO if ERRATA_ANDES
Signature · 1 line
2.39.2
#3 lore raw

Re: [PATCH 01/12] riscv: RISCV_NONSTANDARD_CACHE_OPS shouldn't depend on RISCV_DMA_NONCOHERENT

Quoted 6 lines · Conor Dooley

Hey,

Quoted 2 lines · Christoph Hellwig

RISCV_NONSTANDARD_CACHE_OPS is also used for the pmem cache maintenance helpers, which are built into the kernel unconditionally.

Quoted 9 lines

You surely have better insight than I do here, but is this actually required?
This patch seems to allow creation of a kernel where the cache maintenance operations could be used for pmem, but would be otherwise unavailable, which seems counter intuitive to me.

Why would someone want to provide the pmem helpers with cache maintenance operations, but not provide them generally?

Even if all your periphals are cache coherent (very common on server class hardware) you still need cache maintenance for pmem. No need to force the extra text size and runtime overhead for non-coherent DMA.

Quoted 4 lines

I also don't really understand what the unconditional nature of the pmem helpers has to do with anything, as this patch does not unconditionally provide any cache management operations, only relax the conditions under which the non-standard cache management operations can be provided.

They simply were broken if a platform had non-standard cache mem but only coherent DMA before. That's probably more a theoretical than practial case, but still worth fixing.

maintainer Acked-by
#4 lore raw

Re: [PATCH 01/12] riscv: RISCV_NONSTANDARD_CACHE_OPS shouldn't depend on RISCV_DMA_NONCOHERENT

Quoted 13 lines · Christoph Hellwig
Quoted 12 lines · Conor Dooley

Hey,

Quoted 2 lines · Christoph Hellwig

RISCV_NONSTANDARD_CACHE_OPS is also used for the pmem cache maintenance helpers, which are built into the kernel unconditionally.

You surely have better insight than I do here, but is this actually required?
This patch seems to allow creation of a kernel where the cache maintenance operations could be used for pmem, but would be otherwise unavailable, which seems counter intuitive to me.

Quoted 7 lines
Quoted 3 lines

Why would someone want to provide the pmem helpers with cache maintenance operations, but not provide them generally?

Even if all your periphals are cache coherent (very common on server class hardware) you still need cache maintenance for pmem. No need to force the extra text size and runtime overhead for non-coherent DMA.

Ah, right.

Quoted 8 lines
Quoted 4 lines

I also don't really understand what the unconditional nature of the pmem helpers has to do with anything, as this patch does not unconditionally provide any cache management operations, only relax the conditions under which the non-standard cache management operations can be provided.

They simply were broken if a platform had non-standard cache mem but only coherent DMA before. That's probably more a theoretical than practial case, but still worth fixing.

And this part of it makes more sense with the above use-case explained.

Thanks,
Conor.

#5 lore raw

PATCH 2/12 riscv: only select DMA_DIRECT_REMAP from RISCV_ISA_ZICBOM

In reply to Christoph Hellwig

RISCV_DMA_NONCOHERENT is also used for whacky non-standard non-coherent ops that use different hooks in dma-direct.

---
 arch/riscv/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/Kconfig +1 -1
index 0ac0b538379718..9c48fecc671918 100644
@@ -273,7 +273,6 @@ config RISCV_DMA_NONCOHERENT
 	select ARCH_HAS_SYNC_DMA_FOR_CPU
 	select ARCH_HAS_SYNC_DMA_FOR_DEVICE
 	select DMA_BOUNCE_UNALIGNED_KMALLOC if SWIOTLB
-	select DMA_DIRECT_REMAP if MMU
 
 config RISCV_NONSTANDARD_CACHE_OPS
 	bool
@@ -549,6 +548,7 @@ config RISCV_ISA_ZICBOM
 	depends on RISCV_ALTERNATIVE
 	default y
 	select RISCV_DMA_NONCOHERENT
+	select DMA_DIRECT_REMAP
 	help
 	   Adds support to dynamically detect the presence of the ZICBOM
 	   extension (Cache Block Management Operations) and enable its
Signature · 1 line
2.39.2
reviewer Reviewed-by on v1 2/12
#6 lore raw

Re: [PATCH 02/12] riscv: only select DMA_DIRECT_REMAP from RISCV_ISA_ZICBOM

Quoted 2 lines · Christoph Hellwig

RISCV_DMA_NONCOHERENT is also used for whacky non-standard non-coherent ops that use different hooks in dma-direct.

FWIW,

Quoted 25 lines
---
  arch/riscv/Kconfig | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/Kconfig +1 -1
index 0ac0b538379718..9c48fecc671918 100644
@@ -273,7 +273,6 @@ config RISCV_DMA_NONCOHERENT
  	select ARCH_HAS_SYNC_DMA_FOR_CPU
  	select ARCH_HAS_SYNC_DMA_FOR_DEVICE
  	select DMA_BOUNCE_UNALIGNED_KMALLOC if SWIOTLB
-	select DMA_DIRECT_REMAP if MMU
 
  config RISCV_NONSTANDARD_CACHE_OPS
  	bool
@@ -549,6 +548,7 @@ config RISCV_ISA_ZICBOM
  	depends on RISCV_ALTERNATIVE
  	default y
  	select RISCV_DMA_NONCOHERENT
+	select DMA_DIRECT_REMAP
  	help
  	   Adds support to dynamically detect the presence of the ZICBOM
  	   extension (Cache Block Management Operations) and enable its
Reviewed-by on v1 2/12
#7 lore raw

Re: [PATCH 02/12] riscv: only select DMA_DIRECT_REMAP from RISCV_ISA_ZICBOM

In reply to Christoph Hellwig
Quoted 4 lines · Christoph Hellwig

RISCV_DMA_NONCOHERENT is also used for whacky non-standard non-coherent ops that use different hooks in dma-direct.

Thanks,
Conor.

Quoted 27 lines
---
 arch/riscv/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/Kconfig +1 -1
index 0ac0b538379718..9c48fecc671918 100644
@@ -273,7 +273,6 @@ config RISCV_DMA_NONCOHERENT
 	select ARCH_HAS_SYNC_DMA_FOR_CPU
 	select ARCH_HAS_SYNC_DMA_FOR_DEVICE
 	select DMA_BOUNCE_UNALIGNED_KMALLOC if SWIOTLB
-	select DMA_DIRECT_REMAP if MMU
 
 config RISCV_NONSTANDARD_CACHE_OPS
 	bool
@@ -549,6 +548,7 @@ config RISCV_ISA_ZICBOM
 	depends on RISCV_ALTERNATIVE
 	default y
 	select RISCV_DMA_NONCOHERENT
+	select DMA_DIRECT_REMAP
 	help
 	   Adds support to dynamically detect the presence of the ZICBOM
 	   extension (Cache Block Management Operations) and enable its
Signature · 1 line
2.39.2
Reviewed-by Lad Prabhakar on v1 2/12
#8 lore raw

Re: [PATCH 02/12] riscv: only select DMA_DIRECT_REMAP from RISCV_ISA_ZICBOM

In reply to Christoph Hellwig
Quoted 9 lines · Christoph Hellwig

RISCV_DMA_NONCOHERENT is also used for whacky non-standard non-coherent ops that use different hooks in dma-direct.

---
 arch/riscv/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Cheers,
Prabhakar

Quoted 23 lines
arch/riscv/Kconfig +1 -2
index 0ac0b538379718..9c48fecc671918 100644
@@ -273,7 +273,6 @@ config RISCV_DMA_NONCOHERENT
        select ARCH_HAS_SYNC_DMA_FOR_CPU
        select ARCH_HAS_SYNC_DMA_FOR_DEVICE
        select DMA_BOUNCE_UNALIGNED_KMALLOC if SWIOTLB
-       select DMA_DIRECT_REMAP if MMU
 
 config RISCV_NONSTANDARD_CACHE_OPS
        bool
@@ -549,6 +548,7 @@ config RISCV_ISA_ZICBOM
        depends on RISCV_ALTERNATIVE
        default y
        select RISCV_DMA_NONCOHERENT
+       select DMA_DIRECT_REMAP
        help
           Adds support to dynamically detect the presence of the ZICBOM
           extension (Cache Block Management Operations) and enable its
--

2.39.2

#9 lore raw

PATCH 3/12 soc: renesas: ARCH_R9A07G043 depends on !RISCV_ISA_ZICBOM

In reply to Christoph Hellwig

ARCH_R9A07G043 has it's own non-standard global pool based DMA coherent allocator, which conflicts with the remap based RISCV_ISA_ZICBOM version. Add a proper dependency.

---
 drivers/soc/renesas/Kconfig | 1 +
 1 file changed, 1 insertion(+)
drivers/soc/renesas/Kconfig +1 -0
index 880c544bb2dfda..f1696d3b5018d0 100644
@@ -334,6 +334,7 @@ if RISCV
 config ARCH_R9A07G043
 	bool "RISC-V Platform support for RZ/Five"
 	depends on NONPORTABLE
+	depends on !RISCV_ISA_ZICBOM
 	select ARCH_RZG2L
 	select AX45MP_L2_CACHE
 	select DMA_GLOBAL_POOL
Signature · 1 line
2.39.2
Acked-by on v1 3/12
#10 lore raw

Re: [PATCH 03/12] soc: renesas: ARCH_R9A07G043 depends on !RISCV_ISA_ZICBOM

Quoted 3 lines · Christoph Hellwig

ARCH_R9A07G043 has it's own non-standard global pool based DMA coherent allocator, which conflicts with the remap based RISCV_ISA_ZICBOM version. Add a proper dependency.

Thanks,
Conor.

Quoted 21 lines
---
 drivers/soc/renesas/Kconfig | 1 +
 1 file changed, 1 insertion(+)
drivers/soc/renesas/Kconfig +1 -0
index 880c544bb2dfda..f1696d3b5018d0 100644
@@ -334,6 +334,7 @@ if RISCV
 config ARCH_R9A07G043
 	bool "RISC-V Platform support for RZ/Five"
 	depends on NONPORTABLE
+	depends on !RISCV_ISA_ZICBOM
 	select ARCH_RZG2L
 	select AX45MP_L2_CACHE
 	select DMA_GLOBAL_POOL
Signature · 1 line
2.39.2
Reviewed-by Lad Prabhakar on v1 3/12
#11 lore raw

Re: [PATCH 03/12] soc: renesas: ARCH_R9A07G043 depends on !RISCV_ISA_ZICBOM

In reply to Christoph Hellwig
Quoted 10 lines · Christoph Hellwig

ARCH_R9A07G043 has it's own non-standard global pool based DMA coherent allocator, which conflicts with the remap based RISCV_ISA_ZICBOM version. Add a proper dependency.

---
 drivers/soc/renesas/Kconfig | 1 +
 1 file changed, 1 insertion(+)

Cheers,
Prabhakar

Quoted 15 lines
drivers/soc/renesas/Kconfig +1 -1
index 880c544bb2dfda..f1696d3b5018d0 100644
@@ -334,6 +334,7 @@ if RISCV
 config ARCH_R9A07G043
        bool "RISC-V Platform support for RZ/Five"
        depends on NONPORTABLE
+       depends on !RISCV_ISA_ZICBOM
        select ARCH_RZG2L
        select AX45MP_L2_CACHE
        select DMA_GLOBAL_POOL
--

2.39.2

maintainer Acked-by on v1 3/12
#12 lore raw

Re: [PATCH 03/12] soc: renesas: ARCH_R9A07G043 depends on !RISCV_ISA_ZICBOM

In reply to Christoph Hellwig
Quoted 1 line · Christoph Hellwig

ARCH_R9A07G043 has it's own non-standard global pool based DMA coherent

its

Quoted 4 lines

allocator, which conflicts with the remap based RISCV_ISA_ZICBOM version. Add a proper dependency.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
#13 lore raw

PATCH 4/12 soc: renesas: select RISCV_DMA_NONCOHERENT from ARCH_R9A07G043

In reply to Christoph Hellwig

Selecting DMA_GLOBAL_POOL without the rest of the non-coherent DMA infrastructure does not make sense.

---
 drivers/soc/renesas/Kconfig | 1 +
 1 file changed, 1 insertion(+)
drivers/soc/renesas/Kconfig +1 -0
index f1696d3b5018d0..ea473b4150dfa8 100644
@@ -338,6 +338,7 @@ config ARCH_R9A07G043
 	select ARCH_RZG2L
 	select AX45MP_L2_CACHE
 	select DMA_GLOBAL_POOL
+	select RISCV_DMA_NONCOHERENT
 	select ERRATA_ANDES if RISCV_SBI
 	select ERRATA_ANDES_CMO if ERRATA_ANDES
 
Signature · 1 line
2.39.2
Acked-by on v1 4/12
#14 lore raw

Re: [PATCH 04/12] soc: renesas: select RISCV_DMA_NONCOHERENT from ARCH_R9A07G043

Quoted 13 lines · Christoph Hellwig

Selecting DMA_GLOBAL_POOL without the rest of the non-coherent DMA infrastructure does not make sense.

---
 drivers/soc/renesas/Kconfig | 1 +
 1 file changed, 1 insertion(+)
drivers/soc/renesas/Kconfig +0 -0
index f1696d3b5018d0..ea473b4150dfa8 100644

drivers/soc/renesas/Kconfig config ARCH_R9A07G043 · line 343

Quoted 6 lines
drivers/soc/renesas/Kconfig +1 -0
@@ -338,6 +338,7 @@ config ARCH_R9A07G043
 	select ARCH_RZG2L
 	select AX45MP_L2_CACHE
 	select DMA_GLOBAL_POOL
+	select RISCV_DMA_NONCOHERENT
 	select ERRATA_ANDES if RISCV_SBI
 	select ERRATA_ANDES_CMO if ERRATA_ANDES

Since this Kconfig menu has changed a bit in linux-next, the selects are unconditional here, and ERRATA_ANDES_CMO will in turn select RISCV_DMA_NONCOHERENT.

I don't think being more explicit hurts anyone though, so

Thanks,
Conor.

#15 lore raw

Re: [PATCH 04/12] soc: renesas: select RISCV_DMA_NONCOHERENT from ARCH_R9A07G043

Quoted 7 lines · Conor Dooley

drivers/soc/renesas/Kconfig config ARCH_R9A07G043 · line 343

Quoted 3 lines
drivers/soc/renesas/Kconfig +1 -0
+	select RISCV_DMA_NONCOHERENT
 	select ERRATA_ANDES if RISCV_SBI
 	select ERRATA_ANDES_CMO if ERRATA_ANDES

Since this Kconfig menu has changed a bit in linux-next, the selects are unconditional here, and ERRATA_ANDES_CMO will in turn select RISCV_DMA_NONCOHERENT.

Oh, looks like another patch landed there in linux-next. I had waited for the previous one go go upstream in -rc6. Not sure how to best handle this conflict.

#16 lore raw

Re: [PATCH 04/12] soc: renesas: select RISCV_DMA_NONCOHERENT from ARCH_R9A07G043

Hi Christoph,

Quoted 5 lines · Christoph Hellwig
Quoted 4 lines · Conor Dooley
Quoted 3 lines

+ select RISCV_DMA_NONCOHERENT
select ERRATA_ANDES if RISCV_SBI
select ERRATA_ANDES_CMO if ERRATA_ANDES

Quoted 7 lines
Quoted 3 lines

Since this Kconfig menu has changed a bit in linux-next, the selects are unconditional here, and ERRATA_ANDES_CMO will in turn select RISCV_DMA_NONCOHERENT.

Oh, looks like another patch landed there in linux-next. I had waited for the previous one go go upstream in -rc6. Not sure how to best handle this conflict.

I think the easiest is to ask soc to apply this series?

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
#17 lore raw

Re: [PATCH 04/12] soc: renesas: select RISCV_DMA_NONCOHERENT from ARCH_R9A07G043

Quoted 12 lines · Geert Uytterhoeven

Hi Christoph,

Quoted 9 lines · Christoph Hellwig
Quoted 7 lines · Conor Dooley
Quoted 3 lines

+ select RISCV_DMA_NONCOHERENT
select ERRATA_ANDES if RISCV_SBI
select ERRATA_ANDES_CMO if ERRATA_ANDES

Since this Kconfig menu has changed a bit in linux-next, the selects are unconditional here, and ERRATA_ANDES_CMO will in turn select RISCV_DMA_NONCOHERENT.

Quoted 5 lines
Quoted 3 lines

Oh, looks like another patch landed there in linux-next. I had waited for the previous one go go upstream in -rc6. Not sure how to best handle this conflict.

I think the easiest is to ask soc to apply this series?

I don't think pulling all the DMA bits into a random other tree
would be a good idea. I can hand off the first few bits, but I'd
need a stable branch to pull in after that. Which of the half a dozen soc trees we have in linux-next is this anyway?

#18 lore raw

Re: [PATCH 04/12] soc: renesas: select RISCV_DMA_NONCOHERENT from ARCH_R9A07G043

Hi Christoph,

Quoted 15 lines · Christoph Hellwig
Quoted 14 lines · Geert Uytterhoeven
Quoted 12 lines · Christoph Hellwig
Quoted 7 lines · Conor Dooley
Quoted 3 lines

+ select RISCV_DMA_NONCOHERENT
select ERRATA_ANDES if RISCV_SBI
select ERRATA_ANDES_CMO if ERRATA_ANDES

Since this Kconfig menu has changed a bit in linux-next, the selects are unconditional here, and ERRATA_ANDES_CMO will in turn select RISCV_DMA_NONCOHERENT.

Oh, looks like another patch landed there in linux-next. I had waited for the previous one go go upstream in -rc6. Not sure how to best handle this conflict.

Quoted 6 lines
Quoted 1 line

I think the easiest is to ask soc to apply this series?

I don't think pulling all the DMA bits into a random other tree
would be a good idea. I can hand off the first few bits, but I'd
need a stable branch to pull in after that. Which of the half a dozen soc trees we have in linux-next is this anyway?

The one and only https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git/

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
Reviewed-by Lad Prabhakar on v1 4/12
#19 lore raw

Re: [PATCH 04/12] soc: renesas: select RISCV_DMA_NONCOHERENT from ARCH_R9A07G043

In reply to Christoph Hellwig
Quoted 14 lines · Christoph Hellwig

Selecting DMA_GLOBAL_POOL without the rest of the non-coherent DMA infrastructure does not make sense.

---
 drivers/soc/renesas/Kconfig | 1 +
 1 file changed, 1 insertion(+)
drivers/soc/renesas/Kconfig +0 -0
index f1696d3b5018d0..ea473b4150dfa8 100644

drivers/soc/renesas/Kconfig config ARCH_R9A07G043 · line 341

Quoted 4 lines
drivers/soc/renesas/Kconfig +1 -0
@@ -338,6 +338,7 @@ config ARCH_R9A07G043
        select ARCH_RZG2L
        select AX45MP_L2_CACHE
        select DMA_GLOBAL_POOL
+       select RISCV_DMA_NONCOHERENT

Can we keep this alphabetical sorted please, with that fixed:

Cheers,
Prabhakar

Quoted 6 lines
drivers/soc/renesas/Kconfig +0 -1
        select ERRATA_ANDES if RISCV_SBI
        select ERRATA_ANDES_CMO if ERRATA_ANDES
 
--

2.39.2

maintainer Acked-by on v1 4/12
#20 lore raw

Re: [PATCH 04/12] soc: renesas: select RISCV_DMA_NONCOHERENT from ARCH_R9A07G043

In reply to Christoph Hellwig
Quoted 13 lines · Christoph Hellwig

Selecting DMA_GLOBAL_POOL without the rest of the non-coherent DMA infrastructure does not make sense.

---
 drivers/soc/renesas/Kconfig | 1 +
 1 file changed, 1 insertion(+)
drivers/soc/renesas/Kconfig +0 -0
index f1696d3b5018d0..ea473b4150dfa8 100644

drivers/soc/renesas/Kconfig config ARCH_R9A07G043 · line 343

Quoted 6 lines
drivers/soc/renesas/Kconfig +1 -0
@@ -338,6 +338,7 @@ config ARCH_R9A07G043
        select ARCH_RZG2L
        select AX45MP_L2_CACHE
        select DMA_GLOBAL_POOL
+       select RISCV_DMA_NONCOHERENT
        select ERRATA_ANDES if RISCV_SBI
        select ERRATA_ANDES_CMO if ERRATA_ANDES

With proper sort order, and rebased to soc/for-next:

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
#21 lore raw

PATCH 5/12 dma-direct: add depdenencies to CONFIG_DMA_GLOBAL_POOL

In reply to Christoph Hellwig

CONFIG_DMA_GLOBAL_POOL can't be combined with other DMA coherent allocators. Add dependencies to Kconfig to document this, and make kconfig complain about unment dependencies if someone tries.

---
 kernel/dma/Kconfig | 2 ++
 1 file changed, 2 insertions(+)
kernel/dma/Kconfig +2 -0
index f488997b071712..4524db877eba36 100644
@@ -135,6 +135,8 @@ config DMA_COHERENT_POOL
 
 config DMA_GLOBAL_POOL
 	select DMA_DECLARE_COHERENT
+	depends on !ARCH_HAS_DMA_SET_UNCACHED
+	depends on !DMA_DIRECT_REMAP
 	bool
 
 config DMA_DIRECT_REMAP
Signature · 1 line
2.39.2
reviewer Reviewed-by on v1 5/12
#22 lore raw

Re: [PATCH 05/12] dma-direct: add depdenencies to CONFIG_DMA_GLOBAL_POOL

Quoted 3 lines · Christoph Hellwig

CONFIG_DMA_GLOBAL_POOL can't be combined with other DMA coherent allocators. Add dependencies to Kconfig to document this, and make kconfig complain about unment dependencies if someone tries.

Quoted 18 lines
---
  kernel/dma/Kconfig | 2 ++
  1 file changed, 2 insertions(+)
kernel/dma/Kconfig +2 -0
index f488997b071712..4524db877eba36 100644
@@ -135,6 +135,8 @@ config DMA_COHERENT_POOL
 
  config DMA_GLOBAL_POOL
  	select DMA_DECLARE_COHERENT
+	depends on !ARCH_HAS_DMA_SET_UNCACHED
+	depends on !DMA_DIRECT_REMAP
  	bool
 
  config DMA_DIRECT_REMAP
Reviewed-by Lad Prabhakar on v1 5/12
#23 lore raw

Re: [PATCH 05/12] dma-direct: add depdenencies to CONFIG_DMA_GLOBAL_POOL

In reply to Christoph Hellwig
Quoted 10 lines · Christoph Hellwig

CONFIG_DMA_GLOBAL_POOL can't be combined with other DMA coherent allocators. Add dependencies to Kconfig to document this, and make kconfig complain about unment dependencies if someone tries.

---
 kernel/dma/Kconfig | 2 ++
 1 file changed, 2 insertions(+)

Cheers,
Prabhakar

Quoted 16 lines
kernel/dma/Kconfig +2 -1
index f488997b071712..4524db877eba36 100644
@@ -135,6 +135,8 @@ config DMA_COHERENT_POOL
 
 config DMA_GLOBAL_POOL
        select DMA_DECLARE_COHERENT
+       depends on !ARCH_HAS_DMA_SET_UNCACHED
+       depends on !DMA_DIRECT_REMAP
        bool
 
 config DMA_DIRECT_REMAP
--

2.39.2

#24 lore raw

PATCH 6/12 dma-direct: add a CONFIG_ARCH_DMA_ALLOC symbol

In reply to Christoph Hellwig

Instead of using arch_dma_alloc if none of the generic coherent allocators are used, require the architectures to explicitly opt into providing it. This will used to deal with the case of m68knommu and coldfire where we can't do any coherent allocations whatsoever, and also makes it clear that arch_dma_alloc is a last resort.

---
 arch/arm/Kconfig    |  1 +
 arch/m68k/Kconfig   |  1 +
 arch/parisc/Kconfig |  1 +
 kernel/dma/Kconfig  |  9 +++++++++
 kernel/dma/direct.c | 12 ++----------
 5 files changed, 14 insertions(+), 10 deletions(-)
arch/arm/Kconfig +1 -0
index 9557808e8937b1..a3fdf584278f86 100644
@@ -4,6 +4,7 @@ config ARM
 	default y
 	select ARCH_32BIT_OFF_T
 	select ARCH_CORRECT_STACKTRACE_ON_KRETPROBE if HAVE_KRETPROBES && FRAME_POINTER && !ARM_UNWIND
+	select ARCH_DMA_ALLOC if MMU
 	select ARCH_HAS_BINFMT_FLAT
 	select ARCH_HAS_CPU_FINALIZE_INIT if MMU
 	select ARCH_HAS_CURRENT_STACK_POINTER
arch/m68k/Kconfig +1 -0
index 3e318bf9504c5b..0430b8ba6b5cc6 100644
@@ -3,6 +3,7 @@ config M68K
 	bool
 	default y
 	select ARCH_32BIT_OFF_T
+	select ARCH_DMA_ALLOC if !MMU || COLDFIRE
 	select ARCH_HAS_BINFMT_FLAT
 	select ARCH_HAS_CPU_FINALIZE_INIT if MMU
 	select ARCH_HAS_CURRENT_STACK_POINTER
arch/parisc/Kconfig +1 -0
index a15ab147af2e07..30a4916fa9b0cc 100644
@@ -3,6 +3,7 @@ config PARISC
 	def_bool y
 	select ALTERNATE_USER_ADDRESS_SPACE
 	select ARCH_32BIT_OFF_T if !64BIT
+	select ARCH_DMA_ALLOC if PA11
 	select ARCH_MIGHT_HAVE_PC_PARPORT
 	select HAVE_FUNCTION_TRACER
 	select HAVE_FUNCTION_GRAPH_TRACER
kernel/dma/Kconfig +9 -0
index 4524db877eba36..515d2063b509ac 100644
@@ -144,6 +144,15 @@ config DMA_DIRECT_REMAP
 	select DMA_COHERENT_POOL
 	select DMA_NONCOHERENT_MMAP
 
+#
+# Fallback to arch code for DMA allocations.  This should eventually go away.
+#
+config ARCH_DMA_ALLOC
+	depends on !ARCH_HAS_DMA_SET_UNCACHED
+	depends on !DMA_DIRECT_REMAP
+	depends on !DMA_GLOBAL_POOL
+	bool
+
 config DMA_CMA
 	bool "DMA Contiguous Memory Allocator"
 	depends on HAVE_DMA_CONTIGUOUS && CMA
kernel/dma/direct.c +2 -10
index 9596ae1aa0dacf..ec410af1d8a14e 100644
@@ -220,13 +220,7 @@ void *dma_direct_alloc(struct device *dev, size_t size,
 		return dma_direct_alloc_no_mapping(dev, size, dma_handle, gfp);
 
 	if (!dev_is_dma_coherent(dev)) {
-		/*
-		 * Fallback to the arch handler if it exists.  This should
-		 * eventually go away.
-		 */
-		if (!IS_ENABLED(CONFIG_ARCH_HAS_DMA_SET_UNCACHED) &&
-		    !IS_ENABLED(CONFIG_DMA_DIRECT_REMAP) &&
-		    !IS_ENABLED(CONFIG_DMA_GLOBAL_POOL) &&
+		if (IS_ENABLED(CONFIG_ARCH_DMA_ALLOC) &&
 		    !is_swiotlb_for_alloc(dev))
 			return arch_dma_alloc(dev, size, dma_handle, gfp,
 					      attrs);
@@ -330,9 +324,7 @@ void dma_direct_free(struct device *dev, size_t size,
 		return;
 	}
 
-	if (!IS_ENABLED(CONFIG_ARCH_HAS_DMA_SET_UNCACHED) &&
-	    !IS_ENABLED(CONFIG_DMA_DIRECT_REMAP) &&
-	    !IS_ENABLED(CONFIG_DMA_GLOBAL_POOL) &&
+	if (IS_ENABLED(CONFIG_ARCH_DMA_ALLOC) &&
 	    !dev_is_dma_coherent(dev) &&
 	    !is_swiotlb_for_alloc(dev)) {
 		arch_dma_free(dev, size, cpu_addr, dma_addr, attrs);
Signature · 1 line
2.39.2
reviewer Reviewed-by on v1 6/12
#25 lore raw

Re: [PATCH 06/12] dma-direct: add a CONFIG_ARCH_DMA_ALLOC symbol

Quoted 5 lines · Christoph Hellwig

Instead of using arch_dma_alloc if none of the generic coherent allocators are used, require the architectures to explicitly opt into providing it. This will used to deal with the case of m68knommu and coldfire where we can't do any coherent allocations whatsoever, and also makes it clear that arch_dma_alloc is a last resort.

With one miniscule nit that possibly ARCH_HAS_DMA_ALLOC might be a little more consistent with other symbol names in this area (but feel free to disagree),

Quoted 95 lines
---
  arch/arm/Kconfig    |  1 +
  arch/m68k/Kconfig   |  1 +
  arch/parisc/Kconfig |  1 +
  kernel/dma/Kconfig  |  9 +++++++++
  kernel/dma/direct.c | 12 ++----------
  5 files changed, 14 insertions(+), 10 deletions(-)
arch/arm/Kconfig +1 -0
index 9557808e8937b1..a3fdf584278f86 100644
@@ -4,6 +4,7 @@ config ARM
  	default y
  	select ARCH_32BIT_OFF_T
  	select ARCH_CORRECT_STACKTRACE_ON_KRETPROBE if HAVE_KRETPROBES && FRAME_POINTER && !ARM_UNWIND
+	select ARCH_DMA_ALLOC if MMU
  	select ARCH_HAS_BINFMT_FLAT
  	select ARCH_HAS_CPU_FINALIZE_INIT if MMU
  	select ARCH_HAS_CURRENT_STACK_POINTER
arch/m68k/Kconfig +1 -0
index 3e318bf9504c5b..0430b8ba6b5cc6 100644
@@ -3,6 +3,7 @@ config M68K
  	bool
  	default y
  	select ARCH_32BIT_OFF_T
+	select ARCH_DMA_ALLOC if !MMU || COLDFIRE
  	select ARCH_HAS_BINFMT_FLAT
  	select ARCH_HAS_CPU_FINALIZE_INIT if MMU
  	select ARCH_HAS_CURRENT_STACK_POINTER
arch/parisc/Kconfig +1 -0
index a15ab147af2e07..30a4916fa9b0cc 100644
@@ -3,6 +3,7 @@ config PARISC
  	def_bool y
  	select ALTERNATE_USER_ADDRESS_SPACE
  	select ARCH_32BIT_OFF_T if !64BIT
+	select ARCH_DMA_ALLOC if PA11
  	select ARCH_MIGHT_HAVE_PC_PARPORT
  	select HAVE_FUNCTION_TRACER
  	select HAVE_FUNCTION_GRAPH_TRACER
kernel/dma/Kconfig +9 -0
index 4524db877eba36..515d2063b509ac 100644
@@ -144,6 +144,15 @@ config DMA_DIRECT_REMAP
  	select DMA_COHERENT_POOL
  	select DMA_NONCOHERENT_MMAP
 
+#
+# Fallback to arch code for DMA allocations.  This should eventually go away.
+#
+config ARCH_DMA_ALLOC
+	depends on !ARCH_HAS_DMA_SET_UNCACHED
+	depends on !DMA_DIRECT_REMAP
+	depends on !DMA_GLOBAL_POOL
+	bool
+
  config DMA_CMA
  	bool "DMA Contiguous Memory Allocator"
  	depends on HAVE_DMA_CONTIGUOUS && CMA
kernel/dma/direct.c +2 -10
index 9596ae1aa0dacf..ec410af1d8a14e 100644
@@ -220,13 +220,7 @@ void *dma_direct_alloc(struct device *dev, size_t size,
  		return dma_direct_alloc_no_mapping(dev, size, dma_handle, gfp);
 
  	if (!dev_is_dma_coherent(dev)) {
-		/*
-		 * Fallback to the arch handler if it exists.  This should
-		 * eventually go away.
-		 */
-		if (!IS_ENABLED(CONFIG_ARCH_HAS_DMA_SET_UNCACHED) &&
-		    !IS_ENABLED(CONFIG_DMA_DIRECT_REMAP) &&
-		    !IS_ENABLED(CONFIG_DMA_GLOBAL_POOL) &&
+		if (IS_ENABLED(CONFIG_ARCH_DMA_ALLOC) &&
  		    !is_swiotlb_for_alloc(dev))
  			return arch_dma_alloc(dev, size, dma_handle, gfp,
  					      attrs);
@@ -330,9 +324,7 @@ void dma_direct_free(struct device *dev, size_t size,
  		return;
  	}
 
-	if (!IS_ENABLED(CONFIG_ARCH_HAS_DMA_SET_UNCACHED) &&
-	    !IS_ENABLED(CONFIG_DMA_DIRECT_REMAP) &&
-	    !IS_ENABLED(CONFIG_DMA_GLOBAL_POOL) &&
+	if (IS_ENABLED(CONFIG_ARCH_DMA_ALLOC) &&
  	    !dev_is_dma_coherent(dev) &&
  	    !is_swiotlb_for_alloc(dev)) {
  		arch_dma_free(dev, size, cpu_addr, dma_addr, attrs);
#26 lore raw

PATCH 7/12 dma-direct: simplify the use atomic pool logic in dma_direct_alloc

In reply to Christoph Hellwig

The logic in dma_direct_alloc when to use the atomic pool vs remapping grew a bit unreadable. Consolidate it into a single check, and clean up the set_uncached vs remap logic a bit as well.

---
 kernel/dma/direct.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)
kernel/dma/direct.c +10 -15
index ec410af1d8a14e..1327d04fa32a25 100644
@@ -234,27 +234,22 @@ void *dma_direct_alloc(struct device *dev, size_t size,
 					dma_handle);
 
 		/*
-		 * Otherwise remap if the architecture is asking for it.  But
-		 * given that remapping memory is a blocking operation we'll
-		 * instead have to dip into the atomic pools.
+		 * Otherwise we require the architecture to either be able to
+		 * mark arbitrary parts of the kernel direct mapping uncached,
+		 * or remapped it uncached.
 		 */
+		set_uncached = IS_ENABLED(CONFIG_ARCH_HAS_DMA_SET_UNCACHED);
 		remap = IS_ENABLED(CONFIG_DMA_DIRECT_REMAP);
-		if (remap) {
-			if (dma_direct_use_pool(dev, gfp))
-				return dma_direct_alloc_from_pool(dev, size,
-						dma_handle, gfp);
-		} else {
-			if (!IS_ENABLED(CONFIG_ARCH_HAS_DMA_SET_UNCACHED))
-				return NULL;
-			set_uncached = true;
-		}
+		if (!set_uncached && !remap)
+			return NULL;
 	}
 
 	/*
-	 * Decrypting memory may block, so allocate the memory from the atomic
-	 * pools if we can't block.
+	 * Remapping or decrypting memory may block, allocate the memory from
+	 * the atomic pools instead if we aren't allowed block.
 	 */
-	if (force_dma_unencrypted(dev) && dma_direct_use_pool(dev, gfp))
+	if ((remap || force_dma_unencrypted(dev)) &&
+	    dma_direct_use_pool(dev, gfp))
 		return dma_direct_alloc_from_pool(dev, size, dma_handle, gfp);
 
 	/* we always manually zero the memory once we are done */
Signature · 1 line
2.39.2
reviewer Reviewed-by on v1 7/12
#27 lore raw

Re: [PATCH 07/12] dma-direct: simplify the use atomic pool logic in dma_direct_alloc

Quoted 3 lines · Christoph Hellwig

The logic in dma_direct_alloc when to use the atomic pool vs remapping grew a bit unreadable. Consolidate it into a single check, and clean up the set_uncached vs remap logic a bit as well.

Quoted 47 lines
---
  kernel/dma/direct.c | 25 ++++++++++---------------
  1 file changed, 10 insertions(+), 15 deletions(-)
kernel/dma/direct.c +10 -15
index ec410af1d8a14e..1327d04fa32a25 100644
@@ -234,27 +234,22 @@ void *dma_direct_alloc(struct device *dev, size_t size,
  					dma_handle);
 
  		/*
-		 * Otherwise remap if the architecture is asking for it.  But
-		 * given that remapping memory is a blocking operation we'll
-		 * instead have to dip into the atomic pools.
+		 * Otherwise we require the architecture to either be able to
+		 * mark arbitrary parts of the kernel direct mapping uncached,
+		 * or remapped it uncached.
  		 */
+		set_uncached = IS_ENABLED(CONFIG_ARCH_HAS_DMA_SET_UNCACHED);
  		remap = IS_ENABLED(CONFIG_DMA_DIRECT_REMAP);
-		if (remap) {
-			if (dma_direct_use_pool(dev, gfp))
-				return dma_direct_alloc_from_pool(dev, size,
-						dma_handle, gfp);
-		} else {
-			if (!IS_ENABLED(CONFIG_ARCH_HAS_DMA_SET_UNCACHED))
-				return NULL;
-			set_uncached = true;
-		}
+		if (!set_uncached && !remap)
+			return NULL;
  	}
 
  	/*
-	 * Decrypting memory may block, so allocate the memory from the atomic
-	 * pools if we can't block.
+	 * Remapping or decrypting memory may block, allocate the memory from
+	 * the atomic pools instead if we aren't allowed block.
  	 */
-	if (force_dma_unencrypted(dev) && dma_direct_use_pool(dev, gfp))
+	if ((remap || force_dma_unencrypted(dev)) &&
+	    dma_direct_use_pool(dev, gfp))
  		return dma_direct_alloc_from_pool(dev, size, dma_handle, gfp);
 
  	/* we always manually zero the memory once we are done */
#28 lore raw

PATCH 8/12 dma-direct: warn when coherent allocations aren't supported

In reply to Christoph Hellwig

Log a warning once when dma_alloc_coherent fails because the platform does not support coherent allocations at all.

---
 kernel/dma/direct.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/dma/direct.c +3 -1
index 1327d04fa32a25..fddfea3b2fe173 100644
@@ -240,8 +240,10 @@ void *dma_direct_alloc(struct device *dev, size_t size,
 		 */
 		set_uncached = IS_ENABLED(CONFIG_ARCH_HAS_DMA_SET_UNCACHED);
 		remap = IS_ENABLED(CONFIG_DMA_DIRECT_REMAP);
-		if (!set_uncached && !remap)
+		if (!set_uncached && !remap) {
+			pr_warn_once("coherent DMA allocations not supported on this platform.\n");
 			return NULL;
+		}
 	}
 
 	/*
Signature · 1 line
2.39.2
reviewer Reviewed-by on v1 8/12
#29 lore raw

Re: [PATCH 08/12] dma-direct: warn when coherent allocations aren't supported

Quoted 2 lines · Christoph Hellwig

Log a warning once when dma_alloc_coherent fails because the platform does not support coherent allocations at all.

Quoted 21 lines
---
  kernel/dma/direct.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
kernel/dma/direct.c +3 -1
index 1327d04fa32a25..fddfea3b2fe173 100644
@@ -240,8 +240,10 @@ void *dma_direct_alloc(struct device *dev, size_t size,
  		 */
  		set_uncached = IS_ENABLED(CONFIG_ARCH_HAS_DMA_SET_UNCACHED);
  		remap = IS_ENABLED(CONFIG_DMA_DIRECT_REMAP);
-		if (!set_uncached && !remap)
+		if (!set_uncached && !remap) {
+			pr_warn_once("coherent DMA allocations not supported on this platform.\n");
  			return NULL;
+		}
  	}
 
  	/*
#30 lore raw

PATCH 9/12 m68k: use the coherent DMA code for coldfire without data cache

In reply to Christoph Hellwig

Coldfire cores configured without a data cache are DMA coherent and should thus simply use the simple coherent version of dma-direct.

Introduce a new COLDFIRE_COHERENT_DMA Kconfig symbol as a convenient short hand for such configurations, and a M68K_NONCOHERENT_DMA symbol for all cases where we need to build non-coherent DMA infrastructure to simplify the Kconfig and code conditionals.

Not building the non-coherent DMA code slightly reduces the code size for such configurations.

Numers for m5249evb_defconfig below:

text data bss dec hex filename
2896158 401052 65392 3362602 334f2a vmlinux.before
2895166 400988 65392 3361546 334b0a vmlinux.after

---
 arch/m68k/Kconfig         |  8 ++++----
 arch/m68k/Kconfig.cpu     | 12 ++++++++++++
 arch/m68k/kernel/Makefile |  2 +-
 arch/m68k/kernel/dma.c    |  2 +-
 4 files changed, 18 insertions(+), 6 deletions(-)
arch/m68k/Kconfig +4 -4
index 0430b8ba6b5cc6..6c585eae89f4dc 100644
@@ -3,19 +3,19 @@ config M68K
 	bool
 	default y
 	select ARCH_32BIT_OFF_T
-	select ARCH_DMA_ALLOC if !MMU || COLDFIRE
+	select ARCH_DMA_ALLOC if M68K_NONCOHERENT_DMA && COLDFIRE
 	select ARCH_HAS_BINFMT_FLAT
 	select ARCH_HAS_CPU_FINALIZE_INIT if MMU
 	select ARCH_HAS_CURRENT_STACK_POINTER
-	select ARCH_HAS_DMA_PREP_COHERENT if HAS_DMA && MMU && !COLDFIRE
-	select ARCH_HAS_SYNC_DMA_FOR_DEVICE if HAS_DMA
+	select ARCH_HAS_DMA_PREP_COHERENT if M68K_NONCOHERENT_DMA && !COLDFIRE
+	select ARCH_HAS_SYNC_DMA_FOR_DEVICE if M68K_NONCOHERENT_DMA
 	select ARCH_HAVE_NMI_SAFE_CMPXCHG if RMW_INSNS
 	select ARCH_MIGHT_HAVE_PC_PARPORT if ISA
 	select ARCH_NO_PREEMPT if !COLDFIRE
 	select ARCH_USE_MEMTEST if MMU_MOTOROLA
 	select ARCH_WANT_IPC_PARSE_VERSION
 	select BINFMT_FLAT_ARGVP_ENVP_ON_STACK
-	select DMA_DIRECT_REMAP if HAS_DMA && MMU && !COLDFIRE
+	select DMA_DIRECT_REMAP if M68K_NONCOHERENT_DMA && !COLDFIRE
 	select GENERIC_ATOMIC64
 	select GENERIC_CPU_DEVICES
 	select GENERIC_IOMAP
arch/m68k/Kconfig.cpu +12 -0
index b826e9c677b2ae..e8905d38c714c4 100644
@@ -535,3 +535,15 @@ config CACHE_COPYBACK
 	  The ColdFire CPU cache is set into Copy-back mode.
 endchoice
 endif # HAVE_CACHE_CB
+
+# Coldfire cores that do not have a data cache configured can do coherent DMA.
+config COLDFIRE_COHERENT_DMA
+	bool
+	default y
+	depends on COLDFIRE
+	depends on !HAVE_CACHE_CB && !CONFIG_CACHE_D && !CONFIG_CACHE_BOTH
+
+config M68K_NONCOHERENT_DMA
+	bool
+	default y
+	depends on HAS_DMA && !COLDFIRE_COHERENT_DMA
arch/m68k/kernel/Makefile +1 -1
index af015447dfb4c1..01fb69a5095f43 100644
@@ -23,7 +23,7 @@ obj-$(CONFIG_MMU_MOTOROLA) += ints.o vectors.o
 obj-$(CONFIG_MMU_SUN3) += ints.o vectors.o
 obj-$(CONFIG_PCI) += pcibios.o
 
-obj-$(CONFIG_HAS_DMA)	+= dma.o
+obj-$(CONFIG_M68K_NONCOHERENT_DMA) += dma.o
 
 obj-$(CONFIG_KEXEC)		+= machine_kexec.o relocate_kernel.o
 obj-$(CONFIG_BOOTINFO_PROC)	+= bootinfo_proc.o
arch/m68k/kernel/dma.c +1 -1
index 2e192a5df949bb..f83870cfa79b37 100644
@@ -17,7 +17,7 @@
 
 #include <asm/cacheflush.h>
 
-#if defined(CONFIG_MMU) && !defined(CONFIG_COLDFIRE)
+#ifndef CONFIG_COLDFIRE
 void arch_dma_prep_coherent(struct page *page, size_t size)
 {
 	cache_push(page_to_phys(page), size);
Signature · 1 line
2.39.2
maintainer Acked-by on v1 9/12
#31 lore raw

Re: [PATCH 09/12] m68k: use the coherent DMA code for coldfire without data cache

Quoted 11 lines · Christoph Hellwig

Coldfire cores configured without a data cache are DMA coherent and should thus simply use the simple coherent version of dma-direct.

Introduce a new COLDFIRE_COHERENT_DMA Kconfig symbol as a convenient short hand for such configurations, and a M68K_NONCOHERENT_DMA symbol for all cases where we need to build non-coherent DMA infrastructure to simplify the Kconfig and code conditionals.

Not building the non-coherent DMA code slightly reduces the code size for such configurations.

Quoted 7 lines

Numers for m5249evb_defconfig below:

text data bss dec hex filename

2896158  401052   65392 3362602  334f2a vmlinux.before
2895166  400988   65392 3361546  334b0a vmlinux.after

The m68kclassic-with-MMU parts look fine to me, so

I'll defer to Greg for the nommu and Coldfire parts...

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
#32 lore raw

Re: [PATCH 09/12] m68k: use the coherent DMA code for coldfire without data cache

In reply to Christoph Hellwig

Hi Christoph,

Quoted 58 lines · Christoph Hellwig

Coldfire cores configured without a data cache are DMA coherent and should thus simply use the simple coherent version of dma-direct.

Introduce a new COLDFIRE_COHERENT_DMA Kconfig symbol as a convenient short hand for such configurations, and a M68K_NONCOHERENT_DMA symbol for all cases where we need to build non-coherent DMA infrastructure to simplify the Kconfig and code conditionals.

Not building the non-coherent DMA code slightly reduces the code size for such configurations.

Numers for m5249evb_defconfig below:

text data bss dec hex filename
2896158 401052 65392 3362602 334f2a vmlinux.before
2895166 400988 65392 3361546 334b0a vmlinux.after

---
  arch/m68k/Kconfig         |  8 ++++----
  arch/m68k/Kconfig.cpu     | 12 ++++++++++++
  arch/m68k/kernel/Makefile |  2 +-
  arch/m68k/kernel/dma.c    |  2 +-
  4 files changed, 18 insertions(+), 6 deletions(-)
arch/m68k/Kconfig +4 -4
index 0430b8ba6b5cc6..6c585eae89f4dc 100644
@@ -3,19 +3,19 @@ config M68K
  	bool
  	default y
  	select ARCH_32BIT_OFF_T
-	select ARCH_DMA_ALLOC if !MMU || COLDFIRE
+	select ARCH_DMA_ALLOC if M68K_NONCOHERENT_DMA && COLDFIRE
  	select ARCH_HAS_BINFMT_FLAT
  	select ARCH_HAS_CPU_FINALIZE_INIT if MMU
  	select ARCH_HAS_CURRENT_STACK_POINTER
-	select ARCH_HAS_DMA_PREP_COHERENT if HAS_DMA && MMU && !COLDFIRE
-	select ARCH_HAS_SYNC_DMA_FOR_DEVICE if HAS_DMA
+	select ARCH_HAS_DMA_PREP_COHERENT if M68K_NONCOHERENT_DMA && !COLDFIRE
+	select ARCH_HAS_SYNC_DMA_FOR_DEVICE if M68K_NONCOHERENT_DMA
  	select ARCH_HAVE_NMI_SAFE_CMPXCHG if RMW_INSNS
  	select ARCH_MIGHT_HAVE_PC_PARPORT if ISA
  	select ARCH_NO_PREEMPT if !COLDFIRE
  	select ARCH_USE_MEMTEST if MMU_MOTOROLA
  	select ARCH_WANT_IPC_PARSE_VERSION
  	select BINFMT_FLAT_ARGVP_ENVP_ON_STACK
-	select DMA_DIRECT_REMAP if HAS_DMA && MMU && !COLDFIRE
+	select DMA_DIRECT_REMAP if M68K_NONCOHERENT_DMA && !COLDFIRE
  	select GENERIC_ATOMIC64
  	select GENERIC_CPU_DEVICES
  	select GENERIC_IOMAP
arch/m68k/Kconfig.cpu +0 -0
index b826e9c677b2ae..e8905d38c714c4 100644

arch/m68k/Kconfig.cpu config CACHE_COPYBACK · line 544

Quoted 10 lines
arch/m68k/Kconfig.cpu +7 -0
@@ -535,3 +535,15 @@ config CACHE_COPYBACK
  	  The ColdFire CPU cache is set into Copy-back mode.
  endchoice
  endif # HAVE_CACHE_CB
+
+# Coldfire cores that do not have a data cache configured can do coherent DMA.
+config COLDFIRE_COHERENT_DMA
+	bool
+	default y
+	depends on COLDFIRE
+	depends on !HAVE_CACHE_CB && !CONFIG_CACHE_D && !CONFIG_CACHE_BOTH
                                      ^^^^^^             ^^^^^^

This needs to be "depends on !HAVE_CACHE_CB && !CACHE_D && !CACHE_BOTH".

Regards
Greg

Quoted 31 lines
arch/m68k/Kconfig.cpu +5 -0
+
+config M68K_NONCOHERENT_DMA
+	bool
+	default y
+	depends on HAS_DMA && !COLDFIRE_COHERENT_DMA
arch/m68k/kernel/Makefile +1 -1
index af015447dfb4c1..01fb69a5095f43 100644
@@ -23,7 +23,7 @@ obj-$(CONFIG_MMU_MOTOROLA) += ints.o vectors.o
  obj-$(CONFIG_MMU_SUN3) += ints.o vectors.o
  obj-$(CONFIG_PCI) += pcibios.o
 
-obj-$(CONFIG_HAS_DMA)	+= dma.o
+obj-$(CONFIG_M68K_NONCOHERENT_DMA) += dma.o
 
  obj-$(CONFIG_KEXEC)		+= machine_kexec.o relocate_kernel.o
  obj-$(CONFIG_BOOTINFO_PROC)	+= bootinfo_proc.o
arch/m68k/kernel/dma.c +1 -1
index 2e192a5df949bb..f83870cfa79b37 100644
@@ -17,7 +17,7 @@
 
  #include <asm/cacheflush.h>
 
-#if defined(CONFIG_MMU) && !defined(CONFIG_COLDFIRE)
+#ifndef CONFIG_COLDFIRE
  void arch_dma_prep_coherent(struct page *page, size_t size)
  {
  	cache_push(page_to_phys(page), size);
#33 lore raw

PATCH 10/12 net: fec: use dma_alloc_noncoherent for data cache enabled coldfire

In reply to Christoph Hellwig

Coldfire platforms with data caches can't properly implement dma_alloc_coherent and currently just return noncoherent memory from dma_alloc_coherent.

The fec driver than works around this with a flush of all caches in the receive path. Make this hack a little less bad by using the explicit dma_alloc_noncoherent API and documenting the hacky cache flushes so that the DMA API level hack can be removed.

Also replace the check for CONFIG_M532x for said hack with a check for COLDFIRE && !COLDFIRE_COHERENT_DMA. While m532x is the only such platform with a fec module, this makes the code more consistent and easier to follow.

---
 drivers/net/ethernet/freescale/fec_main.c | 86 ++++++++++++++++++++---
 1 file changed, 76 insertions(+), 10 deletions(-)
drivers/net/ethernet/freescale/fec_main.c +76 -10
index 77c8e9cfb44562..3fc3444402622b 100644
@@ -406,6 +406,70 @@ static void fec_dump(struct net_device *ndev)
 	} while (bdp != txq->bd.base);
 }
 
+/*
+ * Coldfire does not support DMA coherent allocations, and has historically used
+ * a band-aid with a manual flush in fec_enet_rx_queue.
+ */
+#if defined(CONFIG_COLDFIRE) && !defined(CONFIG_COLDFIRE_COHERENT_DMA)
+static void *fec_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
+		gfp_t gfp)
+{
+	return dma_alloc_noncoherent(dev, size, handle, DMA_BIDIRECTIONAL, gfp);
+}
+
+static void fec_dma_free(struct device *dev, size_t size, void *cpu_addr,
+		dma_addr_t handle)
+{
+	dma_free_noncoherent(dev, size, cpu_addr, handle, DMA_BIDIRECTIONAL);
+}
+#else /* CONFIG_COLDFIRE && !CONFIG_COLDFIRE_COHERENT_DMA */
+static void *fec_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
+		gfp_t gfp)
+{
+	return dma_alloc_coherent(dev, size, handle, gfp);
+}
+
+static void fec_dma_free(struct device *dev, size_t size, void *cpu_addr,
+		dma_addr_t handle)
+{
+	dma_free_coherent(dev, size, cpu_addr, handle);
+}
+#endif /* !CONFIG_COLDFIRE && !CONFIG_COLDFIRE_COHERENT_DMA */
+
+struct fec_dma_devres {
+	size_t		size;
+	void		*vaddr;
+	dma_addr_t	dma_handle;
+};
+
+static void fec_dmam_release(struct device *dev, void *res)
+{
+	struct fec_dma_devres *this = res;
+
+	fec_dma_free(dev, this->size, this->vaddr, this->dma_handle);
+}
+
+static void *fec_dmam_alloc(struct device *dev, size_t size, dma_addr_t *handle,
+		gfp_t gfp)
+{
+	struct fec_dma_devres *dr;
+	void *vaddr;
+
+	dr = devres_alloc(fec_dmam_release, sizeof(*dr), gfp);
+	if (!dr)
+		return NULL;
+	vaddr = fec_dma_alloc(dev, size, handle, gfp);
+	if (!vaddr) {
+		devres_free(dr);
+		return NULL;
+	}
+	dr->vaddr = vaddr;
+	dr->dma_handle = *handle;
+	dr->size = size;
+	devres_add(dev, dr);
+	return vaddr;
+}
+
 static inline bool is_ipv4_pkt(struct sk_buff *skb)
 {
 	return skb->protocol == htons(ETH_P_IP) && ip_hdr(skb)->version == 4;
@@ -1660,7 +1724,11 @@ fec_enet_rx_queue(struct net_device *ndev, int budget, u16 queue_id)
 	}
 #endif
 
-#ifdef CONFIG_M532x
+#if defined(CONFIG_COLDFIRE) && !defined(CONFIG_COLDFIRE_COHERENT_DMA)
+	/*
+	 * Hacky flush of all caches instead of using the DMA API for the TSO
+	 * headers.
+	 */
 	flush_cache_all();
 #endif
 	rxq = fep->rx_queue[queue_id];
@@ -3288,10 +3356,9 @@ static void fec_enet_free_queue(struct net_device *ndev)
 	for (i = 0; i < fep->num_tx_queues; i++)
 		if (fep->tx_queue[i] && fep->tx_queue[i]->tso_hdrs) {
 			txq = fep->tx_queue[i];
-			dma_free_coherent(&fep->pdev->dev,
-					  txq->bd.ring_size * TSO_HEADER_SIZE,
-					  txq->tso_hdrs,
-					  txq->tso_hdrs_dma);
+			fec_dma_free(&fep->pdev->dev,
+				     txq->bd.ring_size * TSO_HEADER_SIZE,
+				     txq->tso_hdrs, txq->tso_hdrs_dma);
 		}
 
 	for (i = 0; i < fep->num_rx_queues; i++)
@@ -3321,10 +3388,9 @@ static int fec_enet_alloc_queue(struct net_device *ndev)
 		txq->tx_stop_threshold = FEC_MAX_SKB_DESCS;
 		txq->tx_wake_threshold = FEC_MAX_SKB_DESCS + 2 * MAX_SKB_FRAGS;
 
-		txq->tso_hdrs = dma_alloc_coherent(&fep->pdev->dev,
+		txq->tso_hdrs = fec_dma_alloc(&fep->pdev->dev,
 					txq->bd.ring_size * TSO_HEADER_SIZE,
-					&txq->tso_hdrs_dma,
-					GFP_KERNEL);
+					&txq->tso_hdrs_dma, GFP_KERNEL);
 		if (!txq->tso_hdrs) {
 			ret = -ENOMEM;
 			goto alloc_failed;
@@ -4043,8 +4109,8 @@ static int fec_enet_init(struct net_device *ndev)
 	bd_size = (fep->total_tx_ring_size + fep->total_rx_ring_size) * dsize;
 
 	/* Allocate memory for buffer descriptors. */
-	cbd_base = dmam_alloc_coherent(&fep->pdev->dev, bd_size, &bd_dma,
-				       GFP_KERNEL);
+	cbd_base = fec_dmam_alloc(&fep->pdev->dev, bd_size, &bd_dma,
+				  GFP_KERNEL);
 	if (!cbd_base) {
 		ret = -ENOMEM;
 		goto free_queue_mem;
Signature · 1 line
2.39.2
#34 lore raw

Re: [PATCH 10/12] net: fec: use dma_alloc_noncoherent for data cache enabled coldfire

Hi Christoph,

Quoted 9 lines · Christoph Hellwig

Coldfire platforms with data caches can't properly implement dma_alloc_coherent and currently just return noncoherent memory from dma_alloc_coherent.

The fec driver than works around this with a flush of all caches in the receive path. Make this hack a little less bad by using the explicit dma_alloc_noncoherent API and documenting the hacky cache flushes so that the DMA API level hack can be removed.

Quoted 6 lines

Also replace the check for CONFIG_M532x for said hack with a check for COLDFIRE && !COLDFIRE_COHERENT_DMA. While m532x is the only such platform with a fec module, this makes the code more consistent and easier to follow.

Thanks for your patch!

Quoted 13 lines
drivers/net/ethernet/freescale/fec_main.c +7 -0
@@ -406,6 +406,70 @@ static void fec_dump(struct net_device *ndev)
        } while (bdp != txq->bd.base);
 }
 
+/*
+ * Coldfire does not support DMA coherent allocations, and has historically used
+ * a band-aid with a manual flush in fec_enet_rx_queue.
+ */
+#if defined(CONFIG_COLDFIRE) && !defined(CONFIG_COLDFIRE_COHERENT_DMA)
+static void *fec_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
+               gfp_t gfp)

drivers/net/ethernet/freescale/fec_main.c static void fec_dump(struct net_device *ndev) · line 425

Quoted 10 lines
drivers/net/ethernet/freescale/fec_main.c +10 -0
+{
+       return dma_alloc_noncoherent(dev, size, handle, DMA_BIDIRECTIONAL, gfp);
+}
+
+static void fec_dma_free(struct device *dev, size_t size, void *cpu_addr,
+               dma_addr_t handle)
+{
+       dma_free_noncoherent(dev, size, cpu_addr, handle, DMA_BIDIRECTIONAL);
+}
+#else /* CONFIG_COLDFIRE && !CONFIG_COLDFIRE_COHERENT_DMA */

!CONFIG_COLDFIRE || CONFIG_COLDFIRE_COHERENT_DMA

drivers/net/ethernet/freescale/fec_main.c static void fec_dump(struct net_device *ndev) · line 437

Quoted 12 lines
drivers/net/ethernet/freescale/fec_main.c +12 -0
+static void *fec_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
+               gfp_t gfp)
+{
+       return dma_alloc_coherent(dev, size, handle, gfp);
+}
+
+static void fec_dma_free(struct device *dev, size_t size, void *cpu_addr,
+               dma_addr_t handle)
+{
+       dma_free_coherent(dev, size, cpu_addr, handle);
+}
+#endif /* !CONFIG_COLDFIRE && !CONFIG_COLDFIRE_COHERENT_DMA */

!CONFIG_COLDFIRE || CONFIG_COLDFIRE_COHERENT_DMA

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
#35 lore raw

PATCH 11/12 m68k: don't provide arch_dma_alloc for nommu/coldfire

In reply to Christoph Hellwig

Coldfire cores configured with a data cache can't provide coherent DMA allocations at all.

Instead of returning non-coherent kernel memory in this case, return NULL and fail the allocation.

The only driver that used to rely on the previous behavior (fec) has been switched to use non-coherent allocations for this case recently.

---
 arch/m68k/Kconfig      |  1 -
 arch/m68k/kernel/dma.c | 23 -----------------------
 2 files changed, 24 deletions(-)
arch/m68k/Kconfig +0 -1
index 6c585eae89f4dc..c1c0faffb0d413 100644
@@ -3,7 +3,6 @@ config M68K
 	bool
 	default y
 	select ARCH_32BIT_OFF_T
-	select ARCH_DMA_ALLOC if M68K_NONCOHERENT_DMA && COLDFIRE
 	select ARCH_HAS_BINFMT_FLAT
 	select ARCH_HAS_CPU_FINALIZE_INIT if MMU
 	select ARCH_HAS_CURRENT_STACK_POINTER
arch/m68k/kernel/dma.c +0 -23
index f83870cfa79b37..eef63d032abb53 100644
@@ -33,29 +33,6 @@ pgprot_t pgprot_dmacoherent(pgprot_t prot)
 	}
 	return prot;
 }
-#else
-void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
-		gfp_t gfp, unsigned long attrs)
-{
-	void *ret;
-
-	if (dev == NULL || (*dev->dma_mask < 0xffffffff))
-		gfp |= GFP_DMA;
-	ret = (void *)__get_free_pages(gfp, get_order(size));
-
-	if (ret != NULL) {
-		memset(ret, 0, size);
-		*dma_handle = virt_to_phys(ret);
-	}
-	return ret;
-}
-
-void arch_dma_free(struct device *dev, size_t size, void *vaddr,
-		dma_addr_t dma_handle, unsigned long attrs)
-{
-	free_pages((unsigned long)vaddr, get_order(size));
-}
-
 #endif /* CONFIG_MMU && !CONFIG_COLDFIRE */
 
 void arch_sync_dma_for_device(phys_addr_t handle, size_t size,
Signature · 1 line
2.39.2
#36 lore raw

PATCH 12/12 m68k: remove unused includes from dma.c

In reply to Christoph Hellwig

dma.c doesn't need most of the headers it includes. Also there is no point in undefining the DEBUG symbol given that it isn't used anywhere in this small file.

---
 arch/m68k/kernel/dma.c | 9 ---------
 1 file changed, 9 deletions(-)
arch/m68k/kernel/dma.c +0 -9
index eef63d032abb53..16063783aa80c6 100644
@@ -4,17 +4,8 @@
  * for more details.
  */
 
-#undef DEBUG
-
 #include <linux/dma-map-ops.h>
-#include <linux/device.h>
 #include <linux/kernel.h>
-#include <linux/platform_device.h>
-#include <linux/scatterlist.h>
-#include <linux/slab.h>
-#include <linux/vmalloc.h>
-#include <linux/export.h>
-
 #include <asm/cacheflush.h>
 
 #ifndef CONFIG_COLDFIRE
Signature · 1 line
2.39.2
maintainer Reviewed-by Acked-by on v1 12/12
#37 lore raw

Re: [PATCH 12/12] m68k: remove unused includes from dma.c

Quoted 5 lines · Christoph Hellwig

dma.c doesn't need most of the headers it includes. Also there is no point in undefining the DEBUG symbol given that it isn't used anywhere in this small file.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
Tested-by Reviewed-by
#38 lore raw
In reply to Christoph Hellwig

Hi Christoph,

Quoted 11 lines · Christoph Hellwig

Hi all,

this is the next attempt to not return memory that is not DMA coherent on coldfire/m68knommu. The last one needed more fixups in the fec driver, which this versions includes. On top of that I've also added a few more cleanups to the core DMA allocation code.

Jim: any work to support the set_uncached and remap method for arm32 should probably be based on this, and patch 3 should make that selection a little easier.

Quoted 6 lines

Changes since v1:
- sort out the dependency mess in RISCV
- don't even built non-coherent DMA support for coldfire cores without data caches
- apply the fec workarounds to all coldfire platforms with data caches
- add a trivial cleanup for m68k dma.c

This looks good to me for the ColdFire changes. I tested it on a 5208 (version 2 core) with all combinations of cache (instruction only, data only and both) and it worked good in all cases - with the one configuration fix to patch 9 I sent earlier. So for ColdFire:

I don't have a 532x ColdFire board, so I can't directly test the case of a version 3 core with the FEC hardware block.

Regards
Greg