public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH] pstore: Use root address-cells/size-cells as defaults for reserved-memory
@ 2023-08-26 12:16 Andrey Skvortsov
  2023-08-26 13:10 ` Heinrich Schuchardt
  2023-10-24 23:16 ` Tom Rini
  0 siblings, 2 replies; 6+ messages in thread
From: Andrey Skvortsov @ 2023-08-26 12:16 UTC (permalink / raw)
  To: Jernej Skrabec, Samuel Holland, Jarrah Gosbell, Arnaud Ferraris,
	Pavel Machek, Andre Przywara, u-boot, Detlev Casanova,
	Frédéric Danis
  Cc: Andrey Skvortsov

u-boot adds reserve-memory node, if it's missing, with following
properties:

```
    reserved-memory {
         #address-cells = <2>;
         #size-cells = <2>;
         ranges;
    }
```

But with these default address-cells and size-cells values, pstore
isn't working on A64. Root node for A64 defines 'address-cells' and
'size-cells' as 1.

dtc complains if reserved-memory has different address-cells and
size-cells.

```
     Warning (ranges_format): /reserved-memory:ranges: empty "ranges"
     property but its #address-cells (2) differs from / (1)
```

This patch takes into account address-cells and size-cells of the root
node and uses them as values for new reserved-memory node.

Signed-off-by: Andrey Skvortsov <andrej.skvortzov@gmail.com>
---
 cmd/pstore.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/cmd/pstore.c b/cmd/pstore.c
index cd6f6feb2f..9795eea2db 100644
--- a/cmd/pstore.c
+++ b/cmd/pstore.c
@@ -486,6 +486,8 @@ void fdt_fixup_pstore(void *blob)
 {
 	char node[32];
 	int  nodeoffset;	/* node offset from libfdt */
+	u32 addr_cells_root;
+	u32 size_cells_root;
 	u32 addr_cells;
 	u32 size_cells;
 
@@ -495,6 +497,8 @@ void fdt_fixup_pstore(void *blob)
 		log_err("fdt_path_offset() returned %s\n", fdt_strerror(nodeoffset));
 		return;
 	}
+	addr_cells_root = fdt_getprop_u32_default_node(blob, nodeoffset, 0, "#address-cells", 2);
+	size_cells_root = fdt_getprop_u32_default_node(blob, nodeoffset, 0, "#size-cells", 2);
 
 	nodeoffset = fdt_find_or_add_subnode(blob, nodeoffset, "reserved-memory");
 	if (nodeoffset < 0) {
@@ -503,8 +507,10 @@ void fdt_fixup_pstore(void *blob)
 		return;
 	}
 
-	addr_cells = fdt_getprop_u32_default_node(blob, nodeoffset, 0, "#address-cells", 2);
-	size_cells = fdt_getprop_u32_default_node(blob, nodeoffset, 0, "#size-cells", 2);
+	addr_cells = fdt_getprop_u32_default_node(blob, nodeoffset, 0,
+						  "#address-cells", addr_cells_root);
+	size_cells = fdt_getprop_u32_default_node(blob, nodeoffset, 0,
+						  "#size-cells", size_cells_root);
 	fdt_setprop_u32(blob, nodeoffset, "#address-cells", addr_cells);
 	fdt_setprop_u32(blob, nodeoffset, "#size-cells", size_cells);
 
-- 
2.40.1


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

* Re: [PATCH] pstore: Use root address-cells/size-cells as defaults for reserved-memory
  2023-08-26 12:16 [PATCH] pstore: Use root address-cells/size-cells as defaults for reserved-memory Andrey Skvortsov
@ 2023-08-26 13:10 ` Heinrich Schuchardt
  2023-08-26 18:41   ` Andre Przywara
  2023-08-26 20:06   ` Andrey Skvortsov
  2023-10-24 23:16 ` Tom Rini
  1 sibling, 2 replies; 6+ messages in thread
From: Heinrich Schuchardt @ 2023-08-26 13:10 UTC (permalink / raw)
  To: Andrey Skvortsov
  Cc: Jernej Skrabec, Samuel Holland, Jarrah Gosbell, Arnaud Ferraris,
	Pavel Machek, Andre Przywara, u-boot, Detlev Casanova,
	Frédéric Danis

