of: merge of_attach_node() & of_detach_node()
authorGrant Likely <grant.likely@secretlab.ca>
Fri, 29 Jan 2010 12:04:33 +0000 (05:04 -0700)
committerGrant Likely <grant.likely@secretlab.ca>
Tue, 9 Feb 2010 15:32:42 +0000 (08:32 -0700)
Merge common code between PowerPC and Microblaze

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Tested-by: Wolfram Sang <w.sang@pengutronix.de>
Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
arch/microblaze/include/asm/prom.h
arch/microblaze/kernel/prom.c
arch/powerpc/include/asm/prom.h
arch/powerpc/kernel/prom.c
drivers/of/Kconfig
drivers/of/base.c
include/linux/of.h

index 07d1063f9aae8b585b0d93f173946e30eb2e7113..6c6b386cf3c6e9caf1879a0fc233dd8ec665eca0 100644 (file)
@@ -39,10 +39,6 @@ extern struct device_node *of_chosen;
 
 extern rwlock_t devtree_lock;  /* temporary while merging */
 
-/* For updating the device tree at runtime */
-extern void of_attach_node(struct device_node *);
-extern void of_detach_node(struct device_node *);
-
 /* Other Prototypes */
 extern int early_uartlite_console(void);
 
index cd158ef5b58328b9ad623a52a7a1cffb7be67be4..8171282a0b0d555d5f382a91f70bc468765bdc9e 100644 (file)
@@ -197,65 +197,6 @@ struct device_node *of_find_node_by_phandle(phandle handle)
 }
 EXPORT_SYMBOL(of_find_node_by_phandle);
 
-/*
- * Plug a device node into the tree and global list.
- */
-void of_attach_node(struct device_node *np)
-{
-       unsigned long flags;
-
-       write_lock_irqsave(&devtree_lock, flags);
-       np->sibling = np->parent->child;
-       np->allnext = allnodes;
-       np->parent->child = np;
-       allnodes = np;
-       write_unlock_irqrestore(&devtree_lock, flags);
-}
-
-/*
- * "Unplug" a node from the device tree.  The caller must hold
- * a reference to the node.  The memory associated with the node
- * is not freed until its refcount goes to zero.
- */
-void of_detach_node(struct device_node *np)
-{
-       struct device_node *parent;
-       unsigned long flags;
-
-       write_lock_irqsave(&devtree_lock, flags);
-
-       parent = np->parent;
-       if (!parent)
-               goto out_unlock;
-
-       if (allnodes == np)
-               allnodes = np->allnext;
-       else {
-               struct device_node *prev;
-               for (prev = allnodes;
-                    prev->allnext != np;
-                    prev = prev->allnext)
-                       ;
-               prev->allnext = np->allnext;
-       }
-
-       if (parent->child == np)
-               parent->child = np->sibling;
-       else {
-               struct device_node *prevsib;
-               for (prevsib = np->parent->child;
-                    prevsib->sibling != np;
-                    prevsib = prevsib->sibling)
-                       ;
-               prevsib->sibling = np->sibling;
-       }
-
-       of_node_set_flag(np, OF_DETACHED);
-
-out_unlock:
-       write_unlock_irqrestore(&devtree_lock, flags);
-}
-
 #if defined(CONFIG_DEBUG_FS) && defined(DEBUG)
 static struct debugfs_blob_wrapper flat_dt_blob;
 
index 2ab9cbd98826555ffb3e3f8be70f43846b415074..f384db815ea8393ba26b3c556c867f129fde2c90 100644 (file)
@@ -34,10 +34,6 @@ extern struct device_node *of_chosen;
 
 #define HAVE_ARCH_DEVTREE_FIXUPS
 
