2012-07-24 01:37:05 +04:00
|
|
|
/*
|
|
|
|
* QEMU S/390 Interrupt support
|
|
|
|
*
|
2014-03-11 16:52:06 +04:00
|
|
|
* Copyright IBM Corp. 2012, 2014
|
2012-07-24 01:37:05 +04:00
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or (at your
|
|
|
|
* option) any later version. See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
2016-01-26 21:17:00 +03:00
|
|
|
#include "qemu/osdep.h"
|
2012-07-24 01:37:05 +04:00
|
|
|
#include "cpu.h"
|
2017-08-18 14:43:52 +03:00
|
|
|
#include "kvm_s390x.h"
|
2017-08-18 14:43:49 +03:00
|
|
|
#include "internal.h"
|
2017-07-24 11:52:48 +03:00
|
|
|
#include "exec/exec-all.h"
|
2012-12-17 21:20:04 +04:00
|
|
|
#include "sysemu/kvm.h"
|
2019-05-23 17:35:05 +03:00
|
|
|
#include "sysemu/tcg.h"
|
2015-12-04 14:06:26 +03:00
|
|
|
#include "hw/s390x/ioinst.h"
|
2018-09-27 16:02:55 +03:00
|
|
|
#include "tcg_s390x.h"
|
2018-01-29 15:56:10 +03:00
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
|
|
|
#include "hw/s390x/s390_flic.h"
|
|
|
|
#endif
|
2015-12-04 14:06:26 +03:00
|
|
|
|
2017-07-24 11:52:48 +03:00
|
|
|
/* Ensure to exit the TB after this call! */
|
2019-10-01 20:16:13 +03:00
|
|
|
void trigger_pgm_exception(CPUS390XState *env, uint32_t code)
|
2017-07-24 11:52:48 +03:00
|
|
|
{
|
2019-03-23 05:21:48 +03:00
|
|
|
CPUState *cs = env_cpu(env);
|
2017-07-24 11:52:48 +03:00
|
|
|
|
|
|
|
cs->exception_index = EXCP_PGM;
|
|
|
|
env->int_pgm_code = code;
|
2019-10-01 20:16:13 +03:00
|
|
|
/* env->int_pgm_ilen is already set, or will be set during unwinding */
|
2017-07-24 11:52:48 +03:00
|
|
|
}
|
|
|
|
|
2019-10-01 20:15:59 +03:00
|
|
|
void s390_program_interrupt(CPUS390XState *env, uint32_t code, uintptr_t ra)
|
2017-07-24 11:52:48 +03:00
|
|
|
{
|
|
|
|
if (kvm_enabled()) {
|
2019-03-23 05:21:48 +03:00
|
|
|
kvm_s390_program_interrupt(env_archcpu(env), code);
|
2017-07-24 11:52:48 +03:00
|
|
|
} else if (tcg_enabled()) {
|
2019-10-01 20:15:58 +03:00
|
|
|
tcg_s390_program_interrupt(env, code, ra);
|
2017-07-24 11:52:48 +03:00
|
|
|
} else {
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-04 14:06:26 +03:00
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
2017-09-28 23:36:39 +03:00
|
|
|
void cpu_inject_clock_comparator(S390CPU *cpu)
|
|
|
|
{
|
|
|
|
CPUS390XState *env = &cpu->env;
|
|
|
|
|
|
|
|
env->pending_int |= INTERRUPT_EXT_CLOCK_COMPARATOR;
|
|
|
|
cpu_interrupt(CPU(cpu), CPU_INTERRUPT_HARD);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cpu_inject_cpu_timer(S390CPU *cpu)
|
|
|
|
{
|
|
|
|
CPUS390XState *env = &cpu->env;
|
|
|
|
|
|
|
|
env->pending_int |= INTERRUPT_EXT_CPU_TIMER;
|
2015-12-04 14:06:26 +03:00
|
|
|
cpu_interrupt(CPU(cpu), CPU_INTERRUPT_HARD);
|
|
|
|
}
|
|
|
|
|
2017-09-28 23:36:41 +03:00
|
|
|
void cpu_inject_emergency_signal(S390CPU *cpu, uint16_t src_cpu_addr)
|
|
|
|
{
|
|
|
|
CPUS390XState *env = &cpu->env;
|
|
|
|
|
|
|
|
g_assert(src_cpu_addr < S390_MAX_CPUS);
|
|
|
|
set_bit(src_cpu_addr, env->emergency_signals);
|
|
|
|
|
|
|
|
env->pending_int |= INTERRUPT_EMERGENCY_SIGNAL;
|
|
|
|
cpu_interrupt(CPU(cpu), CPU_INTERRUPT_HARD);
|
|
|
|
}
|
|
|
|
|
|
|
|
int cpu_inject_external_call(S390CPU *cpu, uint16_t src_cpu_addr)
|
|
|
|
{
|
|
|
|
CPUS390XState *env = &cpu->env;
|
|
|
|
|
|
|
|
g_assert(src_cpu_addr < S390_MAX_CPUS);
|
|
|
|
if (env->pending_int & INTERRUPT_EXTERNAL_CALL) {
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
env->external_call_addr = src_cpu_addr;
|
|
|
|
|
|
|
|
env->pending_int |= INTERRUPT_EXTERNAL_CALL;
|
|
|
|
cpu_interrupt(CPU(cpu), CPU_INTERRUPT_HARD);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-28 23:36:50 +03:00
|
|
|
void cpu_inject_restart(S390CPU *cpu)
|
|
|
|
{
|
2017-09-28 23:37:02 +03:00
|
|
|
CPUS390XState *env = &cpu->env;
|
|
|
|
|
2017-09-28 23:36:50 +03:00
|
|
|
if (kvm_enabled()) {
|
|
|
|
kvm_s390_restart_interrupt(cpu);
|
|
|
|
return;
|
|
|
|
}
|
2017-09-28 23:37:02 +03:00
|
|
|
|
|
|
|
env->pending_int |= INTERRUPT_RESTART;
|
|
|
|
cpu_interrupt(CPU(cpu), CPU_INTERRUPT_HARD);
|
2017-09-28 23:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void cpu_inject_stop(S390CPU *cpu)
|
|
|
|
{
|
2017-09-28 23:37:02 +03:00
|
|
|
CPUS390XState *env = &cpu->env;
|
|
|
|
|
2017-09-28 23:36:50 +03:00
|
|
|
if (kvm_enabled()) {
|
|
|
|
kvm_s390_stop_interrupt(cpu);
|
|
|
|
return;
|
|
|
|
}
|
2017-09-28 23:37:02 +03:00
|
|
|
|
|
|
|
env->pending_int |= INTERRUPT_STOP;
|
|
|
|
cpu_interrupt(CPU(cpu), CPU_INTERRUPT_HARD);
|
2017-09-28 23:36:50 +03:00
|
|
|
}
|
|
|
|
|
2014-03-11 16:52:06 +04:00
|
|
|
/*
|
|
|
|
* All of the following interrupts are floating, i.e. not per-vcpu.
|
2014-03-11 16:19:43 +04:00
|
|
|
* We just need a dummy cpustate in order to be able to inject in the
|
|
|
|
* non-kvm case.
|
2014-03-11 16:52:06 +04:00
|
|
|
*/
|
2012-07-24 01:37:05 +04:00
|
|
|
void s390_sclp_extint(uint32_t parm)
|
|
|
|
{
|
2018-01-29 15:56:10 +03:00
|
|
|
S390FLICState *fs = s390_get_flic();
|
2018-01-29 15:56:23 +03:00
|
|
|
S390FLICStateClass *fsc = s390_get_flic_class(fs);
|
2014-03-11 16:19:43 +04:00
|
|
|
|
2018-01-29 15:56:10 +03:00
|
|
|
fsc->inject_service(fs, parm);
|
2012-07-24 01:37:05 +04:00
|
|
|
}
|
2014-03-11 16:52:06 +04:00
|
|
|
|
2014-03-11 16:19:43 +04:00
|
|
|
void s390_io_interrupt(uint16_t subchannel_id, uint16_t subchannel_nr,
|
|
|
|
uint32_t io_int_parm, uint32_t io_int_word)
|
2014-03-11 16:52:06 +04:00
|
|
|
{
|
2018-01-29 15:56:10 +03:00
|
|
|
S390FLICState *fs = s390_get_flic();
|
2018-01-29 15:56:23 +03:00
|
|
|
S390FLICStateClass *fsc = s390_get_flic_class(fs);
|
2014-03-11 16:19:43 +04:00
|
|
|
|
2018-01-29 15:56:10 +03:00
|
|
|
fsc->inject_io(fs, subchannel_id, subchannel_nr, io_int_parm, io_int_word);
|
2014-03-11 16:52:06 +04:00
|
|
|
}
|
|
|
|
|
2014-03-11 16:19:43 +04:00
|
|
|
void s390_crw_mchk(void)
|
2014-03-11 16:52:06 +04:00
|
|
|
{
|
2018-01-29 15:56:10 +03:00
|
|
|
S390FLICState *fs = s390_get_flic();
|
2018-01-29 15:56:23 +03:00
|
|
|
S390FLICStateClass *fsc = s390_get_flic_class(fs);
|
2014-03-11 16:19:43 +04:00
|
|
|
|
2018-01-29 15:56:10 +03:00
|
|
|
fsc->inject_crw_mchk(fs);
|
2014-03-11 16:52:06 +04:00
|
|
|
}
|
|
|
|
|
2017-09-28 23:36:42 +03:00
|
|
|
bool s390_cpu_has_mcck_int(S390CPU *cpu)
|
|
|
|
{
|
2018-01-29 15:56:21 +03:00
|
|
|
QEMUS390FLICState *flic = s390_get_qemu_flic(s390_get_flic());
|
2017-09-28 23:36:42 +03:00
|
|
|
CPUS390XState *env = &cpu->env;
|
|
|
|
|
|
|
|
if (!(env->psw.mask & PSW_MASK_MCHECK)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-29 15:56:09 +03:00
|
|
|
/* for now we only support channel report machine checks (floating) */
|
2018-01-29 15:56:13 +03:00
|
|
|
if (qemu_s390_flic_has_crw_mchk(flic) &&
|
2018-01-29 15:56:09 +03:00
|
|
|
(env->cregs[14] & CR14_CHANNEL_REPORT_SC)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2017-09-28 23:36:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool s390_cpu_has_ext_int(S390CPU *cpu)
|
|
|
|
{
|
2018-01-29 15:56:21 +03:00
|
|
|
QEMUS390FLICState *flic = s390_get_qemu_flic(s390_get_flic());
|
2017-09-28 23:36:42 +03:00
|
|
|
CPUS390XState *env = &cpu->env;
|
|
|
|
|
|
|
|
if (!(env->psw.mask & PSW_MASK_EXT)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-28 23:36:43 +03:00
|
|
|
if ((env->pending_int & INTERRUPT_EMERGENCY_SIGNAL) &&
|
|
|
|
(env->cregs[0] & CR0_EMERGENCY_SIGNAL_SC)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((env->pending_int & INTERRUPT_EXTERNAL_CALL) &&
|
|
|
|
(env->cregs[0] & CR0_EXTERNAL_CALL_SC)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((env->pending_int & INTERRUPT_EXTERNAL_CALL) &&
|
|
|
|
(env->cregs[0] & CR0_EXTERNAL_CALL_SC)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((env->pending_int & INTERRUPT_EXT_CLOCK_COMPARATOR) &&
|
|
|
|
(env->cregs[0] & CR0_CKC_SC)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((env->pending_int & INTERRUPT_EXT_CPU_TIMER) &&
|
|
|
|
(env->cregs[0] & CR0_CPU_TIMER_SC)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-01-29 15:56:13 +03:00
|
|
|
if (qemu_s390_flic_has_service(flic) &&
|
2017-09-28 23:36:43 +03:00
|
|
|
(env->cregs[0] & CR0_SERVICE_SC)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2017-09-28 23:36:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool s390_cpu_has_io_int(S390CPU *cpu)
|
|
|
|
{
|
2018-01-29 15:56:21 +03:00
|
|
|
QEMUS390FLICState *flic = s390_get_qemu_flic(s390_get_flic());
|
2017-09-28 23:36:42 +03:00
|
|
|
CPUS390XState *env = &cpu->env;
|
|
|
|
|
|
|
|
if (!(env->psw.mask & PSW_MASK_IO)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-29 15:56:13 +03:00
|
|
|
return qemu_s390_flic_has_io(flic, env->cregs[6]);
|
2017-09-28 23:36:42 +03:00
|
|
|
}
|
2017-09-28 23:37:02 +03:00
|
|
|
|
|
|
|
bool s390_cpu_has_restart_int(S390CPU *cpu)
|
|
|
|
{
|
|
|
|
CPUS390XState *env = &cpu->env;
|
|
|
|
|
|
|
|
return env->pending_int & INTERRUPT_RESTART;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool s390_cpu_has_stop_int(S390CPU *cpu)
|
|
|
|
{
|
|
|
|
CPUS390XState *env = &cpu->env;
|
|
|
|
|
|
|
|
return env->pending_int & INTERRUPT_STOP;
|
|
|
|
}
|
2012-07-24 01:37:05 +04:00
|
|
|
#endif
|
2017-09-28 23:36:42 +03:00
|
|
|
|
|
|
|
bool s390_cpu_has_int(S390CPU *cpu)
|
|
|
|
{
|
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
if (!tcg_enabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return s390_cpu_has_mcck_int(cpu) ||
|
|
|
|
s390_cpu_has_ext_int(cpu) ||
|
2017-09-28 23:37:02 +03:00
|
|
|
s390_cpu_has_io_int(cpu) ||
|
|
|
|
s390_cpu_has_restart_int(cpu) ||
|
|
|
|
s390_cpu_has_stop_int(cpu);
|
2017-09-28 23:36:42 +03:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|