irqflags-compact.h 4.3 KB

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