intr.h revision 1.17.2.5 1 1.17.2.5 nathanw /* $NetBSD: intr.h,v 1.17.2.5 2002/10/18 02:37:56 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.17.2.5 nathanw /*
43 1.17.2.5 nathanw * Interrupt priority levels.
44 1.17.2.5 nathanw *
45 1.17.2.5 nathanw * There are tty, network and disk drivers that use free() at interrupt
46 1.17.2.5 nathanw * time, so imp > (tty | net | bio).
47 1.17.2.5 nathanw *
48 1.17.2.5 nathanw * Since run queues may be manipulated by both the statclock and tty,
49 1.17.2.5 nathanw * network, and disk drivers, clock > imp.
50 1.17.2.5 nathanw *
51 1.17.2.5 nathanw * IPL_HIGH must block everything that can manipulate a run queue.
52 1.17.2.5 nathanw *
53 1.17.2.5 nathanw * We need serial drivers to run at the absolute highest priority to
54 1.17.2.5 nathanw * avoid overruns, so serial > high.
55 1.17.2.5 nathanw */
56 1.17.2.5 nathanw #define IPL_NONE 0x00 /* nothing */
57 1.17.2.5 nathanw #define IPL_SOFTCLOCK 0x50 /* timeouts */
58 1.17.2.5 nathanw #define IPL_SOFTNET 0x60 /* protocol stacks */
59 1.17.2.5 nathanw #define IPL_BIO 0x70 /* block I/O */
60 1.17.2.5 nathanw #define IPL_NET 0x80 /* network */
61 1.17.2.5 nathanw #define IPL_SOFTSERIAL 0x90 /* serial */
62 1.17.2.5 nathanw #define IPL_TTY 0xa0 /* terminal */
63 1.17.2.5 nathanw #define IPL_IMP 0xb0 /* memory allocation */
64 1.17.2.5 nathanw #define IPL_AUDIO 0xc0 /* audio */
65 1.17.2.5 nathanw #define IPL_CLOCK 0xd0 /* clock */
66 1.17.2.5 nathanw #define IPL_HIGH 0xd0 /* everything */
67 1.17.2.5 nathanw #define IPL_SERIAL 0xd0 /* serial */
68 1.17.2.5 nathanw #define IPL_IPI 0xe0 /* inter-processor interrupts */
69 1.17.2.5 nathanw #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.17.2.5 nathanw extern volatile u_int32_t lapic_tpr;
88 1.17.2.5 nathanw extern volatile u_int32_t ipending;
89 1.17.2.5 nathanw
90 1.17.2.5 nathanw extern int imasks[NIPL];
91 1.17.2.5 nathanw extern int iunmask[NIPL];
92 1.3 mycroft
93 1.17.2.5 nathanw #define CPSHIFT 4
94 1.17.2.5 nathanw #define IMASK(level) imasks[(level)>>CPSHIFT]
95 1.17.2.5 nathanw #define IUNMASK(level) iunmask[(level)>>CPSHIFT]
96 1.17.2.5 nathanw
97 1.17.2.5 nathanw 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.17.2.3 nathanw * compiler barrier: prevent reordering of instructions.
105 1.17.2.3 nathanw * XXX something similar will move to <sys/cdefs.h>
106 1.17.2.3 nathanw * or thereabouts.
107 1.17.2.3 nathanw * This prevents the compiler from reordering code around
108 1.17.2.3 nathanw * this "instruction", acting as a sequence point for code generation.
109 1.17.2.3 nathanw */
110 1.17.2.3 nathanw
111 1.17.2.5 nathanw #define __splbarrier() __asm __volatile("" : : : "memory")
112 1.17.2.3 nathanw
113 1.17.2.3 nathanw /*
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.17.2.5 nathanw splraise(int ncpl)
118 1.3 mycroft {
119 1.17.2.5 nathanw register int ocpl = lapic_tpr;
120 1.3 mycroft
121 1.17.2.5 nathanw if (ncpl > ocpl)
122 1.17.2.5 nathanw lapic_tpr = ncpl;
123 1.17.2.3 nathanw __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.17.2.5 nathanw spllower(int ncpl)
133 1.3 mycroft {
134 1.17.2.5 nathanw register int cmask;
135 1.3 mycroft
136 1.17.2.3 nathanw __splbarrier();
137 1.17.2.5 nathanw lapic_tpr = ncpl;
138 1.17.2.5 nathanw cmask = IUNMASK(ncpl);
139 1.17.2.5 nathanw 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.17.2.5 nathanw #define splbio() splraise(IPL_BIO)
147 1.17.2.5 nathanw #define splnet() splraise(IPL_NET)
148 1.17.2.5 nathanw #define spltty() splraise(IPL_TTY)
149 1.17.2.5 nathanw #define splaudio() splraise(IPL_AUDIO)
150 1.17.2.5 nathanw #define splclock() splraise(IPL_CLOCK)
151 1.7 mycroft #define splstatclock() splclock()
152 1.17.2.5 nathanw #define splserial() splraise(IPL_SERIAL)
153 1.17.2.5 nathanw #define splipi() splraise(IPL_IPI)
154 1.17.2.5 nathanw
155 1.17.2.5 nathanw #define spllpt() spltty()
156 1.8 is
157 1.17.2.5 nathanw #define SPL_ASSERT_ATMOST(x) KDASSERT(lapic_tpr <= (x))
158 1.17.2.3 nathanw #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.17.2.5 nathanw #define spllowersoftclock() spllower(IPL_SOFTCLOCK)
167 1.17.2.5 nathanw
168 1.17.2.5 nathanw #define splsoftclock() splraise(IPL_SOFTCLOCK)
169 1.17.2.5 nathanw #define splsoftnet() splraise(IPL_SOFTNET)
170 1.17.2.5 nathanw #define splsoftserial() splraise(IPL_SOFTSERIAL)
171 1.3 mycroft
172 1.3 mycroft /*
173 1.3 mycroft * Miscellaneous
174 1.3 mycroft */
175 1.17.2.5 nathanw #define splvm() splraise(IPL_IMP)
176 1.17.2.5 nathanw #define splhigh() splraise(IPL_HIGH)
177 1.17.2.5 nathanw #define spl0() spllower(IPL_NONE)
178 1.15 thorpej #define splsched() splhigh()
179 1.17.2.5 nathanw #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.17.2.5 nathanw softintr(register int sir)
189 1.3 mycroft {
190 1.17.2.5 nathanw __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.17.2.5 nathanw /* XXX does ipi goo belong here, or elsewhere? */
196 1.17.2.5 nathanw
197 1.17.2.5 nathanw #define I386_IPI_HALT 0x00000001
198 1.17.2.5 nathanw #define I386_IPI_MICROSET 0x00000002
199 1.17.2.5 nathanw #define I386_IPI_FLUSH_FPU 0x00000004
200 1.17.2.5 nathanw #define I386_IPI_SYNCH_FPU 0x00000008
201 1.17.2.5 nathanw #define I386_IPI_TLB 0x00000010
202 1.17.2.5 nathanw #define I386_IPI_MTRR 0x00000020
203 1.17.2.5 nathanw #define I386_IPI_GDT 0x00000040
204 1.17.2.5 nathanw
205 1.17.2.5 nathanw #define I386_NIPI 7
206 1.17.2.5 nathanw
207 1.17.2.5 nathanw #ifdef MULTIPROCESSOR
208 1.17.2.5 nathanw struct cpu_info;
209 1.17.2.5 nathanw
210 1.17.2.5 nathanw int i386_send_ipi (struct cpu_info *, int);
211 1.17.2.5 nathanw void i386_broadcast_ipi (int);
212 1.17.2.5 nathanw void i386_multicast_ipi (int, int);
213 1.17.2.5 nathanw void i386_ipi_handler (void);
214 1.17.2.5 nathanw #endif
215 1.17.2.5 nathanw
216 1.3 mycroft #endif /* !_LOCORE */
217 1.17.2.1 nathanw
218 1.17.2.1 nathanw /*
219 1.17.2.1 nathanw * Generic software interrupt support.
220 1.17.2.1 nathanw */
221 1.17.2.1 nathanw
222 1.17.2.1 nathanw #define I386_SOFTINTR_SOFTCLOCK 0
223 1.17.2.1 nathanw #define I386_SOFTINTR_SOFTNET 1
224 1.17.2.1 nathanw #define I386_SOFTINTR_SOFTSERIAL 2
225 1.17.2.1 nathanw #define I386_NSOFTINTR 3
226 1.17.2.1 nathanw
227 1.17.2.1 nathanw #ifndef _LOCORE
228 1.17.2.1 nathanw #include <sys/queue.h>
229 1.17.2.1 nathanw
230 1.17.2.1 nathanw struct i386_soft_intrhand {
231 1.17.2.1 nathanw TAILQ_ENTRY(i386_soft_intrhand)
232 1.17.2.1 nathanw sih_q;
233 1.17.2.1 nathanw struct i386_soft_intr *sih_intrhead;
234 1.17.2.1 nathanw void (*sih_fn)(void *);
235 1.17.2.1 nathanw void *sih_arg;
236 1.17.2.1 nathanw int sih_pending;
237 1.17.2.1 nathanw };
238 1.17.2.1 nathanw
239 1.17.2.1 nathanw struct i386_soft_intr {
240 1.17.2.1 nathanw TAILQ_HEAD(, i386_soft_intrhand)
241 1.17.2.1 nathanw softintr_q;
242 1.17.2.1 nathanw int softintr_ssir;
243 1.17.2.5 nathanw struct simplelock softintr_slock;
244 1.17.2.1 nathanw };
245 1.17.2.1 nathanw
246 1.17.2.1 nathanw #define i386_softintr_lock(si, s) \
247 1.17.2.1 nathanw do { \
248 1.17.2.2 nathanw /* XXX splhigh braindamage on i386 */ \
249 1.17.2.2 nathanw (s) = splserial(); \
250 1.17.2.5 nathanw simple_lock(&si->softintr_slock); \
251 1.17.2.1 nathanw } while (/*CONSTCOND*/ 0)
252 1.17.2.1 nathanw
253 1.17.2.1 nathanw #define i386_softintr_unlock(si, s) \
254 1.17.2.1 nathanw do { \
255 1.17.2.5 nathanw simple_unlock(&si->softintr_slock); \
256 1.17.2.1 nathanw splx((s)); \
257 1.17.2.1 nathanw } while (/*CONSTCOND*/ 0)
258 1.17.2.1 nathanw
259 1.17.2.1 nathanw void *softintr_establish(int, void (*)(void *), void *);
260 1.17.2.1 nathanw void softintr_disestablish(void *);
261 1.17.2.1 nathanw void softintr_init(void);
262 1.17.2.1 nathanw void softintr_dispatch(int);
263 1.17.2.1 nathanw
264 1.17.2.1 nathanw #define softintr_schedule(arg) \
265 1.17.2.1 nathanw do { \
266 1.17.2.1 nathanw struct i386_soft_intrhand *__sih = (arg); \
267 1.17.2.1 nathanw struct i386_soft_intr *__si = __sih->sih_intrhead; \
268 1.17.2.1 nathanw int __s; \
269 1.17.2.1 nathanw \
270 1.17.2.1 nathanw i386_softintr_lock(__si, __s); \
271 1.17.2.1 nathanw if (__sih->sih_pending == 0) { \
272 1.17.2.1 nathanw TAILQ_INSERT_TAIL(&__si->softintr_q, __sih, sih_q); \
273 1.17.2.1 nathanw __sih->sih_pending = 1; \
274 1.17.2.1 nathanw softintr(__si->softintr_ssir); \
275 1.17.2.1 nathanw } \
276 1.17.2.1 nathanw i386_softintr_unlock(__si, __s); \
277 1.17.2.1 nathanw } while (/*CONSTCOND*/ 0)
278 1.17.2.1 nathanw #endif /* _LOCORE */
279 1.4 mycroft
280 1.4 mycroft #endif /* !_I386_INTR_H_ */
281