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 static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu, 2263ada6b11SAlexey Kardashevskiy sPAPREnvironment *spapr, 2273ada6b11SAlexey Kardashevskiy uint32_t token, uint32_t nargs, 2283ada6b11SAlexey Kardashevskiy target_ulong args, 2293ada6b11SAlexey Kardashevskiy uint32_t nret, target_ulong rets) 2303ada6b11SAlexey Kardashevskiy { 2313ada6b11SAlexey Kardashevskiy target_ulong parameter = rtas_ld(args, 0); 2323ada6b11SAlexey Kardashevskiy target_ulong buffer = rtas_ld(args, 1); 2333ada6b11SAlexey Kardashevskiy target_ulong length = rtas_ld(args, 2); 2343052d951SSam bobroff target_ulong ret = RTAS_OUT_SUCCESS; 2353ada6b11SAlexey Kardashevskiy 2363ada6b11SAlexey Kardashevskiy switch (parameter) { 2373052d951SSam bobroff case RTAS_SYSPARM_DIAGNOSTICS_RUN_MODE: { 2383052d951SSam bobroff uint8_t param_val = DIAGNOSTICS_RUN_MODE_DISABLED; 2393052d951SSam bobroff 2403052d951SSam bobroff rtas_st_buffer(buffer, length, ¶m_val, sizeof(param_val)); 2413ada6b11SAlexey Kardashevskiy break; 2423ada6b11SAlexey Kardashevskiy } 243*b907d7b0SSam bobroff case RTAS_SYSPARM_UUID: 244*b907d7b0SSam bobroff rtas_st_buffer(buffer, length, qemu_uuid, (qemu_uuid_set ? 16 : 0)); 245*b907d7b0SSam bobroff break; 2463052d951SSam bobroff default: 2473052d951SSam bobroff ret = RTAS_OUT_NOT_SUPPORTED; 2483052d951SSam bobroff } 2493ada6b11SAlexey Kardashevskiy 2503ada6b11SAlexey Kardashevskiy rtas_st(rets, 0, ret); 2513ada6b11SAlexey Kardashevskiy } 2523ada6b11SAlexey Kardashevskiy 2533ada6b11SAlexey Kardashevskiy static void rtas_ibm_set_system_parameter(PowerPCCPU *cpu, 2543ada6b11SAlexey Kardashevskiy sPAPREnvironment *spapr, 2553ada6b11SAlexey Kardashevskiy uint32_t token, uint32_t nargs, 2563ada6b11SAlexey Kardashevskiy target_ulong args, 2573ada6b11SAlexey Kardashevskiy uint32_t nret, target_ulong rets) 2583ada6b11SAlexey Kardashevskiy { 2593ada6b11SAlexey Kardashevskiy target_ulong parameter = rtas_ld(args, 0); 2603ada6b11SAlexey Kardashevskiy target_ulong ret = RTAS_OUT_NOT_SUPPORTED; 2613ada6b11SAlexey Kardashevskiy 2623ada6b11SAlexey Kardashevskiy switch (parameter) { 2633052d951SSam bobroff case RTAS_SYSPARM_DIAGNOSTICS_RUN_MODE: 264*b907d7b0SSam bobroff case RTAS_SYSPARM_UUID: 2653ada6b11SAlexey Kardashevskiy ret = RTAS_OUT_NOT_AUTHORIZED; 2663ada6b11SAlexey Kardashevskiy break; 2673ada6b11SAlexey Kardashevskiy } 2683ada6b11SAlexey Kardashevskiy 2693ada6b11SAlexey Kardashevskiy rtas_st(rets, 0, ret); 2703ada6b11SAlexey Kardashevskiy } 2713ada6b11SAlexey Kardashevskiy 27239ac8455SDavid Gibson static struct rtas_call { 27339ac8455SDavid Gibson const char *name; 27439ac8455SDavid Gibson spapr_rtas_fn fn; 2753a3b8502SAlexey Kardashevskiy } rtas_table[RTAS_TOKEN_MAX - RTAS_TOKEN_BASE]; 27639ac8455SDavid Gibson 277210b580bSAnthony Liguori target_ulong spapr_rtas_call(PowerPCCPU *cpu, sPAPREnvironment *spapr, 27839ac8455SDavid Gibson uint32_t token, uint32_t nargs, target_ulong args, 27939ac8455SDavid Gibson uint32_t nret, target_ulong rets) 28039ac8455SDavid Gibson { 2813a3b8502SAlexey Kardashevskiy if ((token >= RTAS_TOKEN_BASE) && (token < RTAS_TOKEN_MAX)) { 2823a3b8502SAlexey Kardashevskiy struct rtas_call *call = rtas_table + (token - RTAS_TOKEN_BASE); 28339ac8455SDavid Gibson 28439ac8455SDavid Gibson if (call->fn) { 285210b580bSAnthony Liguori call->fn(cpu, spapr, token, nargs, args, nret, rets); 28639ac8455SDavid Gibson return H_SUCCESS; 28739ac8455SDavid Gibson } 28839ac8455SDavid Gibson } 28939ac8455SDavid Gibson 290821303f5SDavid Gibson /* HACK: Some Linux early debug code uses RTAS display-character, 291821303f5SDavid Gibson * but assumes the token value is 0xa (which it is on some real 292821303f5SDavid Gibson * machines) without looking it up in the device tree. This 293821303f5SDavid Gibson * special case makes this work */ 294821303f5SDavid Gibson if (token == 0xa) { 295210b580bSAnthony Liguori rtas_display_character(cpu, spapr, 0xa, nargs, args, nret, rets); 296821303f5SDavid Gibson return H_SUCCESS; 297821303f5SDavid Gibson } 298821303f5SDavid Gibson 29939ac8455SDavid Gibson hcall_dprintf("Unknown RTAS token 0x%x\n", token); 300a64d325dSAlexey Kardashevskiy rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR); 30139ac8455SDavid Gibson return H_PARAMETER; 30239ac8455SDavid Gibson } 30339ac8455SDavid Gibson 3043a3b8502SAlexey Kardashevskiy void spapr_rtas_register(int token, const char *name, spapr_rtas_fn fn) 30539ac8455SDavid Gibson { 3063a3b8502SAlexey Kardashevskiy if (!((token >= RTAS_TOKEN_BASE) && (token < RTAS_TOKEN_MAX))) { 3073a3b8502SAlexey Kardashevskiy fprintf(stderr, "RTAS invalid token 0x%x\n", token); 308c89d5299SDavid Gibson exit(1); 309c89d5299SDavid Gibson } 3103a3b8502SAlexey Kardashevskiy 3113a3b8502SAlexey Kardashevskiy token -= RTAS_TOKEN_BASE; 3123a3b8502SAlexey Kardashevskiy if (rtas_table[token].name) { 3133a3b8502SAlexey Kardashevskiy fprintf(stderr, "RTAS call \"%s\" is registered already as 0x%x\n", 3143a3b8502SAlexey Kardashevskiy rtas_table[token].name, token); 3153a3b8502SAlexey Kardashevskiy exit(1); 316c89d5299SDavid Gibson } 317c89d5299SDavid Gibson 3183a3b8502SAlexey Kardashevskiy rtas_table[token].name = name; 3193a3b8502SAlexey Kardashevskiy rtas_table[token].fn = fn; 32039ac8455SDavid Gibson } 32139ac8455SDavid Gibson 322a8170e5eSAvi Kivity int spapr_rtas_device_tree_setup(void *fdt, hwaddr rtas_addr, 323a8170e5eSAvi Kivity hwaddr rtas_size) 32439ac8455SDavid Gibson { 32539ac8455SDavid Gibson int ret; 32639ac8455SDavid Gibson int i; 32739ac8455SDavid Gibson 32839ac8455SDavid Gibson ret = fdt_add_mem_rsv(fdt, rtas_addr, rtas_size); 32939ac8455SDavid Gibson if (ret < 0) { 33039ac8455SDavid Gibson fprintf(stderr, "Couldn't add RTAS reserve entry: %s\n", 33139ac8455SDavid Gibson fdt_strerror(ret)); 33239ac8455SDavid Gibson return ret; 33339ac8455SDavid Gibson } 33439ac8455SDavid Gibson 3355a4348d1SPeter Crosthwaite ret = qemu_fdt_setprop_cell(fdt, "/rtas", "linux,rtas-base", 33639ac8455SDavid Gibson rtas_addr); 33739ac8455SDavid Gibson if (ret < 0) { 33839ac8455SDavid Gibson fprintf(stderr, "Couldn't add linux,rtas-base property: %s\n", 33939ac8455SDavid Gibson fdt_strerror(ret)); 34039ac8455SDavid Gibson return ret; 34139ac8455SDavid Gibson } 34239ac8455SDavid Gibson 3435a4348d1SPeter Crosthwaite ret = qemu_fdt_setprop_cell(fdt, "/rtas", "linux,rtas-entry", 34439ac8455SDavid Gibson rtas_addr); 34539ac8455SDavid Gibson if (ret < 0) { 34639ac8455SDavid Gibson fprintf(stderr, "Couldn't add linux,rtas-entry property: %s\n", 34739ac8455SDavid Gibson fdt_strerror(ret)); 34839ac8455SDavid Gibson return ret; 34939ac8455SDavid Gibson } 35039ac8455SDavid Gibson 3515a4348d1SPeter Crosthwaite ret = qemu_fdt_setprop_cell(fdt, "/rtas", "rtas-size", 35239ac8455SDavid Gibson rtas_size); 35339ac8455SDavid Gibson if (ret < 0) { 35439ac8455SDavid Gibson fprintf(stderr, "Couldn't add rtas-size property: %s\n", 35539ac8455SDavid Gibson fdt_strerror(ret)); 35639ac8455SDavid Gibson return ret; 35739ac8455SDavid Gibson } 35839ac8455SDavid Gibson 3593a3b8502SAlexey Kardashevskiy for (i = 0; i < RTAS_TOKEN_MAX - RTAS_TOKEN_BASE; i++) { 36039ac8455SDavid Gibson struct rtas_call *call = &rtas_table[i]; 36139ac8455SDavid Gibson 362d36b66f7SBen Herrenschmidt if (!call->name) { 36339ac8455SDavid Gibson continue; 36439ac8455SDavid Gibson } 36539ac8455SDavid Gibson 3665a4348d1SPeter Crosthwaite ret = qemu_fdt_setprop_cell(fdt, "/rtas", call->name, 3673a3b8502SAlexey Kardashevskiy i + RTAS_TOKEN_BASE); 36839ac8455SDavid Gibson if (ret < 0) { 36939ac8455SDavid Gibson fprintf(stderr, "Couldn't add rtas token for %s: %s\n", 37039ac8455SDavid Gibson call->name, fdt_strerror(ret)); 37139ac8455SDavid Gibson return ret; 37239ac8455SDavid Gibson } 37339ac8455SDavid Gibson 37439ac8455SDavid Gibson } 37539ac8455SDavid Gibson return 0; 37639ac8455SDavid Gibson } 377821303f5SDavid Gibson 37883f7d43aSAndreas Färber static void core_rtas_register_types(void) 379821303f5SDavid Gibson { 3803a3b8502SAlexey Kardashevskiy spapr_rtas_register(RTAS_DISPLAY_CHARACTER, "display-character", 3813a3b8502SAlexey Kardashevskiy rtas_display_character); 3823a3b8502SAlexey Kardashevskiy spapr_rtas_register(RTAS_GET_TIME_OF_DAY, "get-time-of-day", 3833a3b8502SAlexey Kardashevskiy rtas_get_time_of_day); 3843a3b8502SAlexey Kardashevskiy spapr_rtas_register(RTAS_SET_TIME_OF_DAY, "set-time-of-day", 3853a3b8502SAlexey Kardashevskiy rtas_set_time_of_day); 3863a3b8502SAlexey Kardashevskiy spapr_rtas_register(RTAS_POWER_OFF, "power-off", rtas_power_off); 3873a3b8502SAlexey Kardashevskiy spapr_rtas_register(RTAS_SYSTEM_REBOOT, "system-reboot", 3883a3b8502SAlexey Kardashevskiy rtas_system_reboot); 3893a3b8502SAlexey Kardashevskiy spapr_rtas_register(RTAS_QUERY_CPU_STOPPED_STATE, "query-cpu-stopped-state", 390a9f8ad8fSDavid Gibson rtas_query_cpu_stopped_state); 3913a3b8502SAlexey Kardashevskiy spapr_rtas_register(RTAS_START_CPU, "start-cpu", rtas_start_cpu); 3923a3b8502SAlexey Kardashevskiy spapr_rtas_register(RTAS_STOP_SELF, "stop-self", rtas_stop_self); 3933a3b8502SAlexey Kardashevskiy spapr_rtas_register(RTAS_IBM_GET_SYSTEM_PARAMETER, 3943a3b8502SAlexey Kardashevskiy "ibm,get-system-parameter", 3953ada6b11SAlexey Kardashevskiy rtas_ibm_get_system_parameter); 3963a3b8502SAlexey Kardashevskiy spapr_rtas_register(RTAS_IBM_SET_SYSTEM_PARAMETER, 3973a3b8502SAlexey Kardashevskiy "ibm,set-system-parameter", 3983ada6b11SAlexey Kardashevskiy rtas_ibm_set_system_parameter); 399821303f5SDavid Gibson } 40083f7d43aSAndreas Färber 40183f7d43aSAndreas Färber type_init(core_rtas_register_types) 402