Allow parsing more than one memory node
cover Allow parsing more than one memory node
Currently, barebox can only parse one memory node. This means that all other memory nodes (with device_type == "memory") will be ignored while parsing memory.
This patchset add a function of_probe_memory which will call of_add_memory for each found memory node. Additionally, of_add_memory has been modified to allow being called multiple times and correctly add all memory banks.
Clement Leger (2):
of: base: parse all available memory nodes
of: base: allow of_add_memory to be called multiple times
drivers/of/base.c | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-)
Signature · 7 lines
2.15.0.276.g89ea799 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 1/2 of: base: parse all available memory nodes
Currently, barebox only parse one memory node which is either the "/memory" node or the first node with device_type == "memory". However, the use of multiple memory nodes with device_type = "memory" property is allowed by the device tree specification and already correctly parsed by Linux kernel.
In order to fix that, add of_probe_memory function which loop over all available memory nodes. In order to try to keep existing legacy search based on "memory" node name, try to find this node and add it. If the memory node contains the device_type property, then it will only be added once.
--- drivers/of/base.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-)
drivers/of/base.c +25 -6
@@ -2061,9 +2061,32 @@ const struct of_device_id of_default_bus_match_table[] = { } }; +static void of_probe_memory (void ) +{ +struct device_node *memory = root_node, *legacy_memory; + +/* Parse node based on name (for legacy dt) */ + legacy_memory =of_find_node_by_path ("/memory" ); +if (legacy_memory) +of_add_memory (legacy_memory, false); + +/* Then, parse all available node with "memory" device_type */ +while (1 ) { + memory =of_find_node_by_type (memory,"memory" ); +if (!memory) +break ; + +/* Skip potentially already added legacy memory node */ +if (memory == legacy_memory) +continue ; + +of_add_memory (memory, false); + } +} +int of_probe (void ) { -struct device_node *memory, *firmware; +struct device_node *firmware;if (!root_node)return -ENODEV ;
@@ -2074,11 +2097,7 @@ int of_probe(void)if (of_model)barebox_set_model (of_model); - memory =of_find_node_by_path ("/memory" ); -if (!memory) - memory =of_find_node_by_type (root_node,"memory" ); -if (memory) -of_add_memory (memory, false); +of_probe_memory (); firmware =of_find_node_by_path ("/firmware" );if (firmware)
Signature · 7 lines
2.15.0.276.g89ea799 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 1/2] of: base: parse all available memory nodes
Quoted 35 lines · Clement Leger
Currently, barebox only parse one memory node which is either the "/memory" node or the first node with
device_type== "memory". However, the use of multiple memory nodes withdevice_type= "memory" property is allowed by the device tree specification and already correctly parsed by Linux kernel.
In order to fix that, addof_probe_memoryfunction which loop over all available memory nodes. In order to try to keep existing legacy search based on "memory" node name, try to find this node and add it. If the memory node contains thedevice_typeproperty, then it will only be added once.Signed-off-by Clement Leger <[email protected]>--- drivers/of/base.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-)drivers/of/base.c +11
-0@@ -2061,9 +2061,32 @@ const struct of_device_id of_default_bus_match_table[] = { } }; +static void of_probe_memory (void ) +{ +struct device_node *memory = root_node, *legacy_memory; + +/* Parse node based on name (for legacy dt) */ + legacy_memory =of_find_node_by_path ("/memory" ); +if (legacy_memory) +of_add_memory (legacy_memory, false); + +/* Then, parse all available node with "memory" device_type */ +while (1 ) {
drivers/of/base.c const struct of_device_id of_default_bus_match_table[] = { · line 2084
Quoted 10 lines
drivers/of/base.c +10
-0+ memory =of_find_node_by_type (memory,"memory" ); +if (!memory) +break ; + +/* Skip potentially already added legacy memory node */ +if (memory == legacy_memory) +continue ; + +of_add_memory (memory, false); + }
AFAIK the device_type = "memory" property was mandatory in the early days as well, there shouldn't be any /memory nodes without this property. Given that, is the add-legacy-node-first still necessary?
Sascha
Signature · 9 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 1/2] of: base: parse all available memory nodes
Hi Sascha,
Quoted 43 lines · ----- On 23 Mar, 2020, at 11:12, Sascha Hauer [email protected] wrote:
Quoted 42 lines · Clement Leger
Currently, barebox only parse one memory node which is either the "/memory" node or the first node with
device_type== "memory". However, the use of multiple memory nodes withdevice_type= "memory" property is allowed by the device tree specification and already correctly parsed by Linux kernel.
In order to fix that, addof_probe_memoryfunction which loop over all available memory nodes. In order to try to keep existing legacy search based on "memory" node name, try to find this node and add it. If the memory node contains thedevice_typeproperty, then it will only be added once.Signed-off-by Clement Leger <[email protected]>--- drivers/of/base.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-)drivers/of/base.c +17
-0@@ -2061,9 +2061,32 @@ const struct of_device_id of_default_bus_match_table[] = { } }; +static void of_probe_memory (void ) +{ +struct device_node *memory = root_node, *legacy_memory; + +/* Parse node based on name (for legacy dt) */ + legacy_memory =of_find_node_by_path ("/memory" ); +if (legacy_memory) +of_add_memory (legacy_memory, false); + +/* Then, parse all available node with "memory" device_type */ +while (1 ) { + memory =of_find_node_by_type (memory,"memory" ); +if (!memory) +break ; + +/* Skip potentially already added legacy memory node */ +if (memory == legacy_memory)
Quoted 8 lines
drivers/of/base.c const struct of_device_id of_default_bus_match_table[] = { · line 2084
Quoted 4 lines
drivers/of/base.c +4
-0+continue ; + +of_add_memory (memory, false); + }AFAIK the
device_type= "memory" property was mandatory in the early days as well, there shouldn't be any /memory nodes without this property. Given that, is the add-legacy-node-first still necessary?
Agreed, I did that after speaking with someone on IRC which stated (rightfully), that I should keep the legacy behavior if possible. However, I agree that since the device_type = "memory" property should have always been there, there is no reason to keep this behavior.
If you are ok with that, I will remove this chunk of code.
Quoted 9 lines
Sascha
--
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 1/2] of: base: parse all available memory nodes
Hi,
Quoted 6 lines · Clément Leger
Quoted 3 lines
AFAIK the
device_type= "memory" property was mandatory in the early days as well, there shouldn't be any /memory nodes without this property. Given that, is the add-legacy-node-first still necessary?Agreed, I did that after speaking with someone on IRC which stated (rightfully), that I should keep the legacy behavior if possible.
My concern was about HW that passes a device tree to barebox (PowerPC possibly?), where it might have worked before and now won't anymore.
If this is no real concern, it can be removed.
Cheers
Ahmad
Quoted 20 lines
However, I agree that since the
device_type= "memory" property should have always been there, there is no reason to keep this behavior.If you are ok with that, I will remove this chunk of code.
Quoted 9 lines
Sascha
--
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 1/2] of: base: parse all available memory nodes
Quoted 7 lines · Ahmad Fatoum
Hi,
Quoted 4 lines · Clément Leger
Quoted 3 lines
AFAIK the
device_type= "memory" property was mandatory in the early days as well, there shouldn't be any /memory nodes without this property. Given that, is the add-legacy-node-first still necessary?
Quoted 7 lines
Quoted 2 lines
Agreed, I did that after speaking with someone on IRC which stated (rightfully), that I should keep the legacy behavior if possible.
My concern was about HW that passes a device tree to barebox (PowerPC possibly?), where it might have worked before and now won't anymore.
If this is no real concern, it can be removed.
There is no PowerPC hardware supported by barebox that passes a device tree to barebox. I don't think this is necessary.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 1/2] of: base: parse all available memory nodes
Quoted 11 lines · Sascha Hauer
Quoted 10 lines · Ahmad Fatoum
Hi,
Quoted 6 lines · Clément Leger
Quoted 3 lines
AFAIK the
device_type= "memory" property was mandatory in the early days as well, there shouldn't be any /memory nodes without this property. Given that, is the add-legacy-node-first still necessary?Agreed, I did that after speaking with someone on IRC which stated (rightfully), that I should keep the legacy behavior if possible.
Quoted 7 lines
Quoted 4 lines
My concern was about HW that passes a device tree to barebox (PowerPC possibly?), where it might have worked before and now won't anymore.
If this is no real concern, it can be removed.
There is no PowerPC hardware supported by barebox that passes a device tree to barebox. I don't think this is necessary.
Turns out we had quite a few device trees that lacked a device_type = "memory"
property: https://lists.infradead.org/pipermail/barebox/2020-June/042269.html
The property used to be there, but when upstream removed skeleton.dtsi and either there was no upstream memory node to extend or it was renamed, we ended up with an invalid memory node.
Quoted 3 lines
Sascha
Signature · 9 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 2/2 of: base: allow of_add_memory to be called multiple times
In reply to Clement LegerCurrently, of_add_memory can't be called multiple times because it will always create memory banks by restarting at value 0. This means that, when adding a second memory bank by calling again of_add_memory, it will be named ram0 and overwrite the previous one. Fix that by using a static variable to store the current memory bank number in order to be preserved from one call to another.
--- drivers/of/base.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/of/base.c +6 -5
@@ -2019,6 +2019,8 @@ int of_set_property(struct device_node *np, const char *name, const void *val, ireturn 0 ; } +static int mem_bank_num; +int of_add_memory (struct device_node *node,bool dump) {const char *device_type;
@@ -2030,14 +2032,13 @@ int of_add_memory(struct device_node *node, bool dump)return -ENXIO ;while (!of_address_to_resource (node, n, &res)) { -if (!resource_size (&res)) { - n++; + n++; +if (!resource_size (&res))continue ; - } -of_add_memory_bank (node, dump, n, +of_add_memory_bank (node, dump, mem_bank_num, res.start,resource_size (&res)); - n++; + mem_bank_num++; }return 0 ;
Signature · 7 lines
2.15.0.276.g89ea799 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
v2 cover Allow parsing more than one memory node
Currently, barebox can only parse one memory node. This means that all other memory nodes (with device_type == "memory") will be ignored while parsing memory.
This patchset add a function of_probe_memory which will call of_add_memory for each found memory node. Additionally, of_add_memory has been modified to allow being called multiple times and correctly add all memory banks.
Changes v1 -> v2
- Reorder patches
- Remove legacy "memory" node handling
Clement Leger (2):
of: base: allow of_add_memory to be called multiple times
of: base: parse all available memory nodes
drivers/of/base.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-)
Signature · 7 lines
2.17.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 1/2 of: base: allow of_add_memory to be called multiple times
Currently, of_add_memory can't be called multiple times because it will always create memory banks by restarting at value 0. This means that, when adding a second memory bank by calling again of_add_memory, it will be named ram0 and overwrite the previous one. Fix that by using a static variable to store the current memory bank number in order to be preserved from one call to another.
--- drivers/of/base.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/of/base.c +6 -5
@@ -2019,6 +2019,8 @@ int of_set_property(struct device_node *np, const char *name, const void *val, ireturn 0 ; } +static int mem_bank_num; +int of_add_memory (struct device_node *node,bool dump) {const char *device_type;
@@ -2030,14 +2032,13 @@ int of_add_memory(struct device_node *node, bool dump)return -ENXIO ;while (!of_address_to_resource (node, n, &res)) { -if (!resource_size (&res)) { - n++; + n++; +if (!resource_size (&res))continue ; - } -of_add_memory_bank (node, dump, n, +of_add_memory_bank (node, dump, mem_bank_num, res.start,resource_size (&res)); - n++; + mem_bank_num++; }return 0 ;
Signature · 7 lines
2.17.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 2/2 of: base: parse all available memory nodes
In reply to Clement LegerCurrently, barebox only parse one memory node which is either the "/memory" node or the first node with device_type == "memory". However, the use of multiple memory nodes with device_type = "memory" property is allowed by the device tree specification and already correctly parsed by Linux kernel.
In order to fix that, add of_probe_memory function which loop over all available memory nodes matching device_type == "memory".
--- drivers/of/base.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
drivers/of/base.c +16 -6
@@ -2062,9 +2062,23 @@ const struct of_device_id of_default_bus_match_table[] = { } }; +static void of_probe_memory (void ) +{ +struct device_node *memory = root_node; + +/* Parse all available node with "memory" device_type */ +while (1 ) { + memory =of_find_node_by_type (memory,"memory" ); +if (!memory) +break ; + +of_add_memory (memory, false); + } +} +int of_probe (void ) { -struct device_node *memory, *firmware; +struct device_node *firmware;if (!root_node)return -ENODEV ;
@@ -2075,11 +2089,7 @@ int of_probe(void)if (of_model)barebox_set_model (of_model); - memory =of_find_node_by_path ("/memory" ); -if (!memory) - memory =of_find_node_by_type (root_node,"memory" ); -if (memory) -of_add_memory (memory, false); +of_probe_memory (); firmware =of_find_node_by_path ("/firmware" );if (firmware)
Signature · 7 lines
2.17.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
AppliedQuoted 8 lines · Clement Leger
Currently, barebox can only parse one memory node. This means that all other memory nodes (with
device_type== "memory") will be ignored while parsing memory.
This patchset add a functionof_probe_memorywhich will callof_add_memoryfor each found memory node. Additionally,of_add_memoryhas been modified to allow being called multiple times and correctly add all memory banks.
Quoted 7 lines
Changes v1 -> v2
- Reorder patches
- Remove legacy "memory" node handlingClement Leger (2):
of: base: allowof_add_memoryto be called multiple times
of: base: parse all available memory nodes
Applied, thanks
Sascha
Signature · 9 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Hi Clement.
Quoted 11 lines · Clement Leger
Currently, barebox can only parse one memory node. This means that all other memory nodes (with
device_type== "memory") will be ignored while parsing memory.
This patchset add a functionof_probe_memorywhich will callof_add_memoryfor each found memory node. Additionally,of_add_memoryhas been modified to allow being called multiple times and correctly add all memory banks.Clement Leger (2):
of: base: parse all available memory nodes
of: base: allowof_add_memoryto be called multiple times
With this order of the patches, after applying patch 1 the code will then use the last and not the first memory node. And only after the second patch it will work.
I think to improve bisectability the order of the two patches should be reversed.
Sam
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Hi Sam,
Quoted 15 lines · ----- On 17 Mar, 2020, at 08:35, Sam Ravnborg [email protected] wrote:
Hi Clement.
Quoted 11 lines · Clement Leger
Currently, barebox can only parse one memory node. This means that all other memory nodes (with
device_type== "memory") will be ignored while parsing memory.
This patchset add a functionof_probe_memorywhich will callof_add_memoryfor each found memory node. Additionally,of_add_memoryhas been modified to allow being called multiple times and correctly add all memory banks.Clement Leger (2):
of: base: parse all available memory nodes
of: base: allowof_add_memoryto be called multiple times
Quoted 6 lines
With this order of the patches, after applying patch 1 the code will then use the last and not the first memory node. And only after the second patch it will work.
I think to improve bisectability the order of the two patches should be reversed.
Oh yes indeed ! I will send a V2 after others have commented it.
Quoted 2 lines
Sam
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox