block: report errno when flock fcntl fails
[qemu/ar7.git] / target / s390x / interrupt.c
blob4cdbbc8849a2109195a74a6d6f37180f259b5bd8
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 "qemu/log.h"
12 #include "cpu.h"
13 #include "kvm_s390x.h"
14 #include "internal.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"
22 #endif
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)
36 if (kvm_enabled()) {
37 kvm_s390_program_interrupt(env_archcpu(env), code);
38 } else if (tcg_enabled()) {
39 tcg_s390_program_interrupt(env, code, ra);
40 } else {
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) {
79 return -EBUSY;
81 env->external_call_addr = src_cpu_addr;
83 env->pending_int |= INTERRUPT_EXTERNAL_CALL;
84 cpu_interrupt(CPU(cpu), CPU_INTERRUPT_HARD);
85 return 0;
88 void cpu_inject_restart(S390CPU *cpu)
90 CPUS390XState *env = &cpu->env;
92 if (kvm_enabled()) {
93 kvm_s390_restart_interrupt(cpu);
94 return;
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;
105 if (kvm_enabled()) {
106 kvm_s390_stop_interrupt(cpu);
107 return;
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
117 * non-kvm case.
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)) {
150 return false;
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)) {
156 return true;
159 return false;
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)) {
168 return false;
171 if ((env->pending_int & INTERRUPT_EMERGENCY_SIGNAL) &&
172 (env->cregs[0] & CR0_EMERGENCY_SIGNAL_SC)) {
173 return true;
176 if ((env->pending_int & INTERRUPT_EXTERNAL_CALL) &&
177 (env->cregs[0] & CR0_EXTERNAL_CALL_SC)) {
178 return true;
181 if ((env->pending_int & INTERRUPT_EXTERNAL_CALL) &&
182 (env->cregs[0] & CR0_EXTERNAL_CALL_SC)) {
183 return true;
186 if ((env->pending_int & INTERRUPT_EXT_CLOCK_COMPARATOR) &&
187 (env->cregs[0] & CR0_CKC_SC)) {
188 return true;
191 if ((env->pending_int & INTERRUPT_EXT_CPU_TIMER) &&
192 (env->cregs[0] & CR0_CPU_TIMER_SC)) {
193 return true;
196 if (qemu_s390_flic_has_service(flic) &&
197 (env->cregs[0] & CR0_SERVICE_SC)) {
198 return true;
201 return false;
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)) {
210 return false;
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;
229 #endif
231 bool s390_cpu_has_int(S390CPU *cpu)
233 #ifndef CONFIG_USER_ONLY
234 if (!tcg_enabled()) {
235 return false;
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);
242 #else
243 return false;
244 #endif