irqflags.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. /*
  53. * Save the current interrupt enable state.
  54. */
  55. static inline unsigned long arch_local_save_flags(void)
  56. {
  57. unsigned long flags;
  58. asm volatile(
  59. "mrs %0, daif // arch_local_save_flags"
  60. : "=r" (flags)
  61. :
  62. : "memory");
  63. return flags;
  64. }
  65. /*
  66. * restore saved IRQ state
  67. */
  68. static inline void arch_local_irq_restore(unsigned long flags)
  69. {
  70. asm volatile(
  71. "msr daif, %0 // arch_local_irq_restore"
  72. :
  73. : "r" (flags)
  74. : "memory");
  75. }
  76. static inline int arch_irqs_disabled_flags(unsigned long flags)
  77. {
  78. return flags & PSR_I_BIT;
  79. }
  80. #endif
  81. #endif