aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/of/base.c130
-rw-r--r--drivers/of/fdt.c4
-rw-r--r--include/linux/of.h8
-rw-r--r--include/linux/of_fdt.h1
4 files changed, 2 insertions, 141 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index fb28b5af733b..3ff22e32b602 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -17,39 +17,14 @@
17 * as published by the Free Software Foundation; either version 17 * as published by the Free Software Foundation; either version
18 * 2 of the License, or (at your option) any later version. 18 * 2 of the License, or (at your option) any later version.
19 */ 19 */
20#include <linux/ctype.h>
21#include <linux/module.h> 20#include <linux/module.h>
22#include <linux/of.h> 21#include <linux/of.h>
23#include <linux/spinlock.h> 22#include <linux/spinlock.h>
24#include <linux/slab.h> 23#include <linux/slab.h>
25#include <linux/proc_fs.h> 24#include <linux/proc_fs.h>
26 25
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 */
38struct alias_prop {
39 struct list_head link;
40 const char *alias;
41 struct device_node *np;
42 int id;
43 char stem[0];
44};
45
46static LIST_HEAD(aliases_lookup);
47
48struct device_node *allnodes; 26struct device_node *allnodes;
49struct device_node *of_chosen; 27struct device_node *of_chosen;
50struct device_node *of_aliases;
51
52static DEFINE_MUTEX(of_aliases_mutex);
53 28
54/* use when traversing tree through the allnext, child, sibling, 29/* use when traversing tree through the allnext, child, sibling,
55 * or parent members of struct device_node. 30 * or parent members of struct device_node.
@@ -1013,108 +988,3 @@ out_unlock:
1013} 988}
1014#endif /* defined(CONFIG_OF_DYNAMIC) */ 989#endif /* defined(CONFIG_OF_DYNAMIC) */
1015 990
1016static void of_alias_add(struct alias_prop *ap, struct device_node *np,
1017 int id, const char *stem, int stem_len)
1018{
1019 ap->id = id;
1020 ap->np = np;
1021 strncpy(ap->stem, stem, stem_len);
1022 ap->stem[stem_len] = 0;
1023 list_add_tail(&ap->link, &aliases_lookup);
1024 pr_debug("adding DT alias:%s: stem=%s id=%i node=%s\n",
1025 ap->alias, ap->stem, ap->id, np ? np->full_name : NULL);
1026}
1027
1028/**
1029 * of_alias_scan() - Scan all properties of 'aliases' node
1030 *
1031 * The function scans all the properties of 'aliases' node and populate
1032 * the global lookup table with the properties. It returns the
1033 * number of alias_prop found, or error code in error case.
1034 */
1035__init void of_alias_scan(void)
1036{
1037 struct property *pp;
1038
1039 if (!of_aliases)
1040 return;
1041
1042 for_each_property(pp, of_aliases->properties) {
1043 const char *start = pp->name;
1044 const char *end = start + strlen(start);
1045 struct device_node *np;
1046 struct alias_prop *ap;
1047 int id, len;
1048
1049 /* Skip those we do not want to proceed */
1050 if (!strcmp(pp->name, "name") ||
1051 !strcmp(pp->name, "phandle") ||
1052 !strcmp(pp->name, "linux,phandle"))
1053 continue;
1054
1055 np = of_find_node_by_path(pp->value);
1056 if (!np)
1057 continue;
1058
1059 /* walk alias backwards to extract the id and 'stem' string */
1060 while (isdigit(*(end-1)) && end > start)
1061 end--;
1062 len = end - start;
1063 id = strlen(end) ? simple_strtoul(end, NULL, 10) : -1;
1064
1065 /* Allocate an alias_prop with enough space for the stem */
1066 ap = early_init_dt_alloc_memory_arch(sizeof(*ap) + len + 1, 4);
1067 if (!ap)
1068 continue;
1069 ap->alias = start;
1070 of_alias_add(ap, np, id, start, len);
1071 }
1072}
1073
1074/**
1075 * of_alias_get_id() - Get alias id for the given device_node
1076 * @np: Pointer to the given device_node
1077 * @stem: Alias stem of the given device_node
1078 *
1079 * The function travels the lookup table to get alias id for the given
1080 * device_node and alias stem. It returns the alias id if find it.
1081 * If not, dynamically creates one in the lookup table and returns it,
1082 * or returns error code if fail to create.
1083 */
1084int of_alias_get_id(struct device_node *np, const char *stem)
1085{
1086 struct alias_prop *app;
1087 int id = 0;
1088 bool found = false;
1089
1090 mutex_lock(&of_aliases_mutex);
1091 list_for_each_entry(app, &aliases_lookup, link) {
1092 if (strcmp(app->stem, stem) != 0)
1093 continue;
1094
1095 if (np == app->np) {
1096 found = true;
1097 id = app->id;
1098 break;
1099 }
1100
1101 if (id <= app->id)
1102 id = app->id + 1;
1103 }
1104
1105 /* If an id is not found, then allocate a new one */
1106 if (!found) {
1107 app = kzalloc(sizeof(*app) + strlen(stem) + 1, 4);
1108 if (!app) {
1109 id = -ENODEV;
1110 goto out;
1111 }
1112 of_alias_add(app, np, id, stem, strlen(stem));
1113 }
1114
1115 out:
1116 mutex_unlock(&of_aliases_mutex);
1117
1118 return id;
1119}
1120EXPORT_SYMBOL_GPL(of_alias_get_id);
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 13d6d3a96b31..65200af29c52 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -707,12 +707,10 @@ void __init unflatten_device_tree(void)
707 __unflatten_device_tree(initial_boot_params, &allnodes, 707 __unflatten_device_tree(initial_boot_params, &allnodes,
708 early_init_dt_alloc_memory_arch); 708 early_init_dt_alloc_memory_arch);
709 709
710 /* Get pointer to "/chosen" and "/aliasas" nodes for use everywhere */ 710 /* Get pointer to OF "/chosen" node for use everywhere */
711 of_chosen = of_find_node_by_path("/chosen"); 711 of_chosen = of_find_node_by_path("/chosen");
712 if (of_chosen == NULL) 712 if (of_chosen == NULL)
713 of_chosen = of_find_node_by_path("/chosen@0"); 713 of_chosen = of_find_node_by_path("/chosen@0");
714 of_aliases = of_find_node_by_path("/aliases");
715 of_alias_scan();
716} 714}
717 715
718#endif /* CONFIG_OF_EARLY_FLATTREE */ 716#endif /* CONFIG_OF_EARLY_FLATTREE */
diff --git a/include/linux/of.h b/include/linux/of.h
index bc3dc6399547..0085bb01c041 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -68,7 +68,6 @@ struct device_node {
68/* Pointer for first entry in chain of all nodes. */ 68/* Pointer for first entry in chain of all nodes. */
69extern struct device_node *allnodes; 69extern struct device_node *allnodes;
70extern struct device_node *of_chosen; 70extern struct device_node *of_chosen;
71extern struct device_node *of_aliases;
72extern rwlock_t devtree_lock; 71extern rwlock_t devtree_lock;
73 72
74static inline bool of_have_populated_dt(void) 73static inline bool of_have_populated_dt(void)
@@ -210,9 +209,6 @@ extern int of_device_is_available(const struct device_node *device);
210extern const void *of_get_property(const struct device_node *node, 209extern const void *of_get_property(const struct device_node *node,
211 const char *name, 210 const char *name,
212 int *lenp); 211 int *lenp);
213#define for_each_property(pp, properties) \
214 for (pp = properties; pp != NULL; pp = pp->next)
215
216extern int of_n_addr_cells(struct device_node *np); 212extern int of_n_addr_cells(struct device_node *np);
217extern int of_n_size_cells(struct device_node *np); 213extern int of_n_size_cells(struct device_node *np);
218extern const struct of_device_id *of_match_node( 214extern const struct of_device_id *of_match_node(
@@ -225,10 +221,6 @@ extern int of_parse_phandles_with_args(struct device_node *np,
225 const char *list_name, const char *cells_name, int index, 221 const char *list_name, const char *cells_name, int index,
226 struct device_node **out_node, const void **out_args); 222 struct device_node **out_node, const void **out_args);
227 223
228extern void *early_init_dt_alloc_memory_arch(u64 size, u64 align);
229extern void of_alias_scan(void);
230extern int of_alias_get_id(struct device_node *np, const char *stem);
231
232extern int of_machine_is_compatible(const char *compat); 224extern int of_machine_is_compatible(const char *compat);
233 225
234extern int prom_add_property(struct device_node* np, struct property* prop); 226extern int prom_add_property(struct device_node* np, struct property* prop);
diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h
index b74b74ffe0e7..c84d900fbbb3 100644
--- a/include/linux/of_fdt.h
+++ b/include/linux/of_fdt.h
@@ -97,6 +97,7 @@ extern void early_init_dt_check_for_initrd(unsigned long node);
97extern int early_init_dt_scan_memory(unsigned long node, const char *uname, 97extern int early_init_dt_scan_memory(unsigned long node, const char *uname,
98 int depth, void *data); 98 int depth, void *data);
99extern void early_init_dt_add_memory_arch(u64 base, u64 size); 99extern void early_init_dt_add_memory_arch(u64 base, u64 size);
100extern void * early_init_dt_alloc_memory_arch(u64 size, u64 align);
100extern u64 dt_mem_next_cell(int s, __be32 **cellp); 101extern u64 dt_mem_next_cell(int s, __be32 **cellp);
101 102
102/* 103/*