irqflags-arcv2.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * Copyright (C) 2014-15 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_IRQFLAGS_ARCV2_H
  9. #define __ASM_IRQFLAGS_ARCV2_H
  10. #include <asm/arcregs.h>
  11. /* status32 Bits */
  12. #define STATUS_AD_BIT 19 /* Disable Align chk: core supports non-aligned */
  13. #define STATUS_IE_BIT 31
  14. #define STATUS_AD_MASK (1<<STATUS_AD_BIT)
  15. #define STATUS_IE_MASK (1<<STATUS_IE_BIT)
  16. /* status32 Bits as encoded/expected by CLRI/SETI */
  17. #define CLRI_STATUS_IE_BIT 4
  18. #define CLRI_STATUS_E_MASK 0xF
  19. #define CLRI_STATUS_IE_MASK (1 << CLRI_STATUS_IE_BIT)
  20. #define AUX_USER_SP 0x00D
  21. #define AUX_IRQ_CTRL 0x00E
  22. #define AUX_IRQ_ACT 0x043 /* Active Intr across all levels */
  23. #define AUX_IRQ_LVL_PEND 0x200 /* Pending Intr across all levels */
  24. #define AUX_IRQ_HINT 0x201 /* For generating Soft Interrupts */
  25. #define AUX_IRQ_PRIORITY 0x206
  26. #define ICAUSE 0x40a
  27. #define AUX_IRQ_SELECT 0x40b
  28. #define AUX_IRQ_ENABLE 0x40c
  29. /* Was Intr taken in User Mode */
  30. #define AUX_IRQ_ACT_BIT_U 31
  31. /*
  32. * User space should be interruptable even by lowest prio interrupt
  33. * Safe even if actual interrupt priorities is fewer or even one
  34. */
  35. #define ARCV2_IRQ_DEF_PRIO 15
  36. /* seed value for status register */
  37. #define ISA_INIT_STATUS_BITS (STATUS_IE_MASK | STATUS_AD_MASK | \
  38. (ARCV2_IRQ_DEF_PRIO << 1))
  39. /* SLEEP needs default irq priority (<=) which can interrupt the doze */
  40. #define ISA_SLEEP_ARG (0x10 | ARCV2_IRQ_DEF_PRIO)
  41. #ifndef __ASSEMBLY__
  42. /*
  43. * Save IRQ state and disable IRQs
  44. */
  45. static inline long arch_local_irq_save(void)
  46. {
  47. unsigned long flags;
  48. __asm__ __volatile__(" clri %0 \n" : "=r" (flags) : : "memory");
  49. return flags;
  50. }
  51. /*
  52. * restore saved IRQ state
  53. */
  54. static inline void arch_local_irq_restore(unsigned long flags)
  55. {
  56. __asm__ __volatile__(" seti %0 \n" : : "r" (flags) : "memory");
  57. }
  58. /*
  59. * Unconditionally Enable IRQs
  60. */
  61. static inline void arch_local_irq_enable(void)
  62. {
  63. unsigned int irqact = read_aux_reg(AUX_IRQ_ACT);
  64. if (irqact & 0xffff)
  65. write_aux_reg(AUX_IRQ_ACT, irqact & ~0xffff);
  66. __asm__ __volatile__(" seti \n" : : : "memory");
  67. }
  68. /*
  69. * Unconditionally Disable IRQs
  70. */
  71. static inline void arch_local_irq_disable(void)
  72. {
  73. __asm__ __volatile__(" clri \n" : : : "memory");
  74. }
  75. /*
  76. * save IRQ state
  77. */
  78. static inline long arch_local_save_flags(void)
  79. {
  80. unsigned long temp;
  81. __asm__ __volatile__(
  82. " lr %0, [status32] \n"
  83. : "=&r"(temp)
  84. :
  85. : "memory");
  86. /* To be compatible with irq_save()/irq_restore()
  87. * encode the irq bits as expected by CLRI/SETI
  88. * (this was needed to make CONFIG_TRACE_IRQFLAGS work)
  89. */
  90. temp = (1 << 5) |
  91. ((!!(temp & STATUS_IE_MASK)) << CLRI_STATUS_IE_BIT) |
  92. ((temp >> 1) & CLRI_STATUS_E_MASK);
  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 & CLRI_STATUS_IE_MASK);
  101. }
  102. static inline int arch_irqs_disabled(void)
  103. {
  104. return arch_irqs_disabled_flags(arch_local_save_flags());
  105. }
  106. static inline void arc_softirq_trigger(int irq)
  107. {
  108. write_aux_reg(AUX_IRQ_HINT, irq);
  109. }
  110. static inline void arc_softirq_clear(int irq)
  111. {
  112. write_aux_reg(AUX_IRQ_HINT, 0);
  113. }
  114. #else
  115. #ifdef CONFIG_TRACE_IRQFLAGS
  116. .macro TRACE_ASM_IRQ_DISABLE
  117. bl trace_hardirqs_off
  118. .endm
  119. .macro TRACE_ASM_IRQ_ENABLE
  120. bl trace_hardirqs_on
  121. .endm
  122. #else
  123. .macro TRACE_ASM_IRQ_DISABLE
  124. .endm
  125. .macro TRACE_ASM_IRQ_ENABLE
  126. .endm
  127. #endif
  128. .macro IRQ_DISABLE scratch
  129. clri
  130. TRACE_ASM_IRQ_DISABLE
  131. .endm
  132. .macro IRQ_ENABLE scratch
  133. TRACE_ASM_IRQ_ENABLE
  134. seti
  135. .endm
  136. #endif /* __ASSEMBLY__ */
  137. #endif