intr.h revision 1.17.2.3 1 1.17.2.3 nathanw /* $NetBSD: intr.h,v 1.17.2.3 2002/01/08 00:25:32 nathanw Exp $ */
2 1.1 mycroft
3 1.9 mycroft /*-
4 1.17.2.1 nathanw * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
5 1.9 mycroft * All rights reserved.
6 1.9 mycroft *
7 1.9 mycroft * This code is derived from software contributed to The NetBSD Foundation
8 1.17.2.1 nathanw * by Charles M. Hannum, and by Jason R. Thorpe.
9 1.1 mycroft *
10 1.1 mycroft * Redistribution and use in source and binary forms, with or without
11 1.1 mycroft * modification, are permitted provided that the following conditions
12 1.1 mycroft * are met:
13 1.1 mycroft * 1. Redistributions of source code must retain the above copyright
14 1.1 mycroft * notice, this list of conditions and the following disclaimer.
15 1.1 mycroft * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 mycroft * notice, this list of conditions and the following disclaimer in the
17 1.1 mycroft * documentation and/or other materials provided with the distribution.
18 1.1 mycroft * 3. All advertising materials mentioning features or use of this software
19 1.1 mycroft * must display the following acknowledgement:
20 1.9 mycroft * This product includes software developed by the NetBSD
21 1.9 mycroft * Foundation, Inc. and its contributors.
22 1.9 mycroft * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.9 mycroft * contributors may be used to endorse or promote products derived
24 1.9 mycroft * from this software without specific prior written permission.
25 1.1 mycroft *
26 1.9 mycroft * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.9 mycroft * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.9 mycroft * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.9 mycroft * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.9 mycroft * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.9 mycroft * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.9 mycroft * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.9 mycroft * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.9 mycroft * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.9 mycroft * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.9 mycroft * POSSIBILITY OF SUCH DAMAGE.
37 1.1 mycroft */
38 1.1 mycroft
39 1.4 mycroft #ifndef _I386_INTR_H_
40 1.4 mycroft #define _I386_INTR_H_
41 1.4 mycroft
42 1.6 mycroft /* Interrupt priority `levels'. */
43 1.7 mycroft #define IPL_NONE 9 /* nothing */
44 1.7 mycroft #define IPL_SOFTCLOCK 8 /* timeouts */
45 1.7 mycroft #define IPL_SOFTNET 7 /* protocol stacks */
46 1.7 mycroft #define IPL_BIO 6 /* block I/O */
47 1.7 mycroft #define IPL_NET 5 /* network */
48 1.7 mycroft #define IPL_SOFTSERIAL 4 /* serial */
49 1.7 mycroft #define IPL_TTY 3 /* terminal */
50 1.7 mycroft #define IPL_IMP 3 /* memory allocation */
51 1.7 mycroft #define IPL_AUDIO 2 /* audio */
52 1.6 mycroft #define IPL_CLOCK 1 /* clock */
53 1.6 mycroft #define IPL_HIGH 1 /* everything */
54 1.6 mycroft #define IPL_SERIAL 0 /* serial */
55 1.7 mycroft #define NIPL 10
56 1.1 mycroft
57 1.1 mycroft /* Interrupt sharing types. */
58 1.1 mycroft #define IST_NONE 0 /* none */
59 1.1 mycroft #define IST_PULSE 1 /* pulsed */
60 1.1 mycroft #define IST_EDGE 2 /* edge-triggered */
61 1.1 mycroft #define IST_LEVEL 3 /* level-triggered */
62 1.3 mycroft
63 1.3 mycroft /* Soft interrupt masks. */
64 1.3 mycroft #define SIR_CLOCK 31
65 1.3 mycroft #define SIR_NET 30
66 1.6 mycroft #define SIR_SERIAL 29
67 1.13 mycroft
68 1.13 mycroft /* Hack for CLKF_INTR(). */
69 1.13 mycroft #define IPL_TAGINTR 28
70 1.3 mycroft
71 1.3 mycroft #ifndef _LOCORE
72 1.3 mycroft
73 1.3 mycroft volatile int cpl, ipending, astpending;
74 1.6 mycroft int imask[NIPL];
75 1.3 mycroft
76 1.17.2.1 nathanw void Xspllower __P((void));
77 1.3 mycroft
78 1.3 mycroft static __inline int splraise __P((int));
79 1.14 cgd static __inline void spllower __P((int));
80 1.3 mycroft static __inline void softintr __P((int));
81 1.3 mycroft
82 1.3 mycroft /*
83 1.17.2.3 nathanw * compiler barrier: prevent reordering of instructions.
84 1.17.2.3 nathanw * XXX something similar will move to <sys/cdefs.h>
85 1.17.2.3 nathanw * or thereabouts.
86 1.17.2.3 nathanw * This prevents the compiler from reordering code around
87 1.17.2.3 nathanw * this "instruction", acting as a sequence point for code generation.
88 1.17.2.3 nathanw */
89 1.17.2.3 nathanw
90 1.17.2.3 nathanw #define __splbarrier() __asm __volatile("":::"memory")
91 1.17.2.3 nathanw
92 1.17.2.3 nathanw /*
93 1.3 mycroft * Add a mask to cpl, and return the old value of cpl.
94 1.3 mycroft */
95 1.3 mycroft static __inline int
96 1.3 mycroft splraise(ncpl)
97 1.3 mycroft register int ncpl;
98 1.3 mycroft {
99 1.3 mycroft register int ocpl = cpl;
100 1.3 mycroft
101 1.3 mycroft cpl = ocpl | ncpl;
102 1.17.2.3 nathanw __splbarrier();
103 1.3 mycroft return (ocpl);
104 1.3 mycroft }
105 1.3 mycroft
106 1.3 mycroft /*
107 1.3 mycroft * Restore a value to cpl (unmasking interrupts). If any unmasked
108 1.3 mycroft * interrupts are pending, call Xspllower() to process them.
109 1.3 mycroft */
110 1.3 mycroft static __inline void
111 1.3 mycroft spllower(ncpl)
112 1.3 mycroft register int ncpl;
113 1.3 mycroft {
114 1.3 mycroft
115 1.17.2.3 nathanw __splbarrier();
116 1.3 mycroft cpl = ncpl;
117 1.3 mycroft if (ipending & ~ncpl)
118 1.3 mycroft Xspllower();
119 1.3 mycroft }
120 1.3 mycroft
121 1.3 mycroft /*
122 1.3 mycroft * Hardware interrupt masks
123 1.3 mycroft */
124 1.3 mycroft #define splbio() splraise(imask[IPL_BIO])
125 1.3 mycroft #define splnet() splraise(imask[IPL_NET])
126 1.3 mycroft #define spltty() splraise(imask[IPL_TTY])
127 1.7 mycroft #define splaudio() splraise(imask[IPL_AUDIO])
128 1.3 mycroft #define splclock() splraise(imask[IPL_CLOCK])
129 1.7 mycroft #define splstatclock() splclock()
130 1.6 mycroft #define splserial() splraise(imask[IPL_SERIAL])
131 1.8 is
132 1.17.2.3 nathanw #define spllpt() spltty()
133 1.3 mycroft
134 1.3 mycroft /*
135 1.3 mycroft * Software interrupt masks
136 1.3 mycroft *
137 1.3 mycroft * NOTE: splsoftclock() is used by hardclock() to lower the priority from
138 1.3 mycroft * clock to softclock before it calls softclock().
139 1.3 mycroft */
140 1.12 thorpej #define spllowersoftclock() spllower(imask[IPL_SOFTCLOCK])
141 1.12 thorpej #define splsoftclock() splraise(imask[IPL_SOFTCLOCK])
142 1.6 mycroft #define splsoftnet() splraise(imask[IPL_SOFTNET])
143 1.6 mycroft #define splsoftserial() splraise(imask[IPL_SOFTSERIAL])
144 1.3 mycroft
145 1.3 mycroft /*
146 1.3 mycroft * Miscellaneous
147 1.3 mycroft */
148 1.17 thorpej #define splvm() splraise(imask[IPL_IMP])
149 1.6 mycroft #define splhigh() splraise(imask[IPL_HIGH])
150 1.15 thorpej #define splsched() splhigh()
151 1.16 thorpej #define spllock() splhigh()
152 1.3 mycroft #define spl0() spllower(0)
153 1.14 cgd #define splx(x) spllower(x)
154 1.3 mycroft
155 1.3 mycroft /*
156 1.3 mycroft * Software interrupt registration
157 1.3 mycroft *
158 1.3 mycroft * We hand-code this to ensure that it's atomic.
159 1.3 mycroft */
160 1.3 mycroft static __inline void
161 1.3 mycroft softintr(mask)
162 1.3 mycroft register int mask;
163 1.3 mycroft {
164 1.11 christos __asm __volatile("orl %1, %0" : "=m"(ipending) : "ir" (1 << mask));
165 1.3 mycroft }
166 1.3 mycroft
167 1.3 mycroft #define setsoftast() (astpending = 1)
168 1.6 mycroft #define setsoftnet() softintr(SIR_NET)
169 1.3 mycroft
170 1.3 mycroft #endif /* !_LOCORE */
171 1.17.2.1 nathanw
172 1.17.2.1 nathanw /*
173 1.17.2.1 nathanw * Generic software interrupt support.
174 1.17.2.1 nathanw */
175 1.17.2.1 nathanw
176 1.17.2.1 nathanw #define I386_SOFTINTR_SOFTCLOCK 0
177 1.17.2.1 nathanw #define I386_SOFTINTR_SOFTNET 1
178 1.17.2.1 nathanw #define I386_SOFTINTR_SOFTSERIAL 2
179 1.17.2.1 nathanw #define I386_NSOFTINTR 3
180 1.17.2.1 nathanw
181 1.17.2.1 nathanw #ifndef _LOCORE
182 1.17.2.1 nathanw #include <sys/queue.h>
183 1.17.2.1 nathanw
184 1.17.2.1 nathanw struct i386_soft_intrhand {
185 1.17.2.1 nathanw TAILQ_ENTRY(i386_soft_intrhand)
186 1.17.2.1 nathanw sih_q;
187 1.17.2.1 nathanw struct i386_soft_intr *sih_intrhead;
188 1.17.2.1 nathanw void (*sih_fn)(void *);
189 1.17.2.1 nathanw void *sih_arg;
190 1.17.2.1 nathanw int sih_pending;
191 1.17.2.1 nathanw };
192 1.17.2.1 nathanw
193 1.17.2.1 nathanw struct i386_soft_intr {
194 1.17.2.1 nathanw TAILQ_HEAD(, i386_soft_intrhand)
195 1.17.2.1 nathanw softintr_q;
196 1.17.2.1 nathanw int softintr_ssir;
197 1.17.2.1 nathanw };
198 1.17.2.1 nathanw
199 1.17.2.1 nathanw #define i386_softintr_lock(si, s) \
200 1.17.2.1 nathanw do { \
201 1.17.2.2 nathanw /* XXX splhigh braindamage on i386 */ \
202 1.17.2.2 nathanw (s) = splserial(); \
203 1.17.2.1 nathanw } while (/*CONSTCOND*/ 0)
204 1.17.2.1 nathanw
205 1.17.2.1 nathanw #define i386_softintr_unlock(si, s) \
206 1.17.2.1 nathanw do { \
207 1.17.2.1 nathanw splx((s)); \
208 1.17.2.1 nathanw } while (/*CONSTCOND*/ 0)
209 1.17.2.1 nathanw
210 1.17.2.1 nathanw void *softintr_establish(int, void (*)(void *), void *);
211 1.17.2.1 nathanw void softintr_disestablish(void *);
212 1.17.2.1 nathanw void softintr_init(void);
213 1.17.2.1 nathanw void softintr_dispatch(int);
214 1.17.2.1 nathanw
215 1.17.2.1 nathanw #define softintr_schedule(arg) \
216 1.17.2.1 nathanw do { \
217 1.17.2.1 nathanw struct i386_soft_intrhand *__sih = (arg); \
218 1.17.2.1 nathanw struct i386_soft_intr *__si = __sih->sih_intrhead; \
219 1.17.2.1 nathanw int __s; \
220 1.17.2.1 nathanw \
221 1.17.2.1 nathanw i386_softintr_lock(__si, __s); \
222 1.17.2.1 nathanw if (__sih->sih_pending == 0) { \
223 1.17.2.1 nathanw TAILQ_INSERT_TAIL(&__si->softintr_q, __sih, sih_q); \
224 1.17.2.1 nathanw __sih->sih_pending = 1; \
225 1.17.2.1 nathanw softintr(__si->softintr_ssir); \
226 1.17.2.1 nathanw } \
227 1.17.2.1 nathanw i386_softintr_unlock(__si, __s); \
228 1.17.2.1 nathanw } while (/*CONSTCOND*/ 0)
229 1.17.2.1 nathanw #endif /* _LOCORE */
230 1.4 mycroft
231 1.4 mycroft #endif /* !_I386_INTR_H_ */
232