Home | History | Annotate | Line # | Download | only in tc
tc_3000_500.c revision 1.4
      1 /*	$NetBSD: tc_3000_500.c,v 1.4 1996/05/02 21:56:46 cgd Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1994, 1995 Carnegie-Mellon University.
      5  * All rights reserved.
      6  *
      7  * Author: Chris G. Demetriou
      8  *
      9  * Permission to use, copy, modify and distribute this software and
     10  * its documentation is hereby granted, provided that both the copyright
     11  * notice and this permission notice appear in all copies of the
     12  * software, derivative works or modified versions, and any portions
     13  * thereof, and that both notices appear in supporting documentation.
     14  *
     15  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18  *
     19  * Carnegie Mellon requests users of this software to return to
     20  *
     21  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22  *  School of Computer Science
     23  *  Carnegie Mellon University
     24  *  Pittsburgh PA 15213-3890
     25  *
     26  * any improvements or extensions that they make and grant Carnegie the
     27  * rights to redistribute these changes.
     28  */
     29 
     30 #include <sys/param.h>
     31 #include <sys/device.h>
     32 
     33 #include <machine/autoconf.h>
     34 #include <machine/pte.h>
     35 
     36 #include <dev/tc/tcvar.h>
     37 #include <alpha/tc/tc_conf.h>
     38 #include <alpha/tc/tc_3000_500.h>
     39 
     40 void	tc_3000_500_intr_setup __P((void));
     41 void	tc_3000_500_intr_establish __P((struct device *, void *,
     42 	    tc_intrlevel_t, int (*)(void *), void *));
     43 void	tc_3000_500_intr_disestablish __P((struct device *, void *));
     44 void	tc_3000_500_iointr __P((void *, int));
     45 
     46 int	tc_3000_500_intrnull __P((void *));
     47 
     48 #define C(x)	((void *)(u_long)x)
     49 #define	KV(x)	(phystok0seg(x))
     50 
     51 struct tc_slotdesc tc_3000_500_slots[] = {
     52 	{ KV(0x100000000), C(TC_3000_500_DEV_OPT0), },	/* 0 - opt slot 0 */
     53 	{ KV(0x120000000), C(TC_3000_500_DEV_OPT1), },	/* 1 - opt slot 1 */
     54 	{ KV(0x140000000), C(TC_3000_500_DEV_OPT2), },	/* 2 - opt slot 2 */
     55 	{ KV(0x160000000), C(TC_3000_500_DEV_OPT3), },	/* 3 - opt slot 3 */
     56 	{ KV(0x180000000), C(TC_3000_500_DEV_OPT4), },	/* 4 - opt slot 4 */
     57 	{ KV(0x1a0000000), C(TC_3000_500_DEV_OPT5), },	/* 5 - opt slot 5 */
     58 	{ KV(0x1c0000000), C(TC_3000_500_DEV_BOGUS), },	/* 6 - TCDS ASIC */
     59 	{ KV(0x1e0000000), C(TC_3000_500_DEV_BOGUS), },	/* 7 - IOCTL ASIC */
     60 };
     61 int tc_3000_500_nslots =
     62     sizeof(tc_3000_500_slots) / sizeof(tc_3000_500_slots[0]);
     63 
     64 struct tc_builtin tc_3000_500_builtins[] = {
     65 	{ "FLAMG-IO",	7, 0x00000000, C(TC_3000_500_DEV_IOASIC),	},
     66 	{ "PMAGB-BA",	7, 0x02000000, C(TC_3000_500_DEV_CXTURBO),	},
     67 	{ "PMAZ-DS ",	6, 0x00000000, C(TC_3000_500_DEV_TCDS),		},
     68 };
     69 int tc_3000_500_nbuiltins =
     70     sizeof(tc_3000_500_builtins) / sizeof(tc_3000_500_builtins[0]);
     71 
     72 u_int32_t tc_3000_500_intrbits[TC_3000_500_NCOOKIES] = {
     73 	TC_3000_500_IR_OPT0,
     74 	TC_3000_500_IR_OPT1,
     75 	TC_3000_500_IR_OPT2,
     76 	TC_3000_500_IR_OPT3,
     77 	TC_3000_500_IR_OPT4,
     78 	TC_3000_500_IR_OPT5,
     79 	TC_3000_500_IR_TCDS,
     80 	TC_3000_500_IR_IOASIC,
     81 	TC_3000_500_IR_CXTURBO,
     82 };
     83 
     84 struct tcintr {
     85 	int	(*tci_func) __P((void *));
     86 	void	*tci_arg;
     87 } tc_3000_500_intr[TC_3000_500_NCOOKIES];
     88 
     89 void
     90 tc_3000_500_intr_setup()
     91 {
     92 	u_long i;
     93 	u_int32_t imr;
     94 
     95 	/*
     96 	 * Disable all slot interrupts.  Note that this cannot
     97 	 * actually disable CXTurbo, TCDS, and IOASIC interrupts.
     98 	 */
     99 	imr = *(volatile u_int32_t *)TC_3000_500_IMR_READ;
    100 	for (i = 0; i < TC_3000_500_NCOOKIES; i++)
    101 		imr |= tc_3000_500_intrbits[i];
    102 	*(volatile u_int32_t *)TC_3000_500_IMR_WRITE = imr;
    103 	tc_mb();
    104 
    105         /*
    106 	 * Set up interrupt handlers.
    107 	 */
    108         for (i = 0; i < TC_3000_500_NCOOKIES; i++) {
    109 		tc_3000_500_intr[i].tci_func = tc_3000_500_intrnull;
    110 		tc_3000_500_intr[i].tci_arg = (void *)i;
    111         }
    112 }
    113 
    114 void
    115 tc_3000_500_intr_establish(tcadev, cookie, level, func, arg)
    116 	struct device *tcadev;
    117 	void *cookie, *arg;
    118 	tc_intrlevel_t level;
    119 	int (*func) __P((void *));
    120 {
    121 	u_long dev = (u_long)cookie;
    122 	u_int32_t imr;
    123 
    124 #ifdef DIAGNOSTIC
    125 	/* XXX bounds-check cookie. */
    126 #endif
    127 
    128 	if (tc_3000_500_intr[dev].tci_func != tc_3000_500_intrnull)
    129 		panic("tc_3000_500_intr_establish: cookie %d twice", dev);
    130 
    131 	tc_3000_500_intr[dev].tci_func = func;
    132 	tc_3000_500_intr[dev].tci_arg = arg;
    133 
    134 	imr = *(volatile u_int32_t *)TC_3000_500_IMR_READ;
    135 	imr &= ~tc_3000_500_intrbits[dev];
    136 	*(volatile u_int32_t *)TC_3000_500_IMR_WRITE = imr;
    137 	tc_mb();
    138 }
    139 
    140 void
    141 tc_3000_500_intr_disestablish(tcadev, cookie)
    142 	struct device *tcadev;
    143 	void *cookie;
    144 {
    145 	u_long dev = (u_long)cookie;
    146 	u_int32_t imr;
    147 
    148 #ifdef DIAGNOSTIC
    149 	/* XXX bounds-check cookie. */
    150 #endif
    151 
    152 	if (tc_3000_500_intr[dev].tci_func == tc_3000_500_intrnull)
    153 		panic("tc_3000_500_intr_disestablish: cookie %d bad intr",
    154 		    dev);
    155 
    156 	imr = *(volatile u_int32_t *)TC_3000_500_IMR_READ;
    157 	imr |= tc_3000_500_intrbits[dev];
    158 	*(volatile u_int32_t *)TC_3000_500_IMR_WRITE = imr;
    159 	tc_mb();
    160 
    161 	tc_3000_500_intr[dev].tci_func = tc_3000_500_intrnull;
    162 	tc_3000_500_intr[dev].tci_arg = (void *)dev;
    163 }
    164 
    165 int
    166 tc_3000_500_intrnull(val)
    167 	void *val;
    168 {
    169 
    170 	panic("tc_3000_500_intrnull: uncaught TC intr for cookie %ld\n",
    171 	    (u_long)val);
    172 }
    173 
    174 void
    175 tc_3000_500_iointr(framep, vec)
    176         void *framep;
    177         int vec;
    178 {
    179         u_int32_t ir, imr, tmp;
    180 	int ifound;
    181 
    182 #ifdef DIAGNOSTIC
    183 	int s;
    184 	if (vec != 0x800)
    185 		panic("INVALID ASSUMPTION: vec %x, not 0x800", vec);
    186 	s = splhigh();
    187 	if (s != PSL_IPL_IO)
    188 		panic("INVALID ASSUMPTION: IPL %d, not %d", s, PSL_IPL_IO);
    189 	splx(s);
    190 #endif
    191 
    192 	do {
    193 		tc_syncbus();
    194 		ir = *(volatile u_int32_t *)TC_3000_500_IR;
    195 		imr = *(volatile u_int32_t *)TC_3000_500_IMR_READ;
    196 		tc_mb();
    197 		tmp = *(volatile u_int32_t *)TC_3000_500_IR_CLEAR;
    198 
    199 		/* Ignore interrupts that we haven't enabled. */
    200 		ir &= ~(imr & 0x1ff);
    201 
    202 		ifound = 0;
    203 #define	CHECKINTR(slot)							\
    204 		if (ir & tc_3000_500_intrbits[slot]) {			\
    205 			ifound = 1;					\
    206 			(*tc_3000_500_intr[slot].tci_func)		\
    207 			    (tc_3000_500_intr[slot].tci_arg);		\
    208 		}
    209 		/* Do them in order of priority; highest slot # first. */
    210 		CHECKINTR(TC_3000_500_DEV_CXTURBO);
    211 		CHECKINTR(TC_3000_500_DEV_IOASIC);
    212 		CHECKINTR(TC_3000_500_DEV_TCDS);
    213 		CHECKINTR(TC_3000_500_DEV_OPT5);
    214 		CHECKINTR(TC_3000_500_DEV_OPT4);
    215 		CHECKINTR(TC_3000_500_DEV_OPT3);
    216 		CHECKINTR(TC_3000_500_DEV_OPT2);
    217 		CHECKINTR(TC_3000_500_DEV_OPT1);
    218 		CHECKINTR(TC_3000_500_DEV_OPT0);
    219 #undef CHECKINTR
    220 
    221 #ifdef DIAGNOSTIC
    222 #define PRINTINTR(msg, bits)						\
    223 	if (ir & bits)							\
    224 		printf(msg);
    225 		PRINTINTR("Second error occurred\n", TC_3000_500_IR_ERR2);
    226 		PRINTINTR("DMA buffer error\n", TC_3000_500_IR_DMABE);
    227 		PRINTINTR("DMA cross 2K boundary\n", TC_3000_500_IR_DMA2K);
    228 		PRINTINTR("TC reset in progress\n", TC_3000_500_IR_TCRESET);
    229 		PRINTINTR("TC parity error\n", TC_3000_500_IR_TCPAR);
    230 		PRINTINTR("DMA tag error\n", TC_3000_500_IR_DMATAG);
    231 		PRINTINTR("Single-bit error\n", TC_3000_500_IR_DMASBE);
    232 		PRINTINTR("Double-bit error\n", TC_3000_500_IR_DMADBE);
    233 		PRINTINTR("TC I/O timeout\n", TC_3000_500_IR_TCTIMEOUT);
    234 		PRINTINTR("DMA block too long\n", TC_3000_500_IR_DMABLOCK);
    235 		PRINTINTR("Invalid I/O address\n", TC_3000_500_IR_IOADDR);
    236 		PRINTINTR("DMA scatter/gather invalid\n", TC_3000_500_IR_DMASG);
    237 		PRINTINTR("Scatter/gather parity error\n",
    238 		    TC_3000_500_IR_SGPAR);
    239 #undef PRINTINTR
    240 #endif
    241 	} while (ifound);
    242 }
    243 
    244 /*
    245  * tc_3000_500_ioslot --
    246  *	Set the PBS bits for devices on the TC.
    247  */
    248 void
    249 tc_3000_500_ioslot(slot, flags, set)
    250 	u_int32_t slot, flags;
    251 	int set;
    252 {
    253 	volatile u_int32_t *iosp;
    254 	u_int32_t ios;
    255 	int s;
    256 
    257 	iosp = (volatile u_int32_t *)TC_3000_500_IOSLOT;
    258 	ios = *iosp;
    259 	flags <<= (slot * 3);
    260 	if (set)
    261 		ios |= flags;
    262 	else
    263 		ios &= ~flags;
    264 	s = splhigh();
    265 	*iosp = ios;
    266 	tc_mb();
    267 	splx(s);
    268 }
    269