Skip to content

Commit fcdeb7f

Browse files
committed
of: merge of_attach_node() & of_detach_node()
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>
1 parent 5805371 commit fcdeb7f

7 files changed

Lines changed: 81 additions & 126 deletions

File tree

‎arch/microblaze/include/asm/prom.h‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ extern struct device_node *of_chosen;
3939

4040
extern rwlock_t devtree_lock; /* temporary while merging */
4141

42-
/* For updating the device tree at runtime */
43-
extern void of_attach_node(struct device_node *);
44-
extern void of_detach_node(struct device_node *);
45-
4642
/* Other Prototypes */
4743
extern int early_uartlite_console(void);
4844

‎arch/microblaze/kernel/prom.c‎

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -197,65 +197,6 @@ struct device_node *of_find_node_by_phandle(phandle handle)
197197
}
198198
EXPORT_SYMBOL(of_find_node_by_phandle);
199199

200-
/*
201-
* Plug a device node into the tree and global list.
202-
*/
203-
void of_attach_node(struct device_node *np)
204-
{
205-
unsigned long flags;
206-
207-
write_lock_irqsave(&devtree_lock, flags);
208-
np->sibling = np->parent->child;
209-
np->allnext = allnodes;
210-
np->parent->child = np;
211-
allnodes = np;
212-
write_unlock_irqrestore(&devtree_lock, flags);
213-
}
214-
215-
/*
216-
* "Unplug" a node from the device tree. The caller must hold
217-
* a reference to the node. The memory associated with the node
218-
* is not freed until its refcount goes to zero.
219-
*/
220-
void of_detach_node(struct device_node *np)
221-
{
222-
struct device_node *parent;
223-
unsigned long flags;
224-
225-
write_lock_irqsave(&devtree_lock, flags);
226-
227-
parent = np->parent;
228-
if (!parent)
229-
goto out_unlock;
230-
231-
if (allnodes == np)
232-
allnodes = np->allnext;
233-
else {
234-
struct device_node *prev;
235-
for (prev = allnodes;
236-
prev->allnext != np;
237-
prev = prev->allnext)
238-
;
239-
prev->allnext = np->allnext;
240-
}
241-
242-
if (parent->child == np)
243-
parent->child = np->sibling;
244-
else {
245-
struct device_node *prevsib;
246-
for (prevsib = np->parent->child;
247-
prevsib->sibling != np;
248-
prevsib = prevsib->sibling)
249-
;
250-
prevsib->sibling = np->sibling;
251-
}
252-
253-
of_node_set_flag(np, OF_DETACHED);
254-
255-
out_unlock:
256-
write_unlock_irqrestore(&devtree_lock, flags);
257-
}
258-
259200
#if defined(CONFIG_DEBUG_FS) && defined(DEBUG)
260201
static struct debugfs_blob_wrapper flat_dt_blob;
261202

‎arch/powerpc/include/asm/prom.h‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ extern struct device_node *of_chosen;
3434

3535
#define HAVE_ARCH_DEVTREE_FIXUPS
3636