On 8/26/23 14:16, Andrey Skvortsov wrote:
> u-boot adds reserve-memory node, if it's missing, with following
> properties:
>
> ```
>      reserved-memory {
>           #address-cells = <2>;
>           #size-cells = <2>;

This defines the size of cells for the children of reserved-memory and
and for the ranges property. If you set the cell sizes to 1 you can no
longer encode 64 bit addresses.

>           ranges;
>      }
> ```
>
> But with these default address-cells and size-cells values, pstore
> isn't working on A64. Root node for A64 defines 'address-cells' and
> 'size-cells' as 1.
>
> dtc complains if reserved-memory has different address-cells and
> size-cells.
>
> ```
>       Warning (ranges_format): /reserved-memory:ranges: empty "ranges"
>       property but its #address-cells (2) differs from / (1)

I cannot find any such requirement in the Devicetree Specification 1.4.
Is this a dtc bug?

> ```
>
> This patch takes into account address-cells and size-cells of the root
> node and uses them as values for new reserved-memory node.

Reservations may be above 4 GiB. How does your patch consider this?

Best regards

Heinrich

>
> Signed-off-by: Andrey Skvortsov <andrej.skvortzov@gmail.com>
> ---
>   cmd/pstore.c | 10 ++++++++--
>   1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/cmd/pstore.c b/cmd/pstore.c
> index cd6f6feb2f..9795eea2db 100644
> --- a/cmd/pstore.c
> +++ b/cmd/pstore.c
> @@ -486,6 +486,8 @@ void fdt_fixup_pstore(void *blob)
>   {
>   	char node[32];
>   	int  nodeoffset;	/* node offset from libfdt */
> +	u32 addr_cells_root;
> +	u32 size_cells_root;
>   	u32 addr_cells;
>   	u32 size_cells;
>
> @@ -495,6 +497,8 @@ void fdt_fixup_pstore(void *blob)
>   		log_err("fdt_path_offset() returned %s\n", fdt_strerror(nodeoffset));
>   		return;
>   	}
> +	addr_cells_root = fdt_getprop_u32_default_node(blob, nodeoffset, 0, "#address-cells", 2);
> +	size_cells_root = fdt_getprop_u32_default_node(blob, nodeoffset, 0, "#size-cells", 2);
>
>   	nodeoffset = fdt_find_or_add_subnode(blob, nodeoffset, "reserved-memory");
>   	if (nodeoffset < 0) {
> @@ -503,8 +507,10 @@ void fdt_fixup_pstore(void *blob)
>   		return;
>   	}
>
> -	addr_cells = fdt_getprop_u32_default_node(blob, nodeoffset, 0, "#address-cells", 2);
> -	size_cells = fdt_getprop_u32_default_node(blob, nodeoffset, 0, "#size-cells", 2);
> +	addr_cells = fdt_getprop_u32_default_node(blob, nodeoffset, 0,
> +						  "#address-cells", addr_cells_root);
> +	size_cells = fdt_getprop_u32_default_node(blob, nodeoffset, 0,
> +						  "#size-cells", size_cells_root);
>   	fdt_setprop_u32(blob, nodeoffset, "#address-cells", addr_cells);
>   	fdt_setprop_u32(blob, nodeoffset, "#size-cells", size_cells);
>


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

* Re: [PATCH] pstore: Use root address-cells/size-cells as defaults for reserved-memory
  2023-08-26 13:10 ` Heinrich Schuchardt
@ 2023-08-26 18:41   ` Andre Przywara
  2023-10-16 12:23     ` Andrey Skvortsov
  2023-08-26 20:06   ` Andrey Skvortsov
  1 sibling, 1 reply; 6+ messages in thread
From: Andre Przywara @ 2023-08-26 18:41 UTC (permalink / raw)
  To: Heinrich Schuchardt
  Cc: Andrey Skvortsov, Jernej Skrabec, Samuel Holland, Jarrah Gosbell,
	Arnaud Ferraris, Pavel Machek, u-boot, Detlev Casanova,
	Frédéric Danis

On Sat, 26 Aug 2023 15:10:10 +0200
Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:

Hi,

