xref: /qemu/hw/ppc/spapr_rtas.c (revision e6fc9568c865f2f81499475a4e322cd563fdfd90)
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"
32db4ef288SBharata B Rao #include "sysemu/cpus.h"
3339ac8455SDavid Gibson 
340d09e41aSPaolo Bonzini #include "hw/ppc/spapr.h"
350d09e41aSPaolo Bonzini #include "hw/ppc/spapr_vio.h"
36e010ad8fSWenchao Xia #include "qapi-event.h"
37e3943228SSam Bobroff #include "hw/boards.h"
3839ac8455SDavid Gibson 
3939ac8455SDavid Gibson #include <libfdt.h>
408c8639dfSMike Day #include "hw/ppc/spapr_drc.h"
418c8639dfSMike Day 
428c8639dfSMike Day /* #define DEBUG_SPAPR */
438c8639dfSMike Day 
448c8639dfSMike Day #ifdef DEBUG_SPAPR
458c8639dfSMike Day #define DPRINTF(fmt, ...) \
468c8639dfSMike Day     do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
478c8639dfSMike Day #else
488c8639dfSMike Day #define DPRINTF(fmt, ...) \
498c8639dfSMike Day     do { } while (0)
508c8639dfSMike Day #endif
518c8639dfSMike Day 
5228e02042SDavid Gibson static sPAPRConfigureConnectorState *spapr_ccs_find(sPAPRMachineState *spapr,
5346503c2bSMichael Roth                                                     uint32_t drc_index)
5446503c2bSMichael Roth {
5546503c2bSMichael Roth     sPAPRConfigureConnectorState *ccs = NULL;
5646503c2bSMichael Roth 
5746503c2bSMichael Roth     QTAILQ_FOREACH(ccs, &spapr->ccs_list, next) {
5846503c2bSMichael Roth         if (ccs->drc_index == drc_index) {
5946503c2bSMichael Roth             break;
6046503c2bSMichael Roth         }
6146503c2bSMichael Roth     }
6246503c2bSMichael Roth 
6346503c2bSMichael Roth     return ccs;
6446503c2bSMichael Roth }
6546503c2bSMichael Roth 
6628e02042SDavid Gibson static void spapr_ccs_add(sPAPRMachineState *spapr,
6746503c2bSMichael Roth                           sPAPRConfigureConnectorState *ccs)
6846503c2bSMichael Roth {
6946503c2bSMichael Roth     g_assert(!spapr_ccs_find(spapr, ccs->drc_index));
7046503c2bSMichael Roth     QTAILQ_INSERT_HEAD(&spapr->ccs_list, ccs, next);
7146503c2bSMichael Roth }
7246503c2bSMichael Roth 
7328e02042SDavid Gibson static void spapr_ccs_remove(sPAPRMachineState *spapr,
7446503c2bSMichael Roth                              sPAPRConfigureConnectorState *ccs)
7546503c2bSMichael Roth {
7646503c2bSMichael Roth     QTAILQ_REMOVE(&spapr->ccs_list, ccs, next);
7746503c2bSMichael Roth     g_free(ccs);
7846503c2bSMichael Roth }
7946503c2bSMichael Roth 
8046503c2bSMichael Roth void spapr_ccs_reset_hook(void *opaque)
8146503c2bSMichael Roth {
8228e02042SDavid Gibson     sPAPRMachineState *spapr = opaque;
8346503c2bSMichael Roth     sPAPRConfigureConnectorState *ccs, *ccs_tmp;
8446503c2bSMichael Roth 
8546503c2bSMichael Roth     QTAILQ_FOREACH_SAFE(ccs, &spapr->ccs_list, next, ccs_tmp) {
8646503c2bSMichael Roth         spapr_ccs_remove(spapr, ccs);
8746503c2bSMichael Roth     }
8846503c2bSMichael Roth }
8939ac8455SDavid Gibson 
9028e02042SDavid Gibson static void rtas_display_character(PowerPCCPU *cpu, sPAPRMachineState *spapr,
91821303f5SDavid Gibson                                    uint32_t token, uint32_t nargs,
92821303f5SDavid Gibson                                    target_ulong args,
93821303f5SDavid Gibson                                    uint32_t nret, target_ulong rets)
94821303f5SDavid Gibson {
95821303f5SDavid Gibson     uint8_t c = rtas_ld(args, 0);
965f2e2ba2SDavid Gibson     VIOsPAPRDevice *sdev = vty_lookup(spapr, 0);
97821303f5SDavid Gibson 
98821303f5SDavid Gibson     if (!sdev) {
99a64d325dSAlexey Kardashevskiy         rtas_st(rets, 0, RTAS_OUT_HW_ERROR);
100821303f5SDavid Gibson     } else {
101821303f5SDavid Gibson         vty_putchars(sdev, &c, sizeof(c));
102a64d325dSAlexey Kardashevskiy         rtas_st(rets, 0, RTAS_OUT_SUCCESS);
103821303f5SDavid Gibson     }
104821303f5SDavid Gibson }
105821303f5SDavid Gibson 
10628e02042SDavid Gibson static void rtas_power_off(PowerPCCPU *cpu, sPAPRMachineState *spapr,
107821303f5SDavid Gibson                            uint32_t token, uint32_t nargs, target_ulong args,
108821303f5SDavid Gibson                            uint32_t nret, target_ulong rets)
109821303f5SDavid Gibson {
110821303f5SDavid Gibson     if (nargs != 2 || nret != 1) {
111a64d325dSAlexey Kardashevskiy         rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
112821303f5SDavid Gibson         return;
113821303f5SDavid Gibson     }
114821303f5SDavid Gibson     qemu_system_shutdown_request();
115a64d325dSAlexey Kardashevskiy     rtas_st(rets, 0, RTAS_OUT_SUCCESS);
116821303f5SDavid Gibson }
117821303f5SDavid Gibson 
11828e02042SDavid Gibson static void rtas_system_reboot(PowerPCCPU *cpu, sPAPRMachineState *spapr,
119c821a43cSDavid Gibson                                uint32_t token, uint32_t nargs,
120c821a43cSDavid Gibson                                target_ulong args,
121c821a43cSDavid Gibson                                uint32_t nret, target_ulong rets)
122c821a43cSDavid Gibson {
123c821a43cSDavid Gibson     if (nargs != 0 || nret != 1) {
124a64d325dSAlexey Kardashevskiy         rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
125c821a43cSDavid Gibson         return;
126c821a43cSDavid Gibson     }
127c821a43cSDavid Gibson     qemu_system_reset_request();
128a64d325dSAlexey Kardashevskiy     rtas_st(rets, 0, RTAS_OUT_SUCCESS);
129c821a43cSDavid Gibson }
130c821a43cSDavid Gibson 
131210b580bSAnthony Liguori static void rtas_query_cpu_stopped_state(PowerPCCPU *cpu_,
13228e02042SDavid Gibson                                          sPAPRMachineState *spapr,
133a9f8ad8fSDavid Gibson                                          uint32_t token, uint32_t nargs,
134a9f8ad8fSDavid Gibson                                          target_ulong args,
135a9f8ad8fSDavid Gibson                                          uint32_t nret, target_ulong rets)
136a9f8ad8fSDavid Gibson {
137a9f8ad8fSDavid Gibson     target_ulong id;
1380f20ba62SAlexey Kardashevskiy     PowerPCCPU *cpu;
139a9f8ad8fSDavid Gibson 
140a9f8ad8fSDavid Gibson     if (nargs != 1 || nret != 2) {
141a64d325dSAlexey Kardashevskiy         rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
142a9f8ad8fSDavid Gibson         return;
143a9f8ad8fSDavid Gibson     }
144a9f8ad8fSDavid Gibson 
145a9f8ad8fSDavid Gibson     id = rtas_ld(args, 0);
1460f20ba62SAlexey Kardashevskiy     cpu = ppc_get_vcpu_by_dt_id(id);
14705318a85SAndreas Färber     if (cpu != NULL) {
1480f20ba62SAlexey Kardashevskiy         if (CPU(cpu)->halted) {
149a9f8ad8fSDavid Gibson             rtas_st(rets, 1, 0);
150a9f8ad8fSDavid Gibson         } else {
151a9f8ad8fSDavid Gibson             rtas_st(rets, 1, 2);
152a9f8ad8fSDavid Gibson         }
153a9f8ad8fSDavid Gibson 
154a64d325dSAlexey Kardashevskiy         rtas_st(rets, 0, RTAS_OUT_SUCCESS);
155a9f8ad8fSDavid Gibson         return;
156a9f8ad8fSDavid Gibson     }
157a9f8ad8fSDavid Gibson 
158a9f8ad8fSDavid Gibson     /* Didn't find a matching cpu */
159a64d325dSAlexey Kardashevskiy     rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
160a9f8ad8fSDavid Gibson }
161a9f8ad8fSDavid Gibson 
16228e02042SDavid Gibson static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr,
163a9f8ad8fSDavid Gibson                            uint32_t token, uint32_t nargs,
164a9f8ad8fSDavid Gibson                            target_ulong args,
165a9f8ad8fSDavid Gibson                            uint32_t nret, target_ulong rets)
166a9f8ad8fSDavid Gibson {
167a9f8ad8fSDavid Gibson     target_ulong id, start, r3;
1680f20ba62SAlexey Kardashevskiy     PowerPCCPU *cpu;
169a9f8ad8fSDavid Gibson 
170a9f8ad8fSDavid Gibson     if (nargs != 3 || nret != 1) {
171a64d325dSAlexey Kardashevskiy         rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
172a9f8ad8fSDavid Gibson         return;
173a9f8ad8fSDavid Gibson     }
174a9f8ad8fSDavid Gibson 
175a9f8ad8fSDavid Gibson     id = rtas_ld(args, 0);
176a9f8ad8fSDavid Gibson     start = rtas_ld(args, 1);
177a9f8ad8fSDavid Gibson     r3 = rtas_ld(args, 2);
178a9f8ad8fSDavid Gibson 
1790f20ba62SAlexey Kardashevskiy     cpu = ppc_get_vcpu_by_dt_id(id);
1800f20ba62SAlexey Kardashevskiy     if (cpu != NULL) {
1810f20ba62SAlexey Kardashevskiy         CPUState *cs = CPU(cpu);
182c67e216bSAndreas Färber         CPUPPCState *env = &cpu->env;
183c08d7424SAndreas Färber 
184c67e216bSAndreas Färber         if (!cs->halted) {
185a64d325dSAlexey Kardashevskiy             rtas_st(rets, 0, RTAS_OUT_HW_ERROR);
186a9f8ad8fSDavid Gibson             return;
187a9f8ad8fSDavid Gibson         }
188a9f8ad8fSDavid Gibson 
189048706d9SDavid Gibson         /* This will make sure qemu state is up to date with kvm, and
190048706d9SDavid Gibson          * mark it dirty so our changes get flushed back before the
191048706d9SDavid Gibson          * new cpu enters */
192dd1750d7SAndreas Färber         kvm_cpu_synchronize_state(cs);
193048706d9SDavid Gibson 
194a9f8ad8fSDavid Gibson         env->msr = (1ULL << MSR_SF) | (1ULL << MSR_ME);
195a9f8ad8fSDavid Gibson         env->nip = start;
196a9f8ad8fSDavid Gibson         env->gpr[3] = r3;
197c67e216bSAndreas Färber         cs->halted = 0;
198a9f8ad8fSDavid Gibson 
199c67e216bSAndreas Färber         qemu_cpu_kick(cs);
200a9f8ad8fSDavid Gibson 
201a64d325dSAlexey Kardashevskiy         rtas_st(rets, 0, RTAS_OUT_SUCCESS);
202a9f8ad8fSDavid Gibson         return;
203a9f8ad8fSDavid Gibson     }
204a9f8ad8fSDavid Gibson 
205a9f8ad8fSDavid Gibson     /* Didn't find a matching cpu */
206a64d325dSAlexey Kardashevskiy     rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
207a9f8ad8fSDavid Gibson }
208a9f8ad8fSDavid Gibson 
20928e02042SDavid Gibson static void rtas_stop_self(PowerPCCPU *cpu, sPAPRMachineState *spapr,
21059760f2dSAlexey Kardashevskiy                            uint32_t token, uint32_t nargs,
21159760f2dSAlexey Kardashevskiy                            target_ulong args,
21259760f2dSAlexey Kardashevskiy                            uint32_t nret, target_ulong rets)
21359760f2dSAlexey Kardashevskiy {
21459760f2dSAlexey Kardashevskiy     CPUState *cs = CPU(cpu);
21559760f2dSAlexey Kardashevskiy     CPUPPCState *env = &cpu->env;
21659760f2dSAlexey Kardashevskiy 
21759760f2dSAlexey Kardashevskiy     cs->halted = 1;
2189102dedaSPaolo Bonzini     qemu_cpu_kick(cs);
21959760f2dSAlexey Kardashevskiy     /*
22059760f2dSAlexey Kardashevskiy      * While stopping a CPU, the guest calls H_CPPR which
22159760f2dSAlexey Kardashevskiy      * effectively disables interrupts on XICS level.
22259760f2dSAlexey Kardashevskiy      * However decrementer interrupts in TCG can still
22359760f2dSAlexey Kardashevskiy      * wake the CPU up so here we disable interrupts in MSR
22459760f2dSAlexey Kardashevskiy      * as well.
22559760f2dSAlexey Kardashevskiy      * As rtas_start_cpu() resets the whole MSR anyway, there is
22659760f2dSAlexey Kardashevskiy      * no need to bother with specific bits, we just clear it.
22759760f2dSAlexey Kardashevskiy      */
22859760f2dSAlexey Kardashevskiy     env->msr = 0;
22959760f2dSAlexey Kardashevskiy }
23059760f2dSAlexey Kardashevskiy 
2313ada6b11SAlexey Kardashevskiy static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu,
23228e02042SDavid Gibson                                           sPAPRMachineState *spapr,
2333ada6b11SAlexey Kardashevskiy                                           uint32_t token, uint32_t nargs,
2343ada6b11SAlexey Kardashevskiy                                           target_ulong args,
2353ada6b11SAlexey Kardashevskiy                                           uint32_t nret, target_ulong rets)
2363ada6b11SAlexey Kardashevskiy {
2373ada6b11SAlexey Kardashevskiy     target_ulong parameter = rtas_ld(args, 0);
2383ada6b11SAlexey Kardashevskiy     target_ulong buffer = rtas_ld(args, 1);
2393ada6b11SAlexey Kardashevskiy     target_ulong length = rtas_ld(args, 2);
2403052d951SSam bobroff     target_ulong ret = RTAS_OUT_SUCCESS;
2413ada6b11SAlexey Kardashevskiy 
2423ada6b11SAlexey Kardashevskiy     switch (parameter) {
2433b50d897SSam bobroff     case RTAS_SYSPARM_SPLPAR_CHARACTERISTICS: {
244e3943228SSam Bobroff         char *param_val = g_strdup_printf("MaxEntCap=%d,"
245e3943228SSam Bobroff                                           "DesMem=%llu,"
246e3943228SSam Bobroff                                           "DesProcs=%d,"
247e3943228SSam Bobroff                                           "MaxPlatProcs=%d",
248e3943228SSam Bobroff                                           max_cpus,
249e3943228SSam Bobroff                                           current_machine->ram_size / M_BYTE,
250e3943228SSam Bobroff                                           smp_cpus,
251e3943228SSam Bobroff                                           max_cpus);
2523b50d897SSam bobroff         rtas_st_buffer(buffer, length, (uint8_t *)param_val, strlen(param_val));
2533b50d897SSam bobroff         g_free(param_val);
2543b50d897SSam bobroff         break;
2553b50d897SSam bobroff     }
2563052d951SSam bobroff     case RTAS_SYSPARM_DIAGNOSTICS_RUN_MODE: {
2573052d951SSam bobroff         uint8_t param_val = DIAGNOSTICS_RUN_MODE_DISABLED;
2583052d951SSam bobroff 
2593052d951SSam bobroff         rtas_st_buffer(buffer, length, &param_val, sizeof(param_val));
2603ada6b11SAlexey Kardashevskiy         break;
2613ada6b11SAlexey Kardashevskiy     }
262b907d7b0SSam bobroff     case RTAS_SYSPARM_UUID:
263b907d7b0SSam bobroff         rtas_st_buffer(buffer, length, qemu_uuid, (qemu_uuid_set ? 16 : 0));
264b907d7b0SSam bobroff         break;
2653052d951SSam bobroff     default:
2663052d951SSam bobroff         ret = RTAS_OUT_NOT_SUPPORTED;
2673052d951SSam bobroff     }
2683ada6b11SAlexey Kardashevskiy 
2693ada6b11SAlexey Kardashevskiy     rtas_st(rets, 0, ret);
2703ada6b11SAlexey Kardashevskiy }
2713ada6b11SAlexey Kardashevskiy 
2723ada6b11SAlexey Kardashevskiy static void rtas_ibm_set_system_parameter(PowerPCCPU *cpu,
27328e02042SDavid Gibson                                           sPAPRMachineState *spapr,
2743ada6b11SAlexey Kardashevskiy                                           uint32_t token, uint32_t nargs,
2753ada6b11SAlexey Kardashevskiy                                           target_ulong args,
2763ada6b11SAlexey Kardashevskiy                                           uint32_t nret, target_ulong rets)
2773ada6b11SAlexey Kardashevskiy {
2783ada6b11SAlexey Kardashevskiy     target_ulong parameter = rtas_ld(args, 0);
2793ada6b11SAlexey Kardashevskiy     target_ulong ret = RTAS_OUT_NOT_SUPPORTED;
2803ada6b11SAlexey Kardashevskiy 
2813ada6b11SAlexey Kardashevskiy     switch (parameter) {
2823b50d897SSam bobroff     case RTAS_SYSPARM_SPLPAR_CHARACTERISTICS:
2833052d951SSam bobroff     case RTAS_SYSPARM_DIAGNOSTICS_RUN_MODE:
284b907d7b0SSam bobroff     case RTAS_SYSPARM_UUID:
2853ada6b11SAlexey Kardashevskiy         ret = RTAS_OUT_NOT_AUTHORIZED;
2863ada6b11SAlexey Kardashevskiy         break;
2873ada6b11SAlexey Kardashevskiy     }
2883ada6b11SAlexey Kardashevskiy 
2893ada6b11SAlexey Kardashevskiy     rtas_st(rets, 0, ret);
2903ada6b11SAlexey Kardashevskiy }
2913ada6b11SAlexey Kardashevskiy 
2922e14072fSNikunj A Dadhania static void rtas_ibm_os_term(PowerPCCPU *cpu,
29328e02042SDavid Gibson                             sPAPRMachineState *spapr,
2942e14072fSNikunj A Dadhania                             uint32_t token, uint32_t nargs,
2952e14072fSNikunj A Dadhania                             target_ulong args,
2962e14072fSNikunj A Dadhania                             uint32_t nret, target_ulong rets)
2972e14072fSNikunj A Dadhania {
2982e14072fSNikunj A Dadhania     target_ulong ret = 0;
2992e14072fSNikunj A Dadhania 
3002e14072fSNikunj A Dadhania     qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE, &error_abort);
3012e14072fSNikunj A Dadhania 
3022e14072fSNikunj A Dadhania     rtas_st(rets, 0, ret);
3032e14072fSNikunj A Dadhania }
3042e14072fSNikunj A Dadhania 
30528e02042SDavid Gibson static void rtas_set_power_level(PowerPCCPU *cpu, sPAPRMachineState *spapr,
306094d2058SNathan Fontenot                                  uint32_t token, uint32_t nargs,
307094d2058SNathan Fontenot                                  target_ulong args, uint32_t nret,
308094d2058SNathan Fontenot                                  target_ulong rets)
309094d2058SNathan Fontenot {
310094d2058SNathan Fontenot     int32_t power_domain;
311094d2058SNathan Fontenot 
312094d2058SNathan Fontenot     if (nargs != 2 || nret != 2) {
313094d2058SNathan Fontenot         rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
314094d2058SNathan Fontenot         return;
315094d2058SNathan Fontenot     }
316094d2058SNathan Fontenot 
317094d2058SNathan Fontenot     /* we currently only use a single, "live insert" powerdomain for
318094d2058SNathan Fontenot      * hotplugged/dlpar'd resources, so the power is always live/full (100)
319094d2058SNathan Fontenot      */
320094d2058SNathan Fontenot     power_domain = rtas_ld(args, 0);
321094d2058SNathan Fontenot     if (power_domain != -1) {
322094d2058SNathan Fontenot         rtas_st(rets, 0, RTAS_OUT_NOT_SUPPORTED);
323094d2058SNathan Fontenot         return;
324094d2058SNathan Fontenot     }
325094d2058SNathan Fontenot 
326094d2058SNathan Fontenot     rtas_st(rets, 0, RTAS_OUT_SUCCESS);
327094d2058SNathan Fontenot     rtas_st(rets, 1, 100);
328094d2058SNathan Fontenot }
329094d2058SNathan Fontenot 
33028e02042SDavid Gibson static void rtas_get_power_level(PowerPCCPU *cpu, sPAPRMachineState *spapr,
331094d2058SNathan Fontenot                                   uint32_t token, uint32_t nargs,
332094d2058SNathan Fontenot                                   target_ulong args, uint32_t nret,
333094d2058SNathan Fontenot                                   target_ulong rets)
334094d2058SNathan Fontenot {
335094d2058SNathan Fontenot     int32_t power_domain;
336094d2058SNathan Fontenot 
337094d2058SNathan Fontenot     if (nargs != 1 || nret != 2) {
338094d2058SNathan Fontenot         rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
339094d2058SNathan Fontenot         return;
340094d2058SNathan Fontenot     }
341094d2058SNathan Fontenot 
342094d2058SNathan Fontenot     /* we currently only use a single, "live insert" powerdomain for
343094d2058SNathan Fontenot      * hotplugged/dlpar'd resources, so the power is always live/full (100)
344094d2058SNathan Fontenot      */
345094d2058SNathan Fontenot     power_domain = rtas_ld(args, 0);
346094d2058SNathan Fontenot     if (power_domain != -1) {
347094d2058SNathan Fontenot         rtas_st(rets, 0, RTAS_OUT_NOT_SUPPORTED);
348094d2058SNathan Fontenot         return;
349094d2058SNathan Fontenot     }
350094d2058SNathan Fontenot 
351094d2058SNathan Fontenot     rtas_st(rets, 0, RTAS_OUT_SUCCESS);
352094d2058SNathan Fontenot     rtas_st(rets, 1, 100);
353094d2058SNathan Fontenot }
354094d2058SNathan Fontenot 
3558c8639dfSMike Day static bool sensor_type_is_dr(uint32_t sensor_type)
3568c8639dfSMike Day {
3578c8639dfSMike Day     switch (sensor_type) {
3588c8639dfSMike Day     case RTAS_SENSOR_TYPE_ISOLATION_STATE:
3598c8639dfSMike Day     case RTAS_SENSOR_TYPE_DR:
3608c8639dfSMike Day     case RTAS_SENSOR_TYPE_ALLOCATION_STATE:
3618c8639dfSMike Day         return true;
3628c8639dfSMike Day     }
3638c8639dfSMike Day 
3648c8639dfSMike Day     return false;
3658c8639dfSMike Day }
3668c8639dfSMike Day 
36728e02042SDavid Gibson static void rtas_set_indicator(PowerPCCPU *cpu, sPAPRMachineState *spapr,
3688c8639dfSMike Day                                uint32_t token, uint32_t nargs,
3698c8639dfSMike Day                                target_ulong args, uint32_t nret,
3708c8639dfSMike Day                                target_ulong rets)
3718c8639dfSMike Day {
3728c8639dfSMike Day     uint32_t sensor_type;
3738c8639dfSMike Day     uint32_t sensor_index;
3748c8639dfSMike Day     uint32_t sensor_state;
3758c8639dfSMike Day     sPAPRDRConnector *drc;
3768c8639dfSMike Day     sPAPRDRConnectorClass *drck;
3778c8639dfSMike Day 
3788c8639dfSMike Day     if (nargs != 3 || nret != 1) {
3798c8639dfSMike Day         rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
3808c8639dfSMike Day         return;
3818c8639dfSMike Day     }
3828c8639dfSMike Day 
3838c8639dfSMike Day     sensor_type = rtas_ld(args, 0);
3848c8639dfSMike Day     sensor_index = rtas_ld(args, 1);
3858c8639dfSMike Day     sensor_state = rtas_ld(args, 2);
3868c8639dfSMike Day 
3878c8639dfSMike Day     if (!sensor_type_is_dr(sensor_type)) {
3888c8639dfSMike Day         goto out_unimplemented;
3898c8639dfSMike Day     }
3908c8639dfSMike Day 
3918c8639dfSMike Day     /* if this is a DR sensor we can assume sensor_index == drc_index */
3928c8639dfSMike Day     drc = spapr_dr_connector_by_index(sensor_index);
3938c8639dfSMike Day     if (!drc) {
3948c8639dfSMike Day         DPRINTF("rtas_set_indicator: invalid sensor/DRC index: %xh\n",
3958c8639dfSMike Day                 sensor_index);
3968c8639dfSMike Day         rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
3978c8639dfSMike Day         return;
3988c8639dfSMike Day     }
3998c8639dfSMike Day     drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
4008c8639dfSMike Day 
4018c8639dfSMike Day     switch (sensor_type) {
4028c8639dfSMike Day     case RTAS_SENSOR_TYPE_ISOLATION_STATE:
40346503c2bSMichael Roth         /* if the guest is configuring a device attached to this
40446503c2bSMichael Roth          * DRC, we should reset the configuration state at this
40546503c2bSMichael Roth          * point since it may no longer be reliable (guest released
40646503c2bSMichael Roth          * device and needs to start over, or unplug occurred so
40746503c2bSMichael Roth          * the FDT is no longer valid)
40846503c2bSMichael Roth          */
40946503c2bSMichael Roth         if (sensor_state == SPAPR_DR_ISOLATION_STATE_ISOLATED) {
41046503c2bSMichael Roth             sPAPRConfigureConnectorState *ccs = spapr_ccs_find(spapr,
41146503c2bSMichael Roth                                                                sensor_index);
41246503c2bSMichael Roth             if (ccs) {
41346503c2bSMichael Roth                 spapr_ccs_remove(spapr, ccs);
41446503c2bSMichael Roth             }
41546503c2bSMichael Roth         }
4168c8639dfSMike Day         drck->set_isolation_state(drc, sensor_state);
4178c8639dfSMike Day         break;
4188c8639dfSMike Day     case RTAS_SENSOR_TYPE_DR:
4198c8639dfSMike Day         drck->set_indicator_state(drc, sensor_state);
4208c8639dfSMike Day         break;
4218c8639dfSMike Day     case RTAS_SENSOR_TYPE_ALLOCATION_STATE:
4228c8639dfSMike Day         drck->set_allocation_state(drc, sensor_state);
4238c8639dfSMike Day         break;
4248c8639dfSMike Day     default:
4258c8639dfSMike Day         goto out_unimplemented;
4268c8639dfSMike Day     }
4278c8639dfSMike Day 
4288c8639dfSMike Day     rtas_st(rets, 0, RTAS_OUT_SUCCESS);
4298c8639dfSMike Day     return;
4308c8639dfSMike Day 
4318c8639dfSMike Day out_unimplemented:
4328c8639dfSMike Day     /* currently only DR-related sensors are implemented */
4338c8639dfSMike Day     DPRINTF("rtas_set_indicator: sensor/indicator not implemented: %d\n",
4348c8639dfSMike Day             sensor_type);
4358c8639dfSMike Day     rtas_st(rets, 0, RTAS_OUT_NOT_SUPPORTED);
4368c8639dfSMike Day }
4378c8639dfSMike Day 
43828e02042SDavid Gibson static void rtas_get_sensor_state(PowerPCCPU *cpu, sPAPRMachineState *spapr,
439886445a6SMike Day                                   uint32_t token, uint32_t nargs,
440886445a6SMike Day                                   target_ulong args, uint32_t nret,
441886445a6SMike Day                                   target_ulong rets)
442886445a6SMike Day {
443886445a6SMike Day     uint32_t sensor_type;
444886445a6SMike Day     uint32_t sensor_index;
445886445a6SMike Day     sPAPRDRConnector *drc;
446886445a6SMike Day     sPAPRDRConnectorClass *drck;
447886445a6SMike Day     uint32_t entity_sense;
448886445a6SMike Day 
449886445a6SMike Day     if (nargs != 2 || nret != 2) {
450886445a6SMike Day         rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
451886445a6SMike Day         return;
452886445a6SMike Day     }
453886445a6SMike Day 
454886445a6SMike Day     sensor_type = rtas_ld(args, 0);
455886445a6SMike Day     sensor_index = rtas_ld(args, 1);
456886445a6SMike Day 
457886445a6SMike Day     if (sensor_type != RTAS_SENSOR_TYPE_ENTITY_SENSE) {
458886445a6SMike Day         /* currently only DR-related sensors are implemented */
459886445a6SMike Day         DPRINTF("rtas_get_sensor_state: sensor/indicator not implemented: %d\n",
460886445a6SMike Day                 sensor_type);
461886445a6SMike Day         rtas_st(rets, 0, RTAS_OUT_NOT_SUPPORTED);
462886445a6SMike Day         return;
463886445a6SMike Day     }
464886445a6SMike Day 
465886445a6SMike Day     drc = spapr_dr_connector_by_index(sensor_index);
466886445a6SMike Day     if (!drc) {
467886445a6SMike Day         DPRINTF("rtas_get_sensor_state: invalid sensor/DRC index: %xh\n",
468886445a6SMike Day                 sensor_index);
469886445a6SMike Day         rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
470886445a6SMike Day         return;
471886445a6SMike Day     }
472886445a6SMike Day     drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
473886445a6SMike Day     entity_sense = drck->entity_sense(drc);
474886445a6SMike Day 
475886445a6SMike Day     rtas_st(rets, 0, RTAS_OUT_SUCCESS);
476886445a6SMike Day     rtas_st(rets, 1, entity_sense);
477886445a6SMike Day }
478886445a6SMike Day 
47946503c2bSMichael Roth /* configure-connector work area offsets, int32_t units for field
48046503c2bSMichael Roth  * indexes, bytes for field offset/len values.
48146503c2bSMichael Roth  *
48246503c2bSMichael Roth  * as documented by PAPR+ v2.7, 13.5.3.5
48346503c2bSMichael Roth  */
48446503c2bSMichael Roth #define CC_IDX_NODE_NAME_OFFSET 2
48546503c2bSMichael Roth #define CC_IDX_PROP_NAME_OFFSET 2
48646503c2bSMichael Roth #define CC_IDX_PROP_LEN 3
48746503c2bSMichael Roth #define CC_IDX_PROP_DATA_OFFSET 4
48846503c2bSMichael Roth #define CC_VAL_DATA_OFFSET ((CC_IDX_PROP_DATA_OFFSET + 1) * 4)
48946503c2bSMichael Roth #define CC_WA_LEN 4096
49046503c2bSMichael Roth 
49146503c2bSMichael Roth static void rtas_ibm_configure_connector(PowerPCCPU *cpu,
49228e02042SDavid Gibson                                          sPAPRMachineState *spapr,
49346503c2bSMichael Roth                                          uint32_t token, uint32_t nargs,
49446503c2bSMichael Roth                                          target_ulong args, uint32_t nret,
49546503c2bSMichael Roth                                          target_ulong rets)
49646503c2bSMichael Roth {
49746503c2bSMichael Roth     uint64_t wa_addr;
49846503c2bSMichael Roth     uint64_t wa_offset;
49946503c2bSMichael Roth     uint32_t drc_index;
50046503c2bSMichael Roth     sPAPRDRConnector *drc;
50146503c2bSMichael Roth     sPAPRDRConnectorClass *drck;
50246503c2bSMichael Roth     sPAPRConfigureConnectorState *ccs;
50346503c2bSMichael Roth     sPAPRDRCCResponse resp = SPAPR_DR_CC_RESPONSE_CONTINUE;
50446503c2bSMichael Roth     int rc;
50546503c2bSMichael Roth     const void *fdt;
50646503c2bSMichael Roth 
50746503c2bSMichael Roth     if (nargs != 2 || nret != 1) {
50846503c2bSMichael Roth         rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
50946503c2bSMichael Roth         return;
51046503c2bSMichael Roth     }
51146503c2bSMichael Roth 
51246503c2bSMichael Roth     wa_addr = ((uint64_t)rtas_ld(args, 1) << 32) | rtas_ld(args, 0);
51346503c2bSMichael Roth 
51446503c2bSMichael Roth     drc_index = rtas_ld(wa_addr, 0);
51546503c2bSMichael Roth     drc = spapr_dr_connector_by_index(drc_index);
51646503c2bSMichael Roth     if (!drc) {
51746503c2bSMichael Roth         DPRINTF("rtas_ibm_configure_connector: invalid DRC index: %xh\n",
51846503c2bSMichael Roth                 drc_index);
51946503c2bSMichael Roth         rc = RTAS_OUT_PARAM_ERROR;
52046503c2bSMichael Roth         goto out;
52146503c2bSMichael Roth     }
52246503c2bSMichael Roth 
52346503c2bSMichael Roth     drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
52446503c2bSMichael Roth     fdt = drck->get_fdt(drc, NULL);
525*e6fc9568SBharata B Rao     if (!fdt) {
526*e6fc9568SBharata B Rao         DPRINTF("rtas_ibm_configure_connector: Missing FDT for DRC index: %xh\n",
527*e6fc9568SBharata B Rao                 drc_index);
528*e6fc9568SBharata B Rao         rc = SPAPR_DR_CC_RESPONSE_NOT_CONFIGURABLE;
529*e6fc9568SBharata B Rao         goto out;
530*e6fc9568SBharata B Rao     }
53146503c2bSMichael Roth 
53246503c2bSMichael Roth     ccs = spapr_ccs_find(spapr, drc_index);
53346503c2bSMichael Roth     if (!ccs) {
53446503c2bSMichael Roth         ccs = g_new0(sPAPRConfigureConnectorState, 1);
53546503c2bSMichael Roth         (void)drck->get_fdt(drc, &ccs->fdt_offset);
53646503c2bSMichael Roth         ccs->drc_index = drc_index;
53746503c2bSMichael Roth         spapr_ccs_add(spapr, ccs);
53846503c2bSMichael Roth     }
53946503c2bSMichael Roth 
54046503c2bSMichael Roth     do {
54146503c2bSMichael Roth         uint32_t tag;
54246503c2bSMichael Roth         const char *name;
54346503c2bSMichael Roth         const struct fdt_property *prop;
54446503c2bSMichael Roth         int fdt_offset_next, prop_len;
54546503c2bSMichael Roth 
54646503c2bSMichael Roth         tag = fdt_next_tag(fdt, ccs->fdt_offset, &fdt_offset_next);
54746503c2bSMichael Roth 
54846503c2bSMichael Roth         switch (tag) {
54946503c2bSMichael Roth         case FDT_BEGIN_NODE:
55046503c2bSMichael Roth             ccs->fdt_depth++;
55146503c2bSMichael Roth             name = fdt_get_name(fdt, ccs->fdt_offset, NULL);
55246503c2bSMichael Roth 
55346503c2bSMichael Roth             /* provide the name of the next OF node */
55446503c2bSMichael Roth             wa_offset = CC_VAL_DATA_OFFSET;
55546503c2bSMichael Roth             rtas_st(wa_addr, CC_IDX_NODE_NAME_OFFSET, wa_offset);
55646503c2bSMichael Roth             rtas_st_buffer_direct(wa_addr + wa_offset, CC_WA_LEN - wa_offset,
55746503c2bSMichael Roth                                   (uint8_t *)name, strlen(name) + 1);
55846503c2bSMichael Roth             resp = SPAPR_DR_CC_RESPONSE_NEXT_CHILD;
55946503c2bSMichael Roth             break;
56046503c2bSMichael Roth         case FDT_END_NODE:
56146503c2bSMichael Roth             ccs->fdt_depth--;
56246503c2bSMichael Roth             if (ccs->fdt_depth == 0) {
56346503c2bSMichael Roth                 /* done sending the device tree, don't need to track
56446503c2bSMichael Roth                  * the state anymore
56546503c2bSMichael Roth                  */
56646503c2bSMichael Roth                 drck->set_configured(drc);
56746503c2bSMichael Roth                 spapr_ccs_remove(spapr, ccs);
56846503c2bSMichael Roth                 ccs = NULL;
56946503c2bSMichael Roth                 resp = SPAPR_DR_CC_RESPONSE_SUCCESS;
57046503c2bSMichael Roth             } else {
57146503c2bSMichael Roth                 resp = SPAPR_DR_CC_RESPONSE_PREV_PARENT;
57246503c2bSMichael Roth             }
57346503c2bSMichael Roth             break;
57446503c2bSMichael Roth         case FDT_PROP:
57546503c2bSMichael Roth             prop = fdt_get_property_by_offset(fdt, ccs->fdt_offset,
57646503c2bSMichael Roth                                               &prop_len);
57746503c2bSMichael Roth             name = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
57846503c2bSMichael Roth 
57946503c2bSMichael Roth             /* provide the name of the next OF property */
58046503c2bSMichael Roth             wa_offset = CC_VAL_DATA_OFFSET;
58146503c2bSMichael Roth             rtas_st(wa_addr, CC_IDX_PROP_NAME_OFFSET, wa_offset);
58246503c2bSMichael Roth             rtas_st_buffer_direct(wa_addr + wa_offset, CC_WA_LEN - wa_offset,
58346503c2bSMichael Roth                                   (uint8_t *)name, strlen(name) + 1);
58446503c2bSMichael Roth 
58546503c2bSMichael Roth             /* provide the length and value of the OF property. data gets
58646503c2bSMichael Roth              * placed immediately after NULL terminator of the OF property's
58746503c2bSMichael Roth              * name string
58846503c2bSMichael Roth              */
58946503c2bSMichael Roth             wa_offset += strlen(name) + 1,
59046503c2bSMichael Roth             rtas_st(wa_addr, CC_IDX_PROP_LEN, prop_len);
59146503c2bSMichael Roth             rtas_st(wa_addr, CC_IDX_PROP_DATA_OFFSET, wa_offset);
59246503c2bSMichael Roth             rtas_st_buffer_direct(wa_addr + wa_offset, CC_WA_LEN - wa_offset,
59346503c2bSMichael Roth                                   (uint8_t *)((struct fdt_property *)prop)->data,
59446503c2bSMichael Roth                                   prop_len);
59546503c2bSMichael Roth             resp = SPAPR_DR_CC_RESPONSE_NEXT_PROPERTY;
59646503c2bSMichael Roth             break;
59746503c2bSMichael Roth         case FDT_END:
59846503c2bSMichael Roth             resp = SPAPR_DR_CC_RESPONSE_ERROR;
59946503c2bSMichael Roth         default:
60046503c2bSMichael Roth             /* keep seeking for an actionable tag */
60146503c2bSMichael Roth             break;
60246503c2bSMichael Roth         }
60346503c2bSMichael Roth         if (ccs) {
60446503c2bSMichael Roth             ccs->fdt_offset = fdt_offset_next;
60546503c2bSMichael Roth         }
60646503c2bSMichael Roth     } while (resp == SPAPR_DR_CC_RESPONSE_CONTINUE);
60746503c2bSMichael Roth 
60846503c2bSMichael Roth     rc = resp;
60946503c2bSMichael Roth out:
61046503c2bSMichael Roth     rtas_st(rets, 0, rc);
61146503c2bSMichael Roth }
61246503c2bSMichael Roth 
61339ac8455SDavid Gibson static struct rtas_call {
61439ac8455SDavid Gibson     const char *name;
61539ac8455SDavid Gibson     spapr_rtas_fn fn;
6163a3b8502SAlexey Kardashevskiy } rtas_table[RTAS_TOKEN_MAX - RTAS_TOKEN_BASE];
61739ac8455SDavid Gibson 
61828e02042SDavid Gibson target_ulong spapr_rtas_call(PowerPCCPU *cpu, sPAPRMachineState *spapr,
61939ac8455SDavid Gibson                              uint32_t token, uint32_t nargs, target_ulong args,
62039ac8455SDavid Gibson                              uint32_t nret, target_ulong rets)
62139ac8455SDavid Gibson {
6223a3b8502SAlexey Kardashevskiy     if ((token >= RTAS_TOKEN_BASE) && (token < RTAS_TOKEN_MAX)) {
6233a3b8502SAlexey Kardashevskiy         struct rtas_call *call = rtas_table + (token - RTAS_TOKEN_BASE);
62439ac8455SDavid Gibson 
62539ac8455SDavid Gibson         if (call->fn) {
626210b580bSAnthony Liguori             call->fn(cpu, spapr, token, nargs, args, nret, rets);
62739ac8455SDavid Gibson             return H_SUCCESS;
62839ac8455SDavid Gibson         }
62939ac8455SDavid Gibson     }
63039ac8455SDavid Gibson 
631821303f5SDavid Gibson     /* HACK: Some Linux early debug code uses RTAS display-character,
632821303f5SDavid Gibson      * but assumes the token value is 0xa (which it is on some real
633821303f5SDavid Gibson      * machines) without looking it up in the device tree.  This
634821303f5SDavid Gibson      * special case makes this work */
635821303f5SDavid Gibson     if (token == 0xa) {
636210b580bSAnthony Liguori         rtas_display_character(cpu, spapr, 0xa, nargs, args, nret, rets);
637821303f5SDavid Gibson         return H_SUCCESS;
638821303f5SDavid Gibson     }
639821303f5SDavid Gibson 
64039ac8455SDavid Gibson     hcall_dprintf("Unknown RTAS token 0x%x\n", token);
641a64d325dSAlexey Kardashevskiy     rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
64239ac8455SDavid Gibson     return H_PARAMETER;
64339ac8455SDavid Gibson }
64439ac8455SDavid Gibson 
6453a3b8502SAlexey Kardashevskiy void spapr_rtas_register(int token, const char *name, spapr_rtas_fn fn)
64639ac8455SDavid Gibson {
6473a3b8502SAlexey Kardashevskiy     if (!((token >= RTAS_TOKEN_BASE) && (token < RTAS_TOKEN_MAX))) {
6483a3b8502SAlexey Kardashevskiy         fprintf(stderr, "RTAS invalid token 0x%x\n", token);
649c89d5299SDavid Gibson         exit(1);
650c89d5299SDavid Gibson     }
6513a3b8502SAlexey Kardashevskiy 
6523a3b8502SAlexey Kardashevskiy     token -= RTAS_TOKEN_BASE;
6533a3b8502SAlexey Kardashevskiy     if (rtas_table[token].name) {
6543a3b8502SAlexey Kardashevskiy         fprintf(stderr, "RTAS call \"%s\" is registered already as 0x%x\n",
6553a3b8502SAlexey Kardashevskiy                 rtas_table[token].name, token);
6563a3b8502SAlexey Kardashevskiy         exit(1);
657c89d5299SDavid Gibson     }
658c89d5299SDavid Gibson 
6593a3b8502SAlexey Kardashevskiy     rtas_table[token].name = name;
6603a3b8502SAlexey Kardashevskiy     rtas_table[token].fn = fn;
66139ac8455SDavid Gibson }
66239ac8455SDavid Gibson 
663a8170e5eSAvi Kivity int spapr_rtas_device_tree_setup(void *fdt, hwaddr rtas_addr,
664a8170e5eSAvi Kivity                                  hwaddr rtas_size)
66539ac8455SDavid Gibson {
66639ac8455SDavid Gibson     int ret;
66739ac8455SDavid Gibson     int i;
668db4ef288SBharata B Rao     uint32_t lrdr_capacity[5];
669db4ef288SBharata B Rao     MachineState *machine = MACHINE(qdev_get_machine());
67039ac8455SDavid Gibson 
67139ac8455SDavid Gibson     ret = fdt_add_mem_rsv(fdt, rtas_addr, rtas_size);
67239ac8455SDavid Gibson     if (ret < 0) {
67339ac8455SDavid Gibson         fprintf(stderr, "Couldn't add RTAS reserve entry: %s\n",
67439ac8455SDavid Gibson                 fdt_strerror(ret));
67539ac8455SDavid Gibson         return ret;
67639ac8455SDavid Gibson     }
67739ac8455SDavid Gibson 
6785a4348d1SPeter Crosthwaite     ret = qemu_fdt_setprop_cell(fdt, "/rtas", "linux,rtas-base",
67939ac8455SDavid Gibson                                 rtas_addr);
68039ac8455SDavid Gibson     if (ret < 0) {
68139ac8455SDavid Gibson         fprintf(stderr, "Couldn't add linux,rtas-base property: %s\n",
68239ac8455SDavid Gibson                 fdt_strerror(ret));
68339ac8455SDavid Gibson         return ret;
68439ac8455SDavid Gibson     }
68539ac8455SDavid Gibson 
6865a4348d1SPeter Crosthwaite     ret = qemu_fdt_setprop_cell(fdt, "/rtas", "linux,rtas-entry",
68739ac8455SDavid Gibson                                 rtas_addr);
68839ac8455SDavid Gibson     if (ret < 0) {
68939ac8455SDavid Gibson         fprintf(stderr, "Couldn't add linux,rtas-entry property: %s\n",
69039ac8455SDavid Gibson                 fdt_strerror(ret));
69139ac8455SDavid Gibson         return ret;
69239ac8455SDavid Gibson     }
69339ac8455SDavid Gibson 
6945a4348d1SPeter Crosthwaite     ret = qemu_fdt_setprop_cell(fdt, "/rtas", "rtas-size",
69539ac8455SDavid Gibson                                 rtas_size);
69639ac8455SDavid Gibson     if (ret < 0) {
69739ac8455SDavid Gibson         fprintf(stderr, "Couldn't add rtas-size property: %s\n",
69839ac8455SDavid Gibson                 fdt_strerror(ret));
69939ac8455SDavid Gibson         return ret;
70039ac8455SDavid Gibson     }
70139ac8455SDavid Gibson 
7023a3b8502SAlexey Kardashevskiy     for (i = 0; i < RTAS_TOKEN_MAX - RTAS_TOKEN_BASE; i++) {
70339ac8455SDavid Gibson         struct rtas_call *call = &rtas_table[i];
70439ac8455SDavid Gibson 
705d36b66f7SBen Herrenschmidt         if (!call->name) {
70639ac8455SDavid Gibson             continue;
70739ac8455SDavid Gibson         }
70839ac8455SDavid Gibson 
7095a4348d1SPeter Crosthwaite         ret = qemu_fdt_setprop_cell(fdt, "/rtas", call->name,
7103a3b8502SAlexey Kardashevskiy                                     i + RTAS_TOKEN_BASE);
71139ac8455SDavid Gibson         if (ret < 0) {
71239ac8455SDavid Gibson             fprintf(stderr, "Couldn't add rtas token for %s: %s\n",
71339ac8455SDavid Gibson                     call->name, fdt_strerror(ret));
71439ac8455SDavid Gibson             return ret;
71539ac8455SDavid Gibson         }
71639ac8455SDavid Gibson 
71739ac8455SDavid Gibson     }
718db4ef288SBharata B Rao 
719db4ef288SBharata B Rao     lrdr_capacity[0] = cpu_to_be32(((uint64_t)machine->maxram_size) >> 32);
720db4ef288SBharata B Rao     lrdr_capacity[1] = cpu_to_be32(machine->maxram_size & 0xffffffff);
721db4ef288SBharata B Rao     lrdr_capacity[2] = 0;
722db4ef288SBharata B Rao     lrdr_capacity[3] = cpu_to_be32(SPAPR_MEMORY_BLOCK_SIZE);
723db4ef288SBharata B Rao     lrdr_capacity[4] = cpu_to_be32(max_cpus/smp_threads);
724db4ef288SBharata B Rao     ret = qemu_fdt_setprop(fdt, "/rtas", "ibm,lrdr-capacity", lrdr_capacity,
725db4ef288SBharata B Rao                      sizeof(lrdr_capacity));
726db4ef288SBharata B Rao     if (ret < 0) {
727db4ef288SBharata B Rao         fprintf(stderr, "Couldn't add ibm,lrdr-capacity rtas property\n");
728db4ef288SBharata B Rao         return ret;
729db4ef288SBharata B Rao     }
730db4ef288SBharata B Rao 
73139ac8455SDavid Gibson     return 0;
73239ac8455SDavid Gibson }
733821303f5SDavid Gibson 
73483f7d43aSAndreas Färber static void core_rtas_register_types(void)
735821303f5SDavid Gibson {
7363a3b8502SAlexey Kardashevskiy     spapr_rtas_register(RTAS_DISPLAY_CHARACTER, "display-character",
7373a3b8502SAlexey Kardashevskiy                         rtas_display_character);
7383a3b8502SAlexey Kardashevskiy     spapr_rtas_register(RTAS_POWER_OFF, "power-off", rtas_power_off);
7393a3b8502SAlexey Kardashevskiy     spapr_rtas_register(RTAS_SYSTEM_REBOOT, "system-reboot",
7403a3b8502SAlexey Kardashevskiy                         rtas_system_reboot);
7413a3b8502SAlexey Kardashevskiy     spapr_rtas_register(RTAS_QUERY_CPU_STOPPED_STATE, "query-cpu-stopped-state",
742a9f8ad8fSDavid Gibson                         rtas_query_cpu_stopped_state);
7433a3b8502SAlexey Kardashevskiy     spapr_rtas_register(RTAS_START_CPU, "start-cpu", rtas_start_cpu);
7443a3b8502SAlexey Kardashevskiy     spapr_rtas_register(RTAS_STOP_SELF, "stop-self", rtas_stop_self);
7453a3b8502SAlexey Kardashevskiy     spapr_rtas_register(RTAS_IBM_GET_SYSTEM_PARAMETER,
7463a3b8502SAlexey Kardashevskiy                         "ibm,get-system-parameter",
7473ada6b11SAlexey Kardashevskiy                         rtas_ibm_get_system_parameter);
7483a3b8502SAlexey Kardashevskiy     spapr_rtas_register(RTAS_IBM_SET_SYSTEM_PARAMETER,
7493a3b8502SAlexey Kardashevskiy                         "ibm,set-system-parameter",
7503ada6b11SAlexey Kardashevskiy                         rtas_ibm_set_system_parameter);
7512e14072fSNikunj A Dadhania     spapr_rtas_register(RTAS_IBM_OS_TERM, "ibm,os-term",
7522e14072fSNikunj A Dadhania                         rtas_ibm_os_term);
753094d2058SNathan Fontenot     spapr_rtas_register(RTAS_SET_POWER_LEVEL, "set-power-level",
754094d2058SNathan Fontenot                         rtas_set_power_level);
755094d2058SNathan Fontenot     spapr_rtas_register(RTAS_GET_POWER_LEVEL, "get-power-level",
756094d2058SNathan Fontenot                         rtas_get_power_level);
7578c8639dfSMike Day     spapr_rtas_register(RTAS_SET_INDICATOR, "set-indicator",
7588c8639dfSMike Day                         rtas_set_indicator);
759886445a6SMike Day     spapr_rtas_register(RTAS_GET_SENSOR_STATE, "get-sensor-state",
760886445a6SMike Day                         rtas_get_sensor_state);
76146503c2bSMichael Roth     spapr_rtas_register(RTAS_IBM_CONFIGURE_CONNECTOR, "ibm,configure-connector",
76246503c2bSMichael Roth                         rtas_ibm_configure_connector);
763821303f5SDavid Gibson }
76483f7d43aSAndreas Färber 
76583f7d43aSAndreas Färber type_init(core_rtas_register_types)
766