* [RFC 04/18] driver core & of: Mark of_nodes of added device as populated
[not found] ` <1387815830-8794-1-git-send-email-pawel.moll-5wv7dgnIgG8@public.gmane.org>
@ 2013-12-23 16:23 ` Pawel Moll
2014-01-08 17:28 ` Rob Herring
0 siblings, 1 reply; 3+ messages in thread
From: Pawel Moll @ 2013-12-23 16:23 UTC (permalink / raw)
To: linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
Cc: Samuel Ortiz, Arnd Bergmann, Jon Medhurst,
arm-DgEjT+Ai2ygdnm+yROfE0A, Olof Johansson, Pawel Moll,
Greg Kroah-Hartman, Grant Likely, Rob Herring,
devicetree-u79uwXL29TY76Z2rM5mHXA
In "Device Tree powered" systems, platform devices are usually
massively populated with of_platform_populate() call, executed
at some level of initcalls, either by generic architecture
or by platform-specific code.
There are situations though where certain devices must be
created (and bound with drivers) before all the others.
This presents small challenge in DT-driven systems, as
devices explicitly created in early code would be created
again by of_platform_populate().
This patch tries to solve that issue in a generic way,
adding a "populated" flag which is set in the device_node
structure when a device is being created in the core.
Later, of_platform_populate() skips such nodes (and
its children) in a similar way to the non-available ones.
Signed-off-by: Pawel Moll <pawel.moll-5wv7dgnIgG8@public.gmane.org>
Cc: Greg Kroah-Hartman <gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>
Cc: Grant Likely <grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
Cc: Rob Herring <rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org>
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
---
drivers/base/core.c | 4 ++++
drivers/of/device.c | 16 ++++++++++++++++
drivers/of/platform.c | 6 ++++--
include/linux/of.h | 6 ++++++
include/linux/of_device.h | 11 +++++++++++
5 files changed, 41 insertions(+), 2 deletions(-)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 67b180d..50dd8f3 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -1086,6 +1086,8 @@ int device_add(struct device *dev)
class_intf->add_dev(dev, class_intf);
mutex_unlock(&dev->class->p->mutex);
}
+
+ of_device_populate(dev);
done:
put_device(dev);
return error;
@@ -1188,6 +1190,8 @@ void device_del(struct device *dev)
struct device *parent = dev->parent;
struct class_interface *class_intf;
+ of_device_depopulate(dev);
+
/* Notify clients of device removal. This call must come
* before dpm_sysfs_remove().
*/
diff --git a/drivers/of/device.c b/drivers/of/device.c
index f685e55..dae092a 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -187,3 +187,19 @@ int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env)
return 0;
}
+
+void of_device_populate(struct device *dev)
+{
+ if ((!dev) || (!dev->of_node))
+ return;
+
+ of_node_set_flag(dev->of_node, OF_POPULATED);
+}
+
+void of_device_depopulate(struct device *dev)
+{
+ if ((!dev) || (!dev->of_node))
+ return;
+
+ of_node_clear_flag(dev->of_node, OF_POPULATED);
+}
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 404d1da..ad43ee0 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -204,7 +204,8 @@ static struct platform_device *of_platform_device_create_pdata(
{
struct platform_device *dev;
- if (!of_device_is_available(np))
+ if (!of_device_is_available(np) ||
+ of_node_check_flag(np, OF_POPULATED))
return NULL;
dev = of_device_alloc(np, bus_id, parent);
@@ -262,7 +263,8 @@ static struct amba_device *of_amba_device_create(struct device_node *node,
pr_debug("Creating amba device %s\n", node->full_name);
- if (!of_device_is_available(node))
+ if (!of_device_is_available(node) ||
+ of_node_check_flag(node, OF_POPULATED))
return NULL;
dev = amba_device_alloc(NULL, 0, 0);
diff --git a/include/linux/of.h b/include/linux/of.h
index 276c546..53989cf 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -114,6 +114,11 @@ static inline void of_node_set_flag(struct device_node *n, unsigned long flag)
set_bit(flag, &n->_flags);
}
+static inline void of_node_clear_flag(struct device_node *n, unsigned long flag)
+{
+ clear_bit(flag, &n->_flags);
+}
+
extern struct device_node *of_find_all_nodes(struct device_node *prev);
/*
@@ -156,6 +161,7 @@ static inline unsigned long of_read_ulong(const __be32 *cell, int size)
/* flag descriptions */
#define OF_DYNAMIC 1 /* node and properties were allocated via kmalloc */
#define OF_DETACHED 2 /* node has been detached from the device tree */
+#define OF_POPULATED 3 /* device already created for the node */
#define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags)
#define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags)
diff --git a/include/linux/of_device.h b/include/linux/of_device.h
index 82ce324..bfb4a48 100644
--- a/include/linux/of_device.h
+++ b/include/linux/of_device.h
@@ -44,6 +44,9 @@ static inline void of_device_node_put(struct device *dev)
of_node_put(dev->of_node);
}
+extern void of_device_populate(struct device *dev);
+extern void of_device_depopulate(struct device *dev);
+
static inline struct device_node *of_cpu_device_node_get(int cpu)
{
struct device *cpu_dev;
@@ -78,6 +81,14 @@ static inline const struct of_device_id *of_match_device(
return NULL;
}
+static inline void of_device_populate(struct device *dev)
+{
+}
+
+static inline void of_device_depopulate(struct device *dev)
+{
+}
+
static inline struct device_node *of_cpu_device_node_get(int cpu)
{
return NULL;
--
1.8.3.2
--
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [RFC 04/18] driver core & of: Mark of_nodes of added device as populated
2013-12-23 16:23 ` [RFC 04/18] driver core & of: Mark of_nodes of added device as populated Pawel Moll
@ 2014-01-08 17:28 ` Rob Herring
0 siblings, 0 replies; 3+ messages in thread
From: Rob Herring @ 2014-01-08 17:28 UTC (permalink / raw)
To: Pawel Moll
Cc: linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, Samuel Ortiz, Arnd Bergmann,
Jon Medhurst, arm@kernel.org, Olof Johansson, Greg Kroah-Hartman,
Grant Likely, Rob Herring, devicetree@vger.kernel.org
On Mon, Dec 23, 2013 at 10:23 AM, Pawel Moll <pawel.moll@arm.com> wrote:
> In "Device Tree powered" systems, platform devices are usually
> massively populated with of_platform_populate() call, executed
> at some level of initcalls, either by generic architecture
> or by platform-specific code.
>
> There are situations though where certain devices must be
> created (and bound with drivers) before all the others.
> This presents small challenge in DT-driven systems, as
> devices explicitly created in early code would be created
> again by of_platform_populate().
Isn't this already at least partially solved with the aux data
support? I'm guessing the difference here is how the early device is
created.
> This patch tries to solve that issue in a generic way,
> adding a "populated" flag which is set in the device_node
> structure when a device is being created in the core.
> Later, of_platform_populate() skips such nodes (and
> its children) in a similar way to the non-available ones.
Couldn't you store a struct device ptr in struct device_node instead?
In any case I'd like to see this contained within the DT code. I don't
see why the driver core needs to be modified for a DT specific
problem.
Rob
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFC 04/18] driver core & of: Mark of_nodes of added device as populated
[not found] ` <CAL_JsqJGQFstgFu=tpho91C0iv4eH9XSCAVKfXXQO4Z+yD-0tw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2014-01-16 17:03 ` Grant Likely
0 siblings, 0 replies; 3+ messages in thread
From: Grant Likely @ 2014-01-16 17:03 UTC (permalink / raw)
To: Rob Herring, Pawel Moll
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
Samuel Ortiz, Arnd Bergmann, Jon Medhurst,
arm-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org, Olof Johansson,
Greg Kroah-Hartman, Rob Herring,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
On Wed, 8 Jan 2014 11:28:01 -0600, Rob Herring <robherring2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> On Mon, Dec 23, 2013 at 10:23 AM, Pawel Moll <pawel.moll-5wv7dgnIgG8@public.gmane.org> wrote:
> > In "Device Tree powered" systems, platform devices are usually
> > massively populated with of_platform_populate() call, executed
> > at some level of initcalls, either by generic architecture
> > or by platform-specific code.
> >
> > There are situations though where certain devices must be
> > created (and bound with drivers) before all the others.
> > This presents small challenge in DT-driven systems, as
> > devices explicitly created in early code would be created
> > again by of_platform_populate().
>
> Isn't this already at least partially solved with the aux data
> support? I'm guessing the difference here is how the early device is
> created.
Still, creating a device early and then trying to remember that it has
been done does nothing but add complexity for a very small number of use
cases. I still would much rather see things that need really early setup
to avoid the device model entirely and do the bare minimum needed to
allow the kernel to get to initcall time. In the cases where a subsystem
API requires a struct device, I would consider using a dummy throwaway
struct device for the early bits.
g.
--
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-01-16 17:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1387815830-8794-1-git-send-email-pawel.moll@arm.com>
[not found] ` <1387815830-8794-1-git-send-email-pawel.moll-5wv7dgnIgG8@public.gmane.org>
2013-12-23 16:23 ` [RFC 04/18] driver core & of: Mark of_nodes of added device as populated Pawel Moll
2014-01-08 17:28 ` Rob Herring
[not found] ` < 1387815830-8794-5-git-send-email-pawel.moll@arm.com>
[not found] ` < CAL_JsqJGQFstgFu=tpho91C0iv4eH9XSCAVKfXXQO4Z+yD-0tw@mail.gmail.com>
[not found] ` <CAL_JsqJGQFstgFu=tpho91C0iv4eH9XSCAVKfXXQO4Z+yD-0tw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-01-16 17:03 ` Grant Likely
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).