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