Skip to content

Commit ced4eec

Browse files
Stepan Moskovchenkoglikely
authored andcommitted
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>
1 parent 88b62b9 commit ced4eec

3 files changed

Lines changed: 52 additions & 20 deletions

File tree

‎drivers/of/base.c‎

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,16 @@
2424
#include <linux/slab.h>
2525
#include <linux/proc_fs.h>
2626

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"
4528

46-
static LIST_HEAD(aliases_lookup);
29+
LIST_HEAD(aliases_lookup);
4730

4831
struct device_node *of_allnodes;
4932
EXPORT_SYMBOL(of_allnodes);
5033
struct device_node *of_chosen;
5134
struct device_node *of_aliases;
5235

53-
static DEFINE_MUTEX(of_aliases_mutex);
36+
DEFINE_MUTEX(of_aliases_mutex);
5437

5538
/* use when traversing tree through the allnext, child, sibling,
5639
* or parent members of struct device_node.

‎drivers/of/device.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/slab.h>
99

1010
#include <asm/errno.h>
11+
#include "of_private.h"
1112

1213
/**
1314
* 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)
131132
void of_device_uevent(struct device *dev, struct kobj_uevent_env *env)
132133
{
133134
const char *compat;
135+
struct alias_prop *app;
134136
int seen = 0, cplen, sl;
135137

136138
if ((!dev) || (!dev->of_node))
@@ -153,6 +155,17 @@ void of_device_uevent(struct device *dev, struct kobj_uevent_env *env)
153155
seen++;
154156
}
155157
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);
156169
}
157170

158171
int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env)

‎drivers/of/of_private.h‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 */

0 commit comments

Comments
 (0)