linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rob Herring <robh@kernel.org>
To: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Frank Rowand <frowand.list@gmail.com>
Subject: [PATCH 01/21] of: Add cpu node iterator for_each_of_cpu_node()
Date: Wed,  5 Sep 2018 14:37:18 -0500	[thread overview]
Message-ID: <20180905193738.19325-2-robh@kernel.org> (raw)
In-Reply-To: <20180905193738.19325-1-robh@kernel.org>

Iterating thru cpu nodes is a common pattern. Create a common iterator
which can find child nodes either by node name or device_type == cpu.
Using the former will allow for eventually dropping device_type
properties which are deprecated for FDT.

Cc: Frank Rowand <frowand.list@gmail.com>
Signed-off-by: Rob Herring <robh@kernel.org>
---
 drivers/of/base.c  | 39 +++++++++++++++++++++++++++++++++++++++
 include/linux/of.h | 11 +++++++++++
 2 files changed, 50 insertions(+)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index a055cd1ef96d..4807db0a35b3 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -741,6 +741,45 @@ struct device_node *of_get_next_available_child(const struct device_node *node,
 }
 EXPORT_SYMBOL(of_get_next_available_child);

+/**
+ *	of_get_next_cpu_node - Iterate on cpu nodes
+ *	@prev:	previous child of the /cpus node, or NULL to get first
+ *
+ *	Returns a cpu node pointer with refcount incremented, use of_node_put()
+ *	on it when done. Returns NULL when prev is the last child. Decrements
+ *	the refcount of prev.
+ */
+struct device_node *of_get_next_cpu_node(struct device_node *prev)
+{
+	struct device_node *next = NULL;
+	unsigned long flags;
+	struct device_node *node;
+
+	if (!prev)
+		node = of_find_node_by_path("/cpus");
+
+	raw_spin_lock_irqsave(&devtree_lock, flags);
+	if (prev)
+		next = prev->sibling;
+	else if (node) {
+		next = node->child;
+		of_node_put(node);
+	}
+	for (; next; next = next->sibling) {
+		if (!(of_node_name_eq(next, "cpu") ||
+		      (next->type && !of_node_cmp(next->type, "cpu"))))
+			continue;
+		if (!__of_device_is_available(next))
+			continue;
+		if (of_node_get(next))
+			break;
+	}
+	of_node_put(prev);
+	raw_spin_unlock_irqrestore(&devtree_lock, flags);
+	return next;
+}
+EXPORT_SYMBOL(of_get_next_cpu_node);
+
 /**
  * of_get_compatible_child - Find compatible child node
  * @parent:	parent node
diff --git a/include/linux/of.h b/include/linux/of.h
index 99b0ebf49632..1aca0dbd35df 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -353,6 +353,8 @@ extern const void *of_get_property(const struct device_node *node,
 				const char *name,
 				int *lenp);
 extern struct device_node *of_get_cpu_node(int cpu, unsigned int *thread);
+extern struct device_node *of_get_next_cpu_node(struct device_node *prev);
+
 #define for_each_property_of_node(dn, pp) \
 	for (pp = dn->properties; pp != NULL; pp = pp->next)

@@ -754,6 +756,11 @@ static inline struct device_node *of_get_cpu_node(int cpu,
 	return NULL;
 }

+static inline struct device_node *of_get_next_cpu_node(struct device_node *prev)
+{
+	return NULL;
+}
+
 static inline int of_n_addr_cells(struct device_node *np)
 {
 	return 0;
@@ -1217,6 +1224,10 @@ static inline int of_property_read_s32(const struct device_node *np,
 	for (child = of_get_next_available_child(parent, NULL); child != NULL; \
 	     child = of_get_next_available_child(parent, child))

+#define for_each_of_cpu_node(cpu) \
+	for (cpu = of_get_next_cpu_node(NULL); cpu != NULL; \
+	     cpu = of_get_next_cpu_node(cpu))
+
 #define for_each_node_with_property(dn, prop_name) \
 	for (dn = of_find_node_with_property(NULL, prop_name); dn; \
 	     dn = of_find_node_with_property(dn, prop_name))
--
2.17.1

  reply	other threads:[~2018-09-05 19:39 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-05 19:37 [PATCH 00/21] DT cpu node iterator Rob Herring
2018-09-05 19:37 ` Rob Herring [this message]
2018-09-06  8:45   ` [PATCH 01/21] of: Add cpu node iterator for_each_of_cpu_node() Geert Uytterhoeven
2018-10-30 14:18   ` Michael Ellerman
2018-10-30 14:20     ` Michael Ellerman
2018-10-30 15:00       ` Rob Herring
2018-11-01 10:52         ` Michael Ellerman
2018-11-01 15:12           ` Segher Boessenkool
2018-11-01 15:57             ` Rob Herring
2018-09-05 19:37 ` [PATCH 02/21] of: Support matching cpu nodes with no 'reg' property Rob Herring
2018-09-05 19:37 ` [PATCH 03/21] ARM: use for_each_of_cpu_node iterator Rob Herring
2018-09-05 19:37 ` [PATCH 04/21] ARM: topology: remove unneeded check for /cpus node Rob Herring
2018-09-05 19:37 ` [PATCH 05/21] ARM: shmobile: use for_each_of_cpu_node iterator Rob Herring
2018-09-06  8:52   ` Geert Uytterhoeven
2018-09-06  8:56   ` Simon Horman
2018-09-05 19:37 ` [PATCH 06/21] arm64: " Rob Herring
2018-09-06 10:04   ` Will Deacon
2018-09-05 19:37 ` [PATCH 07/21] c6x: " Rob Herring
2018-09-05 19:37 ` [PATCH 08/21] microblaze: get cpu node with of_get_cpu_node Rob Herring
2018-09-10 14:56   ` Michal Simek
2018-09-10 20:49     ` Rob Herring
2018-09-11 12:15       ` Michal Simek
2018-09-05 19:37 ` [PATCH 09/21] nios2: " Rob Herring
2018-09-05 19:37 ` [PATCH 10/21] openrisc: use for_each_of_cpu_node iterator Rob Herring
2018-09-06  9:12   ` Stafford Horne
2018-09-05 19:37 ` [PATCH 11/21] powerpc: " Rob Herring
2018-09-05 19:37 ` [PATCH 12/21] powerpc: 4xx: get cpu node with of_get_cpu_node Rob Herring
2018-09-05 19:37 ` [PATCH 13/21] powerpc: 8xx: " Rob Herring
2018-09-05 19:37 ` [PATCH 14/21] riscv: use for_each_of_cpu_node iterator Rob Herring
2018-09-10 13:37   ` Christoph Hellwig
2018-09-10 13:51     ` Rob Herring
2018-09-18 22:53   ` Palmer Dabbelt
2018-09-05 19:37 ` [PATCH 15/21] SH: " Rob Herring
2018-09-05 19:37 ` [PATCH 16/21] x86: DT: " Rob Herring
2018-09-06  8:15   ` Thomas Gleixner
2018-09-05 19:37 ` [PATCH 17/21] clk: mvebu: " Rob Herring
2018-09-06  1:47   ` Stephen Boyd
2018-09-05 19:37 ` [PATCH 18/21] edac: cpc925: " Rob Herring
2018-09-06  8:35   ` Borislav Petkov
2018-09-06 11:12     ` Rob Herring
2018-09-06 12:20       ` Borislav Petkov
2018-09-05 19:37 ` [PATCH 19/21] iommu: fsl_pamu: " Rob Herring
2018-09-05 19:37 ` [PATCH 20/21] of: " Rob Herring
2018-10-31 12:46   ` NXP P50XX/e5500 secondary CPUs not onlined with current mainline (was [PATCH 20/21] of: use for_each_of_cpu_node iterator) Michael Ellerman
2018-10-31 14:25     ` Rob Herring
2018-11-01 10:55       ` Michael Ellerman
2018-09-05 19:37 ` [PATCH 21/21] fbdev: fsl-diu: get cpu node with of_get_cpu_node Rob Herring
2018-09-11  3:34   ` Timur Tabi
     [not found] ` <CAHTX3d+BFKM-jFo8Ww_dXwAzsDVoWqE==erfwVTeijHfh8kkOw@mail.gmail.com>
2018-09-07 13:58   ` [PATCH 00/21] DT cpu node iterator Rob Herring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180905193738.19325-2-robh@kernel.org \
    --to=robh@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).