irq.c 3.3 KB

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