linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] of: base: Skip CPU nodes with non-"okay"/"disabled" status
@ 2021-11-08  8:48 Matthias Schiffer
  2021-11-14 19:41 ` Frank Rowand
  0 siblings, 1 reply; 6+ messages in thread
From: Matthias Schiffer @ 2021-11-08  8:48 UTC (permalink / raw)
  To: Rob Herring, Frank Rowand; +Cc: devicetree, linux-kernel, Matthias Schiffer

Allow fully disabling CPU nodes using status = "fail". Having no status
property at all is still interpreted as "okay" as usual.

This allows a bootloader to change the number of available CPUs (for
example when a common DTS is used for SoC variants with different numbers
of cores) without deleting the nodes altogether, which could require
additional fixups to avoid dangling phandle references.

References:
- https://www.lkml.org/lkml/2020/8/26/1237
- https://www.spinics.net/lists/devicetree-spec/msg01007.html
- https://github.com/devicetree-org/dt-schema/pull/61

Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
---
 drivers/of/base.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 61de453b885c..4e9973627c8d 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -650,6 +650,32 @@ bool of_device_is_available(const struct device_node *device)
 }
 EXPORT_SYMBOL(of_device_is_available);
 
+/**
+ *  __of_device_is_disabled - check if a device has status "disabled"
+ *
+ *  @device: Node to check status for, with locks already held
+ *
+ *  Return: True if the status property is set to "disabled",
+ *  false otherwise
+ *
+ *  Most callers should use __of_device_is_available() instead, this function
+ *  only exists due to the special interpretation of the "disabled" status for
+ *  CPU nodes.
+ */
+static bool __of_device_is_disabled(const struct device_node *device)
+{
+	const char *status;
+
+	if (!device)
+		return false;
+
+	status = __of_get_property(device, "status", NULL);
+	if (status == NULL)
+		return false;
+
+	return !strcmp(status, "disabled");
+}
+
 /**
  *  of_device_is_big_endian - check if a device has BE registers
  *
@@ -817,6 +843,9 @@ struct device_node *of_get_next_cpu_node(struct device_node *prev)
 		of_node_put(node);
 	}
 	for (; next; next = next->sibling) {
+		if (!__of_device_is_available(next) &&
+		    !__of_device_is_disabled(next))
+			continue;
 		if (!(of_node_name_eq(next, "cpu") ||
 		      __of_node_is_type(next, "cpu")))
 			continue;
-- 
2.17.1


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

end of thread, other threads:[~2021-11-16 15:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-08  8:48 [PATCH] of: base: Skip CPU nodes with non-"okay"/"disabled" status Matthias Schiffer
2021-11-14 19:41 ` Frank Rowand
2021-11-15  8:13   ` Matthias Schiffer
2021-11-15 17:23     ` Frank Rowand
2021-11-16  8:32       ` Matthias Schiffer
2021-11-16 15:07         ` Frank Rowand

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).