2023-02-22 13:24:42

by Jiaxun Yang

[permalink] [raw]
Subject: [PATCH v2 0/4] MIPS DMA coherence fixes

Hi all,

This series fixes MIPS per-device DMA coherence support. It's mostly adjusting
Kconfig options.

The v1 series had some extra patches that fixing default coherency settings
for OF probing but I decided to send them as a dedicated series.

Thanks.
- Jiaxun

Jiaxun Yang (4):
MIPS: Remove DMA_PERDEV_COHERENT
MIPS: Always select ARCH_HAS_SETUP_DMA_OPS
MIPS: Always select ARCH_HAS_SYNC_DMA_FOR_CPU for noncoherent
platforms
MIPS: c-r4k: Always install dma flush functions

arch/mips/Kconfig | 16 ++--------------
arch/mips/mm/c-r4k.c | 12 +++---------
2 files changed, 5 insertions(+), 23 deletions(-)

--
2.37.1 (Apple Git-137.1)



2023-02-22 13:24:44

by Jiaxun Yang

[permalink] [raw]
Subject: [PATCH v2 1/4] MIPS: Remove DMA_PERDEV_COHERENT

As now we are always managing DMA coherence on per dev bias,
there is no need to have such option. And it's not selected
by any platform.

Signed-off-by: Jiaxun Yang <[email protected]>
---
v2: Remove unrelated change.
---
arch/mips/Kconfig | 5 -----
1 file changed, 5 deletions(-)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 37072e15b263..a1170f0a0c04 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -1080,11 +1080,6 @@ config FW_CFE
config ARCH_SUPPORTS_UPROBES
bool

-config DMA_PERDEV_COHERENT
- bool
- select ARCH_HAS_SETUP_DMA_OPS
- select DMA_NONCOHERENT
-
config DMA_NONCOHERENT
bool
#
--
2.37.1 (Apple Git-137.1)


2023-02-22 13:24:51

by Jiaxun Yang

[permalink] [raw]
Subject: [PATCH v2 2/4] MIPS: Always select ARCH_HAS_SETUP_DMA_OPS

arch_setup_dma_ops on MIPS sets coherency information in struct device.
It's essential for per-device coherency to work.

Select it for all non-coherent platforms.

Signed-off-by: Jiaxun Yang <[email protected]>
---
arch/mips/Kconfig | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index a1170f0a0c04..dae894b7d857 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -134,7 +134,6 @@ choice

config MIPS_GENERIC_KERNEL
bool "Generic board-agnostic MIPS kernel"
- select ARCH_HAS_SETUP_DMA_OPS
select MIPS_GENERIC
select BOOT_RAW
select BUILTIN_DTB
@@ -1089,6 +1088,7 @@ config DMA_NONCOHERENT
# by pgprot_writcombine can be mixed, and the latter sometimes provides
# significant advantages.
#
+ select ARCH_HAS_SETUP_DMA_OPS
select ARCH_HAS_DMA_WRITE_COMBINE
select ARCH_HAS_DMA_PREP_COHERENT
select ARCH_HAS_SYNC_DMA_FOR_DEVICE
--
2.37.1 (Apple Git-137.1)


2023-02-22 13:24:56

by Jiaxun Yang

[permalink] [raw]
Subject: [PATCH v2 4/4] MIPS: c-r4k: Always install dma flush functions

As nowadays DMA coherence is managed per device, it is possible
to have a system that is defaulted to coherent dma but still
have noncoherent device that needs to use those flush functions.

Just install them unconditionally.

Signed-off-by: Jiaxun Yang <[email protected]>
---
arch/mips/mm/c-r4k.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/arch/mips/mm/c-r4k.c b/arch/mips/mm/c-r4k.c
index a549fa98c2f4..7d447050a20b 100644
--- a/arch/mips/mm/c-r4k.c
+++ b/arch/mips/mm/c-r4k.c
@@ -1867,15 +1867,9 @@ void r4k_cache_init(void)
__local_flush_icache_user_range = local_r4k_flush_icache_user_range;

