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