aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGrant Likely <grant.likely@secretlab.ca>2012-11-06 16:03:27 -0500
committerGrant Likely <grant.likely@linaro.org>2014-03-11 16:48:32 -0400
commit8357041a69b368991d1b04d9f1d297f8d71e1314 (patch)
tree54bc523897eb6c72a95d06efea5c64833fbb51a4
parent7e66c5c74f7348a96d5a3671f8cda4a478242679 (diff)
of: remove /proc/device-tree
The same data is now available in sysfs, so we can remove the code that exports it in /proc and replace it with a symlink to the sysfs version. Tested on versatile qemu model and mpc5200 eval board. More testing would be appreciated. v5: Fixed up conflicts with mainline changes Signed-off-by: Grant Likely <grant.likely@secretlab.ca> Cc: Rob Herring <rob.herring@calxeda.com> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: David S. Miller <davem@davemloft.net> Cc: Nathan Fontenot <nfont@linux.vnet.ibm.com> Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
-rw-r--r--drivers/of/Kconfig8
-rw-r--r--drivers/of/base.c52
-rw-r--r--fs/proc/Makefile1
-rw-r--r--fs/proc/internal.h7
-rw-r--r--fs/proc/proc_devtree.c241
-rw-r--r--fs/proc/root.c3
-rw-r--r--include/linux/of.h11
7 files changed, 1 insertions, 322 deletions
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index ffdcb11f75fb..a46ac1b00032 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -7,14 +7,6 @@ config OF
7menu "Device Tree and Open Firmware support" 7menu "Device Tree and Open Firmware support"
8 depends on OF 8 depends on OF
9 9
10config PROC_DEVICETREE
11 bool "Support for device tree in /proc"
12 depends on PROC_FS && !SPARC
13 help
14 This option adds a device-tree directory under /proc which contains
15 an image of the device tree that the kernel copies from Open
16 Firmware or other boot firmware. If unsure, say Y here.
17
18config OF_SELFTEST 10config OF_SELFTEST
19 bool "Device Tree Runtime self tests" 11 bool "Device Tree Runtime self tests"
20 depends on OF_IRQ 12 depends on OF_IRQ
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 3b70a468c8ab..ed3e70b84957 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -281,11 +281,9 @@ static int __init of_init(void)
281 __of_node_add(np); 281 __of_node_add(np);
282 mutex_unlock(&of_aliases_mutex); 282 mutex_unlock(&of_aliases_mutex);
283 283
284#if !defined(CONFIG_PROC_DEVICETREE) 284 /* Symlink in /proc as required by userspace ABI */
285 /* Symlink to the new tree when PROC_DEVICETREE is disabled */
286 if (of_allnodes) 285 if (of_allnodes)
287 proc_symlink("device-tree", NULL, "/sys/firmware/devicetree/base"); 286 proc_symlink("device-tree", NULL, "/sys/firmware/devicetree/base");
288#endif /* CONFIG_PROC_DEVICETREE */
289 287
290 return 0; 288 return 0;
291} 289}
@@ -1690,12 +1688,6 @@ int of_add_property(struct device_node *np, struct property *prop)
1690 1688
1691 __of_add_property_sysfs(np, prop); 1689 __of_add_property_sysfs(np, prop);
1692 1690
1693#ifdef CONFIG_PROC_DEVICETREE
1694 /* try to add to proc as well if it was initialized */
1695 if (!rc && np->pde)
1696 proc_device_tree_add_prop(np->pde, prop);
1697#endif /* CONFIG_PROC_DEVICETREE */
1698
1699 return rc; 1691 return rc;
1700} 1692}
1701 1693
@@ -1742,12 +1734,6 @@ int of_remove_property(struct device_node *np, struct property *prop)
1742 1734
1743 sysfs_remove_bin_file(&np->kobj, &prop->attr); 1735 sysfs_remove_bin_file(&np->kobj, &prop->attr);
1744 1736
1745#ifdef CONFIG_PROC_DEVICETREE
1746 /* try to remove the proc node as well */
1747 if (np->pde)
1748 proc_device_tree_remove_prop(np->pde, prop);
1749#endif /* CONFIG_PROC_DEVICETREE */
1750
1751 return 0; 1737 return 0;
1752} 1738}
1753 1739
@@ -1803,12 +1789,6 @@ int of_update_property(struct device_node *np, struct property *newprop)
1803 if (!found) 1789 if (!found)
1804 return -ENODEV; 1790 return -ENODEV;
1805 1791
1806#ifdef CONFIG_PROC_DEVICETREE
1807 /* try to add to proc as well if it was initialized */
1808 if (np->pde)
1809 proc_device_tree_update_prop(np->pde, newprop, oldprop);
1810#endif /* CONFIG_PROC_DEVICETREE */
1811
1812 return 0; 1792 return 0;
1813} 1793}
1814 1794
@@ -1843,22 +1823,6 @@ int of_reconfig_notify(unsigned long action, void *p)
1843 return notifier_to_errno(rc); 1823 return notifier_to_errno(rc);
1844} 1824}
1845 1825
1846#ifdef CONFIG_PROC_DEVICETREE
1847static void of_add_proc_dt_entry(struct device_node *dn)
1848{
1849 struct proc_dir_entry *ent;
1850
1851 ent = proc_mkdir(strrchr(dn->full_name, '/') + 1, dn->parent->pde);
1852 if (ent)
1853 proc_device_tree_add_node(dn, ent);
1854}
1855#else
1856static void of_add_proc_dt_entry(struct device_node *dn)
1857{
1858 return;
1859}
1860#endif
1861
1862/** 1826/**
1863 * of_attach_node - Plug a device node into the tree and global list. 1827 * of_attach_node - Plug a device node into the tree and global list.
1864 */ 1828 */
@@ -1880,22 +1844,9 @@ int of_attach_node(struct device_node *np)
1880 raw_spin_unlock_irqrestore(&devtree_lock, flags); 1844 raw_spin_unlock_irqrestore(&devtree_lock, flags);
1881 1845
1882 of_node_add(np); 1846 of_node_add(np);
1883 of_add_proc_dt_entry(np);
1884 return 0; 1847 return 0;
1885} 1848}
1886 1849
1887#ifdef CONFIG_PROC_DEVICETREE
1888static void of_remove_proc_dt_entry(struct device_node *dn)
1889{
1890 proc_remove(dn->pde);
1891}
1892#else
1893static void of_remove_proc_dt_entry(struct device_node *dn)
1894{
1895 return;
1896}
1897#endif
1898
1899/** 1850/**
1900 * of_detach_node - "Unplug" a node from the device tree. 1851 * of_detach_node - "Unplug" a node from the device tree.
1901 * 1852 *
@@ -1951,7 +1902,6 @@ int of_detach_node(struct device_node *np)
1951 of_node_set_flag(np, OF_DETACHED); 1902 of_node_set_flag(np, OF_DETACHED);
1952 raw_spin_unlock_irqrestore(&devtree_lock, flags); 1903 raw_spin_unlock_irqrestore(&devtree_lock, flags);
1953 1904
1954 of_remove_proc_dt_entry(np);
1955 of_node_remove(np); 1905 of_node_remove(np);
1956 return rc; 1906 return rc;
1957} 1907}
diff --git a/fs/proc/Makefile b/fs/proc/Makefile
index ab30716584f5..239493ec718e 100644
--- a/fs/proc/Makefile
+++ b/fs/proc/Makefile
@@ -27,6 +27,5 @@ proc-$(CONFIG_PROC_SYSCTL) += proc_sysctl.o
27proc-$(CONFIG_NET) += proc_net.o 27proc-$(CONFIG_NET) += proc_net.o
28proc-$(CONFIG_PROC_KCORE) += kcore.o 28proc-$(CONFIG_PROC_KCORE) += kcore.o
29proc-$(CONFIG_PROC_VMCORE) += vmcore.o 29proc-$(CONFIG_PROC_VMCORE) += vmcore.o
30proc-$(CONFIG_PROC_DEVICETREE) += proc_devtree.o
31proc-$(CONFIG_PRINTK) += kmsg.o 30proc-$(CONFIG_PRINTK) += kmsg.o
32proc-$(CONFIG_PROC_PAGE_MONITOR) += page.o 31proc-$(CONFIG_PROC_PAGE_MONITOR) += page.o
diff --git a/fs/proc/internal.h b/fs/proc/internal.h
index 651d09a11dde..3ab6d14e71c5 100644
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -211,13 +211,6 @@ extern int proc_fill_super(struct super_block *);
211extern void proc_entry_rundown(struct proc_dir_entry *); 211extern void proc_entry_rundown(struct proc_dir_entry *);
212 212
213/* 213/*
214 * proc_devtree.c
215 */
216#ifdef CONFIG_PROC_DEVICETREE
217extern void proc_device_tree_init(void);
218#endif
219
220/*
221 * proc_namespaces.c 214 * proc_namespaces.c
222 */ 215 */
223extern const struct inode_operations proc_ns_dir_inode_operations; 216extern const struct inode_operations proc_ns_dir_inode_operations;
diff --git a/fs/proc/proc_devtree.c b/fs/proc/proc_devtree.c
deleted file mode 100644
index c82dd5147845..000000000000
--- a/fs/proc/proc_devtree.c
+++ /dev/null
@@ -1,241 +0,0 @@
1/*
2 * proc_devtree.c - handles /proc/device-tree
3 *
4 * Copyright 1997 Paul Mackerras
5 */
6#include <linux/errno.h>
7#include <linux/init.h>
8#include <linux/time.h>
9#include <linux/proc_fs.h>
10#include <linux/seq_file.h>
11#include <linux/printk.h>
12#include <linux/stat.h>
13#include <linux/string.h>
14#include <linux/of.h>
15#include <linux/export.h>
16#include <linux/slab.h>
17#include <asm/uaccess.h>
18#include "internal.h"
19
20static inline void set_node_proc_entry(struct device_node *np,
21 struct proc_dir_entry *de)
22{
23 np->pde = de;
24}
25
26static struct proc_dir_entry *proc_device_tree;
27
28/*
29 * Supply data on a read from /proc/device-tree/node/property.
30 */
31static int property_proc_show(struct seq_file *m, void *v)
32{
33 struct property *pp = m->private;
34
35 seq_write(m, pp->value, pp->length);
36 return 0;
37}
38
39static int property_proc_open(struct inode *inode, struct file *file)
40{
41 return single_open(file, property_proc_show, __PDE_DATA(inode));
42}
43
44static const struct file_operations property_proc_fops = {
45 .owner = THIS_MODULE,
46 .open = property_proc_open,
47 .read = seq_read,
48 .llseek = seq_lseek,
49 .release = single_release,
50};
51
52/*
53 * For a node with a name like "gc@10", we make symlinks called "gc"
54 * and "@10" to it.
55 */
56
57/*
58 * Add a property to a node
59 */
60static struct proc_dir_entry *
61__proc_device_tree_add_prop(struct proc_dir_entry *de, struct property *pp,
62 const char *name)
63{
64 struct proc_dir_entry *ent;
65
66 /*
67 * Unfortunately proc_register puts each new entry
68 * at the beginning of the list. So we rearrange them.
69 */
70 ent = proc_create_data(name,
71 strncmp(name, "security-", 9) ? S_IRUGO : S_IRUSR,
72 de, &property_proc_fops, pp);
73 if (ent == NULL)
74 return NULL;
75
76 if (!strncmp(name, "security-", 9))
77 proc_set_size(ent, 0); /* don't leak number of password chars */
78 else
79 proc_set_size(ent, pp->length);
80
81 return ent;
82}
83
84
85void proc_device_tree_add_prop(struct proc_dir_entry *pde, struct property *prop)
86{
87 __proc_device_tree_add_prop(pde, prop, prop->name);
88}
89
90void proc_device_tree_remove_prop(struct proc_dir_entry *pde,
91 struct property *prop)
92{
93 remove_proc_entry(prop->name, pde);
94}
95
96void proc_device_tree_update_prop(struct proc_dir_entry *pde,
97 struct property *newprop,
98 struct property *oldprop)
99{
100 struct proc_dir_entry *ent;
101
102 if (!oldprop) {
103 proc_device_tree_add_prop(pde, newprop);
104 return;
105 }
106
107 for (ent = pde->subdir; ent != NULL; ent = ent->next)
108 if (ent->data == oldprop)
109 break;
110 if (ent == NULL) {
111 pr_warn("device-tree: property \"%s\" does not exist\n",
112 oldprop->name);
113 } else {
114 ent->data = newprop;
115 ent->size = newprop->length;
116 }
117}
118
119/*
120 * Various dodgy firmware might give us nodes and/or properties with
121 * conflicting names. That's generally ok, except for exporting via /proc,
122 * so munge names here to ensure they're unique.
123 */
124
125static int duplicate_name(struct proc_dir_entry *de, const char *name)
126{
127 struct proc_dir_entry *ent;
128 int found = 0;
129
130 spin_lock(&proc_subdir_lock);
131
132 for (ent = de->subdir; ent != NULL; ent = ent->next) {
133 if (strcmp(ent->name, name) == 0) {
134 found = 1;
135 break;
136 }
137 }
138
139 spin_unlock(&proc_subdir_lock);
140
141 return found;
142}
143
144static const char *fixup_name(struct device_node *np, struct proc_dir_entry *de,
145 const char *name)
146{
147 char *fixed_name;
148 int fixup_len = strlen(name) + 2 + 1; /* name + #x + \0 */
149 int i = 1, size;
150
151realloc:
152 fixed_name = kmalloc(fixup_len, GFP_KERNEL);
153 if (fixed_name == NULL) {
154 pr_err("device-tree: Out of memory trying to fixup "
155 "name \"%s\"\n", name);
156 return name;
157 }
158
159retry:
160 size = snprintf(fixed_name, fixup_len, "%s#%d", name, i);
161 size++; /* account for NULL */
162
163 if (size > fixup_len) {
164 /* We ran out of space, free and reallocate. */
165 kfree(fixed_name);
166 fixup_len = size;
167 goto realloc;
168 }
169
170 if (duplicate_name(de, fixed_name)) {
171 /* Multiple duplicates. Retry with a different offset. */
172 i++;
173 goto retry;
174 }
175
176 pr_warn("device-tree: Duplicate name in %s, renamed to \"%s\"\n",
177 np->full_name, fixed_name);
178
179 return fixed_name;
180}
181
182/*
183 * Process a node, adding entries for its children and its properties.
184 */
185void proc_device_tree_add_node(struct device_node *np,
186 struct proc_dir_entry *de)
187{
188 struct property *pp;
189 struct proc_dir_entry *ent;
190 struct device_node *child;
191 const char *p;
192
193 set_node_proc_entry(np, de);
194 for (child = NULL; (child = of_get_next_child(np, child));) {
195 /* Use everything after the last slash, or the full name */
196 p = kbasename(child->full_name);
197
198 if (duplicate_name(de, p))
199 p = fixup_name(np, de, p);
200
201 ent = proc_mkdir(p, de);
202 if (ent == NULL)
203 break;
204 proc_device_tree_add_node(child, ent);
205 }
206 of_node_put(child);
207
208 for (pp = np->properties; pp != NULL; pp = pp->next) {
209 p = pp->name;
210
211 if (strchr(p, '/'))
212 continue;
213
214 if (duplicate_name(de, p))
215 p = fixup_name(np, de, p);
216
217 ent = __proc_device_tree_add_prop(de, pp, p);
218 if (ent == NULL)
219 break;
220 }
221}
222
223/*
224 * Called on initialization to set up the /proc/device-tree subtree
225 */
226void __init proc_device_tree_init(void)
227{
228 struct device_node *root;
229
230 proc_device_tree = proc_mkdir("device-tree", NULL);
231 if (proc_device_tree == NULL)
232 return;
233 root = of_find_node_by_path("/");
234 if (root == NULL) {
235 remove_proc_entry("device-tree", NULL);
236 pr_debug("/proc/device-tree: can't find root\n");
237 return;
238 }
239 proc_device_tree_add_node(root, proc_device_tree);
240 of_node_put(root);
241}
diff --git a/fs/proc/root.c b/fs/proc/root.c
index 87dbcbef7fe4..7bbeb5257af1 100644
--- a/fs/proc/root.c
+++ b/fs/proc/root.c
@@ -183,9 +183,6 @@ void __init proc_root_init(void)
183 proc_mkdir("openprom", NULL); 183 proc_mkdir("openprom", NULL);
184#endif 184#endif
185 proc_tty_init(); 185 proc_tty_init();
186#ifdef CONFIG_PROC_DEVICETREE
187 proc_device_tree_init();
188#endif
189 proc_mkdir("bus", NULL); 186 proc_mkdir("bus", NULL);
190 proc_sys_init(); 187 proc_sys_init();
191} 188}
diff --git a/include/linux/of.h b/include/linux/of.h
index bd45be5bd565..257994a420f3 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -57,7 +57,6 @@ struct device_node {
57 struct device_node *sibling; 57 struct device_node *sibling;
58 struct device_node *next; /* next device of same type */ 58 struct device_node *next; /* next device of same type */
59 struct device_node *allnext; /* next in list of all nodes */ 59 struct device_node *allnext; /* next in list of all nodes */
60 struct proc_dir_entry *pde; /* this node's proc directory */
61 struct kobject kobj; 60 struct kobject kobj;
62 unsigned long _flags; 61 unsigned long _flags;
63 void *data; 62 void *data;
@@ -658,14 +657,4 @@ static inline int of_get_available_child_count(const struct device_node *np)
658 return num; 657 return num;
659} 658}
660 659
661#if defined(CONFIG_PROC_FS) && defined(CONFIG_PROC_DEVICETREE)
662extern void proc_device_tree_add_node(struct device_node *, struct proc_dir_entry *);
663extern void proc_device_tree_add_prop(struct proc_dir_entry *pde, struct property *prop);
664extern void proc_device_tree_remove_prop(struct proc_dir_entry *pde,
665 struct property *prop);
666extern void proc_device_tree_update_prop(struct proc_dir_entry *pde,
667 struct property *newprop,
668 struct property *oldprop);
669#endif
670
671#endif /* _LINUX_OF_H */ 660#endif /* _LINUX_OF_H */