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