tx39icu.c revision 1.26 1 1.26 uebayasi /* $NetBSD: tx39icu.c,v 1.26 2010/11/15 06:26:58 uebayasi Exp $ */
2 1.1 uch
3 1.9 uch /*-
4 1.14 uch * Copyright (c) 1999-2001 The NetBSD Foundation, Inc.
5 1.1 uch * All rights reserved.
6 1.1 uch *
7 1.9 uch * This code is derived from software contributed to The NetBSD Foundation
8 1.9 uch * by UCHIYAMA Yasushi.
9 1.9 uch *
10 1.1 uch * Redistribution and use in source and binary forms, with or without
11 1.1 uch * modification, are permitted provided that the following conditions
12 1.1 uch * are met:
13 1.1 uch * 1. Redistributions of source code must retain the above copyright
14 1.1 uch * notice, this list of conditions and the following disclaimer.
15 1.9 uch * 2. Redistributions in binary form must reproduce the above copyright
16 1.9 uch * notice, this list of conditions and the following disclaimer in the
17 1.9 uch * documentation and/or other materials provided with the distribution.
18 1.1 uch *
19 1.9 uch * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.9 uch * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.9 uch * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.9 uch * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.9 uch * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.9 uch * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.9 uch * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.9 uch * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.9 uch * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.9 uch * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.9 uch * POSSIBILITY OF SUCH DAMAGE.
30 1.1 uch */
31 1.21 lukem
32 1.21 lukem #include <sys/cdefs.h>
33 1.26 uebayasi __KERNEL_RCSID(0, "$NetBSD: tx39icu.c,v 1.26 2010/11/15 06:26:58 uebayasi Exp $");
34 1.9 uch
35 1.14 uch #include "opt_vr41xx.h"
36 1.14 uch #include "opt_tx39xx.h"
37 1.14 uch
38 1.1 uch #include "opt_use_poll.h"
39 1.16 uch #include "opt_tx39icu_debug.h"
40 1.1 uch #include "opt_tx39_watchdogtimer.h"
41 1.1 uch
42 1.1 uch #include <sys/param.h>
43 1.1 uch #include <sys/systm.h>
44 1.1 uch #include <sys/device.h>
45 1.1 uch #include <sys/malloc.h>
46 1.1 uch #include <sys/queue.h>
47 1.26 uebayasi #include <sys/cpu.h>
48 1.1 uch
49 1.14 uch #include <uvm/uvm_extern.h>
50 1.14 uch
51 1.1 uch #include <mips/cpuregs.h>
52 1.1 uch #include <machine/bus.h>
53 1.1 uch
54 1.1 uch #include <hpcmips/tx/tx39var.h>
55 1.1 uch #include <hpcmips/tx/tx39icureg.h>
56 1.5 uch #include <hpcmips/tx/tx39clockvar.h>
57 1.1 uch
58 1.1 uch #include <machine/cpu.h>
59 1.1 uch #include <dev/dec/clockvar.h>
60 1.1 uch
61 1.16 uch #undef TX39ICU_DEBUG_PRINT_PENDING_INTERRUPT /* For explorer. good luck! */
62 1.1 uch
63 1.14 uch #if defined(VR41XX) && defined(TX39XX)
64 1.14 uch #define TX_INTR tx_intr
65 1.14 uch #else
66 1.14 uch #define TX_INTR cpu_intr /* locore_mips3 directly call this */
67 1.14 uch #endif
68 1.15 uch void TX_INTR(u_int32_t, u_int32_t, u_int32_t, u_int32_t);
69 1.14 uch
70 1.16 uch #ifdef TX39ICU_DEBUG
71 1.16 uch #define DPRINTF_ENABLE
72 1.16 uch #define DPRINTF_DEBUG tx39icu_debug
73 1.1 uch #endif
74 1.16 uch #include <machine/debug.h>
75 1.16 uch
76 1.6 uch u_int32_t tx39intrvec;
77 1.1 uch
78 1.14 uch /*
79 1.14 uch * This is a mask of bits to clear in the SR when we go to a
80 1.14 uch * given interrupt priority level.
81 1.14 uch */
82 1.14 uch const u_int32_t __ipl_sr_bits_tx[_IPL_N] = {
83 1.14 uch 0, /* IPL_NONE */
84 1.14 uch
85 1.14 uch MIPS_SOFT_INT_MASK_0, /* IPL_SOFTCLOCK */
86 1.14 uch
87 1.14 uch MIPS_SOFT_INT_MASK_0|
88 1.14 uch MIPS_SOFT_INT_MASK_1, /* IPL_SOFTNET */
89 1.14 uch
90 1.14 uch MIPS_SOFT_INT_MASK_0|
91 1.14 uch MIPS_SOFT_INT_MASK_1|
92 1.14 uch MIPS_INT_MASK_2|
93 1.23 ad MIPS_INT_MASK_4, /* IPL_VM */
94 1.14 uch
95 1.14 uch MIPS_SOFT_INT_MASK_0|
96 1.14 uch MIPS_SOFT_INT_MASK_1|
97 1.14 uch MIPS_INT_MASK_2|
98 1.23 ad MIPS_INT_MASK_4, /* IPL_SCHED */
99 1.14 uch };
100 1.14 uch
101 1.1 uch /* IRQHIGH lines list */
102 1.4 uch static const struct irqhigh_list {
103 1.1 uch int qh_pri; /* IRQHIGH priority */
104 1.1 uch int qh_set; /* Register set */
105 1.1 uch int qh_bit; /* bit offset in the register set */
106 1.1 uch } irqhigh_list[] = {
107 1.1 uch {15, 5, 25}, /* POSPWROKINT */
108 1.1 uch {15, 5, 24}, /* NEGPWROKINT */
109 1.1 uch {14, 5, 30}, /* ALARMINT*/
110 1.1 uch {13, 5, 29}, /* PERINT */
111 1.1 uch #ifdef TX391X
112 1.1 uch {12, 2, 3}, /* MBUSPOSINT */
113 1.1 uch {12, 2, 2}, /* MBUSNEGINT */
114 1.1 uch {11, 2, 31}, /* UARTARXINT */
115 1.1 uch {10, 2, 21}, /* UARTBRXINT */
116 1.1 uch {9, 3, 19}, /* MFIOPOSINT19 */
117 1.1 uch {9, 3, 18}, /* MFIOPOSINT18 */
118 1.1 uch {9, 3, 17}, /* MFIOPOSINT17 */
119 1.1 uch {9, 3, 16}, /* MFIOPOSINT16 */
120 1.1 uch {8, 3, 1}, /* MFIOPOSINT1 */
121 1.1 uch {8, 3, 0}, /* MFIOPOSINT0 */
122 1.1 uch {8, 5, 13}, /* IOPOSINT6 */
123 1.1 uch {8, 5, 12}, /* IOPOSINT5 */
124 1.1 uch {7, 4, 19}, /* MFIONEGINT19 */
125 1.1 uch {7, 4, 18}, /* MFIONEGINT18 */
126 1.1 uch {7, 4, 17}, /* MFIONEGINT17 */
127 1.1 uch {7, 4, 16}, /* MFIONEGINT16 */
128 1.1 uch {6, 4, 1}, /* MFIONEGINT1 */
129 1.1 uch {6, 4, 0}, /* MFIONEGINT0 */
130 1.1 uch {6, 5, 6}, /* IONEGINT6 */
131 1.1 uch {6, 5, 5}, /* IONEGINT5 */
132 1.1 uch {5, 2, 5}, /* MBUSDMAFULLINT */
133 1.1 uch #endif /* TX391X */
134 1.1 uch #ifdef TX392X
135 1.1 uch {12, 2, 31}, /* UARTARXINT */
136 1.1 uch {12, 2, 21}, /* UARTBRXINT */
137 1.1 uch {11, 3, 19}, /* MFIOPOSINT19 */
138 1.1 uch {11, 3, 18}, /* MFIOPOSINT18 */
139 1.1 uch {11, 3, 17}, /* MFIOPOSINT17 */
140 1.1 uch {11, 3, 16}, /* MFIOPOSINT16 */
141 1.1 uch {10, 3, 1}, /* MFIOPOSINT1 */
142 1.1 uch {10, 3, 0}, /* MFIOPOSINT0 */
143 1.1 uch {10, 5, 13}, /* IOPOSINT6 */
144 1.1 uch {10, 5, 12}, /* IOPOSINT5 */
145 1.1 uch {9, 4, 19}, /* MFIONEGINT19 */
146 1.1 uch {9, 4, 18}, /* MFIONEGINT18 */
147 1.1 uch {9, 4, 17}, /* MFIONEGINT17 */
148 1.1 uch {9, 4, 16}, /* MFIONEGINT16 */
149 1.1 uch {8, 4, 1}, /* MFIONEGINT1 */
150 1.1 uch {8, 4, 0}, /* MFIONEGINT0 */
151 1.1 uch {8, 5, 6}, /* IONEGINT6 */
152 1.1 uch {8, 5, 5}, /* IONEGINT5 */
153 1.1 uch {5, 7, 19}, /* IRRXCINT */
154 1.1 uch {5, 7, 17}, /* IRRXEINT */
155 1.1 uch #endif /* TX392X */
156 1.1 uch {4, 1, 18}, /* SNDDMACNTINT */
157 1.1 uch {3, 1, 17}, /* TELDMACNTINT */
158 1.1 uch {2, 1, 27}, /* CHIDMACNTINT */
159 1.1 uch {1, 5, 7}, /* IOPOSINT0 */
160 1.1 uch {1, 5, 0} /* IONEGINT0 */
161 1.1 uch };
162 1.1 uch
163 1.1 uch struct txintr_high_entry {
164 1.1 uch int he_set;
165 1.1 uch txreg_t he_mask;
166 1.12 uch int (*he_fun)(void *);
167 1.1 uch void *he_arg;
168 1.1 uch TAILQ_ENTRY(txintr_high_entry) he_link;
169 1.1 uch };
170 1.1 uch
171 1.1 uch #ifdef USE_POLL
172 1.1 uch struct txpoll_entry{
173 1.1 uch int p_cnt; /* dispatch interval */
174 1.1 uch int p_desc;
175 1.12 uch int (*p_fun)(void *);
176 1.1 uch void *p_arg;
177 1.1 uch TAILQ_ENTRY(txpoll_entry) p_link;
178 1.1 uch };
179 1.12 uch int tx39_poll_intr(void *);
180 1.1 uch #endif /* USE_POLL */
181 1.1 uch
182 1.1 uch struct tx39icu_softc {
183 1.1 uch struct device sc_dev;
184 1.1 uch tx_chipset_tag_t sc_tc;
185 1.1 uch /* IRQLOW */
186 1.1 uch txreg_t sc_le_mask[TX39_INTRSET_MAX + 1];
187 1.12 uch int (*sc_le_fun[TX39_INTRSET_MAX + 1][32])(void *);
188 1.1 uch void *sc_le_arg[TX39_INTRSET_MAX + 1][32];
189 1.1 uch /* IRQHIGH */
190 1.1 uch TAILQ_HEAD(, txintr_high_entry) sc_he_head[TX39_IRQHIGH_MAX];
191 1.1 uch /* Register */
192 1.1 uch txreg_t sc_regs[TX39_INTRSET_MAX + 1];
193 1.1 uch #ifdef USE_POLL
194 1.1 uch unsigned sc_pollcnt;
195 1.1 uch int sc_polling;
196 1.1 uch void *sc_poll_ih;
197 1.1 uch TAILQ_HEAD(, txpoll_entry) sc_p_head;
198 1.1 uch #endif /* USE_POLL */
199 1.1 uch };
200 1.1 uch
201 1.12 uch int tx39icu_match(struct device *, struct cfdata *, void *);
202 1.12 uch void tx39icu_attach(struct device *, struct device *, void *);
203 1.12 uch int tx39icu_intr(u_int32_t, u_int32_t, u_int32_t, u_int32_t);
204 1.12 uch
205 1.12 uch void tx39_intr_dump(struct tx39icu_softc *);
206 1.12 uch void tx39_intr_decode(int, int *, int *);
207 1.12 uch void tx39_irqhigh_disestablish(tx_chipset_tag_t, int, int, int);
208 1.12 uch void tx39_irqhigh_establish(tx_chipset_tag_t, int, int, int,
209 1.12 uch int (*)(void *), void *);
210 1.12 uch void tx39_irqhigh_intr(u_int32_t, u_int32_t, u_int32_t, u_int32_t);
211 1.12 uch int tx39_irqhigh(int, int);
212 1.1 uch
213 1.20 thorpej CFATTACH_DECL(tx39icu, sizeof(struct tx39icu_softc),
214 1.20 thorpej tx39icu_match, tx39icu_attach, NULL, NULL);
215 1.1 uch
216 1.1 uch int
217 1.12 uch tx39icu_match(struct device *parent, struct cfdata *cf, void *aux)
218 1.1 uch {
219 1.14 uch
220 1.14 uch return (ATTACH_FIRST);
221 1.1 uch }
222 1.1 uch
223 1.1 uch void
224 1.12 uch tx39icu_attach(struct device *parent, struct device *self, void *aux)
225 1.1 uch {
226 1.1 uch struct txsim_attach_args *ta = aux;
227 1.12 uch struct tx39icu_softc *sc = (void *)self;
228 1.1 uch tx_chipset_tag_t tc = ta->ta_tc;
229 1.9 uch txreg_t reg, *regs;
230 1.1 uch int i;
231 1.14 uch
232 1.1 uch printf("\n");
233 1.1 uch sc->sc_tc = ta->ta_tc;
234 1.1 uch
235 1.9 uch regs = sc->sc_regs;
236 1.9 uch regs[0] = tx_conf_read(tc, TX39_INTRSTATUS6_REG);
237 1.9 uch regs[1] = tx_conf_read(tc, TX39_INTRSTATUS1_REG);
238 1.9 uch regs[2] = tx_conf_read(tc, TX39_INTRSTATUS2_REG);
239 1.9 uch regs[3] = tx_conf_read(tc, TX39_INTRSTATUS3_REG);
240 1.9 uch regs[4] = tx_conf_read(tc, TX39_INTRSTATUS4_REG);
241 1.9 uch regs[5] = tx_conf_read(tc, TX39_INTRSTATUS5_REG);
242 1.1 uch #ifdef TX392X
243 1.9 uch regs[7] = tx_conf_read(tc, TX39_INTRSTATUS7_REG);
244 1.9 uch regs[8] = tx_conf_read(tc, TX39_INTRSTATUS8_REG);
245 1.1 uch #endif
246 1.16 uch #ifdef TX39ICU_DEBUG
247 1.2 uch printf("\t[Windows CE setting]\n");
248 1.1 uch tx39_intr_dump(sc);
249 1.16 uch #endif /* TX39ICU_DEBUG */
250 1.2 uch
251 1.1 uch #ifdef WINCE_DEFAULT_SETTING
252 1.1 uch #warning WINCE_DEFAULT_SETTING
253 1.1 uch #else /* WINCE_DEFAULT_SETTING */
254 1.1 uch /* Disable IRQLOW */
255 1.1 uch tx_conf_write(tc, TX39_INTRENABLE1_REG, 0);
256 1.1 uch tx_conf_write(tc, TX39_INTRENABLE2_REG, 0);
257 1.1 uch tx_conf_write(tc, TX39_INTRENABLE3_REG, 0);
258 1.1 uch tx_conf_write(tc, TX39_INTRENABLE4_REG, 0);
259 1.1 uch tx_conf_write(tc, TX39_INTRENABLE5_REG, 0);
260 1.1 uch #ifdef TX392X
261 1.1 uch tx_conf_write(tc, TX39_INTRENABLE7_REG, 0);
262 1.1 uch tx_conf_write(tc, TX39_INTRENABLE8_REG, 0);
263 1.1 uch #endif /* TX392X */
264 1.1 uch
265 1.1 uch /* Disable IRQHIGH */
266 1.1 uch reg = tx_conf_read(tc, TX39_INTRENABLE6_REG);
267 1.1 uch reg &= ~TX39_INTRENABLE6_PRIORITYMASK_MASK;
268 1.1 uch tx_conf_write(tc, TX39_INTRENABLE6_REG, reg);
269 1.1 uch #endif /* WINCE_DEFAULT_SETTING */
270 1.1 uch
271 1.1 uch /* Clear all pending interrupts */
272 1.4 uch tx_conf_write(tc, TX39_INTRCLEAR1_REG,
273 1.12 uch tx_conf_read(tc, TX39_INTRSTATUS1_REG));
274 1.4 uch tx_conf_write(tc, TX39_INTRCLEAR2_REG,
275 1.12 uch tx_conf_read(tc, TX39_INTRSTATUS2_REG));
276 1.4 uch tx_conf_write(tc, TX39_INTRCLEAR3_REG,
277 1.12 uch tx_conf_read(tc, TX39_INTRSTATUS3_REG));
278 1.4 uch tx_conf_write(tc, TX39_INTRCLEAR4_REG,
279 1.12 uch tx_conf_read(tc, TX39_INTRSTATUS4_REG));
280 1.4 uch tx_conf_write(tc, TX39_INTRCLEAR5_REG,
281 1.12 uch tx_conf_read(tc, TX39_INTRSTATUS5_REG));
282 1.1 uch #ifdef TX392X
283 1.4 uch tx_conf_write(tc, TX39_INTRCLEAR7_REG,
284 1.12 uch tx_conf_read(tc, TX39_INTRSTATUS7_REG));
285 1.4 uch tx_conf_write(tc, TX39_INTRCLEAR8_REG,
286 1.12 uch tx_conf_read(tc, TX39_INTRSTATUS8_REG));
287 1.1 uch #endif /* TX392X */
288 1.1 uch
289 1.1 uch /* Enable global interrupts */
290 1.1 uch reg = tx_conf_read(tc, TX39_INTRENABLE6_REG);
291 1.1 uch reg |= TX39_INTRENABLE6_GLOBALEN;
292 1.1 uch tx_conf_write(tc, TX39_INTRENABLE6_REG, reg);
293 1.1 uch
294 1.1 uch /* Initialize IRQHIGH interrupt handler holder*/
295 1.1 uch for (i = 0; i < TX39_IRQHIGH_MAX; i++) {
296 1.1 uch TAILQ_INIT(&sc->sc_he_head[i]);
297 1.1 uch }
298 1.1 uch #ifdef USE_POLL
299 1.1 uch /* Initialize polling handler holder */
300 1.1 uch TAILQ_INIT(&sc->sc_p_head);
301 1.1 uch #endif /* USE_POLL */
302 1.1 uch
303 1.1 uch /* Register interrupt module myself */
304 1.1 uch tx_conf_register_intr(tc, self);
305 1.1 uch }
306 1.1 uch
307 1.14 uch void
308 1.14 uch TX_INTR(u_int32_t status, u_int32_t cause, u_int32_t pc, u_int32_t ipending)
309 1.1 uch {
310 1.1 uch struct tx39icu_softc *sc;
311 1.1 uch tx_chipset_tag_t tc;
312 1.24 tsutsui struct cpu_info *ci;
313 1.9 uch txreg_t reg, pend, *regs;
314 1.1 uch int i, j;
315 1.1 uch
316 1.24 tsutsui ci = curcpu();
317 1.24 tsutsui ci->ci_idepth++;
318 1.14 uch uvmexp.intrs++;
319 1.14 uch
320 1.23 ad #ifdef __HAVE_FAST_SOFTINTS
321 1.14 uch if ((ipending & MIPS_HARD_INT_MASK) == 0)
322 1.14 uch goto softintr;
323 1.23 ad #endif
324 1.14 uch
325 1.1 uch tc = tx_conf_get_tag();
326 1.1 uch sc = tc->tc_intrt;
327 1.1 uch /*
328 1.1 uch * Read regsiter ASAP
329 1.1 uch */
330 1.9 uch regs = sc->sc_regs;
331 1.9 uch regs[0] = tx_conf_read(tc, TX39_INTRSTATUS6_REG);
332 1.9 uch regs[1] = tx_conf_read(tc, TX39_INTRSTATUS1_REG);
333 1.9 uch regs[2] = tx_conf_read(tc, TX39_INTRSTATUS2_REG);
334 1.9 uch regs[3] = tx_conf_read(tc, TX39_INTRSTATUS3_REG);
335 1.9 uch regs[4] = tx_conf_read(tc, TX39_INTRSTATUS4_REG);
336 1.9 uch regs[5] = tx_conf_read(tc, TX39_INTRSTATUS5_REG);
337 1.1 uch #ifdef TX392X
338 1.9 uch regs[7] = tx_conf_read(tc, TX39_INTRSTATUS7_REG);
339 1.9 uch regs[8] = tx_conf_read(tc, TX39_INTRSTATUS8_REG);
340 1.1 uch #endif
341 1.1 uch
342 1.16 uch #ifdef TX39ICU_DEBUG
343 1.7 uch if (!(ipending & MIPS_INT_MASK_4) && !(ipending & MIPS_INT_MASK_2)) {
344 1.16 uch dbg_bit_print(ipending);
345 1.1 uch panic("bogus HwInt");
346 1.1 uch }
347 1.16 uch if (tx39icu_debug > 1) {
348 1.1 uch tx39_intr_dump(sc);
349 1.1 uch }
350 1.16 uch #endif /* TX39ICU_DEBUG */
351 1.1 uch
352 1.1 uch /* IRQHIGH */
353 1.7 uch if (ipending & MIPS_INT_MASK_4) {
354 1.7 uch tx39_irqhigh_intr(ipending, pc, status, cause);
355 1.3 uch
356 1.23 ad #ifdef __HAVE_FAST_SOFTINTS
357 1.14 uch goto softintr;
358 1.23 ad #endif
359 1.1 uch }
360 1.1 uch
361 1.1 uch /* IRQLOW */
362 1.7 uch if (ipending & MIPS_INT_MASK_2) {
363 1.1 uch for (i = 1; i <= TX39_INTRSET_MAX; i++) {
364 1.1 uch int ofs;
365 1.1 uch #ifdef TX392X
366 1.1 uch if (i == 6)
367 1.1 uch continue;
368 1.1 uch #endif /* TX392X */
369 1.1 uch ofs = TX39_INTRSTATUS_REG(i);
370 1.1 uch pend = sc->sc_regs[i];
371 1.1 uch reg = sc->sc_le_mask[i] & pend;
372 1.1 uch /* Clear interrupts */
373 1.1 uch tx_conf_write(tc, ofs, reg);
374 1.1 uch /* Dispatch handler */
375 1.1 uch for (j = 0 ; j < 32; j++) {
376 1.1 uch if ((reg & (1 << j)) &&
377 1.1 uch sc->sc_le_fun[i][j]) {
378 1.16 uch #ifdef TX39ICU_DEBUG
379 1.16 uch if (tx39icu_debug > 1) {
380 1.16 uch tx39intrvec = (i << 16) | j;
381 1.16 uch DPRINTF("IRQLOW %d:%d\n", i, j);
382 1.1 uch }
383 1.16 uch #endif /* TX39ICU_DEBUG */
384 1.1 uch (*sc->sc_le_fun[i][j])
385 1.12 uch (sc->sc_le_arg[i][j]);
386 1.1 uch
387 1.1 uch }
388 1.1 uch }
389 1.16 uch #ifdef TX39ICU_DEBUG_PRINT_PENDING_INTERRUPT
390 1.1 uch pend &= ~reg;
391 1.1 uch if (pend) {
392 1.1 uch printf("%d pending:", i);
393 1.17 takemura dbg_bit_print(pend);
394 1.1 uch }
395 1.1 uch #endif
396 1.1 uch
397 1.1 uch }
398 1.1 uch }
399 1.1 uch #ifdef TX39_WATCHDOGTIMER
400 1.6 uch {
401 1.12 uch extern int tx39biu_intr(void *);
402 1.6 uch /* Bus error (If watch dog timer is enabled)*/
403 1.7 uch if (ipending & MIPS_INT_MASK_1) {
404 1.6 uch tx39biu_intr(0); /* Clear bus error */
405 1.6 uch }
406 1.1 uch }
407 1.1 uch #endif
408 1.6 uch #if 0
409 1.6 uch /* reset priority mask */
410 1.6 uch reg = tx_conf_read(tc, TX39_INTRENABLE6_REG);
411 1.6 uch reg = TX39_INTRENABLE6_PRIORITYMASK_SET(reg, 0xffff);
412 1.6 uch tx_conf_write(tc, TX39_INTRENABLE6_REG, reg);
413 1.6 uch #endif
414 1.14 uch
415 1.23 ad #ifdef __HAVE_FAST_SOFTINTS
416 1.14 uch softintr:
417 1.24 tsutsui #endif
418 1.24 tsutsui ci->ci_idepth--;
419 1.24 tsutsui #ifdef __HAVE_FAST_SOFTINTS
420 1.14 uch _splset((status & ~cause & MIPS_HARD_INT_MASK) | MIPS_SR_INT_IE);
421 1.14 uch softintr(ipending);
422 1.23 ad #endif
423 1.1 uch }
424 1.1 uch
425 1.1 uch int
426 1.12 uch tx39_irqhigh(int set, int bit)
427 1.1 uch {
428 1.1 uch int i, n;
429 1.1 uch
430 1.1 uch n = sizeof irqhigh_list / sizeof (struct irqhigh_list);
431 1.1 uch for (i = 0; i < n; i++) {
432 1.1 uch if (irqhigh_list[i].qh_set == set &&
433 1.1 uch irqhigh_list[i].qh_bit == bit)
434 1.12 uch return (irqhigh_list[i].qh_pri);
435 1.1 uch }
436 1.1 uch
437 1.12 uch return (0);
438 1.1 uch }
439 1.1 uch
440 1.1 uch void
441 1.12 uch tx39_irqhigh_intr(u_int32_t ipending, u_int32_t pc, u_int32_t status,
442 1.12 uch u_int32_t cause)
443 1.1 uch {
444 1.1 uch struct txintr_high_entry *he;
445 1.1 uch struct tx39icu_softc *sc;
446 1.1 uch struct clockframe cf;
447 1.1 uch tx_chipset_tag_t tc;
448 1.1 uch int i, pri, ofs, set;
449 1.1 uch txreg_t he_mask;
450 1.1 uch
451 1.1 uch tc = tx_conf_get_tag();
452 1.1 uch sc = tc->tc_intrt;
453 1.1 uch pri = TX39_INTRSTATUS6_INTVECT(sc->sc_regs[0]);
454 1.1 uch
455 1.1 uch if (pri == TX39_INTRPRI13_TIMER_PERIODIC) {
456 1.3 uch tx_conf_write(tc, TX39_INTRCLEAR5_REG,
457 1.12 uch TX39_INTRSTATUS5_PERINT);
458 1.1 uch cf.pc = pc;
459 1.1 uch cf.sr = status;
460 1.1 uch hardclock(&cf);
461 1.3 uch
462 1.3 uch return;
463 1.1 uch }
464 1.3 uch
465 1.1 uch /* Handle all pending IRQHIGH interrupts */
466 1.1 uch for (i = pri; i > 0; i--) {
467 1.1 uch TAILQ_FOREACH(he, &sc->sc_he_head[i], he_link) {
468 1.1 uch set = he->he_set;
469 1.1 uch he_mask = he->he_mask;
470 1.1 uch if (he_mask & (sc->sc_regs[set])) {
471 1.1 uch ofs = TX39_INTRSTATUS_REG(set);
472 1.1 uch /* Clear interrupt */
473 1.1 uch tx_conf_write(tc, ofs, he_mask);
474 1.16 uch #ifdef TX39ICU_DEBUG
475 1.16 uch if (tx39icu_debug > 1) {
476 1.16 uch tx39intrvec = (set << 16) |
477 1.16 uch (ffs(he_mask) - 1);
478 1.16 uch DPRINTF("IRQHIGH: %d:%d\n",
479 1.16 uch set, ffs(he_mask) - 1);
480 1.1 uch }
481 1.16 uch #endif /* TX39ICU_DEBUG */
482 1.1 uch /* Dispatch handler */
483 1.1 uch (*he->he_fun)(he->he_arg);
484 1.1 uch }
485 1.1 uch }
486 1.1 uch }
487 1.1 uch }
488 1.1 uch
489 1.1 uch void
490 1.12 uch tx39_intr_decode(int intr, int *set, int *bit)
491 1.1 uch {
492 1.1 uch if (!intr || intr >= (TX39_INTRSET_MAX + 1) * 32
493 1.1 uch #ifdef TX392X
494 1.1 uch || intr == 6
495 1.1 uch #endif /* TX392X */
496 1.12 uch ) {
497 1.1 uch panic("tx39icu_decode: bogus intrrupt line. %d", intr);
498 1.1 uch }
499 1.1 uch *set = intr / 32;
500 1.1 uch *bit = intr % 32;
501 1.1 uch }
502 1.1 uch
503 1.1 uch void
504 1.12 uch tx39_irqhigh_establish(tx_chipset_tag_t tc, int set, int bit, int pri,
505 1.12 uch int (*ih_fun)(void *), void *ih_arg)
506 1.1 uch {
507 1.1 uch struct tx39icu_softc *sc;
508 1.1 uch struct txintr_high_entry *he;
509 1.1 uch txreg_t reg;
510 1.1 uch
511 1.1 uch sc = tc->tc_intrt;
512 1.1 uch /*
513 1.6 uch * Add new entry to `pri' priority
514 1.1 uch */
515 1.1 uch if (!(he = malloc(sizeof(struct txintr_high_entry),
516 1.12 uch M_DEVBUF, M_NOWAIT))) {
517 1.1 uch panic ("tx39_irqhigh_establish: no memory.");
518 1.1 uch }
519 1.1 uch memset(he, 0, sizeof(struct txintr_high_entry));
520 1.1 uch he->he_set = set;
521 1.1 uch he->he_mask= (1 << bit);
522 1.1 uch he->he_fun = ih_fun;
523 1.1 uch he->he_arg = ih_arg;
524 1.1 uch TAILQ_INSERT_TAIL(&sc->sc_he_head[pri], he, he_link);
525 1.1 uch /*
526 1.1 uch * Enable interrupt on this priority.
527 1.1 uch */
528 1.1 uch reg = tx_conf_read(tc, TX39_INTRENABLE6_REG);
529 1.1 uch reg = TX39_INTRENABLE6_PRIORITYMASK_SET(reg, (1 << pri));
530 1.1 uch tx_conf_write(tc, TX39_INTRENABLE6_REG, reg);
531 1.1 uch }
532 1.1 uch
533 1.1 uch void
534 1.12 uch tx39_irqhigh_disestablish(tx_chipset_tag_t tc, int set, int bit, int pri)
535 1.1 uch {
536 1.1 uch struct tx39icu_softc *sc;
537 1.1 uch struct txintr_high_entry *he;
538 1.1 uch txreg_t reg;
539 1.1 uch
540 1.1 uch sc = tc->tc_intrt;
541 1.1 uch TAILQ_FOREACH(he, &sc->sc_he_head[pri], he_link) {
542 1.1 uch if (he->he_set == set && he->he_mask == (1 << bit)) {
543 1.1 uch TAILQ_REMOVE(&sc->sc_he_head[pri], he, he_link);
544 1.1 uch free(he, M_DEVBUF);
545 1.1 uch break;
546 1.1 uch }
547 1.1 uch }
548 1.1 uch
549 1.1 uch if (TAILQ_EMPTY(&sc->sc_he_head[pri])) {
550 1.1 uch reg = tx_conf_read(tc, TX39_INTRENABLE6_REG);
551 1.1 uch reg &= ~(1 << pri);
552 1.1 uch tx_conf_write(tc, TX39_INTRENABLE6_REG, reg);
553 1.1 uch }
554 1.1 uch }
555 1.1 uch
556 1.1 uch
557 1.12 uch void *
558 1.12 uch tx_intr_establish(tx_chipset_tag_t tc, int line, int mode, int level,
559 1.12 uch int (*ih_fun)(void *), void *ih_arg)
560 1.1 uch {
561 1.1 uch struct tx39icu_softc *sc;
562 1.1 uch txreg_t reg;
563 1.1 uch int bit, set, highpri, ofs;
564 1.1 uch
565 1.1 uch sc = tc->tc_intrt;
566 1.1 uch
567 1.1 uch tx39_intr_decode(line, &set, &bit);
568 1.1 uch
569 1.1 uch sc->sc_le_fun[set][bit] = ih_fun;
570 1.1 uch sc->sc_le_arg[set][bit] = ih_arg;
571 1.16 uch DPRINTF("tx_intr_establish: %d:%d", set, bit);
572 1.1 uch
573 1.1 uch if ((highpri = tx39_irqhigh(set, bit))) {
574 1.1 uch tx39_irqhigh_establish(tc, set, bit, highpri,
575 1.12 uch ih_fun, ih_arg);
576 1.16 uch DPRINTF("(high)\n");
577 1.1 uch } else {
578 1.1 uch /* Set mask for acknowledge. */
579 1.1 uch sc->sc_le_mask[set] |= (1 << bit);
580 1.1 uch /* Enable interrupt */
581 1.1 uch ofs = TX39_INTRENABLE_REG(set);
582 1.1 uch reg = tx_conf_read(tc, ofs);
583 1.1 uch reg |= (1 << bit);
584 1.1 uch tx_conf_write(tc, ofs, reg);
585 1.16 uch DPRINTF("(low)\n");
586 1.1 uch }
587 1.1 uch
588 1.12 uch return ((void *)line);
589 1.1 uch }
590 1.1 uch
591 1.1 uch void
592 1.12 uch tx_intr_disestablish(tx_chipset_tag_t tc, void *arg)
593 1.1 uch {
594 1.1 uch struct tx39icu_softc *sc;
595 1.1 uch int set, bit, highpri, ofs;
596 1.1 uch txreg_t reg;
597 1.1 uch
598 1.1 uch sc = tc->tc_intrt;
599 1.1 uch
600 1.1 uch tx39_intr_decode((int)arg, &set, &bit);
601 1.16 uch DPRINTF("tx_intr_disestablish: %d:%d", set, bit);
602 1.1 uch
603 1.1 uch if ((highpri = tx39_irqhigh(set, bit))) {
604 1.1 uch tx39_irqhigh_disestablish(tc, set, bit, highpri);
605 1.16 uch DPRINTF("(high)\n");
606 1.1 uch } else {
607 1.1 uch sc->sc_le_fun[set][bit] = 0;
608 1.1 uch sc->sc_le_arg[set][bit] = 0;
609 1.1 uch sc->sc_le_mask[set] &= ~(1 << bit);
610 1.1 uch ofs = TX39_INTRENABLE_REG(set);
611 1.1 uch reg = tx_conf_read(tc, ofs);
612 1.1 uch reg &= ~(1 << bit);
613 1.1 uch tx_conf_write(tc, ofs, reg);
614 1.16 uch DPRINTF("(low)\n");
615 1.1 uch }
616 1.1 uch }
617 1.1 uch
618 1.6 uch u_int32_t
619 1.12 uch tx_intr_status(tx_chipset_tag_t tc, int r)
620 1.1 uch {
621 1.6 uch struct tx39icu_softc *sc = tc->tc_intrt;
622 1.6 uch
623 1.6 uch if (r < 0 || r >= TX39_INTRSET_MAX + 1)
624 1.6 uch panic("tx_intr_status: invalid index %d", r);
625 1.6 uch
626 1.6 uch return (u_int32_t)(sc->sc_regs[r]);
627 1.1 uch }
628 1.1 uch
629 1.1 uch #ifdef USE_POLL
630 1.12 uch void *
631 1.12 uch tx39_poll_establish(tx_chipset_tag_t tc, int interval, int level,
632 1.12 uch int (*ih_fun)(void *), void *ih_arg)
633 1.1 uch {
634 1.1 uch struct tx39icu_softc *sc;
635 1.1 uch struct txpoll_entry *p;
636 1.5 uch int s;
637 1.5 uch void *ret;
638 1.5 uch
639 1.5 uch s = splhigh();
640 1.1 uch sc = tc->tc_intrt;
641 1.1 uch
642 1.1 uch if (!(p = malloc(sizeof(struct txpoll_entry),
643 1.12 uch M_DEVBUF, M_NOWAIT))) {
644 1.1 uch panic ("tx39_poll_establish: no memory.");
645 1.1 uch }
646 1.1 uch memset(p, 0, sizeof(struct txpoll_entry));
647 1.1 uch
648 1.1 uch p->p_fun = ih_fun;
649 1.1 uch p->p_arg = ih_arg;
650 1.1 uch p->p_cnt = interval;
651 1.5 uch
652 1.1 uch if (!sc->sc_polling) {
653 1.5 uch tx39clock_alarm_set(tc, 33); /* 33 msec */
654 1.5 uch
655 1.1 uch if (!(sc->sc_poll_ih =
656 1.12 uch tx_intr_establish(
657 1.12 uch tc, MAKEINTR(5, TX39_INTRSTATUS5_ALARMINT),
658 1.12 uch IST_EDGE, level, tx39_poll_intr, sc))) {
659 1.1 uch printf("tx39_poll_establish: can't hook\n");
660 1.5 uch
661 1.5 uch splx(s);
662 1.12 uch return (0);
663 1.1 uch }
664 1.1 uch }
665 1.5 uch
666 1.1 uch sc->sc_polling++;
667 1.1 uch p->p_desc = sc->sc_polling;
668 1.1 uch TAILQ_INSERT_TAIL(&sc->sc_p_head, p, p_link);
669 1.12 uch ret = (void *)p->p_desc;
670 1.1 uch
671 1.5 uch splx(s);
672 1.12 uch return (ret);
673 1.1 uch }
674 1.1 uch
675 1.1 uch void
676 1.12 uch tx39_poll_disestablish(tx_chipset_tag_t tc, void *arg)
677 1.1 uch {
678 1.1 uch struct tx39icu_softc *sc;
679 1.1 uch struct txpoll_entry *p;
680 1.5 uch int s, desc;
681 1.5 uch
682 1.5 uch s = splhigh();
683 1.1 uch sc = tc->tc_intrt;
684 1.1 uch
685 1.1 uch desc = (int)arg;
686 1.1 uch TAILQ_FOREACH(p, &sc->sc_p_head, p_link) {
687 1.1 uch if (p->p_desc == desc) {
688 1.1 uch TAILQ_REMOVE(&sc->sc_p_head, p, p_link);
689 1.1 uch free(p, M_DEVBUF);
690 1.1 uch break;
691 1.1 uch }
692 1.1 uch }
693 1.5 uch
694 1.1 uch if (TAILQ_EMPTY(&sc->sc_p_head)) {
695 1.1 uch sc->sc_polling = 0;
696 1.1 uch tx_intr_disestablish(tc, sc->sc_poll_ih);
697 1.1 uch }
698 1.5 uch
699 1.5 uch splx(s);
700 1.5 uch return;
701 1.1 uch }
702 1.1 uch
703 1.1 uch int
704 1.12 uch tx39_poll_intr(void *arg)
705 1.1 uch {
706 1.1 uch struct tx39icu_softc *sc = arg;
707 1.1 uch struct txpoll_entry *p;
708 1.1 uch
709 1.5 uch tx39clock_alarm_refill(sc->sc_tc);
710 1.5 uch
711 1.1 uch if (!sc->sc_polling) {
712 1.12 uch return (0);
713 1.1 uch }
714 1.1 uch sc->sc_pollcnt++;
715 1.1 uch TAILQ_FOREACH(p, &sc->sc_p_head, p_link) {
716 1.1 uch if (sc->sc_pollcnt % p->p_cnt == 0) {
717 1.5 uch if ((*p->p_fun)(p->p_arg) == POLL_END)
718 1.5 uch goto disestablish;
719 1.1 uch }
720 1.1 uch }
721 1.5 uch
722 1.12 uch return (0);
723 1.5 uch
724 1.5 uch disestablish:
725 1.5 uch TAILQ_REMOVE(&sc->sc_p_head, p, p_link);
726 1.5 uch free(p, M_DEVBUF);
727 1.5 uch if (TAILQ_EMPTY(&sc->sc_p_head)) {
728 1.5 uch sc->sc_polling = 0;
729 1.5 uch tx_intr_disestablish(sc->sc_tc, sc->sc_poll_ih);
730 1.5 uch }
731 1.5 uch
732 1.12 uch return (0);
733 1.1 uch }
734 1.1 uch #endif /* USE_POLL */
735 1.6 uch
736 1.6 uch void
737 1.12 uch tx39_intr_dump(struct tx39icu_softc *sc)
738 1.6 uch {
739 1.6 uch tx_chipset_tag_t tc = sc->sc_tc;
740 1.6 uch int i, j, ofs;
741 1.6 uch txreg_t reg;
742 1.6 uch char msg[16];
743 1.6 uch
744 1.6 uch for (i = 1; i <= TX39_INTRSET_MAX; i++) {
745 1.6 uch #ifdef TX392X
746 1.6 uch if (i == 6)
747 1.6 uch continue;
748 1.6 uch #endif /* TX392X */
749 1.6 uch for (reg = j = 0; j < 32; j++) {
750 1.6 uch if (tx39_irqhigh(i, j)) {
751 1.6 uch reg |= (1 << j);
752 1.6 uch }
753 1.6 uch }
754 1.6 uch sprintf(msg, "%d high", i);
755 1.17 takemura dbg_bit_print_msg(reg, msg);
756 1.6 uch sprintf(msg, "%d status", i);
757 1.17 takemura dbg_bit_print_msg(sc->sc_regs[i], msg);
758 1.6 uch ofs = TX39_INTRENABLE_REG(i);
759 1.6 uch reg = tx_conf_read(tc, ofs);
760 1.6 uch sprintf(msg, "%d enable", i);
761 1.17 takemura dbg_bit_print_msg(reg, msg);
762 1.6 uch }
763 1.6 uch reg = sc->sc_regs[0];
764 1.6 uch printf("<%s><%s> vector=%2d\t\t[6 status]\n",
765 1.12 uch reg & TX39_INTRSTATUS6_IRQHIGH ? "HI" : "--",
766 1.12 uch reg & TX39_INTRSTATUS6_IRQLOW ? "LO" : "--",
767 1.12 uch TX39_INTRSTATUS6_INTVECT(reg));
768 1.6 uch reg = tx_conf_read(tc, TX39_INTRENABLE6_REG);
769 1.17 takemura __dbg_bit_print(reg, sizeof(reg), 0, 18, "6 enable",
770 1.17 takemura DBG_BIT_PRINT_COUNT);
771 1.6 uch
772 1.6 uch }
773