-/* For updating the device tree at runtime */
-extern void of_attach_node(struct device_node *);
-extern void of_detach_node(struct device_node *);
-
 #ifdef CONFIG_PPC32
 /*
  * PCI <-> OF matching functions
index 1ed2ec2ea05b6401aee875bf7e516855105f7f3c..f954c718d7eb7f8cee9830fcf97f005a0a403c53 100644 (file)
@@ -817,65 +817,6 @@ struct device_node *of_find_next_cache_node(struct device_node *np)
        return NULL;
 }
 
-/*
- * Plug a device node into the tree and global list.
- */
-void of_attach_node(struct device_node *np)
-{
-       unsigned long flags;
-
-       write_lock_irqsave(&devtree_lock, flags);
-       np->sibling = np->parent->child;
-       np->allnext = allnodes;
-       np->parent->child = np;
-       allnodes = np;
-       write_unlock_irqrestore(&devtree_lock, flags);
-}
-
-/*
- * "Unplug" a node from the device tree.  The caller must hold
- * a reference to the node.  The memory associated with the node
- * is not freed until its refcount goes to zero.
- */
-void of_detach_node(struct device_node *np)
-{
-       struct device_node *parent;
-       unsigned long flags;
-
-       write_lock_irqsave(&devtree_lock, flags);
-
-       parent = np->parent;
-       if (!parent)
-               goto out_unlock;
-
-       if (allnodes == np)
-               allnodes = np->allnext;
-       else {
-               struct device_node *prev;
-               for (prev = allnodes;
-                    prev->allnext != np;
-                    prev = prev->allnext)
-                       ;
-               prev->allnext = np->allnext;
-       }
-
-       if (parent->child == np)
-               parent->child = np->sibling;
-       else {
-               struct device_node *prevsib;
-               for (prevsib = np->parent->child;
-                    prevsib->sibling != np;
-                    prevsib = prevsib->sibling)
-                       ;
-               prevsib->sibling = np->sibling;
-       }
-
-       of_node_set_flag(np, OF_DETACHED);
-
-out_unlock:
-       write_unlock_irqrestore(&devtree_lock, flags);
-}
-
 #ifdef CONFIG_PPC_PSERIES
 /*
  * Fix up the uninitialized fields in a new device node:
index 462825e031230925aa33699784ca76532d6d739f..7cecc8fea9bd799ffd37e7361c7636cbe3bd69f1 100644 (file)
@@ -2,6 +2,10 @@ config OF_FLATTREE
        bool
        depends on OF
 
+config OF_DYNAMIC
+       def_bool y
+       depends on OF && PPC_OF
+
 config OF_DEVICE
        def_bool y
        depends on OF && (SPARC || PPC_OF || MICROBLAZE)
index cf89ee6253f3ef9799efaeb630a3ae7a43a8f5cd..2ce58be314afd5d6a000ca6df0f9058ba0c0b80b 100644 (file)
@@ -870,3 +870,74 @@ int prom_update_property(struct device_node *np,
 
        return 0;
 }
+
+#if defined(CONFIG_OF_DYNAMIC)
+/*
+ * Support for dynamic device trees.
+ *
+ * On some platforms, the device tree can be manipulated at runtime.
+ * The routines in this section support adding, removing and changing
+ * device tree nodes.
+ */
+
+/**
+ * of_attach_node - Plug a device node into the tree and global list.
+ */
+void of_attach_node(struct device_node *np)
+{
+       unsigned long flags;
+
+       write_lock_irqsave(&devtree_lock, flags);
+       np->sibling = np->parent->child;
+       np->allnext = allnodes;
+       np->parent->child = np;
+       allnodes = np;
+       write_unlock_irqrestore(&devtree_lock, flags);
+}
+
+/**
+ * of_detach_node - "Unplug" a node from the device tree.
+ *
+ * The caller must hold a reference to the node.  The memory associated with
+ * the node is not freed until its refcount goes to zero.
+ */
+void of_detach_node(struct device_node *np)
+{
+       struct device_node *parent;
+       unsigned long flags;
+
+       write_lock_irqsave(&devtree_lock, flags);
+
+       parent = np->parent;
+       if (!parent)
+               goto out_unlock;
+
+       if (allnodes == np)
+               allnodes = np->allnext;
+       else {
+               struct device_node *prev;
+               for (prev = allnodes;
+                    prev->allnext != np;
+                    prev = prev->allnext)
+                       ;
+               prev->allnext = np->allnext;
+       }
+
+       if (parent->child == np)
+               parent->child = np->sibling;
+       else {
+               struct device_node *prevsib;
+               for (prevsib = np->parent->child;
+                    prevsib->sibling != np;
+                    prevsib = prevsib->sibling)
+                       ;
+               prevsib->sibling = np->sibling;
+       }
+
+       of_node_set_flag(np, OF_DETACHED);
+
+out_unlock:
+       write_unlock_irqrestore(&devtree_lock, flags);
+}
+#endif /* defined(CONFIG_OF_DYNAMIC) */
+
index dbabf86e0b7aeea271cd0100c1b58cc77be449f3..3cc0d7ae290eb2501ce4187c94f647522edbc94a 100644 (file)
@@ -184,4 +184,10 @@ extern int of_parse_phandles_with_args(struct device_node *np,
        const char *list_name, const char *cells_name, int index,
        struct device_node **out_node, const void **out_args);
 
+#if defined(CONFIG_OF_DYNAMIC)
+/* For updating the device tree at runtime */
+extern void of_attach_node(struct device_node *);
+extern void of_detach_node(struct device_node *);
+#endif
+
 #endif /* _LINUX_OF_H */