irq.c 3.3 KB

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