Skip to contentSkip to conversation

Honor FDT status property

PATCH Superseded Jan Remes 2 participants 9 messages May 12, 2022 – May 13, 2022

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Jan Remes

author
#0 lore raw

v3 cover Honor FDT status property

This series introduces a new function to check for the "status" property in the FDT nodes and uses it to ignore CPU nodes that are disabled.

Changes in v3:
- Don't check the property in PLIC/IMSIC/ACLINT drivers
- Start writing this changelog

Changes in v2:
- Implement the functionality separately from fdt_parse_hart_id
- Turn patch into proper series

Jan Remes (3):
lib: utils/fdt: introduce fdt_node_is_enabled()
lib: utils: check if CPU node is enabled
platform: generic: check if CPU node is enabled

 include/sbi_utils/fdt/fdt_helper.h |  2 ++
 lib/utils/fdt/fdt_domain.c         | 14 +++++++++++++-
 lib/utils/fdt/fdt_fixup.c          |  3 +++
 lib/utils/fdt/fdt_helper.c         | 21 +++++++++++++++++++++
 platform/generic/platform.c        |  3 +++
 5 files changed, 42 insertions(+), 1 deletion(-)
Signature · 1 line
2.36.1
author
#1 lore raw

PATCH v3 1/3 lib: utils/fdt: introduce fdt_node_is_enabled()

If an FDT node contains a "status" property and this property is not "ok" or "okay", this node should be ignored. Introduce a function that checks this.

---
 include/sbi_utils/fdt/fdt_helper.h |  2 ++
 lib/utils/fdt/fdt_helper.c         | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+)
