intr.h revision 1.11.20.1 1 1.11.20.1 ad /* $NetBSD: intr.h,v 1.11.20.1 2007/01/12 01:00:54 ad Exp $ */
2 1.1 wdk
3 1.1 wdk /*
4 1.1 wdk * Copyright (c) 1998 Jonathan Stone. All rights reserved.
5 1.1 wdk *
6 1.1 wdk * Redistribution and use in source and binary forms, with or without
7 1.1 wdk * modification, are permitted provided that the following conditions
8 1.1 wdk * are met:
9 1.1 wdk * 1. Redistributions of source code must retain the above copyright
10 1.1 wdk * notice, this list of conditions and the following disclaimer.
11 1.1 wdk * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 wdk * notice, this list of conditions and the following disclaimer in the
13 1.1 wdk * documentation and/or other materials provided with the distribution.
14 1.1 wdk * 3. All advertising materials mentioning features or use of this software
15 1.1 wdk * must display the following acknowledgement:
16 1.1 wdk * This product includes software developed by Jonathan Stone for
17 1.1 wdk * the NetBSD Project.
18 1.1 wdk * 4. The name of the author may not be used to endorse or promote products
19 1.1 wdk * derived from this software without specific prior written permission.
20 1.1 wdk *
21 1.1 wdk * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1 wdk * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1 wdk * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1 wdk * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1 wdk * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1 wdk * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1 wdk * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1 wdk * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1 wdk * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.1 wdk * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 wdk */
32 1.1 wdk
33 1.1 wdk #ifndef _MACHINE_INTR_H_
34 1.1 wdk #define _MACHINE_INTR_H_
35 1.1 wdk
36 1.11.20.1 ad #define IPL_NONE 0 /* disable only this interrupt */
37 1.11.20.1 ad #define IPL_SOFT 1 /* generic software interrupts */
38 1.11.20.1 ad #define IPL_SOFTCLOCK 2 /* clock software interrupts */
39 1.11.20.1 ad #define IPL_SOFTNET 3 /* network software interrupts */
40 1.11.20.1 ad #define IPL_SOFTSERIAL 4 /* serial software interrupts */
41 1.11.20.1 ad #define IPL_BIO 5 /* disable block I/O interrupts */
42 1.11.20.1 ad #define IPL_NET 6 /* disable network interrupts */
43 1.11.20.1 ad #define IPL_TTY 7 /* disable terminal interrupts */
44 1.11.20.1 ad #define IPL_SERIAL IPL_TTY
45 1.11.20.1 ad #define IPL_LPT IPL_TTY
46 1.11.20.1 ad #define IPL_VM IPL_TTY
47 1.11.20.1 ad #define IPL_CLOCK 8 /* disable clock interrupts */
48 1.11.20.1 ad #define IPL_STATCLOCK 9 /* disable profiling interrupts */
49 1.11.20.1 ad #define IPL_SCHED IPL_CLOCK
50 1.11.20.1 ad #define IPL_HIGH 10 /* disable all interrupts */
51 1.11.20.1 ad #define IPL_LOCK IPL_HIGH
52 1.11.20.1 ad
53 1.11.20.1 ad #define IPL_N 11
54 1.6 wdk
55 1.6 wdk /* Interrupt sharing types. */
56 1.6 wdk #define IST_NONE 0 /* none */
57 1.6 wdk #define IST_PULSE 1 /* pulsed */
58 1.6 wdk #define IST_EDGE 2 /* edge-triggered */
59 1.6 wdk #define IST_LEVEL 3 /* level-triggered */
60 1.1 wdk
61 1.11.20.1 ad #define SI_SOFT 0
62 1.11.20.1 ad #define SI_SOFTCLOCK 1
63 1.11.20.1 ad #define SI_SOFTNET 2
64 1.11.20.1 ad #define SI_SOFTSERIAL 3
65 1.1 wdk
66 1.11.20.1 ad #define SI_NQUEUES 4
67 1.11.20.1 ad
68 1.11.20.1 ad #define SI_QUEUENAMES { \
69 1.11.20.1 ad "misc", \
70 1.1 wdk "clock", \
71 1.11.20.1 ad "net", \
72 1.11.20.1 ad "serial", \
73 1.1 wdk }
74 1.1 wdk
75 1.1 wdk #ifdef _KERNEL
76 1.1 wdk #ifndef _LOCORE
77 1.6 wdk #include <sys/types.h>
78 1.6 wdk #include <sys/device.h>
79 1.6 wdk #include <sys/queue.h>
80 1.1 wdk
81 1.1 wdk extern int _splraise __P((int));
82 1.1 wdk extern int _spllower __P((int));
83 1.1 wdk extern int _splset __P((int));
84 1.1 wdk extern int _splget __P((void));
85 1.1 wdk extern void _splnone __P((void));
86 1.1 wdk extern void _setsoftintr __P((int));
87 1.1 wdk extern void _clrsoftintr __P((int));
88 1.1 wdk
89 1.1 wdk /*
90 1.1 wdk * software simulated interrupt
91 1.1 wdk */
92 1.1 wdk #define setsoft(x) do { \
93 1.1 wdk extern u_int ssir; \
94 1.10 he int _s; \
95 1.1 wdk \
96 1.10 he _s = splhigh(); \
97 1.6 wdk ssir |= 1 << (x); \
98 1.1 wdk _setsoftintr(MIPS_SOFT_INT_MASK_1); \
99 1.10 he splx(_s); \
100 1.1 wdk } while (0)
101 1.1 wdk
102 1.6 wdk #define softintr_schedule(arg) \
103 1.6 wdk do { \
104 1.6 wdk struct mipsco_intrhand *__ih = (arg); \
105 1.6 wdk __ih->ih_pending = 1; \
106 1.11.20.1 ad setsoft(__ih->ih_intrhead->intr_siq); \
107 1.6 wdk } while (0)
108 1.6 wdk
109 1.6 wdk extern struct mipsco_intrhand *softnet_intrhand;
110 1.6 wdk
111 1.6 wdk #define setsoftnet() softintr_schedule(softnet_intrhand)
112 1.1 wdk
113 1.1 wdk /*
114 1.1 wdk * nesting interrupt masks.
115 1.1 wdk */
116 1.1 wdk #define MIPS_INT_MASK_SPL_SOFT0 MIPS_SOFT_INT_MASK_0
117 1.1 wdk #define MIPS_INT_MASK_SPL_SOFT1 (MIPS_SOFT_INT_MASK_1|MIPS_INT_MASK_SPL_SOFT0)
118 1.1 wdk #define MIPS_INT_MASK_SPL0 (MIPS_INT_MASK_0|MIPS_INT_MASK_SPL_SOFT1)
119 1.1 wdk #define MIPS_INT_MASK_SPL1 (MIPS_INT_MASK_1|MIPS_INT_MASK_SPL0)
120 1.1 wdk #define MIPS_INT_MASK_SPL2 (MIPS_INT_MASK_2|MIPS_INT_MASK_SPL1)
121 1.1 wdk #define MIPS_INT_MASK_SPL3 (MIPS_INT_MASK_3|MIPS_INT_MASK_SPL2)
122 1.1 wdk #define MIPS_INT_MASK_SPL4 (MIPS_INT_MASK_4|MIPS_INT_MASK_SPL3)
123 1.1 wdk #define MIPS_INT_MASK_SPL5 (MIPS_INT_MASK_5|MIPS_INT_MASK_SPL4)
124 1.1 wdk
125 1.1 wdk #define spl0() (void)_spllower(0)
126 1.1 wdk #define splx(s) (void)_splset(s)
127 1.1 wdk #define splbio() _splraise(MIPS_INT_MASK_SPL1)
128 1.1 wdk #define splnet() _splraise(MIPS_INT_MASK_SPL0)
129 1.1 wdk #define spltty() _splraise(MIPS_INT_MASK_SPL0)
130 1.5 thorpej #define splvm() _splraise(MIPS_INT_MASK_SPL2)
131 1.1 wdk #define splclock() _splraise(MIPS_INT_MASK_SPL2)
132 1.1 wdk #define splstatclock() _splraise(MIPS_INT_MASK_SPL2)
133 1.1 wdk #define splhigh() _splraise(MIPS_INT_MASK_SPL2)
134 1.3 thorpej #define splsched() splhigh()
135 1.4 thorpej #define spllock() splhigh()
136 1.6 wdk #define splserial() spltty()
137 1.8 wdk #define spllpt() spltty()
138 1.1 wdk
139 1.6 wdk #define splsoft() _splraise(MIPS_INT_MASK_SPL_SOFT1)
140 1.11.20.1 ad #define splsoftclock() _splraise(MIPS_INT_MASK_SPL_SOFT0)
141 1.11.20.1 ad #define splsoftnet() splsoft()
142 1.11.20.1 ad #define splsoftserial() splsoft()
143 1.1 wdk #define spllowersoftclock() _spllower(MIPS_INT_MASK_SPL_SOFT0)
144 1.11.20.1 ad
145 1.11.20.1 ad typedef int ipl_t;
146 1.11.20.1 ad typedef struct {
147 1.11.20.1 ad int _sr;
148 1.11.20.1 ad } ipl_cookie_t;
149 1.11.20.1 ad
150 1.11.20.1 ad ipl_cookie_t makeiplcookie(ipl_t ipl);
151 1.11.20.1 ad
152 1.11.20.1 ad static inline int
153 1.11.20.1 ad splraiseipl(ipl_cookie_t icookie)
154 1.11.20.1 ad {
155 1.11.20.1 ad
156 1.11.20.1 ad return _splraise(icookie._sr);
157 1.11.20.1 ad }
158 1.1 wdk
159 1.6 wdk struct mipsco_intrhand {
160 1.6 wdk LIST_ENTRY(mipsco_intrhand)
161 1.6 wdk ih_q;
162 1.6 wdk int (*ih_fun) __P((void *));
163 1.6 wdk void *ih_arg;
164 1.6 wdk struct mipsco_intr *ih_intrhead;
165 1.6 wdk int ih_pending;
166 1.2 wdk };
167 1.6 wdk
168 1.6 wdk struct mipsco_intr {
169 1.6 wdk LIST_HEAD(,mipsco_intrhand)
170 1.6 wdk intr_q;
171 1.6 wdk struct evcnt ih_evcnt;
172 1.11.20.1 ad unsigned long intr_siq;
173 1.6 wdk };
174 1.6 wdk
175 1.6 wdk
176 1.6 wdk extern struct mipsco_intrhand intrtab[];
177 1.2 wdk
178 1.2 wdk #define SYS_INTR_LEVEL0 0
179 1.2 wdk #define SYS_INTR_LEVEL1 1
180 1.2 wdk #define SYS_INTR_LEVEL2 2
181 1.2 wdk #define SYS_INTR_LEVEL3 3
182 1.2 wdk #define SYS_INTR_LEVEL4 4
183 1.2 wdk #define SYS_INTR_LEVEL5 5
184 1.2 wdk #define SYS_INTR_SCSI 6
185 1.2 wdk #define SYS_INTR_TIMER 7
186 1.2 wdk #define SYS_INTR_ETHER 8
187 1.2 wdk #define SYS_INTR_SCC0 9
188 1.2 wdk #define SYS_INTR_FDC 10
189 1.6 wdk #define SYS_INTR_ATBUS 11
190 1.1 wdk
191 1.2 wdk #define MAX_INTR_COOKIES 16
192 1.2 wdk
193 1.6 wdk #define CALL_INTR(lev) ((*intrtab[lev].ih_fun)(intrtab[lev].ih_arg))
194 1.6 wdk
195 1.6 wdk void *softintr_establish(int, void (*)(void *), void *);
196 1.6 wdk void softintr_disestablish(void *);
197 1.6 wdk void softintr_init(void);
198 1.6 wdk void softintr_dispatch(void);
199 1.1 wdk
200 1.1 wdk #endif /* !_LOCORE */
201 1.1 wdk #endif /* _KERNEL */
202 1.1 wdk #endif /* _MACHINE_INTR_H_ */
203