#ifdef CONFIG_DMA_NONCOHERENT
- if (dma_default_coherent) {
- _dma_cache_wback_inv = (void *)cache_noop;
- _dma_cache_wback = (void *)cache_noop;
- _dma_cache_inv = (void *)cache_noop;
- } else {
- _dma_cache_wback_inv = r4k_dma_cache_wback_inv;
- _dma_cache_wback = r4k_dma_cache_wback_inv;
- _dma_cache_inv = r4k_dma_cache_inv;
- }
+ _dma_cache_wback_inv = r4k_dma_cache_wback_inv;
+ _dma_cache_wback = r4k_dma_cache_wback_inv;
+ _dma_cache_inv = r4k_dma_cache_inv;
#endif /* CONFIG_DMA_NONCOHERENT */

build_clear_page();
--
2.37.1 (Apple Git-137.1)


2023-02-22 13:24:59

by Jiaxun Yang

[permalink] [raw]
Subject: [PATCH v2 3/4] MIPS: Always select ARCH_HAS_SYNC_DMA_FOR_CPU for noncoherent platforms

As now we are telling the necessity of post DMA flush per CPU type,
there is no need to select ARCH_HAS_SYNC_DMA_FOR_CPU on per platform
bias, just select it unconditionally and we can sort it at runtime.

Signed-off-by: Jiaxun Yang <[email protected]>
---
arch/mips/Kconfig | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index dae894b7d857..bcca65b25f62 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -115,7 +115,6 @@ config MACH_INGENIC
select SYS_SUPPORTS_LITTLE_ENDIAN
select SYS_SUPPORTS_ZBOOT
select DMA_NONCOHERENT
- select ARCH_HAS_SYNC_DMA_FOR_CPU
select IRQ_MIPS_CPU
select PINCTRL
select GPIOLIB
@@ -1091,6 +1090,7 @@ config DMA_NONCOHERENT
select ARCH_HAS_SETUP_DMA_OPS
select ARCH_HAS_DMA_WRITE_COMBINE
select ARCH_HAS_DMA_PREP_COHERENT
+ select ARCH_HAS_SYNC_DMA_FOR_CPU
select ARCH_HAS_SYNC_DMA_FOR_DEVICE
select ARCH_HAS_DMA_SET_UNCACHED
select DMA_NONCOHERENT_MMAP
@@ -1854,11 +1854,9 @@ config SYS_HAS_CPU_MIPS32_R3_5

config SYS_HAS_CPU_MIPS32_R5
bool
- select ARCH_HAS_SYNC_DMA_FOR_CPU if DMA_NONCOHERENT

config SYS_HAS_CPU_MIPS32_R6
bool
- select ARCH_HAS_SYNC_DMA_FOR_CPU if DMA_NONCOHERENT

config SYS_HAS_CPU_MIPS64_R1
bool
@@ -1868,15 +1866,12 @@ config SYS_HAS_CPU_MIPS64_R2

config SYS_HAS_CPU_MIPS64_R5
bool
- select ARCH_HAS_SYNC_DMA_FOR_CPU if DMA_NONCOHERENT

config SYS_HAS_CPU_MIPS64_R6
bool
- select ARCH_HAS_SYNC_DMA_FOR_CPU if DMA_NONCOHERENT

config SYS_HAS_CPU_P5600
bool
- select ARCH_HAS_SYNC_DMA_FOR_CPU if DMA_NONCOHERENT

config SYS_HAS_CPU_R3000
bool
@@ -1901,7 +1896,6 @@ config SYS_HAS_CPU_NEVADA

config SYS_HAS_CPU_R10000
bool
- select ARCH_HAS_SYNC_DMA_FOR_CPU if DMA_NONCOHERENT

config SYS_HAS_CPU_RM7000
bool
@@ -1930,7 +1924,6 @@ config SYS_HAS_CPU_BMIPS4380
config SYS_HAS_CPU_BMIPS5000
bool
select SYS_HAS_CPU_BMIPS
- select ARCH_HAS_SYNC_DMA_FOR_CPU

