Message ID | 1392137610-27842-2-git-send-email-pawel.moll@arm.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Hi Pawel, On 02/11/2014 11:53 AM, Pawel Moll wrote: > 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. Will there never be a case where it is useful for a parent node to be created early, but not necessarily the child nodes? Might only skipping nodes explicitly marked as populated be a more universal solution? Regards, Christopher
On Tue, Feb 11, 2014 at 10:53 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(). > > 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@arm.com> > --- > 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(-) Go read Grant's and my comments from your last posting. Rob
On Thu, 2014-02-13 at 13:15 -0600, Rob Herring wrote: > On Tue, Feb 11, 2014 at 10:53 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. > > Go read Grant's and my comments from your last posting. Right, I can't explain why I missed those. Will do right now. Pawel
On Tue, 2014-02-11 at 12:32 -0500, Christopher Covington wrote: > Hi Pawel, > > On 02/11/2014 11:53 AM, Pawel Moll wrote: > > 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. > > Will there never be a case where it is useful for a parent node to be created > early, but not necessarily the child nodes? Might only skipping nodes > explicitly marked as populated be a more universal solution? That's a good point. I've assumed one would either use of_platform_device_create() on leaf nodes only (or of_platform_populate() on subtree), and kept this approach in the refreshed patch I'm about to post, but I'm happy to do what you suggested. Thanks! Pawel
On Mon, 2014-04-28 at 18:37 +0100, Pawel Moll wrote: > On Thu, 2014-02-13 at 13:15 -0600, Rob Herring wrote: > > On Tue, Feb 11, 2014 at 10:53 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. > > > > Go read Grant's and my comments from your last posting. > > Right, I can't explain why I missed those. Will do right now. Actually I can't seem to find it in my mail archive, but I remember you were saying that it shouldn't spoil into the driver base code. You're probably right, so the updated patch will be limited to of_platform_* API. Grant was suggesting that I shouldn't be using the device model if I have to initialize some early stuff. The thing is that my stuff is not that early at all. The device model works for me perfectly, as long as I can initialize 3 crucial devices in a correct order (and *then* do mass population). And the init levels are perfect for this job. The only thing I need is a small refinement in the way DT-based devices are populated and this is exactly what I propose. Hope it makes more sense now. Cheers! Pawel
diff --git a/drivers/base/core.c b/drivers/base/core.c index 2b56717..588c9a6 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -1088,6 +1088,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; @@ -1190,6 +1192,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 dafb973..3b31144 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -190,3 +190,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 70c64ba..caf7b8a 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 8d7dd67..513e598 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; @@ -84,6 +87,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;
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@arm.com> --- 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(-)