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