1 \ tag
: device
tree administration
3 \ this
code implements
IEEE 1275-1994
5 \
Copyright (C) 2003 Samuel Rydh
6 \
Copyright (C) 2003-2006 Stefan Reinauer
8 \
See the file
"COPYING" for further information about
9 \
the copyright and warranty status
of this
work.
13 \
7.4.11.1 Device alias
15 : devalias
( "{alias-name}< >{device-specifier}<cr>" -- )
18 : nvalias
( "alias-name< >device-specifier<cr>" -- )
21 : $nvalias
( name
-str name
-len dev
-str dev
-len
-- )
24 : nvunalias
( "alias-name< >" -- )
27 : $nvunalias
( name
-str name
-len
-- )
31 \
7.4.11.2 Device tree browsing
33 : dev
( "<spaces>device-specifier" -- )
42 \ find
-device
( dev
-str dev
-len
-- )
43 \ implemented
in pathres
.fs
53 : ?active
-package
( -- phandle
)
54 active
-package
dup 0= abort
" no active device"
57 \
-------------------------------------------------------
59 \
-------------------------------------------------------
61 \ used
if parent
lacks an encode
-unit method
62 : def
-encode
-unit ( unitaddr
... )
66 : get
-encode
-unit-xt
( phandle
.parent
-- xt
)
68 " encode-unit" rot
find-method
69 0= if ['] def-encode-unit then
72 : get-nodename ( phandle -- str len )
73 " name" rot get-package-property if " <noname>" else 1- then
76 \ helper, return the node name in the format 'cpus
@addr
'
77 : pnodename ( phandle -- str len )
79 dup " reg" rot get-package-property if drop exit then rot
81 \ set active-package and clear my-self (decode-phys needs this)
82 my-self >r 0 to my-self
86 ( name len prop len phandle )
89 ( name len prop len xt )
91 decode-phys r> execute
92 r> -rot >r >r depth! 3drop
94 ( name len R: len str )
96 here 20 + \ abuse dictionary for temporary storage
98 2swap r> tmpstrcat drop
105 : inodename ( ihandle -- str len )
106 my-self over to my-self >r
107 ihandle>phandle get-nodename
109 \ nonzero unit number?
111 depth >r my-unit r> 1+
112 begin depth over > while
113 swap 0<> if r> drop true >r then
117 \ if not... check for presence of "reg" property
119 " reg" my-self ihandle>phandle get-package-property
120 if false else 2drop true then
123 ( name len print-unit-flag )
125 my-self ihandle>phandle get-encode-unit-xt
130 r> -rot >r >r depth! drop
134 " @" rot tmpstrcat drop
135 2swap pocket tmpstrcat drop
140 " :" pocket tmpstrcat drop
141 2swap pocket tmpstrcat drop
149 \ helper, also used by client interface (package-to-path)
150 : get-package-path ( phandle -- str len )
153 dup >dn.parent @ 0= if drop " /" exit then
154 \ dictionary abused for temporary storage
156 begin r> dup >dn.parent @ dup >r while
157 ( path len tempbuf phandle R: phandle.parent )
158 pnodename rot tmpstrcat
162 pocket tmpstrcpy drop
165 \ used by client interface (instance-to-path)
166 : get-instance-path ( ihandle -- str len )
169 dup ihandle>phandle >dn.parent @ 0= if drop " /" exit then
171 \ dictionary abused for temporary storage
173 begin r> dup >in.my-parent @ dup >r while
174 ( path len tempbuf ihandle R: ihandle.parent )
175 dup >in.interposed @ 0= if
176 inodename rot tmpstrcat
183 pocket tmpstrcpy drop
186 \ used by client interface (instance-to-interposed-path)
187 : get-instance-interposed-path ( ihandle -- str len )
190 dup ihandle>phandle >dn.parent @ 0= if drop " /" exit then
192 \ dictionary abused for temporary storage
194 begin r> dup >in.my-parent @ dup >r while
195 ( path len tempbuf ihandle R: ihandle.parent )
196 dup >r inodename rot tmpstrcat
197 r> >in.interposed @ if " /%" else " /" then
201 pocket tmpstrcpy drop
205 ?active-package get-package-path type
210 ?active-package >dn.child @
212 dup u. dup pnodename type cr
219 \ -------------------------------------------
221 \ -------------------------------------------
223 : .p-string? ( data len -- true | data len false )
225 2dup + 1- c@ if 0 exit then
228 \ count zeros and detect unprintable characters?
229 over 1- begin 1- dup 0>= while
236 dup 1b <= swap 80 >= or
237 if 2drop r> swap 0 exit then
244 ascii " emit 1- type ascii " emit true exit
247 \ make sure there are no double zeros (except possibly at the end)
252 2dup 1+ <> if 2drop false exit then
260 \ multistring ( cnt end ptr )
262 rot dup if ." , " then 1+ -rot
264 ascii " emit type ascii " emit
271 : .p-int? ( data len -- 1 | data len 0 )
272 dup 4 <> if false exit then
273 decode-int -rot 2drop true swap
274 dup 0>= if . exit then
275 dup -ff < if u. exit then
279 \ Print a number zero-padded
280 : 0.r ( u minlen -- )
281 0 swap <# 1 ?do # loop #s #> type
284 : .p-bytes? ( data len -- 1 | data len 0 )
297 \ this function tries to heuristically determine the data format
298 : (.property) ( data len -- )
299 dup 0= if 2drop ." <empty>" exit then
301 .p-string? if exit then
303 .p-bytes? if exit then
304 2drop ." <unimplemented type>"
307 \ Print the value of a property in "reg" format
308 : .p-reg ( #acells #scells data len -- )
309 2dup + -rot ( #acells #scells data+len data len )
310 >r >r -rot ( data+len #acells #scells R: len data )
311 4 * swap 4 * dup r> r> ( data+len #sbytes #abytes #abytes data len )
312 bounds ( data+len #sbytes #abytes #abytes data+len data ) ?do
313 dup 0= if 2 spaces then \ start of "size" part
314 2dup <> if \ non-first byte in row
315 dup 3 and 0= if space then \ make numbers more readable
317 i c@ 2 0.r \ print byte
318 1- 3dup nip + 0= if \ end of row
319 3 pick i 1+ > if \ non-last byte
321 d# 26 spaces \ indentation
323 drop dup \ update counter
329 \ Return the number of cells per physical address
330 : .p-translations-#pacells ( -- #cells )
332 " #address-cells" rot get-package-property if
335 decode-int nip nip 1 max
342 \ Return the number of cells per translation entry
343 : .p-translations-#cells ( -- #cells )
346 .p-translations-#pacells +
352 \ Set up column offsets
353 : .p-translations-cols ( -- col1 ... coln #cols )
354 .p-translations-#cells 4 *
358 dup .p-translations-#pacells 4 * -
367 \ Print the value of the MMU translations property
368 : .p-translations ( data len -- )
369 >r >r .p-translations-cols r> r> ( col1 ... coln #cols data len )
370 2dup + -rot ( col1 ... coln #cols data+len data len )
371 >r >r .p-translations-#cells 4 * dup r> r>
372 ( col1 ... coln #cols data+len #bytes #bytes len data )
373 bounds ( col1 ... coln #cols data+len #bytes #bytes data+len data ) ?do
374 3 pick 4 + 4 ?do \ check all defined columns
376 2 spaces \ start new column
379 2dup <> if \ non-first byte in row
380 dup 3 and 0= if space then \ make numbers more readable
382 i c@ 2 0.r \ print byte
383 1- dup 0= if \ end of row
384 2 pick i 1+ > if \ non-last byte
386 d# 26 spaces \ indentation
388 drop dup \ update counter
391 2drop drop 0 ?do drop loop
394 \ This function hardwires data formats to particular node properties
395 : (.property-by-name) ( name-str name-len data len -- )
396 2over " reg" strcmp 0= if
397 my-#acells my-#scells 2swap .p-reg
401 active-package get-nodename " memory" strcmp 0= if
402 2over " available" strcmp 0= if
403 my-#acells my-#scells 2swap .p-reg
407 " /chosen" find-dev if
408 " mmu" rot get-package-property 0= if
409 decode-int nip nip ihandle>phandle active-package = if
410 2over " available" strcmp 0= if
411 my-#acells my-#scells 1 max 2swap .p-reg
414 2over " translations" strcmp 0= if
422 2swap 2drop ( data len )
427 ?active-package dup >r if
432 cr 2dup dup -rot type
433 begin ." " 1+ dup d# 26 >= until drop
435 2dup active-package get-package-property drop
436 ( name-str name-len data len )
447 : print-dev ( phandle -- phandle )
449 dup get-package-path type
450 dup " device_type" rot get-package-property if
453 ." (" decode-string type ." )" cr 2drop
457 : show-sub-devs ( subtree-phandle -- )
467 : show-all-devs ( -- )
470 ?active-package show-sub-devs
475 : show-devs ( "{device-specifier}<cr>" -- )
478 linefeed parse find-device
479 ?active-package show-sub-devs
485 \ 7.4.11.3 Device probing