#
# CPU may reorder R->R, R->W, W->R, W->W
--
2.37.1 (Apple Git-137.1)


2023-02-26 22:18:42

by Philippe Mathieu-Daudé

[permalink] [raw]
Subject: Re: [PATCH v2 1/4] MIPS: Remove DMA_PERDEV_COHERENT

On 22/2/23 14:24, Jiaxun Yang wrote:
> As now we are always managing DMA coherence on per dev bias,
> there is no need to have such option. And it's not selected
> by any platform.

Leftover from 4e0664416c70 ("MIPS: remove CONFIG_DMA_PERDEV_COHERENT").

> Signed-off-by: Jiaxun Yang <[email protected]>
> ---
> v2: Remove unrelated change.
> ---
> arch/mips/Kconfig | 5 -----
> 1 file changed, 5 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <[email protected]>


2023-02-27 22:56:13

by Thomas Bogendoerfer

[permalink] [raw]
Subject: Re: [PATCH v2 1/4] MIPS: Remove DMA_PERDEV_COHERENT

On Wed, Feb 22, 2023 at 01:24:22PM +0000, Jiaxun Yang wrote:
> As now we are always managing DMA coherence on per dev bias,
> there is no need to have such option. And it's not selected
> by any platform.
>
> Signed-off-by: Jiaxun Yang <[email protected]>
> ---
> v2: Remove unrelated change.
> ---
> arch/mips/Kconfig | 5 -----
> 1 file changed, 5 deletions(-)

applied to mips-next.

Thomas.

--
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea. [ RFC1925, 2.3 ]

2023-03-24 13:15:11

by Thomas Bogendoerfer

[permalink] [raw]
Subject: Re: [PATCH v2 4/4] MIPS: c-r4k: Always install dma flush functions

On Wed, Feb 22, 2023 at 01:24:25PM +0000, Jiaxun Yang wrote:
> As nowadays DMA coherence is managed per device, it is possible
> to have a system that is defaulted to coherent dma but still
> have noncoherent device that needs to use those flush functions.
>
> Just install them unconditionally.
>
> Signed-off-by: Jiaxun Yang <[email protected]>
> ---
> arch/mips/mm/c-r4k.c | 12 +++---------
> 1 file changed, 3 insertions(+), 9 deletions(-)

applied to mips-next.

Thomas.

--
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea. [ RFC1925, 2.3 ]

2023-03-24 13:16:46

by Thomas Bogendoerfer

[permalink] [raw]
Subject: Re: [PATCH v2 3/4] MIPS: Always select ARCH_HAS_SYNC_DMA_FOR_CPU for noncoherent platforms

On Wed, Feb 22, 2023 at 01:24:24PM +0000, Jiaxun Yang wrote:
> As now we are telling the necessity of post DMA flush per CPU type,
> there is no need to select ARCH_HAS_SYNC_DMA_FOR_CPU on per platform
> bias, just select it unconditionally and we can sort it at runtime.
>
> Signed-off-by: Jiaxun Yang <[email protected]>
> ---
> arch/mips/Kconfig | 9 +--------
> 1 file changed, 1 insertion(+), 8 deletions(-)

applied to mips-next.

Thomas.

--
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea. [ RFC1925, 2.3 ]

2023-03-24 13:16:57

by Thomas Bogendoerfer

[permalink] [raw]
Subject: Re: [PATCH v2 2/4] MIPS: Always select ARCH_HAS_SETUP_DMA_OPS

On Wed, Feb 22, 2023 at 01:24:23PM +0000, Jiaxun Yang wrote:
> arch_setup_dma_ops on MIPS sets coherency information in struct device.
> It's essential for per-device coherency to work.
>
> Select it for all non-coherent platforms.
>
> Signed-off-by: Jiaxun Yang <[email protected]>
> ---
> arch/mips/Kconfig | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)

applied to mips-next.

Thomas.

--
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea. [ RFC1925, 2.3 ]