Home | History | Annotate | Line # | Download | only in tc
tc_3000_300.c revision 1.38
      1  1.38   thorpej /* $NetBSD: tc_3000_300.c,v 1.38 2020/11/18 02:04:30 thorpej Exp $ */
      2   1.1       cgd 
      3   1.1       cgd /*
      4   1.6       cgd  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
      5   1.1       cgd  * All rights reserved.
      6   1.1       cgd  *
      7   1.1       cgd  * Author: Chris G. Demetriou
      8  1.32      matt  *
      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.32      matt  *
     15  1.32      matt  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16  1.32      matt  * 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.32      matt  *
     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.13       cgd 
     30  1.14       cgd #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     31  1.14       cgd 
     32  1.38   thorpej __KERNEL_RCSID(0, "$NetBSD: tc_3000_300.c,v 1.38 2020/11/18 02:04:30 thorpej Exp $");
     33   1.1       cgd 
     34   1.1       cgd #include <sys/param.h>
     35   1.9       cgd #include <sys/systm.h>
     36   1.1       cgd #include <sys/device.h>
     37  1.38   thorpej #include <sys/kmem.h>
     38  1.37   thorpej #include <sys/cpu.h>
     39   1.1       cgd 
     40   1.1       cgd #include <machine/autoconf.h>
     41   1.1       cgd #include <machine/pte.h>
     42   1.1       cgd 
     43   1.4       cgd #include <dev/tc/tcvar.h>
     44  1.21  nisimura #include <dev/tc/ioasicreg.h>
     45   1.4       cgd #include <alpha/tc/tc_conf.h>
     46   1.1       cgd #include <alpha/tc/tc_3000_300.h>
     47  1.17    briggs 
     48  1.19  drochner #include "wsdisplay.h"
     49  1.17    briggs #include "sfb.h"
     50  1.17    briggs 
     51  1.17    briggs #if NSFB > 0
     52  1.28       dsl extern int	sfb_cnattach(tc_addr_t);
     53  1.17    briggs #endif
     54   1.1       cgd 
     55  1.28       dsl int	tc_3000_300_intrnull(void *);
     56   1.4       cgd 
     57   1.4       cgd #define	C(x)	((void *)(u_long)x)
     58   1.9       cgd #define	KV(x)	(ALPHA_PHYS_TO_K0SEG(x))
     59   1.1       cgd 
     60   1.5       cgd /*
     61   1.5       cgd  * We have to read and modify the IOASIC registers directly, because
     62   1.5       cgd  * the TC option slot interrupt request and mask bits are stored there,
     63   1.5       cgd  * and the ioasic code isn't initted when we need to frob some interrupt
     64   1.5       cgd  * bits.
     65   1.5       cgd  */
     66   1.5       cgd #define	DEC_3000_300_IOASIC_ADDR	KV(0x1a0000000)
     67   1.5       cgd 
     68   1.4       cgd struct tc_slotdesc tc_3000_300_slots[] = {
     69   1.4       cgd 	{ KV(0x100000000), C(TC_3000_300_DEV_OPT0), },	/* 0 - opt slot 0 */
     70   1.4       cgd 	{ KV(0x120000000), C(TC_3000_300_DEV_OPT1), },	/* 1 - opt slot 1 */
     71  1.22  nisimura 	{ KV(0x140000000), C(TC_3000_300_DEV_BOGUS), }, /* 2 - unused */
     72  1.22  nisimura 	{ KV(0x160000000), C(TC_3000_300_DEV_BOGUS), }, /* 3 - unused */
     73  1.22  nisimura 	{ KV(0x180000000), C(TC_3000_300_DEV_BOGUS), },	/* 4 - TCDS ASIC */
     74  1.22  nisimura 	{ KV(0x1a0000000), C(TC_3000_300_DEV_BOGUS), }, /* 5 - IOCTL ASIC */
     75  1.22  nisimura 	{ KV(0x1c0000000), C(TC_3000_300_DEV_BOGUS), }, /* 6 - CXTurbo */
     76   1.1       cgd };
     77   1.4       cgd int tc_3000_300_nslots =
     78   1.4       cgd     sizeof(tc_3000_300_slots) / sizeof(tc_3000_300_slots[0]);
     79   1.1       cgd 
     80   1.4       cgd struct tc_builtin tc_3000_300_builtins[] = {
     81  1.22  nisimura 	{ "PMAGB-BA",	6, 0x02000000, C(TC_3000_300_DEV_CXTURBO),	},
     82  1.22  nisimura 	{ "FLAMG-IO",	5, 0x00000000, C(TC_3000_300_DEV_IOASIC),	},
     83  1.22  nisimura 	{ "PMAZ-DS ",	4, 0x00000000, C(TC_3000_300_DEV_TCDS),		},
     84   1.1       cgd };
     85   1.4       cgd int tc_3000_300_nbuiltins =
     86   1.4       cgd     sizeof(tc_3000_300_builtins) / sizeof(tc_3000_300_builtins[0]);
     87   1.1       cgd 
     88   1.4       cgd struct tcintr {
     89  1.28       dsl 	int	(*tci_func)(void *);
     90   1.4       cgd 	void	*tci_arg;
     91  1.25   thorpej 	struct evcnt tci_evcnt;
     92   1.4       cgd } tc_3000_300_intr[TC_3000_300_NCOOKIES];
     93   1.4       cgd 
     94   1.1       cgd void
     95  1.32      matt tc_3000_300_intr_setup(void)
     96   1.1       cgd {
     97  1.32      matt 	volatile uint32_t *imskp;
     98  1.25   thorpej 	char *cp;
     99   1.4       cgd 	u_long i;
    100   1.1       cgd 
    101   1.4       cgd 	/*
    102   1.5       cgd 	 * Disable all interrupts that we can (can't disable builtins).
    103   1.4       cgd 	 */
    104  1.32      matt 	imskp = (volatile uint32_t *)(DEC_3000_300_IOASIC_ADDR + IOASIC_IMSK);
    105   1.5       cgd 	*imskp &= ~(IOASIC_INTR_300_OPT0 | IOASIC_INTR_300_OPT1);
    106   1.4       cgd 
    107   1.4       cgd 	/*
    108   1.4       cgd 	 * Set up interrupt handlers.
    109   1.4       cgd 	 */
    110   1.4       cgd 	for (i = 0; i < TC_3000_300_NCOOKIES; i++) {
    111  1.32      matt 	        tc_3000_300_intr[i].tci_func = tc_3000_300_intrnull;
    112  1.32      matt 	        tc_3000_300_intr[i].tci_arg = (void *)i;
    113  1.25   thorpej 
    114  1.38   thorpej 		cp = kmem_asprintf("slot %lu", i);
    115  1.25   thorpej 		evcnt_attach_dynamic(&tc_3000_300_intr[i].tci_evcnt,
    116  1.25   thorpej 		    EVCNT_TYPE_INTR, NULL, "tc", cp);
    117   1.2       cgd 	}
    118  1.24       cgd }
    119  1.24       cgd 
    120  1.24       cgd const struct evcnt *
    121  1.31      matt tc_3000_300_intr_evcnt(device_t tcadev, void *cookie)
    122  1.24       cgd {
    123  1.25   thorpej 	u_long dev = (u_long)cookie;
    124  1.25   thorpej 
    125  1.25   thorpej #ifdef DIAGNOSTIC
    126  1.25   thorpej 	/* XXX bounds-check cookie. */
    127  1.25   thorpej #endif
    128  1.24       cgd 
    129  1.25   thorpej 	return (&tc_3000_300_intr[dev].tci_evcnt);
    130   1.1       cgd }
    131   1.1       cgd 
    132   1.1       cgd void
    133  1.31      matt tc_3000_300_intr_establish(device_t tcadev, void *cookie, tc_intrlevel_t level, int (*func)(void *), void *arg)
    134   1.1       cgd {
    135  1.32      matt 	volatile uint32_t *imskp;
    136   1.4       cgd 	u_long dev = (u_long)cookie;
    137   1.1       cgd 
    138   1.1       cgd #ifdef DIAGNOSTIC
    139   1.4       cgd 	/* XXX bounds-check cookie. */
    140   1.1       cgd #endif
    141   1.1       cgd 
    142   1.4       cgd 	if (tc_3000_300_intr[dev].tci_func != tc_3000_300_intrnull)
    143  1.18   thorpej 		panic("tc_3000_300_intr_establish: cookie %lu twice", dev);
    144   1.1       cgd 
    145  1.37   thorpej 	const int s = splhigh();
    146  1.37   thorpej 
    147  1.37   thorpej 	/* All TC systems are uniprocessors. */
    148  1.37   thorpej 	KASSERT(CPU_IS_PRIMARY(curcpu()));
    149  1.37   thorpej 	KASSERT(ncpu == 1);
    150  1.37   thorpej 	curcpu()->ci_nintrhand++;
    151  1.37   thorpej 
    152   1.4       cgd 	tc_3000_300_intr[dev].tci_func = func;
    153   1.4       cgd 	tc_3000_300_intr[dev].tci_arg = arg;
    154   1.1       cgd 
    155  1.37   thorpej 	splx(s);
    156  1.37   thorpej 
    157  1.32      matt 	imskp = (volatile uint32_t *)(DEC_3000_300_IOASIC_ADDR + IOASIC_IMSK);
    158   1.4       cgd 	switch (dev) {
    159   1.4       cgd 	case TC_3000_300_DEV_OPT0:
    160   1.5       cgd 		*imskp |= IOASIC_INTR_300_OPT0;
    161   1.4       cgd 		break;
    162   1.4       cgd 	case TC_3000_300_DEV_OPT1:
    163   1.5       cgd 		*imskp |= IOASIC_INTR_300_OPT1;
    164   1.4       cgd 		break;
    165   1.4       cgd 	default:
    166   1.4       cgd 		/* interrupts for builtins always enabled */
    167   1.4       cgd 		break;
    168   1.4       cgd 	}
    169   1.1       cgd }
    170   1.1       cgd 
    171   1.1       cgd void
    172  1.31      matt tc_3000_300_intr_disestablish(device_t tcadev, void *cookie)
    173   1.1       cgd {
    174  1.32      matt 	volatile uint32_t *imskp;
    175   1.4       cgd 	u_long dev = (u_long)cookie;
    176   1.1       cgd 
    177   1.1       cgd #ifdef DIAGNOSTIC
    178   1.4       cgd 	/* XXX bounds-check cookie. */
    179   1.1       cgd #endif
    180   1.1       cgd 
    181   1.4       cgd 	if (tc_3000_300_intr[dev].tci_func == tc_3000_300_intrnull)
    182  1.18   thorpej 		panic("tc_3000_300_intr_disestablish: cookie %lu bad intr",
    183   1.1       cgd 		    dev);
    184   1.1       cgd 
    185  1.32      matt 	imskp = (volatile uint32_t *)(DEC_3000_300_IOASIC_ADDR + IOASIC_IMSK);
    186   1.4       cgd 	switch (dev) {
    187   1.4       cgd 	case TC_3000_300_DEV_OPT0:
    188   1.5       cgd 		*imskp &= ~IOASIC_INTR_300_OPT0;
    189   1.4       cgd 		break;
    190   1.4       cgd 	case TC_3000_300_DEV_OPT1:
    191   1.5       cgd 		*imskp &= ~IOASIC_INTR_300_OPT1;
    192   1.4       cgd 		break;
    193   1.4       cgd 	default:
    194   1.4       cgd 		/* interrupts for builtins always enabled */
    195   1.4       cgd 		break;
    196   1.4       cgd 	}
    197   1.1       cgd 
    198  1.37   thorpej 	const int s = splhigh();
    199  1.37   thorpej 
    200  1.37   thorpej 	curcpu()->ci_nintrhand--;
    201  1.37   thorpej 
    202   1.4       cgd 	tc_3000_300_intr[dev].tci_func = tc_3000_300_intrnull;
    203   1.4       cgd 	tc_3000_300_intr[dev].tci_arg = (void *)dev;
    204  1.37   thorpej 
    205  1.37   thorpej 	splx(s);
    206   1.4       cgd }
    207   1.4       cgd 
    208   1.4       cgd int
    209  1.29       dsl tc_3000_300_intrnull(void *val)
    210   1.4       cgd {
    211   1.4       cgd 
    212  1.27    provos 	panic("tc_3000_300_intrnull: uncaught TC intr for cookie %ld",
    213   1.4       cgd 	    (u_long)val);
    214   1.1       cgd }
    215   1.1       cgd 
    216   1.1       cgd void
    217  1.29       dsl tc_3000_300_iointr(void *arg, unsigned long vec)
    218   1.1       cgd {
    219  1.32      matt 	uint32_t tcir, ioasicir, ioasicimr;
    220   1.9       cgd 	int ifound;
    221   1.1       cgd 
    222  1.36   thorpej 	KERNEL_LOCK(1, NULL);
    223  1.36   thorpej 
    224   1.1       cgd #ifdef DIAGNOSTIC
    225   1.1       cgd 	int s;
    226   1.1       cgd 	if (vec != 0x800)
    227  1.10       cgd 		panic("INVALID ASSUMPTION: vec 0x%lx, not 0x800", vec);
    228   1.1       cgd 	s = splhigh();
    229  1.35   thorpej 	if (s != ALPHA_PSL_IPL_IO_HI)
    230   1.9       cgd 		panic("INVALID ASSUMPTION: IPL %d, not %d", s,
    231  1.35   thorpej 		    ALPHA_PSL_IPL_IO_HI);
    232   1.1       cgd 	splx(s);
    233   1.1       cgd #endif
    234   1.1       cgd 
    235   1.1       cgd 	do {
    236   1.4       cgd 		tc_syncbus();
    237   1.2       cgd 
    238   1.2       cgd 		/* find out what interrupts/errors occurred */
    239  1.32      matt 		tcir = *(volatile uint32_t *)TC_3000_300_IR;
    240  1.32      matt 		ioasicir = *(volatile uint32_t *)
    241  1.21  nisimura 		    (DEC_3000_300_IOASIC_ADDR + IOASIC_INTR);
    242  1.32      matt 		ioasicimr = *(volatile uint32_t *)
    243  1.21  nisimura 		    (DEC_3000_300_IOASIC_ADDR + IOASIC_IMSK);
    244   1.4       cgd 		tc_mb();
    245   1.2       cgd 
    246   1.7       cgd 		/* Ignore interrupts that aren't enabled out. */
    247   1.7       cgd 		ioasicir &= ioasicimr;
    248   1.7       cgd 
    249   1.2       cgd 		/* clear the interrupts/errors we found. */
    250  1.32      matt 		*(volatile uint32_t *)TC_3000_300_IR = tcir;
    251   1.4       cgd 		/* XXX can't clear TC option slot interrupts here? */
    252   1.4       cgd 		tc_wmb();
    253   1.1       cgd 
    254   1.1       cgd 		ifound = 0;
    255   1.8       cgd 
    256  1.25   thorpej #define	INCRINTRCNT(slot)	tc_3000_300_intr[slot].tci_evcnt.ev_count++
    257   1.8       cgd 
    258   1.4       cgd #define	CHECKINTR(slot, flag)						\
    259   1.8       cgd 		if (flag) {						\
    260   1.1       cgd 			ifound = 1;					\
    261   1.8       cgd 			INCRINTRCNT(slot);				\
    262   1.4       cgd 			(*tc_3000_300_intr[slot].tci_func)		\
    263   1.4       cgd 			    (tc_3000_300_intr[slot].tci_arg);		\
    264   1.1       cgd 		}
    265   1.1       cgd 		/* Do them in order of priority; highest slot # first. */
    266   1.5       cgd 		CHECKINTR(TC_3000_300_DEV_CXTURBO,
    267   1.5       cgd 		    tcir & TC_3000_300_IR_CXTURBO);
    268   1.8       cgd 		CHECKINTR(TC_3000_300_DEV_IOASIC,
    269   1.8       cgd 		    (tcir & TC_3000_300_IR_IOASIC) &&
    270   1.8       cgd 	            (ioasicir & ~(IOASIC_INTR_300_OPT1|IOASIC_INTR_300_OPT0)));
    271   1.5       cgd 		CHECKINTR(TC_3000_300_DEV_TCDS, tcir & TC_3000_300_IR_TCDS);
    272   1.5       cgd 		CHECKINTR(TC_3000_300_DEV_OPT1,
    273   1.7       cgd 		    ioasicir & IOASIC_INTR_300_OPT1);
    274   1.7       cgd 		CHECKINTR(TC_3000_300_DEV_OPT0,
    275   1.5       cgd 		    ioasicir & IOASIC_INTR_300_OPT0);
    276   1.1       cgd #undef CHECKINTR
    277   1.1       cgd 
    278   1.1       cgd #ifdef DIAGNOSTIC
    279   1.1       cgd #define PRINTINTR(msg, bits)						\
    280   1.5       cgd 	if (tcir & bits)						\
    281  1.12  christos 		printf(msg);
    282   1.1       cgd 		PRINTINTR("BCache tag parity error\n",
    283   1.1       cgd 		    TC_3000_300_IR_BCTAGPARITY);
    284   1.1       cgd 		PRINTINTR("TC overrun error\n", TC_3000_300_IR_TCOVERRUN);
    285   1.1       cgd 		PRINTINTR("TC I/O timeout\n", TC_3000_300_IR_TCTIMEOUT);
    286   1.1       cgd 		PRINTINTR("Bcache parity error\n",
    287   1.1       cgd 		    TC_3000_300_IR_BCACHEPARITY);
    288   1.1       cgd 		PRINTINTR("Memory parity error\n", TC_3000_300_IR_MEMPARITY);
    289   1.1       cgd #undef PRINTINTR
    290   1.1       cgd #endif
    291   1.1       cgd 	} while (ifound);
    292  1.36   thorpej 
    293  1.36   thorpej 	KERNEL_UNLOCK_ONE(NULL);
    294  1.16    briggs }
    295  1.16    briggs 
    296  1.19  drochner #if NWSDISPLAY > 0
    297  1.16    briggs /*
    298  1.16    briggs  * tc_3000_300_fb_cnattach --
    299  1.16    briggs  *	Attempt to map the CTB output device to a slot and attach the
    300  1.16    briggs  * framebuffer as the output side of the console.
    301  1.16    briggs  */
    302  1.16    briggs int
    303  1.32      matt tc_3000_300_fb_cnattach(uint64_t turbo_slot)
    304  1.16    briggs {
    305  1.32      matt 	uint32_t output_slot;
    306  1.16    briggs 
    307  1.16    briggs 	output_slot = turbo_slot & 0xffffffff;
    308  1.16    briggs 
    309  1.16    briggs 	if (output_slot >= tc_3000_300_nslots) {
    310  1.20  drochner 		return EINVAL;
    311  1.16    briggs 	}
    312  1.16    briggs 
    313  1.16    briggs 	if (output_slot == 0) {
    314  1.17    briggs #if NSFB > 0
    315  1.16    briggs 		sfb_cnattach(KV(0x1c0000000) + 0x02000000);
    316  1.20  drochner 		return 0;
    317  1.17    briggs #else
    318  1.20  drochner 		return ENXIO;
    319  1.17    briggs #endif
    320  1.16    briggs 	}
    321  1.16    briggs 
    322  1.16    briggs 	return tc_fb_cnattach(tc_3000_300_slots[output_slot-1].tcs_addr);
    323   1.1       cgd }
    324  1.19  drochner #endif /* NWSDISPLAY */
    325