1 \ tag: Useful device related functions
3 \ Copyright (C) 2003, 2004 Samuel Rydh
5 \ See the file "COPYING" for further information about
6 \ the copyright and warranty status of this work.
10 : parent ( phandle -- parent.phandle|0 )
14 \ -------------------------------------------------------------------
16 \ -------------------------------------------------------------------
18 : int-property ( value name-str name-len -- )
19 rot encode-int 2swap property
22 \ -------------------------------------------------------------------------
24 \ -------------------------------------------------------------------------
26 \ like property (except it takes a phandle as an argument)
27 : encode-property ( buf len propname propname-len phandle -- )
28 dup 0= abort" null phandle"
30 my-self >r 0 to my-self
31 active-package >r active-package!
39 \ -------------------------------------------------------------------
40 \ device tree iteration
41 \ -------------------------------------------------------------------
43 : iterate-tree ( phandle -- phandle|0 )
44 ?dup 0= if device-tree @ exit then
56 \ then peer of a parent
57 begin >dn.parent @ dup while
58 dup peer if peer exit then
62 : iterate-tree-begin ( -- first_node )
67 \ -------------------------------------------------------------------
68 \ device tree iteration
69 \ -------------------------------------------------------------------
71 : iterate-device-type ( lastph|0 type-str type-len -- 0|nextph )
73 begin iterate-tree ?dup while
75 2dup " device_type" r@ get-package-property if 0 0 then
77 strcmp 0= if 2drop r> exit then
83 \ -------------------------------------------------------------------
84 \ device tree "cut and paste"
85 \ -------------------------------------------------------------------
87 \ add a subtree to the current device node
88 : link-nodes ( phandle -- )
89 \ reparent phandle and peers
91 dup >dn.parent active-package !
95 \ add to list of children
96 active-package >dn.child
97 begin dup @ while @ >dn.peer repeat dup . !
100 : link-node ( phandle -- )