Home | History | Annotate | Line # | Download | only in jensenio
jensenio_intr.c revision 1.1
      1  1.1  thorpej /* $NetBSD: jensenio_intr.c,v 1.1 2000/07/12 20:36:09 thorpej Exp $ */
      2  1.1  thorpej 
      3  1.1  thorpej /*-
      4  1.1  thorpej  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
      5  1.1  thorpej  * All rights reserved.
      6  1.1  thorpej  *
      7  1.1  thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  thorpej  * by Jason R. Thorpe.
      9  1.1  thorpej  *
     10  1.1  thorpej  * Redistribution and use in source and binary forms, with or without
     11  1.1  thorpej  * modification, are permitted provided that the following conditions
     12  1.1  thorpej  * are met:
     13  1.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     14  1.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     15  1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     18  1.1  thorpej  * 3. All advertising materials mentioning features or use of this software
     19  1.1  thorpej  *    must display the following acknowledgement:
     20  1.1  thorpej  *	This product includes software developed by the NetBSD
     21  1.1  thorpej  *	Foundation, Inc. and its contributors.
     22  1.1  thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  thorpej  *    contributors may be used to endorse or promote products derived
     24  1.1  thorpej  *    from this software without specific prior written permission.
     25  1.1  thorpej  *
     26  1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  thorpej  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  thorpej  */
     38  1.1  thorpej 
     39  1.1  thorpej #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     40  1.1  thorpej 
     41  1.1  thorpej __KERNEL_RCSID(0, "$NetBSD: jensenio_intr.c,v 1.1 2000/07/12 20:36:09 thorpej Exp $");
     42  1.1  thorpej 
     43  1.1  thorpej #include <sys/types.h>
     44  1.1  thorpej #include <sys/param.h>
     45  1.1  thorpej #include <sys/time.h>
     46  1.1  thorpej #include <sys/systm.h>
     47  1.1  thorpej #include <sys/errno.h>
     48  1.1  thorpej #include <sys/malloc.h>
     49  1.1  thorpej #include <sys/device.h>
     50  1.1  thorpej #include <sys/syslog.h>
     51  1.1  thorpej 
     52  1.1  thorpej #include <machine/autoconf.h>
     53  1.1  thorpej 
     54  1.1  thorpej #include <dev/eisa/eisavar.h>
     55  1.1  thorpej 
     56  1.1  thorpej #include <dev/isa/isareg.h>
     57  1.1  thorpej #include <dev/isa/isavar.h>
     58  1.1  thorpej 
     59  1.1  thorpej #include <alpha/jensenio/jenseniovar.h>
     60  1.1  thorpej 
     61  1.1  thorpej static bus_space_tag_t pic_iot;
     62  1.1  thorpej static bus_space_handle_t pic_ioh[2];
     63  1.1  thorpej static bus_space_handle_t pic_elcr_ioh;
     64  1.1  thorpej 
     65  1.1  thorpej static const int irq_to_vector[] = {
     66  1.1  thorpej 	0x900,		/* com0 */
     67  1.1  thorpej 	0x920,		/* com1 */
     68  1.1  thorpej 	0x980,		/* keyboard */
     69  1.1  thorpej 	0x990,		/* mouse */
     70  1.1  thorpej };
     71  1.1  thorpej 
     72  1.1  thorpej int	jensenio_eisa_intr_map(void *, u_int, eisa_intr_handle_t *);
     73  1.1  thorpej const char *jensenio_eisa_intr_string(void *, int);
     74  1.1  thorpej const struct evcnt *jensenio_eisa_intr_evcnt(void *, int);
     75  1.1  thorpej void	*jensenio_eisa_intr_establish(void *, int, int, int,
     76  1.1  thorpej 	    int (*)(void *), void *);
     77  1.1  thorpej void	jensenio_eisa_intr_disestablish(void *, void *);
     78  1.1  thorpej int	jensenio_eisa_intr_alloc(void *, int, int, int *);
     79  1.1  thorpej 
     80  1.1  thorpej /*
     81  1.1  thorpej  * We have 16 (E)ISA IRQs, plus 4 hard-wired vectors which we
     82  1.1  thorpej  * assign to "virtual" IRQs.
     83  1.1  thorpej  */
     84  1.1  thorpej #define	JENSEN_MAX_IRQ	20
     85  1.1  thorpej 
     86  1.1  thorpej struct alpha_shared_intr *jensenio_eisa_intr;
     87  1.1  thorpej 
     88  1.1  thorpej void	jensenio_iointr(void *, u_long);
     89  1.1  thorpej 
     90  1.1  thorpej void	jensenio_enable_intr(int, int);
     91  1.1  thorpej void	jensenio_setlevel(int, int);
     92  1.1  thorpej void	jensenio_pic_init(void);
     93  1.1  thorpej 
     94  1.1  thorpej const int jensenio_intr_deftype[JENSEN_MAX_IRQ] = {
     95  1.1  thorpej 	IST_EDGE,		/*  0: interval timer 0 output */
     96  1.1  thorpej 	IST_EDGE,		/*  1: line printer */
     97  1.1  thorpej 	IST_UNUSABLE,		/*  2: (cascade) */
     98  1.1  thorpej 	IST_NONE,		/*  3: EISA pin B25 */
     99  1.1  thorpej 	IST_NONE,		/*  4: EISA pin B24 */
    100  1.1  thorpej 	IST_NONE,		/*  5: EISA pin B23 */
    101  1.1  thorpej 	IST_NONE,		/*  6: EISA pin B22 (floppy) */
    102  1.1  thorpej 	IST_NONE,		/*  7: EISA pin B21 */
    103  1.1  thorpej 	IST_EDGE,		/*  8: RTC */
    104  1.1  thorpej 	IST_NONE,		/*  9: EISA pin B04 */
    105  1.1  thorpej 	IST_NONE,		/* 10: EISA pin D03 */
    106  1.1  thorpej 	IST_NONE,		/* 11: EISA pin D04 */
    107  1.1  thorpej 	IST_NONE,		/* 12: EISA pin D05 */
    108  1.1  thorpej 	IST_UNUSABLE,		/* 13: not connected */
    109  1.1  thorpej 	IST_NONE,		/* 14: EISA pin D07 (SCSI) */
    110  1.1  thorpej 	IST_NONE,		/* 15: EISA pin D06 */
    111  1.1  thorpej 	IST_EDGE,		/* 16: com0 (vector 0x900) */
    112  1.1  thorpej 	IST_EDGE,		/* 17: com1 (vector 0x920) */
    113  1.1  thorpej 	IST_EDGE,		/* 18: keyboard (vector 0x980) */
    114  1.1  thorpej 	IST_EDGE,		/* 19: mouse (vector 0x990) */
    115  1.1  thorpej };
    116  1.1  thorpej 
    117  1.1  thorpej void
    118  1.1  thorpej jensenio_intr_init(struct jensenio_config *jcp)
    119  1.1  thorpej {
    120  1.1  thorpej 	eisa_chipset_tag_t ec = &jcp->jc_ec;
    121  1.1  thorpej 	isa_chipset_tag_t ic = &jcp->jc_ic;
    122  1.1  thorpej 	char *cp;
    123  1.1  thorpej 	int i;
    124  1.1  thorpej 
    125  1.1  thorpej 	pic_iot = &jcp->jc_eisa_iot;
    126  1.1  thorpej 
    127  1.1  thorpej 	jensenio_pic_init();
    128  1.1  thorpej 
    129  1.1  thorpej 	jensenio_eisa_intr = alpha_shared_intr_alloc(JENSEN_MAX_IRQ, 16);
    130  1.1  thorpej 	for (i = 0; i < JENSEN_MAX_IRQ; i++) {
    131  1.1  thorpej 		alpha_shared_intr_set_dfltsharetype(jensenio_eisa_intr,
    132  1.1  thorpej 		    i, jensenio_intr_deftype[i]);
    133  1.1  thorpej 		/* Don't bother with stray interrupts. */
    134  1.1  thorpej 		alpha_shared_intr_set_maxstrays(jensenio_eisa_intr,
    135  1.1  thorpej 		    i, 0);
    136  1.1  thorpej 
    137  1.1  thorpej 		cp = alpha_shared_intr_string(jensenio_eisa_intr, i);
    138  1.1  thorpej 		if (i > 15) {
    139  1.1  thorpej 			sprintf(cp, "0x%03x", irq_to_vector[i - 16]);
    140  1.1  thorpej 			evcnt_attach_dynamic(alpha_shared_intr_evcnt(
    141  1.1  thorpej 			    jensenio_eisa_intr, i), EVCNT_TYPE_INTR,
    142  1.1  thorpej 			    NULL, "vector", cp);
    143  1.1  thorpej 		} else {
    144  1.1  thorpej 			sprintf(cp, "irq %d", i);
    145  1.1  thorpej 			evcnt_attach_dynamic(alpha_shared_intr_evcnt(
    146  1.1  thorpej 			    jensenio_eisa_intr, i), EVCNT_TYPE_INTR,
    147  1.1  thorpej 			    NULL, "eisa", cp);
    148  1.1  thorpej 		}
    149  1.1  thorpej 	}
    150  1.1  thorpej 
    151  1.1  thorpej 	/*
    152  1.1  thorpej 	 * The cascasde interrupt must be edge triggered and always enabled.
    153  1.1  thorpej 	 */
    154  1.1  thorpej 	jensenio_setlevel(2, 0);
    155  1.1  thorpej 	jensenio_enable_intr(2, 1);
    156  1.1  thorpej 
    157  1.1  thorpej 	/*
    158  1.1  thorpej 	 * Initialize the EISA chipset.
    159  1.1  thorpej 	 */
    160  1.1  thorpej 	ec->ec_v = jcp;
    161  1.1  thorpej 	ec->ec_intr_map = jensenio_eisa_intr_map;
    162  1.1  thorpej 	ec->ec_intr_string = jensenio_eisa_intr_string;
    163  1.1  thorpej 	ec->ec_intr_evcnt = jensenio_eisa_intr_evcnt;
    164  1.1  thorpej 	ec->ec_intr_establish = jensenio_eisa_intr_establish;
    165  1.1  thorpej 	ec->ec_intr_disestablish = jensenio_eisa_intr_disestablish;
    166  1.1  thorpej 
    167  1.1  thorpej 	/*
    168  1.1  thorpej 	 * Initialize the ISA chipset.
    169  1.1  thorpej 	 */
    170  1.1  thorpej 	ic->ic_v = jcp;
    171  1.1  thorpej 	ic->ic_intr_establish = jensenio_eisa_intr_establish;
    172  1.1  thorpej 	ic->ic_intr_disestablish = jensenio_eisa_intr_disestablish;
    173  1.1  thorpej 	ic->ic_intr_alloc = jensenio_eisa_intr_alloc;
    174  1.1  thorpej 	ic->ic_intr_evcnt = jensenio_eisa_intr_evcnt;
    175  1.1  thorpej 
    176  1.1  thorpej 	set_iointr(jensenio_iointr);
    177  1.1  thorpej }
    178  1.1  thorpej 
    179  1.1  thorpej int
    180  1.1  thorpej jensenio_eisa_intr_map(void *v, u_int eirq, eisa_intr_handle_t *ihp)
    181  1.1  thorpej {
    182  1.1  thorpej 
    183  1.1  thorpej 	if (eirq > 15) {
    184  1.1  thorpej 		printf("jensenio_eisa_intr_map: bad EISA IRQ %d\n",
    185  1.1  thorpej 		    eirq);
    186  1.1  thorpej 		*ihp = -1;
    187  1.1  thorpej 		return (1);
    188  1.1  thorpej 	}
    189  1.1  thorpej 
    190  1.1  thorpej 	if (jensenio_intr_deftype[eirq] == IST_UNUSABLE) {
    191  1.1  thorpej 		printf("jensenio_eisa_intr_map: unusable irq %d\n",
    192  1.1  thorpej 		    eirq);
    193  1.1  thorpej 		*ihp = -1;
    194  1.1  thorpej 		return (1);
    195  1.1  thorpej 	}
    196  1.1  thorpej 
    197  1.1  thorpej 	*ihp = eirq;
    198  1.1  thorpej 	return (0);
    199  1.1  thorpej }
    200  1.1  thorpej 
    201  1.1  thorpej const char *
    202  1.1  thorpej jensenio_eisa_intr_string(void *v, int eirq)
    203  1.1  thorpej {
    204  1.1  thorpej 	static char irqstr[64];
    205  1.1  thorpej 
    206  1.1  thorpej 	if (eirq > 19)
    207  1.1  thorpej 		panic("jensenio_eisa_intr_string: bogus IRQ %d\n", eirq);
    208  1.1  thorpej 
    209  1.1  thorpej 	if (eirq > 15)
    210  1.1  thorpej 		sprintf(irqstr, "vector 0x%03x", irq_to_vector[eirq - 16]);
    211  1.1  thorpej 	else
    212  1.1  thorpej 		sprintf(irqstr, "eisa irq %d", eirq);
    213  1.1  thorpej 
    214  1.1  thorpej 	return (irqstr);
    215  1.1  thorpej }
    216  1.1  thorpej 
    217  1.1  thorpej const struct evcnt *
    218  1.1  thorpej jensenio_eisa_intr_evcnt(void *v, int eirq)
    219  1.1  thorpej {
    220  1.1  thorpej 
    221  1.1  thorpej 	if (eirq > 19)
    222  1.1  thorpej 		panic("jensenio_eisa_intr_evcnt: bogus IRQ %d\n", eirq);
    223  1.1  thorpej 
    224  1.1  thorpej 	return (alpha_shared_intr_evcnt(jensenio_eisa_intr, eirq));
    225  1.1  thorpej }
    226  1.1  thorpej 
    227  1.1  thorpej void *
    228  1.1  thorpej jensenio_eisa_intr_establish(void *v, int irq, int type, int level,
    229  1.1  thorpej     int (*fn)(void *), void *arg)
    230  1.1  thorpej {
    231  1.1  thorpej 	void *cookie;
    232  1.1  thorpej 
    233  1.1  thorpej 	if (irq > 19 || type == IST_NONE)
    234  1.1  thorpej 		panic("jensenio_eisa_intr_establish: bogus irq or type");
    235  1.1  thorpej 
    236  1.1  thorpej 	if (jensenio_intr_deftype[irq] == IST_UNUSABLE) {
    237  1.1  thorpej 		printf("jensenio_eisa_intr_establish: IRQ %d not usable\n",
    238  1.1  thorpej 		    irq);
    239  1.1  thorpej 		return (NULL);
    240  1.1  thorpej 	}
    241  1.1  thorpej 
    242  1.1  thorpej 	cookie = alpha_shared_intr_establish(jensenio_eisa_intr, irq,
    243  1.1  thorpej 	    type, level, fn, arg, "eisa irq");
    244  1.1  thorpej 
    245  1.1  thorpej 	if (irq > 15)
    246  1.1  thorpej 		return (cookie);
    247  1.1  thorpej 
    248  1.1  thorpej 	if (cookie != NULL &&
    249  1.1  thorpej 	    alpha_shared_intr_isactive(jensenio_eisa_intr, irq)) {
    250  1.1  thorpej 		jensenio_setlevel(irq,
    251  1.1  thorpej 		    alpha_shared_intr_get_sharetype(jensenio_eisa_intr,
    252  1.1  thorpej 						    irq) == IST_LEVEL);
    253  1.1  thorpej 		jensenio_enable_intr(irq, 1);
    254  1.1  thorpej 	}
    255  1.1  thorpej 
    256  1.1  thorpej 	return (cookie);
    257  1.1  thorpej }
    258  1.1  thorpej 
    259  1.1  thorpej void
    260  1.1  thorpej jensenio_eisa_intr_disestablish(void *v, void *cookie)
    261  1.1  thorpej {
    262  1.1  thorpej 	struct alpha_shared_intrhand *ih = cookie;
    263  1.1  thorpej 	int s, irq = ih->ih_num;
    264  1.1  thorpej 
    265  1.1  thorpej 	s = splhigh();
    266  1.1  thorpej 
    267  1.1  thorpej 	/* Remove it from the link. */
    268  1.1  thorpej 	alpha_shared_intr_disestablish(jensenio_eisa_intr, cookie,
    269  1.1  thorpej 	    "eisa irq");
    270  1.1  thorpej 
    271  1.1  thorpej 	if (irq > 15) {
    272  1.1  thorpej 		splx(s);
    273  1.1  thorpej 		return;
    274  1.1  thorpej 	}
    275  1.1  thorpej 
    276  1.1  thorpej 	if (alpha_shared_intr_isactive(jensenio_eisa_intr, irq) == 0) {
    277  1.1  thorpej 		jensenio_enable_intr(irq, 0);
    278  1.1  thorpej 		alpha_shared_intr_set_dfltsharetype(jensenio_eisa_intr,
    279  1.1  thorpej 		    irq, jensenio_intr_deftype[irq]);
    280  1.1  thorpej 	}
    281  1.1  thorpej 
    282  1.1  thorpej 	splx(s);
    283  1.1  thorpej }
    284  1.1  thorpej 
    285  1.1  thorpej int
    286  1.1  thorpej jensenio_eisa_intr_alloc(void *v, int mask, int type, int *rqp)
    287  1.1  thorpej {
    288  1.1  thorpej 
    289  1.1  thorpej 	/* XXX Not supported right now. */
    290  1.1  thorpej 	return (1);
    291  1.1  thorpej }
    292  1.1  thorpej 
    293  1.1  thorpej void
    294  1.1  thorpej jensenio_iointr(void *framep, u_long vec)
    295  1.1  thorpej {
    296  1.1  thorpej 	int irq;
    297  1.1  thorpej 
    298  1.1  thorpej 	switch (vec) {
    299  1.1  thorpej 	case 0x900: irq = 16; break;		/* com0 */
    300  1.1  thorpej 	case 0x920: irq = 17; break;		/* com1 */
    301  1.1  thorpej 	case 0x980: irq = 18; break;		/* keyboard */
    302  1.1  thorpej 	case 0x990: irq = 19; break;		/* mouse */
    303  1.1  thorpej 	default:
    304  1.1  thorpej 		if (vec >= 0x800) {
    305  1.1  thorpej 			if (vec >= 0x800 + (16 << 4))
    306  1.1  thorpej 				panic("jensenio_iointr: vec 0x%lx out of "
    307  1.1  thorpej 				    "range\n", vec);
    308  1.1  thorpej 			irq = (vec - 0x800) >> 4;
    309  1.1  thorpej 		} else
    310  1.1  thorpej 			panic("jensenio_iointr: wierd vec 0x%lx\n", vec);
    311  1.1  thorpej 	}
    312  1.1  thorpej 
    313  1.1  thorpej 	if (!alpha_shared_intr_dispatch(jensenio_eisa_intr, irq)) {
    314  1.1  thorpej 		alpha_shared_intr_stray(jensenio_eisa_intr, irq,
    315  1.1  thorpej 		    "eisa irq");
    316  1.1  thorpej 		if (ALPHA_SHARED_INTR_DISABLE(jensenio_eisa_intr, irq))
    317  1.1  thorpej 			jensenio_enable_intr(irq, 0);
    318  1.1  thorpej 	}
    319  1.1  thorpej }
    320  1.1  thorpej 
    321  1.1  thorpej void
    322  1.1  thorpej jensenio_enable_intr(int irq, int onoff)
    323  1.1  thorpej {
    324  1.1  thorpej 	int pic;
    325  1.1  thorpej 	u_int8_t bit, mask;
    326  1.1  thorpej 
    327  1.1  thorpej 	pic = irq >> 3;
    328  1.1  thorpej 	bit = 1 << (irq & 0x7);
    329  1.1  thorpej 
    330  1.1  thorpej 	mask = bus_space_read_1(pic_iot, pic_ioh[pic], 1);
    331  1.1  thorpej 	if (onoff)
    332  1.1  thorpej 		mask &= ~bit;
    333  1.1  thorpej 	else
    334  1.1  thorpej 		mask |= bit;
    335  1.1  thorpej 	bus_space_write_1(pic_iot, pic_ioh[pic], 1, mask);
    336  1.1  thorpej }
    337  1.1  thorpej 
    338  1.1  thorpej void
    339  1.1  thorpej jensenio_setlevel(int irq, int level)
    340  1.1  thorpej {
    341  1.1  thorpej 	int elcr;
    342  1.1  thorpej 	u_int8_t bit, mask;
    343  1.1  thorpej 
    344  1.1  thorpej 	elcr = irq >> 3;
    345  1.1  thorpej 	bit = 1 << (irq & 0x7);
    346  1.1  thorpej 
    347  1.1  thorpej 	mask = bus_space_read_1(pic_iot, pic_elcr_ioh, elcr);
    348  1.1  thorpej 	if (level)
    349  1.1  thorpej 		mask |= bit;
    350  1.1  thorpej 	else
    351  1.1  thorpej 		mask &= ~bit;
    352  1.1  thorpej 	bus_space_write_1(pic_iot, pic_elcr_ioh, elcr, mask);
    353  1.1  thorpej }
    354  1.1  thorpej 
    355  1.1  thorpej void
    356  1.1  thorpej jensenio_pic_init(void)
    357  1.1  thorpej {
    358  1.1  thorpej 	static const int picaddr[2] = { IO_ICU1, IO_ICU2 };
    359  1.1  thorpej 	int pic;
    360  1.1  thorpej 
    361  1.1  thorpej 	/*
    362  1.1  thorpej 	 * Map the PICs and mask off the interrupts on them.
    363  1.1  thorpej 	 */
    364  1.1  thorpej 	for (pic = 0; pic < 2; pic++) {
    365  1.1  thorpej 		if (bus_space_map(pic_iot, picaddr[pic], 2, 0, &pic_ioh[pic]))
    366  1.1  thorpej 			panic("jensenio_init_intr: unable to map PIC %d", pic);
    367  1.1  thorpej 		bus_space_write_1(pic_iot, pic_ioh[pic], 1, 0xff);
    368  1.1  thorpej 	}
    369  1.1  thorpej 
    370  1.1  thorpej 	/*
    371  1.1  thorpej 	 * Map the ELCR registers.
    372  1.1  thorpej 	 */
    373  1.1  thorpej 	if (bus_space_map(pic_iot, 0x4d0, 2, 0, &pic_elcr_ioh))
    374  1.1  thorpej 		panic("jensenio_init_intr: unable to map ELCR registers");
    375  1.1  thorpej }
    376