dec_3min.c revision 1.52
11.52Ssimonb/* $NetBSD: dec_3min.c,v 1.52 2005/01/11 08:05:14 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) 1992, 1993
351.1Sjonathan *	The Regents of the University of California.  All rights reserved.
361.1Sjonathan *
371.1Sjonathan * This code is derived from software contributed to Berkeley by
381.1Sjonathan * the Systems Programming Group of the University of Utah Computer
391.1Sjonathan * Science Department, The Mach Operating System project at
401.1Sjonathan * Carnegie-Mellon University and Ralph Campbell.
411.1Sjonathan *
421.1Sjonathan * Redistribution and use in source and binary forms, with or without
431.1Sjonathan * modification, are permitted provided that the following conditions
441.1Sjonathan * are met:
451.1Sjonathan * 1. Redistributions of source code must retain the above copyright
461.1Sjonathan *    notice, this list of conditions and the following disclaimer.
471.1Sjonathan * 2. Redistributions in binary form must reproduce the above copyright
481.1Sjonathan *    notice, this list of conditions and the following disclaimer in the
491.1Sjonathan *    documentation and/or other materials provided with the distribution.
501.50Sagc * 3. Neither the name of the University nor the names of its contributors
511.50Sagc *    may be used to endorse or promote products derived from this software
521.50Sagc *    without specific prior written permission.
531.50Sagc *
541.50Sagc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
551.50Sagc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
561.50Sagc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
571.50Sagc * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
581.50Sagc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
591.50Sagc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
601.50Sagc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
611.50Sagc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
621.50Sagc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
631.50Sagc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
641.50Sagc * SUCH DAMAGE.
651.50Sagc *
661.50Sagc *	@(#)machdep.c	8.3 (Berkeley) 1/12/94
671.50Sagc */
681.50Sagc/*
691.50Sagc * Copyright (c) 1988 University of Utah.
701.50Sagc *
711.50Sagc * This code is derived from software contributed to Berkeley by
721.50Sagc * the Systems Programming Group of the University of Utah Computer
731.50Sagc * Science Department, The Mach Operating System project at
741.50Sagc * Carnegie-Mellon University and Ralph Campbell.
751.50Sagc *
761.50Sagc * Redistribution and use in source and binary forms, with or without
771.50Sagc * modification, are permitted provided that the following conditions
781.50Sagc * are met:
791.50Sagc * 1. Redistributions of source code must retain the above copyright
801.50Sagc *    notice, this list of conditions and the following disclaimer.
811.50Sagc * 2. Redistributions in binary form must reproduce the above copyright
821.50Sagc *    notice, this list of conditions and the following disclaimer in the
831.50Sagc *    documentation and/or other materials provided with the distribution.
841.1Sjonathan * 3. All advertising materials mentioning features or use of this software
851.1Sjonathan *    must display the following acknowledgement:
861.1Sjonathan *	This product includes software developed by the University of
871.1Sjonathan *	California, Berkeley and its contributors.
881.1Sjonathan * 4. Neither the name of the University nor the names of its contributors
891.1Sjonathan *    may be used to endorse or promote products derived from this software
901.1Sjonathan *    without specific prior written permission.
911.1Sjonathan *
921.1Sjonathan * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
931.1Sjonathan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
941.1Sjonathan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
951.1Sjonathan * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
961.1Sjonathan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
971.1Sjonathan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
981.1Sjonathan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
991.1Sjonathan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1001.1Sjonathan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1011.1Sjonathan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1021.1Sjonathan * SUCH DAMAGE.
1031.1Sjonathan *
1041.1Sjonathan *	@(#)machdep.c	8.3 (Berkeley) 1/12/94
1051.1Sjonathan */
1061.1Sjonathan
1071.1Sjonathan#include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
1081.1Sjonathan
1091.52Ssimonb__KERNEL_RCSID(0, "$NetBSD: dec_3min.c,v 1.52 2005/01/11 08:05:14 simonb Exp $");
1101.1Sjonathan
1111.34Snisimura#include <sys/param.h>
1121.1Sjonathan#include <sys/systm.h>
1131.34Snisimura#include <sys/device.h>
1141.1Sjonathan
1151.1Sjonathan#include <machine/cpu.h>
1161.1Sjonathan#include <machine/intr.h>
1171.1Sjonathan#include <machine/sysconf.h>
1181.1Sjonathan
1191.1Sjonathan#include <mips/mips/mips_mcclock.h>	/* mcclock CPUspeed estimation */
1201.2Sjonathan
1211.2Sjonathan/* all these to get ioasic_base */
1221.2Sjonathan#include <dev/tc/tcvar.h>		/* tc type definitions for.. */
1231.7Sjonathan#include <dev/tc/ioasicreg.h>		/* ioasic interrrupt masks */
1241.2Sjonathan#include <dev/tc/ioasicvar.h>		/* ioasic_base */
1251.1Sjonathan
1261.20Ssimonb#include <pmax/pmax/machdep.h>
1271.1Sjonathan#include <pmax/pmax/kmin.h>		/* 3min baseboard addresses */
1281.15Snisimura#include <pmax/pmax/memc.h>		/* 3min/maxine memory errors */
1291.51Sad
1301.51Sad#ifdef WSCONS
1311.51Sad#include <pmax/pmax/cons.h>
1321.51Sad#include <dev/ic/z8530sc.h>
1331.51Sad#include <dev/tc/zs_ioasicvar.h>
1341.51Sad#include "wsdisplay.h"
1351.51Sad#else
1361.34Snisimura#include <pmax/tc/sccvar.h>
1371.34Snisimura#include "rasterconsole.h"
1381.51Sad#endif
1391.1Sjonathan
1401.31Ssimonbvoid		dec_3min_init __P((void));		/* XXX */
1411.31Ssimonbstatic void	dec_3min_bus_reset __P((void));
1421.33Ssimonbstatic void	dec_3min_cons_init __P((void));
1431.42Snisimurastatic void	dec_3min_intr __P((unsigned, unsigned, unsigned, unsigned));
1441.33Ssimonbstatic void	dec_3min_intr_establish __P((struct device *, void *,
1451.33Ssimonb		    int, int (*)(void *), void *));
1461.1Sjonathan
1471.31Ssimonbstatic void	kn02ba_wbflush __P((void));
1481.31Ssimonbstatic unsigned	kn02ba_clkread __P((void));
1491.1Sjonathan
1501.1Sjonathan
1511.1Sjonathan/*
1521.1Sjonathan * Local declarations.
1531.1Sjonathan */
1541.22Snisimurastatic u_int32_t kmin_tc3_imask;
1551.18Snisimura
1561.18Snisimura#ifdef MIPS3
1571.31Ssimonbstatic unsigned latched_cycle_cnt;
1581.18Snisimura#endif
1591.18Snisimura
1601.1Sjonathan
1611.1Sjonathanvoid
1621.1Sjonathandec_3min_init()
1631.1Sjonathan{
1641.24Snisimura	platform.iobus = "tcbus";
1651.1Sjonathan	platform.bus_reset = dec_3min_bus_reset;
1661.1Sjonathan	platform.cons_init = dec_3min_cons_init;
1671.22Snisimura	platform.iointr = dec_3min_intr;
1681.33Ssimonb	platform.intr_establish = dec_3min_intr_establish;
1691.47Smhitch	platform.memsize = memsize_bitmap;
1701.22Snisimura	platform.clkread = kn02ba_clkread;
1711.1Sjonathan
1721.22Snisimura	/* clear any memory errors */
1731.17Snisimura	*(u_int32_t *)MIPS_PHYS_TO_KSEG1(KMIN_REG_TIMEOUT) = 0;
1741.14Snisimura	kn02ba_wbflush();
1751.1Sjonathan
1761.1Sjonathan	ioasic_base = MIPS_PHYS_TO_KSEG1(KMIN_SYS_ASIC);
1771.1Sjonathan
1781.1Sjonathan	/*
1791.22Snisimura	 * Since all the motherboard interrupts come through the
1801.22Snisimura	 * IOASIC, it has to be turned off for all the spls and
1811.22Snisimura	 * since we don't know what kinds of devices are in the
1821.22Snisimura	 * TURBOchannel option slots, just splhigh().
1831.1Sjonathan	 */
1841.16Snisimura	splvec.splbio = MIPS_SPL_0_1_2_3;
1851.44Stsutsui	splvec.splnet = MIPS_SPL_0_1_2_3;
1861.16Snisimura	splvec.spltty = MIPS_SPL_0_1_2_3;
1871.45Sthorpej	splvec.splvm = MIPS_SPL_0_1_2_3;
1881.16Snisimura	splvec.splclock = MIPS_SPL_0_1_2_3;
1891.16Snisimura	splvec.splstatclock = MIPS_SPL_0_1_2_3;
1901.16Snisimura
1911.28Snisimura	/* enable posting of MIPS_INT_MASK_3 to CAUSE register */
1921.28Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_IMSK) = KMIN_INTR_CLOCK;
1931.44Stsutsui	/* calibrate cpu_mhz value */
1941.29Snisimura	mc_cpuspeed(ioasic_base+IOASIC_SLOT_8_START, MIPS_INT_MASK_3);
1951.1Sjonathan
1961.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_LANCE_DECODE) = 0x3;
1971.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_SCSI_DECODE) = 0xe;
1981.44Stsutsui#if 0
1991.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_SCC0_DECODE) = (0x10|4);
2001.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_SCC1_DECODE) = (0x10|6);
2011.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_CSR) = 0x00000f00;
2021.44Stsutsui#endif
2031.44Stsutsui
2041.22Snisimura	/* sanitize interrupt mask */
2051.22Snisimura	kmin_tc3_imask = (KMIN_INTR_CLOCK|KMIN_INTR_PSWARN|KMIN_INTR_TIMEOUT);
2061.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_INTR) = 0;
2071.22Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_IMSK) = kmin_tc3_imask;
2081.1Sjonathan
2091.1Sjonathan	/*
2101.22Snisimura	 * The kmin memory hardware seems to wrap memory addresses
2111.1Sjonathan	 * with 4Mbyte SIMMs, which causes the physmem computation
2121.1Sjonathan	 * to lose.  Find out how big the SIMMS are and set
2131.22Snisimura	 * max_ physmem accordingly.
2141.22Snisimura	 * XXX Do MAXINEs lose the same way?
2151.1Sjonathan	 */
2161.1Sjonathan	physmem_boardmax = KMIN_PHYS_MEMORY_END + 1;
2171.22Snisimura	if ((KMIN_MSR_SIZE_16Mb & *(int *)MIPS_PHYS_TO_KSEG1(KMIN_REG_MSR))
2181.22Snisimura			== 0)
2191.1Sjonathan		physmem_boardmax = physmem_boardmax >> 2;
2201.1Sjonathan	physmem_boardmax = MIPS_PHYS_TO_KSEG1(physmem_boardmax);
2211.10Sjonathan
2221.22Snisimura	sprintf(cpu_model, "DECstation 5000/1%d (3MIN)", cpu_mhz);
2231.22Snisimura}
2241.22Snisimura
2251.22Snisimura/*
2261.49Stsutsui * Initialize the memory system and I/O buses.
2271.22Snisimura */
2281.31Ssimonbstatic void
2291.22Snisimuradec_3min_bus_reset()
2301.22Snisimura{
2311.22Snisimura
2321.22Snisimura	/*
2331.22Snisimura	 * Reset interrupts, clear any errors from newconf probes
2341.22Snisimura	 */
2351.22Snisimura
2361.17Snisimura	*(u_int32_t *)MIPS_PHYS_TO_KSEG1(KMIN_REG_TIMEOUT) = 0;
2371.17Snisimura	kn02ba_wbflush();
2381.17Snisimura
2391.22Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_INTR) = 0;
2401.22Snisimura	kn02ba_wbflush();
2411.1Sjonathan}
2421.1Sjonathan
2431.31Ssimonbstatic void
2441.1Sjonathandec_3min_cons_init()
2451.1Sjonathan{
2461.34Snisimura	int kbd, crt, screen;
2471.34Snisimura
2481.34Snisimura	kbd = crt = screen = 0;
2491.34Snisimura	prom_findcons(&kbd, &crt, &screen);
2501.34Snisimura
2511.34Snisimura	if (screen > 0) {
2521.51Sad#if NWSDISPLAY > 0
2531.51Sad 		if (tcfb_cnattach(crt) > 0) {
2541.51Sad			zs_ioasic_lk201_cnattach(ioasic_base, 0x180000, 0);
2551.51Sad 			return;
2561.51Sad 		}
2571.51Sad#elif NRASTERCONSOLE > 0
2581.51Sad		extern int tcfb_cnattach __P((int));		/* XXX */
2591.51Sad
2601.34Snisimura		if (tcfb_cnattach(crt) > 0) {
2611.34Snisimura			scc_lk201_cnattach(ioasic_base, 0x180000);
2621.34Snisimura			return;
2631.34Snisimura		}
2641.34Snisimura#endif
2651.34Snisimura		printf("No framebuffer device configured for slot %d: ", crt);
2661.34Snisimura		printf("using serial console\n");
2671.34Snisimura	}
2681.34Snisimura	/*
2691.34Snisimura	 * Delay to allow PROM putchars to complete.
2701.34Snisimura	 * FIFO depth * character time,
2711.34Snisimura	 * character time = (1000000 / (defaultrate / 10))
2721.34Snisimura	 */
2731.34Snisimura	DELAY(160000000 / 9600);	/* XXX */
2741.34Snisimura
2751.51Sad#ifdef WSCONS
2761.51Sad	zs_ioasic_cnattach(ioasic_base, 0x180000, 1);
2771.51Sad#else
2781.34Snisimura	scc_cnattach(ioasic_base, 0x180000);
2791.51Sad#endif
2801.1Sjonathan}
2811.1Sjonathan
2821.31Ssimonbstatic void
2831.33Ssimonbdec_3min_intr_establish(dev, cookie, level, handler, arg)
2841.33Ssimonb	struct device *dev;
2851.33Ssimonb	void *cookie;
2861.33Ssimonb	int level;
2871.24Snisimura	int (*handler) __P((void *));
2881.33Ssimonb	void *arg;
2891.1Sjonathan{
2901.13Ssimonb	unsigned mask;
2911.1Sjonathan
2921.35Snisimura	switch ((int)cookie) {
2931.1Sjonathan		/* slots 0-2 don't interrupt through the IOASIC. */
2941.35Snisimura	  case SYS_DEV_OPT0:
2951.33Ssimonb		mask = MIPS_INT_MASK_0;
2961.33Ssimonb		break;
2971.35Snisimura	  case SYS_DEV_OPT1:
2981.33Ssimonb		mask = MIPS_INT_MASK_1;
2991.33Ssimonb		break;
3001.35Snisimura	  case SYS_DEV_OPT2:
3011.33Ssimonb		mask = MIPS_INT_MASK_2;
3021.33Ssimonb		break;
3031.1Sjonathan
3041.35Snisimura	  case SYS_DEV_SCSI:
3051.7Sjonathan		mask = (IOASIC_INTR_SCSI | IOASIC_INTR_SCSI_PTR_LOAD |
3061.7Sjonathan			IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E);
3071.1Sjonathan		break;
3081.35Snisimura	  case SYS_DEV_LANCE:
3091.1Sjonathan		mask = KMIN_INTR_LANCE;
3101.1Sjonathan		break;
3111.35Snisimura	  case SYS_DEV_SCC0:
3121.1Sjonathan		mask = KMIN_INTR_SCC_0;
3131.1Sjonathan		break;
3141.35Snisimura	  case SYS_DEV_SCC1:
3151.1Sjonathan		mask = KMIN_INTR_SCC_1;
3161.1Sjonathan		break;
3171.33Ssimonb	  default:
3181.33Ssimonb#ifdef DIAGNOSTIC
3191.35Snisimura		printf("warning: enabling unknown intr %x\n", (int)cookie);
3201.33Ssimonb#endif
3211.1Sjonathan		return;
3221.1Sjonathan	}
3231.1Sjonathan
3241.38Sad#if defined(DEBUG)
3251.36Sad	printf("3MIN: imask %x, enabling slot %d, dev %p handler %p\n",
3261.36Sad	    kmin_tc3_imask, (int)cookie, dev, handler);
3271.1Sjonathan#endif
3281.1Sjonathan
3291.1Sjonathan	/*
3301.1Sjonathan	 * Enable the interrupt  handler, and if it's an IOASIC
3311.1Sjonathan	 * slot, set the IOASIC interrupt mask.
3321.1Sjonathan	 * Otherwise, set the appropriate spl level in the R3000
3331.1Sjonathan	 * register.
3341.35Snisimura	 * Be careful to set handlers before enabling, and disable
3351.1Sjonathan	 * interrupts before clearing handlers.
3361.1Sjonathan	 */
3371.1Sjonathan
3381.33Ssimonb	/* Set the interrupt handler and argument ... */
3391.35Snisimura	intrtab[(int)cookie].ih_func = handler;
3401.35Snisimura	intrtab[(int)cookie].ih_arg = arg;
3411.33Ssimonb	/* ... and set the relevant mask */
3421.35Snisimura	switch ((int)cookie) {
3431.35Snisimura	case SYS_DEV_OPT0:
3441.35Snisimura	case SYS_DEV_OPT1:
3451.35Snisimura	case SYS_DEV_OPT2:
3461.33Ssimonb		/* it's an option slot */
3471.35Snisimura		{
3481.33Ssimonb		int s = splhigh();
3491.33Ssimonb		s |= mask;
3501.33Ssimonb		splx(s);
3511.35Snisimura		}
3521.35Snisimura		break;
3531.35Snisimura	default:
3541.35Snisimura		/* it's a baseboard device going via the IOASIC */
3551.33Ssimonb		kmin_tc3_imask |= mask;
3561.35Snisimura		break;
3571.1Sjonathan	}
3581.33Ssimonb
3591.25Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_IMSK) = kmin_tc3_imask;
3601.25Snisimura	kn02ba_wbflush();
3611.1Sjonathan}
3621.1Sjonathan
3631.1Sjonathan
3641.44Stsutsui#define CHECKINTR(slot, bits)					\
3651.35Snisimura    do {							\
3661.44Stsutsui	if (can_serve & (bits)) {				\
3671.52Ssimonb		intrtab[slot].ih_count.ev_count++;		\
3681.44Stsutsui		(*intrtab[slot].ih_func)(intrtab[slot].ih_arg);	\
3691.44Stsutsui	}							\
3701.35Snisimura    } while (0)
3711.1Sjonathan
3721.42Snisimurastatic void
3731.39Snisimuradec_3min_intr(status, cause, pc, ipending)
3741.17Snisimura	unsigned status;
3751.17Snisimura	unsigned cause;
3761.39Snisimura	unsigned pc;
3771.39Snisimura	unsigned ipending;
3781.1Sjonathan{
3791.1Sjonathan	static int user_warned = 0;
3801.17Snisimura	static int intr_depth = 0;
3811.17Snisimura	u_int32_t old_mask;
3821.1Sjonathan
3831.10Sjonathan	intr_depth++;
3841.17Snisimura	old_mask = *(u_int32_t *)(ioasic_base + IOASIC_IMSK);
3851.10Sjonathan
3861.39Snisimura	if (ipending & MIPS_INT_MASK_4)
3871.1Sjonathan		prom_haltbutton();
3881.1Sjonathan
3891.39Snisimura	if (ipending & MIPS_INT_MASK_3) {
3901.10Sjonathan		/* NB: status & MIPS_INT_MASK3 must also be set */
3911.10Sjonathan		/* masked interrupts are still observable */
3921.35Snisimura		u_int32_t intr, imsk, can_serve, turnoff;
3931.17Snisimura
3941.17Snisimura		turnoff = 0;
3951.17Snisimura		intr = *(u_int32_t *)(ioasic_base + IOASIC_INTR);
3961.17Snisimura		imsk = *(u_int32_t *)(ioasic_base + IOASIC_IMSK);
3971.35Snisimura		can_serve = intr & imsk;
3981.1Sjonathan
3991.7Sjonathan		if (intr & IOASIC_INTR_SCSI_PTR_LOAD) {
4001.17Snisimura			turnoff |= IOASIC_INTR_SCSI_PTR_LOAD;
4011.1Sjonathan#ifdef notdef
4021.1Sjonathan			asc_dma_intr();
4031.1Sjonathan#endif
4041.1Sjonathan		}
4051.12Ssimonb
4061.7Sjonathan		if (intr & (IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E))
4071.17Snisimura			turnoff |= IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E;
4081.1Sjonathan
4091.7Sjonathan		if (intr & IOASIC_INTR_LANCE_READ_E)
4101.17Snisimura			turnoff |= IOASIC_INTR_LANCE_READ_E;
4111.17Snisimura
4121.17Snisimura		if (turnoff)
4131.17Snisimura			*(u_int32_t *)(ioasic_base + IOASIC_INTR) = ~turnoff;
4141.1Sjonathan
4151.48Snisimura		if (intr & KMIN_INTR_TIMEOUT) {
4161.1Sjonathan			kn02ba_errintr();
4171.48Snisimura			pmax_memerr_evcnt.ev_count++;
4181.48Snisimura		}
4191.12Ssimonb
4201.1Sjonathan		if (intr & KMIN_INTR_CLOCK) {
4211.17Snisimura			struct clockframe cf;
4221.17Snisimura
4231.22Snisimura			__asm __volatile("lbu $0,48(%0)" ::
4241.22Snisimura				"r"(ioasic_base + IOASIC_SLOT_8_START));
4251.6Sjonathan#ifdef MIPS3
4261.6Sjonathan			if (CPUISMIPS3) {
4271.43Scgd				latched_cycle_cnt = mips3_cp0_count_read();
4281.6Sjonathan			}
4291.6Sjonathan#endif
4301.17Snisimura			cf.pc = pc;
4311.17Snisimura			cf.sr = status;
4321.1Sjonathan			hardclock(&cf);
4331.46Snisimura			pmax_clock_evcnt.ev_count++;
4341.1Sjonathan		}
4351.10Sjonathan
4361.10Sjonathan		/* If clock interrups were enabled, re-enable them ASAP. */
4371.10Sjonathan		if (old_mask & KMIN_INTR_CLOCK) {
4381.17Snisimura			/* ioctl interrupt mask to splclock and higher */
4391.17Snisimura			*(u_int32_t *)(ioasic_base + IOASIC_IMSK)
4401.17Snisimura				= old_mask &
4411.17Snisimura					~(KMIN_INTR_SCC_0|KMIN_INTR_SCC_1 |
4421.17Snisimura					  IOASIC_INTR_LANCE|IOASIC_INTR_SCSI);
4431.14Snisimura			kn02ba_wbflush();
4441.17Snisimura			_splset(MIPS_SR_INT_IE | (status & MIPS_INT_MASK_3));
4451.10Sjonathan		}
4461.10Sjonathan
4471.11Sjonathan		if (intr_depth > 1)
4481.11Sjonathan			 goto done;
4491.11Sjonathan
4501.35Snisimura		CHECKINTR(SYS_DEV_SCC0, IOASIC_INTR_SCC_0);
4511.35Snisimura		CHECKINTR(SYS_DEV_SCC1, IOASIC_INTR_SCC_1);
4521.10Sjonathan
4531.10Sjonathan#ifdef notyet /* untested */
4541.10Sjonathan		/* If tty interrupts were enabled, re-enable them ASAP. */
4551.10Sjonathan		if ((old_mask & (KMIN_INTR_SCC_1|KMIN_INTR_SCC_0)) ==
4561.10Sjonathan		     (KMIN_INTR_SCC_1|KMIN_INTR_SCC_0)) {
4571.12Ssimonb			*imaskp = old_mask &
4581.10Sjonathan			  ~(KMIN_INTR_SCC_0|KMIN_INTR_SCC_1 |
4591.10Sjonathan			  IOASIC_INTR_LANCE|IOASIC_INTR_SCSI);
4601.14Snisimura			kn02ba_wbflush();
4611.10Sjonathan		}
4621.10Sjonathan
4631.10Sjonathan		/* XXX until we know about SPLs of TC options. */
4641.10Sjonathan		if (intr_depth > 1)
4651.10Sjonathan			 goto done;
4661.10Sjonathan#endif
4671.35Snisimura		CHECKINTR(SYS_DEV_LANCE, IOASIC_INTR_LANCE);
4681.35Snisimura		CHECKINTR(SYS_DEV_SCSI, IOASIC_INTR_SCSI);
4691.1Sjonathan
4701.1Sjonathan		if (user_warned && ((intr & KMIN_INTR_PSWARN) == 0)) {
4711.1Sjonathan			printf("%s\n", "Power supply ok now.");
4721.1Sjonathan			user_warned = 0;
4731.1Sjonathan		}
4741.1Sjonathan		if ((intr & KMIN_INTR_PSWARN) && (user_warned < 3)) {
4751.1Sjonathan			user_warned++;
4761.1Sjonathan			printf("%s\n", "Power supply overheating");
4771.1Sjonathan		}
4781.1Sjonathan	}
4791.39Snisimura	if ((ipending & MIPS_INT_MASK_0) && intrtab[SYS_DEV_OPT0].ih_func) {
4801.35Snisimura		(*intrtab[SYS_DEV_OPT0].ih_func)(intrtab[SYS_DEV_OPT0].ih_arg);
4811.52Ssimonb		intrtab[SYS_DEV_OPT0].ih_count.ev_count++;
4821.1Sjonathan 	}
4831.12Ssimonb
4841.39Snisimura	if ((ipending & MIPS_INT_MASK_1) && intrtab[SYS_DEV_OPT1].ih_func) {
4851.35Snisimura		(*intrtab[SYS_DEV_OPT1].ih_func)(intrtab[SYS_DEV_OPT1].ih_arg);
4861.52Ssimonb		intrtab[SYS_DEV_OPT1].ih_count.ev_count++;
4871.1Sjonathan	}
4881.39Snisimura	if ((ipending & MIPS_INT_MASK_2) && intrtab[SYS_DEV_OPT2].ih_func) {
4891.35Snisimura		(*intrtab[SYS_DEV_OPT2].ih_func)(intrtab[SYS_DEV_OPT2].ih_arg);
4901.52Ssimonb		intrtab[SYS_DEV_OPT2].ih_count.ev_count++;
4911.1Sjonathan	}
4921.1Sjonathan
4931.10Sjonathandone:
4941.10Sjonathan	/* restore entry state */
4951.10Sjonathan	splhigh();
4961.10Sjonathan	intr_depth--;
4971.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_IMSK) = old_mask;
4981.10Sjonathan
4991.42Snisimura	_splset(MIPS_SR_INT_IE | (status & ~cause & MIPS_HARD_INT_MASK));
5001.1Sjonathan}
5011.1Sjonathan
5021.1Sjonathan
5031.1Sjonathan
5041.1Sjonathan/*
5051.1Sjonathan ************************************************************************
5061.1Sjonathan * Extra functions
5071.1Sjonathan ************************************************************************
5081.1Sjonathan */
5091.14Snisimura
5101.31Ssimonbstatic void
5111.14Snisimurakn02ba_wbflush()
5121.14Snisimura{
5131.21Snisimura	/* read twice IOASIC_IMSK */
5141.27Ssimonb	__asm __volatile("lw $0,%0; lw $0,%0" ::
5151.27Ssimonb	    "i"(MIPS_PHYS_TO_KSEG1(KMIN_REG_IMSK)));
5161.14Snisimura}
5171.14Snisimura
5181.31Ssimonbstatic unsigned
5191.14Snisimurakn02ba_clkread()
5201.14Snisimura{
5211.14Snisimura#ifdef MIPS3
5221.14Snisimura	if (CPUISMIPS3) {
5231.14Snisimura		u_int32_t mips3_cycles;
5241.14Snisimura
5251.43Scgd		mips3_cycles = mips3_cp0_count_read() - latched_cycle_cnt;
5261.14Snisimura		/* XXX divides take 78 cycles: approximate with * 41/2048 */
5271.14Snisimura		return((mips3_cycles >> 6) + (mips3_cycles >> 8) +
5281.14Snisimura		       (mips3_cycles >> 11));
5291.14Snisimura	}
5301.14Snisimura#endif
5311.14Snisimura	return 0;
5321.1Sjonathan}
533