Skip to contentSkip to conversation

Honor FDT status property

PATCH New Jan Remes 2 participants 10 messages May 13, 2022 – May 14, 2022

lore
Share & tools
lore

Jan Remes

author
#0 lore raw

v4 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 v4:
- Rename fdt_parse_max_hart_id to fdt_parse_max_enabled_hart_id
- Assign correct Reviewed-by: tags

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 (4):
lib: utils/fdt: introduce fdt_node_is_enabled()
lib: utils: check if CPU node is enabled
platform: generic: check if CPU node is enabled
lib: utils/fdt: rename fdt_parse_max_hart_id

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

PATCH v4 1/4 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
Applied
#2 lore raw

PATCH v4 1/4 lib: utils/fdt: introduce fdt_node_is_enabled()

Quoted 8 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.

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 50 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

author
#3 lore raw

PATCH v4 2/4 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
Applied
#4 lore raw

PATCH v4 2/4 lib: utils: check if CPU node is enabled

Quoted 5 lines · Jan Remes

Ignore CPU nodes in FDT that are not enabled.

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 90 lines
---
 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 -1
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;
        }
--

2.36.1

author
#5 lore raw

PATCH v4 3/4 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
Applied
#6 lore raw

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

Quoted 6 lines · Jan Remes

Ignore CPU nodes in FDT which are not enabled.

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 21 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

author
#7 lore raw

PATCH v4 4/4 lib: utils/fdt: rename fdt_parse_max_hart_id

In reply to Jan Remes

The function returns the highest hart-id of the harts actually used in the system (enabled). Change the name to reflect this fact.

---
 include/sbi_utils/fdt/fdt_helper.h | 2 +-
 lib/utils/fdt/fdt_helper.c         | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/sbi_utils/fdt/fdt_helper.h +1 -1
index a9c0a8a..74ea234 100644
@@ -52,7 +52,7 @@ 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);
+int fdt_parse_max_enabled_hart_id(void *fdt, u32 *max_hartid);
 
 int fdt_parse_timebase_frequency(void *fdt, unsigned long *freq);
 
lib/utils/fdt/fdt_helper.c +1 -1
index 5db3fbe..2bdb1ef 100644
@@ -262,7 +262,7 @@ int fdt_parse_hart_id(void *fdt, int cpu_offset, u32 *hartid)
 	return 0;
 }
 
-int fdt_parse_max_hart_id(void *fdt, u32 *max_hartid)
+int fdt_parse_max_enabled_hart_id(void *fdt, u32 *max_hartid)
 {
 	u32 hartid;
 	int err, cpu_offset, cpus_offset;
Signature · 1 line
2.36.1
#8 lore raw

PATCH v4 4/4 lib: utils/fdt: rename fdt_parse_max_hart_id

Quoted 5 lines · Jan Remes

The function returns the highest hart-id of the harts actually used in the system (enabled). Change the name to reflect this fact.

Looks good to me.

Regards,
Anup

Quoted 39 lines
---
 include/sbi_utils/fdt/fdt_helper.h | 2 +-
 lib/utils/fdt/fdt_helper.c         | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/sbi_utils/fdt/fdt_helper.h +1 -1
index a9c0a8a..74ea234 100644
@@ -52,7 +52,7 @@ 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);
+int fdt_parse_max_enabled_hart_id(void *fdt, u32 *max_hartid);
 
 int fdt_parse_timebase_frequency(void *fdt, unsigned long *freq);
 
lib/utils/fdt/fdt_helper.c +1 -2
index 5db3fbe..2bdb1ef 100644
@@ -262,7 +262,7 @@ int fdt_parse_hart_id(void *fdt, int cpu_offset, u32 *hartid)
        return 0;
 }
 
-int fdt_parse_max_hart_id(void *fdt, u32 *max_hartid)
+int fdt_parse_max_enabled_hart_id(void *fdt, u32 *max_hartid)
 {
        u32 hartid;
        int err, cpu_offset, cpus_offset;
--

2.36.1

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

Applied
#9 lore raw

PATCH v4 4/4 lib: utils/fdt: rename fdt_parse_max_hart_id

Quoted 11 lines · Anup Patel
Quoted 5 lines · Jan Remes

The function returns the highest hart-id of the harts actually used in the system (enabled). Change the name to reflect this fact.

Looks good to me.

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 43 lines

Regards,
Anup

Quoted 39 lines
---
 include/sbi_utils/fdt/fdt_helper.h | 2 +-
 lib/utils/fdt/fdt_helper.c         | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/sbi_utils/fdt/fdt_helper.h +1 -1
index a9c0a8a..74ea234 100644
@@ -52,7 +52,7 @@ 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);
+int fdt_parse_max_enabled_hart_id(void *fdt, u32 *max_hartid);
 
 int fdt_parse_timebase_frequency(void *fdt, unsigned long *freq);
 
lib/utils/fdt/fdt_helper.c +1 -2
index 5db3fbe..2bdb1ef 100644
@@ -262,7 +262,7 @@ int fdt_parse_hart_id(void *fdt, int cpu_offset, u32 *hartid)
        return 0;
 }
 
-int fdt_parse_max_hart_id(void *fdt, u32 *max_hartid)
+int fdt_parse_max_enabled_hart_id(void *fdt, u32 *max_hartid)
 {
        u32 hartid;
        int err, cpu_offset, cpus_offset;
--

2.36.1

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