2 * QEMU PowerPC pSeries Logical Partition (aka sPAPR) hardware System Emulator
4 * Hypercall based emulated RTAS
6 * Copyright (c) 2010-2011 David Gibson, IBM Corporation.
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29 #include "qemu-char.h"
31 #include "device_tree.h"
34 #include "hw/spapr_vio.h"
38 #define TOKEN_BASE 0x2000
39 #define TOKEN_MAX 0x100
41 static void rtas_display_character(sPAPREnvironment
*spapr
,
42 uint32_t token
, uint32_t nargs
,
44 uint32_t nret
, target_ulong rets
)
46 uint8_t c
= rtas_ld(args
, 0);
47 VIOsPAPRDevice
*sdev
= spapr_vio_find_by_reg(spapr
->vio_bus
, 0);
52 vty_putchars(sdev
, &c
, sizeof(c
));
57 static void rtas_get_time_of_day(sPAPREnvironment
*spapr
,
58 uint32_t token
, uint32_t nargs
,
60 uint32_t nret
, target_ulong rets
)
69 qemu_get_timedate(&tm
, 0);
71 rtas_st(rets
, 0, 0); /* Success */
72 rtas_st(rets
, 1, tm
.tm_year
+ 1900);
73 rtas_st(rets
, 2, tm
.tm_mon
+ 1);
74 rtas_st(rets
, 3, tm
.tm_mday
);
75 rtas_st(rets
, 4, tm
.tm_hour
);
76 rtas_st(rets
, 5, tm
.tm_min
);
77 rtas_st(rets
, 6, tm
.tm_sec
);
78 rtas_st(rets
, 7, 0); /* we don't do nanoseconds */
81 static void rtas_power_off(sPAPREnvironment
*spapr
,
82 uint32_t token
, uint32_t nargs
, target_ulong args
,
83 uint32_t nret
, target_ulong rets
)
85 if (nargs
!= 2 || nret
!= 1) {
89 qemu_system_shutdown_request();
93 static struct rtas_call
{
96 } rtas_table
[TOKEN_MAX
];
98 struct rtas_call
*rtas_next
= rtas_table
;
100 target_ulong
spapr_rtas_call(sPAPREnvironment
*spapr
,
101 uint32_t token
, uint32_t nargs
, target_ulong args
,
102 uint32_t nret
, target_ulong rets
)
104 if ((token
>= TOKEN_BASE
)
105 && ((token
- TOKEN_BASE
) < TOKEN_MAX
)) {
106 struct rtas_call
*call
= rtas_table
+ (token
- TOKEN_BASE
);
109 call
->fn(spapr
, token
, nargs
, args
, nret
, rets
);
114 /* HACK: Some Linux early debug code uses RTAS display-character,
115 * but assumes the token value is 0xa (which it is on some real
116 * machines) without looking it up in the device tree. This
117 * special case makes this work */
119 rtas_display_character(spapr
, 0xa, nargs
, args
, nret
, rets
);
123 hcall_dprintf("Unknown RTAS token 0x%x\n", token
);
124 rtas_st(rets
, 0, -3);
128 void spapr_rtas_register(const char *name
, spapr_rtas_fn fn
)
130 assert(rtas_next
< (rtas_table
+ TOKEN_MAX
));
132 rtas_next
->name
= name
;
138 int spapr_rtas_device_tree_setup(void *fdt
, target_phys_addr_t rtas_addr
,
139 target_phys_addr_t rtas_size
)
144 ret
= fdt_add_mem_rsv(fdt
, rtas_addr
, rtas_size
);
146 fprintf(stderr
, "Couldn't add RTAS reserve entry: %s\n",
151 ret
= qemu_devtree_setprop_cell(fdt
, "/rtas", "linux,rtas-base",
154 fprintf(stderr
, "Couldn't add linux,rtas-base property: %s\n",
159 ret
= qemu_devtree_setprop_cell(fdt
, "/rtas", "linux,rtas-entry",
162 fprintf(stderr
, "Couldn't add linux,rtas-entry property: %s\n",
167 ret
= qemu_devtree_setprop_cell(fdt
, "/rtas", "rtas-size",
170 fprintf(stderr
, "Couldn't add rtas-size property: %s\n",
175 for (i
= 0; i
< TOKEN_MAX
; i
++) {
176 struct rtas_call
*call
= &rtas_table
[i
];
182 ret
= qemu_devtree_setprop_cell(fdt
, "/rtas", call
->name
,
185 fprintf(stderr
, "Couldn't add rtas token for %s: %s\n",
186 call
->name
, fdt_strerror(ret
));
194 static void register_core_rtas(void)
196 spapr_rtas_register("display-character", rtas_display_character
);
197 spapr_rtas_register("get-time-of-day", rtas_get_time_of_day
);
198 spapr_rtas_register("power-off", rtas_power_off
);
200 device_init(register_core_rtas
);