mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexander Holler <holler@ahsoftware.de>
To: linux-kernel@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Russell King <linux@arm.linux.org.uk>,
	Grant Likely <grant.likely@linaro.org>,
	Alexander Holler <holler@ahsoftware.de>
Subject: [PATCH 03/14] init: deps: dt: use (HW-specific) dependencies provided by the DT too
Date: Sat, 17 Oct 2015 19:14:16 +0200	[thread overview]
Message-ID: <1445102067-11519-4-git-send-email-holler@ahsoftware.de> (raw)
In-Reply-To: <1445102067-11519-1-git-send-email-holler@ahsoftware.de>

This patch adds dependencies provided by the hardware description in
the used DT. This avoids the use of the deferred probe mechanism
on most (if not all) DT based kernels.

Drawback is that the binary DT blob has to be enhanced with type
information for phandles (which are used as dependencies) which
needs a modified dtc.

Signed-off-by: Alexander Holler <holler@ahsoftware.de>
---
 drivers/of/base.c   | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/of.h  |   3 ++
 init/dependencies.c |   4 ++
 3 files changed, 121 insertions(+)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 8b5a187..423ddff 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -12,6 +12,8 @@
  *  Reconsolidated from arch/x/kernel/prom.c by Stephen Rothwell and
  *  Grant Likely.
  *
+ *  The dependency related stuff was done by Alexander Holler.
+ *
  *      This program is free software; you can redistribute it and/or
  *      modify it under the terms of the GNU General Public License
  *      as published by the Free Software Foundation; either version
@@ -2308,3 +2310,115 @@ struct device_node *of_graph_get_remote_port(const struct device_node *node)
 	return of_get_next_parent(np);
 }
 EXPORT_SYMBOL(of_graph_get_remote_port);
+
+#ifdef CONFIG_DEPENDENCIES
+
+static const struct _annotated_initcall * __init find_matching_driver(
+	const struct _annotated_initcall *from, const struct device_node *node)
+{
+	while (++from != __annotated_initcall_end)
+		if (from->driver &&
+				__of_match_node(from->driver->of_match_table,
+					node))
+			return from;
+	return NULL;
+}
+
+static int __init add_dep_list(const struct device_node *node, unsigned drvid)
+{
+	const __be32 *list, *list_end;
+	uint32_t ph;
+	int size = 0;
+	int rc = 0;
+	const struct device_node *dep;
+	const struct _annotated_initcall *ac;
+
+	list = __of_get_property(node, "dependencies", &size);
+	if (!list || !size || size % sizeof(*list))
+		return 0;
+	list_end = list + size / sizeof(*list);
+	while (list < list_end) {
+		ph = be32_to_cpup(list++);
+		if (unlikely(!ph)) {
+			/* Should never happen */
+			if (node->name)
+				pr_warn("phandle == 0 for %s\n", node->name);
+			continue;
+		}
+		dep = of_find_node_by_phandle(ph);
+		if (unlikely(!dep)) {
+			pr_err("No DT node for dependency with phandle 0x%x found\n",
+				ph);
+			continue;
+		}
+		ac = __annotated_initcall_start - 1;
+		while ((ac = find_matching_driver(ac, dep))) {
+			if (!ac->id)
+				continue;
+			rc = add_initcall_dependency(drvid, ac->id);
+			if (rc)
+				return rc;
+		}
+	}
+
+	return rc;
+}
+
+static int __init add_deps(unsigned parent, const struct device_node *node)
+{
+	struct device_node *child;
+	const struct _annotated_initcall *ac;
+	int rc = 0;
+	bool found_one_driver = false;
+
+	if (!__of_device_is_available(node))
+		return 0;
+	if (__of_get_property(node, "compatible", NULL)) {
+		ac = __annotated_initcall_start - 1;
+		while ((ac = find_matching_driver(ac, node))) {
+			if (!ac->id)
+				continue;
+			found_one_driver = true;
+			rc = add_initcall_dependency(ac->id, parent);
+			if (unlikely(rc))
+				return rc;
+			rc = add_dep_list(node, ac->id);
+			if (unlikely(rc))
+				return rc;
+			for_each_child_of_node(node, child) {
+				rc = add_deps(ac->id, child);
+				if (unlikely(rc))
+					return rc;
+			}
+		}
+		if (found_one_driver)
+			return rc;
+	}
+	for_each_child_of_node(node, child) {
+		rc = add_deps(parent, child);
+		if (unlikely(rc))
+			break;
+	}
+
+	return rc;
+}
+
+int __init of_add_dependencies(void)
+{
+	int rc = 0;
+	struct device_node *child;
+	struct device_node *root =  of_find_node_by_path("/");
+
+	if (unlikely(!root))
+		return -EINVAL;
+
+	for_each_child_of_node(root, child) {
+		rc = add_deps(0, child);
+		if (unlikely(rc))
+			break;
+	}
+	of_node_put(root);
+
+	return rc;
+}
+#endif /* CONFIG_DEPENDENCIES */
diff --git a/include/linux/of.h b/include/linux/of.h
index edc068d..e3b65c8 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -1101,4 +1101,7 @@ static inline int of_overlay_destroy_all(void)
 
 #endif
 
+/* Inserts dependencies for drivers referenced in the loaded DT. */
+int __init of_add_dependencies(void);
+
 #endif /* _LINUX_OF_H */
diff --git a/init/dependencies.c b/init/dependencies.c
index c47817c..b484f67 100644
--- a/init/dependencies.c
+++ b/init/dependencies.c
@@ -17,6 +17,7 @@
 #include <linux/device.h>
 #include <linux/mod_devicetable.h>
 #include <linux/init.h>
