Home | History | Annotate | Line # | Download | only in tc
tc_3000_500.c revision 1.25
      1 /* $NetBSD: tc_3000_500.c,v 1.25 2002/09/27 15:35:39 provos Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1994, 1995, 1996 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/cdefs.h>			/* RCS ID & Copyright macro defns */
     31 
     32 __KERNEL_RCSID(0, "$NetBSD: tc_3000_500.c,v 1.25 2002/09/27 15:35:39 provos Exp $");
     33 
     34 #include <sys/param.h>
     35 #include <sys/systm.h>
     36 #include <sys/device.h>
     37 #include <sys/malloc.h>
     38 
     39 #include <machine/autoconf.h>
     40 #include <machine/pte.h>
     41 #include <machine/rpb.h>
     42 
     43 #include <dev/tc/tcvar.h>
     44 #include <alpha/tc/tc_conf.h>
     45 #include <alpha/tc/tc_3000_500.h>
     46 
     47 #include "wsdisplay.h"
     48 #include "sfb.h"
     49 
     50 #if NSFB > 0
     51 extern int	sfb_cnattach __P((tc_addr_t));
     52 #endif
     53 
     54 void	tc_3000_500_intr_setup __P((void));
     55 void	tc_3000_500_intr_establish __P((struct device *, void *,
     56 	    tc_intrlevel_t, int (*)(void *), void *));
     57 void	tc_3000_500_intr_disestablish __P((struct device *, void *));
     58 void	tc_3000_500_iointr __P((void *, unsigned long));
     59 
     60 int	tc_3000_500_intrnull __P((void *));
     61 int	tc_3000_500_fb_cnattach __P((u_int64_t));
     62 
     63 #define C(x)	((void *)(u_long)x)
     64 #define	KV(x)	(ALPHA_PHYS_TO_K0SEG(x))
     65 
     66 struct tc_slotdesc tc_3000_500_slots[] = {
     67 	{ KV(0x100000000), C(TC_3000_500_DEV_OPT0), },	/* 0 - opt slot 0 */
     68 	{ KV(0x120000000), C(TC_3000_500_DEV_OPT1), },	/* 1 - opt slot 1 */
     69 	{ KV(0x140000000), C(TC_3000_500_DEV_OPT2), },	/* 2 - opt slot 2 */
     70 	{ KV(0x160000000), C(TC_3000_500_DEV_OPT3), },	/* 3 - opt slot 3 */
     71 	{ KV(0x180000000), C(TC_3000_500_DEV_OPT4), },	/* 4 - opt slot 4 */
     72 	{ KV(0x1a0000000), C(TC_3000_500_DEV_OPT5), },	/* 5 - opt slot 5 */
     73 	{ KV(0x1c0000000), C(TC_3000_500_DEV_BOGUS), },	/* 6 - TCDS ASIC */
     74 	{ KV(0x1e0000000), C(TC_3000_500_DEV_BOGUS), },	/* 7 - IOCTL ASIC */
     75 };
     76 int tc_3000_500_nslots =
     77     sizeof(tc_3000_500_slots) / sizeof(tc_3000_500_slots[0]);
     78 
     79 struct tc_builtin tc_3000_500_graphics_builtins[] = {
     80 	{ "FLAMG-IO",	7, 0x00000000, C(TC_3000_500_DEV_IOASIC),	},
     81 	{ "PMAGB-BA",	7, 0x02000000, C(TC_3000_500_DEV_CXTURBO),	},
     82 	{ "PMAZ-DS ",	6, 0x00000000, C(TC_3000_500_DEV_TCDS),		},
     83 };
     84 int tc_3000_500_graphics_nbuiltins = sizeof(tc_3000_500_graphics_builtins) /
     85     sizeof(tc_3000_500_graphics_builtins[0]);
     86 
     87 struct tc_builtin tc_3000_500_nographics_builtins[] = {
     88 	{ "FLAMG-IO",	7, 0x00000000, C(TC_3000_500_DEV_IOASIC),	},
     89 	{ "PMAZ-DS ",	6, 0x00000000, C(TC_3000_500_DEV_TCDS),		},
     90 };
     91 int tc_3000_500_nographics_nbuiltins = sizeof(tc_3000_500_nographics_builtins) /
     92     sizeof(tc_3000_500_nographics_builtins[0]);
     93 
     94 u_int32_t tc_3000_500_intrbits[TC_3000_500_NCOOKIES] = {
     95 	TC_3000_500_IR_OPT0,
     96 	TC_3000_500_IR_OPT1,
     97 	TC_3000_500_IR_OPT2,
     98 	TC_3000_500_IR_OPT3,
     99 	TC_3000_500_IR_OPT4,
    100 	TC_3000_500_IR_OPT5,
    101 	TC_3000_500_IR_TCDS,
    102 	TC_3000_500_IR_IOASIC,
    103 	TC_3000_500_IR_CXTURBO,
    104 };
    105 
    106 struct tcintr {
    107 	int	(*tci_func) __P((void *));
    108 	void	*tci_arg;
    109 	struct evcnt tci_evcnt;
    110 } tc_3000_500_intr[TC_3000_500_NCOOKIES];
    111 
    112 u_int32_t tc_3000_500_imask;	/* intrs we want to ignore; mirrors IMR. */
    113 
    114 void
    115 tc_3000_500_intr_setup()
    116 {
    117 	char *cp;
    118 	u_long i;
    119 
    120 	/*
    121 	 * Disable all slot interrupts.  Note that this cannot
    122 	 * actually disable CXTurbo, TCDS, and IOASIC interrupts.
    123 	 */
    124 	tc_3000_500_imask = *(volatile u_int32_t *)TC_3000_500_IMR_READ;
    125 	for (i = 0; i < TC_3000_500_NCOOKIES; i++)
    126 		tc_3000_500_imask |= tc_3000_500_intrbits[i];
    127 	*(volatile u_int32_t *)TC_3000_500_IMR_WRITE = tc_3000_500_imask;
    128 	tc_mb();
    129 
    130         /*
    131 	 * Set up interrupt handlers.
    132 	 */
    133         for (i = 0; i < TC_3000_500_NCOOKIES; i++) {
    134 		tc_3000_500_intr[i].tci_func = tc_3000_500_intrnull;
    135 		tc_3000_500_intr[i].tci_arg = (void *)i;
    136 
    137 		cp = malloc(12, M_DEVBUF, M_NOWAIT);
    138 		if (cp == NULL)
    139 			panic("tc_3000_500_intr_setup");
    140 		sprintf(cp, "slot %lu", i);
    141 		evcnt_attach_dynamic(&tc_3000_500_intr[i].tci_evcnt,
    142 		    EVCNT_TYPE_INTR, NULL, "tc", cp);
    143         }
    144 }
    145 
    146 const struct evcnt *
    147 tc_3000_500_intr_evcnt(tcadev, cookie)
    148 	struct device *tcadev;
    149 	void *cookie;
    150 {
    151 	u_long dev = (u_long)cookie;
    152 
    153 #ifdef DIAGNOSTIC
    154 	/* XXX bounds-check cookie. */
    155 #endif
    156 
    157 	return (&tc_3000_500_intr[dev].tci_evcnt);
    158 }
    159 
    160 void
    161 tc_3000_500_intr_establish(tcadev, cookie, level, func, arg)
    162 	struct device *tcadev;
    163 	void *cookie, *arg;
    164 	tc_intrlevel_t level;
    165 	int (*func) __P((void *));
    166 {
    167 	u_long dev = (u_long)cookie;
    168 
    169 #ifdef DIAGNOSTIC
    170 	/* XXX bounds-check cookie. */
    171 #endif
    172 
    173 	if (tc_3000_500_intr[dev].tci_func != tc_3000_500_intrnull)
    174 		panic("tc_3000_500_intr_establish: cookie %lu twice", dev);
    175 
    176 	tc_3000_500_intr[dev].tci_func = func;
    177 	tc_3000_500_intr[dev].tci_arg = arg;
    178 
    179 	tc_3000_500_imask &= ~tc_3000_500_intrbits[dev];
    180 	*(volatile u_int32_t *)TC_3000_500_IMR_WRITE = tc_3000_500_imask;
    181 	tc_mb();
    182 }
    183 
    184 void
    185 tc_3000_500_intr_disestablish(tcadev, cookie)
    186 	struct device *tcadev;
    187 	void *cookie;
    188 {
    189 	u_long dev = (u_long)cookie;
    190 
    191 #ifdef DIAGNOSTIC
    192 	/* XXX bounds-check cookie. */
    193 #endif
    194 
    195 	if (tc_3000_500_intr[dev].tci_func == tc_3000_500_intrnull)
    196 		panic("tc_3000_500_intr_disestablish: cookie %lu bad intr",
    197 		    dev);
    198 
    199 	tc_3000_500_imask |= tc_3000_500_intrbits[dev];
    200 	*(volatile u_int32_t *)TC_3000_500_IMR_WRITE = tc_3000_500_imask;
    201 	tc_mb();
    202 
    203 	tc_3000_500_intr[dev].tci_func = tc_3000_500_intrnull;
    204 	tc_3000_500_intr[dev].tci_arg = (void *)dev;
    205 }
    206 
    207 int
    208 tc_3000_500_intrnull(val)
    209 	void *val;
    210 {
    211 
    212 	panic("tc_3000_500_intrnull: uncaught TC intr for cookie %ld",
    213 	    (u_long)val);
    214 }
    215 
    216 void
    217 tc_3000_500_iointr(arg, vec)
    218         void *arg;
    219         unsigned long vec;
    220 {
    221         u_int32_t ir;
    222 	int ifound;
    223 
    224 #ifdef DIAGNOSTIC
    225 	int s;
    226 	if (vec != 0x800)
    227 		panic("INVALID ASSUMPTION: vec 0x%lx, not 0x800", vec);
    228 	s = splhigh();
    229 	if (s != ALPHA_PSL_IPL_IO)
    230 		panic("INVALID ASSUMPTION: IPL %d, not %d", s,
    231 		    ALPHA_PSL_IPL_IO);
    232 	splx(s);
    233 #endif
    234 
    235 	do {
    236 		tc_syncbus();
    237 		ir = *(volatile u_int32_t *)TC_3000_500_IR_CLEAR;
    238 
    239 		/* Ignore interrupts that we haven't enabled. */
    240 		ir &= ~(tc_3000_500_imask & 0x1ff);
    241 
    242 		ifound = 0;
    243 
    244 #define	INCRINTRCNT(slot)	tc_3000_500_intr[slot].tci_evcnt.ev_count++
    245 
    246 #define	CHECKINTR(slot)							\
    247 		if (ir & tc_3000_500_intrbits[slot]) {			\
    248 			ifound = 1;					\
    249 			INCRINTRCNT(slot);				\
    250 			(*tc_3000_500_intr[slot].tci_func)		\
    251 			    (tc_3000_500_intr[slot].tci_arg);		\
    252 		}
    253 		/* Do them in order of priority; highest slot # first. */
    254 		CHECKINTR(TC_3000_500_DEV_CXTURBO);
    255 		CHECKINTR(TC_3000_500_DEV_IOASIC);
    256 		CHECKINTR(TC_3000_500_DEV_TCDS);
    257 		CHECKINTR(TC_3000_500_DEV_OPT5);
    258 		CHECKINTR(TC_3000_500_DEV_OPT4);
    259 		CHECKINTR(TC_3000_500_DEV_OPT3);
    260 		CHECKINTR(TC_3000_500_DEV_OPT2);
    261 		CHECKINTR(TC_3000_500_DEV_OPT1);
    262 		CHECKINTR(TC_3000_500_DEV_OPT0);
    263 #undef CHECKINTR
    264 
    265 #ifdef DIAGNOSTIC
    266 #define PRINTINTR(msg, bits)						\
    267 	if (ir & bits)							\
    268 		printf(msg);
    269 		PRINTINTR("Second error occurred\n", TC_3000_500_IR_ERR2);
    270 		PRINTINTR("DMA buffer error\n", TC_3000_500_IR_DMABE);
    271 		PRINTINTR("DMA cross 2K boundary\n", TC_3000_500_IR_DMA2K);
    272 		PRINTINTR("TC reset in progress\n", TC_3000_500_IR_TCRESET);
    273 		PRINTINTR("TC parity error\n", TC_3000_500_IR_TCPAR);
    274 		PRINTINTR("DMA tag error\n", TC_3000_500_IR_DMATAG);
    275 		PRINTINTR("Single-bit error\n", TC_3000_500_IR_DMASBE);
    276 		PRINTINTR("Double-bit error\n", TC_3000_500_IR_DMADBE);
    277 		PRINTINTR("TC I/O timeout\n", TC_3000_500_IR_TCTIMEOUT);
    278 		PRINTINTR("DMA block too long\n", TC_3000_500_IR_DMABLOCK);
    279 		PRINTINTR("Invalid I/O address\n", TC_3000_500_IR_IOADDR);
    280 		PRINTINTR("DMA scatter/gather invalid\n", TC_3000_500_IR_DMASG);
    281 		PRINTINTR("Scatter/gather parity error\n",
    282 		    TC_3000_500_IR_SGPAR);
    283 #undef PRINTINTR
    284 #endif
    285 	} while (ifound);
    286 }
    287 
    288 #if NWSDISPLAY > 0
    289 /*
    290  * tc_3000_500_fb_cnattach --
    291  *	Attempt to map the CTB output device to a slot and attach the
    292  * framebuffer as the output side of the console.
    293  */
    294 int
    295 tc_3000_500_fb_cnattach(turbo_slot)
    296 	u_int64_t turbo_slot;
    297 {
    298 	u_int32_t output_slot;
    299 
    300 	output_slot = turbo_slot & 0xffffffff;
    301 
    302 	if (output_slot >= tc_3000_500_nslots) {
    303 		return EINVAL;
    304 	}
    305 
    306 	if (hwrpb->rpb_variation & SV_GRAPHICS) {
    307 		if (output_slot == 0) {
    308 #if NSFB > 0
    309 			sfb_cnattach(KV(0x1e0000000) + 0x02000000);
    310 			return 0;
    311 #else
    312 			return ENXIO;
    313 #endif
    314 		}
    315 	} else {
    316 		/*
    317 		 * Slots 0-2 in the tc_3000_500_slots array are only
    318 		 * on the 500 models that also have the CXTurbo
    319 		 * (500/800/900) and a total of 6 TC slots.  For the
    320 		 * 400/600/700, slots 0-2 are in table locations 3-5, so
    321 		 * offset the CTB slot by 3 to get the address in our table.
    322 		 */
    323 		output_slot += 3;
    324 	}
    325 	return tc_fb_cnattach(tc_3000_500_slots[output_slot-1].tcs_addr);
    326 }
    327 #endif /* NWSDISPLAY */
    328 
    329 #if 0
    330 /*
    331  * tc_3000_500_ioslot --
    332  *	Set the PBS bits for devices on the TC.
    333  */
    334 void
    335 tc_3000_500_ioslot(slot, flags, set)
    336 	u_int32_t slot, flags;
    337 	int set;
    338 {
    339 	volatile u_int32_t *iosp;
    340 	u_int32_t ios;
    341 	int s;
    342 
    343 	iosp = (volatile u_int32_t *)TC_3000_500_IOSLOT;
    344 	ios = *iosp;
    345 	flags <<= (slot * 3);
    346 	if (set)
    347 		ios |= flags;
    348 	else
    349 		ios &= ~flags;
    350 	s = splhigh();
    351 	*iosp = ios;
    352 	tc_mb();
    353 	splx(s);
    354 }
    355 #endif
    356