intr.c revision 1.14 1 1.14 yamt /* $NetBSD: intr.c,v 1.14 2006/12/21 15:55:22 yamt Exp $ */
2 1.1 chris
3 1.1 chris /*
4 1.1 chris * Copyright (c) 1994-1998 Mark Brinicombe.
5 1.1 chris * All rights reserved.
6 1.1 chris *
7 1.1 chris * Redistribution and use in source and binary forms, with or without
8 1.1 chris * modification, are permitted provided that the following conditions
9 1.1 chris * are met:
10 1.1 chris * 1. Redistributions of source code must retain the above copyright
11 1.1 chris * notice, this list of conditions and the following disclaimer.
12 1.1 chris * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 chris * notice, this list of conditions and the following disclaimer in the
14 1.1 chris * documentation and/or other materials provided with the distribution.
15 1.1 chris * 3. All advertising materials mentioning features or use of this software
16 1.1 chris * must display the following acknowledgement:
17 1.1 chris * This product includes software developed by Mark Brinicombe
18 1.1 chris * for the NetBSD Project.
19 1.1 chris * 4. The name of the company nor the name of the author may be used to
20 1.1 chris * endorse or promote products derived from this software without specific
21 1.1 chris * prior written permission.
22 1.1 chris *
23 1.1 chris * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 1.1 chris * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 1.1 chris * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 1.1 chris * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 1.1 chris * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 1.1 chris * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29 1.1 chris * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 chris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 chris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 chris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 chris * SUCH DAMAGE.
34 1.1 chris *
35 1.1 chris * Soft interrupt and other generic interrupt functions.
36 1.1 chris */
37 1.12 lukem
38 1.12 lukem #include <sys/cdefs.h>
39 1.14 yamt __KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.14 2006/12/21 15:55:22 yamt Exp $");
40 1.1 chris
41 1.1 chris #include "opt_irqstats.h"
42 1.1 chris
43 1.1 chris #include <sys/param.h>
44 1.1 chris #include <sys/systm.h>
45 1.1 chris #include <sys/syslog.h>
46 1.1 chris #include <sys/malloc.h>
47 1.9 gehenna #include <sys/conf.h>
48 1.1 chris
49 1.1 chris #include <uvm/uvm_extern.h>
50 1.1 chris
51 1.10 bsh #include <machine/atomic.h>
52 1.2 matt #include <machine/intr.h>
53 1.1 chris #include <machine/cpu.h>
54 1.1 chris
55 1.1 chris #include <net/netisr.h>
56 1.1 chris
57 1.6 chris #include <arm/arm32/machdep.h>
58 1.6 chris
59 1.3 rearnsha #ifndef NPLCOM
60 1.3 rearnsha #define NPLCOM 0
61 1.3 rearnsha #endif
62 1.3 rearnsha
63 1.6 chris /* Prototypes */
64 1.6 chris static void clearsoftintr __P((u_int));
65 1.6 chris
66 1.1 chris u_int soft_interrupts = 0;
67 1.1 chris
68 1.1 chris extern int current_spl_level;
69 1.1 chris
70 1.3 rearnsha extern unsigned spl_mask;
71 1.3 rearnsha
72 1.1 chris /* Generate soft interrupt counts if IRQSTATS is defined */
73 1.1 chris #ifdef IRQSTATS
74 1.1 chris extern u_int sintrcnt[];
75 1.1 chris #define INC_SINTRCNT(x) ++sintrcnt[x]
76 1.1 chris #else
77 1.1 chris #define INC_SINTRCNT(x)
78 1.1 chris #endif /* IRQSTATS */
79 1.1 chris
80 1.1 chris #define COUNT uvmexp.softs;
81 1.1 chris
82 1.1 chris /* Prototypes */
83 1.1 chris
84 1.1 chris #include "com.h"
85 1.1 chris #if NCOM > 0
86 1.1 chris extern void comsoft __P((void));
87 1.1 chris #endif /* NCOM > 0 */
88 1.1 chris
89 1.3 rearnsha #if NPLCOM > 0
90 1.3 rearnsha extern void plcomsoft __P((void));
91 1.3 rearnsha #endif /* NPLCOM > 0 */
92 1.3 rearnsha
93 1.1 chris /* Eventually these will become macros */
94 1.1 chris
95 1.1 chris void
96 1.1 chris setsoftintr(intrmask)
97 1.1 chris u_int intrmask;
98 1.1 chris {
99 1.1 chris atomic_set_bit(&soft_interrupts, intrmask);
100 1.1 chris }
101 1.1 chris
102 1.6 chris static void
103 1.1 chris clearsoftintr(intrmask)
104 1.1 chris u_int intrmask;
105 1.1 chris {
106 1.1 chris atomic_clear_bit(&soft_interrupts, intrmask);
107 1.1 chris }
108 1.1 chris
109 1.1 chris void
110 1.1 chris setsoftclock()
111 1.1 chris {
112 1.1 chris atomic_set_bit(&soft_interrupts, SOFTIRQ_BIT(SOFTIRQ_CLOCK));
113 1.1 chris }
114 1.1 chris
115 1.1 chris void
116 1.1 chris setsoftnet()
117 1.1 chris {
118 1.1 chris atomic_set_bit(&soft_interrupts, SOFTIRQ_BIT(SOFTIRQ_NET));
119 1.1 chris }
120 1.1 chris
121 1.1 chris void
122 1.1 chris setsoftserial()
123 1.1 chris {
124 1.1 chris atomic_set_bit(&soft_interrupts, SOFTIRQ_BIT(SOFTIRQ_SERIAL));
125 1.1 chris }
126 1.1 chris
127 1.1 chris /* Handle software interrupts */
128 1.1 chris
129 1.1 chris void
130 1.1 chris dosoftints()
131 1.1 chris {
132 1.1 chris u_int softints;
133 1.1 chris int s;
134 1.1 chris
135 1.1 chris softints = soft_interrupts & spl_smasks[current_spl_level];
136 1.1 chris if (softints == 0) return;
137 1.1 chris
138 1.1 chris /*
139 1.1 chris * Software clock interrupts
140 1.1 chris */
141 1.1 chris
142 1.1 chris if (softints & SOFTIRQ_BIT(SOFTIRQ_CLOCK)) {
143 1.1 chris s = splsoftclock();
144 1.1 chris ++COUNT;
145 1.1 chris INC_SINTRCNT(SOFTIRQ_CLOCK);
146 1.1 chris clearsoftintr(SOFTIRQ_BIT(SOFTIRQ_CLOCK));
147 1.1 chris softclock(NULL);
148 1.1 chris (void)splx(s);
149 1.1 chris }
150 1.1 chris
151 1.1 chris /*
152 1.1 chris * Network software interrupts
153 1.1 chris */
154 1.1 chris
155 1.1 chris if (softints & SOFTIRQ_BIT(SOFTIRQ_NET)) {
156 1.1 chris s = splsoftnet();
157 1.1 chris ++COUNT;
158 1.1 chris INC_SINTRCNT(SOFTIRQ_NET);
159 1.1 chris clearsoftintr(SOFTIRQ_BIT(SOFTIRQ_NET));
160 1.1 chris
161 1.1 chris #define DONETISR(bit, fn) do { \
162 1.1 chris if (netisr & (1 << bit)) { \
163 1.1 chris atomic_clear_bit(&netisr, (1 << bit)); \
164 1.1 chris fn(); \
165 1.1 chris } \
166 1.1 chris } while (0)
167 1.1 chris
168 1.1 chris #include <net/netisr_dispatch.h>
169 1.1 chris
170 1.1 chris #undef DONETISR
171 1.1 chris
172 1.1 chris (void)splx(s);
173 1.1 chris }
174 1.1 chris /*
175 1.1 chris * Serial software interrupts
176 1.1 chris */
177 1.1 chris
178 1.1 chris if (softints & SOFTIRQ_BIT(SOFTIRQ_SERIAL)) {
179 1.1 chris s = splsoftserial();
180 1.1 chris ++COUNT;
181 1.1 chris INC_SINTRCNT(SOFTIRQ_SERIAL);
182 1.1 chris clearsoftintr(SOFTIRQ_BIT(SOFTIRQ_SERIAL));
183 1.1 chris #if NCOM > 0
184 1.1 chris comsoft();
185 1.1 chris #endif /* NCOM > 0 */
186 1.3 rearnsha #if NPLCOM > 0
187 1.3 rearnsha plcomsoft();
188 1.3 rearnsha #endif /* NPLCOM > 0 */
189 1.1 chris (void)splx(s);
190 1.1 chris }
191 1.1 chris }
192 1.4 thorpej
193 1.4 thorpej int current_spl_level = _SPL_SERIAL;
194 1.4 thorpej u_int spl_masks[_SPL_LEVELS + 1];
195 1.4 thorpej u_int spl_smasks[_SPL_LEVELS];
196 1.4 thorpej int safepri = _SPL_0;
197 1.7 thorpej
198 1.8 chris extern u_int irqmasks[];
199 1.4 thorpej
200 1.4 thorpej void
201 1.4 thorpej set_spl_masks()
202 1.4 thorpej {
203 1.4 thorpej int loop;
204 1.4 thorpej
205 1.4 thorpej for (loop = 0; loop < _SPL_LEVELS; ++loop) {
206 1.4 thorpej spl_masks[loop] = 0xffffffff;
207 1.4 thorpej spl_smasks[loop] = 0;
208 1.4 thorpej }
209 1.4 thorpej
210 1.4 thorpej spl_masks[_SPL_BIO] = irqmasks[IPL_BIO];
211 1.4 thorpej spl_masks[_SPL_NET] = irqmasks[IPL_NET];
212 1.4 thorpej spl_masks[_SPL_SOFTSERIAL] = irqmasks[IPL_TTY];
213 1.4 thorpej spl_masks[_SPL_TTY] = irqmasks[IPL_TTY];
214 1.11 thorpej spl_masks[_SPL_VM] = irqmasks[IPL_VM];
215 1.4 thorpej spl_masks[_SPL_AUDIO] = irqmasks[IPL_AUDIO];
216 1.4 thorpej spl_masks[_SPL_CLOCK] = irqmasks[IPL_CLOCK];
217 1.4 thorpej #ifdef IPL_STATCLOCK
218 1.4 thorpej spl_masks[_SPL_STATCLOCK] = irqmasks[IPL_STATCLOCK];
219 1.4 thorpej #else
220 1.4 thorpej spl_masks[_SPL_STATCLOCK] = irqmasks[IPL_CLOCK];
221 1.4 thorpej #endif
222 1.4 thorpej spl_masks[_SPL_HIGH] = irqmasks[IPL_HIGH];
223 1.4 thorpej spl_masks[_SPL_SERIAL] = irqmasks[IPL_SERIAL];
224 1.4 thorpej spl_masks[_SPL_LEVELS] = 0;
225 1.4 thorpej
226 1.4 thorpej spl_smasks[_SPL_0] = 0xffffffff;
227 1.4 thorpej for (loop = 0; loop < _SPL_SOFTSERIAL; ++loop)
228 1.4 thorpej spl_smasks[loop] |= SOFTIRQ_BIT(SOFTIRQ_SERIAL);
229 1.4 thorpej for (loop = 0; loop < _SPL_SOFTNET; ++loop)
230 1.4 thorpej spl_smasks[loop] |= SOFTIRQ_BIT(SOFTIRQ_NET);
231 1.4 thorpej for (loop = 0; loop < _SPL_SOFTCLOCK; ++loop)
232 1.4 thorpej spl_smasks[loop] |= SOFTIRQ_BIT(SOFTIRQ_CLOCK);
233 1.4 thorpej }
234 1.4 thorpej
235 1.14 yamt int
236 1.14 yamt ipl_to_spl(int ipl)
237 1.14 yamt {
238 1.14 yamt
239 1.14 yamt switch (ipl) {
240 1.14 yamt case IPL_NONE:
241 1.14 yamt return _SPL_0;
242 1.14 yamt #if defined(IPL_SOFTCLOCK)
243 1.14 yamt case IPL_SOFTCLOCK:
244 1.14 yamt return _SPL_SOFTCLOCK;
245 1.14 yamt #endif /* defined(IPL_SOFTCLOCK) */
246 1.14 yamt #if defined(IPL_SOFTNET)
247 1.14 yamt case IPL_SOFTNET:
248 1.14 yamt return _SPL_SOFTNET;
249 1.14 yamt #endif /* defined(IPL_SOFTNET) */
250 1.14 yamt case IPL_BIO:
251 1.14 yamt return _SPL_BIO;
252 1.14 yamt case IPL_NET:
253 1.14 yamt return _SPL_NET;
254 1.14 yamt #if defined(IPL_SOFTSERIAL)
255 1.14 yamt case IPL_SOFTSERIAL:
256 1.14 yamt return _SPL_SOFTSERIAL;
257 1.14 yamt #endif /* defined(IPL_SOFTSERIAL) */
258 1.14 yamt case IPL_TTY:
259 1.14 yamt return _SPL_TTY;
260 1.14 yamt case IPL_VM:
261 1.14 yamt return _SPL_VM;
262 1.14 yamt case IPL_AUDIO:
263 1.14 yamt return _SPL_AUDIO;
264 1.14 yamt case IPL_CLOCK:
265 1.14 yamt return _SPL_CLOCK;
266 1.14 yamt case IPL_STATCLOCK:
267 1.14 yamt return _SPL_STATCLOCK;
268 1.14 yamt case IPL_HIGH:
269 1.14 yamt return _SPL_HIGH;
270 1.14 yamt case IPL_SERIAL:
271 1.14 yamt return _SPL_SERIAL;
272 1.14 yamt default:
273 1.14 yamt panic("bogus ipl %d", ipl);
274 1.14 yamt }
275 1.14 yamt }
276 1.14 yamt
277 1.4 thorpej #ifdef DIAGNOSTIC
278 1.4 thorpej void
279 1.4 thorpej dump_spl_masks()
280 1.4 thorpej {
281 1.4 thorpej int loop;
282 1.4 thorpej
283 1.4 thorpej for (loop = 0; loop < _SPL_LEVELS; ++loop) {
284 1.4 thorpej printf("spl_mask[%d]=%08x splsmask[%d]=%08x\n", loop,
285 1.4 thorpej spl_masks[loop], loop, spl_smasks[loop]);
286 1.4 thorpej }
287 1.4 thorpej }
288 1.4 thorpej #endif
289 1.1 chris
290 1.1 chris /* End of intr.c */
291