avocado/ppc_prep_40p.py: check TCG accel in all tests
[qemu.git] / target / s390x / interrupt.c
blob5195f060ecbf1db7f9486048df4632243b4fec3d
1 /*
2 * QEMU S/390 Interrupt support
4 * Copyright IBM Corp. 2012, 2014
6 * This work is licensed under the terms of the GNU GPL, version 2 or (at your
7 * option) any later version. See the COPYING file in the top-level directory.
8 */
10 #include "qemu/osdep.h"
11 #include "cpu.h"
12 #include "kvm/kvm_s390x.h"
13 #include "s390x-internal.h"
14 #include "exec/exec-all.h"
15 #include "sysemu/kvm.h"
16 #include "sysemu/tcg.h"
17 #include "hw/s390x/ioinst.h"
18 #include "tcg/tcg_s390x.h"
19 #if !defined(CONFIG_USER_ONLY)
20 #include "hw/s390x/s390_flic.h"
21 #endif
23 /* Ensure to exit the TB after this call! */
24 void trigger_pgm_exception(CPUS390XState *env, uint32_t code)
26 CPUState *cs = env_cpu(env);
28 cs->exception_index = EXCP_PGM;
29 env->int_pgm_code = code;
30 /* env->int_pgm_ilen is already set, or will be set during unwinding */
33 void s390_program_interrupt(CPUS390XState *env, uint32_t code, uintptr_t ra)
35 if (kvm_enabled()) {
36 kvm_s390_program_interrupt(env_archcpu(env), code);
37 } else if (tcg_enabled()) {
38 tcg_s390_program_interrupt(env, code, ra);
39 } else {
40 g_assert_not_reached();
44 #if !defined(CONFIG_USER_ONLY)
45 void cpu_inject_clock_comparator(S390CPU *cpu)
47 CPUS390XState *env = &cpu->env;
49 env->pending_int |= INTERRUPT_EXT_CLOCK_COMPARATOR;
50 cpu_interrupt(CPU(cpu), CPU_INTERRUPT_HARD);
53 void cpu_inject_cpu_timer(S390CPU *cpu)
55 CPUS390XState *env = &cpu->env;
57 env->pending_int |= INTERRUPT_EXT_CPU_TIMER;
58 cpu_interrupt(CPU(cpu), CPU_INTERRUPT_HARD);
61 void cpu_inject_emergency_signal(S390CPU *cpu, uint16_t src_cpu_addr)
63 CPUS390XState *env = &cpu->env;
65 g_assert(src_cpu_addr < S390_MAX_CPUS);
66 set_bit(src_cpu_addr, env->emergency_signals);
68 env->pending_int |= INTERRUPT_EMERGENCY_SIGNAL;
69 cpu_interrupt(CPU(cpu), CPU_INTERRUPT_HARD);
72 int cpu_inject_external_call(S390CPU *cpu, uint16_t src_cpu_addr)
74 CPUS390XState *env = &cpu->env;
76 g_assert(src_cpu_addr < S390_MAX_CPUS);
77 if (env->pending_int & INTERRUPT_EXTERNAL_CALL) {
78 return -EBUSY;
80 env->external_call_addr = src_cpu_addr;
82 env->pending_int |= INTERRUPT_EXTERNAL_CALL;
83 cpu_interrupt(CPU(cpu), CPU_INTERRUPT_HARD);
84 return 0;
87 void cpu_inject_restart(S390CPU *cpu)
89 CPUS390XState *env = &cpu->env;
91 if (kvm_enabled()) {
92 kvm_s390_restart_interrupt(cpu);
93 return;
96 env->pending_int |= INTERRUPT_RESTART;
97 cpu_interrupt(CPU(cpu), CPU_INTERRUPT_HARD);
100 void cpu_inject_stop(S390CPU *cpu)
102 CPUS390XState *env = &cpu->env;
104 if (kvm_enabled()) {
105 kvm_s390_stop_interrupt(cpu);
106 return;
109 env->pending_int |= INTERRUPT_STOP;
110 cpu_interrupt(CPU(cpu), CPU_INTERRUPT_HARD);
114 * All of the following interrupts are floating, i.e. not per-vcpu.
115 * We just need a dummy cpustate in order to be able to inject in the
116 * non-kvm case.
118 void s390_sclp_extint(uint32_t parm)
120 S390FLICState *fs = s390_get_flic();
121 S390FLICStateClass *fsc = s390_get_flic_class(fs);
123 fsc->inject_service(fs, parm);
126 void s390_io_interrupt(uint16_t subchannel_id, uint16_t subchannel_nr,
127 uint32_t io_int_parm, uint32_t io_int_word)
129 S390FLICState *fs = s390_get_flic();
130 S390FLICStateClass *fsc = s390_get_flic_class(fs);
132 fsc->inject_io(fs, subchannel_id, subchannel_nr, io_int_parm, io_int_word);
135 void s390_crw_mchk(void)
137 S390FLICState *fs = s390_get_flic();
138 S390FLICStateClass *fsc = s390_get_flic_class(fs);
140 fsc->inject_crw_mchk(fs);
143 bool s390_cpu_has_mcck_int(S390CPU *cpu)
145 QEMUS390FLICState *flic = s390_get_qemu_flic(s390_get_flic());
146 CPUS390XState *env = &cpu->env;
148 if (!(env->psw.mask & PSW_MASK_MCHECK)) {
149 return false;
152 /* for now we only support channel report machine checks (floating) */
153 if (qemu_s390_flic_has_crw_mchk(flic) &&
154 (env->cregs[14] & CR14_CHANNEL_REPORT_SC)) {
155 return true;
158 return false;
161 bool s390_cpu_has_ext_int(S390CPU *cpu)
163 QEMUS390FLICState *flic = s390_get_qemu_flic(s390_get_flic());
164 CPUS390XState *env = &cpu->env;
166 if (!(env->psw.mask & PSW_MASK_EXT)) {
167 return false;
170 if ((env->pending_int & INTERRUPT_EMERGENCY_SIGNAL) &&
171 (env->cregs[0] & CR0_EMERGENCY_SIGNAL_SC)) {
172 return true;
175 if ((env->pending_int & INTERRUPT_EXTERNAL_CALL) &&
176 (env->cregs[0] & CR0_EXTERNAL_CALL_SC)) {
177 return true;
180 if ((env->pending_int & INTERRUPT_EXTERNAL_CALL) &&
181 (env->cregs[0] & CR0_EXTERNAL_CALL_SC)) {
182 return true;
185 if ((env->pending_int & INTERRUPT_EXT_CLOCK_COMPARATOR) &&
186 (env->cregs[0] & CR0_CKC_SC)) {
187 return true;
190 if ((env->pending_int & INTERRUPT_EXT_CPU_TIMER) &&
191 (env->cregs[0] & CR0_CPU_TIMER_SC)) {
192 return true;
195 if (qemu_s390_flic_has_service(flic) &&
196 (env->cregs[0] & CR0_SERVICE_SC)) {
197 return true;
200 return false;
203 bool s390_cpu_has_io_int(S390CPU *cpu)
205 QEMUS390FLICState *flic = s390_get_qemu_flic(s390_get_flic());
206 CPUS390XState *env = &cpu->env;
208 if (!(env->psw.mask & PSW_MASK_IO)) {
209 return false;
212 return qemu_s390_flic_has_io(flic, env->cregs[6]);
215 bool s390_cpu_has_restart_int(S390CPU *cpu)
217 CPUS390XState *env = &cpu->env;
219 return env->pending_int & INTERRUPT_RESTART;
222 bool s390_cpu_has_stop_int(S390CPU *cpu)
224 CPUS390XState *env = &cpu->env;
226 return env->pending_int & INTERRUPT_STOP;
228 #endif
230 bool s390_cpu_has_int(S390CPU *cpu)
232 #ifndef CONFIG_USER_ONLY
233 if (!tcg_enabled()) {
234 return false;
236 return s390_cpu_has_mcck_int(cpu) ||
237 s390_cpu_has_ext_int(cpu) ||
238 s390_cpu_has_io_int(cpu) ||
239 s390_cpu_has_restart_int(cpu) ||
240 s390_cpu_has_stop_int(cpu);
241 #else
242 return false;
243 #endif