blob: 5265f8267b3b6e08e131c36c1aca443e929e60bf [file] [log] [blame]
Eddie Dong85f455f2007-07-06 12:20:49 +03001/*
2 * irq.c: API for in kernel interrupt controller
3 * Copyright (c) 2007, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16 * Place - Suite 330, Boston, MA 02111-1307 USA.
17 * Authors:
18 * Yaozu (Eddie) Dong <Eddie.dong@intel.com>
19 *
20 */
21
22#include <linux/module.h>
23
24#include "kvm.h"
25#include "irq.h"
26
27/*
28 * check if there is pending interrupt without
29 * intack.
30 */
31int kvm_cpu_has_interrupt(struct kvm_vcpu *v)
32{
Eddie Dong97222cc2007-09-12 10:58:04 +030033 struct kvm_pic *s;
Eddie Dong85f455f2007-07-06 12:20:49 +030034
Eddie Dong97222cc2007-09-12 10:58:04 +030035 if (kvm_apic_has_interrupt(v) == -1) { /* LAPIC */
36 s = pic_irqchip(v->kvm); /* PIC */
37 return s->output;
38 }
39 return 1;
Eddie Dong85f455f2007-07-06 12:20:49 +030040}
41EXPORT_SYMBOL_GPL(kvm_cpu_has_interrupt);
42
43/*
44 * Read pending interrupt vector and intack.
45 */
46int kvm_cpu_get_interrupt(struct kvm_vcpu *v)
47{
Eddie Dong97222cc2007-09-12 10:58:04 +030048 struct kvm_pic *s;
Eddie Dong85f455f2007-07-06 12:20:49 +030049 int vector;
50
Eddie Dong97222cc2007-09-12 10:58:04 +030051 vector = kvm_get_apic_interrupt(v); /* APIC */
52 if (vector == -1) {
53 s = pic_irqchip(v->kvm);
54 s->output = 0; /* PIC */
55 vector = kvm_pic_read_irq(s);
56 }
57 return vector;
Eddie Dong85f455f2007-07-06 12:20:49 +030058}
59EXPORT_SYMBOL_GPL(kvm_cpu_get_interrupt);
Eddie Dong97222cc2007-09-12 10:58:04 +030060
61static void vcpu_kick_intr(void *info)
62{
63#ifdef DEBUG
64 struct kvm_vcpu *vcpu = (struct kvm_vcpu *)info;
65 printk(KERN_DEBUG "vcpu_kick_intr %p \n", vcpu);
66#endif
67}
68
69void kvm_vcpu_kick(struct kvm_vcpu *vcpu)
70{
71 int ipi_pcpu = vcpu->cpu;
72
73 if (vcpu->guest_mode)
74 smp_call_function_single(ipi_pcpu, vcpu_kick_intr, vcpu, 0, 0);
75}
76