intr.h revision 1.17.2.1 1 1.17.2.1 nathanw /* $NetBSD: intr.h,v 1.17.2.1 2001/06/21 19:25:50 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.3 mycroft * Add a mask to cpl, and return the old value of cpl.
84 1.3 mycroft */
85 1.3 mycroft static __inline int
86 1.3 mycroft splraise(ncpl)
87 1.3 mycroft register int ncpl;
88 1.3 mycroft {
89 1.3 mycroft register int ocpl = cpl;
90 1.3 mycroft
91 1.3 mycroft cpl = ocpl | ncpl;
92 1.3 mycroft return (ocpl);
93 1.3 mycroft }
94 1.3 mycroft
95 1.3 mycroft /*
96 1.3 mycroft * Restore a value to cpl (unmasking interrupts). If any unmasked
97 1.3 mycroft * interrupts are pending, call Xspllower() to process them.
98 1.3 mycroft */
99 1.3 mycroft static __inline void
100 1.3 mycroft spllower(ncpl)
101 1.3 mycroft register int ncpl;
102 1.3 mycroft {
103 1.3 mycroft
104 1.3 mycroft cpl = ncpl;
105 1.3 mycroft if (ipending & ~ncpl)
106 1.3 mycroft Xspllower();
107 1.3 mycroft }
108 1.3 mycroft
109 1.3 mycroft /*
110 1.3 mycroft * Hardware interrupt masks
111 1.3 mycroft */
112 1.3 mycroft #define splbio() splraise(imask[IPL_BIO])
113 1.3 mycroft #define splnet() splraise(imask[IPL_NET])
114 1.3 mycroft #define spltty() splraise(imask[IPL_TTY])
115 1.7 mycroft #define splaudio() splraise(imask[IPL_AUDIO])
116 1.3 mycroft #define splclock() splraise(imask[IPL_CLOCK])
117 1.7 mycroft #define splstatclock() splclock()
118 1.6 mycroft #define splserial() splraise(imask[IPL_SERIAL])
119 1.8 is
120 1.8 is #define spllpt() spltty()
121 1.3 mycroft
122 1.3 mycroft /*
123 1.3 mycroft * Software interrupt masks
124 1.3 mycroft *
125 1.3 mycroft * NOTE: splsoftclock() is used by hardclock() to lower the priority from
126 1.3 mycroft * clock to softclock before it calls softclock().
127 1.3 mycroft */
128 1.12 thorpej #define spllowersoftclock() spllower(imask[IPL_SOFTCLOCK])
129 1.12 thorpej #define splsoftclock() splraise(imask[IPL_SOFTCLOCK])
130 1.6 mycroft #define splsoftnet() splraise(imask[IPL_SOFTNET])
131 1.6 mycroft #define splsoftserial() splraise(imask[IPL_SOFTSERIAL])
132 1.3 mycroft
133 1.3 mycroft /*
134 1.3 mycroft * Miscellaneous
135 1.3 mycroft */
136 1.17 thorpej #define splvm() splraise(imask[IPL_IMP])
137 1.6 mycroft #define splhigh() splraise(imask[IPL_HIGH])
138 1.15 thorpej #define splsched() splhigh()
139 1.16 thorpej #define spllock() splhigh()
140 1.3 mycroft #define spl0() spllower(0)
141 1.14 cgd #define splx(x) spllower(x)
142 1.3 mycroft
143 1.3 mycroft /*
144 1.3 mycroft * Software interrupt registration
145 1.3 mycroft *
146 1.3 mycroft * We hand-code this to ensure that it's atomic.
147 1.3 mycroft */
148 1.3 mycroft static __inline void
149 1.3 mycroft softintr(mask)
150 1.3 mycroft register int mask;
151 1.3 mycroft {
152 1.11 christos __asm __volatile("orl %1, %0" : "=m"(ipending) : "ir" (1 << mask));
153 1.3 mycroft }
154 1.3 mycroft
155 1.3 mycroft #define setsoftast() (astpending = 1)
156 1.6 mycroft #define setsoftnet() softintr(SIR_NET)
157 1.3 mycroft
158 1.3 mycroft #endif /* !_LOCORE */
159 1.17.2.1 nathanw
160 1.17.2.1 nathanw /*
161 1.17.2.1 nathanw * Generic software interrupt support.
162 1.17.2.1 nathanw */
163 1.17.2.1 nathanw
164 1.17.2.1 nathanw #define I386_SOFTINTR_SOFTCLOCK 0
165 1.17.2.1 nathanw #define I386_SOFTINTR_SOFTNET 1
166 1.17.2.1 nathanw #define I386_SOFTINTR_SOFTSERIAL 2
167 1.17.2.1 nathanw #define I386_NSOFTINTR 3
168 1.17.2.1 nathanw
169 1.17.2.1 nathanw #ifndef _LOCORE
170 1.17.2.1 nathanw #include <sys/queue.h>
171 1.17.2.1 nathanw
172 1.17.2.1 nathanw struct i386_soft_intrhand {
173 1.17.2.1 nathanw TAILQ_ENTRY(i386_soft_intrhand)
174 1.17.2.1 nathanw sih_q;
175 1.17.2.1 nathanw struct i386_soft_intr *sih_intrhead;
176 1.17.2.1 nathanw void (*sih_fn)(void *);
177 1.17.2.1 nathanw void *sih_arg;
178 1.17.2.1 nathanw int sih_pending;
179 1.17.2.1 nathanw };
180 1.17.2.1 nathanw
181 1.17.2.1 nathanw struct i386_soft_intr {
182 1.17.2.1 nathanw TAILQ_HEAD(, i386_soft_intrhand)
183 1.17.2.1 nathanw softintr_q;
184 1.17.2.1 nathanw int softintr_ssir;
185 1.17.2.1 nathanw };
186 1.17.2.1 nathanw
187 1.17.2.1 nathanw #define i386_softintr_lock(si, s) \
188 1.17.2.1 nathanw do { \
189 1.17.2.1 nathanw (s) = splhigh(); \
190 1.17.2.1 nathanw } while (/*CONSTCOND*/ 0)
191 1.17.2.1 nathanw
192 1.17.2.1 nathanw #define i386_softintr_unlock(si, s) \
193 1.17.2.1 nathanw do { \
194 1.17.2.1 nathanw splx((s)); \
195 1.17.2.1 nathanw } while (/*CONSTCOND*/ 0)
196 1.17.2.1 nathanw
197 1.17.2.1 nathanw void *softintr_establish(int, void (*)(void *), void *);
198 1.17.2.1 nathanw void softintr_disestablish(void *);
199 1.17.2.1 nathanw void softintr_init(void);
200 1.17.2.1 nathanw void softintr_dispatch(int);
201 1.17.2.1 nathanw
202 1.17.2.1 nathanw #define softintr_schedule(arg) \
203 1.17.2.1 nathanw do { \
204 1.17.2.1 nathanw struct i386_soft_intrhand *__sih = (arg); \
205 1.17.2.1 nathanw struct i386_soft_intr *__si = __sih->sih_intrhead; \
206 1.17.2.1 nathanw int __s; \
207 1.17.2.1 nathanw \
208 1.17.2.1 nathanw i386_softintr_lock(__si, __s); \
209 1.17.2.1 nathanw if (__sih->sih_pending == 0) { \
210 1.17.2.1 nathanw TAILQ_INSERT_TAIL(&__si->softintr_q, __sih, sih_q); \
211 1.17.2.1 nathanw __sih->sih_pending = 1; \
212 1.17.2.1 nathanw softintr(__si->softintr_ssir); \
213 1.17.2.1 nathanw } \
214 1.17.2.1 nathanw i386_softintr_unlock(__si, __s); \
215 1.17.2.1 nathanw } while (/*CONSTCOND*/ 0)
216 1.17.2.1 nathanw #endif /* _LOCORE */
217 1.4 mycroft
218 1.4 mycroft #endif /* !_I386_INTR_H_ */
219