aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Fontenot <nfont@linux.vnet.ibm.com>2012-10-02 12:55:01 -0400
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>2012-11-14 17:43:54 -0500
commite81b3295bc54eb0d03f4cdfc8cbf72e731d1b402 (patch)
tree562c84116ff9b969512347a6ffd326fdfe3a9592
parent83dac59409387789b88bed40b1be86a8abc572be (diff)
powerpc+of: Add /proc device tree updating to of node add/remove
When adding or removing a device tree node we should also update the device tree in /proc/device-tree. This action is already done in the generic OF code for adding/removing properties of a node. This patch adds this functionality for nodes. Signed-off-by: Nathan Fontenot <nfont@linux.vnet.ibm.com> Acked-by: Rob Herring <rob.herring@calxeda.com> Acked-by: Grant Likely <grant.likely@secretlab.ca> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
-rw-r--r--arch/powerpc/platforms/pseries/dlpar.c24
-rw-r--r--arch/powerpc/platforms/pseries/reconfig.c47
-rw-r--r--drivers/of/base.c55
3 files changed, 51 insertions, 75 deletions
diff --git a/arch/powerpc/platforms/pseries/dlpar.c b/arch/powerpc/platforms/pseries/dlpar.c
index 0f1b706506ed..e36789bd4e6c 100644
--- a/arch/powerpc/platforms/pseries/dlpar.c
+++ b/arch/powerpc/platforms/pseries/dlpar.c
@@ -13,7 +13,6 @@
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/kref.h> 14#include <linux/kref.h>
15#include <linux/notifier.h> 15#include <linux/notifier.h>
16#include <linux/proc_fs.h>
17#include <linux/spinlock.h> 16#include <linux/spinlock.h>
18#include <linux/cpu.h> 17#include <linux/cpu.h>
19#include <linux/slab.h> 18#include <linux/slab.h>
@@ -255,9 +254,6 @@ static struct device_node *derive_parent(const char *path)
255 254
256int dlpar_attach_node(struct device_node *dn) 255int dlpar_attach_node(struct device_node *dn)
257{ 256{
258#ifdef CONFIG_PROC_DEVICETREE
259 struct proc_dir_entry *ent;
260#endif
261 int rc; 257 int rc;
262 258
263 of_node_set_flag(dn, OF_DYNAMIC); 259 of_node_set_flag(dn, OF_DYNAMIC);
@@ -274,32 +270,12 @@ int dlpar_attach_node(struct device_node *dn)
274 } 270 }
275 271
276 of_attach_node(dn); 272 of_attach_node(dn);
277
278#ifdef CONFIG_PROC_DEVICETREE
279 ent = proc_mkdir(strrchr(dn->full_name, '/') + 1, dn->parent->pde);
280 if (ent)
281 proc_device_tree_add_node(dn, ent);
282#endif
283
284 of_node_put(dn->parent); 273 of_node_put(dn->parent);
285 return 0; 274 return 0;
286} 275}
287 276
288int dlpar_detach_node(struct device_node *dn) 277int dlpar_detach_node(struct device_node *dn)
289{ 278{
290#ifdef CONFIG_PROC_DEVICETREE
291 struct device_node *parent = dn->parent;
292 struct property *prop = dn->properties;
293
294 while (prop) {
295 remove_proc_entry(prop->name, dn->pde);
296 prop = prop->next;
297 }
298
299 if (dn->pde)
300 remove_proc_entry(dn->pde->name, parent->pde);
301#endif
302
303 pSeries_reconfig_notify(PSERIES_RECONFIG_REMOVE, dn); 279 pSeries_reconfig_notify(PSERIES_RECONFIG_REMOVE, dn);
304 of_detach_node(dn); 280 of_detach_node(dn);
305 of_node_put(dn); /* Must decrement the refcount */ 281 of_node_put(dn); /* Must decrement the refcount */
diff --git a/arch/powerpc/platforms/pseries/reconfig.c b/arch/powerpc/platforms/pseries/reconfig.c
index 39f71fba9b38..f99f1ca8035b 100644
--- a/arch/powerpc/platforms/pseries/reconfig.c
+++ b/arch/powerpc/platforms/pseries/reconfig.c
@@ -23,48 +23,6 @@
23#include <asm/pSeries_reconfig.h> 23#include <asm/pSeries_reconfig.h>
24#include <asm/mmu.h> 24#include <asm/mmu.h>
25 25
26
27
28/*
29 * Routines for "runtime" addition and removal of device tree nodes.
30 */
31#ifdef CONFIG_PROC_DEVICETREE
32/*
33 * Add a node to /proc/device-tree.
34 */
35static void add_node_proc_entries(struct device_node *np)
36{
37 struct proc_dir_entry *ent;
38
39 ent = proc_mkdir(strrchr(np->full_name, '/') + 1, np->parent->pde);
40 if (ent)
41 proc_device_tree_add_node(np, ent);
42}
43
44static void remove_node_proc_entries(struct device_node *np)
45{
46 struct property *pp = np->properties;
47 struct device_node *parent = np->parent;
48
49 while (pp) {
50 remove_proc_entry(pp->name, np->pde);
51 pp = pp->next;
52 }
53 if (np->pde)
54 remove_proc_entry(np->pde->name, parent->pde);
55}
56#else /* !CONFIG_PROC_DEVICETREE */
57static void add_node_proc_entries(struct device_node *np)
58{
59 return;
60}
61
62static void remove_node_proc_entries(struct device_node *np)
63{
64 return;
65}
66#endif /* CONFIG_PROC_DEVICETREE */
67
68/** 26/**
69 * derive_parent - basically like dirname(1) 27 * derive_parent - basically like dirname(1)
70 * @path: the full_name of a node to be added to the tree 28 * @path: the full_name of a node to be added to the tree
@@ -149,9 +107,6 @@ static int pSeries_reconfig_add_node(const char *path, struct property *proplist
149 } 107 }
150 108
151 of_attach_node(np); 109 of_attach_node(np);
152
153 add_node_proc_entries(np);
154
155 of_node_put(np->parent); 110 of_node_put(np->parent);
156 111
157 return 0; 112 return 0;
@@ -179,8 +134,6 @@ static int pSeries_reconfig_remove_node(struct device_node *np)
179 return -EBUSY; 134 return -EBUSY;
180 } 135 }
181 136
182 remove_node_proc_entries(np);
183
184 pSeries_reconfig_notify(PSERIES_RECONFIG_REMOVE, np); 137 pSeries_reconfig_notify(PSERIES_RECONFIG_REMOVE, np);
185 of_detach_node(np); 138 of_detach_node(np);
186 139
diff --git a/drivers/of/base.c b/drivers/of/base.c
index af3b22ac7627..bbd073f53c9f 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1160,6 +1160,22 @@ int prom_update_property(struct device_node *np,
1160 * device tree nodes. 1160 * device tree nodes.
1161 */ 1161 */
1162 1162
1163#ifdef CONFIG_PROC_DEVICETREE
1164static void of_add_proc_dt_entry(struct device_node *dn)
1165{
1166 struct proc_dir_entry *ent;
1167
1168 ent = proc_mkdir(strrchr(dn->full_name, '/') + 1, dn->parent->pde);
1169 if (ent)
1170 proc_device_tree_add_node(dn, ent);
1171}
1172#else
1173static void of_add_proc_dt_entry(struct device_node *dn)
1174{
1175 return;
1176}
1177#endif
1178
1163/** 1179/**
1164 * of_attach_node - Plug a device node into the tree and global list. 1180 * of_attach_node - Plug a device node into the tree and global list.
1165 */ 1181 */
@@ -1173,8 +1189,31 @@ void of_attach_node(struct device_node *np)
1173 np->parent->child = np; 1189 np->parent->child = np;
1174 allnodes = np; 1190 allnodes = np;
1175 write_unlock_irqrestore(&devtree_lock, flags); 1191 write_unlock_irqrestore(&devtree_lock, flags);
1192
1193 of_add_proc_dt_entry(np);
1176} 1194}
1177 1195
1196#ifdef CONFIG_PROC_DEVICETREE
1197static void of_remove_proc_dt_entry(struct device_node *dn)
1198{
1199 struct device_node *parent = dn->parent;
1200 struct property *prop = dn->properties;
1201
1202 while (prop) {
1203 remove_proc_entry(prop->name, dn->pde);
1204 prop = prop->next;
1205 }
1206
1207 if (dn->pde)
1208 remove_proc_entry(dn->pde->name, parent->pde);
1209}
1210#else
1211static void of_remove_proc_dt_entry(struct device_node *dn)
1212{
1213 return;
1214}
1215#endif
1216
1178/** 1217/**
1179 * of_detach_node - "Unplug" a node from the device tree. 1218 * of_detach_node - "Unplug" a node from the device tree.
1180 * 1219 *
@@ -1188,9 +1227,17 @@ void of_detach_node(struct device_node *np)
1188 1227
1189 write_lock_irqsave(&devtree_lock, flags); 1228 write_lock_irqsave(&devtree_lock, flags);
1190 1229
1230 if (of_node_check_flag(np, OF_DETACHED)) {
1231 /* someone already detached it */
1232 write_unlock_irqrestore(&devtree_lock, flags);
1233 return;
1234 }
1235
1191 parent = np->parent; 1236 parent = np->parent;
1192 if (!parent) 1237 if (!parent) {
1193 goto out_unlock; 1238 write_unlock_irqrestore(&devtree_lock, flags);
1239 return;
1240 }
1194 1241
1195 if (allnodes == np) 1242 if (allnodes == np)
1196 allnodes = np->allnext; 1243 allnodes = np->allnext;
@@ -1215,9 +1262,9 @@ void of_detach_node(struct device_node *np)
1215 } 1262 }
1216 1263
1217 of_node_set_flag(np, OF_DETACHED); 1264 of_node_set_flag(np, OF_DETACHED);
1218
1219out_unlock:
1220 write_unlock_irqrestore(&devtree_lock, flags); 1265 write_unlock_irqrestore(&devtree_lock, flags);
1266
1267 of_remove_proc_dt_entry(np);
1221} 1268}
1222#endif /* defined(CONFIG_OF_DYNAMIC) */ 1269#endif /* defined(CONFIG_OF_DYNAMIC) */
1223 1270