> On 8/26/23 14:16, Andrey Skvortsov wrote:
> > u-boot adds reserve-memory node, if it's missing, with following
> > properties:
> >
> > ```
> >      reserved-memory {
> >           #address-cells = <2>;
> >           #size-cells = <2>;  
> 
> This defines the size of cells for the children of reserved-memory and
> and for the ranges property. If you set the cell sizes to 1 you can no
> longer encode 64 bit addresses.

Yes, this is expected in this case, the Allwinner A64 SoC has its memory
map (including DRAM) completely below 4GB, hence the root node can go
with 1/1.

> 
> >           ranges;
> >      }
> > ```
> >
> > But with these default address-cells and size-cells values, pstore
> > isn't working on A64. Root node for A64 defines 'address-cells' and
> > 'size-cells' as 1.
> >
> > dtc complains if reserved-memory has different address-cells and
> > size-cells.
> >
> > ```
> >       Warning (ranges_format): /reserved-memory:ranges: empty "ranges"
> >       property but its #address-cells (2) differs from / (1)  
> 
> I cannot find any such requirement in the Devicetree Specification 1.4.
> Is this a dtc bug?

I think the culprit here is the *empty* ranges property:
"If the property is defined with an <empty> value, it specifies that the
parent and child address space is identical, and no address translation
is required."
As this is contradicted by the differing #a-c/#s-z properties, it looks
like dtc has good reasons to warn.

> 
> > ```
> >
> > This patch takes into account address-cells and size-cells of the root
> > node and uses them as values for new reserved-memory node.  
> 
> Reservations may be above 4 GiB. How does your patch consider this?

If the root #a-c/#s-c don't allow for more than 4GB, then it's for a
reason (in this case, the A64 being 32-bit only, even with AArch64
capable cores), and keeping it isn't restricting it further. So I think
copying the root properties is the right thing to do. I think almost
every other 64-bit core uses 2/2 anyway, so it's just the odd outlier
here.

Cheers,
Andre

> Best regards
> 
> Heinrich
> 
> >
> > Signed-off-by: Andrey Skvortsov <andrej.skvortzov@gmail.com>
> > ---
> >   cmd/pstore.c | 10 ++++++++--
> >   1 file changed, 8 insertions(+), 2 deletions(-)
> >
> > diff --git a/cmd/pstore.c b/cmd/pstore.c
> > index cd6f6feb2f..9795eea2db 100644
> > --- a/cmd/pstore.c
> > +++ b/cmd/pstore.c
> > @@ -486,6 +486,8 @@ void fdt_fixup_pstore(void *blob)
> >   {
> >   	char node[32];
> >   	int  nodeoffset;	/* node offset from libfdt */
> > +	u32 addr_cells_root;
> > +	u32 size_cells_root;
> >   	u32 addr_cells;
> >   	u32 size_cells;
> >
> > @@ -495,6 +497,8 @@ void fdt_fixup_pstore(void *blob)
> >   		log_err("fdt_path_offset() returned %s\n", fdt_strerror(nodeoffset));
> >   		return;
> >   	}
> > +	addr_cells_root = fdt_getprop_u32_default_node(blob, nodeoffset, 0, "#address-cells", 2);
> > +	size_cells_root = fdt_getprop_u32_default_node(blob, nodeoffset, 0, "#size-cells", 2);
> >
> >   	nodeoffset = fdt_find_or_add_subnode(blob, nodeoffset, "reserved-memory");
> >   	if (nodeoffset < 0) {
> > @@ -503,8 +507,10 @@ void fdt_fixup_pstore(void *blob)
> >   		return;
> >   	}
> >
> > -	addr_cells = fdt_getprop_u32_default_node(blob, nodeoffset, 0, "#address-cells", 2);
> > -	size_cells = fdt_getprop_u32_default_node(blob, nodeoffset, 0, "#size-cells", 2);
> > +	addr_cells = fdt_getprop_u32_default_node(blob, nodeoffset, 0,
> > +						  "#address-cells", addr_cells_root);
> > +	size_cells = fdt_getprop_u32_default_node(blob, nodeoffset, 0,
> > +						  "#size-cells", size_cells_root);
> >   	fdt_setprop_u32(blob, nodeoffset, "#address-cells", addr_cells);
> >   	fdt_setprop_u32(blob, nodeoffset, "#size-cells", size_cells);
> >  
> 


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

