of: Output devicetree alias names in uevent
Subsystems (2)
PATCH 1/1 of: Output devicetree alias names in uevent
In some situations, userspace may want to resolve a device by function and logical number (ie, "serial0") rather than by the base address or full device path. Being able to resolve a device by alias frees userspace from the burden of otherwise having to maintain a mapping between device addresses and their logical assignments on each platform when multiple instances of the same hardware block are present in the system.
Although the uevent device attribute contains devicetree compatible information and the full device path, the uevent does not list the alises that may have been defined for the device.
---
I have followed the OF_COMPATIBLE convention for adding the uevent variables for the alias names, but I can follow some other convention if people feel something else is more appropriate.
drivers/of/base.c | 25 +++++++++++++++++++++++++ drivers/of/device.c | 1 + include/linux/of_device.h | 2 ++ 3 files changed, 28 insertions(+), 0 deletions(-)
drivers/of/base.c +25 -0
@@ -19,6 +19,7 @@*/ #include <linux/ctype.h> #include <linux/module.h> +#include <linux/device.h> #include <linux/of.h> #include <linux/spinlock.h> #include <linux/slab.h>
@@ -1177,6 +1178,30 @@ static void of_alias_add(struct alias_prop *ap, struct device_node *np, }/** +* of_device_uevent_aliases - Display OF alises in uevent +*/ +void of_device_uevent_aliases (struct device_node *node, +struct kobj_uevent_env *env) +{ +struct alias_prop *app; +int seen =0 ; + +mutex_lock (&of_aliases_mutex); +list_for_each_entry (app, &aliases_lookup, link) { +if (node == app->np) { +add_uevent_var (env,"OF_ALIAS_%d=%s%d" , seen, app->stem, + app->id); + seen++; + } + } + +if (seen) +add_uevent_var (env,"OF_ALIAS_N=%d" , seen); + +mutex_unlock (&of_aliases_mutex); +} + +/** * of_alias_scan - Scan all properties of 'aliases' node * * The function scans all the properties of 'aliases' node and populate
drivers/of/device.c +1 -0
@@ -153,6 +153,7 @@ void of_device_uevent(struct device *dev, struct kobj_uevent_env *env) seen++; }add_uevent_var (env,"OF_COMPATIBLE_N=%d" , seen); +of_device_uevent_aliases (dev->of_node, env); }int of_device_uevent_modalias (struct device *dev,struct kobj_uevent_env *env)
include/linux/of_device.h +2 -0
@@ -36,6 +36,8 @@ extern ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len);extern void of_device_uevent (struct device *dev,struct kobj_uevent_env *env); +extern void of_device_uevent_aliases (struct device_node *node, +struct kobj_uevent_env *env);extern int of_device_uevent_modalias (struct device *dev,struct kobj_uevent_env *env);static inline void of_device_node_put (struct device *dev)
--
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Quoted 14 lines · Stepan Moskovchenko
In some situations, userspace may want to resolve a device by function and logical number (ie, "serial0") rather than by the base address or full device path. Being able to resolve a device by alias frees userspace from the burden of otherwise having to maintain a mapping between device addresses and their logical assignments on each platform when multiple instances of the same hardware block are present in the system.
Although the uevent device attribute contains devicetree compatible information and the full device path, the uevent does not list the alises that may have been defined for the device.
Quoted 6 lines
Signed-off-by Stepan Moskovchenko <[email protected]>---
I have followed theOF_COMPATIBLEconvention for adding the uevent variables for the alias names, but I can follow some other convention if people feel something else is more appropriate.
No, this seems fine. Comments below.
Quoted 24 lines
drivers/of/base.c | 25 +++++++++++++++++++++++++ drivers/of/device.c | 1 + include/linux/of_device.h | 2 ++ 3 files changed, 28 insertions(+), 0 deletions(-)drivers/of/base.c +4
-0@@ -19,6 +19,7 @@*/ #include <linux/ctype.h> #include <linux/module.h> +#include <linux/device.h> #include <linux/of.h> #include <linux/spinlock.h> #include <linux/slab.h> @@ -1177,6 +1178,30 @@ static void of_alias_add(struct alias_prop *ap, struct device_node *np, }/** +* of_device_uevent_aliases - Display OF alises in uevent +*/ +void of_device_uevent_aliases(struct device_node *node,
drivers/of/base.c static void of_alias_add(struct alias_prop *ap, struct device_node *np, · line 1193
Quoted 10 lines
drivers/of/base.c +10
-0+ struct kobj_uevent_env *env) +{ +struct alias_prop *app; +int seen =0 ; + +mutex_lock (&of_aliases_mutex); +list_for_each_entry (app, &aliases_lookup, link) { +if (node == app->np) { +add_uevent_var (env,"OF_ALIAS_%d=%s%d" , seen, app->stem, + app->id);
add_uevent_var(env, "OF_ALIAS_%d=%s", seen, app->alias);
drivers/of/base.c static void of_alias_add(struct alias_prop *ap, struct device_node *np, · line 1202
Quoted 9 lines
drivers/of/base.c +9
-0+ seen++; + } + } + +if (seen) +add_uevent_var (env,"OF_ALIAS_N=%d" , seen); + +mutex_unlock (&of_aliases_mutex); +}
Why is this implemented as a separate function? Do you forsee it being called by something else? If not, then just roll it into the body of of_device_uevent_aliases() please.
Oh, wait, alias_prop is only defined in drivers/of/base.c. Rats. Can you create a header named drivers/of/of_private.h to move it into please? I don't want the uevent stuff to appear in drivers/of/base.c.
Quoted 34 lines
drivers/of/base.c +2
-0+ +/** * of_alias_scan - Scan all properties of 'aliases' node * * The function scans all the properties of 'aliases' node and populate drivers/of/device.c +1
-0@@ -153,6 +153,7 @@ void of_device_uevent(struct device *dev, struct kobj_uevent_env *env) seen++; }add_uevent_var (env,"OF_COMPATIBLE_N=%d" , seen); +of_device_uevent_aliases (dev->of_node, env); }int of_device_uevent_modalias (struct device *dev,struct kobj_uevent_env *env)include/linux/of_device.h +2
-1@@ -36,6 +36,8 @@ extern ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len);extern void of_device_uevent (struct device *dev,struct kobj_uevent_env *env); +extern void of_device_uevent_aliases (struct device_node *node, +struct kobj_uevent_env *env);extern int of_device_uevent_modalias (struct device *dev,struct kobj_uevent_env *env);static inline void of_device_node_put (struct device *dev) --The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Signature · 2 lines
Grant Likely, B.Sc, P.Eng. Secret Lab Technologies, Ltd.
PATCH v2 1/1 of: Output devicetree alias names in uevent
In some situations, userspace may want to resolve a device by function and logical number (ie, "serial0") rather than by the base address or full device path. Being able to resolve a device by alias frees userspace from the burden of otherwise having to maintain a mapping between device addresses and their logical assignments on each platform when multiple instances of the same hardware block are present in the system.
Although the uevent device attribute contains devicetree compatible information and the full device path, the uevent does not list the alises that may have been defined for the device.
---
v2: Create of_private.h and move struct alias_prop there
Add alias uevent variables from of_device_uevent Use app->alias instead of app->stem / app->id directly Expose alias_lookup and of_alias_mutex
drivers/of/base.c | 23 +++-------------------- drivers/of/device.c | 17 +++++++++++++++++ drivers/of/of_private.h | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 20 deletions(-) create mode 100644 drivers/of/of_private.h
drivers/of/base.c +3 -20
@@ -24,32 +24,15 @@#include <linux/slab.h> #include <linux/proc_fs.h> -/** -* struct alias_prop - Alias property in 'aliases' node -* @link: List node to link the structure in aliases_lookup list -* @alias: Alias property name -* @np: Pointer to device_node that the alias stands for -* @id: Index value from end of alias name -* @stem: Alias string without the index -* -* The structure represents one alias property of 'aliases' node as -* an entry in aliases_lookup list. -*/ -struct alias_prop { -struct list_head link; -const char *alias; -struct device_node *np; -int id; -char stem[0 ]; -}; +#include "of_private.h" -static LIST_HEAD (aliases_lookup); +LIST_HEAD (aliases_lookup);struct device_node *allnodes;struct device_node *of_chosen;struct device_node *of_aliases; -static DEFINE_MUTEX (of_aliases_mutex); +DEFINE_MUTEX (of_aliases_mutex);/* use when traversing tree through the allnext, child, sibling, * or parent members of struct device_node.
drivers/of/device.c +17 -0
@@ -8,6 +8,7 @@#include <linux/slab.h> #include <asm/errno.h> +#include "of_private.h" /** * of_match_device - Tell if a struct device matches an of_device_id list
@@ -131,6 +132,7 @@ ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len)void of_device_uevent (struct device *dev,struct kobj_uevent_env *env) {const char *compat; +struct alias_prop *app;int seen =0 , cplen, sl;if ((!dev) || (!dev->of_node))
@@ -153,6 +155,21 @@ void of_device_uevent(struct device *dev, struct kobj_uevent_env *env) seen++; }add_uevent_var (env,"OF_COMPATIBLE_N=%d" , seen); + + seen =0 ; +mutex_lock (&of_aliases_mutex); +list_for_each_entry (app, &aliases_lookup, link) { +if (dev->of_node == app->np) { +add_uevent_var (env,"OF_ALIAS_%d=%s" , seen, + app->alias); + seen++; + } + } + +if (seen) +add_uevent_var (env,"OF_ALIAS_N=%d" , seen); + +mutex_unlock (&of_aliases_mutex); }int of_device_uevent_modalias (struct device *dev,struct kobj_uevent_env *env)
drivers/of/of_private.h new file +33 -0
@@ -0,0 +1,33 @@ +/* Copyright (c) 2012, The Linux Foundation. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 and +* only version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +/** +* struct alias_prop - Alias property in 'aliases' node +* @link: List node to link the structure in aliases_lookup list +* @alias: Alias property name +* @np: Pointer to device_node that the alias stands for +* @id: Index value from end of alias name +* @stem: Alias string without the index +* +* The structure represents one alias property of 'aliases' node as +* an entry in aliases_lookup list. +*/ +struct alias_prop { +struct list_head link; +const char *alias; +struct device_node *np; +int id; +char stem[0 ]; +}; + +extern struct mutex of_aliases_mutex; +extern struct list_head aliases_lookup;
--
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Quoted 115 lines · Stepan Moskovchenko
In some situations, userspace may want to resolve a device by function and logical number (ie, "serial0") rather than by the base address or full device path. Being able to resolve a device by alias frees userspace from the burden of otherwise having to maintain a mapping between device addresses and their logical assignments on each platform when multiple instances of the same hardware block are present in the system.
Although the uevent device attribute contains devicetree compatible information and the full device path, the uevent does not list the alises that may have been defined for the device.
Signed-off-by Stepan Moskovchenko <[email protected]>---
v2: Createof_private.hand move structalias_propthere
Add alias uevent variables fromof_device_ueventUseapp->aliasinstead ofapp->stem/app->iddirectly Exposealias_lookupandof_alias_mutexdrivers/of/base.c | 23 +++-------------------- drivers/of/device.c | 17 +++++++++++++++++ drivers/of/of_private.h | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 20 deletions(-) create mode 100644 drivers/of/of_private.hdrivers/of/base.c +3
-20@@ -24,32 +24,15 @@#include <linux/slab.h> #include <linux/proc_fs.h> -/** -* struct alias_prop - Alias property in 'aliases' node -* @link: List node to link the structure in aliases_lookup list -* @alias: Alias property name -* @np: Pointer to device_node that the alias stands for -* @id: Index value from end of alias name -* @stem: Alias string without the index -* -* The structure represents one alias property of 'aliases' node as -* an entry in aliases_lookup list. -*/ -struct alias_prop { -struct list_head link; -const char *alias; -struct device_node *np; -int id; -char stem[0 ]; -}; +#include "of_private.h" -static LIST_HEAD (aliases_lookup); +LIST_HEAD (aliases_lookup);struct device_node *allnodes;struct device_node *of_chosen;struct device_node *of_aliases; -static DEFINE_MUTEX (of_aliases_mutex); +DEFINE_MUTEX (of_aliases_mutex);/* use when traversing tree through the allnext, child, sibling, * or parent members of struct device_node. drivers/of/device.c +17
-0@@ -8,6 +8,7 @@#include <linux/slab.h> #include <asm/errno.h> +#include "of_private.h" /** * of_match_device - Tell if a struct device matches an of_device_id list @@ -131,6 +132,7 @@ ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len)void of_device_uevent (struct device *dev,struct kobj_uevent_env *env) {const char *compat; +struct alias_prop *app;int seen =0 , cplen, sl;if ((!dev) || (!dev->of_node))@@ -153,6 +155,21 @@ void of_device_uevent(struct device *dev, struct kobj_uevent_env *env) seen++; }add_uevent_var (env,"OF_COMPATIBLE_N=%d" , seen); + + seen =0 ; +mutex_lock (&of_aliases_mutex); +list_for_each_entry (app, &aliases_lookup, link) { +if (dev->of_node == app->np) { +add_uevent_var (env,"OF_ALIAS_%d=%s" , seen, + app->alias); + seen++; + } + } + +if (seen) +add_uevent_var (env,"OF_ALIAS_N=%d" , seen); + +mutex_unlock (&of_aliases_mutex); }int of_device_uevent_modalias (struct device *dev,struct kobj_uevent_env *env)drivers/of/of_private.h new file +0
-0
drivers/of/of_private.h line 1
Quoted 1 line
drivers/of/of_private.h new file +1
-0@@ -0,0 +1,33 @@ +/* Copyright (c) 2012, The Linux Foundation. All rights reserved.
Oops, that doesn't look right. You need to preserve the copyright messages from the file this came from. You didn't write this code, you only moved it about.
Otherwise the patch looks good. Can you please respin with that change?
g.
PATCH v3 1/1 of: Output devicetree alias names in uevent
In some situations, userspace may want to resolve a device by function and logical number (ie, "serial0") rather than by the base address or full device path. Being able to resolve a device by alias frees userspace from the burden of otherwise having to maintain a mapping between device addresses and their logical assignments on each platform when multiple instances of the same hardware block are present in the system.
Although the uevent device attribute contains devicetree compatible information and the full device path, the uevent does not list the alises that may have been defined for the device.
---
v3: Fix copyright/license message on of_platform.h to match
the messages in the file the code came from.
I also noticed that some of the comments in the original header might no longer apply, but I copied the header in its entirety. I can try to trim these down if you like.
drivers/of/base.c | 23 +++-------------------- drivers/of/device.c | 17 +++++++++++++++++ drivers/of/of_private.h | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 20 deletions(-) create mode 100644 drivers/of/of_private.h
drivers/of/base.c +3 -20
@@ -24,32 +24,15 @@#include <linux/slab.h> #include <linux/proc_fs.h> -/** -* struct alias_prop - Alias property in 'aliases' node -* @link: List node to link the structure in aliases_lookup list -* @alias: Alias property name -* @np: Pointer to device_node that the alias stands for -* @id: Index value from end of alias name -* @stem: Alias string without the index -* -* The structure represents one alias property of 'aliases' node as -* an entry in aliases_lookup list. -*/ -struct alias_prop { -struct list_head link; -const char *alias; -struct device_node *np; -int id; -char stem[0 ]; -}; +#include "of_private.h" -static LIST_HEAD (aliases_lookup); +LIST_HEAD (aliases_lookup);struct device_node *allnodes;struct device_node *of_chosen;struct device_node *of_aliases; -static DEFINE_MUTEX (of_aliases_mutex); +DEFINE_MUTEX (of_aliases_mutex);/* use when traversing tree through the allnext, child, sibling, * or parent members of struct device_node.
drivers/of/device.c +17 -0
@@ -8,6 +8,7 @@#include <linux/slab.h> #include <asm/errno.h> +#include "of_private.h" /** * of_match_device - Tell if a struct device matches an of_device_id list
@@ -131,6 +132,7 @@ ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len)void of_device_uevent (struct device *dev,struct kobj_uevent_env *env) {const char *compat; +struct alias_prop *app;int seen =0 , cplen, sl;if ((!dev) || (!dev->of_node))
@@ -153,6 +155,21 @@ void of_device_uevent(struct device *dev, struct kobj_uevent_env *env) seen++; }add_uevent_var (env,"OF_COMPATIBLE_N=%d" , seen); + + seen =0 ; +mutex_lock (&of_aliases_mutex); +list_for_each_entry (app, &aliases_lookup, link) { +if (dev->of_node == app->np) { +add_uevent_var (env,"OF_ALIAS_%d=%s" , seen, + app->alias); + seen++; + } + } + +if (seen) +add_uevent_var (env,"OF_ALIAS_N=%d" , seen); + +mutex_unlock (&of_aliases_mutex); }int of_device_uevent_modalias (struct device *dev,struct kobj_uevent_env *env)
drivers/of/of_private.h new file +41 -0
41 lines not on this page · raw message
--
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Quoted 9 lines · Stepan Moskovchenko
In some situations, userspace may want to resolve a device by function and logical number (ie, "serial0") rather than by the base address or full device path. Being able to resolve a device by alias frees userspace from the burden of otherwise having to maintain a mapping between device addresses and their logical assignments on each platform when multiple instances of the same hardware block are present in the system.
Quoted 6 lines
Although the uevent device attribute contains devicetree compatible information and the full device path, the uevent does not list the alises that may have been defined for the device.
Signed-off-by Stepan Moskovchenko <[email protected]>
I've picked this up into my devicetree/next branch. It will get pushed out to linux-next after the merge window closes.
Thanks,
g.