dec_3min.c revision 1.38
11.38Sad/* $NetBSD: dec_3min.c,v 1.38 2000/04/05 17:49:55 ad 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.38Sad__KERNEL_RCSID(0, "$NetBSD: dec_3min.c,v 1.38 2000/04/05 17:49:55 ad Exp $");
771.1Sjonathan
781.34Snisimura#include <sys/param.h>
791.1Sjonathan#include <sys/systm.h>
801.34Snisimura#include <sys/device.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 <dev/tc/tcvar.h>		/* tc type definitions for.. */
901.7Sjonathan#include <dev/tc/ioasicreg.h>		/* ioasic interrrupt masks */
911.2Sjonathan#include <dev/tc/ioasicvar.h>		/* ioasic_base */
921.1Sjonathan
931.20Ssimonb#include <pmax/pmax/machdep.h>
941.1Sjonathan#include <pmax/pmax/kmin.h>		/* 3min baseboard addresses */
951.15Snisimura#include <pmax/pmax/memc.h>		/* 3min/maxine memory errors */
961.34Snisimura#include <pmax/tc/sccvar.h>
971.34Snisimura
981.34Snisimura#include "rasterconsole.h"
991.1Sjonathan
1001.31Ssimonbvoid		dec_3min_init __P((void));		/* XXX */
1011.31Ssimonbstatic void	dec_3min_bus_reset __P((void));
1021.33Ssimonbstatic void	dec_3min_cons_init __P((void));
1031.31Ssimonbstatic int	dec_3min_intr __P((unsigned, unsigned, unsigned, unsigned));
1041.33Ssimonbstatic void	dec_3min_intr_establish __P((struct device *, void *,
1051.33Ssimonb		    int, int (*)(void *), void *));
1061.1Sjonathan
1071.31Ssimonbstatic void	kn02ba_wbflush __P((void));
1081.31Ssimonbstatic unsigned	kn02ba_clkread __P((void));
1091.1Sjonathan
1101.1Sjonathan
1111.1Sjonathan/*
1121.1Sjonathan * Local declarations.
1131.1Sjonathan */
1141.22Snisimurastatic u_int32_t kmin_tc3_imask;
1151.18Snisimura
1161.18Snisimura#ifdef MIPS3
1171.31Ssimonbstatic unsigned latched_cycle_cnt;
1181.18Snisimura#endif
1191.18Snisimura
1201.1Sjonathan
1211.1Sjonathanvoid
1221.1Sjonathandec_3min_init()
1231.1Sjonathan{
1241.31Ssimonb	int physmem_boardmax;
1251.22Snisimura
1261.24Snisimura	platform.iobus = "tcbus";
1271.1Sjonathan	platform.bus_reset = dec_3min_bus_reset;
1281.1Sjonathan	platform.cons_init = dec_3min_cons_init;
1291.22Snisimura	platform.iointr = dec_3min_intr;
1301.33Ssimonb	platform.intr_establish = dec_3min_intr_establish;
1311.26Ssimonb	platform.memsize = memsize_scan;
1321.22Snisimura	platform.clkread = kn02ba_clkread;
1331.1Sjonathan
1341.22Snisimura	/* clear any memory errors */
1351.17Snisimura	*(u_int32_t *)MIPS_PHYS_TO_KSEG1(KMIN_REG_TIMEOUT) = 0;
1361.14Snisimura	kn02ba_wbflush();
1371.1Sjonathan
1381.1Sjonathan	ioasic_base = MIPS_PHYS_TO_KSEG1(KMIN_SYS_ASIC);
1391.22Snisimura	mips_hardware_intr = dec_3min_intr;
1401.1Sjonathan
1411.1Sjonathan	/*
1421.22Snisimura	 * Since all the motherboard interrupts come through the
1431.22Snisimura	 * IOASIC, it has to be turned off for all the spls and
1441.22Snisimura	 * since we don't know what kinds of devices are in the
1451.22Snisimura	 * TURBOchannel option slots, just splhigh().
1461.1Sjonathan	 */
1471.16Snisimura	splvec.splbio = MIPS_SPL_0_1_2_3;
1481.22Snisimura	splvec.splnet = MIPS_SPL_0_1_2_3;
1491.16Snisimura	splvec.spltty = MIPS_SPL_0_1_2_3;
1501.16Snisimura	splvec.splimp = MIPS_SPL_0_1_2_3;
1511.16Snisimura	splvec.splclock = MIPS_SPL_0_1_2_3;
1521.16Snisimura	splvec.splstatclock = MIPS_SPL_0_1_2_3;
1531.16Snisimura
1541.28Snisimura	/* enable posting of MIPS_INT_MASK_3 to CAUSE register */
1551.28Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_IMSK) = KMIN_INTR_CLOCK;
1561.22Snisimura	/* calibrate cpu_mhz value */
1571.29Snisimura	mc_cpuspeed(ioasic_base+IOASIC_SLOT_8_START, MIPS_INT_MASK_3);
1581.1Sjonathan
1591.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_LANCE_DECODE) = 0x3;
1601.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_SCSI_DECODE) = 0xe;
1611.22Snisimura#if 0
1621.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_SCC0_DECODE) = (0x10|4);
1631.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_SCC1_DECODE) = (0x10|6);
1641.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_CSR) = 0x00000f00;
1651.22Snisimura#endif
1661.22Snisimura
1671.22Snisimura	/* sanitize interrupt mask */
1681.22Snisimura	kmin_tc3_imask = (KMIN_INTR_CLOCK|KMIN_INTR_PSWARN|KMIN_INTR_TIMEOUT);
1691.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_INTR) = 0;
1701.22Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_IMSK) = kmin_tc3_imask;
1711.1Sjonathan
1721.1Sjonathan	/*
1731.22Snisimura	 * The kmin memory hardware seems to wrap memory addresses
1741.1Sjonathan	 * with 4Mbyte SIMMs, which causes the physmem computation
1751.1Sjonathan	 * to lose.  Find out how big the SIMMS are and set
1761.22Snisimura	 * max_ physmem accordingly.
1771.22Snisimura	 * XXX Do MAXINEs lose the same way?
1781.1Sjonathan	 */
1791.1Sjonathan	physmem_boardmax = KMIN_PHYS_MEMORY_END + 1;
1801.22Snisimura	if ((KMIN_MSR_SIZE_16Mb & *(int *)MIPS_PHYS_TO_KSEG1(KMIN_REG_MSR))
1811.22Snisimura			== 0)
1821.1Sjonathan		physmem_boardmax = physmem_boardmax >> 2;
1831.1Sjonathan	physmem_boardmax = MIPS_PHYS_TO_KSEG1(physmem_boardmax);
1841.10Sjonathan
1851.22Snisimura	sprintf(cpu_model, "DECstation 5000/1%d (3MIN)", cpu_mhz);
1861.22Snisimura}
1871.22Snisimura
1881.22Snisimura/*
1891.22Snisimura * Initalize the memory system and I/O buses.
1901.22Snisimura */
1911.31Ssimonbstatic void
1921.22Snisimuradec_3min_bus_reset()
1931.22Snisimura{
1941.22Snisimura
1951.22Snisimura	/*
1961.22Snisimura	 * Reset interrupts, clear any errors from newconf probes
1971.22Snisimura	 */
1981.22Snisimura
1991.17Snisimura	*(u_int32_t *)MIPS_PHYS_TO_KSEG1(KMIN_REG_TIMEOUT) = 0;
2001.17Snisimura	kn02ba_wbflush();
2011.17Snisimura
2021.22Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_INTR) = 0;
2031.22Snisimura	kn02ba_wbflush();
2041.1Sjonathan}
2051.1Sjonathan
2061.31Ssimonbstatic void
2071.1Sjonathandec_3min_cons_init()
2081.1Sjonathan{
2091.34Snisimura	int kbd, crt, screen;
2101.34Snisimura	extern int tcfb_cnattach __P((int));		/* XXX */
2111.34Snisimura
2121.34Snisimura	kbd = crt = screen = 0;
2131.34Snisimura	prom_findcons(&kbd, &crt, &screen);
2141.34Snisimura
2151.34Snisimura	if (screen > 0) {
2161.34Snisimura#if NRASTERCONSOLE > 0
2171.34Snisimura		if (tcfb_cnattach(crt) > 0) {
2181.34Snisimura			scc_lk201_cnattach(ioasic_base, 0x180000);
2191.34Snisimura			return;
2201.34Snisimura		}
2211.34Snisimura#endif
2221.34Snisimura		printf("No framebuffer device configured for slot %d: ", crt);
2231.34Snisimura		printf("using serial console\n");
2241.34Snisimura	}
2251.34Snisimura	/*
2261.34Snisimura	 * Delay to allow PROM putchars to complete.
2271.34Snisimura	 * FIFO depth * character time,
2281.34Snisimura	 * character time = (1000000 / (defaultrate / 10))
2291.34Snisimura	 */
2301.34Snisimura	DELAY(160000000 / 9600);	/* XXX */
2311.34Snisimura
2321.34Snisimura	scc_cnattach(ioasic_base, 0x180000);
2331.1Sjonathan}
2341.1Sjonathan
2351.31Ssimonbstatic void
2361.33Ssimonbdec_3min_intr_establish(dev, cookie, level, handler, arg)
2371.33Ssimonb	struct device *dev;
2381.33Ssimonb	void *cookie;
2391.33Ssimonb	int level;
2401.24Snisimura	int (*handler) __P((void *));
2411.33Ssimonb	void *arg;
2421.1Sjonathan{
2431.13Ssimonb	unsigned mask;
2441.1Sjonathan
2451.35Snisimura	switch ((int)cookie) {
2461.1Sjonathan		/* slots 0-2 don't interrupt through the IOASIC. */
2471.35Snisimura	  case SYS_DEV_OPT0:
2481.33Ssimonb		mask = MIPS_INT_MASK_0;
2491.33Ssimonb		break;
2501.35Snisimura	  case SYS_DEV_OPT1:
2511.33Ssimonb		mask = MIPS_INT_MASK_1;
2521.33Ssimonb		break;
2531.35Snisimura	  case SYS_DEV_OPT2:
2541.33Ssimonb		mask = MIPS_INT_MASK_2;
2551.33Ssimonb		break;
2561.1Sjonathan
2571.35Snisimura	  case SYS_DEV_SCSI:
2581.7Sjonathan		mask = (IOASIC_INTR_SCSI | IOASIC_INTR_SCSI_PTR_LOAD |
2591.7Sjonathan			IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E);
2601.1Sjonathan		break;
2611.35Snisimura	  case SYS_DEV_LANCE:
2621.1Sjonathan		mask = KMIN_INTR_LANCE;
2631.1Sjonathan		break;
2641.35Snisimura	  case SYS_DEV_SCC0:
2651.1Sjonathan		mask = KMIN_INTR_SCC_0;
2661.1Sjonathan		break;
2671.35Snisimura	  case SYS_DEV_SCC1:
2681.1Sjonathan		mask = KMIN_INTR_SCC_1;
2691.1Sjonathan		break;
2701.33Ssimonb	  default:
2711.33Ssimonb#ifdef DIAGNOSTIC
2721.35Snisimura		printf("warning: enabling unknown intr %x\n", (int)cookie);
2731.33Ssimonb#endif
2741.1Sjonathan		return;
2751.1Sjonathan	}
2761.1Sjonathan
2771.38Sad#if defined(DEBUG)
2781.36Sad	printf("3MIN: imask %x, enabling slot %d, dev %p handler %p\n",
2791.36Sad	    kmin_tc3_imask, (int)cookie, dev, handler);
2801.1Sjonathan#endif
2811.1Sjonathan
2821.1Sjonathan	/*
2831.1Sjonathan	 * Enable the interrupt  handler, and if it's an IOASIC
2841.1Sjonathan	 * slot, set the IOASIC interrupt mask.
2851.1Sjonathan	 * Otherwise, set the appropriate spl level in the R3000
2861.1Sjonathan	 * register.
2871.35Snisimura	 * Be careful to set handlers before enabling, and disable
2881.1Sjonathan	 * interrupts before clearing handlers.
2891.1Sjonathan	 */
2901.1Sjonathan
2911.33Ssimonb	/* Set the interrupt handler and argument ... */
2921.35Snisimura	intrtab[(int)cookie].ih_func = handler;
2931.35Snisimura	intrtab[(int)cookie].ih_arg = arg;
2941.33Ssimonb	/* ... and set the relevant mask */
2951.35Snisimura	switch ((int)cookie) {
2961.35Snisimura	case SYS_DEV_OPT0:
2971.35Snisimura	case SYS_DEV_OPT1:
2981.35Snisimura	case SYS_DEV_OPT2:
2991.33Ssimonb		/* it's an option slot */
3001.35Snisimura		{
3011.33Ssimonb		int s = splhigh();
3021.33Ssimonb		s |= mask;
3031.33Ssimonb		splx(s);
3041.35Snisimura		}
3051.35Snisimura		break;
3061.35Snisimura	default:
3071.35Snisimura		/* it's a baseboard device going via the IOASIC */
3081.33Ssimonb		kmin_tc3_imask |= mask;
3091.35Snisimura		break;
3101.1Sjonathan	}
3111.33Ssimonb
3121.25Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_IMSK) = kmin_tc3_imask;
3131.25Snisimura	kn02ba_wbflush();
3141.1Sjonathan}
3151.1Sjonathan
3161.1Sjonathan
3171.35Snisimura#define CHECKINTR(slot, bits)                                   \
3181.35Snisimura    do {							\
3191.35Snisimura        if (can_serve & (bits)) {                               \
3201.35Snisimura                intrcnt[slot] += 1;                             \
3211.35Snisimura                (*intrtab[slot].ih_func)(intrtab[slot].ih_arg); \
3221.35Snisimura        }							\
3231.35Snisimura    } while (0)
3241.1Sjonathan
3251.31Ssimonbstatic int
3261.17Snisimuradec_3min_intr(cpumask, pc, status, cause)
3271.17Snisimura	unsigned cpumask;
3281.1Sjonathan	unsigned pc;
3291.17Snisimura	unsigned status;
3301.17Snisimura	unsigned cause;
3311.1Sjonathan{
3321.1Sjonathan	static int user_warned = 0;
3331.17Snisimura	static int intr_depth = 0;
3341.17Snisimura	u_int32_t old_mask;
3351.1Sjonathan
3361.10Sjonathan	intr_depth++;
3371.17Snisimura	old_mask = *(u_int32_t *)(ioasic_base + IOASIC_IMSK);
3381.10Sjonathan
3391.17Snisimura	if (cpumask & MIPS_INT_MASK_4)
3401.1Sjonathan		prom_haltbutton();
3411.1Sjonathan
3421.17Snisimura	if (cpumask & MIPS_INT_MASK_3) {
3431.10Sjonathan		/* NB: status & MIPS_INT_MASK3 must also be set */
3441.10Sjonathan		/* masked interrupts are still observable */
3451.35Snisimura		u_int32_t intr, imsk, can_serve, turnoff;
3461.17Snisimura
3471.17Snisimura		turnoff = 0;
3481.17Snisimura		intr = *(u_int32_t *)(ioasic_base + IOASIC_INTR);
3491.17Snisimura		imsk = *(u_int32_t *)(ioasic_base + IOASIC_IMSK);
3501.35Snisimura		can_serve = intr & imsk;
3511.1Sjonathan
3521.7Sjonathan		if (intr & IOASIC_INTR_SCSI_PTR_LOAD) {
3531.17Snisimura			turnoff |= IOASIC_INTR_SCSI_PTR_LOAD;
3541.1Sjonathan#ifdef notdef
3551.1Sjonathan			asc_dma_intr();
3561.1Sjonathan#endif
3571.1Sjonathan		}
3581.12Ssimonb
3591.7Sjonathan		if (intr & (IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E))
3601.17Snisimura			turnoff |= IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E;
3611.1Sjonathan
3621.7Sjonathan		if (intr & IOASIC_INTR_LANCE_READ_E)
3631.17Snisimura			turnoff |= IOASIC_INTR_LANCE_READ_E;
3641.17Snisimura
3651.17Snisimura		if (turnoff)
3661.17Snisimura			*(u_int32_t *)(ioasic_base + IOASIC_INTR) = ~turnoff;
3671.1Sjonathan
3681.1Sjonathan		if (intr & KMIN_INTR_TIMEOUT)
3691.1Sjonathan			kn02ba_errintr();
3701.12Ssimonb
3711.1Sjonathan		if (intr & KMIN_INTR_CLOCK) {
3721.17Snisimura			struct clockframe cf;
3731.17Snisimura
3741.22Snisimura			__asm __volatile("lbu $0,48(%0)" ::
3751.22Snisimura				"r"(ioasic_base + IOASIC_SLOT_8_START));
3761.6Sjonathan#ifdef MIPS3
3771.6Sjonathan			if (CPUISMIPS3) {
3781.6Sjonathan				latched_cycle_cnt = mips3_cycle_count();
3791.6Sjonathan			}
3801.6Sjonathan#endif
3811.17Snisimura			cf.pc = pc;
3821.17Snisimura			cf.sr = status;
3831.1Sjonathan			hardclock(&cf);
3841.1Sjonathan			intrcnt[HARDCLOCK]++;
3851.1Sjonathan		}
3861.10Sjonathan
3871.10Sjonathan		/* If clock interrups were enabled, re-enable them ASAP. */
3881.10Sjonathan		if (old_mask & KMIN_INTR_CLOCK) {
3891.17Snisimura			/* ioctl interrupt mask to splclock and higher */
3901.17Snisimura			*(u_int32_t *)(ioasic_base + IOASIC_IMSK)
3911.17Snisimura				= old_mask &
3921.17Snisimura					~(KMIN_INTR_SCC_0|KMIN_INTR_SCC_1 |
3931.17Snisimura					  IOASIC_INTR_LANCE|IOASIC_INTR_SCSI);
3941.14Snisimura			kn02ba_wbflush();
3951.17Snisimura			_splset(MIPS_SR_INT_IE | (status & MIPS_INT_MASK_3));
3961.10Sjonathan		}
3971.10Sjonathan
3981.11Sjonathan		if (intr_depth > 1)
3991.11Sjonathan			 goto done;
4001.11Sjonathan
4011.35Snisimura		CHECKINTR(SYS_DEV_SCC0, IOASIC_INTR_SCC_0);
4021.35Snisimura		CHECKINTR(SYS_DEV_SCC1, IOASIC_INTR_SCC_1);
4031.10Sjonathan
4041.10Sjonathan#ifdef notyet /* untested */
4051.10Sjonathan		/* If tty interrupts were enabled, re-enable them ASAP. */
4061.10Sjonathan		if ((old_mask & (KMIN_INTR_SCC_1|KMIN_INTR_SCC_0)) ==
4071.10Sjonathan		     (KMIN_INTR_SCC_1|KMIN_INTR_SCC_0)) {
4081.12Ssimonb			*imaskp = old_mask &
4091.10Sjonathan			  ~(KMIN_INTR_SCC_0|KMIN_INTR_SCC_1 |
4101.10Sjonathan			  IOASIC_INTR_LANCE|IOASIC_INTR_SCSI);
4111.14Snisimura			kn02ba_wbflush();
4121.10Sjonathan		}
4131.10Sjonathan
4141.10Sjonathan		/* XXX until we know about SPLs of TC options. */
4151.10Sjonathan		if (intr_depth > 1)
4161.10Sjonathan			 goto done;
4171.10Sjonathan#endif
4181.35Snisimura		CHECKINTR(SYS_DEV_LANCE, IOASIC_INTR_LANCE);
4191.35Snisimura		CHECKINTR(SYS_DEV_SCSI, IOASIC_INTR_SCSI);
4201.1Sjonathan
4211.1Sjonathan		if (user_warned && ((intr & KMIN_INTR_PSWARN) == 0)) {
4221.1Sjonathan			printf("%s\n", "Power supply ok now.");
4231.1Sjonathan			user_warned = 0;
4241.1Sjonathan		}
4251.1Sjonathan		if ((intr & KMIN_INTR_PSWARN) && (user_warned < 3)) {
4261.1Sjonathan			user_warned++;
4271.1Sjonathan			printf("%s\n", "Power supply overheating");
4281.1Sjonathan		}
4291.1Sjonathan	}
4301.35Snisimura	if ((cpumask & MIPS_INT_MASK_0) && intrtab[SYS_DEV_OPT0].ih_func) {
4311.35Snisimura		(*intrtab[SYS_DEV_OPT0].ih_func)(intrtab[SYS_DEV_OPT0].ih_arg);
4321.35Snisimura		intrcnt[SYS_DEV_OPT0]++;
4331.1Sjonathan 	}
4341.12Ssimonb
4351.35Snisimura	if ((cpumask & MIPS_INT_MASK_1) && intrtab[SYS_DEV_OPT1].ih_func) {
4361.35Snisimura		(*intrtab[SYS_DEV_OPT1].ih_func)(intrtab[SYS_DEV_OPT1].ih_arg);
4371.35Snisimura		intrcnt[SYS_DEV_OPT1]++;
4381.1Sjonathan	}
4391.35Snisimura	if ((cpumask & MIPS_INT_MASK_2) && intrtab[SYS_DEV_OPT2].ih_func) {
4401.35Snisimura		(*intrtab[SYS_DEV_OPT2].ih_func)(intrtab[SYS_DEV_OPT2].ih_arg);
4411.35Snisimura		intrcnt[SYS_DEV_OPT2]++;
4421.1Sjonathan	}
4431.1Sjonathan
4441.10Sjonathandone:
4451.10Sjonathan	/* restore entry state */
4461.10Sjonathan	splhigh();
4471.10Sjonathan	intr_depth--;
4481.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_IMSK) = old_mask;
4491.10Sjonathan
4501.14Snisimura
4511.17Snisimura	return (MIPS_SR_INT_IE | (status & ~cause & MIPS_HARD_INT_MASK));
4521.1Sjonathan}
4531.1Sjonathan
4541.1Sjonathan
4551.1Sjonathan
4561.1Sjonathan/*
4571.1Sjonathan ************************************************************************
4581.1Sjonathan * Extra functions
4591.1Sjonathan ************************************************************************
4601.1Sjonathan */
4611.14Snisimura
4621.31Ssimonbstatic void
4631.14Snisimurakn02ba_wbflush()
4641.14Snisimura{
4651.21Snisimura	/* read twice IOASIC_IMSK */
4661.27Ssimonb	__asm __volatile("lw $0,%0; lw $0,%0" ::
4671.27Ssimonb	    "i"(MIPS_PHYS_TO_KSEG1(KMIN_REG_IMSK)));
4681.14Snisimura}
4691.14Snisimura
4701.31Ssimonbstatic unsigned
4711.14Snisimurakn02ba_clkread()
4721.14Snisimura{
4731.14Snisimura#ifdef MIPS3
4741.14Snisimura	if (CPUISMIPS3) {
4751.14Snisimura		u_int32_t mips3_cycles;
4761.14Snisimura
4771.14Snisimura		mips3_cycles = mips3_cycle_count() - latched_cycle_cnt;
4781.14Snisimura		/* XXX divides take 78 cycles: approximate with * 41/2048 */
4791.14Snisimura		return((mips3_cycles >> 6) + (mips3_cycles >> 8) +
4801.14Snisimura		       (mips3_cycles >> 11));
4811.14Snisimura	}
4821.14Snisimura#endif
4831.14Snisimura	return 0;
4841.1Sjonathan}
485