* Re: [PATCH] pstore: Use root address-cells/size-cells as defaults for reserved-memory
  2023-08-26 13:10 ` Heinrich Schuchardt
  2023-08-26 18:41   ` Andre Przywara
@ 2023-08-26 20:06   ` Andrey Skvortsov
  1 sibling, 0 replies; 6+ messages in thread
From: Andrey Skvortsov @ 2023-08-26 20:06 UTC (permalink / raw)
  To: Heinrich Schuchardt
  Cc: Jernej Skrabec, Samuel Holland, Jarrah Gosbell, Arnaud Ferraris,
	Pavel Machek, Andre Przywara, u-boot, Detlev Casanova,
	Frédéric Danis

Hi Heinrich,

On 23-08-26 15:10, Heinrich Schuchardt wrote:
> On 8/26/23 14:16, Andrey Skvortsov wrote:
> > u-boot adds reserve-memory node, if it's missing, with following
> > properties:
> > 
> > ```
> >      reserved-memory {
> >           #address-cells = <2>;
> >           #size-cells = <2>;
> 
> This defines the size of cells for the children of reserved-memory and
> and for the ranges property. If you set the cell sizes to 1 you can no
> longer encode 64 bit addresses.

This will be limited to 32 bit only for platforms, that don't support
64 bit. These platforms explicitly defines #address-cells = 1 and #size-cells = 1 in
root node.


> >           ranges;
> >      }
> > ```
> > 
> > But with these default address-cells and size-cells values, pstore
> > isn't working on A64. Root node for A64 defines 'address-cells' and
> > 'size-cells' as 1.
> > 
> > dtc complains if reserved-memory has different address-cells and
> > size-cells.
> > 
> > ```
> >       Warning (ranges_format): /reserved-memory:ranges: empty "ranges"
> >       property but its #address-cells (2) differs from / (1)
> 
> I cannot find any such requirement in the Devicetree Specification 1.4.
> Is this a dtc bug?

This is current behavior of Linux kernel. When root #address-cells and
reserved-memory #address-cells don't match, then reserved-memory
region is ignored. See [1].

dmesg output:
```
 OF: fdt: Reserved memory: unsupported node format, ignoring
```

> > This patch takes into account address-cells and size-cells of the root
> > node and uses them as values for new reserved-memory node.
> 
> Reservations may be above 4 GiB. How does your patch consider this?

It's entirely possible to do on platforms, that support that. Default
fallback value is still 2 for #address-cells and #size-cells.


1. https://elixir.bootlin.com/linux/latest/source/drivers/of/fdt.c#L548

-- 
Best regards,
Andrey Skvortsov

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

* Re: [PATCH] pstore: Use root address-cells/size-cells as defaults for reserved-memory
  2023-08-26 18:41   ` Andre Przywara
@ 2023-10-16 12:23     ` Andrey Skvortsov
  0 siblings, 0 replies; 6+ messages in thread
From: Andrey Skvortsov @ 2023-10-16 12:23 UTC (permalink / raw)
  To: Andre Przywara
  Cc: Heinrich Schuchardt, Jernej Skrabec, Samuel Holland,
	Jarrah Gosbell, Arnaud Ferraris, Pavel Machek, u-boot,
	Detlev Casanova, Frédéric Danis, Tom Rini

Hi,

