devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gaurav Minocha <gaurav.minocha.os-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
	rob.herring-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
	Gaurav Minocha
	<gaurav.minocha.os-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Subject: [PATCH v2] Removes OF_SELFTEST dependency on OF_DYNAMIC config symbol
Date: Sat, 13 Sep 2014 05:35:08 -0700	[thread overview]
Message-ID: <1410611708-9369-1-git-send-email-gaurav.minocha.os@gmail.com> (raw)

This patch is used to remove the selftests dependency on
OF_DYNAMIC config flag. Now, it selectively builds only
 the functions required by the selftests.

Tested with and without OF_DYNAMIC enabled.

Signed-off-by: Gaurav Minocha <gaurav.minocha.os-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 drivers/of/Kconfig    |   1 -
 drivers/of/selftest.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 110 insertions(+), 1 deletion(-)

diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 5160c4e..1fe3805 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -10,7 +10,6 @@ menu "Device Tree and Open Firmware support"
 config OF_SELFTEST
 	bool "Device Tree Runtime self tests"
 	depends on OF_IRQ && OF_EARLY_FLATTREE
-	select OF_DYNAMIC
 	help
 	  This option builds in test cases for the device tree infrastructure
 	  that are executed once at boot time, and the results dumped to the
diff --git a/drivers/of/selftest.c b/drivers/of/selftest.c
index a737cb5..4b2704e 100644
--- a/drivers/of/selftest.c
+++ b/drivers/of/selftest.c
@@ -600,6 +600,116 @@ static void __init of_selftest_platform_populate(void)
 	}
 }
 
+#if !defined(CONFIG_OF_DYNAMIC)
+/**
+ * of_attach_node() - Plug a device node into the tree and global list.
+ */
+int of_attach_node(struct device_node *np)
+{
+	unsigned long flags;
+	const __be32 *phandle;
+	int sz;
+
+	mutex_lock(&of_mutex);
+	raw_spin_lock_irqsave(&devtree_lock, flags);
+	np->name = __of_get_property(np, "name", NULL) ? : "<NULL>";
+	np->type = __of_get_property(np, "device_type", NULL) ? : "<NULL>";
+
+	phandle = __of_get_property(np, "phandle", &sz);
+	if (!phandle)
+		phandle = __of_get_property(np, "linux,phandle", &sz);
+	np->phandle = (phandle && (sz >= 4)) ? be32_to_cpup(phandle) : 0;
+
+	np->child = NULL;
+	np->sibling = np->parent->child;
+	np->allnext = np->parent->allnext;
+	np->parent->allnext = np;
+	np->parent->child = np;
+	of_node_clear_flag(np, OF_DETACHED);
+	raw_spin_unlock_irqrestore(&devtree_lock, flags);
+
+	__of_attach_node_sysfs(np);
+	mutex_unlock(&of_mutex);
+
+	return 0;
+}
+
+void __of_detach_node_sysfs(struct device_node *np)
+{
+	struct property *pp;
+
+	if (!IS_ENABLED(CONFIG_SYSFS))
+		return;
+
+	BUG_ON(!of_node_is_initialized(np));
+	if (!of_kset)
+		return;
+
+	/* only remove properties if on sysfs */
+	if (of_node_is_attached(np)) {
+		for_each_property_of_node(np, pp)
+			sysfs_remove_bin_file(&np->kobj, &pp->attr);
+		kobject_del(&np->kobj);
+	}
+
+	/* finally remove the kobj_init ref */
+	of_node_put(np);
+}
+
+/**
+ * of_detach_node() - "Unplug" a node from the device tree.
+ *
+ * The caller must hold a reference to the node.  The memory associated with
+ * the node is not freed until its refcount goes to zero.
+ */
+int of_detach_node(struct device_node *np)
+{
+	unsigned long flags;
+	int rc = 0;
+	struct device_node *parent;
+
+	mutex_lock(&of_mutex);
+	raw_spin_lock_irqsave(&devtree_lock, flags);
+
+	if (!WARN_ON(of_node_check_flag(np, OF_DETACHED))) {
+		parent = np->parent;
+		if (!WARN_ON(!parent)) {
+			if (of_allnodes == np)
+				of_allnodes = np->allnext;
+			else {
+				struct device_node *prev;
+
+				for (prev = of_allnodes;
+					prev->allnext != np;
+					prev = prev->allnext)
+					;
+				prev->allnext = np->allnext;
+			}
+
+			if (parent->child == np)
+				parent->child = np->sibling;
+			else {
+				struct device_node *prevsib;
+
+				for (prevsib = np->parent->child;
+					prevsib->sibling != np;
+					prevsib = prevsib->sibling)
+						;
+				prevsib->sibling = np->sibling;
+			}
+
+			of_node_set_flag(np, OF_DETACHED);
+		}
+	}
+	raw_spin_unlock_irqrestore(&devtree_lock, flags);
+
+	__of_detach_node_sysfs(np);
+	mutex_unlock(&of_mutex);
+
+	return rc;
+}
+#endif
+
 /**
  *	update_node_properties - adds the properties
  *	of np into dup node (present in live tree) and
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

             reply	other threads:[~2014-09-13 12:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-13 12:35 Gaurav Minocha [this message]
     [not found] ` <1410611708-9369-1-git-send-email-gaurav.minocha.os-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-09-15  9:34   ` [PATCH v2] Removes OF_SELFTEST dependency on OF_DYNAMIC config symbol Pantelis Antoniou
     [not found]     ` <9D65D8A3-6404-451B-A3F4-E9ED94810B7B-wVdstyuyKrO8r51toPun2/C9HSW9iNxf@public.gmane.org>
2014-09-15 19:16       ` Gaurav Minocha
2014-09-27 22:23       ` Grant Likely
     [not found]         ` <CBCF02E6-831F-425B-9FE7-CB4EE9A2F19C@antoniou-consulting.com>
     [not found]           ` <CBCF02E6-831F-425B-9FE7-CB4EE9A2F19C-wVdstyuyKrO8r51toPun2/C9HSW9iNxf@public.gmane.org>
2014-09-29 12:51             ` Grant Likely

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=1410611708-9369-1-git-send-email-gaurav.minocha.os@gmail.com \
    --to=gaurav.minocha.os-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=rob.herring-QSEj5FYQhm4dnm+yROfE0A@public.gmane.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).