diff mbox series

[2/3] riscv: Set dma_default_coherent to true

Message ID 20230222133712.8079-3-jiaxun.yang@flygoat.com (mailing list archive)
State Superseded
Headers show
Series Use dma_default_coherent for devicetree default coherency | expand

Checks

Context Check Description
conchuod/cover_letter success Series has a cover letter
conchuod/tree_selection success Guessed tree name to be for-next
conchuod/fixes_present success Fixes tag not required for -next series
conchuod/maintainers_pattern success MAINTAINERS pattern errors before the patch: 13 and now 13
conchuod/verify_signedoff success Signed-off-by tag matches author and committer
conchuod/kdoc success Errors and warnings before: 0 this patch: 0
conchuod/build_rv64_clang_allmodconfig fail Failed to build the tree with this patch.
conchuod/module_param success Was 0 now: 0
conchuod/build_rv64_gcc_allmodconfig fail Failed to build the tree with this patch.
conchuod/alphanumeric_selects success Out of order selects before the patch: 729 and now 729
conchuod/build_rv32_defconfig fail Build failed
conchuod/dtb_warn_rv64 success Errors and warnings before: 2 this patch: 2
conchuod/header_inline success No static functions without inline keyword in header files
conchuod/checkpatch warning WARNING: 'begining' may be misspelled - perhaps 'beginning'?
conchuod/source_inline success Was 0 now: 0
conchuod/build_rv64_nommu_k210_defconfig success Build OK
conchuod/verify_fixes success No Fixes tag
conchuod/build_rv64_nommu_virt_defconfig success Build OK

Commit Message

Jiaxun Yang Feb. 22, 2023, 1:37 p.m. UTC
For riscv our assumption is unless a device states it is non-coherent,
we take it to be DMA coherent.

For devicetree probed devices that have been true since very begining
with OF_DMA_DEFAULT_COHERENT selected.

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
---
 arch/riscv/kernel/setup.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Conor Dooley Feb. 22, 2023, 2:50 p.m. UTC | #1
On Wed, Feb 22, 2023 at 01:37:11PM +0000, Jiaxun Yang wrote:
> For riscv our assumption is unless a device states it is non-coherent,
> we take it to be DMA coherent.
> 
> For devicetree probed devices that have been true since very begining
> with OF_DMA_DEFAULT_COHERENT selected.
> 
> Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
> ---
>  arch/riscv/kernel/setup.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
> index 376d2827e736..34b371180976 100644
> --- a/arch/riscv/kernel/setup.c
> +++ b/arch/riscv/kernel/setup.c
> @@ -300,6 +300,9 @@ void __init setup_arch(char **cmdline_p)
>  	riscv_init_cbom_blocksize();
>  	riscv_fill_hwcap();
>  	apply_boot_alternatives();
> +#ifdef CONFIG_RISCV_DMA_NONCOHERENT
> +	dma_default_coherent = true;
> +#endif

Do we really need to add ifdeffery for this here?
It's always coherent by default, so why do we need to say set it in
setup_arch() when we know that, regardless of options, it is true?

Cheers,
Conor.

>  	if (IS_ENABLED(CONFIG_RISCV_ISA_ZICBOM) &&
>  	    riscv_isa_extension_available(NULL, ZICBOM))
>  		riscv_noncoherent_supported();
> -- 
> 2.37.1 (Apple Git-137.1)
>
Jiaxun Yang Feb. 22, 2023, 3:55 p.m. UTC | #2
> 2023年2月22日 14:50,Conor Dooley <conor@kernel.org> 写道:
> 
> On Wed, Feb 22, 2023 at 01:37:11PM +0000, Jiaxun Yang wrote:
>> For riscv our assumption is unless a device states it is non-coherent,
>> we take it to be DMA coherent.
>> 
>> For devicetree probed devices that have been true since very begining
>> with OF_DMA_DEFAULT_COHERENT selected.
>> 
>> Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
>> ---
>> arch/riscv/kernel/setup.c | 3 +++
>> 1 file changed, 3 insertions(+)
>> 
>> diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
>> index 376d2827e736..34b371180976 100644
>> --- a/arch/riscv/kernel/setup.c
>> +++ b/arch/riscv/kernel/setup.c
>> @@ -300,6 +300,9 @@ void __init setup_arch(char **cmdline_p)
>> riscv_init_cbom_blocksize();
>> riscv_fill_hwcap();
>> apply_boot_alternatives();
>> +#ifdef CONFIG_RISCV_DMA_NONCOHERENT
>> + dma_default_coherent = true;
>> +#endif
> 
> Do we really need to add ifdeffery for this here?
> It's always coherent by default, so why do we need to say set it in
> setup_arch() when we know that, regardless of options, it is true?

Because this symbol is only a variable when:

defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \
defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \
defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL)

Which is only true if  CONFIG_RISCV_DMA_NONCOHERENT is selected.

Otherwise this symbol is defined to true and we can’t make a assignment to it.

Thanks
- Jiaxun


> 
> Cheers,
> Conor.
> 
>> if (IS_ENABLED(CONFIG_RISCV_ISA_ZICBOM) &&
>>     riscv_isa_extension_available(NULL, ZICBOM))
>> riscv_noncoherent_supported();
>> -- 
>> 2.37.1 (Apple Git-137.1)
Conor Dooley Feb. 22, 2023, 4:02 p.m. UTC | #3
On Wed, Feb 22, 2023 at 03:55:19PM +0000, Jiaxun Yang wrote:
> 
> 
> > 2023年2月22日 14:50,Conor Dooley <conor@kernel.org> 写道:
> > 
> > On Wed, Feb 22, 2023 at 01:37:11PM +0000, Jiaxun Yang wrote:
> >> For riscv our assumption is unless a device states it is non-coherent,
> >> we take it to be DMA coherent.
> >> 
> >> For devicetree probed devices that have been true since very begining
> >> with OF_DMA_DEFAULT_COHERENT selected.
> >> 
> >> Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
> >> ---
> >> arch/riscv/kernel/setup.c | 3 +++
> >> 1 file changed, 3 insertions(+)
> >> 
> >> diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
> >> index 376d2827e736..34b371180976 100644
> >> --- a/arch/riscv/kernel/setup.c
> >> +++ b/arch/riscv/kernel/setup.c
> >> @@ -300,6 +300,9 @@ void __init setup_arch(char **cmdline_p)
> >> riscv_init_cbom_blocksize();
> >> riscv_fill_hwcap();
> >> apply_boot_alternatives();
> >> +#ifdef CONFIG_RISCV_DMA_NONCOHERENT
> >> + dma_default_coherent = true;
> >> +#endif
> > 
> > Do we really need to add ifdeffery for this here?
> > It's always coherent by default, so why do we need to say set it in
> > setup_arch() when we know that, regardless of options, it is true?
> 
> Because this symbol is only a variable when:
> 
> defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \
> defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \
> defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL)
> 
> Which is only true if  CONFIG_RISCV_DMA_NONCOHERENT is selected.
> 
> Otherwise this symbol is defined to true and we can’t make a assignment to it.

Maybe I am just slow today, but I don't get why you need to add
ifdeffery to setup_arch() to do something that is always true.
Why can't you just set this in riscv/mm/dma-noncoherent.c? What am I
missing?

Cheers,
Conor.

> >> if (IS_ENABLED(CONFIG_RISCV_ISA_ZICBOM) &&
> >>     riscv_isa_extension_available(NULL, ZICBOM))
> >> riscv_noncoherent_supported();
> >> -- 
> >> 2.37.1 (Apple Git-137.1)
> 
>
Jiaxun Yang Feb. 22, 2023, 4:20 p.m. UTC | #4
> 2023年2月22日 16:02,Conor Dooley <conor@kernel.org> 写道:
> 
> On Wed, Feb 22, 2023 at 03:55:19PM +0000, Jiaxun Yang wrote:
>> 
>> 
>>> 2023年2月22日 14:50,Conor Dooley <conor@kernel.org> 写道:
>>> 
>>> On Wed, Feb 22, 2023 at 01:37:11PM +0000, Jiaxun Yang wrote:
>>>> For riscv our assumption is unless a device states it is non-coherent,
>>>> we take it to be DMA coherent.
>>>> 
>>>> For devicetree probed devices that have been true since very begining
>>>> with OF_DMA_DEFAULT_COHERENT selected.
>>>> 
>>>> Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
>>>> ---
>>>> arch/riscv/kernel/setup.c | 3 +++
>>>> 1 file changed, 3 insertions(+)
>>>> 
>>>> diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
>>>> index 376d2827e736..34b371180976 100644
>>>> --- a/arch/riscv/kernel/setup.c
>>>> +++ b/arch/riscv/kernel/setup.c
>>>> @@ -300,6 +300,9 @@ void __init setup_arch(char **cmdline_p)
>>>> riscv_init_cbom_blocksize();
>>>> riscv_fill_hwcap();
>>>> apply_boot_alternatives();
>>>> +#ifdef CONFIG_RISCV_DMA_NONCOHERENT
>>>> + dma_default_coherent = true;
>>>> +#endif
>>> 
>>> Do we really need to add ifdeffery for this here?
>>> It's always coherent by default, so why do we need to say set it in
>>> setup_arch() when we know that, regardless of options, it is true?
>> 
>> Because this symbol is only a variable when:
>> 
>> defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \
>> defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \
>> defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL)
>> 
>> Which is only true if  CONFIG_RISCV_DMA_NONCOHERENT is selected.
>> 
>> Otherwise this symbol is defined to true and we can’t make a assignment to it.
> 
> Maybe I am just slow today, but I don't get why you need to add
> ifdeffery to setup_arch() to do something that is always true.
> Why can't you just set this in riscv/mm/dma-noncoherent.c? What am I
> missing?

