139ac8455SDavid Gibson /* 239ac8455SDavid Gibson * QEMU PowerPC pSeries Logical Partition (aka sPAPR) hardware System Emulator 339ac8455SDavid Gibson * 439ac8455SDavid Gibson * Hypercall based emulated RTAS 539ac8455SDavid Gibson * 639ac8455SDavid Gibson * Copyright (c) 2010-2011 David Gibson, IBM Corporation. 739ac8455SDavid Gibson * 839ac8455SDavid Gibson * Permission is hereby granted, free of charge, to any person obtaining a copy 939ac8455SDavid Gibson * of this software and associated documentation files (the "Software"), to deal 1039ac8455SDavid Gibson * in the Software without restriction, including without limitation the rights 1139ac8455SDavid Gibson * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 1239ac8455SDavid Gibson * copies of the Software, and to permit persons to whom the Software is 1339ac8455SDavid Gibson * furnished to do so, subject to the following conditions: 1439ac8455SDavid Gibson * 1539ac8455SDavid Gibson * The above copyright notice and this permission notice shall be included in 1639ac8455SDavid Gibson * all copies or substantial portions of the Software. 1739ac8455SDavid Gibson * 1839ac8455SDavid Gibson * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1939ac8455SDavid Gibson * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2039ac8455SDavid Gibson * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 2139ac8455SDavid Gibson * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 2239ac8455SDavid Gibson * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 2339ac8455SDavid Gibson * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 2439ac8455SDavid Gibson * THE SOFTWARE. 2539ac8455SDavid Gibson * 2639ac8455SDavid Gibson */ 2739ac8455SDavid Gibson #include "cpu.h" 289c17d615SPaolo Bonzini #include "sysemu/sysemu.h" 29dccfcd0eSPaolo Bonzini #include "sysemu/char.h" 3039ac8455SDavid Gibson #include "hw/qdev.h" 319c17d615SPaolo Bonzini #include "sysemu/device_tree.h" 3239ac8455SDavid Gibson 330d09e41aSPaolo Bonzini #include "hw/ppc/spapr.h" 340d09e41aSPaolo Bonzini #include "hw/ppc/spapr_vio.h" 35e010ad8fSWenchao Xia #include "qapi-event.h" 3639ac8455SDavid Gibson 3739ac8455SDavid Gibson #include <libfdt.h> 3839ac8455SDavid Gibson 39210b580bSAnthony Liguori static void rtas_display_character(PowerPCCPU *cpu, sPAPREnvironment *spapr, 40821303f5SDavid Gibson uint32_t token, uint32_t nargs, 41821303f5SDavid Gibson target_ulong args, 42821303f5SDavid Gibson uint32_t nret, target_ulong rets) 43821303f5SDavid Gibson { 44821303f5SDavid Gibson uint8_t c = rtas_ld(args, 0); 455f2e2ba2SDavid Gibson VIOsPAPRDevice *sdev = vty_lookup(spapr, 0); 46821303f5SDavid Gibson 47821303f5SDavid Gibson if (!sdev) { 48a64d325dSAlexey Kardashevskiy rtas_st(rets, 0, RTAS_OUT_HW_ERROR); 49821303f5SDavid Gibson } else { 50821303f5SDavid Gibson vty_putchars(sdev, &c, sizeof(c)); 51a64d325dSAlexey Kardashevskiy rtas_st(rets, 0, RTAS_OUT_SUCCESS); 52821303f5SDavid Gibson } 53821303f5SDavid Gibson } 54821303f5SDavid Gibson 55210b580bSAnthony Liguori static void rtas_get_time_of_day(PowerPCCPU *cpu, sPAPREnvironment *spapr, 56821303f5SDavid Gibson uint32_t token, uint32_t nargs, 57821303f5SDavid Gibson target_ulong args, 58821303f5SDavid Gibson uint32_t nret, target_ulong rets) 59821303f5SDavid Gibson { 60821303f5SDavid Gibson struct tm tm; 61821303f5SDavid Gibson 62821303f5SDavid Gibson if (nret != 8) { 63a64d325dSAlexey Kardashevskiy rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR); 64821303f5SDavid Gibson return; 65821303f5SDavid Gibson } 66821303f5SDavid Gibson 67ac26f8c3SBreno Leitao qemu_get_timedate(&tm, spapr->rtc_offset); 68821303f5SDavid Gibson 69a64d325dSAlexey Kardashevskiy rtas_st(rets, 0, RTAS_OUT_SUCCESS); 70821303f5SDavid Gibson rtas_st(rets, 1, tm.tm_year + 1900); 71821303f5SDavid Gibson rtas_st(rets, 2, tm.tm_mon + 1); 72821303f5SDavid Gibson rtas_st(rets, 3, tm.tm_mday); 73821303f5SDavid Gibson rtas_st(rets, 4, tm.tm_hour); 74821303f5SDavid Gibson rtas_st(rets, 5, tm.tm_min); 75821303f5SDavid Gibson rtas_st(rets, 6, tm.tm_sec); 76821303f5SDavid Gibson rtas_st(rets, 7, 0); /* we don't do nanoseconds */ 77821303f5SDavid Gibson } 78821303f5SDavid Gibson 79210b580bSAnthony Liguori static void rtas_set_time_of_day(PowerPCCPU *cpu, sPAPREnvironment *spapr, 80ac26f8c3SBreno Leitao uint32_t token, uint32_t nargs, 81ac26f8c3SBreno Leitao target_ulong args, 82ac26f8c3SBreno Leitao uint32_t nret, target_ulong rets) 83ac26f8c3SBreno Leitao { 84ac26f8c3SBreno Leitao struct tm tm; 85ac26f8c3SBreno Leitao 86ac26f8c3SBreno Leitao tm.tm_year = rtas_ld(args, 0) - 1900; 87ac26f8c3SBreno Leitao tm.tm_mon = rtas_ld(args, 1) - 1; 88ac26f8c3SBreno Leitao tm.tm_mday = rtas_ld(args, 2); 89ac26f8c3SBreno Leitao tm.tm_hour = rtas_ld(args, 3); 90ac26f8c3SBreno Leitao tm.tm_min = rtas_ld(args, 4); 91ac26f8c3SBreno Leitao tm.tm_sec = rtas_ld(args, 5); 92ac26f8c3SBreno Leitao 93ac26f8c3SBreno Leitao /* Just generate a monitor event for the change */ 94e010ad8fSWenchao Xia qapi_event_send_rtc_change(qemu_timedate_diff(&tm), &error_abort); 95ac26f8c3SBreno Leitao spapr->rtc_offset = qemu_timedate_diff(&tm); 96ac26f8c3SBreno Leitao 97a64d325dSAlexey Kardashevskiy rtas_st(rets, 0, RTAS_OUT_SUCCESS); 98ac26f8c3SBreno Leitao } 99ac26f8c3SBreno Leitao 100210b580bSAnthony Liguori static void rtas_power_off(PowerPCCPU *cpu, sPAPREnvironment *spapr, 101821303f5SDavid Gibson uint32_t token, uint32_t nargs, target_ulong args, 102821303f5SDavid Gibson uint32_t nret, target_ulong rets) 103821303f5SDavid Gibson { 104821303f5SDavid Gibson if (nargs != 2 || nret != 1) { 105a64d325dSAlexey Kardashevskiy rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR); 106821303f5SDavid Gibson return; 107821303f5SDavid Gibson } 108821303f5SDavid Gibson qemu_system_shutdown_request(); 109a64d325dSAlexey Kardashevskiy rtas_st(rets, 0, RTAS_OUT_SUCCESS); 110821303f5SDavid Gibson } 111821303f5SDavid Gibson 112210b580bSAnthony Liguori static void rtas_system_reboot(PowerPCCPU *cpu, sPAPREnvironment *spapr, 113c821a43cSDavid Gibson uint32_t token, uint32_t nargs, 114c821a43cSDavid Gibson target_ulong args, 115c821a43cSDavid Gibson uint32_t nret, target_ulong rets) 116c821a43cSDavid Gibson { 117c821a43cSDavid Gibson if (nargs != 0 || nret != 1) { 118a64d325dSAlexey Kardashevskiy rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR); 119c821a43cSDavid Gibson return; 120c821a43cSDavid Gibson } 121c821a43cSDavid Gibson qemu_system_reset_request(); 122a64d325dSAlexey Kardashevskiy rtas_st(rets, 0, RTAS_OUT_SUCCESS); 123c821a43cSDavid Gibson } 124c821a43cSDavid Gibson 125210b580bSAnthony Liguori static void rtas_query_cpu_stopped_state(PowerPCCPU *cpu_, 126210b580bSAnthony Liguori sPAPREnvironment *spapr, 127a9f8ad8fSDavid Gibson uint32_t token, uint32_t nargs, 128a9f8ad8fSDavid Gibson target_ulong args, 129a9f8ad8fSDavid Gibson uint32_t nret, target_ulong rets) 130a9f8ad8fSDavid Gibson { 131a9f8ad8fSDavid Gibson target_ulong id; 1320f20ba62SAlexey Kardashevskiy PowerPCCPU *cpu; 133a9f8ad8fSDavid Gibson 134a9f8ad8fSDavid Gibson if (nargs != 1 || nret != 2) { 135a64d325dSAlexey Kardashevskiy rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR); 136a9f8ad8fSDavid Gibson return; 137a9f8ad8fSDavid Gibson } 138a9f8ad8fSDavid Gibson 139a9f8ad8fSDavid Gibson id = rtas_ld(args, 0); 1400f20ba62SAlexey Kardashevskiy cpu = ppc_get_vcpu_by_dt_id(id); 14105318a85SAndreas Färber if (cpu != NULL) { 1420f20ba62SAlexey Kardashevskiy if (CPU(cpu)->halted) { 143a9f8ad8fSDavid Gibson rtas_st(rets, 1, 0); 144a9f8ad8fSDavid Gibson } else { 145a9f8ad8fSDavid Gibson rtas_st(rets, 1, 2); 146a9f8ad8fSDavid Gibson } 147a9f8ad8fSDavid Gibson 148a64d325dSAlexey Kardashevskiy rtas_st(rets, 0, RTAS_OUT_SUCCESS); 149a9f8ad8fSDavid Gibson return; 150a9f8ad8fSDavid Gibson } 151a9f8ad8fSDavid Gibson 152a9f8ad8fSDavid Gibson /* Didn't find a matching cpu */ 153a64d325dSAlexey Kardashevskiy rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR); 154a9f8ad8fSDavid Gibson } 155a9f8ad8fSDavid Gibson 156210b580bSAnthony Liguori static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPREnvironment *spapr, 157a9f8ad8fSDavid Gibson uint32_t token, uint32_t nargs, 158a9f8ad8fSDavid Gibson target_ulong args, 159a9f8ad8fSDavid Gibson uint32_t nret, target_ulong rets) 160a9f8ad8fSDavid Gibson { 161a9f8ad8fSDavid Gibson target_ulong id, start, r3; 1620f20ba62SAlexey Kardashevskiy PowerPCCPU *cpu; 163a9f8ad8fSDavid Gibson 164a9f8ad8fSDavid Gibson if (nargs != 3 || nret != 1) { 165a64d325dSAlexey Kardashevskiy rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR); 166a9f8ad8fSDavid Gibson return; 167a9f8ad8fSDavid Gibson } 168a9f8ad8fSDavid Gibson 169a9f8ad8fSDavid Gibson id = rtas_ld(args, 0); 170a9f8ad8fSDavid Gibson start = rtas_ld(args, 1); 171a9f8ad8fSDavid Gibson r3 = rtas_ld(args, 2); 172a9f8ad8fSDavid Gibson 1730f20ba62SAlexey Kardashevskiy cpu = ppc_get_vcpu_by_dt_id(id); 1740f20ba62SAlexey Kardashevskiy if (cpu != NULL) { 1750f20ba62SAlexey Kardashevskiy CPUState *cs = CPU(cpu); 176c67e216bSAndreas Färber CPUPPCState *env = &cpu->env; 177c08d7424SAndreas Färber 178c67e216bSAndreas Färber if (!cs->halted) { 179a64d325dSAlexey Kardashevskiy rtas_st(rets, 0, RTAS_OUT_HW_ERROR); 180a9f8ad8fSDavid Gibson return; 181a9f8ad8fSDavid Gibson } 182a9f8ad8fSDavid Gibson 183048706d9SDavid Gibson /* This will make sure qemu state is up to date with kvm, and 184048706d9SDavid Gibson * mark it dirty so our changes get flushed back before the 185048706d9SDavid Gibson * new cpu enters */ 186dd1750d7SAndreas Färber kvm_cpu_synchronize_state(cs); 187048706d9SDavid Gibson 188a9f8ad8fSDavid Gibson env->msr = (1ULL << MSR_SF) | (1ULL << MSR_ME); 189a9f8ad8fSDavid Gibson env->nip = start; 190a9f8ad8fSDavid Gibson env->gpr[3] = r3; 191c67e216bSAndreas Färber cs->halted = 0; 192a9f8ad8fSDavid Gibson 193c67e216bSAndreas Färber qemu_cpu_kick(cs); 194a9f8ad8fSDavid Gibson 195a64d325dSAlexey Kardashevskiy rtas_st(rets, 0, RTAS_OUT_SUCCESS); 196a9f8ad8fSDavid Gibson return; 197a9f8ad8fSDavid Gibson } 198a9f8ad8fSDavid Gibson 199a9f8ad8fSDavid Gibson /* Didn't find a matching cpu */ 200a64d325dSAlexey Kardashevskiy rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR); 201a9f8ad8fSDavid Gibson } 202a9f8ad8fSDavid Gibson 20359760f2dSAlexey Kardashevskiy static void rtas_stop_self(PowerPCCPU *cpu, sPAPREnvironment *spapr, 20459760f2dSAlexey Kardashevskiy uint32_t token, uint32_t nargs, 20559760f2dSAlexey Kardashevskiy target_ulong args, 20659760f2dSAlexey Kardashevskiy uint32_t nret, target_ulong rets) 20759760f2dSAlexey Kardashevskiy { 20859760f2dSAlexey Kardashevskiy CPUState *cs = CPU(cpu); 20959760f2dSAlexey Kardashevskiy CPUPPCState *env = &cpu->env; 21059760f2dSAlexey Kardashevskiy 21159760f2dSAlexey Kardashevskiy cs->halted = 1; 21259760f2dSAlexey Kardashevskiy cpu_exit(cs); 21359760f2dSAlexey Kardashevskiy /* 21459760f2dSAlexey Kardashevskiy * While stopping a CPU, the guest calls H_CPPR which 21559760f2dSAlexey Kardashevskiy * effectively disables interrupts on XICS level. 21659760f2dSAlexey Kardashevskiy * However decrementer interrupts in TCG can still 21759760f2dSAlexey Kardashevskiy * wake the CPU up so here we disable interrupts in MSR 21859760f2dSAlexey Kardashevskiy * as well. 21959760f2dSAlexey Kardashevskiy * As rtas_start_cpu() resets the whole MSR anyway, there is 22059760f2dSAlexey Kardashevskiy * no need to bother with specific bits, we just clear it. 22159760f2dSAlexey Kardashevskiy */ 22259760f2dSAlexey Kardashevskiy env->msr = 0; 22359760f2dSAlexey Kardashevskiy } 22459760f2dSAlexey Kardashevskiy 2253ada6b11SAlexey Kardashevskiy #define DIAGNOSTICS_RUN_MODE 42 2263ada6b11SAlexey Kardashevskiy 2273ada6b11SAlexey Kardashevskiy static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu, 2283ada6b11SAlexey Kardashevskiy sPAPREnvironment *spapr, 2293ada6b11SAlexey Kardashevskiy uint32_t token, uint32_t nargs, 2303ada6b11SAlexey Kardashevskiy target_ulong args, 2313ada6b11SAlexey Kardashevskiy uint32_t nret, target_ulong rets) 2323ada6b11SAlexey Kardashevskiy { 2333ada6b11SAlexey Kardashevskiy target_ulong parameter = rtas_ld(args, 0); 2343ada6b11SAlexey Kardashevskiy target_ulong buffer = rtas_ld(args, 1); 2353ada6b11SAlexey Kardashevskiy target_ulong length = rtas_ld(args, 2); 2363ada6b11SAlexey Kardashevskiy target_ulong ret = RTAS_OUT_NOT_SUPPORTED; 2373ada6b11SAlexey Kardashevskiy 2383ada6b11SAlexey Kardashevskiy switch (parameter) { 2393ada6b11SAlexey Kardashevskiy case DIAGNOSTICS_RUN_MODE: 2403ada6b11SAlexey Kardashevskiy if (length == 1) { 2413ada6b11SAlexey Kardashevskiy rtas_st(buffer, 0, 0); 2423ada6b11SAlexey Kardashevskiy ret = RTAS_OUT_SUCCESS; 2433ada6b11SAlexey Kardashevskiy } 2443ada6b11SAlexey Kardashevskiy break; 2453ada6b11SAlexey Kardashevskiy } 2463ada6b11SAlexey Kardashevskiy 2473ada6b11SAlexey Kardashevskiy rtas_st(rets, 0, ret); 2483ada6b11SAlexey Kardashevskiy } 2493ada6b11SAlexey Kardashevskiy 2503ada6b11SAlexey Kardashevskiy static void rtas_ibm_set_system_parameter(PowerPCCPU *cpu, 2513ada6b11SAlexey Kardashevskiy sPAPREnvironment *spapr, 2523ada6b11SAlexey Kardashevskiy uint32_t token, uint32_t nargs, 2533ada6b11SAlexey Kardashevskiy target_ulong args, 2543ada6b11SAlexey Kardashevskiy uint32_t nret, target_ulong rets) 2553ada6b11SAlexey Kardashevskiy { 2563ada6b11SAlexey Kardashevskiy target_ulong parameter = rtas_ld(args, 0); 2573ada6b11SAlexey Kardashevskiy target_ulong ret = RTAS_OUT_NOT_SUPPORTED; 2583ada6b11SAlexey Kardashevskiy 2593ada6b11SAlexey Kardashevskiy switch (parameter) { 2603ada6b11SAlexey Kardashevskiy case DIAGNOSTICS_RUN_MODE: 2613ada6b11SAlexey Kardashevskiy ret = RTAS_OUT_NOT_AUTHORIZED; 2623ada6b11SAlexey Kardashevskiy break; 2633ada6b11SAlexey Kardashevskiy } 2643ada6b11SAlexey Kardashevskiy 2653ada6b11SAlexey Kardashevskiy rtas_st(rets, 0, ret); 2663ada6b11SAlexey Kardashevskiy } 2673ada6b11SAlexey Kardashevskiy 26839ac8455SDavid Gibson static struct rtas_call { 26939ac8455SDavid Gibson const char *name; 27039ac8455SDavid Gibson spapr_rtas_fn fn; 271*3a3b8502SAlexey Kardashevskiy } rtas_table[RTAS_TOKEN_MAX - RTAS_TOKEN_BASE]; 27239ac8455SDavid Gibson 273210b580bSAnthony Liguori target_ulong spapr_rtas_call(PowerPCCPU *cpu, sPAPREnvironment *spapr, 27439ac8455SDavid Gibson uint32_t token, uint32_t nargs, target_ulong args, 27539ac8455SDavid Gibson uint32_t nret, target_ulong rets) 27639ac8455SDavid Gibson { 277*3a3b8502SAlexey Kardashevskiy if ((token >= RTAS_TOKEN_BASE) && (token < RTAS_TOKEN_MAX)) { 278*3a3b8502SAlexey Kardashevskiy struct rtas_call *call = rtas_table + (token - RTAS_TOKEN_BASE); 27939ac8455SDavid Gibson 28039ac8455SDavid Gibson if (call->fn) { 281210b580bSAnthony Liguori call->fn(cpu, spapr, token, nargs, args, nret, rets); 28239ac8455SDavid Gibson return H_SUCCESS; 28339ac8455SDavid Gibson } 28439ac8455SDavid Gibson } 28539ac8455SDavid Gibson 286821303f5SDavid Gibson /* HACK: Some Linux early debug code uses RTAS display-character, 287821303f5SDavid Gibson * but assumes the token value is 0xa (which it is on some real 288821303f5SDavid Gibson * machines) without looking it up in the device tree. This 289821303f5SDavid Gibson * special case makes this work */ 290821303f5SDavid Gibson if (token == 0xa) { 291210b580bSAnthony Liguori rtas_display_character(cpu, spapr, 0xa, nargs, args, nret, rets); 292821303f5SDavid Gibson return H_SUCCESS; 293821303f5SDavid Gibson } 294821303f5SDavid Gibson 29539ac8455SDavid Gibson hcall_dprintf("Unknown RTAS token 0x%x\n", token); 296a64d325dSAlexey Kardashevskiy rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR); 29739ac8455SDavid Gibson return H_PARAMETER; 29839ac8455SDavid Gibson } 29939ac8455SDavid Gibson 300*3a3b8502SAlexey Kardashevskiy void spapr_rtas_register(int token, const char *name, spapr_rtas_fn fn) 30139ac8455SDavid Gibson { 302*3a3b8502SAlexey Kardashevskiy if (!((token >= RTAS_TOKEN_BASE) && (token < RTAS_TOKEN_MAX))) { 303*3a3b8502SAlexey Kardashevskiy fprintf(stderr, "RTAS invalid token 0x%x\n", token); 304c89d5299SDavid Gibson exit(1); 305c89d5299SDavid Gibson } 306*3a3b8502SAlexey Kardashevskiy 307*3a3b8502SAlexey Kardashevskiy token -= RTAS_TOKEN_BASE; 308*3a3b8502SAlexey Kardashevskiy if (rtas_table[token].name) { 309*3a3b8502SAlexey Kardashevskiy fprintf(stderr, "RTAS call \"%s\" is registered already as 0x%x\n", 310*3a3b8502SAlexey Kardashevskiy rtas_table[token].name, token); 311*3a3b8502SAlexey Kardashevskiy exit(1); 312c89d5299SDavid Gibson } 313c89d5299SDavid Gibson 314*3a3b8502SAlexey Kardashevskiy rtas_table[token].name = name; 315*3a3b8502SAlexey Kardashevskiy rtas_table[token].fn = fn; 31639ac8455SDavid Gibson } 31739ac8455SDavid Gibson 318a8170e5eSAvi Kivity int spapr_rtas_device_tree_setup(void *fdt, hwaddr rtas_addr, 319a8170e5eSAvi Kivity hwaddr rtas_size) 32039ac8455SDavid Gibson { 32139ac8455SDavid Gibson int ret; 32239ac8455SDavid Gibson int i; 32339ac8455SDavid Gibson 32439ac8455SDavid Gibson ret = fdt_add_mem_rsv(fdt, rtas_addr, rtas_size); 32539ac8455SDavid Gibson if (ret < 0) { 32639ac8455SDavid Gibson fprintf(stderr, "Couldn't add RTAS reserve entry: %s\n", 32739ac8455SDavid Gibson fdt_strerror(ret)); 32839ac8455SDavid Gibson return ret; 32939ac8455SDavid Gibson } 33039ac8455SDavid Gibson 3315a4348d1SPeter Crosthwaite ret = qemu_fdt_setprop_cell(fdt, "/rtas", "linux,rtas-base", 33239ac8455SDavid Gibson rtas_addr); 33339ac8455SDavid Gibson if (ret < 0) { 33439ac8455SDavid Gibson fprintf(stderr, "Couldn't add linux,rtas-base property: %s\n", 33539ac8455SDavid Gibson fdt_strerror(ret)); 33639ac8455SDavid Gibson return ret; 33739ac8455SDavid Gibson } 33839ac8455SDavid Gibson 3395a4348d1SPeter Crosthwaite ret = qemu_fdt_setprop_cell(fdt, "/rtas", "linux,rtas-entry", 34039ac8455SDavid Gibson rtas_addr); 34139ac8455SDavid Gibson if (ret < 0) { 34239ac8455SDavid Gibson fprintf(stderr, "Couldn't add linux,rtas-entry property: %s\n", 34339ac8455SDavid Gibson fdt_strerror(ret)); 34439ac8455SDavid Gibson return ret; 34539ac8455SDavid Gibson } 34639ac8455SDavid Gibson 3475a4348d1SPeter Crosthwaite ret = qemu_fdt_setprop_cell(fdt, "/rtas", "rtas-size", 34839ac8455SDavid Gibson rtas_size); 34939ac8455SDavid Gibson if (ret < 0) { 35039ac8455SDavid Gibson fprintf(stderr, "Couldn't add rtas-size property: %s\n", 35139ac8455SDavid Gibson fdt_strerror(ret)); 35239ac8455SDavid Gibson return ret; 35339ac8455SDavid Gibson } 35439ac8455SDavid Gibson 355*3a3b8502SAlexey Kardashevskiy for (i = 0; i < RTAS_TOKEN_MAX - RTAS_TOKEN_BASE; i++) { 35639ac8455SDavid Gibson struct rtas_call *call = &rtas_table[i]; 35739ac8455SDavid Gibson 358d36b66f7SBen Herrenschmidt if (!call->name) { 35939ac8455SDavid Gibson continue; 36039ac8455SDavid Gibson } 36139ac8455SDavid Gibson 3625a4348d1SPeter Crosthwaite ret = qemu_fdt_setprop_cell(fdt, "/rtas", call->name, 363*3a3b8502SAlexey Kardashevskiy i + RTAS_TOKEN_BASE); 36439ac8455SDavid Gibson if (ret < 0) { 36539ac8455SDavid Gibson fprintf(stderr, "Couldn't add rtas token for %s: %s\n", 36639ac8455SDavid Gibson call->name, fdt_strerror(ret)); 36739ac8455SDavid Gibson return ret; 36839ac8455SDavid Gibson } 36939ac8455SDavid Gibson 37039ac8455SDavid Gibson } 37139ac8455SDavid Gibson return 0; 37239ac8455SDavid Gibson } 373821303f5SDavid Gibson 37483f7d43aSAndreas Färber static void core_rtas_register_types(void) 375821303f5SDavid Gibson { 376*3a3b8502SAlexey Kardashevskiy spapr_rtas_register(RTAS_DISPLAY_CHARACTER, "display-character", 377*3a3b8502SAlexey Kardashevskiy rtas_display_character); 378*3a3b8502SAlexey Kardashevskiy spapr_rtas_register(RTAS_GET_TIME_OF_DAY, "get-time-of-day", 379*3a3b8502SAlexey Kardashevskiy rtas_get_time_of_day); 380*3a3b8502SAlexey Kardashevskiy spapr_rtas_register(RTAS_SET_TIME_OF_DAY, "set-time-of-day", 381*3a3b8502SAlexey Kardashevskiy rtas_set_time_of_day); 382*3a3b8502SAlexey Kardashevskiy spapr_rtas_register(RTAS_POWER_OFF, "power-off", rtas_power_off); 383*3a3b8502SAlexey Kardashevskiy spapr_rtas_register(RTAS_SYSTEM_REBOOT, "system-reboot", 384*3a3b8502SAlexey Kardashevskiy rtas_system_reboot); 385*3a3b8502SAlexey Kardashevskiy spapr_rtas_register(RTAS_QUERY_CPU_STOPPED_STATE, "query-cpu-stopped-state", 386a9f8ad8fSDavid Gibson rtas_query_cpu_stopped_state); 387*3a3b8502SAlexey Kardashevskiy spapr_rtas_register(RTAS_START_CPU, "start-cpu", rtas_start_cpu); 388*3a3b8502SAlexey Kardashevskiy spapr_rtas_register(RTAS_STOP_SELF, "stop-self", rtas_stop_self); 389*3a3b8502SAlexey Kardashevskiy spapr_rtas_register(RTAS_IBM_GET_SYSTEM_PARAMETER, 390*3a3b8502SAlexey Kardashevskiy "ibm,get-system-parameter", 3913ada6b11SAlexey Kardashevskiy rtas_ibm_get_system_parameter); 392*3a3b8502SAlexey Kardashevskiy spapr_rtas_register(RTAS_IBM_SET_SYSTEM_PARAMETER, 393*3a3b8502SAlexey Kardashevskiy "ibm,set-system-parameter", 3943ada6b11SAlexey Kardashevskiy rtas_ibm_set_system_parameter); 395821303f5SDavid Gibson } 39683f7d43aSAndreas Färber 39783f7d43aSAndreas Färber type_init(core_rtas_register_types) 398