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
, uint32_t ilen
)
27 CPUState
*cs
= env_cpu(env
);
29 cs
->exception_index
= EXCP_PGM
;
30 env
->int_pgm_code
= code
;
31 /* If ILEN_UNWIND, int_pgm_ilen already has the correct value. */
32 if (ilen
!= ILEN_UNWIND
) {
33 env
->int_pgm_ilen
= ilen
;
37 void s390_program_interrupt(CPUS390XState
*env
, uint32_t code
, uintptr_t ra
)
40 kvm_s390_program_interrupt(env_archcpu(env
), code
);
41 } else if (tcg_enabled()) {
42 tcg_s390_program_interrupt(env
, code
, ra
);
44 g_assert_not_reached();
48 #if !defined(CONFIG_USER_ONLY)
49 void cpu_inject_clock_comparator(S390CPU
*cpu
)
51 CPUS390XState
*env
= &cpu
->env
;
53 env
->pending_int
|= INTERRUPT_EXT_CLOCK_COMPARATOR
;
54 cpu_interrupt(CPU(cpu
), CPU_INTERRUPT_HARD
);
57 void cpu_inject_cpu_timer(S390CPU
*cpu
)
59 CPUS390XState
*env
= &cpu
->env
;
61 env
->pending_int
|= INTERRUPT_EXT_CPU_TIMER
;
62 cpu_interrupt(CPU(cpu
), CPU_INTERRUPT_HARD
);
65 void cpu_inject_emergency_signal(S390CPU
*cpu
, uint16_t src_cpu_addr
)
67 CPUS390XState
*env
= &cpu
->env
;
69 g_assert(src_cpu_addr
< S390_MAX_CPUS
);
70 set_bit(src_cpu_addr
, env
->emergency_signals
);
72 env
->pending_int
|= INTERRUPT_EMERGENCY_SIGNAL
;
73 cpu_interrupt(CPU(cpu
), CPU_INTERRUPT_HARD
);
76 int cpu_inject_external_call(S390CPU
*cpu
, uint16_t src_cpu_addr
)
78 CPUS390XState
*env
= &cpu
->env
;
80 g_assert(src_cpu_addr
< S390_MAX_CPUS
);
81 if (env
->pending_int
& INTERRUPT_EXTERNAL_CALL
) {
84 env
->external_call_addr
= src_cpu_addr
;
86 env
->pending_int
|= INTERRUPT_EXTERNAL_CALL
;
87 cpu_interrupt(CPU(cpu
), CPU_INTERRUPT_HARD
);
91 void cpu_inject_restart(S390CPU
*cpu
)
93 CPUS390XState
*env
= &cpu
->env
;
96 kvm_s390_restart_interrupt(cpu
);
100 env
->pending_int
|= INTERRUPT_RESTART
;
101 cpu_interrupt(CPU(cpu
), CPU_INTERRUPT_HARD
);
104 void cpu_inject_stop(S390CPU
*cpu
)
106 CPUS390XState
*env
= &cpu
->env
;
109 kvm_s390_stop_interrupt(cpu
);
113 env
->pending_int
|= INTERRUPT_STOP
;
114 cpu_interrupt(CPU(cpu
), CPU_INTERRUPT_HARD
);
118 * All of the following interrupts are floating, i.e. not per-vcpu.
119 * We just need a dummy cpustate in order to be able to inject in the
122 void s390_sclp_extint(uint32_t parm
)
124 S390FLICState
*fs
= s390_get_flic();
125 S390FLICStateClass
*fsc
= s390_get_flic_class(fs
);
127 fsc
->inject_service(fs
, parm
);
130 void s390_io_interrupt(uint16_t subchannel_id
, uint16_t subchannel_nr
,
131 uint32_t io_int_parm
, uint32_t io_int_word
)
133 S390FLICState
*fs
= s390_get_flic();
134 S390FLICStateClass
*fsc
= s390_get_flic_class(fs
);
136 fsc
->inject_io(fs
, subchannel_id
, subchannel_nr
, io_int_parm
, io_int_word
);
139 void s390_crw_mchk(void)
141 S390FLICState
*fs
= s390_get_flic();
142 S390FLICStateClass
*fsc
= s390_get_flic_class(fs
);
144 fsc
->inject_crw_mchk(fs
);
147 bool s390_cpu_has_mcck_int(S390CPU
*cpu
)
149 QEMUS390FLICState
*flic
= s390_get_qemu_flic(s390_get_flic());
150 CPUS390XState
*env
= &cpu
->env
;
152 if (!(env
->psw
.mask
& PSW_MASK_MCHECK
)) {
156 /* for now we only support channel report machine checks (floating) */
157 if (qemu_s390_flic_has_crw_mchk(flic
) &&
158 (env
->cregs
[14] & CR14_CHANNEL_REPORT_SC
)) {
165 bool s390_cpu_has_ext_int(S390CPU
*cpu
)
167 QEMUS390FLICState
*flic
= s390_get_qemu_flic(s390_get_flic());
168 CPUS390XState
*env
= &cpu
->env
;
170 if (!(env
->psw
.mask
& PSW_MASK_EXT
)) {
174 if ((env
->pending_int
& INTERRUPT_EMERGENCY_SIGNAL
) &&
175 (env
->cregs
[0] & CR0_EMERGENCY_SIGNAL_SC
)) {
179 if ((env
->pending_int
& INTERRUPT_EXTERNAL_CALL
) &&
180 (env
->cregs
[0] & CR0_EXTERNAL_CALL_SC
)) {
184 if ((env
->pending_int
& INTERRUPT_EXTERNAL_CALL
) &&
185 (env
->cregs
[0] & CR0_EXTERNAL_CALL_SC
)) {
189 if ((env
->pending_int
& INTERRUPT_EXT_CLOCK_COMPARATOR
) &&
190 (env
->cregs
[0] & CR0_CKC_SC
)) {
194 if ((env
->pending_int
& INTERRUPT_EXT_CPU_TIMER
) &&
195 (env
->cregs
[0] & CR0_CPU_TIMER_SC
)) {
199 if (qemu_s390_flic_has_service(flic
) &&
200 (env
->cregs
[0] & CR0_SERVICE_SC
)) {
207 bool s390_cpu_has_io_int(S390CPU
*cpu
)
209 QEMUS390FLICState
*flic
= s390_get_qemu_flic(s390_get_flic());
210 CPUS390XState
*env
= &cpu
->env
;
212 if (!(env
->psw
.mask
& PSW_MASK_IO
)) {
216 return qemu_s390_flic_has_io(flic
, env
->cregs
[6]);
219 bool s390_cpu_has_restart_int(S390CPU
*cpu
)
221 CPUS390XState
*env
= &cpu
->env
;
223 return env
->pending_int
& INTERRUPT_RESTART
;
226 bool s390_cpu_has_stop_int(S390CPU
*cpu
)
228 CPUS390XState
*env
= &cpu
->env
;
230 return env
->pending_int
& INTERRUPT_STOP
;
234 bool s390_cpu_has_int(S390CPU
*cpu
)
236 #ifndef CONFIG_USER_ONLY
237 if (!tcg_enabled()) {
240 return s390_cpu_has_mcck_int(cpu
) ||
241 s390_cpu_has_ext_int(cpu
) ||
242 s390_cpu_has_io_int(cpu
) ||
243 s390_cpu_has_restart_int(cpu
) ||
244 s390_cpu_has_stop_int(cpu
);