irqflags.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. #ifndef _X86_IRQFLAGS_H_
  2. #define _X86_IRQFLAGS_H_
  3. #include <asm/processor-flags.h>
  4. #ifndef __ASSEMBLY__
  5. /*
  6. * Interrupt control:
  7. */
  8. static inline unsigned long native_save_fl(void)
  9. {
  10. unsigned long flags;
  11. asm volatile("# __raw_save_flags\n\t"
  12. "pushf ; pop %0"
  13. : "=g" (flags)
  14. : /* no input */
  15. : "memory");
  16. return flags;
  17. }
  18. static inline void native_restore_fl(unsigned long flags)
  19. {
  20. asm volatile("push %0 ; popf"
  21. : /* no output */
  22. :"g" (flags)
  23. :"memory", "cc");
  24. }
  25. static inline void native_irq_disable(void)
  26. {
  27. asm volatile("cli": : :"memory");
  28. }
  29. static inline void native_irq_enable(void)
  30. {
  31. asm volatile("sti": : :"memory");
  32. }
  33. static inline void native_safe_halt(void)
  34. {
  35. asm volatile("sti; hlt": : :"memory");
  36. }
  37. static inline void native_halt(void)
  38. {
  39. asm volatile("hlt": : :"memory");
  40. }
  41. #endif
  42. #ifdef CONFIG_PARAVIRT
  43. #include <asm/paravirt.h>
  44. #else
  45. #ifndef __ASSEMBLY__
  46. static inline unsigned long __raw_local_save_flags(void)
  47. {
  48. return native_save_fl();
  49. }
  50. static inline void raw_local_irq_restore(unsigned long flags)
  51. {
  52. native_restore_fl(flags);
  53. }
  54. static inline void raw_local_irq_disable(void)
  55. {
  56. native_irq_disable();
  57. }
  58. static inline void raw_local_irq_enable(void)
  59. {
  60. native_irq_enable();
  61. }
  62. /*
  63. * Used in the idle loop; sti takes one instruction cycle
  64. * to complete:
  65. */
  66. static inline void raw_safe_halt(void)
  67. {
  68. native_safe_halt();
  69. }
  70. /*
  71. * Used when interrupts are already enabled or to
  72. * shutdown the processor:
  73. */
  74. static inline void halt(void)
  75. {
  76. native_halt();
  77. }
  78. /*
  79. * For spinlocks, etc:
  80. */
  81. static inline unsigned long __raw_local_irq_save(void)
  82. {
  83. unsigned long flags = __raw_local_save_flags();
  84. raw_local_irq_disable();
  85. return flags;
  86. }
  87. #else
  88. #define ENABLE_INTERRUPTS(x) sti
  89. #define DISABLE_INTERRUPTS(x) cli
  90. #ifdef CONFIG_X86_64
  91. #define SWAPGS swapgs
  92. /*
  93. * Currently paravirt can't handle swapgs nicely when we
  94. * don't have a stack we can rely on (such as a user space
  95. * stack). So we either find a way around these or just fault
  96. * and emulate if a guest tries to call swapgs directly.
  97. *
  98. * Either way, this is a good way to document that we don't
  99. * have a reliable stack. x86_64 only.
  100. */
  101. #define SWAPGS_UNSAFE_STACK swapgs
  102. #define PARAVIRT_ADJUST_EXCEPTION_FRAME /* */
  103. #define INTERRUPT_RETURN iretq
  104. #define USERGS_SYSRET64 \
  105. swapgs; \
  106. sysretq;
  107. #define USERGS_SYSRET32 \
  108. swapgs; \
  109. sysretl
  110. #define ENABLE_INTERRUPTS_SYSEXIT32 \
  111. swapgs; \
  112. sti; \
  113. sysexit
  114. #else
  115. #define INTERRUPT_RETURN iret
  116. #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
  117. #define GET_CR0_INTO_EAX movl %cr0, %eax
  118. #endif
  119. #endif /* __ASSEMBLY__ */
  120. #endif /* CONFIG_PARAVIRT */
  121. #ifndef __ASSEMBLY__
  122. #define raw_local_save_flags(flags) \
  123. do { (flags) = __raw_local_save_flags(); } while (0)
  124. #define raw_local_irq_save(flags) \
  125. do { (flags) = __raw_local_irq_save(); } while (0)
  126. static inline int raw_irqs_disabled_flags(unsigned long flags)
  127. {
  128. return !(flags & X86_EFLAGS_IF);
  129. }
  130. static inline int raw_irqs_disabled(void)
  131. {
  132. unsigned long flags = __raw_local_save_flags();
  133. return raw_irqs_disabled_flags(flags);
  134. }
  135. /*
  136. * makes the traced hardirq state match with the machine state
  137. *
  138. * should be a rarely used function, only in places where its
  139. * otherwise impossible to know the irq state, like in traps.
  140. */
  141. static inline void trace_hardirqs_fixup_flags(unsigned long flags)
  142. {
  143. if (raw_irqs_disabled_flags(flags))
  144. trace_hardirqs_off();
  145. else
  146. trace_hardirqs_on();
  147. }
  148. static inline void trace_hardirqs_fixup(void)
  149. {
  150. unsigned long flags = __raw_local_save_flags();
  151. trace_hardirqs_fixup_flags(flags);
  152. }
  153. #else
  154. #ifdef CONFIG_X86_64
  155. #define ARCH_TRACE_IRQS_ON call trace_hardirqs_on_thunk
  156. #define ARCH_TRACE_IRQS_OFF call trace_hardirqs_off_thunk
  157. #define ARCH_LOCKDEP_SYS_EXIT call lockdep_sys_exit_thunk
  158. #define ARCH_LOCKDEP_SYS_EXIT_IRQ \
  159. TRACE_IRQS_ON; \
  160. sti; \
  161. SAVE_REST; \
  162. LOCKDEP_SYS_EXIT; \
  163. RESTORE_REST; \
  164. cli; \
  165. TRACE_IRQS_OFF;
  166. #else
  167. #define ARCH_TRACE_IRQS_ON \
  168. pushl %eax; \
  169. pushl %ecx; \
  170. pushl %edx; \
  171. call trace_hardirqs_on; \
  172. popl %edx; \
  173. popl %ecx; \
  174. popl %eax;
  175. #define ARCH_TRACE_IRQS_OFF \
  176. pushl %eax; \
  177. pushl %ecx; \
  178. pushl %edx; \
  179. call trace_hardirqs_off; \
  180. popl %edx; \
  181. popl %ecx; \
  182. popl %eax;
  183. #define ARCH_LOCKDEP_SYS_EXIT \
  184. pushl %eax; \
  185. pushl %ecx; \
  186. pushl %edx; \
  187. call lockdep_sys_exit; \
  188. popl %edx; \
  189. popl %ecx; \
  190. popl %eax;
  191. #define ARCH_LOCKDEP_SYS_EXIT_IRQ
  192. #endif
  193. #ifdef CONFIG_TRACE_IRQFLAGS
  194. # define TRACE_IRQS_ON ARCH_TRACE_IRQS_ON
  195. # define TRACE_IRQS_OFF ARCH_TRACE_IRQS_OFF
  196. #else
  197. # define TRACE_IRQS_ON
  198. # define TRACE_IRQS_OFF
  199. #endif
  200. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  201. # define LOCKDEP_SYS_EXIT ARCH_LOCKDEP_SYS_EXIT
  202. # define LOCKDEP_SYS_EXIT_IRQ ARCH_LOCKDEP_SYS_EXIT_IRQ
  203. # else
  204. # define LOCKDEP_SYS_EXIT
  205. # define LOCKDEP_SYS_EXIT_IRQ
  206. # endif
  207. #endif /* __ASSEMBLY__ */
  208. #endif