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