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