intr.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /* $OpenBSD: intr.h,v 1.6 2015/07/08 13:37:31 dlg Exp $ */
  2. /*
  3. * Copyright (c) 2001-2004 Opsycon AB (www.opsycon.se / www.opsycon.com)
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
  15. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  18. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  20. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  21. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  22. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  23. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  24. * SUCH DAMAGE.
  25. *
  26. */
  27. #ifndef _MACHINE_INTR_H_
  28. #define _MACHINE_INTR_H_
  29. /*
  30. * The interrupt level ipl is a logical level; per-platform interrupt
  31. * code will turn it into the appropriate hardware interrupt masks
  32. * values.
  33. *
  34. * Interrupt sources on the CPU are kept enabled regardless of the
  35. * current ipl value; individual hardware sources interrupting while
  36. * logically masked are masked on the fly, remembered as pending, and
  37. * unmasked at the first splx() opportunity.
  38. *
  39. * An exception to this rule is the clock interrupt. Clock interrupts
  40. * are always allowed to happen, but will (of course!) not be serviced
  41. * if logically masked. The reason for this is that clocks usually sit on
  42. * INT5 and cannot be easily masked if external hardware masking is used.
  43. */
  44. /* Interrupt priority `levels'; not mutually exclusive. */
  45. #define IPL_NONE 0 /* nothing */
  46. #define IPL_SOFTINT 1 /* soft interrupts */
  47. #define IPL_BIO 2 /* block I/O */
  48. #define IPL_AUDIO IPL_BIO
  49. #define IPL_NET 3 /* network */
  50. #define IPL_TTY 4 /* terminal */
  51. #define IPL_VM 5 /* memory allocation */
  52. #define IPL_CLOCK 6 /* clock */
  53. #define IPL_STATCLOCK IPL_CLOCK
  54. #define IPL_SCHED 7 /* everything */
  55. #define IPL_HIGH 7 /* everything */
  56. #define NIPLS 8 /* Number of levels */
  57. #define IPL_MPFLOOR IPL_TTY
  58. /* Interrupt priority 'flags'. */
  59. #define IPL_MPSAFE 0 /* no "mpsafe" interrupts */
  60. /* Interrupt sharing types. */
  61. #define IST_NONE 0 /* none */
  62. #define IST_PULSE 1 /* pulsed */
  63. #define IST_EDGE 2 /* edge-triggered */
  64. #define IST_LEVEL 3 /* level-triggered */
  65. #define SINTBIT(q) (q)
  66. #define SINTMASK(q) (1 << SINTBIT(q))
  67. /* Soft interrupt masks. */
  68. #define IPL_SOFT 0
  69. #define IPL_SOFTCLOCK 1
  70. #define IPL_SOFTNET 2
  71. #define IPL_SOFTTTY 3
  72. #define SI_SOFT 0 /* for IPL_SOFT */
  73. #define SI_SOFTCLOCK 1 /* for IPL_SOFTCLOCK */
  74. #define SI_SOFTNET 2 /* for IPL_SOFTNET */
  75. #define SI_SOFTTTY 3 /* for IPL_SOFTTTY */
  76. #define SI_NQUEUES 4
  77. #ifndef _LOCORE
  78. #include <machine/mutex.h>
  79. #include <sys/queue.h>
  80. struct soft_intrhand {
  81. TAILQ_ENTRY(soft_intrhand) sih_list;
  82. void (*sih_func)(void *);
  83. void *sih_arg;
  84. struct soft_intrq *sih_siq;
  85. int sih_pending;
  86. };
  87. struct soft_intrq {
  88. TAILQ_HEAD(, soft_intrhand) siq_list;
  89. int siq_si;
  90. struct mutex siq_mtx;
  91. };
  92. void softintr_disestablish(void *);
  93. void softintr_dispatch(int);
  94. void *softintr_establish(int, void (*)(void *), void *);
  95. void softintr_init(void);
  96. void softintr_schedule(void *);
  97. #define splsoft() splraise(IPL_SOFTINT)
  98. #define splbio() splraise(IPL_BIO)
  99. #define splnet() splraise(IPL_NET)
  100. #define spltty() splraise(IPL_TTY)
  101. #define splaudio() splraise(IPL_AUDIO)
  102. #define splclock() splraise(IPL_CLOCK)
  103. #define splvm() splraise(IPL_VM)
  104. #define splhigh() splraise(IPL_HIGH)
  105. #define splsoftclock() splsoft()
  106. #define splsoftnet() splsoft()
  107. #define splstatclock() splhigh()
  108. #define splsched() splhigh()
  109. #define spllock() splhigh()
  110. #define spl0() spllower(0)
  111. void splinit(void);
  112. #define splassert(X)
  113. #define splsoftassert(X)
  114. /* Inlines */
  115. static __inline void register_splx_handler(void (*)(int));
  116. typedef void (int_f)(int);
  117. extern int_f *splx_hand;
  118. static __inline void
  119. register_splx_handler(void(*handler)(int))
  120. {
  121. splx_hand = handler;
  122. }
  123. int splraise(int);
  124. void splx(int);
  125. int spllower(int);
  126. /*
  127. * Interrupt control struct used by interrupt dispatchers
  128. * to hold interrupt handler info.
  129. */
  130. #include <sys/evcount.h>
  131. struct intrhand {
  132. struct intrhand *ih_next;
  133. int (*ih_fun)(void *);
  134. void *ih_arg;
  135. int ih_level;
  136. int ih_irq;
  137. struct evcount ih_count;
  138. };
  139. /*
  140. * Low level interrupt dispatcher registration data.
  141. */
  142. /* Schedule priorities for base interrupts (CPU) */
  143. #define INTPRI_CLOCK 0
  144. /* other values are system-specific */
  145. #define NLOWINT 4 /* Number of low level registrations possible */
  146. extern uint32_t idle_mask;
  147. struct trap_frame;
  148. void set_intr(int, uint32_t, uint32_t(*)(uint32_t, struct trap_frame *));
  149. uint32_t updateimask(uint32_t);
  150. void dosoftint(void);
  151. #endif /* _LOCORE */
  152. #endif /* _MACHINE_INTR_H_ */