s3c2800_intr.c revision 1.9.52.1 1 /* $NetBSD: s3c2800_intr.c,v 1.9.52.1 2008/01/09 01:45:23 matt Exp $ */
2
3 /*
4 * Copyright (c) 2002 Fujitsu Component Limited
5 * Copyright (c) 2002 Genetec Corporation
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of The Fujitsu Component Limited nor the name of
17 * Genetec corporation may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY FUJITSU COMPONENT LIMITED AND GENETEC
21 * CORPORATION ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL FUJITSU COMPONENT LIMITED OR GENETEC
25 * CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
28 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35 /*
36 * IRQ handler for Samsung S3C2800 processor.
37 * It has integrated interrupt controller.
38 */
39
40 #include <sys/cdefs.h>
41 __KERNEL_RCSID(0, "$NetBSD: s3c2800_intr.c,v 1.9.52.1 2008/01/09 01:45:23 matt Exp $");
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/malloc.h>
46 #include <uvm/uvm_extern.h>
47 #include <machine/bus.h>
48 #include <machine/intr.h>
49 #include <arm/cpufunc.h>
50
51 #include <arm/s3c2xx0/s3c2800reg.h>
52 #include <arm/s3c2xx0/s3c2800var.h>
53
54 /*
55 * interrupt dispatch table.
56 */
57
58 struct s3c2xx0_intr_dispatch handler[ICU_LEN];
59
60 #ifdef __HAVE_FAST_SOFTINTS
61 volatile int softint_pending;
62 #endif
63
64 volatile int intr_mask; /* XXX: does this need to be volatile? */
65 volatile int global_intr_mask = 0; /* mask some interrupts at all spl level */
66
67 /* interrupt masks for each level */
68 int s3c2xx0_imask[NIPL];
69 int s3c2xx0_ilevel[ICU_LEN];
70
71 vaddr_t intctl_base; /* interrupt controller registers */
72 #define icreg(offset) \
73 (*(volatile uint32_t *)(intctl_base+(offset)))
74
75 #ifdef __HAVE_FAST_SOFTINTS
76 /*
77 * Map a software interrupt queue to an interrupt priority level.
78 */
79 static const int si_to_ipl[] = {
80 [SI_SOFTBIO] = IPL_SOFTBIO,
81 [SI_SOFTCLOCK] = IPL_SOFTCLOCK,
82 [SI_SOFTNET] = IPL_SOFTNET,
83 [SI_SOFTSERIAL] = IPL_SOFTSERIAL,
84 };
85 #endif
86
87 /*
88 * Clearing interrupt pending bits affects some built-in
89 * peripherals. For example, IIC starts transmitting next data when
90 * its interrupt pending bit is cleared.
91 * We need to leave those bits to peripheral handlers.
92 */
93 #define PENDING_CLEAR_MASK (~((1<<S3C2800_INT_IIC0)|(1<<S3C2800_INT_IIC1)))
94
95 /*
96 * called from irq_entry.
97 */
98 void s3c2800_irq_handler(struct clockframe *);
99 void
100 s3c2800_irq_handler(struct clockframe *frame)
101 {
102 uint32_t irqbits;
103 int irqno;
104 int saved_spl_level;
105
106 saved_spl_level = curcpl();
107
108 while ((irqbits = icreg(INTCTL_IRQPND) & ICU_INT_HWMASK) != 0) {
109
110 for (irqno = ICU_LEN-1; irqno >= 0; --irqno)
111 if (irqbits & (1<<irqno))
112 break;
113
114 if (irqno < 0)
115 break;
116
117 /* raise spl to stop interrupts of lower priorities */
118 if (saved_spl_level < handler[irqno].level)
119 s3c2xx0_setipl(handler[irqno].level);
120
121 /* clear pending bit */
122 icreg(INTCTL_SRCPND) = PENDING_CLEAR_MASK & (1 << irqno);
123
124 enable_interrupts(I32_bit); /* allow nested interrupts */
125
126 (*handler[irqno].func) (
127 handler[irqno].cookie == 0
128 ? frame : handler[irqno].cookie);
129
130 disable_interrupts(I32_bit);
131
132 /* restore spl to that was when this interrupt happen */
133 s3c2xx0_setipl(saved_spl_level);
134 }
135
136 #ifdef __HAVE_FAST_SOFTINTS
137 if (softint_pending & intr_mask)
138 s3c2xx0_do_pending(1);
139 #endif
140 }
141
142 static const u_char s3c2800_ist[] = {
143 EXTINTR_LOW, /* NONE */
144 EXTINTR_FALLING, /* PULSE */
145 EXTINTR_FALLING, /* EDGE */
146 EXTINTR_LOW, /* LEVEL */
147 EXTINTR_HIGH,
148 EXTINTR_RISING,
149 EXTINTR_BOTH,
150 };
151
152 void *
153 s3c2800_intr_establish(int irqno, int level, int type,
154 int (* func) (void *), void *cookie)
155 {
156 int save;
157
158 if (irqno < 0 || irqno >= ICU_LEN ||
159 type < IST_NONE || IST_EDGE_BOTH < type)
160 panic("intr_establish: bogus irq or type");
161
162 save = disable_interrupts(I32_bit);
163
164 handler[irqno].cookie = cookie;
165 handler[irqno].func = func;
166 handler[irqno].level = level;
167
168 s3c2xx0_update_intr_masks(irqno, level);
169
170 if (irqno <= S3C2800_INT_EXT(7)) {
171 /*
172 * Update external interrupt control
173 */
174 uint32_t reg;
175 u_int trig;
176
177 trig = s3c2800_ist[type];
178
179 reg = bus_space_read_4(s3c2xx0_softc->sc_iot,
180 s3c2xx0_softc->sc_gpio_ioh,
181 GPIO_EXTINTR);
182
183 reg = reg & ~(0x0f << (4*irqno));
184 reg |= trig << (4*irqno);
185
186 bus_space_write_4(s3c2xx0_softc->sc_iot, s3c2xx0_softc->sc_gpio_ioh,
187 GPIO_EXTINTR, reg);
188 }
189
190 s3c2xx0_setipl(curcpl());
191
192 restore_interrupts(save);
193
194 return (&handler[irqno]);
195 }
196
197
198 static void
199 init_interrupt_masks(void)
200 {
201 int i = 0;
202
203 #ifdef __HAVE_FAST_SOFTINTS
204 s3c2xx0_imask[IPL_NONE] = SI_TO_IRQBIT(SI_SOFTSERIAL) |
205 SI_TO_IRQBIT(SI_SOFTNET) | SI_TO_IRQBIT(SI_SOFTCLOCK) |
206 SI_TO_IRQBIT(SI_SOFTBIO);
207
208 s3c2xx0_imask[IPL_SOFTBIO] = SI_TO_IRQBIT(SI_SOFTSERIAL) |
209 SI_TO_IRQBIT(SI_SOFTNET) | SI_TO_IRQBIT(SI_SOFTCLOCK);
210
211 /*
212 * splsoftclock() is the only interface that users of the
213 * generic software interrupt facility have to block their
214 * soft intrs, so splsoftclock() must also block IPL_SOFT.
215 */
216 s3c2xx0_imask[IPL_SOFTCLOCK] = SI_TO_IRQBIT(SI_SOFTSERIAL) |
217 SI_TO_IRQBIT(SI_SOFTNET);
218
219 /*
220 * splsoftnet() must also block splsoftclock(), since we don't
221 * want timer-driven network events to occur while we're
222 * processing incoming packets.
223 */
224 s3c2xx0_imask[IPL_SOFTNET] = SI_TO_IRQBIT(SI_SOFTSERIAL);
225
226 for (i = IPL_BIO; i < IPL_SOFTSERIAL; ++i)
227 s3c2xx0_imask[i] = SI_TO_IRQBIT(SI_SOFTSERIAL);
228 #endif
229 for (; i < NIPL; ++i)
230 s3c2xx0_imask[i] = 0;
231 }
232
233 void
234 s3c2800_intr_init(struct s3c2800_softc *sc)
235 {
236 intctl_base = (vaddr_t) bus_space_vaddr(sc->sc_sx.sc_iot,
237 sc->sc_sx.sc_intctl_ioh);
238
239 s3c2xx0_intr_mask_reg = (uint32_t *)(intctl_base + INTCTL_INTMSK);
240
241 /* clear all pending interrupt */
242 icreg(INTCTL_SRCPND) = 0xffffffff;
243
244 init_interrupt_masks();
245
246 s3c2xx0_intr_init(handler, ICU_LEN);
247
248 }
249