Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / openbios / drivers / sbus.fs
1 \ -------------------------------------------------------------------------
2 \ SBus encode/decode unit
3 \ -------------------------------------------------------------------------
4
5 : decode-unit-sbus ( str len -- id lun )
6   ascii , left-split
7   ( addr-R len-R addr-L len-L )
8   parse-hex
9   -rot parse-hex
10   swap
11 ;
12
13 : encode-unit-sbus ( id lun -- str len)
14   swap
15   pocket tohexstr
16   " ," pocket tmpstrcat >r
17   rot pocket tohexstr r> tmpstrcat drop
18 ;
19
20 \ Convert sbus unit (from decode-unit) to physical address using
21 \ sbus node ranges property
22
23 : sbus-unit>addr ( phys.lo phys.hi -- phys.lo phys.hi -1 | 0 )
24   " ranges" my-self ihandle>phandle
25   get-package-property 0= if  ( phys.lo phys.hi prop prop-len )
26     begin
27       2over swap drop 0 swap  \ force phys.lo to zero for matching
28       2swap  ( unit.phys.lo unit.phys.hi 0 phys.hi res prop prop-len )
29       0 -rot  ( unit.phys.lo unit.phys.hi res prop prop-len )
30       2 0 do
31         decode-int -rot >r >r  ( unit.phys.lo unit.phys.hi res phys.x -- R: prop-len prop )
32         rot  ( unit.phys.lo res phys.x phys.hi )
33         = if
34           1+
35         then  ( unit.phys.lo res )
36         r> r>  ( unit.phys.lo res prop prop-len )
37       loop
38       rot  ( prop prop-len res )
39       2 = if  \ did we match the unit address? if so, return the physical address
40         decode-phys 2swap 2drop 2swap  ( unit.phys.lo unit.phys.hi phys.lo phys.hi )
41         drop 0 d+   \ force unit.phys.hi to zero and add address for final offset
42         -1 exit
43       else
44         decode-phys 2drop decode-int drop   \ drop the size and carry on
45       then
46     dup 0= until
47     2drop 2drop 0
48   then
49 ;
50
51 : map-in-sbus ( phys.lo phys.hi size )
52   >r sbus-unit>addr if
53     r@ " map-in" $call-parent
54   then
55   r> drop
56 ;
57
58 : map-out-sbus ( virt size )
59   " map-out" $call-parent
60 ;
61
62 \ -------------------------------------------------------------------------
63 \ SBus probe
64 \ -------------------------------------------------------------------------
65
66 : probe-self-sbus ( arg-adr arg-len reg-adr reg-len fcode-adr fcode-len -- )
67
68   0 to probe-fcode?
69
70   ['] decode-unit-sbus catch if
71     2drop 2drop 2drop 2drop
72     exit
73   then
74
75   h# 10000 map-in-sbus
76
77   dup cpeek if
78     dup h# f1 = swap h# fd = or if
79       new-device
80       >r set-args r>
81       dup 1 byte-load
82       finish-device
83
84       -1 to probe-fcode?
85     else
86       nip nip nip nip
87       ." Invalid FCode start byte" cr
88     then
89   else
90     nip nip nip nip
91   then
92
93   h# 10000 map-out-sbus
94 ;