dec_3min.c revision 1.47
11.47Smhitch/* $NetBSD: dec_3min.c,v 1.47 2001/08/24 15:33:16 mhitch 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.47Smhitch__KERNEL_RCSID(0, "$NetBSD: dec_3min.c,v 1.47 2001/08/24 15:33:16 mhitch 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.42Snisimurastatic void	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.24Snisimura	platform.iobus = "tcbus";
1251.1Sjonathan	platform.bus_reset = dec_3min_bus_reset;
1261.1Sjonathan	platform.cons_init = dec_3min_cons_init;
1271.22Snisimura	platform.iointr = dec_3min_intr;
1281.33Ssimonb	platform.intr_establish = dec_3min_intr_establish;
1291.47Smhitch	platform.memsize = memsize_bitmap;
1301.22Snisimura	platform.clkread = kn02ba_clkread;
1311.1Sjonathan
1321.22Snisimura	/* clear any memory errors */
1331.17Snisimura	*(u_int32_t *)MIPS_PHYS_TO_KSEG1(KMIN_REG_TIMEOUT) = 0;
1341.14Snisimura	kn02ba_wbflush();
1351.1Sjonathan
1361.1Sjonathan	ioasic_base = MIPS_PHYS_TO_KSEG1(KMIN_SYS_ASIC);
1371.1Sjonathan
1381.1Sjonathan	/*
1391.22Snisimura	 * Since all the motherboard interrupts come through the
1401.22Snisimura	 * IOASIC, it has to be turned off for all the spls and
1411.22Snisimura	 * since we don't know what kinds of devices are in the
1421.22Snisimura	 * TURBOchannel option slots, just splhigh().
1431.1Sjonathan	 */
1441.16Snisimura	splvec.splbio = MIPS_SPL_0_1_2_3;
1451.44Stsutsui	splvec.splnet = MIPS_SPL_0_1_2_3;
1461.16Snisimura	splvec.spltty = MIPS_SPL_0_1_2_3;
1471.45Sthorpej	splvec.splvm = MIPS_SPL_0_1_2_3;
1481.16Snisimura	splvec.splclock = MIPS_SPL_0_1_2_3;
1491.16Snisimura	splvec.splstatclock = MIPS_SPL_0_1_2_3;
1501.16Snisimura
1511.28Snisimura	/* enable posting of MIPS_INT_MASK_3 to CAUSE register */
1521.28Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_IMSK) = KMIN_INTR_CLOCK;
1531.44Stsutsui	/* calibrate cpu_mhz value */
1541.29Snisimura	mc_cpuspeed(ioasic_base+IOASIC_SLOT_8_START, MIPS_INT_MASK_3);
1551.1Sjonathan
1561.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_LANCE_DECODE) = 0x3;
1571.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_SCSI_DECODE) = 0xe;
1581.44Stsutsui#if 0
1591.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_SCC0_DECODE) = (0x10|4);
1601.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_SCC1_DECODE) = (0x10|6);
1611.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_CSR) = 0x00000f00;
1621.44Stsutsui#endif
1631.44Stsutsui
1641.22Snisimura	/* sanitize interrupt mask */
1651.22Snisimura	kmin_tc3_imask = (KMIN_INTR_CLOCK|KMIN_INTR_PSWARN|KMIN_INTR_TIMEOUT);
1661.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_INTR) = 0;
1671.22Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_IMSK) = kmin_tc3_imask;
1681.1Sjonathan
1691.1Sjonathan	/*
1701.22Snisimura	 * The kmin memory hardware seems to wrap memory addresses
1711.1Sjonathan	 * with 4Mbyte SIMMs, which causes the physmem computation
1721.1Sjonathan	 * to lose.  Find out how big the SIMMS are and set
1731.22Snisimura	 * max_ physmem accordingly.
1741.22Snisimura	 * XXX Do MAXINEs lose the same way?
1751.1Sjonathan	 */
1761.1Sjonathan	physmem_boardmax = KMIN_PHYS_MEMORY_END + 1;
1771.22Snisimura	if ((KMIN_MSR_SIZE_16Mb & *(int *)MIPS_PHYS_TO_KSEG1(KMIN_REG_MSR))
1781.22Snisimura			== 0)
1791.1Sjonathan		physmem_boardmax = physmem_boardmax >> 2;
1801.1Sjonathan	physmem_boardmax = MIPS_PHYS_TO_KSEG1(physmem_boardmax);
1811.10Sjonathan
1821.22Snisimura	sprintf(cpu_model, "DECstation 5000/1%d (3MIN)", cpu_mhz);
1831.22Snisimura}
1841.22Snisimura
1851.22Snisimura/*
1861.22Snisimura * Initalize the memory system and I/O buses.
1871.22Snisimura */
1881.31Ssimonbstatic void
1891.22Snisimuradec_3min_bus_reset()
1901.22Snisimura{
1911.22Snisimura
1921.22Snisimura	/*
1931.22Snisimura	 * Reset interrupts, clear any errors from newconf probes
1941.22Snisimura	 */
1951.22Snisimura
1961.17Snisimura	*(u_int32_t *)MIPS_PHYS_TO_KSEG1(KMIN_REG_TIMEOUT) = 0;
1971.17Snisimura	kn02ba_wbflush();
1981.17Snisimura
1991.22Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_INTR) = 0;
2001.22Snisimura	kn02ba_wbflush();
2011.1Sjonathan}
2021.1Sjonathan
2031.31Ssimonbstatic void
2041.1Sjonathandec_3min_cons_init()
2051.1Sjonathan{
2061.34Snisimura	int kbd, crt, screen;
2071.34Snisimura	extern int tcfb_cnattach __P((int));		/* XXX */
2081.34Snisimura
2091.34Snisimura	kbd = crt = screen = 0;
2101.34Snisimura	prom_findcons(&kbd, &crt, &screen);
2111.34Snisimura
2121.34Snisimura	if (screen > 0) {
2131.34Snisimura#if NRASTERCONSOLE > 0
2141.34Snisimura		if (tcfb_cnattach(crt) > 0) {
2151.34Snisimura			scc_lk201_cnattach(ioasic_base, 0x180000);
2161.34Snisimura			return;
2171.34Snisimura		}
2181.34Snisimura#endif
2191.34Snisimura		printf("No framebuffer device configured for slot %d: ", crt);
2201.34Snisimura		printf("using serial console\n");
2211.34Snisimura	}
2221.34Snisimura	/*
2231.34Snisimura	 * Delay to allow PROM putchars to complete.
2241.34Snisimura	 * FIFO depth * character time,
2251.34Snisimura	 * character time = (1000000 / (defaultrate / 10))
2261.34Snisimura	 */
2271.34Snisimura	DELAY(160000000 / 9600);	/* XXX */
2281.34Snisimura
2291.34Snisimura	scc_cnattach(ioasic_base, 0x180000);
2301.1Sjonathan}
2311.1Sjonathan
2321.31Ssimonbstatic void
2331.33Ssimonbdec_3min_intr_establish(dev, cookie, level, handler, arg)
2341.33Ssimonb	struct device *dev;
2351.33Ssimonb	void *cookie;
2361.33Ssimonb	int level;
2371.24Snisimura	int (*handler) __P((void *));
2381.33Ssimonb	void *arg;
2391.1Sjonathan{
2401.13Ssimonb	unsigned mask;
2411.1Sjonathan
2421.35Snisimura	switch ((int)cookie) {
2431.1Sjonathan		/* slots 0-2 don't interrupt through the IOASIC. */
2441.35Snisimura	  case SYS_DEV_OPT0:
2451.33Ssimonb		mask = MIPS_INT_MASK_0;
2461.33Ssimonb		break;
2471.35Snisimura	  case SYS_DEV_OPT1:
2481.33Ssimonb		mask = MIPS_INT_MASK_1;
2491.33Ssimonb		break;
2501.35Snisimura	  case SYS_DEV_OPT2:
2511.33Ssimonb		mask = MIPS_INT_MASK_2;
2521.33Ssimonb		break;
2531.1Sjonathan
2541.35Snisimura	  case SYS_DEV_SCSI:
2551.7Sjonathan		mask = (IOASIC_INTR_SCSI | IOASIC_INTR_SCSI_PTR_LOAD |
2561.7Sjonathan			IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E);
2571.1Sjonathan		break;
2581.35Snisimura	  case SYS_DEV_LANCE:
2591.1Sjonathan		mask = KMIN_INTR_LANCE;
2601.1Sjonathan		break;
2611.35Snisimura	  case SYS_DEV_SCC0:
2621.1Sjonathan		mask = KMIN_INTR_SCC_0;
2631.1Sjonathan		break;
2641.35Snisimura	  case SYS_DEV_SCC1:
2651.1Sjonathan		mask = KMIN_INTR_SCC_1;
2661.1Sjonathan		break;
2671.33Ssimonb	  default:
2681.33Ssimonb#ifdef DIAGNOSTIC
2691.35Snisimura		printf("warning: enabling unknown intr %x\n", (int)cookie);
2701.33Ssimonb#endif
2711.1Sjonathan		return;
2721.1Sjonathan	}
2731.1Sjonathan
2741.38Sad#if defined(DEBUG)
2751.36Sad	printf("3MIN: imask %x, enabling slot %d, dev %p handler %p\n",
2761.36Sad	    kmin_tc3_imask, (int)cookie, dev, 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.35Snisimura	 * 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.35Snisimura	intrtab[(int)cookie].ih_func = handler;
2901.35Snisimura	intrtab[(int)cookie].ih_arg = arg;
2911.33Ssimonb	/* ... and set the relevant mask */
2921.35Snisimura	switch ((int)cookie) {
2931.35Snisimura	case SYS_DEV_OPT0:
2941.35Snisimura	case SYS_DEV_OPT1:
2951.35Snisimura	case SYS_DEV_OPT2:
2961.33Ssimonb		/* it's an option slot */
2971.35Snisimura		{
2981.33Ssimonb		int s = splhigh();
2991.33Ssimonb		s |= mask;
3001.33Ssimonb		splx(s);
3011.35Snisimura		}
3021.35Snisimura		break;
3031.35Snisimura	default:
3041.35Snisimura		/* it's a baseboard device going via the IOASIC */
3051.33Ssimonb		kmin_tc3_imask |= mask;
3061.35Snisimura		break;
3071.1Sjonathan	}
3081.33Ssimonb
3091.25Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_IMSK) = kmin_tc3_imask;
3101.25Snisimura	kn02ba_wbflush();
3111.1Sjonathan}
3121.1Sjonathan
3131.1Sjonathan
3141.44Stsutsui#define CHECKINTR(slot, bits)					\
3151.35Snisimura    do {							\
3161.44Stsutsui	if (can_serve & (bits)) {				\
3171.44Stsutsui		intrcnt[slot] += 1;				\
3181.44Stsutsui		(*intrtab[slot].ih_func)(intrtab[slot].ih_arg);	\
3191.44Stsutsui	}							\
3201.35Snisimura    } while (0)
3211.1Sjonathan
3221.42Snisimurastatic void
3231.39Snisimuradec_3min_intr(status, cause, pc, ipending)
3241.17Snisimura	unsigned status;
3251.17Snisimura	unsigned cause;
3261.39Snisimura	unsigned pc;
3271.39Snisimura	unsigned ipending;
3281.1Sjonathan{
3291.1Sjonathan	static int user_warned = 0;
3301.17Snisimura	static int intr_depth = 0;
3311.17Snisimura	u_int32_t old_mask;
3321.1Sjonathan
3331.10Sjonathan	intr_depth++;
3341.17Snisimura	old_mask = *(u_int32_t *)(ioasic_base + IOASIC_IMSK);
3351.10Sjonathan
3361.39Snisimura	if (ipending & MIPS_INT_MASK_4)
3371.1Sjonathan		prom_haltbutton();
3381.1Sjonathan
3391.39Snisimura	if (ipending & MIPS_INT_MASK_3) {
3401.10Sjonathan		/* NB: status & MIPS_INT_MASK3 must also be set */
3411.10Sjonathan		/* masked interrupts are still observable */
3421.35Snisimura		u_int32_t intr, imsk, can_serve, turnoff;
3431.17Snisimura
3441.17Snisimura		turnoff = 0;
3451.17Snisimura		intr = *(u_int32_t *)(ioasic_base + IOASIC_INTR);
3461.17Snisimura		imsk = *(u_int32_t *)(ioasic_base + IOASIC_IMSK);
3471.35Snisimura		can_serve = intr & imsk;
3481.1Sjonathan
3491.7Sjonathan		if (intr & IOASIC_INTR_SCSI_PTR_LOAD) {
3501.17Snisimura			turnoff |= IOASIC_INTR_SCSI_PTR_LOAD;
3511.1Sjonathan#ifdef notdef
3521.1Sjonathan			asc_dma_intr();
3531.1Sjonathan#endif
3541.1Sjonathan		}
3551.12Ssimonb
3561.7Sjonathan		if (intr & (IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E))
3571.17Snisimura			turnoff |= IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E;
3581.1Sjonathan
3591.7Sjonathan		if (intr & IOASIC_INTR_LANCE_READ_E)
3601.17Snisimura			turnoff |= IOASIC_INTR_LANCE_READ_E;
3611.17Snisimura
3621.17Snisimura		if (turnoff)
3631.17Snisimura			*(u_int32_t *)(ioasic_base + IOASIC_INTR) = ~turnoff;
3641.1Sjonathan
3651.1Sjonathan		if (intr & KMIN_INTR_TIMEOUT)
3661.1Sjonathan			kn02ba_errintr();
3671.12Ssimonb
3681.1Sjonathan		if (intr & KMIN_INTR_CLOCK) {
3691.17Snisimura			struct clockframe cf;
3701.17Snisimura
3711.22Snisimura			__asm __volatile("lbu $0,48(%0)" ::
3721.22Snisimura				"r"(ioasic_base + IOASIC_SLOT_8_START));
3731.6Sjonathan#ifdef MIPS3
3741.6Sjonathan			if (CPUISMIPS3) {
3751.43Scgd				latched_cycle_cnt = mips3_cp0_count_read();
3761.6Sjonathan			}
3771.6Sjonathan#endif
3781.17Snisimura			cf.pc = pc;
3791.17Snisimura			cf.sr = status;
3801.1Sjonathan			hardclock(&cf);
3811.46Snisimura			pmax_clock_evcnt.ev_count++;
3821.1Sjonathan		}
3831.10Sjonathan
3841.10Sjonathan		/* If clock interrups were enabled, re-enable them ASAP. */
3851.10Sjonathan		if (old_mask & KMIN_INTR_CLOCK) {
3861.17Snisimura			/* ioctl interrupt mask to splclock and higher */
3871.17Snisimura			*(u_int32_t *)(ioasic_base + IOASIC_IMSK)
3881.17Snisimura				= old_mask &
3891.17Snisimura					~(KMIN_INTR_SCC_0|KMIN_INTR_SCC_1 |
3901.17Snisimura					  IOASIC_INTR_LANCE|IOASIC_INTR_SCSI);
3911.14Snisimura			kn02ba_wbflush();
3921.17Snisimura			_splset(MIPS_SR_INT_IE | (status & MIPS_INT_MASK_3));
3931.10Sjonathan		}
3941.10Sjonathan
3951.11Sjonathan		if (intr_depth > 1)
3961.11Sjonathan			 goto done;
3971.11Sjonathan
3981.35Snisimura		CHECKINTR(SYS_DEV_SCC0, IOASIC_INTR_SCC_0);
3991.35Snisimura		CHECKINTR(SYS_DEV_SCC1, IOASIC_INTR_SCC_1);
4001.10Sjonathan
4011.10Sjonathan#ifdef notyet /* untested */
4021.10Sjonathan		/* If tty interrupts were enabled, re-enable them ASAP. */
4031.10Sjonathan		if ((old_mask & (KMIN_INTR_SCC_1|KMIN_INTR_SCC_0)) ==
4041.10Sjonathan		     (KMIN_INTR_SCC_1|KMIN_INTR_SCC_0)) {
4051.12Ssimonb			*imaskp = old_mask &
4061.10Sjonathan			  ~(KMIN_INTR_SCC_0|KMIN_INTR_SCC_1 |
4071.10Sjonathan			  IOASIC_INTR_LANCE|IOASIC_INTR_SCSI);
4081.14Snisimura			kn02ba_wbflush();
4091.10Sjonathan		}
4101.10Sjonathan
4111.10Sjonathan		/* XXX until we know about SPLs of TC options. */
4121.10Sjonathan		if (intr_depth > 1)
4131.10Sjonathan			 goto done;
4141.10Sjonathan#endif
4151.35Snisimura		CHECKINTR(SYS_DEV_LANCE, IOASIC_INTR_LANCE);
4161.35Snisimura		CHECKINTR(SYS_DEV_SCSI, IOASIC_INTR_SCSI);
4171.1Sjonathan
4181.1Sjonathan		if (user_warned && ((intr & KMIN_INTR_PSWARN) == 0)) {
4191.1Sjonathan			printf("%s\n", "Power supply ok now.");
4201.1Sjonathan			user_warned = 0;
4211.1Sjonathan		}
4221.1Sjonathan		if ((intr & KMIN_INTR_PSWARN) && (user_warned < 3)) {
4231.1Sjonathan			user_warned++;
4241.1Sjonathan			printf("%s\n", "Power supply overheating");
4251.1Sjonathan		}
4261.1Sjonathan	}
4271.39Snisimura	if ((ipending & MIPS_INT_MASK_0) && intrtab[SYS_DEV_OPT0].ih_func) {
4281.35Snisimura		(*intrtab[SYS_DEV_OPT0].ih_func)(intrtab[SYS_DEV_OPT0].ih_arg);
4291.35Snisimura		intrcnt[SYS_DEV_OPT0]++;
4301.1Sjonathan 	}
4311.12Ssimonb
4321.39Snisimura	if ((ipending & MIPS_INT_MASK_1) && intrtab[SYS_DEV_OPT1].ih_func) {
4331.35Snisimura		(*intrtab[SYS_DEV_OPT1].ih_func)(intrtab[SYS_DEV_OPT1].ih_arg);
4341.35Snisimura		intrcnt[SYS_DEV_OPT1]++;
4351.1Sjonathan	}
4361.39Snisimura	if ((ipending & MIPS_INT_MASK_2) && intrtab[SYS_DEV_OPT2].ih_func) {
4371.35Snisimura		(*intrtab[SYS_DEV_OPT2].ih_func)(intrtab[SYS_DEV_OPT2].ih_arg);
4381.35Snisimura		intrcnt[SYS_DEV_OPT2]++;
4391.1Sjonathan	}
4401.1Sjonathan
4411.10Sjonathandone:
4421.10Sjonathan	/* restore entry state */
4431.10Sjonathan	splhigh();
4441.10Sjonathan	intr_depth--;
4451.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_IMSK) = old_mask;
4461.10Sjonathan
4471.42Snisimura	_splset(MIPS_SR_INT_IE | (status & ~cause & MIPS_HARD_INT_MASK));
4481.1Sjonathan}
4491.1Sjonathan
4501.1Sjonathan
4511.1Sjonathan
4521.1Sjonathan/*
4531.1Sjonathan ************************************************************************
4541.1Sjonathan * Extra functions
4551.1Sjonathan ************************************************************************
4561.1Sjonathan */
4571.14Snisimura
4581.31Ssimonbstatic void
4591.14Snisimurakn02ba_wbflush()
4601.14Snisimura{
4611.21Snisimura	/* read twice IOASIC_IMSK */
4621.27Ssimonb	__asm __volatile("lw $0,%0; lw $0,%0" ::
4631.27Ssimonb	    "i"(MIPS_PHYS_TO_KSEG1(KMIN_REG_IMSK)));
4641.14Snisimura}
4651.14Snisimura
4661.31Ssimonbstatic unsigned
4671.14Snisimurakn02ba_clkread()
4681.14Snisimura{
4691.14Snisimura#ifdef MIPS3
4701.14Snisimura	if (CPUISMIPS3) {
4711.14Snisimura		u_int32_t mips3_cycles;
4721.14Snisimura
4731.43Scgd		mips3_cycles = mips3_cp0_count_read() - latched_cycle_cnt;
4741.14Snisimura		/* XXX divides take 78 cycles: approximate with * 41/2048 */
4751.14Snisimura		return((mips3_cycles >> 6) + (mips3_cycles >> 8) +
4761.14Snisimura		       (mips3_cycles >> 11));
4771.14Snisimura	}
4781.14Snisimura#endif
4791.14Snisimura	return 0;
4801.1Sjonathan}
481