Home | History | Annotate | Line # | Download | only in tc
tc_3000_300.c revision 1.2
      1  1.1  cgd /*	$NetBSD: tc_3000_300.c,v 1.2 1995/03/24 14:59:37 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.1  cgd #include <alpha/tc/tc.h>
     37  1.1  cgd #include <alpha/tc/tc_3000_300.h>
     38  1.1  cgd 
     39  1.1  cgd /* XXX ESTABLISH, DISESTABLISH */
     40  1.1  cgd void	tc_3000_300_intr_setup __P((void));
     41  1.1  cgd void	tc_3000_300_intr_establish
     42  1.1  cgd 	    __P((struct confargs *, intr_handler_t, void *));
     43  1.1  cgd void	tc_3000_300_intr_disestablish __P((struct confargs *));
     44  1.1  cgd void	tc_3000_300_iointr __P((void *, int));
     45  1.1  cgd int	tc_3000_300_getdev __P((struct confargs *));
     46  1.1  cgd 
     47  1.1  cgd #define	KV(x)	((caddr_t)phystok0seg(x))
     48  1.1  cgd #define	TC_3000_300_NSLOTS	5
     49  1.1  cgd #define	TC_3000_300_MAXDEVS	5
     50  1.1  cgd 
     51  1.1  cgd static struct tc_slot_desc dec_3000_300_slots[TC_3000_300_NSLOTS] = {
     52  1.1  cgd 	{ KV(0x100000000), },		/* slot 0 - TC option slot 0 */
     53  1.1  cgd 	{ KV(0x120000000), },		/* slot 1 - TC option slot 1 */
     54  1.1  cgd 	{ KV(0x180000000), },		/* slot 2 - TCDS ASIC on cpu board */
     55  1.1  cgd 	{ KV(0x1a0000000), },		/* slot 3 - IOCTL ASIC on cpu board */
     56  1.1  cgd 	{ KV(0x1c0000000), },		/* slot 4 - CXTurbo on cpu board */
     57  1.1  cgd };
     58  1.1  cgd 
     59  1.1  cgd static struct confargs dec_3000_300_devs[TC_3000_300_MAXDEVS] = {
     60  1.1  cgd 	{ "PMAGB-BA",	4, 0x02000000,	},
     61  1.1  cgd 	{ "IOCTL   ",	3, 0x00000000,	},
     62  1.1  cgd 	{ "PMAZ-DS ",	2, 0x00000000,	},
     63  1.1  cgd 	{ NULL,		1, 0x0,		},
     64  1.1  cgd 	{ NULL,		0, 0x0,		},
     65  1.1  cgd };
     66  1.1  cgd 
     67  1.1  cgd /* Indices into the struct confargs array. */
     68  1.1  cgd #define	TC_3000_300_DEV_CXTURBO	0
     69  1.1  cgd #define	TC_3000_300_DEV_IOCTL	1
     70  1.1  cgd #define	TC_3000_300_DEV_TCDS	2
     71  1.1  cgd #define	TC_3000_300_DEV_OPT1	3
     72  1.1  cgd #define	TC_3000_300_DEV_OPT0	4
     73  1.1  cgd 
     74  1.1  cgd struct tc_cpu_desc dec_3000_300_cpu = {
     75  1.1  cgd 	dec_3000_300_slots, TC_3000_300_NSLOTS,
     76  1.1  cgd 	dec_3000_300_devs, TC_3000_300_MAXDEVS,
     77  1.1  cgd 	tc_3000_300_intr_setup,
     78  1.1  cgd 	tc_3000_300_intr_establish,
     79  1.1  cgd 	tc_3000_300_intr_disestablish,
     80  1.1  cgd 	tc_3000_300_iointr,
     81  1.1  cgd };
     82  1.1  cgd 
     83  1.1  cgd intr_handler_t	tc_3000_300_intrhand[TC_3000_300_MAXDEVS];
     84  1.1  cgd void		*tc_3000_300_intrval[TC_3000_300_MAXDEVS];
     85  1.1  cgd 
     86  1.1  cgd void
     87  1.1  cgd tc_3000_300_intr_setup()
     88  1.1  cgd {
     89  1.1  cgd 	int i;
     90  1.1  cgd 
     91  1.2  cgd 	/* Set up interrupt handlers. */
     92  1.2  cgd 	for (i = 0; i < TC_3000_300_MAXDEVS; i++) {
     93  1.2  cgd 		tc_3000_300_intrhand[i] = tc_intrnull;
     94  1.2  cgd 		tc_3000_300_intrval[i] = (void *)(long)i;
     95  1.2  cgd 	}
     96  1.1  cgd }
     97  1.1  cgd 
     98  1.1  cgd void
     99  1.1  cgd tc_3000_300_intr_establish(ca, handler, val)
    100  1.1  cgd 	struct confargs *ca;
    101  1.1  cgd 	int (*handler) __P((void *));
    102  1.1  cgd 	void *val;
    103  1.1  cgd {
    104  1.1  cgd 	int dev = tc_3000_300_getdev(ca);
    105  1.1  cgd 
    106  1.1  cgd #ifdef DIAGNOSTIC
    107  1.1  cgd 	if (dev == -1)
    108  1.1  cgd 		panic("tc_3000_300_intr_establish: dev == -1");
    109  1.1  cgd #endif
    110  1.1  cgd 
    111  1.1  cgd 	if (tc_3000_300_intrhand[dev] != tc_intrnull)
    112  1.1  cgd 		panic("tc_3000_300_intr_establish: dev %d twice", dev);
    113  1.1  cgd 
    114  1.1  cgd 	tc_3000_300_intrhand[dev] = handler;
    115  1.1  cgd 	tc_3000_300_intrval[dev] = val;
    116  1.1  cgd 
    117  1.1  cgd 	/* XXX ENABLE INTERRUPT MASK FOR DEV */
    118  1.1  cgd }
    119  1.1  cgd 
    120  1.1  cgd void
    121  1.1  cgd tc_3000_300_intr_disestablish(ca)
    122  1.1  cgd 	struct confargs *ca;
    123  1.1  cgd {
    124  1.1  cgd 	int dev = tc_3000_300_getdev(ca);
    125  1.1  cgd 
    126  1.1  cgd #ifdef DIAGNOSTIC
    127  1.1  cgd 	if (dev == -1)
    128  1.1  cgd 		panic("tc_3000_300_intr_disestablish: somebody goofed");
    129  1.1  cgd #endif
    130  1.1  cgd 
    131  1.1  cgd 	if (tc_3000_300_intrhand[dev] == tc_intrnull)
    132  1.1  cgd 		panic("tc_3000_300_intr_disestablish: dev %d missing intr",
    133  1.1  cgd 		    dev);
    134  1.1  cgd 
    135  1.1  cgd 	tc_3000_300_intrhand[dev] = tc_intrnull;
    136  1.1  cgd 	tc_3000_300_intrval[dev] = (void *)(long)dev;
    137  1.1  cgd 
    138  1.1  cgd 	/* XXX DISABLE INTERRUPT MASK FOR DEV */
    139  1.1  cgd }
    140  1.1  cgd 
    141  1.1  cgd void
    142  1.1  cgd tc_3000_300_iointr(framep, vec)
    143  1.2  cgd 	void *framep;
    144  1.2  cgd 	int vec;
    145  1.1  cgd {
    146  1.2  cgd 	u_int32_t ir;
    147  1.1  cgd 	int ifound;
    148  1.1  cgd 
    149  1.1  cgd #ifdef DIAGNOSTIC
    150  1.1  cgd 	int s;
    151  1.1  cgd 	if (vec != 0x800)
    152  1.1  cgd 		panic("INVALID ASSUMPTION: vec %x, not 0x800", vec);
    153  1.1  cgd 	s = splhigh();
    154  1.1  cgd 	if (s != PSL_IPL_IO)
    155  1.1  cgd 		panic("INVALID ASSUMPTION: IPL %d, not %d", s, PSL_IPL_IO);
    156  1.1  cgd 	splx(s);
    157  1.1  cgd #endif
    158  1.1  cgd 
    159  1.1  cgd 	do {
    160  1.2  cgd 		MAGIC_READ;
    161  1.2  cgd 		MB();
    162  1.2  cgd 
    163  1.2  cgd 		/* find out what interrupts/errors occurred */
    164  1.2  cgd 		ir = *(volatile u_int32_t *)TC_3000_300_IR;
    165  1.1  cgd 		MB();
    166  1.2  cgd 
    167  1.2  cgd 		/* clear the interrupts/errors we found. */
    168  1.2  cgd 		*(volatile u_int32_t *)TC_3000_300_IR = ir;
    169  1.1  cgd 		MB();
    170  1.1  cgd 
    171  1.1  cgd 		ifound = 0;
    172  1.1  cgd #define	CHECKINTR(slot, bits)						\
    173  1.1  cgd 		if (ir & bits) {					\
    174  1.1  cgd 			ifound = 1;					\
    175  1.1  cgd 			(*tc_3000_300_intrhand[slot])			\
    176  1.1  cgd 			    (tc_3000_300_intrval[slot]);		\
    177  1.1  cgd 		}
    178  1.1  cgd 		/* Do them in order of priority; highest slot # first. */
    179  1.1  cgd 		CHECKINTR(TC_3000_300_DEV_CXTURBO, TC_3000_300_IR_CXTURBO);
    180  1.1  cgd 		CHECKINTR(TC_3000_300_DEV_IOCTL, TC_3000_300_IR_IOCTL);
    181  1.1  cgd 		CHECKINTR(TC_3000_300_DEV_TCDS, TC_3000_300_IR_TCDS);
    182  1.1  cgd #if 0
    183  1.1  cgd 		CHECKINTR(TC_3000_300_DEV_OPT1, TC_3000_300_IR_OPT1);
    184  1.1  cgd 		CHECKINTR(TC_3000_300_DEV_OPT0, TC_3000_300_IR_OPT0);
    185  1.1  cgd #else
    186  1.1  cgd 		/* XXX XXX XXX CHECK OPTION SLOT INTERRUPTS!!! */
    187  1.2  cgd 		/* XXX XXX XXX THEIR BITS LIVE IN ANOTHER REG. */
    188  1.1  cgd #endif
    189  1.1  cgd #undef CHECKINTR
    190  1.1  cgd 
    191  1.1  cgd 
    192  1.1  cgd #ifdef DIAGNOSTIC
    193  1.1  cgd #define PRINTINTR(msg, bits)						\
    194  1.1  cgd 	if (ir & bits)							\
    195  1.1  cgd 		printf(msg);
    196  1.1  cgd 		PRINTINTR("BCache tag parity error\n",
    197  1.1  cgd 		    TC_3000_300_IR_BCTAGPARITY);
    198  1.1  cgd 		PRINTINTR("TC overrun error\n", TC_3000_300_IR_TCOVERRUN);
    199  1.1  cgd 		PRINTINTR("TC I/O timeout\n", TC_3000_300_IR_TCTIMEOUT);
    200  1.1  cgd 		PRINTINTR("Bcache parity error\n",
    201  1.1  cgd 		    TC_3000_300_IR_BCACHEPARITY);
    202  1.1  cgd 		PRINTINTR("Memory parity error\n", TC_3000_300_IR_MEMPARITY);
    203  1.1  cgd #undef PRINTINTR
    204  1.1  cgd #endif
    205  1.1  cgd 	} while (ifound);
    206  1.1  cgd }
    207  1.1  cgd 
    208  1.1  cgd int
    209  1.1  cgd tc_3000_300_getdev(ca)
    210  1.1  cgd 	struct confargs *ca;
    211  1.1  cgd {
    212  1.1  cgd 	int i;
    213  1.1  cgd 
    214  1.1  cgd 	for (i = 0; i < TC_3000_300_MAXDEVS; i++)
    215  1.1  cgd 		if (ca->ca_slot == dec_3000_300_devs[i].ca_slot &&
    216  1.1  cgd 		    ca->ca_offset == dec_3000_300_devs[i].ca_offset &&
    217  1.1  cgd 		    !strncmp(ca->ca_name, dec_3000_300_devs[i].ca_name))
    218  1.1  cgd 			return (i);
    219  1.1  cgd 
    220  1.1  cgd 	return (-1);
    221  1.1  cgd }
    222