blob: 48192d22f36255a95290be281049929d5f054b4b [file] [log] [blame]
Aurelien Jarno7b9cbad2010-03-14 23:30:19 +01001/*
2 * QEMU MIPS interrupt support
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
Peter Maydellc6848222016-01-18 17:35:00 +000023#include "qemu/osdep.h"
Paolo Bonzini83c9f4c2013-02-04 15:40:22 +010024#include "hw/hw.h"
Paolo Bonzini0d09e412013-02-05 17:06:20 +010025#include "hw/mips/cpudevs.h"
ths4de9b242007-01-24 01:47:51 +000026#include "cpu.h"
Sanjay Lalb1bd8b22014-06-17 23:10:34 +010027#include "sysemu/kvm.h"
28#include "kvm_mips.h"
ths4de9b242007-01-24 01:47:51 +000029
pbrookd537cf62007-04-07 18:14:41 +000030static void cpu_mips_irq_request(void *opaque, int irq, int level)
ths4de9b242007-01-24 01:47:51 +000031{
Andreas Färberd8ed8872013-01-17 22:30:20 +010032 MIPSCPU *cpu = opaque;
33 CPUMIPSState *env = &cpu->env;
34 CPUState *cs = CPU(cpu);
ths4de9b242007-01-24 01:47:51 +000035
ths39d51eb2007-03-18 12:43:40 +000036 if (irq < 0 || irq > 7)
ths4de9b242007-01-24 01:47:51 +000037 return;
38
ths4de9b242007-01-24 01:47:51 +000039 if (level) {
ths39d51eb2007-03-18 12:43:40 +000040 env->CP0_Cause |= 1 << (irq + CP0Ca_IP);
Sanjay Lalb1bd8b22014-06-17 23:10:34 +010041
42 if (kvm_enabled() && irq == 2) {
43 kvm_mips_set_interrupt(cpu, irq, level);
44 }
45
ths4de9b242007-01-24 01:47:51 +000046 } else {
thsa4bc3af2007-03-31 16:54:14 +000047 env->CP0_Cause &= ~(1 << (irq + CP0Ca_IP));
Sanjay Lalb1bd8b22014-06-17 23:10:34 +010048
49 if (kvm_enabled() && irq == 2) {
50 kvm_mips_set_interrupt(cpu, irq, level);
51 }
ths4de9b242007-01-24 01:47:51 +000052 }
Edgar E. Iglesias36388312010-07-24 13:40:05 +020053
54 if (env->CP0_Cause & CP0Ca_IP_mask) {
Andreas Färberc3affe52013-01-18 15:03:43 +010055 cpu_interrupt(cs, CPU_INTERRUPT_HARD);
Edgar E. Iglesias36388312010-07-24 13:40:05 +020056 } else {
Andreas Färberd8ed8872013-01-17 22:30:20 +010057 cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
Edgar E. Iglesias36388312010-07-24 13:40:05 +020058 }
ths4de9b242007-01-24 01:47:51 +000059}
pbrookd537cf62007-04-07 18:14:41 +000060
Paolo Bonzini5a975d42016-03-15 14:32:19 +010061void cpu_mips_irq_init_cpu(MIPSCPU *cpu)
pbrookd537cf62007-04-07 18:14:41 +000062{
Paolo Bonzini5a975d42016-03-15 14:32:19 +010063 CPUMIPSState *env = &cpu->env;
pbrookd537cf62007-04-07 18:14:41 +000064 qemu_irq *qi;
65 int i;
66
Andreas Färberd8ed8872013-01-17 22:30:20 +010067 qi = qemu_allocate_irqs(cpu_mips_irq_request, mips_env_get_cpu(env), 8);
pbrookd537cf62007-04-07 18:14:41 +000068 for (i = 0; i < 8; i++) {
69 env->irq[i] = qi[i];
70 }
71}
Aurelien Jarno5dc5d9f2010-07-25 16:51:29 +020072
Andreas Färber61c56c82012-03-14 01:38:23 +010073void cpu_mips_soft_irq(CPUMIPSState *env, int irq, int level)
Aurelien Jarno5dc5d9f2010-07-25 16:51:29 +020074{
75 if (irq < 0 || irq > 2) {
76 return;
77 }
78
79 qemu_set_irq(env->irq[irq], level);
80}