From: Marc Zyngier <marc.zyngier@arm.com>
To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Cc: Mark Rutland <mark.rutland@arm.com>,
Rob Herring <robh+dt@kernel.org>,
Jason Cooper <jason@lakedaemon.net>,
Thomas Gleixner <tglx@linutronix.de>,
Bjorn Helgaas <bhelgaas@google.com>,
Mark Rutland <Mark.Rutland@arm.com>
Subject: [PATCH 1/4] of: Add of_parse_phandle_with_opt_args() helper function
Date: Tue, 22 Sep 2015 18:52:13 +0100 [thread overview]
Message-ID: <1442944336-11754-2-git-send-email-marc.zyngier@arm.com> (raw)
In-Reply-To: <1442944336-11754-1-git-send-email-marc.zyngier@arm.com>
of_parse_phandle_with_args() is slightly inflexible as it doesn't
allow the (unusual) case where the #*-cells property is not defined.
In order to support this, introduce of_parse_phandle_with_opt_args()
which assumes that #*-cells is zero when it is not defined,
as required by the msi-parent binding
This is done by turning __of_parse_phandle_with_args into an even
bigger monster, which is a bit frightening.
Acked-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
drivers/of/base.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
include/linux/of.h | 3 +++
2 files changed, 65 insertions(+), 2 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 8b5a187..1612342e 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1479,6 +1479,10 @@ static int __of_parse_phandle_with_args(const struct device_node *np,
* (i.e. cells_name not set, but cell_count is set),
* except when we're going to return the found node
* below.
+ *
+ * If #*-cells is not found, but cell_count is set
+ * to a non-zero value, use (cell_count-1) as a
+ * fallback value.
*/
if (cells_name || cur_index == index) {
node = of_find_node_by_phandle(phandle);
@@ -1490,13 +1494,21 @@ static int __of_parse_phandle_with_args(const struct device_node *np,
}
if (cells_name) {
- if (of_property_read_u32(node, cells_name,
- &count)) {
+ int ret;
+ ret = of_property_read_u32(node, cells_name,
+ &count);
+ if (ret && !cell_count) {
pr_err("%s: could not get %s for %s\n",
np->full_name, cells_name,
node->full_name);
goto err;
}
+ if (ret) {
+ count = cell_count - 1;
+ pr_debug("%s: could not get %s for %s, assuming %d\n",
+ np->full_name, cells_name,
+ node->full_name, count);
+ }
} else {
count = cell_count;
}
@@ -1628,6 +1640,54 @@ int of_parse_phandle_with_args(const struct device_node *np, const char *list_na
EXPORT_SYMBOL(of_parse_phandle_with_args);
/**
+ * of_parse_phandle_with_opt_args() - Find a node pointed by phandle in a list
+ * @np: pointer to a device tree node containing a list
+ * @list_name: property name that contains a list
+ * @cells_name: property name that specifies phandles' arguments count
+ * @index: index of a phandle to parse out
+ * @out_args: optional pointer to output arguments structure (will be filled)
+ *
+ * This function is useful to parse lists of phandles and their arguments.
+ * If cells_name is not found, then it is assumed to be zero.
+ * Returns 0 on success and fills out_args, on error returns appropriate
+ * errno value.
+ *
+ * Caller is responsible to call of_node_put() on the returned out_args->np
+ * pointer.
+ *
+ * Example:
+ *
+ * phandle1: node1 {
+ * #list-cells = <2>;
+ * }
+ *
+ * phandle2: node2 {
+ * }
+ *
+ * phandle3: node3 {
+ * #list-cells = <1>;
+ * }
+ *
+ * node3 {
+ * list = <&phandle1 1 2 &phandle2 &phandle 3>;
+ * }
+ *
+ * To get a device_node of the `node2' node you may call this:
+ * of_parse_phandle_with_args(node3, "list", "#list-cells", 1, &args);
+ */
+int of_parse_phandle_with_opt_args(const struct device_node *np,
+ const char *list_name,
+ const char *cells_name, int index,
+ struct of_phandle_args *out_args)
+{
+ if (index < 0)
+ return -EINVAL;
+ return __of_parse_phandle_with_args(np, list_name, cells_name, 1,
+ index, out_args);
+}
+EXPORT_SYMBOL(of_parse_phandle_with_opt_args);
+
+/**
* of_parse_phandle_with_fixed_args() - Find a node pointed by phandle in a list
* @np: pointer to a device tree node containing a list
* @list_name: property name that contains a list
diff --git a/include/linux/of.h b/include/linux/of.h
index 2194b8c..ae6cd03 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -328,6 +328,9 @@ extern struct device_node *of_parse_phandle(const struct device_node *np,
extern int of_parse_phandle_with_args(const struct device_node *np,
const char *list_name, const char *cells_name, int index,
struct of_phandle_args *out_args);
+extern int of_parse_phandle_with_opt_args(const struct device_node *np,
+ const char *list_name, const char *cells_name, int index,
+ struct of_phandle_args *out_args);
extern int of_parse_phandle_with_fixed_args(const struct device_node *np,
const char *list_name, int cells_count, int index,
struct of_phandle_args *out_args);
--
2.1.4
next prev parent reply other threads:[~2015-09-22 17:52 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-22 17:52 [PATCH 0/4] of: Handle multi-parent version of msi-parent Marc Zyngier
2015-09-22 17:52 ` Marc Zyngier [this message]
2015-09-29 17:28 ` [PATCH 1/4] of: Add of_parse_phandle_with_opt_args() helper function Rob Herring
2015-09-30 9:08 ` Marc Zyngier
2015-09-30 13:57 ` Mark Rutland
2015-09-30 15:39 ` Robin Murphy
2015-09-30 17:18 ` Marc Zyngier
2015-09-22 17:52 ` [PATCH 2/4] of: irq: Add support for the new definition of "msi-parent" Marc Zyngier
2015-09-23 14:39 ` Sergei Shtylyov
2015-09-27 10:29 ` Thomas Gleixner
2015-09-27 13:02 ` Sergei Shtylyov
2015-09-22 17:52 ` [PATCH 3/4] PCI/MSI: " Marc Zyngier
2015-09-22 17:52 ` [PATCH 4/4] irqchip/gic-v3-its: Parse new version of msi-parent property Marc Zyngier
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=1442944336-11754-2-git-send-email-marc.zyngier@arm.com \
--to=marc.zyngier@arm.com \
--cc=bhelgaas@google.com \
--cc=jason@lakedaemon.net \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=robh+dt@kernel.org \
--cc=tglx@linutronix.de \
/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
all inboxes | Powered by JetHome®