s3c2xx0_intr.c revision 1.1.2.2 1 1.1.2.2 thorpej /* $NetBSD: s3c2xx0_intr.c,v 1.1.2.2 2002/12/11 05:53:16 thorpej Exp $ */
2 1.1.2.2 thorpej
3 1.1.2.2 thorpej /*
4 1.1.2.2 thorpej * Copyright (c) 2002 Fujitsu Component Limited
5 1.1.2.2 thorpej * Copyright (c) 2002 Genetec Corporation
6 1.1.2.2 thorpej * All rights reserved.
7 1.1.2.2 thorpej *
8 1.1.2.2 thorpej * Redistribution and use in source and binary forms, with or without
9 1.1.2.2 thorpej * modification, are permitted provided that the following conditions
10 1.1.2.2 thorpej * are met:
11 1.1.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
12 1.1.2.2 thorpej * notice, this list of conditions and the following disclaimer.
13 1.1.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
14 1.1.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
15 1.1.2.2 thorpej * documentation and/or other materials provided with the distribution.
16 1.1.2.2 thorpej * 3. Neither the name of The Fujitsu Component Limited nor the name of
17 1.1.2.2 thorpej * Genetec corporation may not be used to endorse or promote products
18 1.1.2.2 thorpej * derived from this software without specific prior written permission.
19 1.1.2.2 thorpej *
20 1.1.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY FUJITSU COMPONENT LIMITED AND GENETEC
21 1.1.2.2 thorpej * CORPORATION ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 1.1.2.2 thorpej * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 1.1.2.2 thorpej * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 1.1.2.2 thorpej * DISCLAIMED. IN NO EVENT SHALL FUJITSU COMPONENT LIMITED OR GENETEC
25 1.1.2.2 thorpej * CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 1.1.2.2 thorpej * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 1.1.2.2 thorpej * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
28 1.1.2.2 thorpej * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29 1.1.2.2 thorpej * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 1.1.2.2 thorpej * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 1.1.2.2 thorpej * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.1.2.2 thorpej * SUCH DAMAGE.
33 1.1.2.2 thorpej */
34 1.1.2.2 thorpej
35 1.1.2.2 thorpej /*
36 1.1.2.2 thorpej * Common part of IRQ handlers for Samsung S3C2800/2400/2410 processors.
37 1.1.2.2 thorpej * derived from i80321_icu.c
38 1.1.2.2 thorpej */
39 1.1.2.2 thorpej
40 1.1.2.2 thorpej /*
41 1.1.2.2 thorpej * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
42 1.1.2.2 thorpej * All rights reserved.
43 1.1.2.2 thorpej *
44 1.1.2.2 thorpej * Written by Jason R. Thorpe for Wasabi Systems, Inc.
45 1.1.2.2 thorpej *
46 1.1.2.2 thorpej * Redistribution and use in source and binary forms, with or without
47 1.1.2.2 thorpej * modification, are permitted provided that the following conditions
48 1.1.2.2 thorpej * are met:
49 1.1.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
50 1.1.2.2 thorpej * notice, this list of conditions and the following disclaimer.
51 1.1.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
52 1.1.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
53 1.1.2.2 thorpej * documentation and/or other materials provided with the distribution.
54 1.1.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
55 1.1.2.2 thorpej * must display the following acknowledgement:
56 1.1.2.2 thorpej * This product includes software developed for the NetBSD Project by
57 1.1.2.2 thorpej * Wasabi Systems, Inc.
58 1.1.2.2 thorpej * 4. The name of Wasabi Systems, Inc. may not be used to endorse
59 1.1.2.2 thorpej * or promote products derived from this software without specific prior
60 1.1.2.2 thorpej * written permission.
61 1.1.2.2 thorpej *
62 1.1.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
63 1.1.2.2 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
64 1.1.2.2 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
65 1.1.2.2 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
66 1.1.2.2 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
67 1.1.2.2 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
68 1.1.2.2 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
69 1.1.2.2 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
70 1.1.2.2 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
71 1.1.2.2 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
72 1.1.2.2 thorpej * POSSIBILITY OF SUCH DAMAGE.
73 1.1.2.2 thorpej */
74 1.1.2.2 thorpej
75 1.1.2.2 thorpej #include <sys/param.h>
76 1.1.2.2 thorpej #include <sys/systm.h>
77 1.1.2.2 thorpej #include <sys/malloc.h>
78 1.1.2.2 thorpej #include <uvm/uvm_extern.h>
79 1.1.2.2 thorpej #include <machine/bus.h>
80 1.1.2.2 thorpej #include <machine/intr.h>
81 1.1.2.2 thorpej #include <arm/cpufunc.h>
82 1.1.2.2 thorpej
83 1.1.2.2 thorpej #include <arm/s3c2xx0/s3c2xx0reg.h>
84 1.1.2.2 thorpej #include <arm/s3c2xx0/s3c2xx0var.h>
85 1.1.2.2 thorpej #include <arm/s3c2xx0/s3c2xx0_intr.h>
86 1.1.2.2 thorpej
87 1.1.2.2 thorpej volatile uint32_t *s3c2xx0_intr_mask_reg;
88 1.1.2.2 thorpej
89 1.1.2.2 thorpej static __inline void
90 1.1.2.2 thorpej __raise(int ipl)
91 1.1.2.2 thorpej {
92 1.1.2.2 thorpej if (current_spl_level < ipl) {
93 1.1.2.2 thorpej s3c2xx0_setipl(ipl);
94 1.1.2.2 thorpej }
95 1.1.2.2 thorpej }
96 1.1.2.2 thorpej /*
97 1.1.2.2 thorpej * modify interrupt mask table for SPL levels
98 1.1.2.2 thorpej */
99 1.1.2.2 thorpej void
100 1.1.2.2 thorpej s3c2xx0_update_intr_masks(int irqno, int level)
101 1.1.2.2 thorpej {
102 1.1.2.2 thorpej int mask = 1 << irqno;
103 1.1.2.2 thorpej int i;
104 1.1.2.2 thorpej
105 1.1.2.2 thorpej
106 1.1.2.2 thorpej s3c2xx0_ilevel[irqno] = level;
107 1.1.2.2 thorpej
108 1.1.2.2 thorpej for (i = 0; i < level; ++i)
109 1.1.2.2 thorpej s3c2xx0_imask[i] |= mask; /* Enable interrupt at lower
110 1.1.2.2 thorpej * level */
111 1.1.2.2 thorpej for (; i < NIPL - 1; ++i)
112 1.1.2.2 thorpej s3c2xx0_imask[i] &= ~mask; /* Disable itnerrupt at upper
113 1.1.2.2 thorpej * level */
114 1.1.2.2 thorpej
115 1.1.2.2 thorpej /*
116 1.1.2.2 thorpej * Enforce a heirarchy that gives "slow" device (or devices with
117 1.1.2.2 thorpej * limited input buffer space/"real-time" requirements) a better
118 1.1.2.2 thorpej * chance at not dropping data.
119 1.1.2.2 thorpej */
120 1.1.2.2 thorpej s3c2xx0_imask[IPL_BIO] &= s3c2xx0_imask[IPL_SOFTNET];
121 1.1.2.2 thorpej s3c2xx0_imask[IPL_NET] &= s3c2xx0_imask[IPL_BIO];
122 1.1.2.2 thorpej s3c2xx0_imask[IPL_SOFTSERIAL] &= s3c2xx0_imask[IPL_NET];
123 1.1.2.2 thorpej s3c2xx0_imask[IPL_TTY] &= s3c2xx0_imask[IPL_SOFTSERIAL];
124 1.1.2.2 thorpej
125 1.1.2.2 thorpej /*
126 1.1.2.2 thorpej * splvm() blocks all interrupts that use the kernel memory
127 1.1.2.2 thorpej * allocation facilities.
128 1.1.2.2 thorpej */
129 1.1.2.2 thorpej s3c2xx0_imask[IPL_IMP] &= s3c2xx0_imask[IPL_TTY];
130 1.1.2.2 thorpej
131 1.1.2.2 thorpej /*
132 1.1.2.2 thorpej * Audio devices are not allowed to perform memory allocation
133 1.1.2.2 thorpej * in their interrupt routines, and they have fairly "real-time"
134 1.1.2.2 thorpej * requirements, so give them a high interrupt priority.
135 1.1.2.2 thorpej */
136 1.1.2.2 thorpej s3c2xx0_imask[IPL_AUDIO] &= s3c2xx0_imask[IPL_IMP];
137 1.1.2.2 thorpej
138 1.1.2.2 thorpej /*
139 1.1.2.2 thorpej * splclock() must block anything that uses the scheduler.
140 1.1.2.2 thorpej */
141 1.1.2.2 thorpej s3c2xx0_imask[IPL_CLOCK] &= s3c2xx0_imask[IPL_AUDIO];
142 1.1.2.2 thorpej
143 1.1.2.2 thorpej /*
144 1.1.2.2 thorpej * splhigh() must block "everything".
145 1.1.2.2 thorpej */
146 1.1.2.2 thorpej s3c2xx0_imask[IPL_HIGH] &= s3c2xx0_imask[IPL_STATCLOCK];
147 1.1.2.2 thorpej
148 1.1.2.2 thorpej /*
149 1.1.2.2 thorpej * XXX We need serial drivers to run at the absolute highest priority
150 1.1.2.2 thorpej * in order to avoid overruns, so serial > high.
151 1.1.2.2 thorpej */
152 1.1.2.2 thorpej s3c2xx0_imask[IPL_SERIAL] &= s3c2xx0_imask[IPL_HIGH];
153 1.1.2.2 thorpej
154 1.1.2.2 thorpej }
155 1.1.2.2 thorpej
156 1.1.2.2 thorpej
157 1.1.2.2 thorpej static void
158 1.1.2.2 thorpej init_interrupt_masks(void)
159 1.1.2.2 thorpej {
160 1.1.2.2 thorpej int i;
161 1.1.2.2 thorpej s3c2xx0_imask[IPL_NONE] = 0xffffffff;
162 1.1.2.2 thorpej
163 1.1.2.2 thorpej for (i = IPL_BIO; i < IPL_SOFTSERIAL; ++i)
164 1.1.2.2 thorpej s3c2xx0_imask[i] = SI_TO_IRQBIT(SI_SOFTSERIAL);
165 1.1.2.2 thorpej for (; i < NIPL; ++i)
166 1.1.2.2 thorpej s3c2xx0_imask[i] = 0;
167 1.1.2.2 thorpej
168 1.1.2.2 thorpej /*
169 1.1.2.2 thorpej * Initialize the soft interrupt masks to block themselves.
170 1.1.2.2 thorpej */
171 1.1.2.2 thorpej s3c2xx0_imask[IPL_SOFT] = ~SI_TO_IRQBIT(SI_SOFT);
172 1.1.2.2 thorpej s3c2xx0_imask[IPL_SOFTCLOCK] = ~SI_TO_IRQBIT(SI_SOFTCLOCK);
173 1.1.2.2 thorpej s3c2xx0_imask[IPL_SOFTNET] = ~SI_TO_IRQBIT(SI_SOFTNET);
174 1.1.2.2 thorpej
175 1.1.2.2 thorpej /*
176 1.1.2.2 thorpej * splsoftclock() is the only interface that users of the
177 1.1.2.2 thorpej * generic software interrupt facility have to block their
178 1.1.2.2 thorpej * soft intrs, so splsoftclock() must also block IPL_SOFT.
179 1.1.2.2 thorpej */
180 1.1.2.2 thorpej s3c2xx0_imask[IPL_SOFTCLOCK] &= s3c2xx0_imask[IPL_SOFT];
181 1.1.2.2 thorpej
182 1.1.2.2 thorpej /*
183 1.1.2.2 thorpej * splsoftnet() must also block splsoftclock(), since we don't
184 1.1.2.2 thorpej * want timer-driven network events to occur while we're
185 1.1.2.2 thorpej * processing incoming packets.
186 1.1.2.2 thorpej */
187 1.1.2.2 thorpej s3c2xx0_imask[IPL_SOFTNET] &= s3c2xx0_imask[IPL_SOFTCLOCK];
188 1.1.2.2 thorpej
189 1.1.2.2 thorpej }
190 1.1.2.2 thorpej
191 1.1.2.2 thorpej
192 1.1.2.2 thorpej /*
193 1.1.2.2 thorpej * Disable/enable interrupts.
194 1.1.2.2 thorpej * This is for S3C2XX0's intergrated UART, which can't disable tx/rx
195 1.1.2.2 thorpej * interrupts without disabling tx/rx by means of UART regsiters.
196 1.1.2.2 thorpej */
197 1.1.2.2 thorpej void
198 1.1.2.2 thorpej s3c2xx0_mask_interrupts(int mask)
199 1.1.2.2 thorpej {
200 1.1.2.2 thorpej int save = disable_interrupts(I32_bit);
201 1.1.2.2 thorpej int i;
202 1.1.2.2 thorpej
203 1.1.2.2 thorpej for (i = 0; i < NIPL - 1; ++i)
204 1.1.2.2 thorpej s3c2xx0_imask[i] &= ~mask;
205 1.1.2.2 thorpej
206 1.1.2.2 thorpej intr_mask = s3c2xx0_imask[current_spl_level];
207 1.1.2.2 thorpej *s3c2xx0_intr_mask_reg = intr_mask;
208 1.1.2.2 thorpej
209 1.1.2.2 thorpej restore_interrupts(save);
210 1.1.2.2 thorpej }
211 1.1.2.2 thorpej
212 1.1.2.2 thorpej void
213 1.1.2.2 thorpej s3c2xx0_unmask_interrupts(int mask)
214 1.1.2.2 thorpej {
215 1.1.2.2 thorpej int save = disable_interrupts(I32_bit);
216 1.1.2.2 thorpej int i;
217 1.1.2.2 thorpej
218 1.1.2.2 thorpej for (i = 0; i < ICU_LEN; ++i) {
219 1.1.2.2 thorpej if ((mask & (1 << i)) == 0)
220 1.1.2.2 thorpej continue;
221 1.1.2.2 thorpej s3c2xx0_update_intr_masks(i, s3c2xx0_ilevel[i]);
222 1.1.2.2 thorpej }
223 1.1.2.2 thorpej
224 1.1.2.2 thorpej intr_mask = s3c2xx0_imask[current_spl_level];
225 1.1.2.2 thorpej *s3c2xx0_intr_mask_reg = intr_mask;
226 1.1.2.2 thorpej
227 1.1.2.2 thorpej restore_interrupts(save);
228 1.1.2.2 thorpej }
229 1.1.2.2 thorpej
230 1.1.2.2 thorpej void
231 1.1.2.2 thorpej s3c2xx0_do_pending(void)
232 1.1.2.2 thorpej {
233 1.1.2.2 thorpej static __cpu_simple_lock_t processing = __SIMPLELOCK_UNLOCKED;
234 1.1.2.2 thorpej int oldirqstate, spl_save;
235 1.1.2.2 thorpej
236 1.1.2.2 thorpej if (__cpu_simple_lock_try(&processing) == 0)
237 1.1.2.2 thorpej return;
238 1.1.2.2 thorpej
239 1.1.2.2 thorpej spl_save = current_spl_level;
240 1.1.2.2 thorpej
241 1.1.2.2 thorpej oldirqstate = disable_interrupts(I32_bit);
242 1.1.2.2 thorpej
243 1.1.2.2 thorpej #define DO_SOFTINT(si,ipl) \
244 1.1.2.2 thorpej if ((softint_pending & intr_mask) & SI_TO_IRQBIT(si)) { \
245 1.1.2.2 thorpej softint_pending &= ~SI_TO_IRQBIT(si); \
246 1.1.2.2 thorpej __raise(ipl); \
247 1.1.2.2 thorpej restore_interrupts(oldirqstate); \
248 1.1.2.2 thorpej softintr_dispatch(si); \
249 1.1.2.2 thorpej oldirqstate = disable_interrupts(I32_bit); \
250 1.1.2.2 thorpej s3c2xx0_setipl(spl_save); \
251 1.1.2.2 thorpej }
252 1.1.2.2 thorpej
253 1.1.2.2 thorpej do {
254 1.1.2.2 thorpej DO_SOFTINT(SI_SOFTSERIAL, IPL_SOFTSERIAL);
255 1.1.2.2 thorpej DO_SOFTINT(SI_SOFTNET, IPL_SOFTNET);
256 1.1.2.2 thorpej DO_SOFTINT(SI_SOFTCLOCK, IPL_SOFTCLOCK);
257 1.1.2.2 thorpej DO_SOFTINT(SI_SOFT, IPL_SOFT);
258 1.1.2.2 thorpej } while (softint_pending & intr_mask);
259 1.1.2.2 thorpej
260 1.1.2.2 thorpej __cpu_simple_unlock(&processing);
261 1.1.2.2 thorpej
262 1.1.2.2 thorpej restore_interrupts(oldirqstate);
263 1.1.2.2 thorpej }
264 1.1.2.2 thorpej
265 1.1.2.2 thorpej
266 1.1.2.2 thorpej static int
267 1.1.2.2 thorpej stray_interrupt(void *cookie)
268 1.1.2.2 thorpej {
269 1.1.2.2 thorpej int save;
270 1.1.2.2 thorpej int irqno = (int) cookie;
271 1.1.2.2 thorpej printf("stray interrupt %d\n", irqno);
272 1.1.2.2 thorpej
273 1.1.2.2 thorpej save = disable_interrupts(I32_bit);
274 1.1.2.2 thorpej *s3c2xx0_intr_mask_reg &= ~(1U << irqno);
275 1.1.2.2 thorpej restore_interrupts(save);
276 1.1.2.2 thorpej
277 1.1.2.2 thorpej return 0;
278 1.1.2.2 thorpej }
279 1.1.2.2 thorpej /*
280 1.1.2.2 thorpej * Initialize interrupt dispatcher.
281 1.1.2.2 thorpej */
282 1.1.2.2 thorpej void
283 1.1.2.2 thorpej s3c2xx0_intr_init(struct s3c2xx0_intr_dispatch * dispatch_table, int icu_len)
284 1.1.2.2 thorpej {
285 1.1.2.2 thorpej int i;
286 1.1.2.2 thorpej
287 1.1.2.2 thorpej for (i = 0; i < icu_len; ++i) {
288 1.1.2.2 thorpej dispatch_table[i].func = stray_interrupt;
289 1.1.2.2 thorpej dispatch_table[i].cookie = (void *) (i);
290 1.1.2.2 thorpej dispatch_table[i].level = IPL_BIO;
291 1.1.2.2 thorpej }
292 1.1.2.2 thorpej
293 1.1.2.2 thorpej init_interrupt_masks();
294 1.1.2.2 thorpej
295 1.1.2.2 thorpej _splraise(IPL_SERIAL);
296 1.1.2.2 thorpej enable_interrupts(I32_bit);
297 1.1.2.2 thorpej }
298 1.1.2.2 thorpej #undef splx
299 1.1.2.2 thorpej void
300 1.1.2.2 thorpej splx(int ipl)
301 1.1.2.2 thorpej {
302 1.1.2.2 thorpej s3c2xx0_splx(ipl);
303 1.1.2.2 thorpej }
304 1.1.2.2 thorpej #undef _splraise
305 1.1.2.2 thorpej int
306 1.1.2.2 thorpej _splraise(int ipl)
307 1.1.2.2 thorpej {
308 1.1.2.2 thorpej return s3c2xx0_splraise(ipl);
309 1.1.2.2 thorpej }
310 1.1.2.2 thorpej #undef _spllower
311 1.1.2.2 thorpej int
312 1.1.2.2 thorpej _spllower(int ipl)
313 1.1.2.2 thorpej {
314 1.1.2.2 thorpej return s3c2xx0_spllower(ipl);
315 1.1.2.2 thorpej }
316 1.1.2.2 thorpej #undef _setsoftintr
317 1.1.2.2 thorpej void
318 1.1.2.2 thorpej _setsoftintr(int si)
319 1.1.2.2 thorpej {
320 1.1.2.2 thorpej return s3c2xx0_setsoftintr(si);
321 1.1.2.2 thorpej }
322