root / hw / spapr_rtas.c @ a1e47211
History | View | Annotate | Download (9.1 kB)
1 | 39ac8455 | David Gibson | /*
|
---|---|---|---|
2 | 39ac8455 | David Gibson | * QEMU PowerPC pSeries Logical Partition (aka sPAPR) hardware System Emulator
|
3 | 39ac8455 | David Gibson | *
|
4 | 39ac8455 | David Gibson | * Hypercall based emulated RTAS
|
5 | 39ac8455 | David Gibson | *
|
6 | 39ac8455 | David Gibson | * Copyright (c) 2010-2011 David Gibson, IBM Corporation.
|
7 | 39ac8455 | David Gibson | *
|
8 | 39ac8455 | David Gibson | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
9 | 39ac8455 | David Gibson | * of this software and associated documentation files (the "Software"), to deal
|
10 | 39ac8455 | David Gibson | * in the Software without restriction, including without limitation the rights
|
11 | 39ac8455 | David Gibson | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12 | 39ac8455 | David Gibson | * copies of the Software, and to permit persons to whom the Software is
|
13 | 39ac8455 | David Gibson | * furnished to do so, subject to the following conditions:
|
14 | 39ac8455 | David Gibson | *
|
15 | 39ac8455 | David Gibson | * The above copyright notice and this permission notice shall be included in
|
16 | 39ac8455 | David Gibson | * all copies or substantial portions of the Software.
|
17 | 39ac8455 | David Gibson | *
|
18 | 39ac8455 | David Gibson | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19 | 39ac8455 | David Gibson | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20 | 39ac8455 | David Gibson | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
21 | 39ac8455 | David Gibson | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22 | 39ac8455 | David Gibson | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23 | 39ac8455 | David Gibson | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24 | 39ac8455 | David Gibson | * THE SOFTWARE.
|
25 | 39ac8455 | David Gibson | *
|
26 | 39ac8455 | David Gibson | */
|
27 | 39ac8455 | David Gibson | #include "cpu.h" |
28 | 39ac8455 | David Gibson | #include "sysemu.h" |
29 | 39ac8455 | David Gibson | #include "qemu-char.h" |
30 | 39ac8455 | David Gibson | #include "hw/qdev.h" |
31 | 39ac8455 | David Gibson | #include "device_tree.h" |
32 | 39ac8455 | David Gibson | |
33 | 39ac8455 | David Gibson | #include "hw/spapr.h" |
34 | 39ac8455 | David Gibson | #include "hw/spapr_vio.h" |
35 | 39ac8455 | David Gibson | |
36 | 39ac8455 | David Gibson | #include <libfdt.h> |
37 | 39ac8455 | David Gibson | |
38 | 39ac8455 | David Gibson | #define TOKEN_BASE 0x2000 |
39 | 39ac8455 | David Gibson | #define TOKEN_MAX 0x100 |
40 | 39ac8455 | David Gibson | |
41 | 821303f5 | David Gibson | static void rtas_display_character(sPAPREnvironment *spapr, |
42 | 821303f5 | David Gibson | uint32_t token, uint32_t nargs, |
43 | 821303f5 | David Gibson | target_ulong args, |
44 | 821303f5 | David Gibson | uint32_t nret, target_ulong rets) |
45 | 821303f5 | David Gibson | { |
46 | 821303f5 | David Gibson | uint8_t c = rtas_ld(args, 0);
|
47 | 5f2e2ba2 | David Gibson | VIOsPAPRDevice *sdev = vty_lookup(spapr, 0);
|
48 | 821303f5 | David Gibson | |
49 | 821303f5 | David Gibson | if (!sdev) {
|
50 | 821303f5 | David Gibson | rtas_st(rets, 0, -1); |
51 | 821303f5 | David Gibson | } else {
|
52 | 821303f5 | David Gibson | vty_putchars(sdev, &c, sizeof(c));
|
53 | 821303f5 | David Gibson | rtas_st(rets, 0, 0); |
54 | 821303f5 | David Gibson | } |
55 | 821303f5 | David Gibson | } |
56 | 821303f5 | David Gibson | |
57 | 821303f5 | David Gibson | static void rtas_get_time_of_day(sPAPREnvironment *spapr, |
58 | 821303f5 | David Gibson | uint32_t token, uint32_t nargs, |
59 | 821303f5 | David Gibson | target_ulong args, |
60 | 821303f5 | David Gibson | uint32_t nret, target_ulong rets) |
61 | 821303f5 | David Gibson | { |
62 | 821303f5 | David Gibson | struct tm tm;
|
63 | 821303f5 | David Gibson | |
64 | 821303f5 | David Gibson | if (nret != 8) { |
65 | 821303f5 | David Gibson | rtas_st(rets, 0, -3); |
66 | 821303f5 | David Gibson | return;
|
67 | 821303f5 | David Gibson | } |
68 | 821303f5 | David Gibson | |
69 | ac26f8c3 | Breno Leitao | qemu_get_timedate(&tm, spapr->rtc_offset); |
70 | 821303f5 | David Gibson | |
71 | 821303f5 | David Gibson | rtas_st(rets, 0, 0); /* Success */ |
72 | 821303f5 | David Gibson | rtas_st(rets, 1, tm.tm_year + 1900); |
73 | 821303f5 | David Gibson | rtas_st(rets, 2, tm.tm_mon + 1); |
74 | 821303f5 | David Gibson | rtas_st(rets, 3, tm.tm_mday);
|
75 | 821303f5 | David Gibson | rtas_st(rets, 4, tm.tm_hour);
|
76 | 821303f5 | David Gibson | rtas_st(rets, 5, tm.tm_min);
|
77 | 821303f5 | David Gibson | rtas_st(rets, 6, tm.tm_sec);
|
78 | 821303f5 | David Gibson | rtas_st(rets, 7, 0); /* we don't do nanoseconds */ |
79 | 821303f5 | David Gibson | } |
80 | 821303f5 | David Gibson | |
81 | ac26f8c3 | Breno Leitao | static void rtas_set_time_of_day(sPAPREnvironment *spapr, |
82 | ac26f8c3 | Breno Leitao | uint32_t token, uint32_t nargs, |
83 | ac26f8c3 | Breno Leitao | target_ulong args, |
84 | ac26f8c3 | Breno Leitao | uint32_t nret, target_ulong rets) |
85 | ac26f8c3 | Breno Leitao | { |
86 | ac26f8c3 | Breno Leitao | struct tm tm;
|
87 | ac26f8c3 | Breno Leitao | |
88 | ac26f8c3 | Breno Leitao | tm.tm_year = rtas_ld(args, 0) - 1900; |
89 | ac26f8c3 | Breno Leitao | tm.tm_mon = rtas_ld(args, 1) - 1; |
90 | ac26f8c3 | Breno Leitao | tm.tm_mday = rtas_ld(args, 2);
|
91 | ac26f8c3 | Breno Leitao | tm.tm_hour = rtas_ld(args, 3);
|
92 | ac26f8c3 | Breno Leitao | tm.tm_min = rtas_ld(args, 4);
|
93 | ac26f8c3 | Breno Leitao | tm.tm_sec = rtas_ld(args, 5);
|
94 | ac26f8c3 | Breno Leitao | |
95 | ac26f8c3 | Breno Leitao | /* Just generate a monitor event for the change */
|
96 | ac26f8c3 | Breno Leitao | rtc_change_mon_event(&tm); |
97 | ac26f8c3 | Breno Leitao | spapr->rtc_offset = qemu_timedate_diff(&tm); |
98 | ac26f8c3 | Breno Leitao | |
99 | ac26f8c3 | Breno Leitao | rtas_st(rets, 0, 0); /* Success */ |
100 | ac26f8c3 | Breno Leitao | } |
101 | ac26f8c3 | Breno Leitao | |
102 | 821303f5 | David Gibson | static void rtas_power_off(sPAPREnvironment *spapr, |
103 | 821303f5 | David Gibson | uint32_t token, uint32_t nargs, target_ulong args, |
104 | 821303f5 | David Gibson | uint32_t nret, target_ulong rets) |
105 | 821303f5 | David Gibson | { |
106 | 821303f5 | David Gibson | if (nargs != 2 || nret != 1) { |
107 | 821303f5 | David Gibson | rtas_st(rets, 0, -3); |
108 | 821303f5 | David Gibson | return;
|
109 | 821303f5 | David Gibson | } |
110 | 821303f5 | David Gibson | qemu_system_shutdown_request(); |
111 | 821303f5 | David Gibson | rtas_st(rets, 0, 0); |
112 | 821303f5 | David Gibson | } |
113 | 821303f5 | David Gibson | |
114 | c821a43c | David Gibson | static void rtas_system_reboot(sPAPREnvironment *spapr, |
115 | c821a43c | David Gibson | uint32_t token, uint32_t nargs, |
116 | c821a43c | David Gibson | target_ulong args, |
117 | c821a43c | David Gibson | uint32_t nret, target_ulong rets) |
118 | c821a43c | David Gibson | { |
119 | c821a43c | David Gibson | if (nargs != 0 || nret != 1) { |
120 | c821a43c | David Gibson | rtas_st(rets, 0, -3); |
121 | c821a43c | David Gibson | return;
|
122 | c821a43c | David Gibson | } |
123 | c821a43c | David Gibson | qemu_system_reset_request(); |
124 | c821a43c | David Gibson | rtas_st(rets, 0, 0); |
125 | c821a43c | David Gibson | } |
126 | c821a43c | David Gibson | |
127 | a9f8ad8f | David Gibson | static void rtas_query_cpu_stopped_state(sPAPREnvironment *spapr, |
128 | a9f8ad8f | David Gibson | uint32_t token, uint32_t nargs, |
129 | a9f8ad8f | David Gibson | target_ulong args, |
130 | a9f8ad8f | David Gibson | uint32_t nret, target_ulong rets) |
131 | a9f8ad8f | David Gibson | { |
132 | a9f8ad8f | David Gibson | target_ulong id; |
133 | e2684c0b | Andreas Färber | CPUPPCState *env; |
134 | a9f8ad8f | David Gibson | |
135 | a9f8ad8f | David Gibson | if (nargs != 1 || nret != 2) { |
136 | a9f8ad8f | David Gibson | rtas_st(rets, 0, -3); |
137 | a9f8ad8f | David Gibson | return;
|
138 | a9f8ad8f | David Gibson | } |
139 | a9f8ad8f | David Gibson | |
140 | a9f8ad8f | David Gibson | id = rtas_ld(args, 0);
|
141 | a9f8ad8f | David Gibson | for (env = first_cpu; env; env = env->next_cpu) {
|
142 | a9f8ad8f | David Gibson | if (env->cpu_index != id) {
|
143 | a9f8ad8f | David Gibson | continue;
|
144 | a9f8ad8f | David Gibson | } |
145 | a9f8ad8f | David Gibson | |
146 | a9f8ad8f | David Gibson | if (env->halted) {
|
147 | a9f8ad8f | David Gibson | rtas_st(rets, 1, 0); |
148 | a9f8ad8f | David Gibson | } else {
|
149 | a9f8ad8f | David Gibson | rtas_st(rets, 1, 2); |
150 | a9f8ad8f | David Gibson | } |
151 | a9f8ad8f | David Gibson | |
152 | a9f8ad8f | David Gibson | rtas_st(rets, 0, 0); |
153 | a9f8ad8f | David Gibson | return;
|
154 | a9f8ad8f | David Gibson | } |
155 | a9f8ad8f | David Gibson | |
156 | a9f8ad8f | David Gibson | /* Didn't find a matching cpu */
|
157 | a9f8ad8f | David Gibson | rtas_st(rets, 0, -3); |
158 | a9f8ad8f | David Gibson | } |
159 | a9f8ad8f | David Gibson | |
160 | a9f8ad8f | David Gibson | static void rtas_start_cpu(sPAPREnvironment *spapr, |
161 | a9f8ad8f | David Gibson | uint32_t token, uint32_t nargs, |
162 | a9f8ad8f | David Gibson | target_ulong args, |
163 | a9f8ad8f | David Gibson | uint32_t nret, target_ulong rets) |
164 | a9f8ad8f | David Gibson | { |
165 | a9f8ad8f | David Gibson | target_ulong id, start, r3; |
166 | e2684c0b | Andreas Färber | CPUPPCState *env; |
167 | a9f8ad8f | David Gibson | |
168 | a9f8ad8f | David Gibson | if (nargs != 3 || nret != 1) { |
169 | a9f8ad8f | David Gibson | rtas_st(rets, 0, -3); |
170 | a9f8ad8f | David Gibson | return;
|
171 | a9f8ad8f | David Gibson | } |
172 | a9f8ad8f | David Gibson | |
173 | a9f8ad8f | David Gibson | id = rtas_ld(args, 0);
|
174 | a9f8ad8f | David Gibson | start = rtas_ld(args, 1);
|
175 | a9f8ad8f | David Gibson | r3 = rtas_ld(args, 2);
|
176 | a9f8ad8f | David Gibson | |
177 | a9f8ad8f | David Gibson | for (env = first_cpu; env; env = env->next_cpu) {
|
178 | a9f8ad8f | David Gibson | if (env->cpu_index != id) {
|
179 | a9f8ad8f | David Gibson | continue;
|
180 | a9f8ad8f | David Gibson | } |
181 | a9f8ad8f | David Gibson | |
182 | a9f8ad8f | David Gibson | if (!env->halted) {
|
183 | a9f8ad8f | David Gibson | rtas_st(rets, 0, -1); |
184 | a9f8ad8f | David Gibson | return;
|
185 | a9f8ad8f | David Gibson | } |
186 | a9f8ad8f | David Gibson | |
187 | a9f8ad8f | David Gibson | env->msr = (1ULL << MSR_SF) | (1ULL << MSR_ME); |
188 | a9f8ad8f | David Gibson | env->nip = start; |
189 | a9f8ad8f | David Gibson | env->gpr[3] = r3;
|
190 | a9f8ad8f | David Gibson | env->halted = 0;
|
191 | a9f8ad8f | David Gibson | |
192 | a9f8ad8f | David Gibson | qemu_cpu_kick(env); |
193 | a9f8ad8f | David Gibson | |
194 | a9f8ad8f | David Gibson | rtas_st(rets, 0, 0); |
195 | a9f8ad8f | David Gibson | return;
|
196 | a9f8ad8f | David Gibson | } |
197 | a9f8ad8f | David Gibson | |
198 | a9f8ad8f | David Gibson | /* Didn't find a matching cpu */
|
199 | a9f8ad8f | David Gibson | rtas_st(rets, 0, -3); |
200 | a9f8ad8f | David Gibson | } |
201 | a9f8ad8f | David Gibson | |
202 | 39ac8455 | David Gibson | static struct rtas_call { |
203 | 39ac8455 | David Gibson | const char *name; |
204 | 39ac8455 | David Gibson | spapr_rtas_fn fn; |
205 | 39ac8455 | David Gibson | } rtas_table[TOKEN_MAX]; |
206 | 39ac8455 | David Gibson | |
207 | 39ac8455 | David Gibson | struct rtas_call *rtas_next = rtas_table;
|
208 | 39ac8455 | David Gibson | |
209 | 39ac8455 | David Gibson | target_ulong spapr_rtas_call(sPAPREnvironment *spapr, |
210 | 39ac8455 | David Gibson | uint32_t token, uint32_t nargs, target_ulong args, |
211 | 39ac8455 | David Gibson | uint32_t nret, target_ulong rets) |
212 | 39ac8455 | David Gibson | { |
213 | 39ac8455 | David Gibson | if ((token >= TOKEN_BASE)
|
214 | 39ac8455 | David Gibson | && ((token - TOKEN_BASE) < TOKEN_MAX)) { |
215 | 39ac8455 | David Gibson | struct rtas_call *call = rtas_table + (token - TOKEN_BASE);
|
216 | 39ac8455 | David Gibson | |
217 | 39ac8455 | David Gibson | if (call->fn) {
|
218 | 39ac8455 | David Gibson | call->fn(spapr, token, nargs, args, nret, rets); |
219 | 39ac8455 | David Gibson | return H_SUCCESS;
|
220 | 39ac8455 | David Gibson | } |
221 | 39ac8455 | David Gibson | } |
222 | 39ac8455 | David Gibson | |
223 | 821303f5 | David Gibson | /* HACK: Some Linux early debug code uses RTAS display-character,
|
224 | 821303f5 | David Gibson | * but assumes the token value is 0xa (which it is on some real
|
225 | 821303f5 | David Gibson | * machines) without looking it up in the device tree. This
|
226 | 821303f5 | David Gibson | * special case makes this work */
|
227 | 821303f5 | David Gibson | if (token == 0xa) { |
228 | 821303f5 | David Gibson | rtas_display_character(spapr, 0xa, nargs, args, nret, rets);
|
229 | 821303f5 | David Gibson | return H_SUCCESS;
|
230 | 821303f5 | David Gibson | } |
231 | 821303f5 | David Gibson | |
232 | 39ac8455 | David Gibson | hcall_dprintf("Unknown RTAS token 0x%x\n", token);
|
233 | 39ac8455 | David Gibson | rtas_st(rets, 0, -3); |
234 | 39ac8455 | David Gibson | return H_PARAMETER;
|
235 | 39ac8455 | David Gibson | } |
236 | 39ac8455 | David Gibson | |
237 | 39ac8455 | David Gibson | void spapr_rtas_register(const char *name, spapr_rtas_fn fn) |
238 | 39ac8455 | David Gibson | { |
239 | 39ac8455 | David Gibson | assert(rtas_next < (rtas_table + TOKEN_MAX)); |
240 | 39ac8455 | David Gibson | |
241 | 39ac8455 | David Gibson | rtas_next->name = name; |
242 | 39ac8455 | David Gibson | rtas_next->fn = fn; |
243 | 39ac8455 | David Gibson | |
244 | 39ac8455 | David Gibson | rtas_next++; |
245 | 39ac8455 | David Gibson | } |
246 | 39ac8455 | David Gibson | |
247 | 39ac8455 | David Gibson | int spapr_rtas_device_tree_setup(void *fdt, target_phys_addr_t rtas_addr, |
248 | 39ac8455 | David Gibson | target_phys_addr_t rtas_size) |
249 | 39ac8455 | David Gibson | { |
250 | 39ac8455 | David Gibson | int ret;
|
251 | 39ac8455 | David Gibson | int i;
|
252 | 39ac8455 | David Gibson | |
253 | 39ac8455 | David Gibson | ret = fdt_add_mem_rsv(fdt, rtas_addr, rtas_size); |
254 | 39ac8455 | David Gibson | if (ret < 0) { |
255 | 39ac8455 | David Gibson | fprintf(stderr, "Couldn't add RTAS reserve entry: %s\n",
|
256 | 39ac8455 | David Gibson | fdt_strerror(ret)); |
257 | 39ac8455 | David Gibson | return ret;
|
258 | 39ac8455 | David Gibson | } |
259 | 39ac8455 | David Gibson | |
260 | 39ac8455 | David Gibson | ret = qemu_devtree_setprop_cell(fdt, "/rtas", "linux,rtas-base", |
261 | 39ac8455 | David Gibson | rtas_addr); |
262 | 39ac8455 | David Gibson | if (ret < 0) { |
263 | 39ac8455 | David Gibson | fprintf(stderr, "Couldn't add linux,rtas-base property: %s\n",
|
264 | 39ac8455 | David Gibson | fdt_strerror(ret)); |
265 | 39ac8455 | David Gibson | return ret;
|
266 | 39ac8455 | David Gibson | } |
267 | 39ac8455 | David Gibson | |
268 | 39ac8455 | David Gibson | ret = qemu_devtree_setprop_cell(fdt, "/rtas", "linux,rtas-entry", |
269 | 39ac8455 | David Gibson | rtas_addr); |
270 | 39ac8455 | David Gibson | if (ret < 0) { |
271 | 39ac8455 | David Gibson | fprintf(stderr, "Couldn't add linux,rtas-entry property: %s\n",
|
272 | 39ac8455 | David Gibson | fdt_strerror(ret)); |
273 | 39ac8455 | David Gibson | return ret;
|
274 | 39ac8455 | David Gibson | } |
275 | 39ac8455 | David Gibson | |
276 | 39ac8455 | David Gibson | ret = qemu_devtree_setprop_cell(fdt, "/rtas", "rtas-size", |
277 | 39ac8455 | David Gibson | rtas_size); |
278 | 39ac8455 | David Gibson | if (ret < 0) { |
279 | 39ac8455 | David Gibson | fprintf(stderr, "Couldn't add rtas-size property: %s\n",
|
280 | 39ac8455 | David Gibson | fdt_strerror(ret)); |
281 | 39ac8455 | David Gibson | return ret;
|
282 | 39ac8455 | David Gibson | } |
283 | 39ac8455 | David Gibson | |
284 | 39ac8455 | David Gibson | for (i = 0; i < TOKEN_MAX; i++) { |
285 | 39ac8455 | David Gibson | struct rtas_call *call = &rtas_table[i];
|
286 | 39ac8455 | David Gibson | |
287 | 39ac8455 | David Gibson | if (!call->fn) {
|
288 | 39ac8455 | David Gibson | continue;
|
289 | 39ac8455 | David Gibson | } |
290 | 39ac8455 | David Gibson | |
291 | 39ac8455 | David Gibson | ret = qemu_devtree_setprop_cell(fdt, "/rtas", call->name,
|
292 | 39ac8455 | David Gibson | i + TOKEN_BASE); |
293 | 39ac8455 | David Gibson | if (ret < 0) { |
294 | 39ac8455 | David Gibson | fprintf(stderr, "Couldn't add rtas token for %s: %s\n",
|
295 | 39ac8455 | David Gibson | call->name, fdt_strerror(ret)); |
296 | 39ac8455 | David Gibson | return ret;
|
297 | 39ac8455 | David Gibson | } |
298 | 39ac8455 | David Gibson | |
299 | 39ac8455 | David Gibson | } |
300 | 39ac8455 | David Gibson | return 0; |
301 | 39ac8455 | David Gibson | } |
302 | 821303f5 | David Gibson | |
303 | 83f7d43a | Andreas Färber | static void core_rtas_register_types(void) |
304 | 821303f5 | David Gibson | { |
305 | 821303f5 | David Gibson | spapr_rtas_register("display-character", rtas_display_character);
|
306 | 821303f5 | David Gibson | spapr_rtas_register("get-time-of-day", rtas_get_time_of_day);
|
307 | ac26f8c3 | Breno Leitao | spapr_rtas_register("set-time-of-day", rtas_set_time_of_day);
|
308 | 821303f5 | David Gibson | spapr_rtas_register("power-off", rtas_power_off);
|
309 | c821a43c | David Gibson | spapr_rtas_register("system-reboot", rtas_system_reboot);
|
310 | a9f8ad8f | David Gibson | spapr_rtas_register("query-cpu-stopped-state",
|
311 | a9f8ad8f | David Gibson | rtas_query_cpu_stopped_state); |
312 | a9f8ad8f | David Gibson | spapr_rtas_register("start-cpu", rtas_start_cpu);
|
313 | 821303f5 | David Gibson | } |
314 | 83f7d43a | Andreas Färber | |
315 | 83f7d43a | Andreas Färber | type_init(core_rtas_register_types) |