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