irqflags-compact.h 4.0 KB

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