37-
/* For updating the device tree at runtime */
38-
extern void of_attach_node(struct device_node *);
39-
extern void of_detach_node(struct device_node *);
40-
4137
#ifdef CONFIG_PPC32
4238
/*
4339
* PCI <-> OF matching functions

‎arch/powerpc/kernel/prom.c‎

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -817,65 +817,6 @@ struct device_node *of_find_next_cache_node(struct device_node *np)
817817
return NULL;
818818
}
819819

820-
/*
821-
* Plug a device node into the tree and global list.
822-
*/
823-
void of_attach_node(struct device_node *np)
824-
{
825-
unsigned long flags;
826-
827-
write_lock_irqsave(&devtree_lock, flags);
828-
np->sibling = np->parent->child;
829-
np->allnext = allnodes;
830-
np->parent->child = np;
831-
allnodes = np;
832-
write_unlock_irqrestore(&devtree_lock, flags);
833-
}
834-
835-
/*
836-
* "Unplug" a node from the device tree. The caller must hold
837-
* a reference to the node. The memory associated with the node
838-
* is not freed until its refcount goes to zero.
839-
*/
840-
void of_detach_node(struct device_node *np)
841-
{
842-
struct device_node *parent;
843-
unsigned long flags;
844-
845-
write_lock_irqsave(&devtree_lock, flags);
846-
847-
parent = np->parent;
848-
if (!parent)
849-
goto out_unlock;
850-
851-
if (allnodes == np)
852-
allnodes = np->allnext;
853-
else {
854-
struct device_node *prev;
855-
for (prev = allnodes;
856-
prev->allnext != np;
857-
prev = prev->allnext)
858-
;
859-
prev->allnext = np->allnext;
860-
}
861-
862-
if (parent->child == np)
863-
parent->child = np->sibling;
864-
else {
865-
struct device_node *prevsib;
866-
for (prevsib = np->parent->child;
867-
prevsib->sibling != np;
868-
prevsib = prevsib->sibling)
869-
;
870-
prevsib->sibling = np->sibling;
871-
}
872-
873-
of_node_set_flag(np, OF_DETACHED);
874-
875-
out_unlock:
876-
write_unlock_irqrestore(&devtree_lock, flags);
877-
}
878-
879820
#ifdef CONFIG_PPC_PSERIES
880821
/*
881822
* Fix up the uninitialized fields in a new device node:

‎drivers/of/Kconfig‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ config OF_FLATTREE
22
bool
33
depends on OF
44

5+
config OF_DYNAMIC
6+
def_bool y
7+
depends on OF && PPC_OF
8+
59
config OF_DEVICE
610
def_bool y
711
depends on OF && (SPARC || PPC_OF || MICROBLAZE)

‎drivers/of/base.c‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,3 +870,74 @@ int prom_update_property(struct device_node *np,
870870

871871
return 0;
872872
}
873+
874+
#if defined(CONFIG_OF_DYNAMIC)
875+
/*
876+
* Support for dynamic device trees.
877+
*
878+
* On some platforms, the device tree can be manipulated at runtime.
879+
* The routines in this section support adding, removing and changing
880+
* device tree nodes.
881+
*/
882+
883+
/**
884+
* of_attach_node - Plug a device node into the tree and global list.
885+
*/
886+
void of_attach_node(struct device_node *np)
887+
{
888+
unsigned long flags;
889+
890+
write_lock_irqsave(&devtree_lock, flags);
891+
np->sibling = np->parent->child;
892+
np->allnext = allnodes;
893+
np->parent->child = np;
894+
allnodes = np;
895+
write_unlock_irqrestore(&devtree_lock, flags);
896+
}
897+
898+
/**
899+
* of_detach_node - "Unplug" a node from the device tree.
900+
*
901+
* The caller must hold a reference to the node. The memory associated with
902+
* the node is not freed until its refcount goes to zero.
903+
*/
904+
void of_detach_node(struct device_node *np)
905+
{
906+
struct device_node *parent;
907+
unsigned long flags;
908+
909+
write_lock_irqsave(&devtree_lock, flags);
910+
911+
parent = np->parent;
912+
if (!parent)
913+
goto out_unlock;
914+
915+
if (allnodes == np)
916+
allnodes = np->allnext;
917+
else {
918+
struct device_node *prev;
919+
for (prev = allnodes;
920+
prev->allnext != np;
921+
prev = prev->allnext)
922+
;
923+
prev->allnext = np->allnext;
924+
}
925+
926+
if (parent->child == np)
927+
parent->child = np->sibling;
928+
else {
929+
struct device_node *prevsib;
930+
for (prevsib = np->parent->child;
931+
prevsib->sibling != np;
932+
prevsib = prevsib->sibling)
933+
;
934+
prevsib->sibling = np->sibling;
935+
}
936+
937+
of_node_set_flag(np, OF_DETACHED);
938+
939+
out_unlock:
940+
write_unlock_irqrestore(&devtree_lock, flags);
941+
}
942+
#endif /* defined(CONFIG_OF_DYNAMIC) */
943+

‎include/linux/of.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,10 @@ extern int of_parse_phandles_with_args(struct device_node *np,
184184
const char *list_name, const char *cells_name, int index,
185185
struct device_node **out_node, const void **out_args);
186186

187+
#if defined(CONFIG_OF_DYNAMIC)
188+
/* For updating the device tree at runtime */
189+
extern void of_attach_node(struct device_node *);
190+
extern void of_detach_node(struct device_node *);
191+
#endif
192+
187193
#endif /* _LINUX_OF_H */

0 commit comments

Comments
 (0)