irqflags-compact.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. #ifndef __ASSEMBLY__
  38. /******************************************************************
  39. * IRQ Control Macros
  40. *
  41. * All of them have "memory" clobber (compiler barrier) which is needed to
  42. * ensure that LD/ST requiring irq safetly (R-M-W when LLSC is not available)
  43. * are redone after IRQs are re-enabled (and gcc doesn't reuse stale register)
  44. *
  45. * Noted at the time of Abilis Timer List corruption
  46. * Orig Bug + Rejected solution : https://lkml.org/lkml/2013/3/29/67
  47. * Reasoning : https://lkml.org/lkml/2013/4/8/15
  48. *
  49. ******************************************************************/
  50. /*
  51. * Save IRQ state and disable IRQs
  52. */
  53. static inline long arch_local_irq_save(void)
  54. {
  55. unsigned long temp, flags;
  56. __asm__ __volatile__(
  57. " lr %1, [status32] \n"
  58. " bic %0, %1, %2 \n"
  59. " and.f 0, %1, %2 \n"
  60. " flag.nz %0 \n"
  61. : "=r"(temp), "=r"(flags)
  62. : "n"((STATUS_E1_MASK | STATUS_E2_MASK))
  63. : "memory", "cc");
  64. return flags;
  65. }
  66. /*
  67. * restore saved IRQ state
  68. */
  69. static inline void arch_local_irq_restore(unsigned long flags)
  70. {
  71. __asm__ __volatile__(
  72. " flag %0 \n"
  73. :
  74. : "r"(flags)
  75. : "memory");
  76. }
  77. /*
  78. * Unconditionally Enable IRQs
  79. */
  80. static inline void arch_local_irq_enable(void)
  81. {
  82. unsigned long temp;
  83. __asm__ __volatile__(
  84. " lr %0, [status32] \n"
  85. " or %0, %0, %1 \n"
  86. " flag %0 \n"
  87. : "=&r"(temp)
  88. : "n"((STATUS_E1_MASK | STATUS_E2_MASK))
  89. : "cc", "memory");
  90. }
  91. /*
  92. * Unconditionally Disable IRQs
  93. */
  94. static inline void arch_local_irq_disable(void)
  95. {
  96. unsigned long temp;
  97. __asm__ __volatile__(
  98. " lr %0, [status32] \n"
  99. " and %0, %0, %1 \n"
  100. " flag %0 \n"
  101. : "=&r"(temp)
  102. : "n"(~(STATUS_E1_MASK | STATUS_E2_MASK))
  103. : "memory");
  104. }
  105. /*
  106. * save IRQ state
  107. */
  108. static inline long arch_local_save_flags(void)
  109. {
  110. unsigned long temp;
  111. __asm__ __volatile__(
  112. " lr %0, [status32] \n"
  113. : "=&r"(temp)
  114. :
  115. : "memory");
  116. return temp;
  117. }
  118. /*
  119. * Query IRQ state
  120. */
  121. static inline int arch_irqs_disabled_flags(unsigned long flags)
  122. {
  123. return !(flags & (STATUS_E1_MASK
  124. #ifdef CONFIG_ARC_COMPACT_IRQ_LEVELS
  125. | STATUS_E2_MASK
  126. #endif
  127. ));
  128. }
  129. static inline int arch_irqs_disabled(void)
  130. {
  131. return arch_irqs_disabled_flags(arch_local_save_flags());
  132. }
  133. #else
  134. #ifdef CONFIG_TRACE_IRQFLAGS
  135. .macro TRACE_ASM_IRQ_DISABLE
  136. bl trace_hardirqs_off
  137. .endm
  138. .macro TRACE_ASM_IRQ_ENABLE
  139. bl trace_hardirqs_on
  140. .endm
  141. #else
  142. .macro TRACE_ASM_IRQ_DISABLE
  143. .endm
  144. .macro TRACE_ASM_IRQ_ENABLE
  145. .endm
  146. #endif
  147. .macro IRQ_DISABLE scratch
  148. lr \scratch, [status32]
  149. bic \scratch, \scratch, (STATUS_E1_MASK | STATUS_E2_MASK)
  150. flag \scratch
  151. TRACE_ASM_IRQ_DISABLE
  152. .endm
  153. .macro IRQ_ENABLE scratch
  154. TRACE_ASM_IRQ_ENABLE
  155. lr \scratch, [status32]
  156. or \scratch, \scratch, (STATUS_E1_MASK | STATUS_E2_MASK)
  157. flag \scratch
  158. .endm
  159. #endif /* __ASSEMBLY__ */
  160. #endif