devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mark Rutland <mark.rutland@arm.com>
To: linux-arm-kernel@lists.infradead.org
Cc: Mark Rutland <mark.rutland@arm.com>,
	lorenzo.pieralisi@arm.com, benh@kernel.crashing.org,
	devicetree-discuss@lists.ozlabs.org, will.deacon@arm.com,
	rob.herring@calxeda.com, grant.likely@secretlab.ca,
	tglx@linutronix.de
Subject: [PATCH 1/2] of: add of_property_count_phandles
Date: Fri, 26 Oct 2012 15:48:44 +0100	[thread overview]
Message-ID: <1351262925-10306-2-git-send-email-mark.rutland@arm.com> (raw)
In-Reply-To: <1351262925-10306-1-git-send-email-mark.rutland@arm.com>

Though of_parse_phandle handles lists of phandles, and takes an index
parameter, there is no standard way of discovering how many phandles are
present on a node. This patch adds a function to count how many phandles
are in a phandle list.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
---
 drivers/of/base.c  |   39 +++++++++++++++++++++++++++++++++++++++
 include/linux/of.h |    8 ++++++++
 2 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index af3b22a..30ae562 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -884,6 +884,45 @@ int of_property_count_strings(struct device_node *np, const char *propname)
 EXPORT_SYMBOL_GPL(of_property_count_strings);
 
 /**
+ * of_property_count_phandles - find and return the number of phandles from a
+ * multiple phandles property.
+ * @np:		device node from which the property value is to be read.
+ * @propname:	name of the property to be searched.
+ *
+ * Search for a property in a device tree node and retrieve the number of
+ * phandles contained in it. Returns the number of phandles on success, -ENOENT
+ * if the property does not exist, -ENODATA if there are no phandles, and
+ * -EINVAL if the property is not correctly sized for an array of phandles.
+ */
+int of_property_count_phandles(struct device_node *np, const char *propname)
+{
+	int size, count, i;
+	const __be32 *phandle;
+
+	phandle = of_get_property(np, propname, &size);
+
+	if (!phandle)
+		return -ENOENT;
+	if (size == 0)
+		return -ENODATA;
+	if (size % (sizeof *phandle))
+		return -EINVAL;
+
+	count = size / (sizeof(*phandle));
+
+	/* Check the phandle targets actually exist */
+	for (i = 0; i < count; i++) {
+		struct device_node *node = of_parse_phandle(np, propname, i);
+		if (!node)
+			return -EINVAL;
+		of_node_put(node);
+	}
+
+	return count;
+}
+EXPORT_SYMBOL_GPL(of_property_count_phandles);
+
+/**
  * of_parse_phandle - Resolve a phandle property to a device_node pointer
  * @np: Pointer to device node holding phandle property
  * @phandle_name: Name of property holding a phandle value
diff --git a/include/linux/of.h b/include/linux/of.h
index b4e50d5..1f03f46 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -258,6 +258,8 @@ extern int of_modalias_node(struct device_node *node, char *modalias, int len);
 extern struct device_node *of_parse_phandle(struct device_node *np,
 					    const char *phandle_name,
 					    int index);
+extern int of_property_count_phandles(struct device_node *np,
+				      const char *propname);
 extern int of_parse_phandle_with_args(struct device_node *np,
 	const char *list_name, const char *cells_name, int index,
 	struct of_phandle_args *out_args);
@@ -411,6 +413,12 @@ static inline int of_property_match_string(struct device_node *np,
 	return -ENOSYS;
 }
 
+static inline int of_property_count_phandles(struct device_node *np,
+					     const char *propname)
+{
+	return -ENOSYS;
+}
+
 static inline struct device_node *of_parse_phandle(struct device_node *np,
 						   const char *phandle_name,
 						   int index)
-- 
1.7.0.4

  reply	other threads:[~2012-10-26 14:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-26 14:48 [RFC 0/2] Representing interrupt affinity in devicetree Mark Rutland
2012-10-26 14:48 ` Mark Rutland [this message]
2012-10-26 14:48 ` [PATCH 2/2] ARM: Add functions to parse dt irq affinity Mark Rutland

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=1351262925-10306-2-git-send-email-mark.rutland@arm.com \
    --to=mark.rutland@arm.com \
    --cc=benh@kernel.crashing.org \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=grant.likely@secretlab.ca \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=rob.herring@calxeda.com \
    --cc=tglx@linutronix.de \
    --cc=will.deacon@arm.com \
    /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).