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.
10 #include "qemu/osdep.h"
13 #include "kvm_s390x.h"
15 #include "exec/exec-all.h"
16 #include "sysemu/kvm.h"
17 #include "sysemu/tcg.h"
18 #include "hw/s390x/ioinst.h"
19 #include "tcg_s390x.h"
20 #if !defined(CONFIG_USER_ONLY)
21 #include "hw/s390x/s390_flic.h"
24 /* Ensure to exit the TB after this call! */
25 void trigger_pgm_exception(CPUS390XState
*env
, uint32_t code
)
27 CPUState
*cs
= env_cpu(env
);
29 cs
->exception_index
= EXCP_PGM
;
30 env
->int_pgm_code
= code
;
31 /* env->int_pgm_ilen is already set, or will be set during unwinding */
34 void s390_program_interrupt(CPUS390XState
*env
, uint32_t code
, uintptr_t ra
)
37 kvm_s390_program_interrupt(env_archcpu(env
), code
);
38 } else if (tcg_enabled()) {
39 tcg_s390_program_interrupt(env
, code
, ra
);
41 g_assert_not_reached();
45 #if !defined(CONFIG_USER_ONLY)
46 void cpu_inject_clock_comparator(S390CPU
*cpu
)
48 CPUS390XState
*env
= &cpu
->env
;
50 env
->pending_int
|= INTERRUPT_EXT_CLOCK_COMPARATOR
;
51 cpu_interrupt(CPU(cpu
), CPU_INTERRUPT_HARD
);
54 void cpu_inject_cpu_timer(S390CPU
*cpu
)
56 CPUS390XState
*env
= &cpu
->env
;
58 env
->pending_int
|= INTERRUPT_EXT_CPU_TIMER
;
59 cpu_interrupt(CPU(cpu
), CPU_INTERRUPT_HARD
);
62 void cpu_inject_emergency_signal(S390CPU
*cpu
, uint16_t src_cpu_addr
)
64 CPUS390XState
*env
= &cpu
->env
;
66 g_assert(src_cpu_addr
< S390_MAX_CPUS
);
67 set_bit(src_cpu_addr
, env
->emergency_signals
);
69 env
->pending_int
|= INTERRUPT_EMERGENCY_SIGNAL
;
70 cpu_interrupt(CPU(cpu
), CPU_INTERRUPT_HARD
);
73 int cpu_inject_external_call(S390CPU
*cpu
, uint16_t src_cpu_addr
)
75 CPUS390XState
*env
= &cpu
->env
;
77 g_assert(src_cpu_addr
< S390_MAX_CPUS
);
78 if (env
->pending_int
& INTERRUPT_EXTERNAL_CALL
) {
81 env
->external_call_addr
= src_cpu_addr
;
83 env
->pending_int
|= INTERRUPT_EXTERNAL_CALL
;
84 cpu_interrupt(CPU(cpu
), CPU_INTERRUPT_HARD
);
88 void cpu_inject_restart(S390CPU
*cpu
)
90 CPUS390XState
*env
= &cpu
->env
;
93 kvm_s390_restart_interrupt(cpu
);
97 env
->pending_int
|= INTERRUPT_RESTART
;
98 cpu_interrupt(CPU(cpu
), CPU_INTERRUPT_HARD
);
101 void cpu_inject_stop(S390CPU
*cpu
)
103 CPUS390XState
*env
= &cpu
->env
;
106 kvm_s390_stop_interrupt(cpu
);
110 env
->pending_int
|= INTERRUPT_STOP
;
111 cpu_interrupt(CPU(cpu
), CPU_INTERRUPT_HARD
);
115 * All of the following interrupts are floating, i.e. not per-vcpu.
116 * We just need a dummy cpustate in order to be able to inject in the
119 void s390_sclp_extint(uint32_t parm
)
121 S390FLICState
*fs
= s390_get_flic();
122 S390FLICStateClass
*fsc
= s390_get_flic_class(fs
);
124 fsc
->inject_service(fs
, parm
);
127 void s390_io_interrupt(uint16_t subchannel_id
, uint16_t subchannel_nr
,
128 uint32_t io_int_parm
, uint32_t io_int_word
)
130 S390FLICState
*fs
= s390_get_flic();
131 S390FLICStateClass
*fsc
= s390_get_flic_class(fs
);
133 fsc
->inject_io(fs
, subchannel_id
, subchannel_nr
, io_int_parm
, io_int_word
);
136 void s390_crw_mchk(void)
138 S390FLICState
*fs
= s390_get_flic();
139 S390FLICStateClass
*fsc
= s390_get_flic_class(fs
);
141 fsc
->inject_crw_mchk(fs
);
144 bool s390_cpu_has_mcck_int(S390CPU
*cpu
)
146 QEMUS390FLICState
*flic
= s390_get_qemu_flic(s390_get_flic());
147 CPUS390XState
*env
= &cpu
->env
;
149 if (!(env
->psw
.mask
& PSW_MASK_MCHECK
)) {
153 /* for now we only support channel report machine checks (floating) */
154 if (qemu_s390_flic_has_crw_mchk(flic
) &&
155 (env
->cregs
[14] & CR14_CHANNEL_REPORT_SC
)) {
162 bool s390_cpu_has_ext_int(S390CPU
*cpu
)
164 QEMUS390FLICState
*flic
= s390_get_qemu_flic(s390_get_flic());
165 CPUS390XState
*env
= &cpu
->env
;
167 if (!(env
->psw
.mask
& PSW_MASK_EXT
)) {
171 if ((env
->pending_int
& INTERRUPT_EMERGENCY_SIGNAL
) &&
172 (env
->cregs
[0] & CR0_EMERGENCY_SIGNAL_SC
)) {
176 if ((env
->pending_int
& INTERRUPT_EXTERNAL_CALL
) &&
177 (env
->cregs
[0] & CR0_EXTERNAL_CALL_SC
)) {
181 if ((env
->pending_int
& INTERRUPT_EXTERNAL_CALL
) &&
182 (env
->cregs
[0] & CR0_EXTERNAL_CALL_SC
)) {
186 if ((env
->pending_int
& INTERRUPT_EXT_CLOCK_COMPARATOR
) &&
187 (env
->cregs
[0] & CR0_CKC_SC
)) {
191 if ((env
->pending_int
& INTERRUPT_EXT_CPU_TIMER
) &&
192 (env
->cregs
[0] & CR0_CPU_TIMER_SC
)) {
196 if (qemu_s390_flic_has_service(flic
) &&
197 (env
->cregs
[0] & CR0_SERVICE_SC
)) {
204 bool s390_cpu_has_io_int(S390CPU
*cpu
)
206 QEMUS390FLICState
*flic
= s390_get_qemu_flic(s390_get_flic());
207 CPUS390XState
*env
= &cpu
->env
;
209 if (!(env
->psw
.mask
& PSW_MASK_IO
)) {
213 return qemu_s390_flic_has_io(flic
, env
->cregs
[6]);
216 bool s390_cpu_has_restart_int(S390CPU
*cpu
)
218 CPUS390XState
*env
= &cpu
->env
;
220 return env
->pending_int
& INTERRUPT_RESTART
;
223 bool s390_cpu_has_stop_int(S390CPU
*cpu
)
225 CPUS390XState
*env
= &cpu
->env
;
227 return env
->pending_int
& INTERRUPT_STOP
;
231 bool s390_cpu_has_int(S390CPU
*cpu
)
233 #ifndef CONFIG_USER_ONLY
234 if (!tcg_enabled()) {
237 return s390_cpu_has_mcck_int(cpu
) ||
238 s390_cpu_has_ext_int(cpu
) ||
239 s390_cpu_has_io_int(cpu
) ||
240 s390_cpu_has_restart_int(cpu
) ||
241 s390_cpu_has_stop_int(cpu
);