Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / SLOF / board-qemu / slof / rtas.fs
1 \ *****************************************************************************
2 \ * Copyright (c) 2011 IBM Corporation
3 \ * All rights reserved.
4 \ * This program and the accompanying materials
5 \ * are made available under the terms of the BSD License
6 \ * which accompanies this distribution, and is available at
7 \ * http://www.opensource.org/licenses/bsd-license.php
8 \ *
9 \ * Contributors:
10 \ *     IBM Corporation - initial implementation
11 \ ****************************************************************************/
12
13 \ KVM/qemu RTAS
14
15 \ rtas control block
16
17 371 cp
18
19 STRUCT
20     /l field rtas>token
21     /l field rtas>nargs
22     /l field rtas>nret
23     /l field rtas>args0
24     /l field rtas>args1
25     /l field rtas>args2
26     /l field rtas>args3
27     /l field rtas>args4
28     /l field rtas>args5
29     /l field rtas>args6
30     /l field rtas>args7
31     /l C * field rtas>args
32     /l field rtas>bla
33 CONSTANT /rtas-control-block
34
35 CREATE rtas-cb /rtas-control-block allot
36 rtas-cb /rtas-control-block erase
37
38 0 VALUE rtas-base
39 0 VALUE rtas-size
40 0 VALUE rtas-entry
41 0 VALUE rtas-node
42
43 \ Locate qemu RTAS, remove the linux,... properties we really don't
44 \ want them to stick around
45
46 372 cp
47
48 : find-qemu-rtas ( -- )
49     " /rtas" find-device get-node to rtas-node
50
51     " linux,rtas-base" rtas-node get-package-property IF
52          device-end EXIT THEN
53     drop l@ to rtas-base
54     " linux,rtas-base" delete-property
55
56     " rtas-size" rtas-node get-package-property IF
57          device-end EXIT THEN
58     drop l@ to rtas-size
59
60     " linux,rtas-entry" rtas-node get-package-property IF
61         rtas-base to rtas-entry
62     ELSE
63         drop l@ to rtas-entry
64         " linux,rtas-entry" delete-property
65     THEN
66
67 \    ." RTAS found, base=" rtas-base . ."  size=" rtas-size . cr
68
69     \ Patch the RTAS blob with our sc1 patcher if necessary
70     0
71     rtas-base
72     dup rtas-size +
73     check-and-patch-sc1
74
75     device-end
76 ;
77 find-qemu-rtas
78 373 cp
79
80 : enter-rtas ( -- )
81     rtas-cb rtas-base 0 rtas-entry call-c drop
82 ;
83
84 : rtas-get-token ( str len -- token | 0 )
85     rtas-node get-package-property IF 0 ELSE drop l@ THEN
86 ;
87
88 #include <rtas/rtas-reboot.fs>
89 #include <rtas/rtas-cpu.fs>
90
91 : rtas-set-tce-bypass ( unit enable -- )
92     " ibm,set-tce-bypass" rtas-get-token rtas-cb rtas>token l!
93     2 rtas-cb rtas>nargs l!
94     0 rtas-cb rtas>nret l!
95     rtas-cb rtas>args1 l!
96     rtas-cb rtas>args0 l!
97     enter-rtas
98 ;
99
100 : rtas-quiesce ( -- )
101     " quiesce" rtas-get-token rtas-cb rtas>token l!
102     0 rtas-cb rtas>nargs l!
103     0 rtas-cb rtas>nret l!
104     enter-rtas
105 ;
106
107
108 0 value puid
109
110 : rtas-do-config-@ ( config-addr size -- value)
111     \ We really want to cache this !
112     " ibm,read-pci-config" rtas-get-token rtas-cb rtas>token l!
113     4 rtas-cb rtas>nargs l!
114     2 rtas-cb rtas>nret l!
115     ( addr size ) rtas-cb rtas>args3 l!
116     puid ffffffff and rtas-cb rtas>args2 l!
117     puid 20 rshift rtas-cb rtas>args1 l!
118     ( addr ) rtas-cb rtas>args0 l!
119     enter-rtas
120     rtas-cb rtas>args4 l@ dup IF
121         \ Do not warn on error as this is part of the
122         \ normal PCI probing pass
123         drop ffffffff
124     ELSE
125         drop rtas-cb rtas>args5 l@
126     THEN
127 ;
128
129 : rtas-do-config-! ( value config-addr size )
130     \ We really want to cache this !
131     " ibm,write-pci-config" rtas-get-token rtas-cb rtas>token l!
132     5 rtas-cb rtas>nargs l!
133     1 rtas-cb rtas>nret l!
134     ( value addr size ) rtas-cb rtas>args3 l!
135     puid ffffffff and rtas-cb rtas>args2 l!
136     puid 20 rshift rtas-cb rtas>args1 l!
137     ( value addr ) rtas-cb rtas>args0 l!
138     ( value ) rtas-cb rtas>args4 l!
139     enter-rtas
140     rtas-cb rtas>args5 l@ dup IF
141             ." RTAS write config err " . cr
142     ELSE drop THEN
143 ;
144
145 : rtas-config-b@ ( config-addr -- value )
146   1 rtas-do-config-@ ff and
147 ;
148 : rtas-config-b! ( value config-addr -- )
149   1 rtas-do-config-!
150 ;
151 : rtas-config-w@ ( config-addr -- value )
152   2 rtas-do-config-@ ffff and
153 ;
154 : rtas-config-w! ( value config-addr -- )
155   2 rtas-do-config-!
156 ;
157 : rtas-config-l@ ( config-addr -- value )
158   4 rtas-do-config-@ ffffffff and
159 ;
160 : rtas-config-l! ( value config-addr -- )
161   4 rtas-do-config-!
162 ;
163
164 : of-start-cpu rtas-start-cpu ;
165
166 ' power-off to halt
167 ' rtas-system-reboot to reboot
168
169 \ Methods of the rtas node proper
170 rtas-node set-node
171
172 : open true ;
173 : close ;
174
175 : instantiate-rtas ( adr -- entry )
176     dup rtas-base swap rtas-size move
177     dup rtas-entry rtas-base - +
178     2dup hv-rtas-update dup 0 <> IF
179         \ Ignore hcall not implemented error, print error otherwise
180         dup -2 <> IF ." HV-RTAS-UPDATE error: " . cr ELSE drop THEN
181     ELSE
182         drop
183     THEN
184     nip
185 ;
186
187 device-end
188
189 374 cp