diff mbox series

[1/4] of: also handle dma-noncoherent in of_dma_is_coherent()

Message ID 20220619203212.3604485-2-heiko@sntech.de (mailing list archive)
State New, archived
Headers show
Series riscv: implement Zicbom-based CMO instructions + the t-head variant | expand

Commit Message

Heiko Stübner June 19, 2022, 8:32 p.m. UTC
of_dma_is_coherent() currently expects the architecture to be
non-coherent and some devices being coherent getting marked
as such with the dma-coherent devicetree property.

For PowerPC CONFIG_OF_DMA_DEFAULT_COHERENT was added which currently
makes of_dma_is_coherent() always return true but doesn't handle
the case of the architecture being coherent but some devices not.

So modify the function to also check for dma-noncoherent and
set a suitable default return value. If CONFIG_OF_DMA_DEFAULT_COHERENT
is set the value starts with true and finding dma-noncoherent will
set it to false and without CONFIG_OF_DMA_DEFAULT_COHERENT, the
behaviour is reversed.

Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
 drivers/of/address.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

Comments

Christoph Hellwig June 20, 2022, 6:01 a.m. UTC | #1
On Sun, Jun 19, 2022 at 10:32:09PM +0200, Heiko Stuebner wrote:
>  bool of_dma_is_coherent(struct device_node *np)
>  {
>  	struct device_node *node;
> +	bool ret = false;

I'd rename this to coherent or is_coherent.

>  
>  	if (IS_ENABLED(CONFIG_OF_DMA_DEFAULT_COHERENT))
> -		return true;
> +		ret = true;

And then do this at initialization time:

	bool is_coherent = IS_ENABLED(CONFIG_OF_DMA_DEFAULT_COHERENT);

but otherwise this looks good to me.
Atish Patra June 20, 2022, 4:33 p.m. UTC | #2
On Sun, Jun 19, 2022 at 1:32 PM Heiko Stuebner <heiko@sntech.de> wrote:
>
> of_dma_is_coherent() currently expects the architecture to be
> non-coherent and some devices being coherent getting marked
> as such with the dma-coherent devicetree property.
>
> For PowerPC CONFIG_OF_DMA_DEFAULT_COHERENT was added which currently
> makes of_dma_is_coherent() always return true but doesn't handle
> the case of the architecture being coherent but some devices not.
>
> So modify the function to also check for dma-noncoherent and
> set a suitable default return value. If CONFIG_OF_DMA_DEFAULT_COHERENT
> is set the value starts with true and finding dma-noncoherent will
> set it to false and without CONFIG_OF_DMA_DEFAULT_COHERENT, the
> behaviour is reversed.
>
> Signed-off-by: Heiko Stuebner <heiko@sntech.de>
> ---
>  drivers/of/address.c | 16 +++++++++++-----
>  1 file changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/of/address.c b/drivers/of/address.c
> index 94f017d808c4..1c362d09983d 100644
> --- a/drivers/of/address.c
> +++ b/drivers/of/address.c
> @@ -1045,26 +1045,32 @@ phys_addr_t __init of_dma_get_max_cpu_address(struct device_node *np)
>   *
>   * It returns true if "dma-coherent" property was found
>   * for this device in the DT, or if DMA is coherent by
> - * default for OF devices on the current platform.
> + * default for OF devices on the current platform and no
> + * "dma-noncoherent" property was found for this device.

"dma-noncoherent" is not a standard DT property. I couldn't find any
references to
it in the kernel as well. If we are introducing a new DT property for
non-coherent devices,
it should be added in DT bindings as well ?

>   */
>  bool of_dma_is_coherent(struct device_node *np)
>  {
>         struct device_node *node;
> +       bool ret = false;
>
>         if (IS_ENABLED(CONFIG_OF_DMA_DEFAULT_COHERENT))
> -               return true;
> +               ret = true;
>
>         node = of_node_get(np);
>
>         while (node) {
>                 if (of_property_read_bool(node, "dma-coherent")) {
> -                       of_node_put(node);
> -                       return true;
> +                       ret = true;
> +                       break;
> +               }
> +               if (of_property_read_bool(node, "dma-noncoherent")) {
> +                       ret = false;
> +                       break;
>                 }
>                 node = of_get_next_dma_parent(node);
>         }
>         of_node_put(node);
> -       return false;
> +       return ret;
>  }
>  EXPORT_SYMBOL_GPL(of_dma_is_coherent);
>
> --
> 2.35.1
>
Heiko Stübner June 20, 2022, 6:11 p.m. UTC | #3
Hi Atish,

Am Montag, 20. Juni 2022, 18:33:09 CEST schrieb Atish Patra:
> On Sun, Jun 19, 2022 at 1:32 PM Heiko Stuebner <heiko@sntech.de> wrote:
> >
> > of_dma_is_coherent() currently expects the architecture to be
> > non-coherent and some devices being coherent getting marked
> > as such with the dma-coherent devicetree property.
> >
> > For PowerPC CONFIG_OF_DMA_DEFAULT_COHERENT was added which currently
> > makes of_dma_is_coherent() always return true but doesn't handle
> > the case of the architecture being coherent but some devices not.
> >
> > So modify the function to also check for dma-noncoherent and
> > set a suitable default return value. If CONFIG_OF_DMA_DEFAULT_COHERENT
> > is set the value starts with true and finding dma-noncoherent will
> > set it to false and without CONFIG_OF_DMA_DEFAULT_COHERENT, the
> > behaviour is reversed.
> >
> > Signed-off-by: Heiko Stuebner <heiko@sntech.de>
> > ---
> >  drivers/of/address.c | 16 +++++++++++-----
> >  1 file changed, 11 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/of/address.c b/drivers/of/address.c
> > index 94f017d808c4..1c362d09983d 100644
> > --- a/drivers/of/address.c
> > +++ b/drivers/of/address.c
> > @@ -1045,26 +1045,32 @@ phys_addr_t __init of_dma_get_max_cpu_address(struct device_node *np)
> >   *
> >   * It returns true if "dma-coherent" property was found
> >   * for this device in the DT, or if DMA is coherent by
> > - * default for OF devices on the current platform.
> > + * default for OF devices on the current platform and no
> > + * "dma-noncoherent" property was found for this device.
> 
> "dma-noncoherent" is not a standard DT property. I couldn't find any
> references to
> it in the kernel as well. If we are introducing a new DT property for
> non-coherent devices,
> it should be added in DT bindings as well ?

The dma-coherent is part of the core devicetree-spec,
so I sent a patch adding dma-noncoherent [0]
to the devicetree-spec mailing list yesterday as well.

[0] https://www.spinics.net/lists/devicetree-spec/msg01053.html


> 
> >   */
> >  bool of_dma_is_coherent(struct device_node *np)
> >  {
> >         struct device_node *node;
> > +       bool ret = false;
> >
> >         if (IS_ENABLED(CONFIG_OF_DMA_DEFAULT_COHERENT))
> > -               return true;
> > +               ret = true;
> >
> >         node = of_node_get(np);
> >
> >         while (node) {
> >                 if (of_property_read_bool(node, "dma-coherent")) {
> > -                       of_node_put(node);
> > -                       return true;
> > +                       ret = true;
> > +                       break;
> > +               }
> > +               if (of_property_read_bool(node, "dma-noncoherent")) {
> > +                       ret = false;
> > +                       break;
> >                 }
> >                 node = of_get_next_dma_parent(node);
> >         }
> >         of_node_put(node);
> > -       return false;
> > +       return ret;
> >  }
> >  EXPORT_SYMBOL_GPL(of_dma_is_coherent);
> >
> > --
> > 2.35.1
> >
> 
> 
>
Atish Patra June 20, 2022, 7:41 p.m. UTC | #4
On Mon, Jun 20, 2022 at 11:11 AM Heiko Stuebner <heiko@sntech.de> wrote:
>
> Hi Atish,
>
> Am Montag, 20. Juni 2022, 18:33:09 CEST schrieb Atish Patra:
> > On Sun, Jun 19, 2022 at 1:32 PM Heiko Stuebner <heiko@sntech.de> wrote:
> > >
> > > of_dma_is_coherent() currently expects the architecture to be
> > > non-coherent and some devices being coherent getting marked
> > > as such with the dma-coherent devicetree property.
> > >
> > > For PowerPC CONFIG_OF_DMA_DEFAULT_COHERENT was added which currently
> > > makes of_dma_is_coherent() always return true but doesn't handle
> > > the case of the architecture being coherent but some devices not.
> > >
> > > So modify the function to also check for dma-noncoherent and
> > > set a suitable default return value. If CONFIG_OF_DMA_DEFAULT_COHERENT
> > > is set the value starts with true and finding dma-noncoherent will
> > > set it to false and without CONFIG_OF_DMA_DEFAULT_COHERENT, the
> > > behaviour is reversed.
> > >
> > > Signed-off-by: Heiko Stuebner <heiko@sntech.de>
> > > ---
> > >  drivers/of/address.c | 16 +++++++++++-----
> > >  1 file changed, 11 insertions(+), 5 deletions(-)
> > >
> > > diff --git a/drivers/of/address.c b/drivers/of/address.c
> > > index 94f017d808c4..1c362d09983d 100644
> > > --- a/drivers/of/address.c
> > > +++ b/drivers/of/address.c
> > > @@ -1045,26 +1045,32 @@ phys_addr_t __init of_dma_get_max_cpu_address(struct device_node *np)
> > >   *
> > >   * It returns true if "dma-coherent" property was found
> > >   * for this device in the DT, or if DMA is coherent by
> > > - * default for OF devices on the current platform.
> > > + * default for OF devices on the current platform and no
> > > + * "dma-noncoherent" property was found for this device.
> >
> > "dma-noncoherent" is not a standard DT property. I couldn't find any
> > references to
> > it in the kernel as well. If we are introducing a new DT property for
> > non-coherent devices,
> > it should be added in DT bindings as well ?
>
> The dma-coherent is part of the core devicetree-spec,
> so I sent a patch adding dma-noncoherent [0]
> to the devicetree-spec mailing list yesterday as well.
>

Ahh. That's great. Thanks!

> [0] https://www.spinics.net/lists/devicetree-spec/msg01053.html
>
>
> >
> > >   */
> > >  bool of_dma_is_coherent(struct device_node *np)
> > >  {
> > >         struct device_node *node;
> > > +       bool ret = false;
> > >
> > >         if (IS_ENABLED(CONFIG_OF_DMA_DEFAULT_COHERENT))
> > > -               return true;
> > > +               ret = true;
> > >
> > >         node = of_node_get(np);
> > >
> > >         while (node) {
> > >                 if (of_property_read_bool(node, "dma-coherent")) {
> > > -                       of_node_put(node);
> > > -                       return true;
> > > +                       ret = true;
> > > +                       break;
> > > +               }
> > > +               if (of_property_read_bool(node, "dma-noncoherent")) {
> > > +                       ret = false;
> > > +                       break;
> > >                 }
> > >                 node = of_get_next_dma_parent(node);
> > >         }
> > >         of_node_put(node);
> > > -       return false;
> > > +       return ret;
> > >  }
> > >  EXPORT_SYMBOL_GPL(of_dma_is_coherent);
> > >
> > > --
> > > 2.35.1
> > >
> >
> >
> >
>
>
>
>
diff mbox series

Patch

diff --git a/drivers/of/address.c b/drivers/of/address.c
index 94f017d808c4..1c362d09983d 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -1045,26 +1045,32 @@  phys_addr_t __init of_dma_get_max_cpu_address(struct device_node *np)
  *
  * It returns true if "dma-coherent" property was found
  * for this device in the DT, or if DMA is coherent by
- * default for OF devices on the current platform.
+ * default for OF devices on the current platform and no
+ * "dma-noncoherent" property was found for this device.
  */
 bool of_dma_is_coherent(struct device_node *np)
 {
 	struct device_node *node;
+	bool ret = false;
 
 	if (IS_ENABLED(CONFIG_OF_DMA_DEFAULT_COHERENT))
-		return true;
+		ret = true;
 
 	node = of_node_get(np);
 
 	while (node) {
 		if (of_property_read_bool(node, "dma-coherent")) {
-			of_node_put(node);
-			return true;
+			ret = true;
+			break;
+		}
+		if (of_property_read_bool(node, "dma-noncoherent")) {
+			ret = false;
+			break;
 		}
 		node = of_get_next_dma_parent(node);
 	}
 	of_node_put(node);
-	return false;
+	return ret;
 }
 EXPORT_SYMBOL_GPL(of_dma_is_coherent);