irqflags.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. #ifdef __KERNEL__
  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. /* 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. #ifndef __ASSEMBLY__
  34. /******************************************************************
  35. * IRQ Control Macros
  36. ******************************************************************/
  37. /*
  38. * Save IRQ state and disable IRQs
  39. */
  40. static inline long arch_local_irq_save(void)
  41. {
  42. unsigned long temp, flags;
  43. __asm__ __volatile__(
  44. " lr %1, [status32] \n"
  45. " bic %0, %1, %2 \n"
  46. " and.f 0, %1, %2 \n"
  47. " flag.nz %0 \n"
  48. : "=r"(temp), "=r"(flags)
  49. : "n"((STATUS_E1_MASK | STATUS_E2_MASK))
  50. : "memory", "cc");
  51. return flags;
  52. }
  53. /*
  54. * restore saved IRQ state
  55. */
  56. static inline void arch_local_irq_restore(unsigned long flags)
  57. {
  58. __asm__ __volatile__(
  59. " flag %0 \n"
  60. :
  61. : "r"(flags)
  62. : "memory");
  63. }
  64. /*
  65. * Unconditionally Enable IRQs
  66. */
  67. extern void arch_local_irq_enable(void);
  68. /*
  69. * Unconditionally Disable IRQs
  70. */
  71. static inline void arch_local_irq_disable(void)
  72. {
  73. unsigned long temp;
  74. __asm__ __volatile__(
  75. " lr %0, [status32] \n"
  76. " and %0, %0, %1 \n"
  77. " flag %0 \n"
  78. : "=&r"(temp)
  79. : "n"(~(STATUS_E1_MASK | STATUS_E2_MASK))
  80. : "memory");
  81. }
  82. /*
  83. * save IRQ state
  84. */
  85. static inline long arch_local_save_flags(void)
  86. {
  87. unsigned long temp;
  88. __asm__ __volatile__(
  89. " lr %0, [status32] \n"
  90. : "=&r"(temp)
  91. :
  92. : "memory");
  93. return temp;
  94. }
  95. /*
  96. * Query IRQ state
  97. */
  98. static inline int arch_irqs_disabled_flags(unsigned long flags)
  99. {
  100. return !(flags & (STATUS_E1_MASK
  101. #ifdef CONFIG_ARC_COMPACT_IRQ_LEVELS
  102. | STATUS_E2_MASK
  103. #endif
  104. ));
  105. }
  106. static inline int arch_irqs_disabled(void)
  107. {
  108. return arch_irqs_disabled_flags(arch_local_save_flags());
  109. }
  110. #else
  111. #ifdef CONFIG_TRACE_IRQFLAGS
  112. .macro TRACE_ASM_IRQ_DISABLE
  113. bl trace_hardirqs_off
  114. .endm
  115. .macro TRACE_ASM_IRQ_ENABLE
  116. bl trace_hardirqs_on
  117. .endm
  118. #else
  119. .macro TRACE_ASM_IRQ_DISABLE
  120. .endm
  121. .macro TRACE_ASM_IRQ_ENABLE
  122. .endm
  123. #endif
  124. .macro IRQ_DISABLE scratch
  125. lr \scratch, [status32]
  126. bic \scratch, \scratch, (STATUS_E1_MASK | STATUS_E2_MASK)
  127. flag \scratch
  128. TRACE_ASM_IRQ_DISABLE
  129. .endm
  130. .macro IRQ_ENABLE scratch
  131. lr \scratch, [status32]
  132. or \scratch, \scratch, (STATUS_E1_MASK | STATUS_E2_MASK)
  133. flag \scratch
  134. TRACE_ASM_IRQ_ENABLE
  135. .endm
  136. #endif /* __ASSEMBLY__ */
  137. #endif /* KERNEL */
  138. #endif