irqflags.h 3.4 KB

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