dec_3min.c revision 1.33
11.33Ssimonb/* $NetBSD: dec_3min.c,v 1.33 2000/01/14 13:45:25 simonb Exp $ */
21.1Sjonathan
31.1Sjonathan/*
41.1Sjonathan * Copyright (c) 1998 Jonathan Stone.  All rights reserved.
51.1Sjonathan *
61.1Sjonathan * Redistribution and use in source and binary forms, with or without
71.1Sjonathan * modification, are permitted provided that the following conditions
81.1Sjonathan * are met:
91.1Sjonathan * 1. Redistributions of source code must retain the above copyright
101.1Sjonathan *    notice, this list of conditions and the following disclaimer.
111.1Sjonathan * 2. Redistributions in binary form must reproduce the above copyright
121.1Sjonathan *    notice, this list of conditions and the following disclaimer in the
131.1Sjonathan *    documentation and/or other materials provided with the distribution.
141.1Sjonathan * 3. All advertising materials mentioning features or use of this software
151.1Sjonathan *    must display the following acknowledgement:
161.1Sjonathan *	This product includes software developed by Jonathan Stone for
171.1Sjonathan *      the NetBSD Project.
181.1Sjonathan * 4. The name of the author may not be used to endorse or promote products
191.1Sjonathan *    derived from this software without specific prior written permission.
201.1Sjonathan *
211.1Sjonathan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
221.1Sjonathan * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
231.1Sjonathan * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
241.1Sjonathan * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
251.1Sjonathan * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
261.1Sjonathan * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
271.1Sjonathan * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
281.1Sjonathan * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
291.1Sjonathan * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
301.1Sjonathan * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
311.1Sjonathan */
321.1Sjonathan
331.1Sjonathan/*
341.1Sjonathan * Copyright (c) 1988 University of Utah.
351.1Sjonathan * Copyright (c) 1992, 1993
361.1Sjonathan *	The Regents of the University of California.  All rights reserved.
371.1Sjonathan *
381.1Sjonathan * This code is derived from software contributed to Berkeley by
391.1Sjonathan * the Systems Programming Group of the University of Utah Computer
401.1Sjonathan * Science Department, The Mach Operating System project at
411.1Sjonathan * Carnegie-Mellon University and Ralph Campbell.
421.1Sjonathan *
431.1Sjonathan * Redistribution and use in source and binary forms, with or without
441.1Sjonathan * modification, are permitted provided that the following conditions
451.1Sjonathan * are met:
461.1Sjonathan * 1. Redistributions of source code must retain the above copyright
471.1Sjonathan *    notice, this list of conditions and the following disclaimer.
481.1Sjonathan * 2. Redistributions in binary form must reproduce the above copyright
491.1Sjonathan *    notice, this list of conditions and the following disclaimer in the
501.1Sjonathan *    documentation and/or other materials provided with the distribution.
511.1Sjonathan * 3. All advertising materials mentioning features or use of this software
521.1Sjonathan *    must display the following acknowledgement:
531.1Sjonathan *	This product includes software developed by the University of
541.1Sjonathan *	California, Berkeley and its contributors.
551.1Sjonathan * 4. Neither the name of the University nor the names of its contributors
561.1Sjonathan *    may be used to endorse or promote products derived from this software
571.1Sjonathan *    without specific prior written permission.
581.1Sjonathan *
591.1Sjonathan * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
601.1Sjonathan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
611.1Sjonathan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
621.1Sjonathan * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
631.1Sjonathan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
641.1Sjonathan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
651.1Sjonathan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
661.1Sjonathan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
671.1Sjonathan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
681.1Sjonathan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
691.1Sjonathan * SUCH DAMAGE.
701.1Sjonathan *
711.1Sjonathan *	@(#)machdep.c	8.3 (Berkeley) 1/12/94
721.1Sjonathan */
731.1Sjonathan
741.1Sjonathan#include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
751.1Sjonathan
761.33Ssimonb__KERNEL_RCSID(0, "$NetBSD: dec_3min.c,v 1.33 2000/01/14 13:45:25 simonb Exp $");
771.1Sjonathan
781.1Sjonathan
791.1Sjonathan#include <sys/types.h>
801.1Sjonathan#include <sys/systm.h>
811.1Sjonathan
821.1Sjonathan#include <machine/cpu.h>
831.1Sjonathan#include <machine/intr.h>
841.1Sjonathan#include <machine/sysconf.h>
851.1Sjonathan
861.1Sjonathan#include <mips/mips/mips_mcclock.h>	/* mcclock CPUspeed estimation */
871.2Sjonathan
881.2Sjonathan/* all these to get ioasic_base */
891.2Sjonathan#include <sys/device.h>			/* struct cfdata for.. */
901.2Sjonathan#include <dev/tc/tcvar.h>		/* tc type definitions for.. */
911.7Sjonathan#include <dev/tc/ioasicreg.h>		/* ioasic interrrupt masks */
921.2Sjonathan#include <dev/tc/ioasicvar.h>		/* ioasic_base */
931.1Sjonathan
941.20Ssimonb#include <pmax/pmax/machdep.h>
951.1Sjonathan#include <pmax/pmax/kmin.h>		/* 3min baseboard addresses */
961.15Snisimura#include <pmax/pmax/memc.h>		/* 3min/maxine memory errors */
971.1Sjonathan
981.1Sjonathan
991.1Sjonathan/*
1001.1Sjonathan * forward declarations
1011.1Sjonathan */
1021.31Ssimonbvoid		dec_3min_init __P((void));		/* XXX */
1031.31Ssimonbstatic void	dec_3min_bus_reset __P((void));
1041.33Ssimonbstatic void	dec_3min_cons_init __P((void));
1051.33Ssimonbstatic void	dec_3min_device_register __P((struct device *, void *));
1061.31Ssimonbstatic int	dec_3min_intr __P((unsigned, unsigned, unsigned, unsigned));
1071.33Ssimonbstatic void	dec_3min_intr_establish __P((struct device *, void *,
1081.33Ssimonb		    int, int (*)(void *), void *));
1091.33Ssimonbstatic void	dec_3min_intr_disestablish __P((struct device *, void *));
1101.1Sjonathan
1111.31Ssimonbstatic void	kn02ba_wbflush __P((void));
1121.31Ssimonbstatic unsigned	kn02ba_clkread __P((void));
1131.1Sjonathan
1141.1Sjonathan
1151.1Sjonathan/*
1161.1Sjonathan * Local declarations.
1171.1Sjonathan */
1181.22Snisimurastatic u_int32_t kmin_tc3_imask;
1191.18Snisimura
1201.18Snisimura#ifdef MIPS3
1211.31Ssimonbstatic unsigned latched_cycle_cnt;
1221.18Snisimura#endif
1231.18Snisimura
1241.1Sjonathan
1251.1Sjonathanvoid
1261.1Sjonathandec_3min_init()
1271.1Sjonathan{
1281.31Ssimonb	int physmem_boardmax;
1291.22Snisimura
1301.24Snisimura	platform.iobus = "tcbus";
1311.1Sjonathan	platform.bus_reset = dec_3min_bus_reset;
1321.1Sjonathan	platform.cons_init = dec_3min_cons_init;
1331.1Sjonathan	platform.device_register = dec_3min_device_register;
1341.22Snisimura	platform.iointr = dec_3min_intr;
1351.33Ssimonb	platform.intr_establish = dec_3min_intr_establish;
1361.33Ssimonb	platform.intr_disestablish = dec_3min_intr_disestablish;
1371.26Ssimonb	platform.memsize = memsize_scan;
1381.22Snisimura	platform.clkread = kn02ba_clkread;
1391.1Sjonathan
1401.22Snisimura	/* clear any memory errors */
1411.17Snisimura	*(u_int32_t *)MIPS_PHYS_TO_KSEG1(KMIN_REG_TIMEOUT) = 0;
1421.14Snisimura	kn02ba_wbflush();
1431.1Sjonathan
1441.1Sjonathan	ioasic_base = MIPS_PHYS_TO_KSEG1(KMIN_SYS_ASIC);
1451.22Snisimura	mips_hardware_intr = dec_3min_intr;
1461.1Sjonathan
1471.1Sjonathan	/*
1481.22Snisimura	 * Since all the motherboard interrupts come through the
1491.22Snisimura	 * IOASIC, it has to be turned off for all the spls and
1501.22Snisimura	 * since we don't know what kinds of devices are in the
1511.22Snisimura	 * TURBOchannel option slots, just splhigh().
1521.1Sjonathan	 */
1531.16Snisimura	splvec.splbio = MIPS_SPL_0_1_2_3;
1541.22Snisimura	splvec.splnet = MIPS_SPL_0_1_2_3;
1551.16Snisimura	splvec.spltty = MIPS_SPL_0_1_2_3;
1561.16Snisimura	splvec.splimp = MIPS_SPL_0_1_2_3;
1571.16Snisimura	splvec.splclock = MIPS_SPL_0_1_2_3;
1581.16Snisimura	splvec.splstatclock = MIPS_SPL_0_1_2_3;
1591.16Snisimura
1601.28Snisimura	/* enable posting of MIPS_INT_MASK_3 to CAUSE register */
1611.28Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_IMSK) = KMIN_INTR_CLOCK;
1621.22Snisimura	/* calibrate cpu_mhz value */
1631.29Snisimura	mc_cpuspeed(ioasic_base+IOASIC_SLOT_8_START, MIPS_INT_MASK_3);
1641.1Sjonathan
1651.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_LANCE_DECODE) = 0x3;
1661.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_SCSI_DECODE) = 0xe;
1671.22Snisimura#if 0
1681.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_SCC0_DECODE) = (0x10|4);
1691.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_SCC1_DECODE) = (0x10|6);
1701.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_CSR) = 0x00000f00;
1711.22Snisimura#endif
1721.22Snisimura
1731.22Snisimura	/* sanitize interrupt mask */
1741.22Snisimura	kmin_tc3_imask = (KMIN_INTR_CLOCK|KMIN_INTR_PSWARN|KMIN_INTR_TIMEOUT);
1751.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_INTR) = 0;
1761.22Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_IMSK) = kmin_tc3_imask;
1771.1Sjonathan
1781.1Sjonathan	/*
1791.22Snisimura	 * The kmin memory hardware seems to wrap memory addresses
1801.1Sjonathan	 * with 4Mbyte SIMMs, which causes the physmem computation
1811.1Sjonathan	 * to lose.  Find out how big the SIMMS are and set
1821.22Snisimura	 * max_ physmem accordingly.
1831.22Snisimura	 * XXX Do MAXINEs lose the same way?
1841.1Sjonathan	 */
1851.1Sjonathan	physmem_boardmax = KMIN_PHYS_MEMORY_END + 1;
1861.22Snisimura	if ((KMIN_MSR_SIZE_16Mb & *(int *)MIPS_PHYS_TO_KSEG1(KMIN_REG_MSR))
1871.22Snisimura			== 0)
1881.1Sjonathan		physmem_boardmax = physmem_boardmax >> 2;
1891.1Sjonathan	physmem_boardmax = MIPS_PHYS_TO_KSEG1(physmem_boardmax);
1901.10Sjonathan
1911.22Snisimura	sprintf(cpu_model, "DECstation 5000/1%d (3MIN)", cpu_mhz);
1921.22Snisimura}
1931.22Snisimura
1941.22Snisimura/*
1951.22Snisimura * Initalize the memory system and I/O buses.
1961.22Snisimura */
1971.31Ssimonbstatic void
1981.22Snisimuradec_3min_bus_reset()
1991.22Snisimura{
2001.22Snisimura
2011.22Snisimura	/*
2021.22Snisimura	 * Reset interrupts, clear any errors from newconf probes
2031.22Snisimura	 */
2041.22Snisimura
2051.17Snisimura	*(u_int32_t *)MIPS_PHYS_TO_KSEG1(KMIN_REG_TIMEOUT) = 0;
2061.17Snisimura	kn02ba_wbflush();
2071.17Snisimura
2081.22Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_INTR) = 0;
2091.22Snisimura	kn02ba_wbflush();
2101.1Sjonathan}
2111.1Sjonathan
2121.31Ssimonbstatic void
2131.1Sjonathandec_3min_cons_init()
2141.1Sjonathan{
2151.1Sjonathan	/* notyet */
2161.1Sjonathan}
2171.1Sjonathan
2181.1Sjonathan
2191.31Ssimonbstatic void
2201.1Sjonathandec_3min_device_register(dev, aux)
2211.1Sjonathan	struct device *dev;
2221.1Sjonathan	void *aux;
2231.1Sjonathan{
2241.1Sjonathan	panic("dec_3min_device_register unimplemented");
2251.1Sjonathan}
2261.1Sjonathan
2271.1Sjonathan
2281.31Ssimonbstatic void
2291.33Ssimonbdec_3min_intr_establish(dev, cookie, level, handler, arg)
2301.33Ssimonb	struct device *dev;
2311.33Ssimonb	void *cookie;
2321.33Ssimonb	int level;
2331.24Snisimura	int (*handler) __P((void *));
2341.33Ssimonb	void *arg;
2351.1Sjonathan{
2361.33Ssimonb	int slotno = (int)cookie;
2371.13Ssimonb	unsigned mask;
2381.1Sjonathan
2391.1Sjonathan	switch (slotno) {
2401.1Sjonathan		/* slots 0-2 don't interrupt through the IOASIC. */
2411.33Ssimonb	  case 0:
2421.33Ssimonb		mask = MIPS_INT_MASK_0;
2431.33Ssimonb		break;
2441.33Ssimonb	  case 1:
2451.33Ssimonb		mask = MIPS_INT_MASK_1;
2461.33Ssimonb		break;
2471.33Ssimonb	  case 2:
2481.33Ssimonb		mask = MIPS_INT_MASK_2;
2491.33Ssimonb		break;
2501.1Sjonathan
2511.33Ssimonb	  case KMIN_SCSI_SLOT:
2521.7Sjonathan		mask = (IOASIC_INTR_SCSI | IOASIC_INTR_SCSI_PTR_LOAD |
2531.7Sjonathan			IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E);
2541.1Sjonathan		break;
2551.33Ssimonb	  case KMIN_LANCE_SLOT:
2561.1Sjonathan		mask = KMIN_INTR_LANCE;
2571.1Sjonathan		break;
2581.33Ssimonb	  case KMIN_SCC0_SLOT:
2591.1Sjonathan		mask = KMIN_INTR_SCC_0;
2601.1Sjonathan		break;
2611.33Ssimonb	  case KMIN_SCC1_SLOT:
2621.1Sjonathan		mask = KMIN_INTR_SCC_1;
2631.1Sjonathan		break;
2641.33Ssimonb	  case KMIN_ASIC_SLOT:
2651.1Sjonathan		mask = KMIN_INTR_ASIC;
2661.1Sjonathan		break;
2671.33Ssimonb	  default:
2681.33Ssimonb#ifdef DIAGNOSTIC
2691.33Ssimonb		printf("warning: enabling unknown intr %x\n", slotno);
2701.33Ssimonb#endif
2711.1Sjonathan		return;
2721.1Sjonathan	}
2731.1Sjonathan
2741.1Sjonathan#if defined(DEBUG) || defined(DIAGNOSTIC)
2751.25Snisimura	printf("3MIN: imask %x, %sabling slot %d, sc %p handler %p\n",
2761.33Ssimonb	    kmin_tc3_imask, (on? "en" : "dis"), slotno, sc, handler);
2771.1Sjonathan#endif
2781.1Sjonathan
2791.1Sjonathan	/*
2801.1Sjonathan	 * Enable the interrupt  handler, and if it's an IOASIC
2811.1Sjonathan	 * slot, set the IOASIC interrupt mask.
2821.1Sjonathan	 * Otherwise, set the appropriate spl level in the R3000
2831.1Sjonathan	 * register.
2841.1Sjonathan	 * Be careful to set handlers  before enabling, and disable
2851.1Sjonathan	 * interrupts before clearing handlers.
2861.1Sjonathan	 */
2871.1Sjonathan
2881.33Ssimonb	/* Set the interrupt handler and argument ... */
2891.33Ssimonb	intrtab[slotno].ih_func = handler;
2901.33Ssimonb	intrtab[slotno].ih_arg = arg;
2911.33Ssimonb	/* ... and set the relevant mask */
2921.33Ssimonb	if (slotno <= 2) {
2931.33Ssimonb		/* it's an option slot */
2941.33Ssimonb		int s = splhigh();
2951.33Ssimonb		s |= mask;
2961.33Ssimonb		splx(s);
2971.1Sjonathan	} else {
2981.33Ssimonb		/* it's a baseboard device going via the ASIC */
2991.33Ssimonb		kmin_tc3_imask |= mask;
3001.1Sjonathan	}
3011.33Ssimonb
3021.25Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_IMSK) = kmin_tc3_imask;
3031.25Snisimura	kn02ba_wbflush();
3041.1Sjonathan}
3051.1Sjonathan
3061.1Sjonathan
3071.33Ssimonbstatic void
3081.33Ssimonbdec_3min_intr_disestablish(dev, arg)
3091.33Ssimonb	struct device *dev;
3101.33Ssimonb	void *arg;
3111.33Ssimonb{
3121.33Ssimonb	printf("dec_3min_intr_distestablish: not implemented\n");
3131.33Ssimonb}
3141.33Ssimonb
3151.1Sjonathan
3161.1Sjonathan/*
3171.1Sjonathan * 3min hardware interrupts. (DECstation 5000/1xx)
3181.1Sjonathan */
3191.31Ssimonbstatic int
3201.17Snisimuradec_3min_intr(cpumask, pc, status, cause)
3211.17Snisimura	unsigned cpumask;
3221.1Sjonathan	unsigned pc;
3231.17Snisimura	unsigned status;
3241.17Snisimura	unsigned cause;
3251.1Sjonathan{
3261.1Sjonathan	static int user_warned = 0;
3271.17Snisimura	static int intr_depth = 0;
3281.17Snisimura	u_int32_t old_mask;
3291.1Sjonathan
3301.10Sjonathan	intr_depth++;
3311.17Snisimura	old_mask = *(u_int32_t *)(ioasic_base + IOASIC_IMSK);
3321.10Sjonathan
3331.17Snisimura	if (cpumask & MIPS_INT_MASK_4)
3341.1Sjonathan		prom_haltbutton();
3351.1Sjonathan
3361.17Snisimura	if (cpumask & MIPS_INT_MASK_3) {
3371.10Sjonathan		/* NB: status & MIPS_INT_MASK3 must also be set */
3381.10Sjonathan		/* masked interrupts are still observable */
3391.17Snisimura		u_int32_t intr, imsk, turnoff;
3401.17Snisimura
3411.17Snisimura		turnoff = 0;
3421.17Snisimura		intr = *(u_int32_t *)(ioasic_base + IOASIC_INTR);
3431.17Snisimura		imsk = *(u_int32_t *)(ioasic_base + IOASIC_IMSK);
3441.17Snisimura		intr &= imsk;
3451.1Sjonathan
3461.7Sjonathan		if (intr & IOASIC_INTR_SCSI_PTR_LOAD) {
3471.17Snisimura			turnoff |= IOASIC_INTR_SCSI_PTR_LOAD;
3481.1Sjonathan#ifdef notdef
3491.1Sjonathan			asc_dma_intr();
3501.1Sjonathan#endif
3511.1Sjonathan		}
3521.12Ssimonb
3531.7Sjonathan		if (intr & (IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E))
3541.17Snisimura			turnoff |= IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E;
3551.1Sjonathan
3561.7Sjonathan		if (intr & IOASIC_INTR_LANCE_READ_E)
3571.17Snisimura			turnoff |= IOASIC_INTR_LANCE_READ_E;
3581.17Snisimura
3591.17Snisimura		if (turnoff)
3601.17Snisimura			*(u_int32_t *)(ioasic_base + IOASIC_INTR) = ~turnoff;
3611.1Sjonathan
3621.1Sjonathan		if (intr & KMIN_INTR_TIMEOUT)
3631.1Sjonathan			kn02ba_errintr();
3641.12Ssimonb
3651.1Sjonathan		if (intr & KMIN_INTR_CLOCK) {
3661.17Snisimura			struct clockframe cf;
3671.17Snisimura
3681.22Snisimura			__asm __volatile("lbu $0,48(%0)" ::
3691.22Snisimura				"r"(ioasic_base + IOASIC_SLOT_8_START));
3701.6Sjonathan#ifdef MIPS3
3711.6Sjonathan			if (CPUISMIPS3) {
3721.6Sjonathan				latched_cycle_cnt = mips3_cycle_count();
3731.6Sjonathan			}
3741.6Sjonathan#endif
3751.17Snisimura			cf.pc = pc;
3761.17Snisimura			cf.sr = status;
3771.1Sjonathan			hardclock(&cf);
3781.1Sjonathan			intrcnt[HARDCLOCK]++;
3791.1Sjonathan		}
3801.10Sjonathan
3811.10Sjonathan		/* If clock interrups were enabled, re-enable them ASAP. */
3821.10Sjonathan		if (old_mask & KMIN_INTR_CLOCK) {
3831.17Snisimura			/* ioctl interrupt mask to splclock and higher */
3841.17Snisimura			*(u_int32_t *)(ioasic_base + IOASIC_IMSK)
3851.17Snisimura				= old_mask &
3861.17Snisimura					~(KMIN_INTR_SCC_0|KMIN_INTR_SCC_1 |
3871.17Snisimura					  IOASIC_INTR_LANCE|IOASIC_INTR_SCSI);
3881.14Snisimura			kn02ba_wbflush();
3891.17Snisimura			_splset(MIPS_SR_INT_IE | (status & MIPS_INT_MASK_3));
3901.10Sjonathan		}
3911.10Sjonathan
3921.11Sjonathan		if (intr_depth > 1)
3931.11Sjonathan			 goto done;
3941.11Sjonathan
3951.1Sjonathan		if ((intr & KMIN_INTR_SCC_0) &&
3961.33Ssimonb		    intrtab[KMIN_SCC0_SLOT].ih_func) {
3971.33Ssimonb			(*(intrtab[KMIN_SCC0_SLOT].ih_func))
3981.33Ssimonb			  (intrtab[KMIN_SCC0_SLOT].ih_arg);
3991.1Sjonathan			intrcnt[SERIAL0_INTR]++;
4001.1Sjonathan		}
4011.1Sjonathan
4021.1Sjonathan		if ((intr & KMIN_INTR_SCC_1) &&
4031.33Ssimonb		    intrtab[KMIN_SCC1_SLOT].ih_func) {
4041.33Ssimonb			(*(intrtab[KMIN_SCC1_SLOT].ih_func))
4051.33Ssimonb			  (intrtab[KMIN_SCC1_SLOT].ih_arg);
4061.1Sjonathan			intrcnt[SERIAL1_INTR]++;
4071.1Sjonathan		}
4081.10Sjonathan
4091.10Sjonathan#ifdef notyet /* untested */
4101.10Sjonathan		/* If tty interrupts were enabled, re-enable them ASAP. */
4111.10Sjonathan		if ((old_mask & (KMIN_INTR_SCC_1|KMIN_INTR_SCC_0)) ==
4121.10Sjonathan		     (KMIN_INTR_SCC_1|KMIN_INTR_SCC_0)) {
4131.12Ssimonb			*imaskp = old_mask &
4141.10Sjonathan			  ~(KMIN_INTR_SCC_0|KMIN_INTR_SCC_1 |
4151.10Sjonathan			  IOASIC_INTR_LANCE|IOASIC_INTR_SCSI);
4161.14Snisimura			kn02ba_wbflush();
4171.10Sjonathan		}
4181.10Sjonathan
4191.10Sjonathan		/* XXX until we know about SPLs of TC options. */
4201.10Sjonathan		if (intr_depth > 1)
4211.10Sjonathan			 goto done;
4221.10Sjonathan#endif
4231.9Sjonathan		if ((intr & IOASIC_INTR_LANCE) &&
4241.33Ssimonb		    intrtab[KMIN_LANCE_SLOT].ih_func) {
4251.33Ssimonb			(*(intrtab[KMIN_LANCE_SLOT].ih_func))
4261.33Ssimonb			  (intrtab[KMIN_LANCE_SLOT].ih_arg);
4271.9Sjonathan			intrcnt[LANCE_INTR]++;
4281.9Sjonathan		}
4291.9Sjonathan
4301.7Sjonathan		if ((intr & IOASIC_INTR_SCSI) &&
4311.33Ssimonb		    intrtab[KMIN_SCSI_SLOT].ih_func) {
4321.33Ssimonb			(*(intrtab[KMIN_SCSI_SLOT].ih_func))
4331.33Ssimonb			  (intrtab[KMIN_SCSI_SLOT].ih_arg);
4341.1Sjonathan			intrcnt[SCSI_INTR]++;
4351.1Sjonathan		}
4361.1Sjonathan
4371.1Sjonathan		if (user_warned && ((intr & KMIN_INTR_PSWARN) == 0)) {
4381.1Sjonathan			printf("%s\n", "Power supply ok now.");
4391.1Sjonathan			user_warned = 0;
4401.1Sjonathan		}
4411.1Sjonathan		if ((intr & KMIN_INTR_PSWARN) && (user_warned < 3)) {
4421.1Sjonathan			user_warned++;
4431.1Sjonathan			printf("%s\n", "Power supply overheating");
4441.1Sjonathan		}
4451.1Sjonathan	}
4461.33Ssimonb	if ((cpumask & MIPS_INT_MASK_0) && intrtab[0].ih_func) {
4471.33Ssimonb		(*intrtab[0].ih_func)(intrtab[0].ih_arg);
4481.1Sjonathan		intrcnt[SLOT0_INTR]++;
4491.1Sjonathan 	}
4501.12Ssimonb
4511.33Ssimonb	if ((cpumask & MIPS_INT_MASK_1) && intrtab[1].ih_func) {
4521.33Ssimonb		(*intrtab[1].ih_func)(intrtab[1].ih_arg);
4531.1Sjonathan		intrcnt[SLOT1_INTR]++;
4541.1Sjonathan	}
4551.33Ssimonb	if ((cpumask & MIPS_INT_MASK_2) && intrtab[2].ih_func) {
4561.33Ssimonb		(*intrtab[2].ih_func)(intrtab[2].ih_arg);
4571.1Sjonathan		intrcnt[SLOT2_INTR]++;
4581.1Sjonathan	}
4591.1Sjonathan
4601.10Sjonathandone:
4611.10Sjonathan	/* restore entry state */
4621.10Sjonathan	splhigh();
4631.10Sjonathan	intr_depth--;
4641.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_IMSK) = old_mask;
4651.10Sjonathan
4661.14Snisimura
4671.17Snisimura	return (MIPS_SR_INT_IE | (status & ~cause & MIPS_HARD_INT_MASK));
4681.1Sjonathan}
4691.1Sjonathan
4701.1Sjonathan
4711.1Sjonathan
4721.1Sjonathan/*
4731.1Sjonathan ************************************************************************
4741.1Sjonathan * Extra functions
4751.1Sjonathan ************************************************************************
4761.1Sjonathan */
4771.14Snisimura
4781.31Ssimonbstatic void
4791.14Snisimurakn02ba_wbflush()
4801.14Snisimura{
4811.21Snisimura	/* read twice IOASIC_IMSK */
4821.27Ssimonb	__asm __volatile("lw $0,%0; lw $0,%0" ::
4831.27Ssimonb	    "i"(MIPS_PHYS_TO_KSEG1(KMIN_REG_IMSK)));
4841.14Snisimura}
4851.14Snisimura
4861.31Ssimonbstatic unsigned
4871.14Snisimurakn02ba_clkread()
4881.14Snisimura{
4891.14Snisimura#ifdef MIPS3
4901.14Snisimura	if (CPUISMIPS3) {
4911.14Snisimura		u_int32_t mips3_cycles;
4921.14Snisimura
4931.14Snisimura		mips3_cycles = mips3_cycle_count() - latched_cycle_cnt;
4941.14Snisimura		/* XXX divides take 78 cycles: approximate with * 41/2048 */
4951.14Snisimura		return((mips3_cycles >> 6) + (mips3_cycles >> 8) +
4961.14Snisimura		       (mips3_cycles >> 11));
4971.14Snisimura	}
4981.14Snisimura#endif
4991.14Snisimura	return 0;
5001.1Sjonathan}
501