devicetree-compiler.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] checks: Handle #dma-address-cells and #dma-size-cells
@ 2022-11-11 11:47 Thierry Reding
       [not found] ` <20221111114728.462767-1-thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Thierry Reding @ 2022-11-11 11:47 UTC (permalink / raw)
  To: David Gibson
  Cc: Rob Herring, Lucas Stach,
	devicetree-compiler-u79uwXL29TY76Z2rM5mHXA

From: Thierry Reding <treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>

The #dma-address-cells and #dma-size-cells properties can be used to
override their non-DMA counterparts (#address-cells and #size-cells)
for cases where the control bus (defined by the "reg" and "ranges"
properties) has different addressing requirements from the DMA bus.

The "dma-ranges" property needs to be sized depending on these DMA
bus properties rather than the control bus properties, so adjust the
check accordingly.

Signed-off-by: Thierry Reding <treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
 checks.c | 48 +++++++++++++++++++++++++++++++++++++-----------
 dtc.h    |  1 +
 2 files changed, 38 insertions(+), 11 deletions(-)

diff --git a/checks.c b/checks.c
index 9f31d2607182..ee13dce03483 100644
--- a/checks.c
+++ b/checks.c
@@ -743,6 +743,17 @@ static void fixup_addr_size_cells(struct check *c, struct dt_info *dti,
 	prop = get_property(node, "#size-cells");
 	if (prop)
 		node->size_cells = propval_cell(prop);
+
+	node->dma_addr_cells = -1;
+	node->dma_size_cells = -1;
+
+	prop = get_property(node, "#dma-address-cells");
+	if (prop)
+		node->dma_addr_cells = propval_cell(prop);
+
+	prop = get_property(node, "#dma-size-cells");
+	if (prop)
+		node->dma_size_cells = propval_cell(prop);
 }
 WARNING(addr_size_cells, fixup_addr_size_cells, NULL,
 	&address_cells_is_cell, &size_cells_is_cell);
@@ -751,6 +762,10 @@ WARNING(addr_size_cells, fixup_addr_size_cells, NULL,
 	(((n)->addr_cells == -1) ? 2 : (n)->addr_cells)
 #define node_size_cells(n) \
 	(((n)->size_cells == -1) ? 1 : (n)->size_cells)
+#define node_dma_addr_cells(n) \
+	(((n)->dma_addr_cells == -1) ? node_addr_cells(n) : (n)->dma_addr_cells)
+#define node_dma_size_cells(n) \
+	(((n)->dma_size_cells == -1) ? node_size_cells(n) : (n)->dma_size_cells)
 
 static void check_reg_format(struct check *c, struct dt_info *dti,
 			     struct node *node)
@@ -787,6 +802,7 @@ static void check_ranges_format(struct check *c, struct dt_info *dti,
 	struct property *prop;
 	int c_addr_cells, p_addr_cells, c_size_cells, p_size_cells, entrylen;
 	const char *ranges = c->data;
+	const char *prefix;
 
 	prop = get_property(node, ranges);
 	if (!prop)
@@ -798,28 +814,38 @@ static void check_ranges_format(struct check *c, struct dt_info *dti,
 		return;
 	}
 
-	p_addr_cells = node_addr_cells(node->parent);
-	p_size_cells = node_size_cells(node->parent);
-	c_addr_cells = node_addr_cells(node);
-	c_size_cells = node_size_cells(node);
+	if (strcmp(ranges, "dma-ranges") == 0) {
+		p_addr_cells = node_dma_addr_cells(node->parent);
+		p_size_cells = node_dma_size_cells(node->parent);
+		c_addr_cells = node_dma_addr_cells(node);
+		c_size_cells = node_dma_size_cells(node);
+		prefix = "dma-";
+	} else {
+		p_addr_cells = node_addr_cells(node->parent);
+		p_size_cells = node_size_cells(node->parent);
+		c_addr_cells = node_addr_cells(node);
+		c_size_cells = node_size_cells(node);
+		prefix = "";
+	}
+
 	entrylen = (p_addr_cells + c_addr_cells + c_size_cells) * sizeof(cell_t);
 
 	if (prop->val.len == 0) {
 		if (p_addr_cells != c_addr_cells)
 			FAIL_PROP(c, dti, node, prop, "empty \"%s\" property but its "
-				  "#address-cells (%d) differs from %s (%d)",
-				  ranges, c_addr_cells, node->parent->fullpath,
+				  "#%saddress-cells (%d) differs from %s (%d)",
+				  ranges, prefix, c_addr_cells, node->parent->fullpath,
 				  p_addr_cells);
 		if (p_size_cells != c_size_cells)
 			FAIL_PROP(c, dti, node, prop, "empty \"%s\" property but its "
-				  "#size-cells (%d) differs from %s (%d)",
-				  ranges, c_size_cells, node->parent->fullpath,
+				  "#%ssize-cells (%d) differs from %s (%d)",
+				  ranges, prefix, c_size_cells, node->parent->fullpath,
 				  p_size_cells);
 	} else if (!is_multiple_of(prop->val.len, entrylen)) {
 		FAIL_PROP(c, dti, node, prop, "\"%s\" property has invalid length (%d bytes) "
-			  "(parent #address-cells == %d, child #address-cells == %d, "
-			  "#size-cells == %d)", ranges, prop->val.len,
-			  p_addr_cells, c_addr_cells, c_size_cells);
+			  "(parent #%saddress-cells == %d, child #%saddress-cells == %d, "
+			  "#size-cells == %d)", ranges, prop->val.len, prefix,
+			  p_addr_cells, prefix, c_addr_cells, c_size_cells);
 	}
 }
 WARNING(ranges_format, check_ranges_format, "ranges", &addr_size_cells);
diff --git a/dtc.h b/dtc.h
index 0a1f54991026..3d2ef7f3616f 100644
--- a/dtc.h
+++ b/dtc.h
@@ -228,6 +228,7 @@ struct node {
 
 	cell_t phandle;
 	int addr_cells, size_cells;
+	int dma_addr_cells, dma_size_cells;
 
 	struct label *labels;
 	const struct bus_type *bus;
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] checks: Handle #dma-address-cells and #dma-size-cells
       [not found] ` <20221111114728.462767-1-thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2022-11-11 17:01   ` Rob Herring
       [not found]     ` <CAL_JsqLV2ZHLJ=14zf9zNfq+S+Rs09EYmZrNHsvdhbmvvehj6g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Rob Herring @ 2022-11-11 17:01 UTC (permalink / raw)
  To: Thierry Reding
  Cc: David Gibson, Lucas Stach,
	devicetree-compiler-u79uwXL29TY76Z2rM5mHXA

