irq.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. #include <linux/module.h>
  22. #include "kvm.h"
  23. #include "x86.h"
  24. #include "irq.h"
  25. /*
  26. * check if there is pending interrupt without
  27. * intack.
  28. */
  29. int kvm_cpu_has_interrupt(struct kvm_vcpu *v)
  30. {
  31. struct kvm_pic *s;
  32. if (kvm_apic_has_interrupt(v) == -1) { /* LAPIC */
  33. if (kvm_apic_accept_pic_intr(v)) {
  34. s = pic_irqchip(v->kvm); /* PIC */
  35. return s->output;
  36. } else
  37. return 0;
  38. }
  39. return 1;
  40. }
  41. EXPORT_SYMBOL_GPL(kvm_cpu_has_interrupt);
  42. /*
  43. * Read pending interrupt vector and intack.
  44. */
  45. int kvm_cpu_get_interrupt(struct kvm_vcpu *v)
  46. {
  47. struct kvm_pic *s;
  48. int vector;
  49. vector = kvm_get_apic_interrupt(v); /* APIC */
  50. if (vector == -1) {
  51. if (kvm_apic_accept_pic_intr(v)) {
  52. s = pic_irqchip(v->kvm);
  53. s->output = 0; /* PIC */
  54. vector = kvm_pic_read_irq(s);
  55. }
  56. }
  57. return vector;
  58. }
  59. EXPORT_SYMBOL_GPL(kvm_cpu_get_interrupt);
  60. static void vcpu_kick_intr(void *info)
  61. {
  62. #ifdef DEBUG
  63. struct kvm_vcpu *vcpu = (struct kvm_vcpu *)info;
  64. printk(KERN_DEBUG "vcpu_kick_intr %p \n", vcpu);
  65. #endif
  66. }
  67. void kvm_vcpu_kick(struct kvm_vcpu *vcpu)
  68. {
  69. int ipi_pcpu = vcpu->cpu;
  70. if (waitqueue_active(&vcpu->wq)) {
  71. wake_up_interruptible(&vcpu->wq);
  72. ++vcpu->stat.halt_wakeup;
  73. }
  74. if (vcpu->guest_mode)
  75. smp_call_function_single(ipi_pcpu, vcpu_kick_intr, vcpu, 0, 0);
  76. }
  77. void kvm_inject_pending_timer_irqs(struct kvm_vcpu *vcpu)
  78. {
  79. kvm_inject_apic_timer_irqs(vcpu);
  80. /* TODO: PIT, RTC etc. */
  81. }
  82. EXPORT_SYMBOL_GPL(kvm_inject_pending_timer_irqs);
  83. void kvm_timer_intr_post(struct kvm_vcpu *vcpu, int vec)
  84. {
  85. kvm_apic_timer_intr_post(vcpu, vec);
  86. /* TODO: PIT, RTC etc. */
  87. }
  88. EXPORT_SYMBOL_GPL(kvm_timer_intr_post);