diff options
author | Nathan Fontenot <nfont@linux.vnet.ibm.com> | 2012-10-02 12:55:01 -0400 |
---|---|---|
committer | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2012-11-14 17:43:54 -0500 |
commit | e81b3295bc54eb0d03f4cdfc8cbf72e731d1b402 (patch) | |
tree | 562c84116ff9b969512347a6ffd326fdfe3a9592 /drivers | |
parent | 83dac59409387789b88bed40b1be86a8abc572be (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>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/of/base.c | 55 |
1 files changed, 51 insertions, 4 deletions
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 | ||
1164 | static 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 | ||
1173 | static 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 | ||
1197 | static 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 | ||
1211 | static 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 | |||
1219 | out_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 | ||