intr.h revision 1.28 1 1.28 fvdl /* $NetBSD: intr.h,v 1.28 2002/10/05 21:25:24 fvdl Exp $ */
2 1.1 mycroft
3 1.9 mycroft /*-
4 1.19 thorpej * 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.19 thorpej * 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.26 fvdl /*
43 1.26 fvdl * Interrupt priority levels.
44 1.26 fvdl *
45 1.26 fvdl * There are tty, network and disk drivers that use free() at interrupt
46 1.26 fvdl * time, so imp > (tty | net | bio).
47 1.26 fvdl *
48 1.26 fvdl * Since run queues may be manipulated by both the statclock and tty,
49 1.26 fvdl * network, and disk drivers, clock > imp.
50 1.26 fvdl *
51 1.26 fvdl * IPL_HIGH must block everything that can manipulate a run queue.
52 1.26 fvdl *
53 1.26 fvdl * We need serial drivers to run at the absolute highest priority to
54 1.26 fvdl * avoid overruns, so serial > high.
55 1.26 fvdl */
56 1.26 fvdl #define IPL_NONE 0x00 /* nothing */
57 1.26 fvdl #define IPL_SOFTCLOCK 0x50 /* timeouts */
58 1.26 fvdl #define IPL_SOFTNET 0x60 /* protocol stacks */
59 1.26 fvdl #define IPL_BIO 0x70 /* block I/O */
60 1.26 fvdl #define IPL_NET 0x80 /* network */
61 1.26 fvdl #define IPL_SOFTSERIAL 0x90 /* serial */
62 1.26 fvdl #define IPL_TTY 0xa0 /* terminal */
63 1.26 fvdl #define IPL_IMP 0xb0 /* memory allocation */
64 1.26 fvdl #define IPL_AUDIO 0xc0 /* audio */
65 1.26 fvdl #define IPL_CLOCK 0xd0 /* clock */
66 1.26 fvdl #define IPL_HIGH 0xd0 /* everything */
67 1.28 fvdl #define IPL_SERIAL 0xd0 /* serial */
68 1.26 fvdl #define IPL_IPI 0xe0 /* inter-processor interrupts */
69 1.26 fvdl #define NIPL 16
70 1.1 mycroft
71 1.1 mycroft /* Interrupt sharing types. */
72 1.1 mycroft #define IST_NONE 0 /* none */
73 1.1 mycroft #define IST_PULSE 1 /* pulsed */
74 1.1 mycroft #define IST_EDGE 2 /* edge-triggered */
75 1.1 mycroft #define IST_LEVEL 3 /* level-triggered */
76 1.3 mycroft
77 1.3 mycroft /* Soft interrupt masks. */
78 1.3 mycroft #define SIR_CLOCK 31
79 1.3 mycroft #define SIR_NET 30
80 1.6 mycroft #define SIR_SERIAL 29
81 1.13 mycroft
82 1.13 mycroft /* Hack for CLKF_INTR(). */
83 1.13 mycroft #define IPL_TAGINTR 28
84 1.3 mycroft
85 1.3 mycroft #ifndef _LOCORE
86 1.3 mycroft
87 1.26 fvdl extern volatile u_int32_t lapic_tpr;
88 1.26 fvdl extern volatile u_int32_t ipending;
89 1.26 fvdl
90 1.26 fvdl extern int imasks[NIPL];
91 1.26 fvdl extern int iunmask[NIPL];
92 1.3 mycroft
93 1.26 fvdl #define CPSHIFT 4
94 1.26 fvdl #define IMASK(level) imasks[(level)>>CPSHIFT]
95 1.26 fvdl #define IUNMASK(level) iunmask[(level)>>CPSHIFT]
96 1.26 fvdl
97 1.26 fvdl extern void Xspllower __P((void));
98 1.3 mycroft
99 1.3 mycroft static __inline int splraise __P((int));
100 1.14 cgd static __inline void spllower __P((int));
101 1.3 mycroft static __inline void softintr __P((int));
102 1.3 mycroft
103 1.3 mycroft /*
104 1.23 fvdl * compiler barrier: prevent reordering of instructions.
105 1.23 fvdl * XXX something similar will move to <sys/cdefs.h>
106 1.23 fvdl * or thereabouts.
107 1.23 fvdl * This prevents the compiler from reordering code around
108 1.23 fvdl * this "instruction", acting as a sequence point for code generation.
109 1.23 fvdl */
110 1.23 fvdl
111 1.27 matt #define __splbarrier() __asm __volatile("" : : : "memory")
112 1.23 fvdl
113 1.23 fvdl /*
114 1.3 mycroft * Add a mask to cpl, and return the old value of cpl.
115 1.3 mycroft */
116 1.3 mycroft static __inline int
117 1.27 matt splraise(int ncpl)
118 1.3 mycroft {
119 1.26 fvdl register int ocpl = lapic_tpr;
120 1.3 mycroft
121 1.26 fvdl if (ncpl > ocpl)
122 1.26 fvdl lapic_tpr = ncpl;
123 1.23 fvdl __splbarrier();
124 1.3 mycroft return (ocpl);
125 1.3 mycroft }
126 1.3 mycroft
127 1.3 mycroft /*
128 1.3 mycroft * Restore a value to cpl (unmasking interrupts). If any unmasked
129 1.3 mycroft * interrupts are pending, call Xspllower() to process them.
130 1.3 mycroft */
131 1.3 mycroft static __inline void
132 1.27 matt spllower(int ncpl)
133 1.3 mycroft {
134 1.26 fvdl register int cmask;
135 1.3 mycroft
136 1.23 fvdl __splbarrier();
137 1.26 fvdl lapic_tpr = ncpl;
138 1.26 fvdl cmask = IUNMASK(ncpl);
139 1.26 fvdl if (ipending & cmask)
140 1.3 mycroft Xspllower();
141 1.3 mycroft }
142 1.3 mycroft
143 1.3 mycroft /*
144 1.3 mycroft * Hardware interrupt masks
145 1.3 mycroft */
146 1.26 fvdl #define splbio() splraise(IPL_BIO)
147 1.26 fvdl #define splnet() splraise(IPL_NET)
148 1.26 fvdl #define spltty() splraise(IPL_TTY)
149 1.26 fvdl #define splaudio() splraise(IPL_AUDIO)
150 1.26 fvdl #define splclock() splraise(IPL_CLOCK)
151 1.7 mycroft #define splstatclock() splclock()
152 1.26 fvdl #define splserial() splraise(IPL_SERIAL)
153 1.26 fvdl #define splipi() splraise(IPL_IPI)
154 1.26 fvdl
155 1.26 fvdl #define spllpt() spltty()
156 1.8 is
157 1.26 fvdl #define SPL_ASSERT_ATMOST(x) KDASSERT(lapic_tpr <= (x))
158 1.24 yamt #define spllpt() spltty()
159 1.3 mycroft
160 1.3 mycroft /*
161 1.3 mycroft * Software interrupt masks
162 1.3 mycroft *
163 1.3 mycroft * NOTE: splsoftclock() is used by hardclock() to lower the priority from
164 1.3 mycroft * clock to softclock before it calls softclock().
165 1.3 mycroft */
166 1.26 fvdl #define spllowersoftclock() spllower(IPL_SOFTCLOCK)
167 1.26 fvdl
168 1.26 fvdl #define splsoftclock() splraise(IPL_SOFTCLOCK)
169 1.26 fvdl #define splsoftnet() splraise(IPL_SOFTNET)
170 1.26 fvdl #define splsoftserial() splraise(IPL_SOFTSERIAL)
171 1.3 mycroft
172 1.3 mycroft /*
173 1.3 mycroft * Miscellaneous
174 1.3 mycroft */
175 1.26 fvdl #define splvm() splraise(IPL_IMP)
176 1.26 fvdl #define splhigh() splraise(IPL_HIGH)
177 1.26 fvdl #define spl0() spllower(IPL_NONE)
178 1.15 thorpej #define splsched() splhigh()
179 1.28 fvdl #define spllock() splhigh()
180 1.14 cgd #define splx(x) spllower(x)
181 1.3 mycroft
182 1.3 mycroft /*
183 1.3 mycroft * Software interrupt registration
184 1.3 mycroft *
185 1.3 mycroft * We hand-code this to ensure that it's atomic.
186 1.3 mycroft */
187 1.3 mycroft static __inline void
188 1.26 fvdl softintr(register int sir)
189 1.3 mycroft {
190 1.26 fvdl __asm __volatile("lock ; orl %1, %0" : "=m"(ipending) : "ir" (1 << sir));
191 1.3 mycroft }
192 1.3 mycroft
193 1.6 mycroft #define setsoftnet() softintr(SIR_NET)
194 1.3 mycroft
195 1.26 fvdl /* XXX does ipi goo belong here, or elsewhere? */
196 1.26 fvdl
197 1.26 fvdl #define I386_IPI_HALT 0x00000001
198 1.26 fvdl #define I386_IPI_MICROSET 0x00000002
199 1.26 fvdl #define I386_IPI_FLUSH_FPU 0x00000004
200 1.26 fvdl #define I386_IPI_SYNCH_FPU 0x00000008
201 1.26 fvdl #define I386_IPI_TLB 0x00000010
202 1.26 fvdl #define I386_IPI_MTRR 0x00000020
203 1.26 fvdl #define I386_IPI_GDT 0x00000040
204 1.26 fvdl
205 1.26 fvdl #define I386_NIPI 7
206 1.26 fvdl
207 1.26 fvdl #ifdef MULTIPROCESSOR
208 1.26 fvdl struct cpu_info;
209 1.26 fvdl
210 1.28 fvdl int i386_send_ipi (struct cpu_info *, int);
211 1.26 fvdl void i386_broadcast_ipi (int);
212 1.26 fvdl void i386_multicast_ipi (int, int);
213 1.26 fvdl void i386_ipi_handler (void);
214 1.26 fvdl #endif
215 1.26 fvdl
216 1.3 mycroft #endif /* !_LOCORE */
217 1.19 thorpej
218 1.19 thorpej /*
219 1.19 thorpej * Generic software interrupt support.
220 1.19 thorpej */
221 1.19 thorpej
222 1.19 thorpej #define I386_SOFTINTR_SOFTCLOCK 0
223 1.19 thorpej #define I386_SOFTINTR_SOFTNET 1
224 1.19 thorpej #define I386_SOFTINTR_SOFTSERIAL 2
225 1.19 thorpej #define I386_NSOFTINTR 3
226 1.19 thorpej
227 1.19 thorpej #ifndef _LOCORE
228 1.19 thorpej #include <sys/queue.h>
229 1.19 thorpej
230 1.19 thorpej struct i386_soft_intrhand {
231 1.19 thorpej TAILQ_ENTRY(i386_soft_intrhand)
232 1.19 thorpej sih_q;
233 1.19 thorpej struct i386_soft_intr *sih_intrhead;
234 1.19 thorpej void (*sih_fn)(void *);
235 1.19 thorpej void *sih_arg;
236 1.19 thorpej int sih_pending;
237 1.19 thorpej };
238 1.19 thorpej
239 1.19 thorpej struct i386_soft_intr {
240 1.19 thorpej TAILQ_HEAD(, i386_soft_intrhand)
241 1.19 thorpej softintr_q;
242 1.19 thorpej int softintr_ssir;
243 1.26 fvdl struct simplelock softintr_slock;
244 1.19 thorpej };
245 1.19 thorpej
246 1.19 thorpej #define i386_softintr_lock(si, s) \
247 1.19 thorpej do { \
248 1.22 thorpej /* XXX splhigh braindamage on i386 */ \
249 1.22 thorpej (s) = splserial(); \
250 1.26 fvdl simple_lock(&si->softintr_slock); \
251 1.20 lukem } while (/*CONSTCOND*/ 0)
252 1.19 thorpej
253 1.19 thorpej #define i386_softintr_unlock(si, s) \
254 1.19 thorpej do { \
255 1.26 fvdl simple_unlock(&si->softintr_slock); \
256 1.19 thorpej splx((s)); \
257 1.20 lukem } while (/*CONSTCOND*/ 0)
258 1.19 thorpej
259 1.19 thorpej void *softintr_establish(int, void (*)(void *), void *);
260 1.19 thorpej void softintr_disestablish(void *);
261 1.19 thorpej void softintr_init(void);
262 1.19 thorpej void softintr_dispatch(int);
263 1.19 thorpej
264 1.19 thorpej #define softintr_schedule(arg) \
265 1.19 thorpej do { \
266 1.19 thorpej struct i386_soft_intrhand *__sih = (arg); \
267 1.19 thorpej struct i386_soft_intr *__si = __sih->sih_intrhead; \
268 1.19 thorpej int __s; \
269 1.19 thorpej \
270 1.19 thorpej i386_softintr_lock(__si, __s); \
271 1.19 thorpej if (__sih->sih_pending == 0) { \
272 1.19 thorpej TAILQ_INSERT_TAIL(&__si->softintr_q, __sih, sih_q); \
273 1.19 thorpej __sih->sih_pending = 1; \
274 1.19 thorpej softintr(__si->softintr_ssir); \
275 1.19 thorpej } \
276 1.19 thorpej i386_softintr_unlock(__si, __s); \
277 1.20 lukem } while (/*CONSTCOND*/ 0)
278 1.19 thorpej #endif /* _LOCORE */
279 1.4 mycroft
280 1.4 mycroft #endif /* !_I386_INTR_H_ */
281