irqflags-compact.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2014-15 Synopsys, Inc. (www.synopsys.com)
  4. * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
  5. */
  6. #ifndef __ASM_IRQFLAGS_ARCOMPACT_H
  7. #define __ASM_IRQFLAGS_ARCOMPACT_H
  8. /* vineetg: March 2010 : local_irq_save( ) optimisation
  9. * -Remove explicit mov of current status32 into reg, that is not needed
  10. * -Use BIC insn instead of INVERTED + AND
  11. * -Conditionally disable interrupts (if they are not enabled, don't disable)
  12. */
  13. #include <asm/arcregs.h>
  14. /* status32 Reg bits related to Interrupt Handling */
  15. #define STATUS_E1_BIT 1 /* Int 1 enable */
  16. #define STATUS_E2_BIT 2 /* Int 2 enable */
  17. #define STATUS_A1_BIT 3 /* Int 1 active */
  18. #define STATUS_A2_BIT 4 /* Int 2 active */
  19. #define STATUS_AE_BIT 5 /* Exception active */
  20. #define STATUS_E1_MASK (1<<STATUS_E1_BIT)
  21. #define STATUS_E2_MASK (1<<STATUS_E2_BIT)
  22. #define STATUS_A1_MASK (1<<STATUS_A1_BIT)
  23. #define STATUS_A2_MASK (1<<STATUS_A2_BIT)
  24. #define STATUS_AE_MASK (1<<STATUS_AE_BIT)
  25. #define STATUS_IE_MASK (STATUS_E1_MASK | STATUS_E2_MASK)
  26. /* Other Interrupt Handling related Aux regs */
  27. #define AUX_IRQ_LEV 0x200 /* IRQ Priority: L1 or L2 */
  28. #define AUX_IRQ_HINT 0x201 /* For generating Soft Interrupts */
  29. #define AUX_IRQ_LV12 0x43 /* interrupt level register */
  30. #define AUX_IENABLE 0x40c
  31. #define AUX_ITRIGGER 0x40d
  32. #define AUX_IPULSE 0x415
  33. #define ISA_INIT_STATUS_BITS STATUS_IE_MASK
  34. #ifndef __ASSEMBLY__
  35. /******************************************************************
  36. * IRQ Control Macros
  37. *
  38. * All of them have "memory" clobber (compiler barrier) which is needed to
  39. * ensure that LD/ST requiring irq safetly (R-M-W when LLSC is not available)
  40. * are redone after IRQs are re-enabled (and gcc doesn't reuse stale register)
  41. *
  42. * Noted at the time of Abilis Timer List corruption
  43. *
  44. * Orig Bug + Rejected solution:
  45. * https://lore.kernel.org/lkml/[email protected]
  46. *
  47. * Reasoning:
  48. * https://lore.kernel.org/lkml/CA+55aFyFWjpSVQM6M266tKrG_ZXJzZ-nYejpmXYQXbrr42mGPQ@mail.gmail.com
  49. *
  50. ******************************************************************/
  51. /*
  52. * Save IRQ state and disable IRQs
  53. */
  54. static inline long arch_local_irq_save(void)
  55. {
  56. unsigned long temp, flags;
  57. __asm__ __volatile__(
  58. " lr %1, [status32] \n"
  59. " bic %0, %1, %2 \n"
  60. " and.f 0, %1, %2 \n"
  61. " flag.nz %0 \n"
  62. : "=r"(temp), "=r"(flags)
  63. : "n"((STATUS_E1_MASK | STATUS_E2_MASK))
  64. : "memory", "cc");
  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. " flag %0 \n"
  74. :
  75. : "r"(flags)
  76. : "memory");
  77. }
  78. /*
  79. * Unconditionally Enable IRQs
  80. */
  81. #ifdef CONFIG_ARC_COMPACT_IRQ_LEVELS
  82. extern void arch_local_irq_enable(void);
  83. #else
  84. static inline void arch_local_irq_enable(void)
  85. {
  86. unsigned long temp;
  87. __asm__ __volatile__(
  88. " lr %0, [status32] \n"
  89. " or %0, %0, %1 \n"
  90. " flag %0 \n"
  91. : "=&r"(temp)
  92. : "n"((STATUS_E1_MASK | STATUS_E2_MASK))
  93. : "cc", "memory");
  94. }
  95. #endif
  96. /*
  97. * Unconditionally Disable IRQs
  98. */
  99. static inline void arch_local_irq_disable(void)
  100. {
  101. unsigned long temp;
  102. __asm__ __volatile__(
  103. " lr %0, [status32] \n"
  104. " and %0, %0, %1 \n"
  105. " flag %0 \n"
  106. : "=&r"(temp)
  107. : "n"(~(STATUS_E1_MASK | STATUS_E2_MASK))
  108. : "memory");
  109. }
  110. /*
  111. * save IRQ state
  112. */
  113. static inline long arch_local_save_flags(void)
  114. {
  115. unsigned long temp;
  116. __asm__ __volatile__(
  117. " lr %0, [status32] \n"
  118. : "=&r"(temp)
  119. :
  120. : "memory");
  121. return temp;
  122. }
  123. /*
  124. * Query IRQ state
  125. */
  126. static inline int arch_irqs_disabled_flags(unsigned long flags)
  127. {
  128. return !(flags & (STATUS_E1_MASK
  129. #ifdef CONFIG_ARC_COMPACT_IRQ_LEVELS
  130. | STATUS_E2_MASK
  131. #endif
  132. ));
  133. }
  134. static inline int arch_irqs_disabled(void)
  135. {
  136. return arch_irqs_disabled_flags(arch_local_save_flags());
  137. }
  138. #else
  139. #ifdef CONFIG_TRACE_IRQFLAGS
  140. .macro TRACE_ASM_IRQ_DISABLE
  141. bl trace_hardirqs_off
  142. .endm
  143. .macro TRACE_ASM_IRQ_ENABLE
  144. bl trace_hardirqs_on
  145. .endm
  146. #else
  147. .macro TRACE_ASM_IRQ_DISABLE
  148. .endm
  149. .macro TRACE_ASM_IRQ_ENABLE
  150. .endm
  151. #endif
  152. .macro IRQ_DISABLE scratch
  153. lr \scratch, [status32]
  154. bic \scratch, \scratch, (STATUS_E1_MASK | STATUS_E2_MASK)
  155. flag \scratch
  156. TRACE_ASM_IRQ_DISABLE
  157. .endm
  158. .macro IRQ_ENABLE scratch
  159. TRACE_ASM_IRQ_ENABLE
  160. lr \scratch, [status32]
  161. or \scratch, \scratch, (STATUS_E1_MASK | STATUS_E2_MASK)
  162. flag \scratch
  163. .endm
  164. #endif /* __ASSEMBLY__ */
  165. #endif