irqflags_64.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * include/asm/irqflags.h
  3. *
  4. * IRQ flags handling
  5. *
  6. * This file gets included from lowlevel asm headers too, to provide
  7. * wrapped versions of the local_irq_*() APIs, based on the
  8. * raw_local_irq_*() functions from the lowlevel headers.
  9. */
  10. #ifndef _ASM_IRQFLAGS_H
  11. #define _ASM_IRQFLAGS_H
  12. #include <asm/pil.h>
  13. #ifndef __ASSEMBLY__
  14. static inline unsigned long __raw_local_save_flags(void)
  15. {
  16. unsigned long flags;
  17. __asm__ __volatile__(
  18. "rdpr %%pil, %0"
  19. : "=r" (flags)
  20. );
  21. return flags;
  22. }
  23. #define raw_local_save_flags(flags) \
  24. do { (flags) = __raw_local_save_flags(); } while (0)
  25. static inline void raw_local_irq_restore(unsigned long flags)
  26. {
  27. __asm__ __volatile__(
  28. "wrpr %0, %%pil"
  29. : /* no output */
  30. : "r" (flags)
  31. : "memory"
  32. );
  33. }
  34. static inline void raw_local_irq_disable(void)
  35. {
  36. __asm__ __volatile__(
  37. "wrpr %0, %%pil"
  38. : /* no outputs */
  39. : "i" (PIL_NORMAL_MAX)
  40. : "memory"
  41. );
  42. }
  43. static inline void raw_local_irq_enable(void)
  44. {
  45. __asm__ __volatile__(
  46. "wrpr 0, %%pil"
  47. : /* no outputs */
  48. : /* no inputs */
  49. : "memory"
  50. );
  51. }
  52. static inline int raw_irqs_disabled_flags(unsigned long flags)
  53. {
  54. return (flags > 0);
  55. }
  56. static inline int raw_irqs_disabled(void)
  57. {
  58. unsigned long flags = __raw_local_save_flags();
  59. return raw_irqs_disabled_flags(flags);
  60. }
  61. /*
  62. * For spinlocks, etc:
  63. */
  64. static inline unsigned long __raw_local_irq_save(void)
  65. {
  66. unsigned long flags, tmp;
  67. /* Disable interrupts to PIL_NORMAL_MAX unless we already
  68. * are using PIL_NMI, in which case PIL_NMI is retained.
  69. *
  70. * The only values we ever program into the %pil are 0,
  71. * PIL_NORMAL_MAX and PIL_NMI.
  72. *
  73. * Since PIL_NMI is the largest %pil value and all bits are
  74. * set in it (0xf), it doesn't matter what PIL_NORMAL_MAX
  75. * actually is.
  76. */
  77. __asm__ __volatile__(
  78. "rdpr %%pil, %0\n\t"
  79. "or %0, %2, %1\n\t"
  80. "wrpr %1, 0x0, %%pil"
  81. : "=r" (flags), "=r" (tmp)
  82. : "i" (PIL_NORMAL_MAX)
  83. : "memory"
  84. );
  85. return flags;
  86. }
  87. #define raw_local_irq_save(flags) \
  88. do { (flags) = __raw_local_irq_save(); } while (0)
  89. #endif /* (__ASSEMBLY__) */
  90. #endif /* !(_ASM_IRQFLAGS_H) */