irq.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /****************************************************************************
  2. * arch/or1k/include/mor1kx/irq.h
  3. *
  4. * Copyright (C) 2018 Extent3D. All rights reserved.
  5. * Author: Matt Thompson <matt@extent3d.com>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. /* This file should never be included directed but, rather, only indirectly
  36. * through nuttx/irq.h
  37. */
  38. #ifndef __ARCH_OR1K_INCLUDE_MOR1KX_IRQ_H
  39. #define __ARCH_OR1K_INCLUDE_MOR1KX_IRQ_H
  40. /****************************************************************************
  41. * Included Files
  42. ****************************************************************************/
  43. #include <nuttx/config.h>
  44. #include <nuttx/irq.h>
  45. #ifndef __ASSEMBLY__
  46. # include <stdint.h>
  47. # include <debug.h>
  48. #endif
  49. #include <arch/spr.h>
  50. /****************************************************************************
  51. * Pre-processor Definitions
  52. ****************************************************************************/
  53. #define OR1K_NR_EXT_IRQ (32)
  54. #define OR1K_NR_INT_IRQ (1)
  55. #define NR_IRQS (OR1K_NR_EXT_IRQ + OR1K_NR_INT_IRQ)
  56. /* External interrupts are numbered 0-31. These can be used directly
  57. * as bit shift offsets in the programmable interrupt controller register.
  58. */
  59. #define OR1K_IRQ_EXT0 (0)
  60. #define OR1K_IRQ_EXT1 (1)
  61. #define OR1K_IRQ_EXT2 (2)
  62. #define OR1K_IRQ_EXT3 (3)
  63. #define OR1K_IRQ_EXT4 (4)
  64. #define OR1K_IRQ_EXT5 (5)
  65. #define OR1K_IRQ_EXT6 (6)
  66. #define OR1K_IRQ_EXT7 (7)
  67. #define OR1K_IRQ_EXT8 (8)
  68. #define OR1K_IRQ_EXT9 (9)
  69. #define OR1K_IRQ_EXT10 (10)
  70. #define OR1K_IRQ_EXT11 (11)
  71. #define OR1K_IRQ_EXT12 (12)
  72. #define OR1K_IRQ_EXT13 (13)
  73. #define OR1K_IRQ_EXT14 (14)
  74. #define OR1K_IRQ_EXT15 (15)
  75. #define OR1K_IRQ_EXT16 (16)
  76. #define OR1K_IRQ_EXT17 (17)
  77. #define OR1K_IRQ_EXT18 (18)
  78. #define OR1K_IRQ_EXT19 (19)
  79. #define OR1K_IRQ_EXT20 (20)
  80. #define OR1K_IRQ_EXT21 (21)
  81. #define OR1K_IRQ_EXT22 (22)
  82. #define OR1K_IRQ_EXT23 (23)
  83. #define OR1K_IRQ_EXT24 (24)
  84. #define OR1K_IRQ_EXT25 (25)
  85. #define OR1K_IRQ_EXT26 (26)
  86. #define OR1K_IRQ_EXT27 (27)
  87. #define OR1K_IRQ_EXT28 (28)
  88. #define OR1K_IRQ_EXT29 (29)
  89. #define OR1K_IRQ_EXT30 (30)
  90. #define OR1K_IRQ_EXT31 (31)
  91. /* Internal interrupts are numbered 32-xx */
  92. #define OR1K_IRQ_TICK (32)
  93. /* IRQ Stack Frame Format:
  94. *
  95. * We're going to store [r1..r31], pc and sr
  96. * into a register set for context switches
  97. * and exception handlers.
  98. *
  99. * Note that the PC and SR can be removed once
  100. * context switches are done through syscall exceptions.
  101. *
  102. * We should rely on EPCR[0-15], ESR[0-15] and shadow regs.
  103. *
  104. * Indices into the xcp.regs array:
  105. */
  106. #define REG_R1 (0)
  107. #define REG_R2 (1)
  108. #define REG_R3 (2)
  109. #define REG_R4 (3)
  110. #define REG_R5 (4)
  111. #define REG_R6 (5)
  112. #define REG_R7 (6)
  113. #define REG_R8 (7)
  114. #define REG_R9 (8)
  115. #define REG_R10 (9)
  116. #define REG_R11 (10)
  117. #define REG_R12 (11)
  118. #define REG_R13 (12)
  119. #define REG_R14 (13)
  120. #define REG_R15 (14)
  121. #define REG_R16 (15)
  122. #define REG_R17 (16)
  123. #define REG_R18 (17)
  124. #define REG_R19 (18)
  125. #define REG_R20 (19)
  126. #define REG_R21 (20)
  127. #define REG_R22 (21)
  128. #define REG_R23 (22)
  129. #define REG_R24 (23)
  130. #define REG_R25 (24)
  131. #define REG_R26 (25)
  132. #define REG_R27 (26)
  133. #define REG_R28 (27)
  134. #define REG_R29 (28)
  135. #define REG_R30 (29)
  136. #define REG_R31 (30)
  137. #define REG_PC (31)
  138. #define REG_SR (32)
  139. #define XCPTCONTEXT_REGS (33)
  140. #define XCPTCONTEXT_SIZE (4 * XCPTCONTEXT_REGS)
  141. /****************************************************************************
  142. * Public Types
  143. ****************************************************************************/
  144. /* The exception context structure defines how state is stored
  145. * for interrupt handlers and context switches
  146. *
  147. * All general purpose registers, the re-entry point (PC), and SR
  148. * are stored in the regs array.
  149. */
  150. #ifndef __ASSEMBLY__
  151. struct xcptcontext
  152. {
  153. /* Register save area */
  154. uint32_t regs[XCPTCONTEXT_REGS];
  155. /* The following function pointer is non-zero if there
  156. * are pending signals to be processed.
  157. */
  158. void *sigdeliver; /* Actual type is sig_deliver_t */
  159. /* These are saved copies of LR and CPSR used during
  160. * signal processing.
  161. *
  162. * REVISIT: Because there is only one copy of these save areas,
  163. * only a single signal handler can be active. This precludes
  164. * queuing of signal actions. As a result, signals received while
  165. * another signal handler is executing will be ignored!
  166. */
  167. uint32_t saved_pc;
  168. uint32_t saved_flags;
  169. };
  170. #endif
  171. /****************************************************************************
  172. * Inline functions
  173. ****************************************************************************/
  174. #ifndef __ASSEMBLY__
  175. /* Name: up_irq_save, up_irq_restore, and friends.
  176. *
  177. * NOTE: This function should never be called from application code and,
  178. * as a general rule unless you really know what you are doing, this
  179. * function should not be called directly from operating system code either:
  180. * Typically, the wrapper functions, enter_critical_section() and
  181. * leave_critical section(), are probably what you really want.
  182. */
  183. /* Save the current interrupt enable state & disable IRQs. */
  184. static inline irqstate_t up_irq_save(void)
  185. {
  186. irqstate_t flags;
  187. irqstate_t x;
  188. mfspr(SPR_SYS_SR, flags);
  189. /* Disable IRQs */
  190. x = flags & ~(SPR_SR_IEE | SPR_SR_TEE);
  191. mtspr(SPR_SYS_SR, x);
  192. return flags;
  193. }
  194. /* Restore saved state */
  195. static inline void up_irq_restore(irqstate_t flags)
  196. {
  197. uint32_t x;
  198. mfspr(SPR_SYS_SR, x);
  199. x |= flags & (SPR_SR_IEE | SPR_SR_TEE);
  200. mtspr(SPR_SYS_SR, x);
  201. }
  202. /* Enable IRQs */
  203. static inline void up_irq_enable(void) inline_function;
  204. static inline void up_irq_enable(void)
  205. {
  206. irqstate_t flags;
  207. mfspr(SPR_SYS_SR, flags);
  208. flags |= (SPR_SR_IEE | SPR_SR_TEE);
  209. mtspr(SPR_SYS_SR, flags);
  210. }
  211. #endif /* __ASSEMBLY__ */
  212. /****************************************************************************
  213. * Public Data
  214. ****************************************************************************/
  215. /****************************************************************************
  216. * Public Function Prototypes
  217. ****************************************************************************/
  218. #ifndef __ASSEMBLY__
  219. #ifdef __cplusplus
  220. #define EXTERN extern "C"
  221. extern "C"
  222. {
  223. #else
  224. #define EXTERN extern
  225. #endif
  226. #undef EXTERN
  227. #ifdef __cplusplus
  228. }
  229. #endif
  230. #endif
  231. #endif /* __ARCH_OR1K_INCLUDE_MOR1KX_IRQ_H */