1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#include "qemu/osdep.h"
24#include "qemu/main-loop.h"
25#include "hw/irq.h"
26#include "hw/mips/cpudevs.h"
27#include "cpu.h"
28#include "sysemu/kvm.h"
29#include "kvm_mips.h"
30
31static void cpu_mips_irq_request(void *opaque, int irq, int level)
32{
33 MIPSCPU *cpu = opaque;
34 CPUMIPSState *env = &cpu->env;
35 CPUState *cs = CPU(cpu);
36 bool locked = false;
37
38 if (irq < 0 || irq > 7) {
39 return;
40 }
41
42
43 if (!qemu_mutex_iothread_locked()) {
44 locked = true;
45 qemu_mutex_lock_iothread();
46 }
47
48 if (level) {
49 env->CP0_Cause |= 1 << (irq + CP0Ca_IP);
50 } else {
51 env->CP0_Cause &= ~(1 << (irq + CP0Ca_IP));
52 }
53
54 if (kvm_enabled() && (irq == 2 || irq == 3)) {
55 kvm_mips_set_interrupt(cpu, irq, level);
56 }
57
58 if (env->CP0_Cause & CP0Ca_IP_mask) {
59 cpu_interrupt(cs, CPU_INTERRUPT_HARD);
60 } else {
61 cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
62 }
63
64 if (locked) {
65 qemu_mutex_unlock_iothread();
66 }
67}
68
69void cpu_mips_irq_init_cpu(MIPSCPU *cpu)
70{
71 CPUMIPSState *env = &cpu->env;
72 qemu_irq *qi;
73 int i;
74
75 qi = qemu_allocate_irqs(cpu_mips_irq_request, cpu, 8);
76 for (i = 0; i < 8; i++) {
77 env->irq[i] = qi[i];
78 }
79 g_free(qi);
80}
81
82void cpu_mips_soft_irq(CPUMIPSState *env, int irq, int level)
83{
84 if (irq < 0 || irq > 2) {
85 return;
86 }
87
88 qemu_set_irq(env->irq[irq], level);
89}
90