irq.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #include <linux/hardirq.h>
  2. #include <xen/interface/xen.h>
  3. #include <xen/interface/sched.h>
  4. #include <xen/interface/vcpu.h>
  5. #include <asm/xen/hypercall.h>
  6. #include <asm/xen/hypervisor.h>
  7. #include "xen-ops.h"
  8. /*
  9. * Force a proper event-channel callback from Xen after clearing the
  10. * callback mask. We do this in a very simple manner, by making a call
  11. * down into Xen. The pending flag will be checked by Xen on return.
  12. */
  13. void xen_force_evtchn_callback(void)
  14. {
  15. (void)HYPERVISOR_xen_version(0, NULL);
  16. }
  17. static void __init __xen_init_IRQ(void)
  18. {
  19. int i;
  20. /* Create identity vector->irq map */
  21. for(i = 0; i < NR_VECTORS; i++) {
  22. int cpu;
  23. for_each_possible_cpu(cpu)
  24. per_cpu(vector_irq, cpu)[i] = i;
  25. }
  26. xen_init_IRQ();
  27. }
  28. static unsigned long xen_save_fl(void)
  29. {
  30. struct vcpu_info *vcpu;
  31. unsigned long flags;
  32. vcpu = x86_read_percpu(xen_vcpu);
  33. /* flag has opposite sense of mask */
  34. flags = !vcpu->evtchn_upcall_mask;
  35. /* convert to IF type flag
  36. -0 -> 0x00000000
  37. -1 -> 0xffffffff
  38. */
  39. return (-flags) & X86_EFLAGS_IF;
  40. }
  41. static void xen_restore_fl(unsigned long flags)
  42. {
  43. struct vcpu_info *vcpu;
  44. /* convert from IF type flag */
  45. flags = !(flags & X86_EFLAGS_IF);
  46. /* There's a one instruction preempt window here. We need to
  47. make sure we're don't switch CPUs between getting the vcpu
  48. pointer and updating the mask. */
  49. preempt_disable();
  50. vcpu = x86_read_percpu(xen_vcpu);
  51. vcpu->evtchn_upcall_mask = flags;
  52. preempt_enable_no_resched();
  53. /* Doesn't matter if we get preempted here, because any
  54. pending event will get dealt with anyway. */
  55. if (flags == 0) {
  56. preempt_check_resched();
  57. barrier(); /* unmask then check (avoid races) */
  58. if (unlikely(vcpu->evtchn_upcall_pending))
  59. xen_force_evtchn_callback();
  60. }
  61. }
  62. static void xen_irq_disable(void)
  63. {
  64. /* There's a one instruction preempt window here. We need to
  65. make sure we're don't switch CPUs between getting the vcpu
  66. pointer and updating the mask. */
  67. preempt_disable();
  68. x86_read_percpu(xen_vcpu)->evtchn_upcall_mask = 1;
  69. preempt_enable_no_resched();
  70. }
  71. static void xen_irq_enable(void)
  72. {
  73. struct vcpu_info *vcpu;
  74. /* We don't need to worry about being preempted here, since
  75. either a) interrupts are disabled, so no preemption, or b)
  76. the caller is confused and is trying to re-enable interrupts
  77. on an indeterminate processor. */
  78. vcpu = x86_read_percpu(xen_vcpu);
  79. vcpu->evtchn_upcall_mask = 0;
  80. /* Doesn't matter if we get preempted here, because any
  81. pending event will get dealt with anyway. */
  82. barrier(); /* unmask then check (avoid races) */
  83. if (unlikely(vcpu->evtchn_upcall_pending))
  84. xen_force_evtchn_callback();
  85. }
  86. static void xen_safe_halt(void)
  87. {
  88. /* Blocking includes an implicit local_irq_enable(). */
  89. if (HYPERVISOR_sched_op(SCHEDOP_block, NULL) != 0)
  90. BUG();
  91. }
  92. static void xen_halt(void)
  93. {
  94. if (irqs_disabled())
  95. HYPERVISOR_vcpu_op(VCPUOP_down, smp_processor_id(), NULL);
  96. else
  97. xen_safe_halt();
  98. }
  99. static const struct pv_irq_ops xen_irq_ops __initdata = {
  100. .init_IRQ = __xen_init_IRQ,
  101. .save_fl = xen_save_fl,
  102. .restore_fl = xen_restore_fl,
  103. .irq_disable = xen_irq_disable,
  104. .irq_enable = xen_irq_enable,
  105. .safe_halt = xen_safe_halt,
  106. .halt = xen_halt,
  107. #ifdef CONFIG_X86_64
  108. .adjust_exception_frame = xen_adjust_exception_frame,
  109. #endif
  110. };
  111. void __init xen_init_irq_ops()
  112. {
  113. pv_irq_ops = xen_irq_ops;
  114. }