irqflags.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (C) 2012 ARM Ltd.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef __ASM_IRQFLAGS_H
  17. #define __ASM_IRQFLAGS_H
  18. #ifdef __KERNEL__
  19. #include <asm/ptrace.h>
  20. /*
  21. * CPU interrupt mask handling.
  22. */
  23. static inline unsigned long arch_local_irq_save(void)
  24. {
  25. unsigned long flags;
  26. asm volatile(
  27. "mrs %0, daif // arch_local_irq_save\n"
  28. "msr daifset, #2"
  29. : "=r" (flags)
  30. :
  31. : "memory");
  32. return flags;
  33. }
  34. static inline void arch_local_irq_enable(void)
  35. {
  36. asm volatile(
  37. "msr daifclr, #2 // arch_local_irq_enable"
  38. :
  39. :
  40. : "memory");
  41. }
  42. static inline void arch_local_irq_disable(void)
  43. {
  44. asm volatile(
  45. "msr daifset, #2 // arch_local_irq_disable"
  46. :
  47. :
  48. : "memory");
  49. }
  50. #define local_fiq_enable() asm("msr daifclr, #1" : : : "memory")
  51. #define local_fiq_disable() asm("msr daifset, #1" : : : "memory")
  52. #define local_async_enable() asm("msr daifclr, #4" : : : "memory")
  53. #define local_async_disable() asm("msr daifset, #4" : : : "memory")
  54. /*
  55. * Save the current interrupt enable state.
  56. */
  57. static inline unsigned long arch_local_save_flags(void)
  58. {
  59. unsigned long flags;
  60. asm volatile(
  61. "mrs %0, daif // arch_local_save_flags"
  62. : "=r" (flags)
  63. :
  64. : "memory");
  65. return flags;
  66. }
  67. /*
  68. * restore saved IRQ state
  69. */
  70. static inline void arch_local_irq_restore(unsigned long flags)
  71. {
  72. asm volatile(
  73. "msr daif, %0 // arch_local_irq_restore"
  74. :
  75. : "r" (flags)
  76. : "memory");
  77. }
  78. static inline int arch_irqs_disabled_flags(unsigned long flags)
  79. {
  80. return flags & PSR_I_BIT;
  81. }
  82. /*
  83. * save and restore debug state
  84. */
  85. #define local_dbg_save(flags) \
  86. do { \
  87. typecheck(unsigned long, flags); \
  88. asm volatile( \
  89. "mrs %0, daif // local_dbg_save\n" \
  90. "msr daifset, #8" \
  91. : "=r" (flags) : : "memory"); \
  92. } while (0)
  93. #define local_dbg_restore(flags) \
  94. do { \
  95. typecheck(unsigned long, flags); \
  96. asm volatile( \
  97. "msr daif, %0 // local_dbg_restore\n" \
  98. : : "r" (flags) : "memory"); \
  99. } while (0)
  100. #define local_dbg_enable() asm("msr daifclr, #8" : : : "memory")
  101. #define local_dbg_disable() asm("msr daifset, #8" : : : "memory")
  102. #endif
  103. #endif