Home | History | Annotate | Line # | Download | only in pci
pci_2100_a500.c revision 1.1
      1 /* $NetBSD: pci_2100_a500.c,v 1.1 2000/12/21 20:51:53 thorpej Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the NetBSD
     21  *	Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     40 
     41 __KERNEL_RCSID(0, "$NetBSD: pci_2100_a500.c,v 1.1 2000/12/21 20:51:53 thorpej Exp $");
     42 
     43 #include <sys/types.h>
     44 #include <sys/param.h>
     45 #include <sys/time.h>
     46 #include <sys/systm.h>
     47 #include <sys/errno.h>
     48 #include <sys/malloc.h>
     49 #include <sys/device.h>
     50 #include <sys/syslog.h>
     51 
     52 #include <machine/autoconf.h>
     53 
     54 #include <dev/eisa/eisavar.h>
     55 
     56 #include <dev/pci/pcireg.h>
     57 #include <dev/pci/pcivar.h>
     58 
     59 #include <alpha/pci/ttwogareg.h>
     60 #include <alpha/pci/ttwogavar.h>
     61 #include <alpha/pci/pci_2100_a500.h>
     62 
     63 static bus_space_tag_t pic_iot;
     64 static bus_space_handle_t pic_master_ioh;
     65 static bus_space_handle_t pic_slave_ioh[4];
     66 static bus_space_handle_t pic_elcr_ioh;
     67 
     68 static const int pic_slave_to_master[4] = { 1, 3, 4, 5 };
     69 
     70 int	dec_2100_a500_pic_intr_map(void *, pcitag_t, int, int,
     71 	    pci_intr_handle_t *);
     72 
     73 int	dec_2100_a500_icic_intr_map(void *, pcitag_t, int, int,
     74 	    pci_intr_handle_t *);
     75 
     76 const char *dec_2100_a500_intr_string(void *, pci_intr_handle_t);
     77 const struct evcnt *dec_2100_a500_intr_evcnt(void *, pci_intr_handle_t);
     78 void	*dec_2100_a500_intr_establish(void *, pci_intr_handle_t,
     79 	    int, int (*)(void *), void *);
     80 void	dec_2100_a500_intr_disestablish(void *, void *);
     81 
     82 int	dec_2100_a500_eisa_intr_map(void *, u_int, eisa_intr_handle_t *);
     83 const char *dec_2100_a500_eisa_intr_string(void *, int);
     84 const struct evcnt *dec_2100_a500_eisa_intr_evcnt(void *, int);
     85 void	*dec_2100_a500_eisa_intr_establish(void *, int, int, int,
     86 	    int (*)(void *), void *);
     87 void	dec_2100_a500_eisa_intr_disestablish(void *, void *);
     88 int	dec_2100_a500_eisa_intr_alloc(void *, int, int, int *);
     89 
     90 #define	PCI_STRAY_MAX	5
     91 
     92 /*
     93  * On systems with cascaded 8259s, it's actually 32.  Systems which
     94  * use the ICIC interrupt logic have 64, however.
     95  */
     96 #define	SABLE_MAX_IRQ		64
     97 #define	SABLE_8259_MAX_IRQ	32
     98 
     99 void	dec_2100_a500_iointr(void *, u_long);
    100 
    101 void	dec_2100_a500_pic_enable_intr(struct ttwoga_config *, int, int);
    102 void	dec_2100_a500_pic_init_intr(struct ttwoga_config *);
    103 void	dec_2100_a500_pic_setlevel(struct ttwoga_config *, int, int);
    104 void	dec_2100_a500_pic_eoi(struct ttwoga_config *, int);
    105 
    106 void	dec_2100_a500_icic_enable_intr(struct ttwoga_config *, int, int);
    107 void	dec_2100_a500_icic_init_intr(struct ttwoga_config *);
    108 void	dec_2100_a500_icic_setlevel(struct ttwoga_config *, int, int);
    109 void	dec_2100_a500_icic_eoi(struct ttwoga_config *, int);
    110 
    111 #define	T2_IRQ_EISA_START	7
    112 #define	T2_IRQ_EISA_COUNT	16
    113 
    114 #define	T2_IRQ_IS_EISA(irq)						\
    115 	((irq) >= T2_IRQ_EISA_START &&					\
    116 	 (irq) < (T2_IRQ_EISA_START + T2_IRQ_EISA_COUNT))
    117 
    118 const int dec_2100_a500_intr_deftype[SABLE_MAX_IRQ] = {
    119 	IST_LEVEL,		/* PCI slot 0 A */
    120 	IST_LEVEL,		/* on-board SCSI */
    121 	IST_LEVEL,		/* on-board Ethernet */
    122 	IST_EDGE,		/* mouse */
    123 	IST_LEVEL,		/* PCI slot 1 A */
    124 	IST_LEVEL,		/* PCI slot 2 A */
    125 	IST_EDGE,		/* keyboard */
    126 	IST_EDGE,		/* floppy (EISA IRQ 0) */
    127 	IST_EDGE,		/* serial port 1 (EISA IRQ 1) */
    128 	IST_EDGE,		/* parallel port (EISA IRQ 2) */
    129 	IST_NONE,		/* EISA IRQ 3 (edge/level) */
    130 	IST_NONE,		/* EISA IRQ 4 (edge/level) */
    131 	IST_NONE,		/* EISA IRQ 5 (edge/level) */
    132 	IST_NONE,		/* EISA IRQ 6 (edge/level) */
    133 	IST_NONE,		/* EISA IRQ 7 (edge/level) */
    134 	IST_EDGE,		/* serial port 0 (EISA IRQ 8) */
    135 	IST_NONE,		/* EISA IRQ 9 (edge/level) */
    136 	IST_NONE,		/* EISA IRQ 10 (edge/level) */
    137 	IST_NONE,		/* EISA IRQ 11 (edge/level) */
    138 	IST_NONE,		/* EISA IRQ 12 (edge/level) */
    139 	IST_LEVEL,		/* PCI slot 2 B (EISA IRQ 13 n/c) */
    140 	IST_NONE,		/* EISA IRQ 14 (edge/level) */
    141 	IST_NONE,		/* EISA IRQ 15 (edge/level) */
    142 	IST_LEVEL,		/* I2C (XXX double-check this) */
    143 	IST_LEVEL,		/* PCI slot 0 B */
    144 	IST_LEVEL,		/* PCI slot 1 B */
    145 	IST_LEVEL,		/* PCI slot 0 C */
    146 	IST_LEVEL,		/* PCI slot 1 C */
    147 	IST_LEVEL,		/* PCI slot 2 C */
    148 	IST_LEVEL,		/* PCI slot 0 D */
    149 	IST_LEVEL,		/* PCI slot 1 D */
    150 	IST_LEVEL,		/* PCI slot 2 D */
    151 
    152 	/*
    153 	 * These are the PCI interrupts on the T3/T4 systems.  See
    154 	 * dec_2100_a500_icic_intr_map() for the mapping.
    155 	 */
    156 	IST_LEVEL,
    157 	IST_LEVEL,
    158 	IST_LEVEL,
    159 	IST_LEVEL,
    160 	IST_LEVEL,
    161 	IST_LEVEL,
    162 	IST_LEVEL,
    163 	IST_LEVEL,
    164 	IST_LEVEL,
    165 	IST_LEVEL,
    166 	IST_LEVEL,
    167 	IST_LEVEL,
    168 	IST_LEVEL,
    169 	IST_LEVEL,
    170 	IST_LEVEL,
    171 	IST_LEVEL,
    172 	IST_LEVEL,
    173 	IST_LEVEL,
    174 	IST_LEVEL,
    175 	IST_LEVEL,
    176 	IST_LEVEL,
    177 	IST_LEVEL,
    178 	IST_LEVEL,
    179 	IST_LEVEL,
    180 	IST_LEVEL,
    181 	IST_LEVEL,
    182 	IST_LEVEL,
    183 	IST_LEVEL,
    184 	IST_LEVEL,
    185 	IST_LEVEL,
    186 	IST_LEVEL,
    187 	IST_LEVEL,
    188 };
    189 
    190 void
    191 pci_2100_a500_pickintr(struct ttwoga_config *tcp)
    192 {
    193 	pci_chipset_tag_t pc = &tcp->tc_pc;
    194 	char *cp;
    195 	int i;
    196 
    197 	pic_iot = &tcp->tc_iot;
    198 
    199 	pc->pc_intr_v = tcp;
    200 	pc->pc_intr_string = dec_2100_a500_intr_string;
    201 	pc->pc_intr_evcnt = dec_2100_a500_intr_evcnt;
    202 	pc->pc_intr_establish = dec_2100_a500_intr_establish;
    203 	pc->pc_intr_disestablish = dec_2100_a500_intr_disestablish;
    204 
    205 	/* Not supported on T2. */
    206 	pc->pc_pciide_compat_intr_establish = NULL;
    207 
    208 	tcp->tc_intrtab = alpha_shared_intr_alloc(SABLE_MAX_IRQ, 8);
    209 	for (i = 0; i < SABLE_MAX_IRQ; i++) {
    210 		alpha_shared_intr_set_dfltsharetype(tcp->tc_intrtab,
    211 		    i, tcp->tc_hose == 0 ?
    212 		    dec_2100_a500_intr_deftype[i] : IST_LEVEL);
    213 		alpha_shared_intr_set_maxstrays(tcp->tc_intrtab,
    214 		    i, PCI_STRAY_MAX);
    215 
    216 		cp = alpha_shared_intr_string(tcp->tc_intrtab, i);
    217 		sprintf(cp, "irq %d", T2_IRQ_IS_EISA(i) ?
    218 		    i - T2_IRQ_EISA_START : i);
    219 		evcnt_attach_dynamic(alpha_shared_intr_evcnt(
    220 		    tcp->tc_intrtab, i), EVCNT_TYPE_INTR, NULL,
    221 		    T2_IRQ_IS_EISA(i) ? "eisa" : "T2", cp);
    222 	}
    223 
    224 	/*
    225 	 * T2 uses a custom layout of cascaded 8259 PICs for interrupt
    226 	 * control.  T3 and T4 use a built-in interrupt controller.
    227 	 *
    228 	 * Note that the external PCI bus (Hose 1) always uses
    229 	 * the new interrupt controller.
    230 	 */
    231 	if (tcp->tc_rev < TRN_T3 && tcp->tc_hose == 0) {
    232 		pc->pc_intr_map = dec_2100_a500_pic_intr_map;
    233 		tcp->tc_enable_intr = dec_2100_a500_pic_enable_intr;
    234 		tcp->tc_setlevel = dec_2100_a500_pic_setlevel;
    235 		tcp->tc_eoi = dec_2100_a500_pic_eoi;
    236 		dec_2100_a500_pic_init_intr(tcp);
    237 	} else {
    238 		pc->pc_intr_map = dec_2100_a500_icic_intr_map;
    239 		tcp->tc_enable_intr = dec_2100_a500_icic_enable_intr;
    240 		tcp->tc_setlevel = dec_2100_a500_icic_setlevel;
    241 		tcp->tc_eoi = dec_2100_a500_icic_eoi;
    242 		dec_2100_a500_icic_init_intr(tcp);
    243 	}
    244 
    245 	set_iointr(dec_2100_a500_iointr);
    246 }
    247 
    248 void
    249 pci_2100_a500_eisa_pickintr(pci_chipset_tag_t pc, eisa_chipset_tag_t ec)
    250 {
    251 
    252 	ec->ec_v = pc->pc_intr_v;
    253 	ec->ec_intr_map = dec_2100_a500_eisa_intr_map;
    254 	ec->ec_intr_string = dec_2100_a500_eisa_intr_string;
    255 	ec->ec_intr_evcnt = dec_2100_a500_eisa_intr_evcnt;
    256 	ec->ec_intr_establish = dec_2100_a500_eisa_intr_establish;
    257 	ec->ec_intr_disestablish = dec_2100_a500_eisa_intr_disestablish;
    258 }
    259 
    260 void
    261 pci_2100_a500_isa_pickintr(pci_chipset_tag_t pc, isa_chipset_tag_t ic)
    262 {
    263 
    264 	ic->ic_v = pc->pc_intr_v;
    265 	ic->ic_intr_evcnt = dec_2100_a500_eisa_intr_evcnt;
    266 	ic->ic_intr_establish = dec_2100_a500_eisa_intr_establish;
    267 	ic->ic_intr_disestablish = dec_2100_a500_eisa_intr_disestablish;
    268 	ic->ic_intr_alloc = dec_2100_a500_eisa_intr_alloc;
    269 }
    270 
    271 /*****************************************************************************
    272  * PCI interrupt support.
    273  *****************************************************************************/
    274 
    275 int
    276 dec_2100_a500_pic_intr_map(void *v, pcitag_t bustag, int buspin,
    277     int line, pci_intr_handle_t *ihp)
    278 {
    279 	/*
    280 	 * Interrupts in the Sable are even more of a pain than other
    281 	 * Alpha systems.  The interrupt logic is made up of 5 8259
    282 	 * PICs, arranged as follows:
    283 	 *
    284 	 *	Slave 0 --------------------------------+
    285 	 *	0 PCI slot 0 A				|
    286 	 *	1 on-board SCSI				|
    287 	 *	2 on-board Ethernet			|
    288 	 *	3 mouse					|
    289 	 *	4 PCI slot 1 A				|
    290 	 *	5 PCI slot 2 A				|
    291 	 *	6 keyboard				|
    292 	 *	7 floppy (EISA IRQ 0)			|
    293 	 *						|
    294 	 *	Slave 1	------------------------+	|   Master
    295 	 *	0 serial port 1 (EISA IRQ 1)	|	|   0 ESC interrupt
    296 	 *	1 parallel port (EISA IRQ 2)	|	+-- 1 Slave 0
    297 	 *	2 EISA IRQ 3			|	    2 reserved
    298 	 *	3 EISA IRQ 4			+---------- 3 Slave 1
    299 	 *	4 EISA IRQ 5			+---------- 4 Slave 2
    300 	 *	5 EISA IRQ 6			|	+-- 5 Slave 3
    301 	 *	6 EISA IRQ 7			|	|   6 reserved
    302 	 *	7 serial port 0 (EISA IRQ 8)	|	|   7 n/c
    303 	 *					|	|
    304 	 *	Slave 2 ------------------------+	|
    305 	 *	0 EISA IRQ 9				|
    306 	 *	1 EISA IRQ 10				|
    307 	 *	2 EISA IRQ 11				|
    308 	 *	3 EISA IRQ 12				|
    309 	 *	4 PCI slot 2 B (EISA IRQ 13 n/c)	|
    310 	 *	5 EISA IRQ 14				|
    311 	 *	6 EISA IRQ 15				|
    312 	 *	7 I2C					|
    313 	 *						|
    314 	 *	Slave 3 --------------------------------+
    315 	 *	0 PCI slot 0 B
    316 	 *	1 PCI slot 1 B
    317 	 *	2 PCI slot 0 C
    318 	 *	3 PCI slot 1 C
    319 	 *	4 PCI slot 2 C
    320 	 *	5 PCI slot 0 D
    321 	 *	6 PCI slot 1 D
    322 	 *	7 PCI slot 2 D
    323 	 *
    324 	 * Careful readers will note that the PCEB does not handle ISA
    325 	 * interrupts at all; when ISA interrupts are established, they
    326 	 * must be mapped to Sable interrupts.  Thankfully, this is easy
    327 	 * to do.
    328 	 *
    329 	 * The T3 and T4, generally found on Lynx, use a totally different
    330 	 * scheme because they have more PCI interrupts to handle; see below.
    331 	 */
    332 	static const int irqmap[9/*device*/][4/*pin*/] = {
    333 		{ 0x02, -1, -1, -1 },		/* 0: on-board Ethernet */
    334 		{ 0x01, -1, -1, -1 },		/* 1: on-board SCSI */
    335 		{ -1, -1, -1, -1 },		/* 2: invalid */
    336 		{ -1, -1, -1, -1 },		/* 3: invalid */
    337 		{ -1, -1, -1, -1 },		/* 4: invalid */
    338 		{ -1, -1, -1, -1 },		/* 5: invalid */
    339 		{ 0x00, 0x18, 0x1a, 0x1d },	/* 6: PCI slot 0 */
    340 		{ 0x04, 0x19, 0x1b, 0x1e },	/* 7: PCI slot 1 */
    341 		{ 0x05, 0x14, 0x1c, 0x1f },	/* 8: PCI slot 2 */
    342 	};
    343 	struct ttwoga_config *tcp = v;
    344 	pci_chipset_tag_t pc = &tcp->tc_pc;
    345 	int device, irq;
    346 
    347 	if (buspin == 0) {
    348 		/* No IRQ used. */
    349 		return (1);
    350 	}
    351 
    352 	if (buspin > 4) {
    353 		printf("dec_2100_a500_pic_intr_map: bad interrupt pin %d\n",
    354 		    buspin);
    355 		return (1);
    356 	}
    357 
    358 	alpha_pci_decompose_tag(pc, bustag, NULL, &device, NULL);
    359 	if (device > 8) {
    360 		printf("dec_2100_a500_pic_intr_map: bad device %d\n",
    361 		    device);
    362 		return (1);
    363 	}
    364 
    365 	irq = irqmap[device][buspin - 1];
    366 	if (irq == -1) {
    367 		printf("dec_2100_a500_pic_intr_map: no mapping for "
    368 		    "device %d pin %d\n", device, buspin);
    369 		return (1);
    370 	}
    371 	*ihp = irq;
    372 	return (0);
    373 }
    374 
    375 int
    376 dec_2100_a500_icic_intr_map(void *v, pcitag_t bustag, int buspin,
    377     int line, pci_intr_handle_t *ihp)
    378 {
    379 	struct ttwoga_config *tcp = v;
    380 	pci_chipset_tag_t pc = &tcp->tc_pc;
    381 	int device, irq;
    382 
    383 	if (buspin == 0) {
    384 		/* No IRQ used. */
    385 		return (1);
    386 	}
    387 
    388 	if (buspin > 4) {
    389 		printf("dec_2100_a500_icic_intr_map: bad interrupt in %d\n",
    390 		    buspin);
    391 		return (1);
    392 	}
    393 
    394 	alpha_pci_decompose_tag(pc, bustag, NULL, &device, NULL);
    395 	switch (device) {
    396 	case 0:		/* on-board Ethernet */
    397 		irq = 24;
    398 		break;
    399 
    400 	case 1:		/* on-board SCSI */
    401 		irq = 28;
    402 		break;
    403 
    404 	case 6:		/* PCI slots */
    405 	case 7:
    406 	case 8:
    407 		irq = (32 + (4 * (device - 6))) + (buspin - 1);
    408 		break;
    409 
    410 	default:
    411 		printf("dec_2100_a500_icic_intr_map: bad device %d\n",
    412 		    device);
    413 		return (1);
    414 	}
    415 
    416 	*ihp = irq;
    417 	return (0);
    418 }
    419 
    420 const char *
    421 dec_2100_a500_intr_string(void *v, pci_intr_handle_t ih)
    422 {
    423 	static char irqstr[15];		/* 11 + 2 + NULL + sanity */
    424 
    425 	if (ih >= SABLE_MAX_IRQ)
    426 		panic("dec_2100_a500_intr_string: bogus T2 IRQ 0x%lx\n", ih);
    427 
    428 	sprintf(irqstr, "T2 irq %ld", ih);
    429 	return (irqstr);
    430 }
    431 
    432 const struct evcnt *
    433 dec_2100_a500_intr_evcnt(void *v, pci_intr_handle_t ih)
    434 {
    435 	struct ttwoga_config *tcp = v;
    436 
    437 	if (ih >= SABLE_MAX_IRQ)
    438 		panic("dec_2100_a500_intr_evcnt: bogus T2 IRQ 0x%lx\n", ih);
    439 
    440 	return (alpha_shared_intr_evcnt(tcp->tc_intrtab, ih));
    441 }
    442 
    443 void *
    444 dec_2100_a500_intr_establish(void *v, pci_intr_handle_t ih, int level,
    445     int (*func)(void *), void *arg)
    446 {
    447 	struct ttwoga_config *tcp = v;
    448 	void *cookie;
    449 
    450 	if (ih >= SABLE_MAX_IRQ)
    451 		panic("dec_2100_a500_intr_establish: bogus IRQ 0x%lx\n",
    452 		    ih);
    453 
    454 	cookie = alpha_shared_intr_establish(tcp->tc_intrtab, ih,
    455 	    dec_2100_a500_intr_deftype[ih], level, func, arg, "T2 irq");
    456 
    457 	if (cookie != NULL &&
    458 	    alpha_shared_intr_isactive(tcp->tc_intrtab, ih))
    459 		(*tcp->tc_enable_intr)(tcp, ih, 1);
    460 
    461 	return (cookie);
    462 }
    463 
    464 void
    465 dec_2100_a500_intr_disestablish(void *v, void *cookie)
    466 {
    467 	struct ttwoga_config *tcp = v;
    468 	struct alpha_shared_intrhand *ih = cookie;
    469 	unsigned int irq = ih->ih_num;
    470 	int s;
    471 
    472 	s = splhigh();
    473 
    474 	alpha_shared_intr_disestablish(tcp->tc_intrtab, cookie,
    475 	    "T2 irq");
    476 	if (alpha_shared_intr_isactive(tcp->tc_intrtab, irq) == 0) {
    477 		(*tcp->tc_enable_intr)(tcp, irq, 0);
    478 		alpha_shared_intr_set_dfltsharetype(tcp->tc_intrtab,
    479 		    irq, dec_2100_a500_intr_deftype[irq]);
    480 	}
    481 
    482 	splx(s);
    483 }
    484 
    485 /*****************************************************************************
    486  * EISA interrupt support.
    487  *****************************************************************************/
    488 
    489 int
    490 dec_2100_a500_eisa_intr_map(void *v, u_int eirq, eisa_intr_handle_t *ihp)
    491 {
    492 
    493 	if (eirq > 15) {
    494 		printf("dec_2100_a500_eisa_intr_map: bad EISA IRQ %d\n",
    495 		    eirq);
    496 		*ihp = -1;
    497 		return (1);
    498 	}
    499 
    500 	/*
    501 	 * EISA IRQ 13 is not connected.
    502 	 */
    503 	if (eirq == 13) {
    504 		printf("dec_2100_a500_eisa_intr_map: EISA IRQ 13 not "
    505 		    "connected\n");
    506 		*ihp = -1;
    507 		return (1);
    508 	}
    509 
    510 	/*
    511 	 * Don't map to a T2 IRQ here; we must do this when we hook the
    512 	 * interrupt up, since ISA interrupts aren't explicitly translated.
    513 	 */
    514 
    515 	*ihp = eirq;
    516 	return (0);
    517 }
    518 
    519 const char *
    520 dec_2100_a500_eisa_intr_string(void *v, int eirq)
    521 {
    522 	static char irqstr[32];
    523 
    524 	if (eirq > 15 || eirq == 13)
    525 		panic("dec_2100_a500_eisa_intr_string: bogus EISA IRQ 0x%x\n",
    526 		    eirq);
    527 
    528 	sprintf(irqstr, "eisa irq %d (T2 irq %d)", eirq,
    529 	    eirq + T2_IRQ_EISA_START);
    530 	return (irqstr);
    531 }
    532 
    533 const struct evcnt *
    534 dec_2100_a500_eisa_intr_evcnt(void *v, int eirq)
    535 {
    536 	struct ttwoga_config *tcp = v;
    537 
    538 	if (eirq > 15 || eirq == 13)
    539 		panic("dec_2100_a500_eisa_intr_evcnt: bogus EISA IRQ 0x%x\n",
    540 		    eirq);
    541 
    542 	return (alpha_shared_intr_evcnt(tcp->tc_intrtab,
    543 	    eirq + T2_IRQ_EISA_START));
    544 }
    545 
    546 void *
    547 dec_2100_a500_eisa_intr_establish(void *v, int eirq, int type, int level,
    548     int (*fn)(void *), void *arg)
    549 {
    550 	struct ttwoga_config *tcp = v;
    551 	void *cookie;
    552 	int irq;
    553 
    554 	if (eirq > 15 || type == IST_NONE)
    555 		panic("dec_2100_a500_eisa_intr_establish: bogus irq or type");
    556 
    557 	if (eirq == 13) {
    558 		printf("dec_2100_a500_eisa_intr_establish: EISA IRQ 13 not "
    559 		    "connected\n");
    560 		return (NULL);
    561 	}
    562 
    563 	irq = eirq + T2_IRQ_EISA_START;
    564 
    565 	/*
    566 	 * We can't change the trigger type of some interrupts.  Don't allow
    567 	 * level triggers to be hooked up to non-changeable edge triggers.
    568 	 */
    569 	if (dec_2100_a500_intr_deftype[irq] == IST_EDGE && type == IST_LEVEL) {
    570 		printf("dec_2100_a500_eisa_intr_establish: non-EDGE on EDGE\n");
    571 		return (NULL);
    572 	}
    573 
    574 	cookie = alpha_shared_intr_establish(tcp->tc_intrtab, irq,
    575 	    type, level, fn, arg, "T2 irq");
    576 
    577 	if (cookie != NULL &&
    578 	    alpha_shared_intr_isactive(tcp->tc_intrtab, irq)) {
    579 		(*tcp->tc_setlevel)(tcp, eirq,
    580 		    alpha_shared_intr_get_sharetype(tcp->tc_intrtab,
    581 						    irq) == IST_LEVEL);
    582 		(*tcp->tc_enable_intr)(tcp, irq, 1);
    583 	}
    584 
    585 	return (cookie);
    586 }
    587 
    588 void
    589 dec_2100_a500_eisa_intr_disestablish(void *v, void *cookie)
    590 {
    591 	struct ttwoga_config *tcp = v;
    592 	struct alpha_shared_intrhand *ih = cookie;
    593 	int s, irq = ih->ih_num;
    594 
    595 	s = splhigh();
    596 
    597 	/* Remove it from the link. */
    598 	alpha_shared_intr_disestablish(tcp->tc_intrtab, cookie,
    599 	    "T2 irq");
    600 
    601 	if (alpha_shared_intr_isactive(tcp->tc_intrtab, irq) == 0) {
    602 		(*tcp->tc_enable_intr)(tcp, irq, 0);
    603 		alpha_shared_intr_set_dfltsharetype(tcp->tc_intrtab,
    604 		    irq, dec_2100_a500_intr_deftype[irq]);
    605 	}
    606 
    607 	splx(s);
    608 }
    609 
    610 int
    611 dec_2100_a500_eisa_intr_alloc(void *v, int mask, int type, int *eirqp)
    612 {
    613 
    614 	/* XXX Not supported right now. */
    615 	return (1);
    616 }
    617 
    618 /*****************************************************************************
    619  * Interrupt support routines.
    620  *****************************************************************************/
    621 
    622 #define	ICIC_ADDR(tcp, addr)						\
    623 do {									\
    624 	alpha_mb();							\
    625 	T2GA((tcp), T2_AIR) = (addr);					\
    626 	alpha_mb();							\
    627 	alpha_mb();							\
    628 	(void) T2GA((tcp), T2_AIR);					\
    629 	alpha_mb();							\
    630 	alpha_mb();							\
    631 } while (0)
    632 
    633 #define	ICIC_READ(tcp)	T2GA((tcp), T2_DIR)
    634 #define	ICIC_WRITE(tcp, val)						\
    635 do {									\
    636 	alpha_mb();							\
    637 	T2GA((tcp), T2_DIR) = (val);					\
    638 	alpha_mb();							\
    639 	alpha_mb();							\
    640 } while (0)
    641 
    642 void
    643 dec_2100_a500_iointr(void *framep, u_long vec)
    644 {
    645 	struct ttwoga_config *tcp;
    646 	int irq, hose, vecbase, rv;
    647 
    648 	if (vec >= 0xc00) {
    649 		hose = 1;
    650 		vecbase = 0xc00;
    651 	} else if (vec >= 0x800) {
    652 		hose = 0;
    653 		vecbase = 0x800;
    654 	} else
    655 		panic("dec_2100_a500_iointr: weird vec 0x%lx\n", vec);
    656 
    657 	tcp = &ttwoga_configuration[hose];
    658 
    659 	if (vec >= vecbase + (SABLE_MAX_IRQ << 4))
    660 		panic("dec_2100_a500_iointr: vec 0x%lx out of range\n",
    661 		    vec);
    662 	irq = (vec - vecbase) >> 4;
    663 	rv = alpha_shared_intr_dispatch(tcp->tc_intrtab, irq);
    664 	(*tcp->tc_eoi)(tcp, irq);
    665 	if (rv == 0) {
    666 		alpha_shared_intr_stray(tcp->tc_intrtab, irq, "T2 irq");
    667 		if (ALPHA_SHARED_INTR_DISABLE(tcp->tc_intrtab, irq))
    668 			(*tcp->tc_enable_intr)(tcp, irq, 0);
    669 	}
    670 }
    671 
    672 void
    673 dec_2100_a500_pic_enable_intr(struct ttwoga_config *tcp, int irq, int onoff)
    674 {
    675 	int pic;
    676 	u_int8_t bit, mask;
    677 
    678 	pic = irq >> 3;
    679 	bit = 1 << (irq & 0x7);
    680 
    681 	mask = bus_space_read_1(pic_iot, pic_slave_ioh[pic], 1);
    682 	if (onoff)
    683 		mask &= ~bit;
    684 	else
    685 		mask |= bit;
    686 	bus_space_write_1(pic_iot, pic_slave_ioh[pic], 1, mask);
    687 }
    688 
    689 void
    690 dec_2100_a500_icic_enable_intr(struct ttwoga_config *tcp, int irq, int onoff)
    691 {
    692 	u_int64_t bit, mask;
    693 
    694 	bit = 1UL << irq;
    695 
    696 	ICIC_ADDR(tcp, 0x40);
    697 
    698 	mask = ICIC_READ(tcp);
    699 	if (onoff)
    700 		mask &= ~bit;
    701 	else
    702 		mask |= bit;
    703 	ICIC_WRITE(tcp, mask);
    704 }
    705 
    706 void
    707 dec_2100_a500_pic_init_intr(struct ttwoga_config *tcp)
    708 {
    709 	static const int picaddr[4] = {
    710 		0x536, 0x53a, 0x53c, 0x53e
    711 	};
    712 	int pic;
    713 
    714 	/*
    715 	 * Map the master PIC.
    716 	 */
    717 	if (bus_space_map(pic_iot, 0x534, 2, 0, &pic_master_ioh))
    718 		panic("dec_2100_a500_pic_init_intr: unable to map master PIC");
    719 
    720 	/*
    721 	 * Map all slave PICs and mask off the interrupts on them.
    722 	 */
    723 	for (pic = 0; pic < 4; pic++) {
    724 		if (bus_space_map(pic_iot, picaddr[pic], 2, 0,
    725 		    &pic_slave_ioh[pic]))
    726 			panic("dec_2100_a500_pic_init_intr: unable to map "
    727 			    "slave PIC %d", pic);
    728 		bus_space_write_1(pic_iot, pic_slave_ioh[pic], 1, 0xff);
    729 	}
    730 
    731 	/*
    732 	 * Map the ELCR registers.
    733 	 */
    734 	if (bus_space_map(pic_iot, 0x26, 2, 0, &pic_elcr_ioh))
    735 		panic("dec_2100_a500_pic_init_intr: unable to map ELCR "
    736 		    "registers");
    737 }
    738 
    739 void
    740 dec_2100_a500_icic_init_intr(struct ttwoga_config *tcp)
    741 {
    742 
    743 	ICIC_ADDR(tcp, 0x40);
    744 	ICIC_WRITE(tcp, 0xffffffffffffffffUL);
    745 }
    746 
    747 void
    748 dec_2100_a500_pic_setlevel(struct ttwoga_config *tcp, int eirq, int level)
    749 {
    750 	int elcr;
    751 	u_int8_t bit, mask;
    752 
    753 	switch (eirq) {		/* EISA IRQ */
    754 	case 3:
    755 	case 4:
    756 	case 5:
    757 	case 6:
    758 	case 7:
    759 		elcr = 0;
    760 		bit = 1 << (eirq - 3);
    761 		break;
    762 
    763 	case 9:
    764 	case 10:
    765 	case 11:
    766 		elcr = 0;
    767 		bit = 1 << (eirq - 4);
    768 		break;
    769 
    770 	case 12:
    771 		elcr = 1;
    772 		bit = 1 << (eirq - 12);
    773 		break;
    774 
    775 	case 14:
    776 	case 15:
    777 		elcr = 1;
    778 		bit = 1 << (eirq - 13);
    779 		break;
    780 
    781 	default:
    782 		panic("dec_2100_a500_pic_setlevel: bogus EISA IRQ %d", eirq);
    783 	}
    784 
    785 	mask = bus_space_read_1(pic_iot, pic_elcr_ioh, elcr);
    786 	if (level)
    787 		mask |= bit;
    788 	else
    789 		mask &= ~bit;
    790 	bus_space_write_1(pic_iot, pic_elcr_ioh, elcr, mask);
    791 }
    792 
    793 void
    794 dec_2100_a500_icic_setlevel(struct ttwoga_config *tcp, int eirq, int level)
    795 {
    796 	u_int64_t bit, mask;
    797 
    798 	switch (eirq) {
    799 	case 3:
    800 	case 4:
    801 	case 5:
    802 	case 6:
    803 	case 7:
    804 	case 9:
    805 	case 10:
    806 	case 11:
    807 	case 12:
    808 	case 14:
    809 	case 15:
    810 		bit = 1UL << (eirq + T2_IRQ_EISA_START);
    811 
    812 		ICIC_ADDR(tcp, 0x50);
    813 		mask = ICIC_READ(tcp);
    814 		if (level)
    815 			mask |= bit;
    816 		else
    817 			mask &= ~bit;
    818 		ICIC_WRITE(tcp, mask);
    819 		break;
    820 
    821 	default:
    822 		panic("dec_2100_a500_icic_setlevel: bogus EISA IRQ %d", eirq);
    823 	}
    824 }
    825 
    826 void
    827 dec_2100_a500_pic_eoi(struct ttwoga_config *tcp, int irq)
    828 {
    829 	int pic;
    830 
    831 	if (irq >= 0 && irq <= 7)
    832 		pic = 0;
    833 	else if (irq >= 8 && irq <= 15)
    834 		pic = 1;
    835 	else if (irq >= 16 && irq <= 23)
    836 		pic = 2;
    837 	else
    838 		pic = 3;
    839 
    840 	bus_space_write_1(pic_iot, pic_slave_ioh[pic], 0,
    841 	    0xe0 | (irq - (8 * pic)));
    842 	bus_space_write_1(pic_iot, pic_master_ioh, 0,
    843 	    0xe0 | pic_slave_to_master[pic]);
    844 }
    845 
    846 void
    847 dec_2100_a500_icic_eoi(struct ttwoga_config *tcp, int irq)
    848 {
    849 
    850 	T2GA(tcp, T2_VAR) = irq;
    851 	alpha_mb();
    852 	alpha_mb();	/* MAGIC */
    853 }
    854