+#include <linux/of.h>
 
 #if defined(CONFIG_DEPENDENCIES_PRINT_INIT_ORDER) \
 	|| defined(CONFIG_DEPENDENCIES_PRINT_CALLS)
@@ -335,6 +336,9 @@ static int __init build_order(void)
 
 	build_inventory();
 	add_dependencies();
+#ifdef CONFIG_OF
+	of_add_dependencies();
+#endif
 	if (topological_sort())
 		return -EINVAL; /* cycle found */
 	pr_debug("init: vertices: %u edges %u count %u\n",
-- 
2.1.0


  parent reply	other threads:[~2015-10-17 17:15 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-17 17:14 [PATCH 0/14] init: deps: dependency based (parallelized) init Alexander Holler
2015-10-17 17:14 ` [PATCH 01/14] init: deps: introduce annotated initcalls Alexander Holler
2015-10-17 17:14 ` [PATCH 02/14] init: deps: use annotated initcalls for a dependency based (optionally parallelized) init Alexander Holler
2015-10-17 17:14 ` Alexander Holler [this message]
2015-10-19 12:37   ` [PATCH 03/14] init: deps: dt: use (HW-specific) dependencies provided by the DT too Mark Brown
2015-10-19 16:27     ` Rob Herring
2015-10-19 17:24       ` Alexander Holler
2015-10-19 17:10     ` Alexander Holler
2015-10-17 17:14 ` [PATCH 04/14] init: deps: order network interfaces by link order Alexander Holler
2015-10-17 18:23   ` Linus Torvalds
2015-10-17 18:37     ` Alexander Holler
2015-10-17 18:52       ` Linus Torvalds
2015-10-17 19:01         ` Alexander Holler
2015-10-17 19:08           ` Linus Torvalds
2015-10-17 19:14             ` Alexander Holler
2015-10-17 19:36               ` Greg Kroah-Hartman
2015-10-17 19:58                 ` Alexander Holler
2015-10-17 21:20                   ` Alexander Holler
2015-10-18  4:59                 ` Alexander Holler
2015-10-18  5:14                   ` Greg Kroah-Hartman
2015-10-18  5:20                     ` Alexander Holler
2015-10-18  5:59                       ` Greg Kroah-Hartman
2015-10-18 10:11                         ` Alexander Holler
2015-10-19 10:57                           ` Alexander Holler
2015-10-19 11:31                             ` Alexander Holler
2015-10-22  6:47                               ` Alexander Holler
2015-10-17 19:37               ` Linus Torvalds
2015-10-17 21:32             ` Alexander Holler
2015-10-17 18:55       ` Greg Kroah-Hartman
2015-10-17 19:03       ` Linus Torvalds
2015-10-17 19:07         ` Alexander Holler
2015-10-17 17:14 ` [PATCH 05/14] init: deps: order I2C bus drivers by their ID Alexander Holler
2015-10-17 17:14 ` [PATCH 06/14] dtc: deps: Automatically add new property 'dependencies' which contains a list of referenced phandles Alexander Holler
2015-10-17 17:14 ` [PATCH 07/14] dtc: deps: introduce new (virtual) property no-dependencies Alexander Holler
2015-10-17 17:14 ` [PATCH 08/14] dtc: deps: Add option to print initialization order Alexander Holler
2015-10-17 17:14 ` [PATCH 09/14] dtc: deps: Add option to print dependency graph as dot (Graphviz) Alexander Holler
2015-10-17 17:14 ` [PATCH 10/14] init: deps: IDs for annotated initcalls Alexander Holler
2015-10-17 17:45   ` Greg Kroah-Hartman
2015-10-17 17:55     ` Alexander Holler
2015-10-17 18:29       ` Greg Kroah-Hartman
2015-10-17 18:46         ` Alexander Holler
2015-10-19 13:12           ` Mark Brown
2015-10-20 10:30             ` Alexander Holler
2015-10-20 10:42               ` Alexander Holler
2015-10-20 10:50                 ` Alexander Holler
2015-10-20 10:57                 ` Alexander Holler
2015-10-17 17:14 ` [PATCH 11/14] init: deps: annotate various initcalls Alexander Holler
2015-10-17 18:47   ` Linus Torvalds
2015-10-17 18:59     ` Alexander Holler
2015-10-17 17:14 ` [PATCH 12/14] dt: dts: deps: kirkwood: dockstar: add dependency ehci -> usb power regulator Alexander Holler
2015-10-17 17:14 ` [PATCH 13/14] dt: dts: deps: imx6q: make some remote-endpoints non-dependencies Alexander Holler
2015-10-17 17:14 ` [PATCH 14/14] dt: dts: deps: omap: beagle: " Alexander Holler
2015-10-17 17:44 ` [PATCH 0/14] init: deps: dependency based (parallelized) init Greg Kroah-Hartman
2015-10-17 18:19   ` Alexander Holler
2015-10-17 18:38     ` Greg Kroah-Hartman
2015-10-17 19:43       ` Alexander Holler
2015-10-17 20:20         ` Greg Kroah-Hartman
2015-10-17 20:37           ` Alexander Holler
2015-11-06 16:07 ` Alexander Holler

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=1445102067-11519-4-git-send-email-holler@ahsoftware.de \
    --to=holler@ahsoftware.de \
    --cc=akpm@linux-foundation.org \
    --cc=grant.likely@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=torvalds@linux-foundation.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

all inboxes | Powered by JetHome®