Statistics
| Branch: | Revision:

root / hw / arm / pic_cpu.c @ e03ba136

History | View | Annotate | Download (1.7 kB)

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.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
    CPUState *cs = CPU(cpu);
19

    
20
    switch (irq) {
21
    case ARM_PIC_CPU_IRQ:
22
        if (level) {
23
            cpu_interrupt(cs, CPU_INTERRUPT_HARD);
24
        } else {
25
            cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
26
        }
27
        break;
28
    case ARM_PIC_CPU_FIQ:
29
        if (level) {
30
            cpu_interrupt(cs, CPU_INTERRUPT_FIQ);
31
        } else {
32
            cpu_reset_interrupt(cs, CPU_INTERRUPT_FIQ);
33
        }
34
        break;
35
    default:
36
        hw_error("arm_pic_cpu_handler: Bad interrupt line %d\n", irq);
37
    }
38
}
39

    
40
static void kvm_arm_pic_cpu_handler(void *opaque, int irq, int level)
41
{
42
#ifdef CONFIG_KVM
43
    ARMCPU *cpu = opaque;
44
    CPUState *cs = CPU(cpu);
45
    int kvm_irq = KVM_ARM_IRQ_TYPE_CPU << KVM_ARM_IRQ_TYPE_SHIFT;
46

    
47
    switch (irq) {
48
    case ARM_PIC_CPU_IRQ:
49
        kvm_irq |= KVM_ARM_IRQ_CPU_IRQ;
50
        break;
51
    case ARM_PIC_CPU_FIQ:
52
        kvm_irq |= KVM_ARM_IRQ_CPU_FIQ;
53
        break;
54
    default:
55
        hw_error("kvm_arm_pic_cpu_handler: Bad interrupt line %d\n", irq);
56
    }
57
    kvm_irq |= cs->cpu_index << KVM_ARM_IRQ_VCPU_SHIFT;
58
    kvm_set_irq(kvm_state, kvm_irq, level ? 1 : 0);
59
#endif
60
}
61

    
62
qemu_irq *arm_pic_init_cpu(ARMCPU *cpu)
63
{
64
    if (kvm_enabled()) {
65
        return qemu_allocate_irqs(kvm_arm_pic_cpu_handler, cpu, 2);
66
    }
67
    return qemu_allocate_irqs(arm_pic_cpu_handler, cpu, 2);
68
}