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 "hw/s390x/ioinst.h"
19 /* Ensure to exit the TB after this call! */
20 void trigger_pgm_exception(CPUS390XState
*env
, uint32_t code
, uint32_t ilen
)
22 CPUState
*cs
= CPU(s390_env_get_cpu(env
));
24 cs
->exception_index
= EXCP_PGM
;
25 env
->int_pgm_code
= code
;
26 env
->int_pgm_ilen
= ilen
;
29 static void tcg_s390_program_interrupt(CPUS390XState
*env
, uint32_t code
,
30 int ilen
, uintptr_t ra
)
33 trigger_pgm_exception(env
, code
, ilen
);
34 cpu_loop_exit_restore(CPU(s390_env_get_cpu(env
)), ra
);
36 g_assert_not_reached();
40 void s390_program_interrupt(CPUS390XState
*env
, uint32_t code
, int ilen
,
43 S390CPU
*cpu
= s390_env_get_cpu(env
);
45 qemu_log_mask(CPU_LOG_INT
, "program interrupt at %#" PRIx64
"\n",
49 kvm_s390_program_interrupt(cpu
, code
);
50 } else if (tcg_enabled()) {
51 tcg_s390_program_interrupt(env
, code
, ilen
, ra
);
53 g_assert_not_reached();
57 #if !defined(CONFIG_USER_ONLY)
58 static void cpu_inject_service(S390CPU
*cpu
, uint32_t param
)
60 CPUS390XState
*env
= &cpu
->env
;
62 /* multiplexing is good enough for sclp - kvm does it internally as well*/
63 env
->service_param
|= param
;
65 env
->pending_int
|= INTERRUPT_EXT_SERVICE
;
66 cpu_interrupt(CPU(cpu
), CPU_INTERRUPT_HARD
);
69 void cpu_inject_clock_comparator(S390CPU
*cpu
)
71 CPUS390XState
*env
= &cpu
->env
;
73 env
->pending_int
|= INTERRUPT_EXT_CLOCK_COMPARATOR
;
74 cpu_interrupt(CPU(cpu
), CPU_INTERRUPT_HARD
);
77 void cpu_inject_cpu_timer(S390CPU
*cpu
)
79 CPUS390XState
*env
= &cpu
->env
;
81 env
->pending_int
|= INTERRUPT_EXT_CPU_TIMER
;
82 cpu_interrupt(CPU(cpu
), CPU_INTERRUPT_HARD
);
85 void cpu_inject_emergency_signal(S390CPU
*cpu
, uint16_t src_cpu_addr
)
87 CPUS390XState
*env
= &cpu
->env
;
89 g_assert(src_cpu_addr
< S390_MAX_CPUS
);
90 set_bit(src_cpu_addr
, env
->emergency_signals
);
92 env
->pending_int
|= INTERRUPT_EMERGENCY_SIGNAL
;
93 cpu_interrupt(CPU(cpu
), CPU_INTERRUPT_HARD
);
96 int cpu_inject_external_call(S390CPU
*cpu
, uint16_t src_cpu_addr
)
98 CPUS390XState
*env
= &cpu
->env
;
100 g_assert(src_cpu_addr
< S390_MAX_CPUS
);
101 if (env
->pending_int
& INTERRUPT_EXTERNAL_CALL
) {
104 env
->external_call_addr
= src_cpu_addr
;
106 env
->pending_int
|= INTERRUPT_EXTERNAL_CALL
;
107 cpu_interrupt(CPU(cpu
), CPU_INTERRUPT_HARD
);
111 void cpu_inject_restart(S390CPU
*cpu
)
113 CPUS390XState
*env
= &cpu
->env
;
116 kvm_s390_restart_interrupt(cpu
);
120 env
->pending_int
|= INTERRUPT_RESTART
;
121 cpu_interrupt(CPU(cpu
), CPU_INTERRUPT_HARD
);
124 void cpu_inject_stop(S390CPU
*cpu
)
126 CPUS390XState
*env
= &cpu
->env
;
129 kvm_s390_stop_interrupt(cpu
);
133 env
->pending_int
|= INTERRUPT_STOP
;
134 cpu_interrupt(CPU(cpu
), CPU_INTERRUPT_HARD
);
137 static void cpu_inject_io(S390CPU
*cpu
, uint16_t subchannel_id
,
138 uint16_t subchannel_number
,
139 uint32_t io_int_parm
, uint32_t io_int_word
)
141 CPUS390XState
*env
= &cpu
->env
;
142 int isc
= IO_INT_WORD_ISC(io_int_word
);
144 if (env
->io_index
[isc
] == MAX_IO_QUEUE
- 1) {
145 /* ugh - can't queue anymore. Let's drop. */
149 env
->io_index
[isc
]++;
150 assert(env
->io_index
[isc
] < MAX_IO_QUEUE
);
152 env
->io_queue
[env
->io_index
[isc
]][isc
].id
= subchannel_id
;
153 env
->io_queue
[env
->io_index
[isc
]][isc
].nr
= subchannel_number
;
154 env
->io_queue
[env
->io_index
[isc
]][isc
].parm
= io_int_parm
;
155 env
->io_queue
[env
->io_index
[isc
]][isc
].word
= io_int_word
;
157 env
->pending_int
|= INTERRUPT_IO
;
158 cpu_interrupt(CPU(cpu
), CPU_INTERRUPT_HARD
);
161 static void cpu_inject_crw_mchk(S390CPU
*cpu
)
163 CPUS390XState
*env
= &cpu
->env
;
165 if (env
->mchk_index
== MAX_MCHK_QUEUE
- 1) {
166 /* ugh - can't queue anymore. Let's drop. */
171 assert(env
->mchk_index
< MAX_MCHK_QUEUE
);
173 env
->mchk_queue
[env
->mchk_index
].type
= 1;
175 env
->pending_int
|= INTERRUPT_MCHK
;
176 cpu_interrupt(CPU(cpu
), CPU_INTERRUPT_HARD
);
180 * All of the following interrupts are floating, i.e. not per-vcpu.
181 * We just need a dummy cpustate in order to be able to inject in the
184 void s390_sclp_extint(uint32_t parm
)
187 kvm_s390_service_interrupt(parm
);
189 S390CPU
*dummy_cpu
= s390_cpu_addr2state(0);
191 cpu_inject_service(dummy_cpu
, parm
);
195 void s390_io_interrupt(uint16_t subchannel_id
, uint16_t subchannel_nr
,
196 uint32_t io_int_parm
, uint32_t io_int_word
)
199 kvm_s390_io_interrupt(subchannel_id
, subchannel_nr
, io_int_parm
,
202 S390CPU
*dummy_cpu
= s390_cpu_addr2state(0);
204 cpu_inject_io(dummy_cpu
, subchannel_id
, subchannel_nr
, io_int_parm
,
209 void s390_crw_mchk(void)
214 S390CPU
*dummy_cpu
= s390_cpu_addr2state(0);
216 cpu_inject_crw_mchk(dummy_cpu
);
220 bool s390_cpu_has_mcck_int(S390CPU
*cpu
)
222 CPUS390XState
*env
= &cpu
->env
;
224 if (!(env
->psw
.mask
& PSW_MASK_MCHECK
)) {
228 return env
->pending_int
& INTERRUPT_MCHK
;
231 bool s390_cpu_has_ext_int(S390CPU
*cpu
)
233 CPUS390XState
*env
= &cpu
->env
;
235 if (!(env
->psw
.mask
& PSW_MASK_EXT
)) {
239 if ((env
->pending_int
& INTERRUPT_EMERGENCY_SIGNAL
) &&
240 (env
->cregs
[0] & CR0_EMERGENCY_SIGNAL_SC
)) {
244 if ((env
->pending_int
& INTERRUPT_EXTERNAL_CALL
) &&
245 (env
->cregs
[0] & CR0_EXTERNAL_CALL_SC
)) {
249 if ((env
->pending_int
& INTERRUPT_EXTERNAL_CALL
) &&
250 (env
->cregs
[0] & CR0_EXTERNAL_CALL_SC
)) {
254 if ((env
->pending_int
& INTERRUPT_EXT_CLOCK_COMPARATOR
) &&
255 (env
->cregs
[0] & CR0_CKC_SC
)) {
259 if ((env
->pending_int
& INTERRUPT_EXT_CPU_TIMER
) &&
260 (env
->cregs
[0] & CR0_CPU_TIMER_SC
)) {
264 if ((env
->pending_int
& INTERRUPT_EXT_SERVICE
) &&
265 (env
->cregs
[0] & CR0_SERVICE_SC
)) {
272 bool s390_cpu_has_io_int(S390CPU
*cpu
)
274 CPUS390XState
*env
= &cpu
->env
;
276 if (!(env
->psw
.mask
& PSW_MASK_IO
)) {
280 return env
->pending_int
& INTERRUPT_IO
;
283 bool s390_cpu_has_restart_int(S390CPU
*cpu
)
285 CPUS390XState
*env
= &cpu
->env
;
287 return env
->pending_int
& INTERRUPT_RESTART
;
290 bool s390_cpu_has_stop_int(S390CPU
*cpu
)
292 CPUS390XState
*env
= &cpu
->env
;
294 return env
->pending_int
& INTERRUPT_STOP
;
298 bool s390_cpu_has_int(S390CPU
*cpu
)
300 #ifndef CONFIG_USER_ONLY
301 if (!tcg_enabled()) {
304 return s390_cpu_has_mcck_int(cpu
) ||
305 s390_cpu_has_ext_int(cpu
) ||
306 s390_cpu_has_io_int(cpu
) ||
307 s390_cpu_has_restart_int(cpu
) ||
308 s390_cpu_has_stop_int(cpu
);