irq.c 2.3 KB

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