Hmm that sounds like a good idea but I was unable to find a place for this.

riscv/mm/dma-noncoherent.c are just a bunch of callbacks, there is no initialisation
function that will always run on every boot. riscv_noncoherent_supported is only
called conditionally.

Perhaps I can add a initcall in dma-noncoherent.c but it seems to be a little bit
overkilling.

Actually I’d prefer to have a config option for the default value but it seems like
it’s not in Christoph’s flavour.

Thanks
- Jiaxun
Conor Dooley Feb. 22, 2023, 4:59 p.m. UTC | #5
On Wed, Feb 22, 2023 at 04:20:16PM +0000, Jiaxun Yang wrote:
> > 2023年2月22日 16:02,Conor Dooley <conor@kernel.org> 写道:
> > On Wed, Feb 22, 2023 at 03:55:19PM +0000, Jiaxun Yang wrote:
> >>> 2023年2月22日 14:50,Conor Dooley <conor@kernel.org> 写道:
> >>> On Wed, Feb 22, 2023 at 01:37:11PM +0000, Jiaxun Yang wrote:
> >>>> For riscv our assumption is unless a device states it is non-coherent,
> >>>> we take it to be DMA coherent.
> >>>> 
> >>>> For devicetree probed devices that have been true since very begining
> >>>> with OF_DMA_DEFAULT_COHERENT selected.
> >>>> 
> >>>> Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
> >>>> ---
> >>>> arch/riscv/kernel/setup.c | 3 +++
> >>>> 1 file changed, 3 insertions(+)
> >>>> 
> >>>> diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
> >>>> index 376d2827e736..34b371180976 100644
> >>>> --- a/arch/riscv/kernel/setup.c
> >>>> +++ b/arch/riscv/kernel/setup.c
> >>>> @@ -300,6 +300,9 @@ void __init setup_arch(char **cmdline_p)
> >>>> riscv_init_cbom_blocksize();
> >>>> riscv_fill_hwcap();
> >>>> apply_boot_alternatives();
> >>>> +#ifdef CONFIG_RISCV_DMA_NONCOHERENT
> >>>> + dma_default_coherent = true;
> >>>> +#endif
> >>> 
> >>> Do we really need to add ifdeffery for this here?
> >>> It's always coherent by default, so why do we need to say set it in
> >>> setup_arch() when we know that, regardless of options, it is true?
> >> 
> >> Because this symbol is only a variable when:
> >> 
> >> defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \
> >> defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \
> >> defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL)
> >> 
> >> Which is only true if  CONFIG_RISCV_DMA_NONCOHERENT is selected.
> >> 
> >> Otherwise this symbol is defined to true and we can’t make a assignment to it.

> > Maybe I am just slow today, but I don't get why you need to add
> > ifdeffery to setup_arch() to do something that is always true.
> > Why can't you just set this in riscv/mm/dma-noncoherent.c? What am I
> > missing?
> 
> Hmm that sounds like a good idea but I was unable to find a place for this.
> 
> riscv/mm/dma-noncoherent.c are just a bunch of callbacks, there is no initialisation
> function that will always run on every boot. riscv_noncoherent_supported is only
> called conditionally.

Right, that's fair. riscv_noncoherent_supported() is for when we know we
can support non-coherent DMA, not to detect whether we can, hence the
conditional nature.
Apologies for sending you on a wild goose chase there.

> Perhaps I can add a initcall in dma-noncoherent.c but it seems to be a little bit
> overkilling.

Yah, probably would be.

> Actually I’d prefer to have a config option for the default value but it seems like
> it’s not in Christoph’s flavour.

We already have a config option that sets things up nicely for RISC-V
that you're getting rid of! ;)
diff mbox series

Patch

diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
index 376d2827e736..34b371180976 100644
--- a/arch/riscv/kernel/setup.c
+++ b/arch/riscv/kernel/setup.c
@@ -300,6 +300,9 @@  void __init setup_arch(char **cmdline_p)
 	riscv_init_cbom_blocksize();
 	riscv_fill_hwcap();
 	apply_boot_alternatives();
+#ifdef CONFIG_RISCV_DMA_NONCOHERENT
+	dma_default_coherent = true;
+#endif
 	if (IS_ENABLED(CONFIG_RISCV_ISA_ZICBOM) &&
 	    riscv_isa_extension_available(NULL, ZICBOM))
 		riscv_noncoherent_supported();