xref: /netbsd-src/sys/arch/arm/arm32/intr.c (revision 06be8101a16cc95f40783b3cb7afd12112103a9a)
1 /*	$NetBSD: intr.c,v 1.3 2001/10/27 16:34:12 rearnsha Exp $	*/
2 
3 /*
4  * Copyright (c) 1994-1998 Mark Brinicombe.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by Mark Brinicombe
18  *	for the NetBSD Project.
19  * 4. The name of the company nor the name of the author may be used to
20  *    endorse or promote products derived from this software without specific
21  *    prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  * Soft interrupt and other generic interrupt functions.
36  */
37 
38 #include "opt_irqstats.h"
39 
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/syslog.h>
43 #include <sys/malloc.h>
44 
45 #include <uvm/uvm_extern.h>
46 
47 #include <machine/intr.h>
48 #include <machine/cpu.h>
49 
50 #include <net/netisr.h>
51 
52 #include <machine/conf.h>
53 
54 #ifndef NPLCOM
55 #define NPLCOM 0
56 #endif
57 
58 u_int soft_interrupts = 0;
59 
60 extern int current_spl_level;
61 
62 extern unsigned spl_mask;
63 
64 /* Generate soft interrupt counts if IRQSTATS is defined */
65 #ifdef IRQSTATS
66 extern u_int sintrcnt[];
67 #define INC_SINTRCNT(x) ++sintrcnt[x]
68 #else
69 #define INC_SINTRCNT(x)
70 #endif	/* IRQSTATS */
71 
72 #define	COUNT	uvmexp.softs;
73 
74 /* Prototypes */
75 
76 #include "com.h"
77 #if NCOM > 0
78 extern void comsoft	__P((void));
79 #endif	/* NCOM > 0 */
80 
81 #if NPLCOM > 0
82 extern void plcomsoft	__P((void));
83 #endif	/* NPLCOM > 0 */
84 
85 /* Eventually these will become macros */
86 
87 void
88 setsoftintr(intrmask)
89 	u_int intrmask;
90 {
91 	atomic_set_bit(&soft_interrupts, intrmask);
92 }
93 
94 void
95 clearsoftintr(intrmask)
96 	u_int intrmask;
97 {
98 	atomic_clear_bit(&soft_interrupts, intrmask);
99 }
100 
101 void
102 setsoftclock()
103 {
104 	atomic_set_bit(&soft_interrupts, SOFTIRQ_BIT(SOFTIRQ_CLOCK));
105 }
106 
107 void
108 setsoftnet()
109 {
110 	atomic_set_bit(&soft_interrupts, SOFTIRQ_BIT(SOFTIRQ_NET));
111 }
112 
113 void
114 setsoftserial()
115 {
116 	atomic_set_bit(&soft_interrupts, SOFTIRQ_BIT(SOFTIRQ_SERIAL));
117 }
118 
119 int astpending;
120 
121 /* Handle software interrupts */
122 
123 void
124 dosoftints()
125 {
126 	u_int softints;
127 	int s;
128 
129 	softints = soft_interrupts & spl_smasks[current_spl_level];
130 	if (softints == 0) return;
131 
132 	/*
133 	 * Software clock interrupts
134 	 */
135 
136 	if (softints & SOFTIRQ_BIT(SOFTIRQ_CLOCK)) {
137 		s = splsoftclock();
138 		++COUNT;
139 		INC_SINTRCNT(SOFTIRQ_CLOCK);
140 		clearsoftintr(SOFTIRQ_BIT(SOFTIRQ_CLOCK));
141 		softclock(NULL);
142 		(void)splx(s);
143 	}
144 
145 	/*
146 	 * Network software interrupts
147 	 */
148 
149 	if (softints & SOFTIRQ_BIT(SOFTIRQ_NET)) {
150 		s = splsoftnet();
151 		++COUNT;
152 		INC_SINTRCNT(SOFTIRQ_NET);
153 		clearsoftintr(SOFTIRQ_BIT(SOFTIRQ_NET));
154 
155 #define DONETISR(bit, fn) do {					\
156 		if (netisr & (1 << bit)) {			\
157 			atomic_clear_bit(&netisr, (1 << bit));	\
158 			fn();					\
159 		}						\
160 } while (0)
161 
162 #include <net/netisr_dispatch.h>
163 
164 #undef DONETISR
165 
166 		(void)splx(s);
167 	}
168 	/*
169 	 * Serial software interrupts
170 	 */
171 
172 	if (softints & SOFTIRQ_BIT(SOFTIRQ_SERIAL)) {
173 		s = splsoftserial();
174 		++COUNT;
175 		INC_SINTRCNT(SOFTIRQ_SERIAL);
176 		clearsoftintr(SOFTIRQ_BIT(SOFTIRQ_SERIAL));
177 #if NCOM > 0
178 		comsoft();
179 #endif	/* NCOM > 0 */
180 #if NPLCOM > 0
181 		plcomsoft();
182 #endif	/* NPLCOM > 0 */
183 		(void)splx(s);
184 	}
185 }
186 
187 /* End of intr.c */
188