On Fri, Nov 11, 2022 at 5:47 AM Thierry Reding <thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> From: Thierry Reding <treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
>
> The #dma-address-cells and #dma-size-cells properties can be used to
> override their non-DMA counterparts (#address-cells and #size-cells)
> for cases where the control bus (defined by the "reg" and "ranges"
> properties) has different addressing requirements from the DMA bus.
>
> The "dma-ranges" property needs to be sized depending on these DMA
> bus properties rather than the control bus properties, so adjust the
> check accordingly.

I assume I'll be seeing a spec and schema addition too.

I imagine David is wondering where this is coming from given these are
new properties, not existing ones that the checks just didn't handle.

>
> Signed-off-by: Thierry Reding <treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
> ---
>  checks.c | 48 +++++++++++++++++++++++++++++++++++++-----------
>  dtc.h    |  1 +
>  2 files changed, 38 insertions(+), 11 deletions(-)
>
> diff --git a/checks.c b/checks.c
> index 9f31d2607182..ee13dce03483 100644
> --- a/checks.c
> +++ b/checks.c
> @@ -743,6 +743,17 @@ static void fixup_addr_size_cells(struct check *c, struct dt_info *dti,
>         prop = get_property(node, "#size-cells");
>         if (prop)
>                 node->size_cells = propval_cell(prop);
> +
> +       node->dma_addr_cells = -1;
> +       node->dma_size_cells = -1;
> +
> +       prop = get_property(node, "#dma-address-cells");
> +       if (prop)
> +               node->dma_addr_cells = propval_cell(prop);

else
    node->dma_addr_cells = node->addr_cells;

> +
> +       prop = get_property(node, "#dma-size-cells");
> +       if (prop)
> +               node->dma_size_cells = propval_cell(prop);
>  }
>  WARNING(addr_size_cells, fixup_addr_size_cells, NULL,
>         &address_cells_is_cell, &size_cells_is_cell);
> @@ -751,6 +762,10 @@ WARNING(addr_size_cells, fixup_addr_size_cells, NULL,
>         (((n)->addr_cells == -1) ? 2 : (n)->addr_cells)
>  #define node_size_cells(n) \
>         (((n)->size_cells == -1) ? 1 : (n)->size_cells)
> +#define node_dma_addr_cells(n) \
> +       (((n)->dma_addr_cells == -1) ? node_addr_cells(n) : (n)->dma_addr_cells)
> +#define node_dma_size_cells(n) \
> +       (((n)->dma_size_cells == -1) ? node_size_cells(n) : (n)->dma_size_cells)

Then these can be just "(n)->dma_size_cells".

But wait, what about the default sizes? Those have been a dtc warning
since longer than I've run dtc. The defaults don't even agree with
Linux depending on the architecture. Certainly anyone using these new
properties must not be relying on defaults.

>
>  static void check_reg_format(struct check *c, struct dt_info *dti,
>                              struct node *node)
> @@ -787,6 +802,7 @@ static void check_ranges_format(struct check *c, struct dt_info *dti,
>         struct property *prop;
>         int c_addr_cells, p_addr_cells, c_size_cells, p_size_cells, entrylen;
>         const char *ranges = c->data;
> +       const char *prefix;
>
>         prop = get_property(node, ranges);
>         if (!prop)
> @@ -798,28 +814,38 @@ static void check_ranges_format(struct check *c, struct dt_info *dti,
>                 return;
>         }
>
> -       p_addr_cells = node_addr_cells(node->parent);
> -       p_size_cells = node_size_cells(node->parent);
> -       c_addr_cells = node_addr_cells(node);
> -       c_size_cells = node_size_cells(node);
> +       if (strcmp(ranges, "dma-ranges") == 0) {
> +               p_addr_cells = node_dma_addr_cells(node->parent);
> +               p_size_cells = node_dma_size_cells(node->parent);
> +               c_addr_cells = node_dma_addr_cells(node);
> +               c_size_cells = node_dma_size_cells(node);
> +               prefix = "dma-";
> +       } else {
> +               p_addr_cells = node_addr_cells(node->parent);
> +               p_size_cells = node_size_cells(node->parent);
> +               c_addr_cells = node_addr_cells(node);
> +               c_size_cells = node_size_cells(node);
> +               prefix = "";
> +       }
> +
>         entrylen = (p_addr_cells + c_addr_cells + c_size_cells) * sizeof(cell_t);
>
>         if (prop->val.len == 0) {
>                 if (p_addr_cells != c_addr_cells)
>                         FAIL_PROP(c, dti, node, prop, "empty \"%s\" property but its "
> -                                 "#address-cells (%d) differs from %s (%d)",
> -                                 ranges, c_addr_cells, node->parent->fullpath,
> +                                 "#%saddress-cells (%d) differs from %s (%d)",
> +                                 ranges, prefix, c_addr_cells, node->parent->fullpath,

This is going to misleadingly print '#dma-address-cells' in cases that
actually have '#address-cells'. It's probably easiest if you say 'DMA?
address cells' rather than using the property name.

>                                   p_addr_cells);
>                 if (p_size_cells != c_size_cells)
>                         FAIL_PROP(c, dti, node, prop, "empty \"%s\" property but its "
> -                                 "#size-cells (%d) differs from %s (%d)",
> -                                 ranges, c_size_cells, node->parent->fullpath,
> +                                 "#%ssize-cells (%d) differs from %s (%d)",
> +                                 ranges, prefix, c_size_cells, node->parent->fullpath,
>                                   p_size_cells);
>         } else if (!is_multiple_of(prop->val.len, entrylen)) {
>                 FAIL_PROP(c, dti, node, prop, "\"%s\" property has invalid length (%d bytes) "
> -                         "(parent #address-cells == %d, child #address-cells == %d, "
> -                         "#size-cells == %d)", ranges, prop->val.len,
> -                         p_addr_cells, c_addr_cells, c_size_cells);
> +                         "(parent #%saddress-cells == %d, child #%saddress-cells == %d, "
> +                         "#size-cells == %d)", ranges, prop->val.len, prefix,
> +                         p_addr_cells, prefix, c_addr_cells, c_size_cells);
>         }
>  }
>  WARNING(ranges_format, check_ranges_format, "ranges", &addr_size_cells);
> diff --git a/dtc.h b/dtc.h
> index 0a1f54991026..3d2ef7f3616f 100644
> --- a/dtc.h
> +++ b/dtc.h
> @@ -228,6 +228,7 @@ struct node {
>
>         cell_t phandle;
>         int addr_cells, size_cells;
> +       int dma_addr_cells, dma_size_cells;
>
>         struct label *labels;
>         const struct bus_type *bus;
> --
> 2.38.1
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] checks: Handle #dma-address-cells and #dma-size-cells
       [not found]     ` <CAL_JsqLV2ZHLJ=14zf9zNfq+S+Rs09EYmZrNHsvdhbmvvehj6g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2022-11-13  5:07       ` David Gibson
  2022-11-14 10:34       ` Thierry Reding
  1 sibling, 0 replies; 5+ messages in thread
From: David Gibson @ 2022-11-13  5:07 UTC (permalink / raw)
  To: Rob Herring
  Cc: Thierry Reding, Lucas Stach,
	devicetree-compiler-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 7536 bytes --]

On Fri, Nov 11, 2022 at 11:01:58AM -0600, Rob Herring wrote:
> On Fri, Nov 11, 2022 at 5:47 AM Thierry Reding <thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> >
> > From: Thierry Reding <treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
> >
> > The #dma-address-cells and #dma-size-cells properties can be used to
> > override their non-DMA counterparts (#address-cells and #size-cells)
> > for cases where the control bus (defined by the "reg" and "ranges"
> > properties) has different addressing requirements from the DMA bus.
> >
> > The "dma-ranges" property needs to be sized depending on these DMA
> > bus properties rather than the control bus properties, so adjust the
> > check accordingly.
> 
> I assume I'll be seeing a spec and schema addition too.
> 
> I imagine David is wondering where this is coming from given these are
> new properties, not existing ones that the checks just didn't handle.

Right.  In addition, kind of the whole point of dma-ranges is that
it's describing address translations going "up" the tree (reverse of
"ranges").  I'm having trouble seeing how that would make any sense
if the cell numbers are different for the two cases.

> >
> > Signed-off-by: Thierry Reding <treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
> > ---
> >  checks.c | 48 +++++++++++++++++++++++++++++++++++++-----------
> >  dtc.h    |  1 +
> >  2 files changed, 38 insertions(+), 11 deletions(-)
> >
> > diff --git a/checks.c b/checks.c
> > index 9f31d2607182..ee13dce03483 100644
> > --- a/checks.c
> > +++ b/checks.c
> > @@ -743,6 +743,17 @@ static void fixup_addr_size_cells(struct check *c, struct dt_info *dti,
> >         prop = get_property(node, "#size-cells");
> >         if (prop)
> >                 node->size_cells = propval_cell(prop);
> > +
> > +       node->dma_addr_cells = -1;
> > +       node->dma_size_cells = -1;
> > +
> > +       prop = get_property(node, "#dma-address-cells");
> > +       if (prop)
> > +               node->dma_addr_cells = propval_cell(prop);
> 
> else
>     node->dma_addr_cells = node->addr_cells;
> 
> > +
> > +       prop = get_property(node, "#dma-size-cells");
> > +       if (prop)
> > +               node->dma_size_cells = propval_cell(prop);
> >  }
> >  WARNING(addr_size_cells, fixup_addr_size_cells, NULL,
> >         &address_cells_is_cell, &size_cells_is_cell);
> > @@ -751,6 +762,10 @@ WARNING(addr_size_cells, fixup_addr_size_cells, NULL,
> >         (((n)->addr_cells == -1) ? 2 : (n)->addr_cells)
> >  #define node_size_cells(n) \
> >         (((n)->size_cells == -1) ? 1 : (n)->size_cells)
> > +#define node_dma_addr_cells(n) \
> > +       (((n)->dma_addr_cells == -1) ? node_addr_cells(n) : (n)->dma_addr_cells)
> > +#define node_dma_size_cells(n) \
> > +       (((n)->dma_size_cells == -1) ? node_size_cells(n) : (n)->dma_size_cells)
> 
> Then these can be just "(n)->dma_size_cells".
> 
> But wait, what about the default sizes? Those have been a dtc warning
> since longer than I've run dtc. The defaults don't even agree with
> Linux depending on the architecture. Certainly anyone using these new
> properties must not be relying on defaults.
> 
> >
> >  static void check_reg_format(struct check *c, struct dt_info *dti,
> >                              struct node *node)
> > @@ -787,6 +802,7 @@ static void check_ranges_format(struct check *c, struct dt_info *dti,
> >         struct property *prop;
> >         int c_addr_cells, p_addr_cells, c_size_cells, p_size_cells, entrylen;
> >         const char *ranges = c->data;
> > +       const char *prefix;
> >
> >         prop = get_property(node, ranges);
> >         if (!prop)
> > @@ -798,28 +814,38 @@ static void check_ranges_format(struct check *c, struct dt_info *dti,
> >                 return;
> >         }
> >
> > -       p_addr_cells = node_addr_cells(node->parent);
> > -       p_size_cells = node_size_cells(node->parent);
> > -       c_addr_cells = node_addr_cells(node);
> > -       c_size_cells = node_size_cells(node);
> > +       if (strcmp(ranges, "dma-ranges") == 0) {
> > +               p_addr_cells = node_dma_addr_cells(node->parent);
> > +               p_size_cells = node_dma_size_cells(node->parent);
> > +               c_addr_cells = node_dma_addr_cells(node);
> > +               c_size_cells = node_dma_size_cells(node);
> > +               prefix = "dma-";
> > +       } else {
> > +               p_addr_cells = node_addr_cells(node->parent);
> > +               p_size_cells = node_size_cells(node->parent);
> > +               c_addr_cells = node_addr_cells(node);
> > +               c_size_cells = node_size_cells(node);
> > +               prefix = "";
> > +       }
> > +
> >         entrylen = (p_addr_cells + c_addr_cells + c_size_cells) * sizeof(cell_t);
> >
> >         if (prop->val.len == 0) {
> >                 if (p_addr_cells != c_addr_cells)
> >                         FAIL_PROP(c, dti, node, prop, "empty \"%s\" property but its "
> > -                                 "#address-cells (%d) differs from %s (%d)",
> > -                                 ranges, c_addr_cells, node->parent->fullpath,
> > +                                 "#%saddress-cells (%d) differs from %s (%d)",
> > +                                 ranges, prefix, c_addr_cells, node->parent->fullpath,
> 
> This is going to misleadingly print '#dma-address-cells' in cases that
> actually have '#address-cells'. It's probably easiest if you say 'DMA?
> address cells' rather than using the property name.
> 
> >                                   p_addr_cells);
> >                 if (p_size_cells != c_size_cells)
> >                         FAIL_PROP(c, dti, node, prop, "empty \"%s\" property but its "
> > -                                 "#size-cells (%d) differs from %s (%d)",
> > -                                 ranges, c_size_cells, node->parent->fullpath,
> > +                                 "#%ssize-cells (%d) differs from %s (%d)",
> > +                                 ranges, prefix, c_size_cells, node->parent->fullpath,
> >                                   p_size_cells);
> >         } else if (!is_multiple_of(prop->val.len, entrylen)) {
> >                 FAIL_PROP(c, dti, node, prop, "\"%s\" property has invalid length (%d bytes) "
> > -                         "(parent #address-cells == %d, child #address-cells == %d, "
> > -                         "#size-cells == %d)", ranges, prop->val.len,
> > -                         p_addr_cells, c_addr_cells, c_size_cells);
> > +                         "(parent #%saddress-cells == %d, child #%saddress-cells == %d, "
> > +                         "#size-cells == %d)", ranges, prop->val.len, prefix,
> > +                         p_addr_cells, prefix, c_addr_cells, c_size_cells);
> >         }
> >  }
> >  WARNING(ranges_format, check_ranges_format, "ranges", &addr_size_cells);
> > diff --git a/dtc.h b/dtc.h
> > index 0a1f54991026..3d2ef7f3616f 100644
> > --- a/dtc.h
> > +++ b/dtc.h
> > @@ -228,6 +228,7 @@ struct node {
> >
> >         cell_t phandle;
> >         int addr_cells, size_cells;
> > +       int dma_addr_cells, dma_size_cells;
> >
> >         struct label *labels;
> >         const struct bus_type *bus;
> >
> 

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] checks: Handle #dma-address-cells and #dma-size-cells
       [not found]     ` <CAL_JsqLV2ZHLJ=14zf9zNfq+S+Rs09EYmZrNHsvdhbmvvehj6g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  2022-11-13  5:07       ` David Gibson
@ 2022-11-14 10:34       ` Thierry Reding
  2022-11-14 14:27         ` Thierry Reding
  1 sibling, 1 reply; 5+ messages in thread
From: Thierry Reding @ 2022-11-14 10:34 UTC (permalink / raw)
  To: Rob Herring
  Cc: David Gibson, Lucas Stach,
	devicetree-compiler-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 7677 bytes --]

On Fri, Nov 11, 2022 at 11:01:58AM -0600, Rob Herring wrote:
> On Fri, Nov 11, 2022 at 5:47 AM Thierry Reding <thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> >
> > From: Thierry Reding <treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
> >
> > The #dma-address-cells and #dma-size-cells properties can be used to
> > override their non-DMA counterparts (#address-cells and #size-cells)
> > for cases where the control bus (defined by the "reg" and "ranges"
> > properties) has different addressing requirements from the DMA bus.
> >
> > The "dma-ranges" property needs to be sized depending on these DMA
> > bus properties rather than the control bus properties, so adjust the
> > check accordingly.
> 
> I assume I'll be seeing a spec and schema addition too.

Yeah, I was looking around to see where else we may need changes. I had
looked at dt-schema but couldn't find a good place to add them since
#address-cells and #size-cells seem to be mostly handled in the library
code rather than in the json-schema definitions. So if you could provide
some pointers as to how you think this should be added, that'd be great.

I can look at writing an update to the spec, but to be frank could use
some guidance on that as well.

> I imagine David is wondering where this is coming from given these are
> new properties, not existing ones that the checks just didn't handle.

Right, I should've provided a bit more background on this. Evidently the
commit message was not enough.

Thierry

> > Signed-off-by: Thierry Reding <treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
> > ---
> >  checks.c | 48 +++++++++++++++++++++++++++++++++++++-----------
> >  dtc.h    |  1 +
> >  2 files changed, 38 insertions(+), 11 deletions(-)
> >
> > diff --git a/checks.c b/checks.c
> > index 9f31d2607182..ee13dce03483 100644
> > --- a/checks.c
> > +++ b/checks.c
> > @@ -743,6 +743,17 @@ static void fixup_addr_size_cells(struct check *c, struct dt_info *dti,
> >         prop = get_property(node, "#size-cells");
> >         if (prop)
> >                 node->size_cells = propval_cell(prop);
> > +
> > +       node->dma_addr_cells = -1;
> > +       node->dma_size_cells = -1;
> > +
> > +       prop = get_property(node, "#dma-address-cells");
> > +       if (prop)
> > +               node->dma_addr_cells = propval_cell(prop);
> 
> else
>     node->dma_addr_cells = node->addr_cells;
> 
> > +
> > +       prop = get_property(node, "#dma-size-cells");
> > +       if (prop)
> > +               node->dma_size_cells = propval_cell(prop);
> >  }
> >  WARNING(addr_size_cells, fixup_addr_size_cells, NULL,
> >         &address_cells_is_cell, &size_cells_is_cell);
> > @@ -751,6 +762,10 @@ WARNING(addr_size_cells, fixup_addr_size_cells, NULL,
> >         (((n)->addr_cells == -1) ? 2 : (n)->addr_cells)
> >  #define node_size_cells(n) \
> >         (((n)->size_cells == -1) ? 1 : (n)->size_cells)
> > +#define node_dma_addr_cells(n) \
> > +       (((n)->dma_addr_cells == -1) ? node_addr_cells(n) : (n)->dma_addr_cells)
> > +#define node_dma_size_cells(n) \
> > +       (((n)->dma_size_cells == -1) ? node_size_cells(n) : (n)->dma_size_cells)
> 
> Then these can be just "(n)->dma_size_cells".
> 
> But wait, what about the default sizes? Those have been a dtc warning
> since longer than I've run dtc. The defaults don't even agree with
> Linux depending on the architecture. Certainly anyone using these new
> properties must not be relying on defaults.
> 
> >
> >  static void check_reg_format(struct check *c, struct dt_info *dti,
> >                              struct node *node)
> > @@ -787,6 +802,7 @@ static void check_ranges_format(struct check *c, struct dt_info *dti,
> >         struct property *prop;
> >         int c_addr_cells, p_addr_cells, c_size_cells, p_size_cells, entrylen;
> >         const char *ranges = c->data;
> > +       const char *prefix;
> >
> >         prop = get_property(node, ranges);
> >         if (!prop)
> > @@ -798,28 +814,38 @@ static void check_ranges_format(struct check *c, struct dt_info *dti,
> >                 return;
> >         }
> >
> > -       p_addr_cells = node_addr_cells(node->parent);
> > -       p_size_cells = node_size_cells(node->parent);
> > -       c_addr_cells = node_addr_cells(node);
> > -       c_size_cells = node_size_cells(node);
> > +       if (strcmp(ranges, "dma-ranges") == 0) {
> > +               p_addr_cells = node_dma_addr_cells(node->parent);
> > +               p_size_cells = node_dma_size_cells(node->parent);
> > +               c_addr_cells = node_dma_addr_cells(node);
> > +               c_size_cells = node_dma_size_cells(node);
> > +               prefix = "dma-";
> > +       } else {
> > +               p_addr_cells = node_addr_cells(node->parent);
> > +               p_size_cells = node_size_cells(node->parent);
> > +               c_addr_cells = node_addr_cells(node);
> > +               c_size_cells = node_size_cells(node);
> > +               prefix = "";
> > +       }
> > +
> >         entrylen = (p_addr_cells + c_addr_cells + c_size_cells) * sizeof(cell_t);
> >
> >         if (prop->val.len == 0) {
> >                 if (p_addr_cells != c_addr_cells)
> >                         FAIL_PROP(c, dti, node, prop, "empty \"%s\" property but its "
> > -                                 "#address-cells (%d) differs from %s (%d)",
> > -                                 ranges, c_addr_cells, node->parent->fullpath,
> > +                                 "#%saddress-cells (%d) differs from %s (%d)",
> > +                                 ranges, prefix, c_addr_cells, node->parent->fullpath,
> 
> This is going to misleadingly print '#dma-address-cells' in cases that
> actually have '#address-cells'. It's probably easiest if you say 'DMA?
> address cells' rather than using the property name.
> 
> >                                   p_addr_cells);
> >                 if (p_size_cells != c_size_cells)
> >                         FAIL_PROP(c, dti, node, prop, "empty \"%s\" property but its "
> > -                                 "#size-cells (%d) differs from %s (%d)",
> > -                                 ranges, c_size_cells, node->parent->fullpath,
> > +                                 "#%ssize-cells (%d) differs from %s (%d)",
> > +                                 ranges, prefix, c_size_cells, node->parent->fullpath,
> >                                   p_size_cells);
> >         } else if (!is_multiple_of(prop->val.len, entrylen)) {
> >                 FAIL_PROP(c, dti, node, prop, "\"%s\" property has invalid length (%d bytes) "
> > -                         "(parent #address-cells == %d, child #address-cells == %d, "
> > -                         "#size-cells == %d)", ranges, prop->val.len,
> > -                         p_addr_cells, c_addr_cells, c_size_cells);
> > +                         "(parent #%saddress-cells == %d, child #%saddress-cells == %d, "
> > +                         "#size-cells == %d)", ranges, prop->val.len, prefix,
> > +                         p_addr_cells, prefix, c_addr_cells, c_size_cells);
> >         }
> >  }
> >  WARNING(ranges_format, check_ranges_format, "ranges", &addr_size_cells);
> > diff --git a/dtc.h b/dtc.h
> > index 0a1f54991026..3d2ef7f3616f 100644
> > --- a/dtc.h
> > +++ b/dtc.h
> > @@ -228,6 +228,7 @@ struct node {
> >
> >         cell_t phandle;
> >         int addr_cells, size_cells;
> > +       int dma_addr_cells, dma_size_cells;
> >
> >         struct label *labels;
> >         const struct bus_type *bus;
> > --
> > 2.38.1
> >

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] checks: Handle #dma-address-cells and #dma-size-cells
  2022-11-14 10:34       ` Thierry Reding
@ 2022-11-14 14:27         ` Thierry Reding
  0 siblings, 0 replies; 5+ messages in thread
From: Thierry Reding @ 2022-11-14 14:27 UTC (permalink / raw)
  To: Rob Herring
  Cc: David Gibson, Lucas Stach,
	devicetree-compiler-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 1830 bytes --]

On Mon, Nov 14, 2022 at 11:34:06AM +0100, Thierry Reding wrote:
> On Fri, Nov 11, 2022 at 11:01:58AM -0600, Rob Herring wrote:
> > On Fri, Nov 11, 2022 at 5:47 AM Thierry Reding <thierry.reding-Re5JQEeQqe8@public.gmane.orgm> wrote:
> > >
> > > From: Thierry Reding <treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
> > >
> > > The #dma-address-cells and #dma-size-cells properties can be used to
> > > override their non-DMA counterparts (#address-cells and #size-cells)
> > > for cases where the control bus (defined by the "reg" and "ranges"
> > > properties) has different addressing requirements from the DMA bus.
> > >
> > > The "dma-ranges" property needs to be sized depending on these DMA
> > > bus properties rather than the control bus properties, so adjust the
> > > check accordingly.
> > 
> > I assume I'll be seeing a spec and schema addition too.
> 
> Yeah, I was looking around to see where else we may need changes. I had
> looked at dt-schema but couldn't find a good place to add them since
> #address-cells and #size-cells seem to be mostly handled in the library
> code rather than in the json-schema definitions. So if you could provide
> some pointers as to how you think this should be added, that'd be great.
> 
> I can look at writing an update to the spec, but to be frank could use
> some guidance on that as well.

So, I was typing up the spec changes for this and now I'm having second
thoughts. The only reason why I can justify the existence of these
properties is because we don't want to touch #address-cells and
#size-cells. But there's really no good reason to not do that. Yes, it
will be slightly painful to do this, but it's not like we can't.

Given all the weird special cases that this is going to add, I'm no
longer sure this is a good idea.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-11-14 14:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-11 11:47 [PATCH] checks: Handle #dma-address-cells and #dma-size-cells Thierry Reding
     [not found] ` <20221111114728.462767-1-thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2022-11-11 17:01   ` Rob Herring
     [not found]     ` <CAL_JsqLV2ZHLJ=14zf9zNfq+S+Rs09EYmZrNHsvdhbmvvehj6g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2022-11-13  5:07       ` David Gibson
2022-11-14 10:34       ` Thierry Reding
2022-11-14 14:27         ` Thierry Reding

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).