Eddie Dong | 85f455f | 2007-07-06 12:20:49 +0300 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 31 | int kvm_cpu_has_interrupt(struct kvm_vcpu *v) |
| 32 | { |
Eddie Dong | 97222cc | 2007-09-12 10:58:04 +0300 | [diff] [blame] | 33 | struct kvm_pic *s; |
Eddie Dong | 85f455f | 2007-07-06 12:20:49 +0300 | [diff] [blame] | 34 | |
Eddie Dong | 97222cc | 2007-09-12 10:58:04 +0300 | [diff] [blame] | 35 | if (kvm_apic_has_interrupt(v) == -1) { /* LAPIC */ |
| 36 | s = pic_irqchip(v->kvm); /* PIC */ |
| 37 | return s->output; |
| 38 | } |
| 39 | return 1; |
Eddie Dong | 85f455f | 2007-07-06 12:20:49 +0300 | [diff] [blame] | 40 | } |
| 41 | EXPORT_SYMBOL_GPL(kvm_cpu_has_interrupt); |
| 42 | |
| 43 | /* |
| 44 | * Read pending interrupt vector and intack. |
| 45 | */ |
| 46 | int kvm_cpu_get_interrupt(struct kvm_vcpu *v) |
| 47 | { |
Eddie Dong | 97222cc | 2007-09-12 10:58:04 +0300 | [diff] [blame] | 48 | struct kvm_pic *s; |
Eddie Dong | 85f455f | 2007-07-06 12:20:49 +0300 | [diff] [blame] | 49 | int vector; |
| 50 | |
Eddie Dong | 97222cc | 2007-09-12 10:58:04 +0300 | [diff] [blame] | 51 | 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 Dong | 85f455f | 2007-07-06 12:20:49 +0300 | [diff] [blame] | 58 | } |
| 59 | EXPORT_SYMBOL_GPL(kvm_cpu_get_interrupt); |
Eddie Dong | 97222cc | 2007-09-12 10:58:04 +0300 | [diff] [blame] | 60 | |
| 61 | static 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 | |
| 69 | void 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 | |