include/sbi_utils/fdt/fdt_helper.h +2 -0
index 2279f96..a9c0a8a 100644
@@ -48,6 +48,8 @@ int fdt_parse_phandle_with_args(void *fdt, int nodeoff,
 int fdt_get_node_addr_size(void *fdt, int node, int index,
 			   uint64_t *addr, uint64_t *size);
 
+bool fdt_node_is_enabled(void *fdt, int nodeoff);
+
 int fdt_parse_hart_id(void *fdt, int cpu_offset, u32 *hartid);
 
 int fdt_parse_max_hart_id(void *fdt, u32 *max_hartid);
lib/utils/fdt/fdt_helper.c +18 -0
index 9a35969..3b45ae8 100644
@@ -216,6 +216,24 @@ int fdt_get_node_addr_size(void *fdt, int node, int index,
 	return 0;
 }
 
+bool fdt_node_is_enabled(void *fdt, int nodeoff)
+{
+	int len;
+	const void *prop;
+
+	prop = fdt_getprop(fdt, nodeoff, "status", &len);
+	if (!prop)
+		return true;
+
+	if (!strncmp(prop, "okay", strlen("okay")))
+		return true;
+
+	if (!strncmp(prop, "ok", strlen("ok")))
+		return true;
+
+	return false;
+}
+
 int fdt_parse_hart_id(void *fdt, int cpu_offset, u32 *hartid)
 {
 	int len;
Signature · 1 line
2.36.1
#2 lore raw

PATCH v3 1/3 lib: utils/fdt: introduce fdt_node_is_enabled()

Quoted 6 lines · Jan Remes

If an FDT node contains a "status" property and this property is not "ok" or "okay", this node should be ignored. Introduce a function that checks this.

I had already given Reviewed-by to this patch in v2. Please add various Reviewed-by tags after your Signed-off-by when sending new patch version so that we know which patches are already reviewed.

We also have patchwork setup for OpenSBI mailing list which also tracks reviewed/acked patches.
(https://patchwork.ozlabs.org/project/opensbi/list/)

Looks good to me.

Regards,
Anup

Quoted 55 lines
---
 include/sbi_utils/fdt/fdt_helper.h |  2 ++
 lib/utils/fdt/fdt_helper.c         | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+)
include/sbi_utils/fdt/fdt_helper.h +2 -0
index 2279f96..a9c0a8a 100644
@@ -48,6 +48,8 @@ int fdt_parse_phandle_with_args(void *fdt, int nodeoff,
 int fdt_get_node_addr_size(void *fdt, int node, int index,
                           uint64_t *addr, uint64_t *size);
 
+bool fdt_node_is_enabled(void *fdt, int nodeoff);
+
 int fdt_parse_hart_id(void *fdt, int cpu_offset, u32 *hartid);
 
 int fdt_parse_max_hart_id(void *fdt, u32 *max_hartid);
lib/utils/fdt/fdt_helper.c +18 -1
index 9a35969..3b45ae8 100644
@@ -216,6 +216,24 @@ int fdt_get_node_addr_size(void *fdt, int node, int index,
        return 0;
 }
 
+bool fdt_node_is_enabled(void *fdt, int nodeoff)
+{
+       int len;
+       const void *prop;
+
+       prop = fdt_getprop(fdt, nodeoff, "status", &len);
+       if (!prop)
+               return true;
+
+       if (!strncmp(prop, "okay", strlen("okay")))
+               return true;
+
+       if (!strncmp(prop, "ok", strlen("ok")))
+               return true;
+
+       return false;
+}
+
 int fdt_parse_hart_id(void *fdt, int cpu_offset, u32 *hartid)
 {
        int len;
--

2.36.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

author
#3 lore raw

PATCH v3 2/3 lib: utils: check if CPU node is enabled

In reply to Jan Remes

Ignore CPU nodes in FDT that are not enabled.

---
 lib/utils/fdt/fdt_domain.c | 14 +++++++++++++-
 lib/utils/fdt/fdt_fixup.c  |  3 +++
 lib/utils/fdt/fdt_helper.c |  3 +++
 3 files changed, 19 insertions(+), 1 deletion(-)
lib/utils/fdt/fdt_domain.c +13 -1
index 676c757..bd0eec3 100644
@@ -165,6 +165,9 @@ void fdt_domain_fixup(void *fdt)
 		if (err)
 			continue;
 
+		if (!fdt_node_is_enabled(fdt, doffset))
+			continue;
+
 		fdt_nop_property(fdt, doffset, "opensbi-domain");
 	}
 
@@ -308,6 +311,9 @@ static int __fdt_parse_domain(void *fdt, int domain_offset, void *opaque)
 			if (err)
 				return err;
 
+			if (!fdt_node_is_enabled(fdt, cpu_offset))
+				continue;
+
 			sbi_hartmask_set_hart(val32, mask);
 		}
 	}
@@ -347,7 +353,7 @@ static int __fdt_parse_domain(void *fdt, int domain_offset, void *opaque)
 	if (val && len >= 4) {
 		cpu_offset = fdt_node_offset_by_phandle(fdt,
 							 fdt32_to_cpu(*val));
-		if (cpu_offset >= 0)
+		if (cpu_offset >= 0 && fdt_node_is_enabled(fdt, cpu_offset))
 			fdt_parse_hart_id(fdt, cpu_offset, &val32);
 	} else {
 		if (domain_offset == *cold_domain_offset)
@@ -414,6 +420,9 @@ static int __fdt_parse_domain(void *fdt, int domain_offset, void *opaque)
 		if (SBI_HARTMASK_MAX_BITS <= val32)
 			continue;
 
+		if (!fdt_node_is_enabled(fdt, cpu_offset))
+			continue;
+
 		val = fdt_getprop(fdt, cpu_offset, "opensbi-domain", &len);
 		if (!val || len < 4)
 			return SBI_EINVAL;
@@ -460,6 +469,9 @@ int fdt_domains_populate(void *fdt)
 		if (hartid != cold_hartid)
 			continue;
 
+		if (!fdt_node_is_enabled(fdt, cpu_offset))
+			continue;
+
 		val = fdt_getprop(fdt, cpu_offset, "opensbi-domain", &len);
 		if (val && len >= 4)
 			cold_domain_offset = fdt_node_offset_by_phandle(fdt,
lib/utils/fdt/fdt_fixup.c +3 -0
index a80bd82..d1050bb 100644
@@ -38,6 +38,9 @@ void fdt_cpu_fixup(void *fdt)
 		if (err)
 			continue;
 
+		if (!fdt_node_is_enabled(fdt, cpu_offset))
+			continue;
+
 		/*
 		 * Disable a HART DT node if one of the following is true:
 		 * 1. The HART is not assigned to the current domain
lib/utils/fdt/fdt_helper.c +3 -0
index 3b45ae8..5db3fbe 100644
@@ -283,6 +283,9 @@ int fdt_parse_max_hart_id(void *fdt, u32 *max_hartid)
 		if (err)
 			continue;
 
+		if (!fdt_node_is_enabled(fdt, cpu_offset))
+			continue;
+
 		if (hartid > *max_hartid)
 			*max_hartid = hartid;
 	}
Signature · 1 line
2.36.1
#4 lore raw

PATCH v3 2/3 lib: utils: check if CPU node is enabled

Quoted 82 lines · Jan Remes

Ignore CPU nodes in FDT that are not enabled.

---
 lib/utils/fdt/fdt_domain.c | 14 +++++++++++++-
 lib/utils/fdt/fdt_fixup.c  |  3 +++
 lib/utils/fdt/fdt_helper.c |  3 +++
 3 files changed, 19 insertions(+), 1 deletion(-)
lib/utils/fdt/fdt_domain.c +13 -1
index 676c757..bd0eec3 100644
@@ -165,6 +165,9 @@ void fdt_domain_fixup(void *fdt)
                if (err)
                        continue;
 
+               if (!fdt_node_is_enabled(fdt, doffset))
+                       continue;
+
                fdt_nop_property(fdt, doffset, "opensbi-domain");
        }
 
@@ -308,6 +311,9 @@ static int __fdt_parse_domain(void *fdt, int domain_offset, void *opaque)
                        if (err)
                                return err;
 
+                       if (!fdt_node_is_enabled(fdt, cpu_offset))
+                               continue;
+
                        sbi_hartmask_set_hart(val32, mask);
                }
        }
@@ -347,7 +353,7 @@ static int __fdt_parse_domain(void *fdt, int domain_offset, void *opaque)
        if (val && len >= 4) {
                cpu_offset = fdt_node_offset_by_phandle(fdt,
                                                         fdt32_to_cpu(*val));
-               if (cpu_offset >= 0)
+               if (cpu_offset >= 0 && fdt_node_is_enabled(fdt, cpu_offset))
                        fdt_parse_hart_id(fdt, cpu_offset, &val32);
        } else {
                if (domain_offset == *cold_domain_offset)
@@ -414,6 +420,9 @@ static int __fdt_parse_domain(void *fdt, int domain_offset, void *opaque)
                if (SBI_HARTMASK_MAX_BITS <= val32)
                        continue;
 
+               if (!fdt_node_is_enabled(fdt, cpu_offset))
+                       continue;
+
                val = fdt_getprop(fdt, cpu_offset, "opensbi-domain", &len);
                if (!val || len < 4)
                        return SBI_EINVAL;
@@ -460,6 +469,9 @@ int fdt_domains_populate(void *fdt)
                if (hartid != cold_hartid)
                        continue;
 
+               if (!fdt_node_is_enabled(fdt, cpu_offset))
+                       continue;
+
                val = fdt_getprop(fdt, cpu_offset, "opensbi-domain", &len);
                if (val && len >= 4)
                        cold_domain_offset = fdt_node_offset_by_phandle(fdt,
lib/utils/fdt/fdt_fixup.c +3 -0
index a80bd82..d1050bb 100644
@@ -38,6 +38,9 @@ void fdt_cpu_fixup(void *fdt)
                if (err)
                        continue;
 
+               if (!fdt_node_is_enabled(fdt, cpu_offset))
+                       continue;
+
                /*
                 * Disable a HART DT node if one of the following is true:
                 * 1. The HART is not assigned to the current domain
lib/utils/fdt/fdt_helper.c +0 -0
index 3b45ae8..5db3fbe 100644

lib/utils/fdt/fdt_helper.c int fdt_parse_max_hart_id(void *fdt, u32 *max_hartid) · line 288

Quoted 6 lines
lib/utils/fdt/fdt_helper.c +3 -0
@@ -283,6 +283,9 @@ int fdt_parse_max_hart_id(void *fdt, u32 *max_hartid)
                if (err)
                        continue;
 
+               if (!fdt_node_is_enabled(fdt, cpu_offset))
+                       continue;
+

This change is not needed because maximum hartid supported in a system remains the same irrespective of whether certain CPU are disabled/fused.

Quoted 11 lines
lib/utils/fdt/fdt_helper.c +0 -1
                if (hartid > *max_hartid)
                        *max_hartid = hartid;
        }
--

2.36.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

Apart from the above minor comment, this looks good to me.

Regards,
Anup

author
#5 lore raw

PATCH v3 2/3 lib: utils: check if CPU node is enabled

Quoted 87 lines · Anup Patel
Quoted 85 lines · Jan Remes

Ignore CPU nodes in FDT that are not enabled.

---
 lib/utils/fdt/fdt_domain.c | 14 +++++++++++++-
 lib/utils/fdt/fdt_fixup.c  |  3 +++
 lib/utils/fdt/fdt_helper.c |  3 +++
 3 files changed, 19 insertions(+), 1 deletion(-)
lib/utils/fdt/fdt_domain.c +13 -1
index 676c757..bd0eec3 100644
@@ -165,6 +165,9 @@ void fdt_domain_fixup(void *fdt)
                if (err)
                        continue;
 
+               if (!fdt_node_is_enabled(fdt, doffset))
+                       continue;
+
                fdt_nop_property(fdt, doffset, "opensbi-domain");
        }
 
@@ -308,6 +311,9 @@ static int __fdt_parse_domain(void *fdt, int domain_offset, void *opaque)
                        if (err)
                                return err;
 
+                       if (!fdt_node_is_enabled(fdt, cpu_offset))
+                               continue;
+
                        sbi_hartmask_set_hart(val32, mask);
                }
        }
@@ -347,7 +353,7 @@ static int __fdt_parse_domain(void *fdt, int domain_offset, void *opaque)
        if (val && len >= 4) {
                cpu_offset = fdt_node_offset_by_phandle(fdt,
                                                         fdt32_to_cpu(*val));
-               if (cpu_offset >= 0)
+               if (cpu_offset >= 0 && fdt_node_is_enabled(fdt, cpu_offset))
                        fdt_parse_hart_id(fdt, cpu_offset, &val32);
        } else {
                if (domain_offset == *cold_domain_offset)
@@ -414,6 +420,9 @@ static int __fdt_parse_domain(void *fdt, int domain_offset, void *opaque)
                if (SBI_HARTMASK_MAX_BITS <= val32)
                        continue;
 
+               if (!fdt_node_is_enabled(fdt, cpu_offset))
+                       continue;
+
                val = fdt_getprop(fdt, cpu_offset, "opensbi-domain", &len);
                if (!val || len < 4)
                        return SBI_EINVAL;
@@ -460,6 +469,9 @@ int fdt_domains_populate(void *fdt)
                if (hartid != cold_hartid)
                        continue;
 
+               if (!fdt_node_is_enabled(fdt, cpu_offset))
+                       continue;
+
                val = fdt_getprop(fdt, cpu_offset, "opensbi-domain", &len);
                if (val && len >= 4)
                        cold_domain_offset = fdt_node_offset_by_phandle(fdt,
lib/utils/fdt/fdt_fixup.c +3 -0
index a80bd82..d1050bb 100644
@@ -38,6 +38,9 @@ void fdt_cpu_fixup(void *fdt)
                if (err)
                        continue;
 
+               if (!fdt_node_is_enabled(fdt, cpu_offset))
+                       continue;
+
                /*
                 * Disable a HART DT node if one of the following is true:
                 * 1. The HART is not assigned to the current domain
lib/utils/fdt/fdt_helper.c +0 -0
index 3b45ae8..5db3fbe 100644
@@ -283,6 +283,9 @@ int fdt_parse_max_hart_id(void *fdt, u32 *max_hartid)
                if (err)
                        continue;
 
Quoted 7 lines

lib/utils/fdt/fdt_helper.c int fdt_parse_max_hart_id(void *fdt, u32 *max_hartid) · line 288

Quoted 3 lines
lib/utils/fdt/fdt_helper.c +3 -0
+               if (!fdt_node_is_enabled(fdt, cpu_offset))
+                       continue;
+

This change is not needed because maximum hartid supported in a system remains the same irrespective of whether certain CPU are disabled/fused.

What should the fdt_parse_max_hart_id() function return? The highest hart-id of the harts *used* in the system or *supported* by a system?

It makes sense to me to completely ignore the FDT nodes with status = "disabled" except in the code handling interrupts-extended which leads to them (where they should be skipped properly).

For an FPGA based system where there can be a different number of harts for each build, it makes sense to maintain a base FDT with all harts disabled, and selectively
enable just those present in the build. And then the disabled cores are very much
not there at all.

Quoted 13 lines
Quoted 8 lines
lib/utils/fdt/fdt_helper.c +0 -1
                if (hartid > *max_hartid)
                        *max_hartid = hartid;
        }
--

2.36.1

Quoted 4 lines

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

Quoted 6 lines

Apart from the above minor comment, this looks good to me.

Regards,
Anup

When we resolve the discussion above, I can send a v4 with correct
Reviewed-by: tags.

Thanks,
Jan

#6 lore raw

PATCH v3 2/3 lib: utils: check if CPU node is enabled

Quoted 97 lines · Jan Reme?
Quoted 87 lines · Anup Patel
Quoted 85 lines · Jan Remes

Ignore CPU nodes in FDT that are not enabled.

---
 lib/utils/fdt/fdt_domain.c | 14 +++++++++++++-
 lib/utils/fdt/fdt_fixup.c  |  3 +++
 lib/utils/fdt/fdt_helper.c |  3 +++
 3 files changed, 19 insertions(+), 1 deletion(-)
lib/utils/fdt/fdt_domain.c +13 -1
index 676c757..bd0eec3 100644
@@ -165,6 +165,9 @@ void fdt_domain_fixup(void *fdt)
                if (err)
                        continue;
 
+               if (!fdt_node_is_enabled(fdt, doffset))
+                       continue;
+
                fdt_nop_property(fdt, doffset, "opensbi-domain");
        }
 
@@ -308,6 +311,9 @@ static int __fdt_parse_domain(void *fdt, int domain_offset, void *opaque)
                        if (err)
                                return err;
 
+                       if (!fdt_node_is_enabled(fdt, cpu_offset))
+                               continue;
+
                        sbi_hartmask_set_hart(val32, mask);
                }
        }
@@ -347,7 +353,7 @@ static int __fdt_parse_domain(void *fdt, int domain_offset, void *opaque)
        if (val && len >= 4) {
                cpu_offset = fdt_node_offset_by_phandle(fdt,
                                                         fdt32_to_cpu(*val));
-               if (cpu_offset >= 0)
+               if (cpu_offset >= 0 && fdt_node_is_enabled(fdt, cpu_offset))
                        fdt_parse_hart_id(fdt, cpu_offset, &val32);
        } else {
                if (domain_offset == *cold_domain_offset)
@@ -414,6 +420,9 @@ static int __fdt_parse_domain(void *fdt, int domain_offset, void *opaque)
                if (SBI_HARTMASK_MAX_BITS <= val32)
                        continue;
 
+               if (!fdt_node_is_enabled(fdt, cpu_offset))
+                       continue;
+
                val = fdt_getprop(fdt, cpu_offset, "opensbi-domain", &len);
                if (!val || len < 4)
                        return SBI_EINVAL;
@@ -460,6 +469,9 @@ int fdt_domains_populate(void *fdt)
                if (hartid != cold_hartid)
                        continue;
 
+               if (!fdt_node_is_enabled(fdt, cpu_offset))
+                       continue;
+
                val = fdt_getprop(fdt, cpu_offset, "opensbi-domain", &len);
                if (val && len >= 4)
                        cold_domain_offset = fdt_node_offset_by_phandle(fdt,
lib/utils/fdt/fdt_fixup.c +3 -0
index a80bd82..d1050bb 100644
@@ -38,6 +38,9 @@ void fdt_cpu_fixup(void *fdt)
                if (err)
                        continue;
 
+               if (!fdt_node_is_enabled(fdt, cpu_offset))
+                       continue;
+
                /*
                 * Disable a HART DT node if one of the following is true:
                 * 1. The HART is not assigned to the current domain
lib/utils/fdt/fdt_helper.c +0 -0
index 3b45ae8..5db3fbe 100644
@@ -283,6 +283,9 @@ int fdt_parse_max_hart_id(void *fdt, u32 *max_hartid)
                if (err)
                        continue;
 
Quoted 7 lines

lib/utils/fdt/fdt_helper.c int fdt_parse_max_hart_id(void *fdt, u32 *max_hartid) · line 288

Quoted 3 lines
lib/utils/fdt/fdt_helper.c +3 -0
+               if (!fdt_node_is_enabled(fdt, cpu_offset))
+                       continue;
+

This change is not needed because maximum hartid supported in a system remains the same irrespective of whether certain CPU are disabled/fused.

Quoted 2 lines

What should the fdt_parse_max_hart_id() function return? The highest hart-id of the harts *used* in the system or *supported* by a system?

Actually, it was meant to return the highest hard-id of the harts "supported" by a system. Unfortunately, we have not added doxygen style comments for various FDT helper functions.

Quoted 4 lines

It makes sense to me to completely ignore the FDT nodes with status = "disabled" except in the code handling interrupts-extended which leads to them (where they should be skipped properly).

I am fine with what you are suggesting but the semantics of function should be reflected in the name.

You can rename fdt_parse_max_hart_id() to fdt_parse_max_enabled_hart_id() and have the fdt_node_is_enabled() check.

Quoted 7 lines

For an FPGA based system where there can be a different number of harts for each build, it makes sense to maintain a base FDT with all harts disabled, and selectively
enable just those present in the build. And then the disabled cores are very much
not there at all.

I suggest you rename the function to reflect what you are suggesting here.

Quoted 18 lines
Quoted 18 lines
Quoted 9 lines
lib/utils/fdt/fdt_helper.c +0 -1
                if (hartid > *max_hartid)
                        *max_hartid = hartid;
        }
--

2.36.1

Quoted 4 lines

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

Apart from the above minor comment, this looks good to me.

Quoted 8 lines
Quoted 2 lines

Regards,
Anup

When we resolve the discussion above, I can send a v4 with correct
Reviewed-by: tags.

Thanks,
Jan

Regards,
Anup

author
#7 lore raw

PATCH v3 3/3 platform: generic: check if CPU node is enabled

In reply to Jan Remes

Ignore CPU nodes in FDT which are not enabled.

---
 platform/generic/platform.c | 3 +++
 1 file changed, 3 insertions(+)
platform/generic/platform.c +3 -0
index 8a4fb70..86db960 100644
@@ -107,6 +107,9 @@ unsigned long fw_platform_init(unsigned long arg0, unsigned long arg1,
 		if (SBI_HARTMASK_MAX_BITS <= hartid)
 			continue;
 
+		if (!fdt_node_is_enabled(fdt, cpu_offset))
+			continue;
+
 		generic_hart_index2id[hart_count++] = hartid;
 	}
 
Signature · 1 line
2.36.1
#8 lore raw

PATCH v3 3/3 platform: generic: check if CPU node is enabled

Quoted 4 lines · Jan Remes

Ignore CPU nodes in FDT which are not enabled.

This was already reviewed in your v2 series.

Looks good to me.

Regards,
Anup

Quoted 26 lines
---
 platform/generic/platform.c | 3 +++
 1 file changed, 3 insertions(+)
platform/generic/platform.c +3 -1
index 8a4fb70..86db960 100644
@@ -107,6 +107,9 @@ unsigned long fw_platform_init(unsigned long arg0, unsigned long arg1,
                if (SBI_HARTMASK_MAX_BITS <= hartid)
                        continue;
 
+               if (!fdt_node_is_enabled(fdt, cpu_offset))
+                       continue;
+
                generic_hart_index2id[hart_count++] = hartid;
        }
 
--

2.36.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi