]> git.proxmox.com Git - qemu.git/blob - hw/arm/pic_cpu.c
Merge remote-tracking branch 'bonzini/hw-dirs' into staging
[qemu.git] / hw / arm / pic_cpu.c
1 /*
2 * Generic ARM Programmable Interrupt Controller support.
3 *
4 * Copyright (c) 2006 CodeSourcery.
5 * Written by Paul Brook
6 *
7 * This code is licensed under the LGPL
8 */
9
10 #include "hw/hw.h"
11 #include "hw/arm-misc.h"
12 #include "sysemu/kvm.h"
13
14 /* Input 0 is IRQ and input 1 is FIQ. */
15 static void arm_pic_cpu_handler(void *opaque, int irq, int level)
16 {
17 ARMCPU *cpu = opaque;
18 CPUARMState *env = &cpu->env;
19
20 switch (irq) {
21 case ARM_PIC_CPU_IRQ:
22 if (level)
23 cpu_interrupt(env, CPU_INTERRUPT_HARD);
24 else
25 cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
26 break;
27 case ARM_PIC_CPU_FIQ:
28 if (level)
29 cpu_interrupt(env, CPU_INTERRUPT_FIQ);
30 else
31 cpu_reset_interrupt(env, CPU_INTERRUPT_FIQ);
32 break;
33 default:
34 hw_error("arm_pic_cpu_handler: Bad interrupt line %d\n", irq);
35 }
36 }
37
38 static void kvm_arm_pic_cpu_handler(void *opaque, int irq, int level)
39 {
40 #ifdef CONFIG_KVM
41 ARMCPU *cpu = opaque;
42 CPUState *cs = CPU(cpu);
43 int kvm_irq = KVM_ARM_IRQ_TYPE_CPU << KVM_ARM_IRQ_TYPE_SHIFT;
44
45 switch (irq) {
46 case ARM_PIC_CPU_IRQ:
47 kvm_irq |= KVM_ARM_IRQ_CPU_IRQ;
48 break;
49 case ARM_PIC_CPU_FIQ:
50 kvm_irq |= KVM_ARM_IRQ_CPU_FIQ;
51 break;
52 default:
53 hw_error("kvm_arm_pic_cpu_handler: Bad interrupt line %d\n", irq);
54 }
55 kvm_irq |= cs->cpu_index << KVM_ARM_IRQ_VCPU_SHIFT;
56 kvm_set_irq(kvm_state, kvm_irq, level ? 1 : 0);
57 #endif
58 }
59
60 qemu_irq *arm_pic_init_cpu(ARMCPU *cpu)
61 {
62 if (kvm_enabled()) {
63 return qemu_allocate_irqs(kvm_arm_pic_cpu_handler, cpu, 2);
64 }
65 return qemu_allocate_irqs(arm_pic_cpu_handler, cpu, 2);
66 }