irqflags.h 3.8 KB

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