intr.c revision 1.1 1 1.1 chris /* $NetBSD: intr.c,v 1.1 2001/07/28 13:28:03 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.1 chris #include <machine/irqhandler.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.1 chris u_int soft_interrupts = 0;
53 1.1 chris
54 1.1 chris extern int current_spl_level;
55 1.1 chris
56 1.1 chris /* Generate soft interrupt counts if IRQSTATS is defined */
57 1.1 chris #ifdef IRQSTATS
58 1.1 chris extern u_int sintrcnt[];
59 1.1 chris #define INC_SINTRCNT(x) ++sintrcnt[x]
60 1.1 chris #else
61 1.1 chris #define INC_SINTRCNT(x)
62 1.1 chris #endif /* IRQSTATS */
63 1.1 chris
64 1.1 chris #define COUNT uvmexp.softs;
65 1.1 chris
66 1.1 chris /* Prototypes */
67 1.1 chris
68 1.1 chris #include "com.h"
69 1.1 chris #if NCOM > 0
70 1.1 chris extern void comsoft __P((void));
71 1.1 chris #endif /* NCOM > 0 */
72 1.1 chris
73 1.1 chris /* Eventually these will become macros */
74 1.1 chris
75 1.1 chris void
76 1.1 chris setsoftintr(intrmask)
77 1.1 chris u_int intrmask;
78 1.1 chris {
79 1.1 chris atomic_set_bit(&soft_interrupts, intrmask);
80 1.1 chris }
81 1.1 chris
82 1.1 chris void
83 1.1 chris clearsoftintr(intrmask)
84 1.1 chris u_int intrmask;
85 1.1 chris {
86 1.1 chris atomic_clear_bit(&soft_interrupts, intrmask);
87 1.1 chris }
88 1.1 chris
89 1.1 chris void
90 1.1 chris setsoftclock()
91 1.1 chris {
92 1.1 chris atomic_set_bit(&soft_interrupts, SOFTIRQ_BIT(SOFTIRQ_CLOCK));
93 1.1 chris }
94 1.1 chris
95 1.1 chris void
96 1.1 chris setsoftnet()
97 1.1 chris {
98 1.1 chris atomic_set_bit(&soft_interrupts, SOFTIRQ_BIT(SOFTIRQ_NET));
99 1.1 chris }
100 1.1 chris
101 1.1 chris void
102 1.1 chris setsoftserial()
103 1.1 chris {
104 1.1 chris atomic_set_bit(&soft_interrupts, SOFTIRQ_BIT(SOFTIRQ_SERIAL));
105 1.1 chris }
106 1.1 chris
107 1.1 chris int astpending;
108 1.1 chris
109 1.1 chris /* Handle software interrupts */
110 1.1 chris
111 1.1 chris void
112 1.1 chris dosoftints()
113 1.1 chris {
114 1.1 chris u_int softints;
115 1.1 chris int s;
116 1.1 chris
117 1.1 chris softints = soft_interrupts & spl_smasks[current_spl_level];
118 1.1 chris if (softints == 0) return;
119 1.1 chris
120 1.1 chris /*
121 1.1 chris * Software clock interrupts
122 1.1 chris */
123 1.1 chris
124 1.1 chris if (softints & SOFTIRQ_BIT(SOFTIRQ_CLOCK)) {
125 1.1 chris s = splsoftclock();
126 1.1 chris ++COUNT;
127 1.1 chris INC_SINTRCNT(SOFTIRQ_CLOCK);
128 1.1 chris clearsoftintr(SOFTIRQ_BIT(SOFTIRQ_CLOCK));
129 1.1 chris softclock(NULL);
130 1.1 chris (void)splx(s);
131 1.1 chris }
132 1.1 chris
133 1.1 chris /*
134 1.1 chris * Network software interrupts
135 1.1 chris */
136 1.1 chris
137 1.1 chris if (softints & SOFTIRQ_BIT(SOFTIRQ_NET)) {
138 1.1 chris s = splsoftnet();
139 1.1 chris ++COUNT;
140 1.1 chris INC_SINTRCNT(SOFTIRQ_NET);
141 1.1 chris clearsoftintr(SOFTIRQ_BIT(SOFTIRQ_NET));
142 1.1 chris
143 1.1 chris #define DONETISR(bit, fn) do { \
144 1.1 chris if (netisr & (1 << bit)) { \
145 1.1 chris atomic_clear_bit(&netisr, (1 << bit)); \
146 1.1 chris fn(); \
147 1.1 chris } \
148 1.1 chris } while (0)
149 1.1 chris
150 1.1 chris #include <net/netisr_dispatch.h>
151 1.1 chris
152 1.1 chris #undef DONETISR
153 1.1 chris
154 1.1 chris (void)splx(s);
155 1.1 chris }
156 1.1 chris /*
157 1.1 chris * Serial software interrupts
158 1.1 chris */
159 1.1 chris
160 1.1 chris if (softints & SOFTIRQ_BIT(SOFTIRQ_SERIAL)) {
161 1.1 chris s = splsoftserial();
162 1.1 chris ++COUNT;
163 1.1 chris INC_SINTRCNT(SOFTIRQ_SERIAL);
164 1.1 chris clearsoftintr(SOFTIRQ_BIT(SOFTIRQ_SERIAL));
165 1.1 chris #if NCOM > 0
166 1.1 chris comsoft();
167 1.1 chris #endif /* NCOM > 0 */
168 1.1 chris (void)splx(s);
169 1.1 chris }
170 1.1 chris }
171 1.1 chris
172 1.1 chris /* End of intr.c */
173