1
0

irqflags.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. * Aarch64 has flags for masking: Debug, Asynchronous (serror), Interrupts and
  22. * FIQ exceptions, in the 'daif' register. We mask and unmask them in 'dai'
  23. * order:
  24. * Masking debug exceptions causes all other exceptions to be masked too/
  25. * Masking SError masks irq, but not debug exceptions. Masking irqs has no
  26. * side effects for other flags. Keeping to this order makes it easier for
  27. * entry.S to know which exceptions should be unmasked.
  28. *
  29. * FIQ is never expected, but we mask it when we disable debug exceptions, and
  30. * unmask it at all other times.
  31. */
  32. /*
  33. * CPU interrupt mask handling.
  34. */
  35. static inline unsigned long arch_local_irq_save(void)
  36. {
  37. unsigned long flags;
  38. asm volatile(
  39. "mrs %0, daif // arch_local_irq_save\n"
  40. "msr daifset, #2"
  41. : "=r" (flags)
  42. :
  43. : "memory");
  44. return flags;
  45. }
  46. static inline void arch_local_irq_enable(void)
  47. {
  48. asm volatile(
  49. "msr daifclr, #2 // arch_local_irq_enable"
  50. :
  51. :
  52. : "memory");
  53. }
  54. static inline void arch_local_irq_disable(void)
  55. {
  56. asm volatile(
  57. "msr daifset, #2 // arch_local_irq_disable"
  58. :
  59. :
  60. : "memory");
  61. }
  62. /*
  63. * Save the current interrupt enable state.
  64. */
  65. static inline unsigned long arch_local_save_flags(void)
  66. {
  67. unsigned long flags;
  68. asm volatile(
  69. "mrs %0, daif // arch_local_save_flags"
  70. : "=r" (flags)
  71. :
  72. : "memory");
  73. return flags;
  74. }
  75. /*
  76. * restore saved IRQ state
  77. */
  78. static inline void arch_local_irq_restore(unsigned long flags)
  79. {
  80. asm volatile(
  81. "msr daif, %0 // arch_local_irq_restore"
  82. :
  83. : "r" (flags)
  84. : "memory");
  85. }
  86. static inline int arch_irqs_disabled_flags(unsigned long flags)
  87. {
  88. return flags & PSR_I_BIT;
  89. }
  90. #endif
  91. #endif