irq.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 = percpu_read(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. PV_CALLEE_SAVE_REGS_THUNK(xen_save_fl);
  42. static void xen_restore_fl(unsigned long flags)
  43. {
  44. struct vcpu_info *vcpu;
  45. /* convert from IF type flag */
  46. flags = !(flags & X86_EFLAGS_IF);
  47. /* There's a one instruction preempt window here. We need to
  48. make sure we're don't switch CPUs between getting the vcpu
  49. pointer and updating the mask. */
  50. preempt_disable();
  51. vcpu = percpu_read(xen_vcpu);
  52. vcpu->evtchn_upcall_mask = flags;
  53. preempt_enable_no_resched();
  54. /* Doesn't matter if we get preempted here, because any
  55. pending event will get dealt with anyway. */
  56. if (flags == 0) {
  57. preempt_check_resched();
  58. barrier(); /* unmask then check (avoid races) */
  59. if (unlikely(vcpu->evtchn_upcall_pending))
  60. xen_force_evtchn_callback();
  61. }
  62. }
  63. PV_CALLEE_SAVE_REGS_THUNK(xen_restore_fl);
  64. static void xen_irq_disable(void)
  65. {
  66. /* There's a one instruction preempt window here. We need to
  67. make sure we're don't switch CPUs between getting the vcpu
  68. pointer and updating the mask. */
  69. preempt_disable();
  70. percpu_read(xen_vcpu)->evtchn_upcall_mask = 1;
  71. preempt_enable_no_resched();
  72. }
  73. PV_CALLEE_SAVE_REGS_THUNK(xen_irq_disable);
  74. static void xen_irq_enable(void)
  75. {
  76. struct vcpu_info *vcpu;
  77. /* We don't need to worry about being preempted here, since
  78. either a) interrupts are disabled, so no preemption, or b)
  79. the caller is confused and is trying to re-enable interrupts
  80. on an indeterminate processor. */
  81. vcpu = percpu_read(xen_vcpu);
  82. vcpu->evtchn_upcall_mask = 0;
  83. /* Doesn't matter if we get preempted here, because any
  84. pending event will get dealt with anyway. */
  85. barrier(); /* unmask then check (avoid races) */
  86. if (unlikely(vcpu->evtchn_upcall_pending))
  87. xen_force_evtchn_callback();
  88. }
  89. PV_CALLEE_SAVE_REGS_THUNK(xen_irq_enable);
  90. static void xen_safe_halt(void)
  91. {
  92. /* Blocking includes an implicit local_irq_enable(). */
  93. if (HYPERVISOR_sched_op(SCHEDOP_block, NULL) != 0)
  94. BUG();
  95. }
  96. static void xen_halt(void)
  97. {
  98. if (irqs_disabled())
  99. HYPERVISOR_vcpu_op(VCPUOP_down, smp_processor_id(), NULL);
  100. else
  101. xen_safe_halt();
  102. }
  103. static const struct pv_irq_ops xen_irq_ops __initdata = {
  104. .init_IRQ = __xen_init_IRQ,
  105. .save_fl = PV_CALLEE_SAVE(xen_save_fl),
  106. .restore_fl = PV_CALLEE_SAVE(xen_restore_fl),
  107. .irq_disable = PV_CALLEE_SAVE(xen_irq_disable),
  108. .irq_enable = PV_CALLEE_SAVE(xen_irq_enable),
  109. .safe_halt = xen_safe_halt,
  110. .halt = xen_halt,
  111. #ifdef CONFIG_X86_64
  112. .adjust_exception_frame = xen_adjust_exception_frame,
  113. #endif
  114. };
  115. void __init xen_init_irq_ops()
  116. {
  117. pv_irq_ops = xen_irq_ops;
  118. }