On 23-08-26 19:41, Andre Przywara wrote:
> On Sat, 26 Aug 2023 15:10:10 +0200
> Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
> 
> Hi,
> 
> > On 8/26/23 14:16, Andrey Skvortsov wrote:
> > > u-boot adds reserve-memory node, if it's missing, with following
> > > properties:
> > >
> > > ```
> > >      reserved-memory {
> > >           #address-cells = <2>;
> > >           #size-cells = <2>;  
> > 
> > This defines the size of cells for the children of reserved-memory and
> > and for the ranges property. If you set the cell sizes to 1 you can no
> > longer encode 64 bit addresses.
> 
> Yes, this is expected in this case, the Allwinner A64 SoC has its memory
> map (including DRAM) completely below 4GB, hence the root node can go
> with 1/1.
> 
> > 
> > >           ranges;
> > >      }
> > > ```
> > >
> > > But with these default address-cells and size-cells values, pstore
> > > isn't working on A64. Root node for A64 defines 'address-cells' and
> > > 'size-cells' as 1.
> > >
> > > dtc complains if reserved-memory has different address-cells and
> > > size-cells.
> > >
> > > ```
> > >       Warning (ranges_format): /reserved-memory:ranges: empty "ranges"
> > >       property but its #address-cells (2) differs from / (1)  
> > 
> > I cannot find any such requirement in the Devicetree Specification 1.4.
> > Is this a dtc bug?
> 
> I think the culprit here is the *empty* ranges property:
> "If the property is defined with an <empty> value, it specifies that the
> parent and child address space is identical, and no address translation
> is required."
> As this is contradicted by the differing #a-c/#s-z properties, it looks
> like dtc has good reasons to warn.
> 
> > 
> > > ```
> > >
> > > This patch takes into account address-cells and size-cells of the root
> > > node and uses them as values for new reserved-memory node.  
> > 
> > Reservations may be above 4 GiB. How does your patch consider this?
> 
> If the root #a-c/#s-c don't allow for more than 4GB, then it's for a
> reason (in this case, the A64 being 32-bit only, even with AArch64
> capable cores), and keeping it isn't restricting it further. So I think
> copying the root properties is the right thing to do. I think almost
> every other 64-bit core uses 2/2 anyway, so it's just the odd outlier
> here.
> 
> Cheers,
> Andre

Are there any comments I should fix to get this change merged or maybe
another way of solving this problem?

I see, that patch requires review from Tom Rini currently on patchwork [1].

1. https://patchwork.ozlabs.org/project/uboot/patch/20230826121652.2487643-1-andrej.skvortzov@gmail.com/

-- 
Best regards,
Andrey Skvortsov

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

* Re: [PATCH] pstore: Use root address-cells/size-cells as defaults for reserved-memory
  2023-08-26 12:16 [PATCH] pstore: Use root address-cells/size-cells as defaults for reserved-memory Andrey Skvortsov
  2023-08-26 13:10 ` Heinrich Schuchardt
@ 2023-10-24 23:16 ` Tom Rini
  1 sibling, 0 replies; 6+ messages in thread
From: Tom Rini @ 2023-10-24 23:16 UTC (permalink / raw)
  To: Andrey Skvortsov
  Cc: Jernej Skrabec, Samuel Holland, Jarrah Gosbell, Arnaud Ferraris,
	Pavel Machek, Andre Przywara, u-boot, Detlev Casanova,
	Frédéric Danis

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

On Sat, Aug 26, 2023 at 03:16:52PM +0300, Andrey Skvortsov wrote:

> u-boot adds reserve-memory node, if it's missing, with following
> properties:
> 
> ```
>     reserved-memory {
>          #address-cells = <2>;
>          #size-cells = <2>;
>          ranges;
>     }
> ```
> 
> But with these default address-cells and size-cells values, pstore
> isn't working on A64. Root node for A64 defines 'address-cells' and
> 'size-cells' as 1.
> 
> dtc complains if reserved-memory has different address-cells and
> size-cells.
> 
> ```
>      Warning (ranges_format): /reserved-memory:ranges: empty "ranges"
>      property but its #address-cells (2) differs from / (1)
> ```
> 
> This patch takes into account address-cells and size-cells of the root
> node and uses them as values for new reserved-memory node.
> 
> Signed-off-by: Andrey Skvortsov <andrej.skvortzov@gmail.com>

Applied to u-boot/master, thanks!

-- 
Tom

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

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

end of thread, other threads:[~2023-10-24 23:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-26 12:16 [PATCH] pstore: Use root address-cells/size-cells as defaults for reserved-memory Andrey Skvortsov
2023-08-26 13:10 ` Heinrich Schuchardt
2023-08-26 18:41   ` Andre Przywara
2023-10-16 12:23     ` Andrey Skvortsov
2023-08-26 20:06   ` Andrey Skvortsov
2023-10-24 23:16 ` Tom Rini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox