intr.c revision 1.11 1 1.11 thorpej /* $NetBSD: intr.c,v 1.11 2003/06/16 20:00:57 thorpej 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.1 chris
38 1.1 chris #include "opt_irqstats.h"
39 1.1 chris
40 1.1 chris #include <sys/param.h>
41 1.1 chris #include <sys/systm.h>
42 1.1 chris #include <sys/syslog.h>
43 1.1 chris #include <sys/malloc.h>
44 1.9 gehenna #include <sys/conf.h>
45 1.1 chris
46 1.1 chris #include <uvm/uvm_extern.h>
47 1.1 chris
48 1.10 bsh #include <machine/atomic.h>
49 1.2 matt #include <machine/intr.h>
50 1.1 chris #include <machine/cpu.h>
51 1.1 chris
52 1.1 chris #include <net/netisr.h>
53 1.1 chris
54 1.6 chris #include <arm/arm32/machdep.h>
55 1.6 chris
56 1.3 rearnsha #ifndef NPLCOM
57 1.3 rearnsha #define NPLCOM 0
58 1.3 rearnsha #endif
59 1.3 rearnsha
60 1.6 chris /* Prototypes */
61 1.6 chris static void clearsoftintr __P((u_int));
62 1.6 chris
63 1.1 chris u_int soft_interrupts = 0;
64 1.1 chris
65 1.1 chris extern int current_spl_level;
66 1.1 chris
67 1.3 rearnsha extern unsigned spl_mask;
68 1.3 rearnsha
69 1.1 chris /* Generate soft interrupt counts if IRQSTATS is defined */
70 1.1 chris #ifdef IRQSTATS
71 1.1 chris extern u_int sintrcnt[];
72 1.1 chris #define INC_SINTRCNT(x) ++sintrcnt[x]
73 1.1 chris #else
74 1.1 chris #define INC_SINTRCNT(x)
75 1.1 chris #endif /* IRQSTATS */
76 1.1 chris
77 1.1 chris #define COUNT uvmexp.softs;
78 1.1 chris
79 1.1 chris /* Prototypes */
80 1.1 chris
81 1.1 chris #include "com.h"
82 1.1 chris #if NCOM > 0
83 1.1 chris extern void comsoft __P((void));
84 1.1 chris #endif /* NCOM > 0 */
85 1.1 chris
86 1.3 rearnsha #if NPLCOM > 0
87 1.3 rearnsha extern void plcomsoft __P((void));
88 1.3 rearnsha #endif /* NPLCOM > 0 */
89 1.3 rearnsha
90 1.1 chris /* Eventually these will become macros */
91 1.1 chris
92 1.1 chris void
93 1.1 chris setsoftintr(intrmask)
94 1.1 chris u_int intrmask;
95 1.1 chris {
96 1.1 chris atomic_set_bit(&soft_interrupts, intrmask);
97 1.1 chris }
98 1.1 chris
99 1.6 chris static void
100 1.1 chris clearsoftintr(intrmask)
101 1.1 chris u_int intrmask;
102 1.1 chris {
103 1.1 chris atomic_clear_bit(&soft_interrupts, intrmask);
104 1.1 chris }
105 1.1 chris
106 1.1 chris void
107 1.1 chris setsoftclock()
108 1.1 chris {
109 1.1 chris atomic_set_bit(&soft_interrupts, SOFTIRQ_BIT(SOFTIRQ_CLOCK));
110 1.1 chris }
111 1.1 chris
112 1.1 chris void
113 1.1 chris setsoftnet()
114 1.1 chris {
115 1.1 chris atomic_set_bit(&soft_interrupts, SOFTIRQ_BIT(SOFTIRQ_NET));
116 1.1 chris }
117 1.1 chris
118 1.1 chris void
119 1.1 chris setsoftserial()
120 1.1 chris {
121 1.1 chris atomic_set_bit(&soft_interrupts, SOFTIRQ_BIT(SOFTIRQ_SERIAL));
122 1.1 chris }
123 1.1 chris
124 1.1 chris /* Handle software interrupts */
125 1.1 chris
126 1.1 chris void
127 1.1 chris dosoftints()
128 1.1 chris {
129 1.1 chris u_int softints;
130 1.1 chris int s;
131 1.1 chris
132 1.1 chris softints = soft_interrupts & spl_smasks[current_spl_level];
133 1.1 chris if (softints == 0) return;
134 1.1 chris
135 1.1 chris /*
136 1.1 chris * Software clock interrupts
137 1.1 chris */
138 1.1 chris
139 1.1 chris if (softints & SOFTIRQ_BIT(SOFTIRQ_CLOCK)) {
140 1.1 chris s = splsoftclock();
141 1.1 chris ++COUNT;
142 1.1 chris INC_SINTRCNT(SOFTIRQ_CLOCK);
143 1.1 chris clearsoftintr(SOFTIRQ_BIT(SOFTIRQ_CLOCK));
144 1.1 chris softclock(NULL);
145 1.1 chris (void)splx(s);
146 1.1 chris }
147 1.1 chris
148 1.1 chris /*
149 1.1 chris * Network software interrupts
150 1.1 chris */
151 1.1 chris
152 1.1 chris if (softints & SOFTIRQ_BIT(SOFTIRQ_NET)) {
153 1.1 chris s = splsoftnet();
154 1.1 chris ++COUNT;
155 1.1 chris INC_SINTRCNT(SOFTIRQ_NET);
156 1.1 chris clearsoftintr(SOFTIRQ_BIT(SOFTIRQ_NET));
157 1.1 chris
158 1.1 chris #define DONETISR(bit, fn) do { \
159 1.1 chris if (netisr & (1 << bit)) { \
160 1.1 chris atomic_clear_bit(&netisr, (1 << bit)); \
161 1.1 chris fn(); \
162 1.1 chris } \
163 1.1 chris } while (0)
164 1.1 chris
165 1.1 chris #include <net/netisr_dispatch.h>
166 1.1 chris
167 1.1 chris #undef DONETISR
168 1.1 chris
169 1.1 chris (void)splx(s);
170 1.1 chris }
171 1.1 chris /*
172 1.1 chris * Serial software interrupts
173 1.1 chris */
174 1.1 chris
175 1.1 chris if (softints & SOFTIRQ_BIT(SOFTIRQ_SERIAL)) {
176 1.1 chris s = splsoftserial();
177 1.1 chris ++COUNT;
178 1.1 chris INC_SINTRCNT(SOFTIRQ_SERIAL);
179 1.1 chris clearsoftintr(SOFTIRQ_BIT(SOFTIRQ_SERIAL));
180 1.1 chris #if NCOM > 0
181 1.1 chris comsoft();
182 1.1 chris #endif /* NCOM > 0 */
183 1.3 rearnsha #if NPLCOM > 0
184 1.3 rearnsha plcomsoft();
185 1.3 rearnsha #endif /* NPLCOM > 0 */
186 1.1 chris (void)splx(s);
187 1.1 chris }
188 1.1 chris }
189 1.4 thorpej
190 1.4 thorpej int current_spl_level = _SPL_SERIAL;
191 1.4 thorpej u_int spl_masks[_SPL_LEVELS + 1];
192 1.4 thorpej u_int spl_smasks[_SPL_LEVELS];
193 1.4 thorpej int safepri = _SPL_0;
194 1.7 thorpej
195 1.8 chris extern u_int irqmasks[];
196 1.4 thorpej
197 1.4 thorpej void
198 1.4 thorpej set_spl_masks()
199 1.4 thorpej {
200 1.4 thorpej int loop;
201 1.4 thorpej
202 1.4 thorpej for (loop = 0; loop < _SPL_LEVELS; ++loop) {
203 1.4 thorpej spl_masks[loop] = 0xffffffff;
204 1.4 thorpej spl_smasks[loop] = 0;
205 1.4 thorpej }
206 1.4 thorpej
207 1.4 thorpej spl_masks[_SPL_BIO] = irqmasks[IPL_BIO];
208 1.4 thorpej spl_masks[_SPL_NET] = irqmasks[IPL_NET];
209 1.4 thorpej spl_masks[_SPL_SOFTSERIAL] = irqmasks[IPL_TTY];
210 1.4 thorpej spl_masks[_SPL_TTY] = irqmasks[IPL_TTY];
211 1.11 thorpej spl_masks[_SPL_VM] = irqmasks[IPL_VM];
212 1.4 thorpej spl_masks[_SPL_AUDIO] = irqmasks[IPL_AUDIO];
213 1.4 thorpej spl_masks[_SPL_CLOCK] = irqmasks[IPL_CLOCK];
214 1.4 thorpej #ifdef IPL_STATCLOCK
215 1.4 thorpej spl_masks[_SPL_STATCLOCK] = irqmasks[IPL_STATCLOCK];
216 1.4 thorpej #else
217 1.4 thorpej spl_masks[_SPL_STATCLOCK] = irqmasks[IPL_CLOCK];
218 1.4 thorpej #endif
219 1.4 thorpej spl_masks[_SPL_HIGH] = irqmasks[IPL_HIGH];
220 1.4 thorpej spl_masks[_SPL_SERIAL] = irqmasks[IPL_SERIAL];
221 1.4 thorpej spl_masks[_SPL_LEVELS] = 0;
222 1.4 thorpej
223 1.4 thorpej spl_smasks[_SPL_0] = 0xffffffff;
224 1.4 thorpej for (loop = 0; loop < _SPL_SOFTSERIAL; ++loop)
225 1.4 thorpej spl_smasks[loop] |= SOFTIRQ_BIT(SOFTIRQ_SERIAL);
226 1.4 thorpej for (loop = 0; loop < _SPL_SOFTNET; ++loop)
227 1.4 thorpej spl_smasks[loop] |= SOFTIRQ_BIT(SOFTIRQ_NET);
228 1.4 thorpej for (loop = 0; loop < _SPL_SOFTCLOCK; ++loop)
229 1.4 thorpej spl_smasks[loop] |= SOFTIRQ_BIT(SOFTIRQ_CLOCK);
230 1.4 thorpej }
231 1.4 thorpej
232 1.4 thorpej #ifdef DIAGNOSTIC
233 1.4 thorpej void
234 1.4 thorpej dump_spl_masks()
235 1.4 thorpej {
236 1.4 thorpej int loop;
237 1.4 thorpej
238 1.4 thorpej for (loop = 0; loop < _SPL_LEVELS; ++loop) {
239 1.4 thorpej printf("spl_mask[%d]=%08x splsmask[%d]=%08x\n", loop,
240 1.4 thorpej spl_masks[loop], loop, spl_smasks[loop]);
241 1.4 thorpej }
242 1.4 thorpej }
243 1.4 thorpej #endif
244 1.1 chris
245 1.1 chris /* End of intr.c */
246