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