Commit ced4eec900850627409d7ff566b009471162b56b

Authored by Stepan Moskovchenko
Committed by Grant Likely
1 parent 88b62b915b

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.

Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
[grant.likely: Removed OF_ALIAS_N field; I don't think it's needed]
[grant.likely: Added #ifndef _LINUX_OF_PRIVATE_H wrapper]
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>

Showing 3 changed files with 52 additions and 20 deletions Side-by-side Diff

... ... @@ -24,33 +24,16 @@
24 24 #include <linux/slab.h>
25 25 #include <linux/proc_fs.h>
26 26  
27   -/**
28   - * struct alias_prop - Alias property in 'aliases' node
29   - * @link: List node to link the structure in aliases_lookup list
30   - * @alias: Alias property name
31   - * @np: Pointer to device_node that the alias stands for
32   - * @id: Index value from end of alias name
33   - * @stem: Alias string without the index
34   - *
35   - * The structure represents one alias property of 'aliases' node as
36   - * an entry in aliases_lookup list.
37   - */
38   -struct alias_prop {
39   - struct list_head link;
40   - const char *alias;
41   - struct device_node *np;
42   - int id;
43   - char stem[0];
44   -};
  27 +#include "of_private.h"
45 28  
46   -static LIST_HEAD(aliases_lookup);
  29 +LIST_HEAD(aliases_lookup);
47 30  
48 31 struct device_node *of_allnodes;
49 32 EXPORT_SYMBOL(of_allnodes);
50 33 struct device_node *of_chosen;
51 34 struct device_node *of_aliases;
52 35  
53   -static DEFINE_MUTEX(of_aliases_mutex);
  36 +DEFINE_MUTEX(of_aliases_mutex);
54 37  
55 38 /* use when traversing tree through the allnext, child, sibling,
56 39 * or parent members of struct device_node.
... ... @@ -8,6 +8,7 @@
8 8 #include <linux/slab.h>
9 9  
10 10 #include <asm/errno.h>
  11 +#include "of_private.h"
11 12  
12 13 /**
13 14 * of_match_device - Tell if a struct device matches an of_device_id list
... ... @@ -131,6 +132,7 @@
131 132 void of_device_uevent(struct device *dev, struct kobj_uevent_env *env)
132 133 {
133 134 const char *compat;
  135 + struct alias_prop *app;
134 136 int seen = 0, cplen, sl;
135 137  
136 138 if ((!dev) || (!dev->of_node))
... ... @@ -153,6 +155,17 @@
153 155 seen++;
154 156 }
155 157 add_uevent_var(env, "OF_COMPATIBLE_N=%d", seen);
  158 +
  159 + seen = 0;
  160 + mutex_lock(&of_aliases_mutex);
  161 + list_for_each_entry(app, &aliases_lookup, link) {
  162 + if (dev->of_node == app->np) {
  163 + add_uevent_var(env, "OF_ALIAS_%d=%s", seen,
  164 + app->alias);
  165 + seen++;
  166 + }
  167 + }
  168 + mutex_unlock(&of_aliases_mutex);
156 169 }
157 170  
158 171 int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env)
drivers/of/of_private.h
  1 +#ifndef _LINUX_OF_PRIVATE_H
  2 +#define _LINUX_OF_PRIVATE_H
  3 +/*
  4 + * Private symbols used by OF support code
  5 + *
  6 + * Paul Mackerras August 1996.
  7 + * Copyright (C) 1996-2005 Paul Mackerras.
  8 + *
  9 + * This program is free software; you can redistribute it and/or
  10 + * modify it under the terms of the GNU General Public License
  11 + * as published by the Free Software Foundation; either version
  12 + * 2 of the License, or (at your option) any later version.
  13 + */
  14 +
  15 +/**
  16 + * struct alias_prop - Alias property in 'aliases' node
  17 + * @link: List node to link the structure in aliases_lookup list
  18 + * @alias: Alias property name
  19 + * @np: Pointer to device_node that the alias stands for
  20 + * @id: Index value from end of alias name
  21 + * @stem: Alias string without the index
  22 + *
  23 + * The structure represents one alias property of 'aliases' node as
  24 + * an entry in aliases_lookup list.
  25 + */
  26 +struct alias_prop {
  27 + struct list_head link;
  28 + const char *alias;
  29 + struct device_node *np;
  30 + int id;
  31 + char stem[0];
  32 +};
  33 +
  34 +extern struct mutex of_aliases_mutex;
  35 +extern struct list_head aliases_lookup;
  36 +#endif /* _LINUX_OF_PRIVATE_H */