dec_3min.c revision 1.67
11.67Srmind/* $NetBSD: dec_3min.c,v 1.67 2011/02/08 20:20:22 rmind 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.67Srmind * 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.50Sagc * 3. Neither the name of the University nor the names of its contributors
521.50Sagc *    may be used to endorse or promote products derived from this software
531.50Sagc *    without specific prior written permission.
541.50Sagc *
551.50Sagc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
561.50Sagc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
571.50Sagc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
581.50Sagc * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
591.50Sagc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
601.50Sagc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
611.50Sagc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
621.50Sagc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
631.50Sagc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
641.50Sagc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
651.50Sagc * SUCH DAMAGE.
661.50Sagc *
671.50Sagc *	@(#)machdep.c	8.3 (Berkeley) 1/12/94
681.50Sagc */
691.1Sjonathan
701.67Srmind#include <sys/cdefs.h>
711.67Srmind__KERNEL_RCSID(0, "$NetBSD: dec_3min.c,v 1.67 2011/02/08 20:20:22 rmind Exp $");
721.1Sjonathan
731.34Snisimura#include <sys/param.h>
741.1Sjonathan#include <sys/systm.h>
751.34Snisimura#include <sys/device.h>
761.59Sjoerg#include <sys/timetc.h>
771.1Sjonathan
781.1Sjonathan#include <machine/cpu.h>
791.1Sjonathan#include <machine/intr.h>
801.1Sjonathan#include <machine/sysconf.h>
811.1Sjonathan
821.1Sjonathan#include <mips/mips/mips_mcclock.h>	/* mcclock CPUspeed estimation */
831.2Sjonathan
841.2Sjonathan/* all these to get ioasic_base */
851.2Sjonathan#include <dev/tc/tcvar.h>		/* tc type definitions for.. */
861.7Sjonathan#include <dev/tc/ioasicreg.h>		/* ioasic interrrupt masks */
871.2Sjonathan#include <dev/tc/ioasicvar.h>		/* ioasic_base */
881.1Sjonathan
891.20Ssimonb#include <pmax/pmax/machdep.h>
901.1Sjonathan#include <pmax/pmax/kmin.h>		/* 3min baseboard addresses */
911.15Snisimura#include <pmax/pmax/memc.h>		/* 3min/maxine memory errors */
921.51Sad
931.51Sad#include <pmax/pmax/cons.h>
941.51Sad#include <dev/ic/z8530sc.h>
951.51Sad#include <dev/tc/zs_ioasicvar.h>
961.51Sad#include "wsdisplay.h"
971.1Sjonathan
981.61Sdslvoid		dec_3min_init(void);		/* XXX */
991.61Sdslstatic void	dec_3min_bus_reset(void);
1001.61Sdslstatic void	dec_3min_cons_init(void);
1011.61Sdslstatic void	dec_3min_intr(unsigned, unsigned, unsigned, unsigned);
1021.61Sdslstatic void	dec_3min_intr_establish(struct device *, void *,
1031.61Sdsl		    int, int (*)(void *), void *);
1041.1Sjonathan
1051.61Sdslstatic void	kn02ba_wbflush(void);
1061.1Sjonathan
1071.59Sjoergstatic void	dec_3min_tc_init(void);
1081.1Sjonathan
1091.1Sjonathan/*
1101.1Sjonathan * Local declarations.
1111.1Sjonathan */
1121.65Stsutsuistatic uint32_t kmin_tc3_imask;
1131.18Snisimura
1141.57Syamtstatic const int dec_3min_ipl2spl_table[] = {
1151.57Syamt	[IPL_NONE] = 0,
1161.57Syamt	[IPL_SOFTCLOCK] = _SPL_SOFTCLOCK,
1171.57Syamt	[IPL_SOFTNET] = _SPL_SOFTNET,
1181.57Syamt	/*
1191.57Syamt	 * Since all the motherboard interrupts come through the
1201.57Syamt	 * IOASIC, it has to be turned off for all the spls and
1211.57Syamt	 * since we don't know what kinds of devices are in the
1221.57Syamt	 * TURBOchannel option slots, just splhigh().
1231.57Syamt	 */
1241.57Syamt	[IPL_VM] = MIPS_SPL_0_1_2_3,
1251.58Sad	[IPL_SCHED] = MIPS_SPL_0_1_2_3,
1261.58Sad	[IPL_HIGH] = MIPS_SPL_0_1_2_3,
1271.57Syamt};
1281.1Sjonathan
1291.1Sjonathanvoid
1301.65Stsutsuidec_3min_init(void)
1311.1Sjonathan{
1321.65Stsutsui
1331.24Snisimura	platform.iobus = "tcbus";
1341.1Sjonathan	platform.bus_reset = dec_3min_bus_reset;
1351.1Sjonathan	platform.cons_init = dec_3min_cons_init;
1361.22Snisimura	platform.iointr = dec_3min_intr;
1371.33Ssimonb	platform.intr_establish = dec_3min_intr_establish;
1381.47Smhitch	platform.memsize = memsize_bitmap;
1391.59Sjoerg	platform.tc_init = dec_3min_tc_init;
1401.1Sjonathan
1411.22Snisimura	/* clear any memory errors */
1421.65Stsutsui	*(volatile uint32_t *)MIPS_PHYS_TO_KSEG1(KMIN_REG_TIMEOUT) = 0;
1431.14Snisimura	kn02ba_wbflush();
1441.1Sjonathan
1451.1Sjonathan	ioasic_base = MIPS_PHYS_TO_KSEG1(KMIN_SYS_ASIC);
1461.1Sjonathan
1471.57Syamt	ipl2spl_table = dec_3min_ipl2spl_table;
1481.16Snisimura
1491.28Snisimura	/* enable posting of MIPS_INT_MASK_3 to CAUSE register */
1501.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_IMSK) = KMIN_INTR_CLOCK;
1511.44Stsutsui	/* calibrate cpu_mhz value */
1521.29Snisimura	mc_cpuspeed(ioasic_base+IOASIC_SLOT_8_START, MIPS_INT_MASK_3);
1531.1Sjonathan
1541.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_LANCE_DECODE) = 0x3;
1551.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_SCSI_DECODE) = 0xe;
1561.44Stsutsui#if 0
1571.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_SCC0_DECODE) = (0x10|4);
1581.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_SCC1_DECODE) = (0x10|6);
1591.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_CSR) = 0x00000f00;
1601.44Stsutsui#endif
1611.44Stsutsui
1621.22Snisimura	/* sanitize interrupt mask */
1631.22Snisimura	kmin_tc3_imask = (KMIN_INTR_CLOCK|KMIN_INTR_PSWARN|KMIN_INTR_TIMEOUT);
1641.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_INTR) = 0;
1651.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_IMSK) = kmin_tc3_imask;
1661.1Sjonathan
1671.1Sjonathan	/*
1681.22Snisimura	 * The kmin memory hardware seems to wrap memory addresses
1691.1Sjonathan	 * with 4Mbyte SIMMs, which causes the physmem computation
1701.1Sjonathan	 * to lose.  Find out how big the SIMMS are and set
1711.22Snisimura	 * max_ physmem accordingly.
1721.22Snisimura	 * XXX Do MAXINEs lose the same way?
1731.1Sjonathan	 */
1741.1Sjonathan	physmem_boardmax = KMIN_PHYS_MEMORY_END + 1;
1751.22Snisimura	if ((KMIN_MSR_SIZE_16Mb & *(int *)MIPS_PHYS_TO_KSEG1(KMIN_REG_MSR))
1761.65Stsutsui	    == 0)
1771.1Sjonathan		physmem_boardmax = physmem_boardmax >> 2;
1781.1Sjonathan	physmem_boardmax = MIPS_PHYS_TO_KSEG1(physmem_boardmax);
1791.10Sjonathan
1801.22Snisimura	sprintf(cpu_model, "DECstation 5000/1%d (3MIN)", cpu_mhz);
1811.22Snisimura}
1821.22Snisimura
1831.22Snisimura/*
1841.49Stsutsui * Initialize the memory system and I/O buses.
1851.22Snisimura */
1861.31Ssimonbstatic void
1871.65Stsutsuidec_3min_bus_reset(void)
1881.22Snisimura{
1891.22Snisimura
1901.22Snisimura	/*
1911.22Snisimura	 * Reset interrupts, clear any errors from newconf probes
1921.22Snisimura	 */
1931.22Snisimura
1941.65Stsutsui	*(volatile uint32_t *)MIPS_PHYS_TO_KSEG1(KMIN_REG_TIMEOUT) = 0;
1951.17Snisimura	kn02ba_wbflush();
1961.17Snisimura
1971.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_INTR) = 0;
1981.22Snisimura	kn02ba_wbflush();
1991.1Sjonathan}
2001.1Sjonathan
2011.31Ssimonbstatic void
2021.65Stsutsuidec_3min_cons_init(void)
2031.1Sjonathan{
2041.34Snisimura	int kbd, crt, screen;
2051.34Snisimura
2061.34Snisimura	kbd = crt = screen = 0;
2071.34Snisimura	prom_findcons(&kbd, &crt, &screen);
2081.34Snisimura
2091.34Snisimura	if (screen > 0) {
2101.51Sad#if NWSDISPLAY > 0
2111.51Sad 		if (tcfb_cnattach(crt) > 0) {
2121.51Sad			zs_ioasic_lk201_cnattach(ioasic_base, 0x180000, 0);
2131.51Sad 			return;
2141.51Sad 		}
2151.34Snisimura#endif
2161.34Snisimura		printf("No framebuffer device configured for slot %d: ", crt);
2171.34Snisimura		printf("using serial console\n");
2181.34Snisimura	}
2191.34Snisimura	/*
2201.34Snisimura	 * Delay to allow PROM putchars to complete.
2211.34Snisimura	 * FIFO depth * character time,
2221.34Snisimura	 * character time = (1000000 / (defaultrate / 10))
2231.34Snisimura	 */
2241.34Snisimura	DELAY(160000000 / 9600);	/* XXX */
2251.34Snisimura
2261.51Sad	zs_ioasic_cnattach(ioasic_base, 0x180000, 1);
2271.1Sjonathan}
2281.1Sjonathan
2291.31Ssimonbstatic void
2301.65Stsutsuidec_3min_intr_establish(struct device *dev, void *cookie, int level,
2311.65Stsutsui    int (*handler)(void *), void *arg)
2321.1Sjonathan{
2331.65Stsutsui	uint32_t mask;
2341.1Sjonathan
2351.66Smatt	switch ((uintptr_t)cookie) {
2361.1Sjonathan		/* slots 0-2 don't interrupt through the IOASIC. */
2371.65Stsutsui	case SYS_DEV_OPT0:
2381.33Ssimonb		mask = MIPS_INT_MASK_0;
2391.33Ssimonb		break;
2401.65Stsutsui	case SYS_DEV_OPT1:
2411.33Ssimonb		mask = MIPS_INT_MASK_1;
2421.33Ssimonb		break;
2431.65Stsutsui	case SYS_DEV_OPT2:
2441.33Ssimonb		mask = MIPS_INT_MASK_2;
2451.33Ssimonb		break;
2461.1Sjonathan
2471.65Stsutsui	case SYS_DEV_SCSI:
2481.7Sjonathan		mask = (IOASIC_INTR_SCSI | IOASIC_INTR_SCSI_PTR_LOAD |
2491.7Sjonathan			IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E);
2501.1Sjonathan		break;
2511.65Stsutsui	case SYS_DEV_LANCE:
2521.1Sjonathan		mask = KMIN_INTR_LANCE;
2531.1Sjonathan		break;
2541.65Stsutsui	case SYS_DEV_SCC0:
2551.1Sjonathan		mask = KMIN_INTR_SCC_0;
2561.1Sjonathan		break;
2571.65Stsutsui	case SYS_DEV_SCC1:
2581.1Sjonathan		mask = KMIN_INTR_SCC_1;
2591.1Sjonathan		break;
2601.65Stsutsui	default:
2611.33Ssimonb#ifdef DIAGNOSTIC
2621.66Smatt		printf("warning: enabling unknown intr %p\n", cookie);
2631.33Ssimonb#endif
2641.1Sjonathan		return;
2651.1Sjonathan	}
2661.1Sjonathan
2671.38Sad#if defined(DEBUG)
2681.66Smatt	printf("3MIN: imask %x, enabling slot %p, dev %p handler %p\n",
2691.66Smatt	    kmin_tc3_imask, cookie, dev, handler);
2701.1Sjonathan#endif
2711.1Sjonathan
2721.1Sjonathan	/*
2731.1Sjonathan	 * Enable the interrupt  handler, and if it's an IOASIC
2741.1Sjonathan	 * slot, set the IOASIC interrupt mask.
2751.1Sjonathan	 * Otherwise, set the appropriate spl level in the R3000
2761.1Sjonathan	 * register.
2771.35Snisimura	 * Be careful to set handlers before enabling, and disable
2781.1Sjonathan	 * interrupts before clearing handlers.
2791.1Sjonathan	 */
2801.1Sjonathan
2811.33Ssimonb	/* Set the interrupt handler and argument ... */
2821.66Smatt	intrtab[(uintptr_t)cookie].ih_func = handler;
2831.66Smatt	intrtab[(uintptr_t)cookie].ih_arg = arg;
2841.33Ssimonb	/* ... and set the relevant mask */
2851.66Smatt	switch ((uintptr_t)cookie) {
2861.35Snisimura	case SYS_DEV_OPT0:
2871.35Snisimura	case SYS_DEV_OPT1:
2881.35Snisimura	case SYS_DEV_OPT2:
2891.33Ssimonb		/* it's an option slot */
2901.35Snisimura		{
2911.33Ssimonb		int s = splhigh();
2921.33Ssimonb		s |= mask;
2931.33Ssimonb		splx(s);
2941.35Snisimura		}
2951.35Snisimura		break;
2961.35Snisimura	default:
2971.35Snisimura		/* it's a baseboard device going via the IOASIC */
2981.33Ssimonb		kmin_tc3_imask |= mask;
2991.35Snisimura		break;
3001.1Sjonathan	}
3011.33Ssimonb
3021.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_IMSK) = kmin_tc3_imask;
3031.25Snisimura	kn02ba_wbflush();
3041.1Sjonathan}
3051.1Sjonathan
3061.1Sjonathan
3071.44Stsutsui#define CHECKINTR(slot, bits)					\
3081.35Snisimura    do {							\
3091.44Stsutsui	if (can_serve & (bits)) {				\
3101.52Ssimonb		intrtab[slot].ih_count.ev_count++;		\
3111.44Stsutsui		(*intrtab[slot].ih_func)(intrtab[slot].ih_arg);	\
3121.44Stsutsui	}							\
3131.65Stsutsui    } while (/*CONSTCOND*/0)
3141.1Sjonathan
3151.42Snisimurastatic void
3161.65Stsutsuidec_3min_intr(uint32_t status, uint32_t cause, uint32_t pc, uint32_t ipending)
3171.1Sjonathan{
3181.1Sjonathan	static int user_warned = 0;
3191.17Snisimura	static int intr_depth = 0;
3201.65Stsutsui	uint32_t old_mask;
3211.1Sjonathan
3221.10Sjonathan	intr_depth++;
3231.65Stsutsui	old_mask = *(volatile uint32_t *)(ioasic_base + IOASIC_IMSK);
3241.10Sjonathan
3251.39Snisimura	if (ipending & MIPS_INT_MASK_4)
3261.1Sjonathan		prom_haltbutton();
3271.1Sjonathan
3281.39Snisimura	if (ipending & MIPS_INT_MASK_3) {
3291.10Sjonathan		/* NB: status & MIPS_INT_MASK3 must also be set */
3301.10Sjonathan		/* masked interrupts are still observable */
3311.65Stsutsui		uint32_t intr, imsk, can_serve, turnoff;
3321.17Snisimura
3331.17Snisimura		turnoff = 0;
3341.65Stsutsui		intr = *(volatile uint32_t *)(ioasic_base + IOASIC_INTR);
3351.65Stsutsui		imsk = *(volatile uint32_t *)(ioasic_base + IOASIC_IMSK);
3361.35Snisimura		can_serve = intr & imsk;
3371.1Sjonathan
3381.7Sjonathan		if (intr & IOASIC_INTR_SCSI_PTR_LOAD) {
3391.17Snisimura			turnoff |= IOASIC_INTR_SCSI_PTR_LOAD;
3401.1Sjonathan#ifdef notdef
3411.1Sjonathan			asc_dma_intr();
3421.1Sjonathan#endif
3431.1Sjonathan		}
3441.12Ssimonb
3451.7Sjonathan		if (intr & (IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E))
3461.65Stsutsui			turnoff |=
3471.65Stsutsui			    IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E;
3481.1Sjonathan
3491.7Sjonathan		if (intr & IOASIC_INTR_LANCE_READ_E)
3501.17Snisimura			turnoff |= IOASIC_INTR_LANCE_READ_E;
3511.17Snisimura
3521.17Snisimura		if (turnoff)
3531.65Stsutsui			*(volatile uint32_t *)(ioasic_base + IOASIC_INTR) =
3541.65Stsutsui			    ~turnoff;
3551.1Sjonathan
3561.48Snisimura		if (intr & KMIN_INTR_TIMEOUT) {
3571.1Sjonathan			kn02ba_errintr();
3581.48Snisimura			pmax_memerr_evcnt.ev_count++;
3591.48Snisimura		}
3601.12Ssimonb
3611.1Sjonathan		if (intr & KMIN_INTR_CLOCK) {
3621.17Snisimura			struct clockframe cf;
3631.17Snisimura
3641.54Sperry			__asm volatile("lbu $0,48(%0)" ::
3651.22Snisimura				"r"(ioasic_base + IOASIC_SLOT_8_START));
3661.59Sjoerg
3671.17Snisimura			cf.pc = pc;
3681.17Snisimura			cf.sr = status;
3691.1Sjonathan			hardclock(&cf);
3701.46Snisimura			pmax_clock_evcnt.ev_count++;
3711.1Sjonathan		}
3721.10Sjonathan
3731.55Swiz		/* If clock interrupts were enabled, re-enable them ASAP. */
3741.10Sjonathan		if (old_mask & KMIN_INTR_CLOCK) {
3751.17Snisimura			/* ioctl interrupt mask to splclock and higher */
3761.65Stsutsui			*(volatile uint32_t *)(ioasic_base + IOASIC_IMSK)
3771.17Snisimura				= old_mask &
3781.17Snisimura					~(KMIN_INTR_SCC_0|KMIN_INTR_SCC_1 |
3791.17Snisimura					  IOASIC_INTR_LANCE|IOASIC_INTR_SCSI);
3801.14Snisimura			kn02ba_wbflush();
3811.17Snisimura			_splset(MIPS_SR_INT_IE | (status & MIPS_INT_MASK_3));
3821.10Sjonathan		}
3831.10Sjonathan
3841.11Sjonathan		if (intr_depth > 1)
3851.11Sjonathan			 goto done;
3861.11Sjonathan
3871.35Snisimura		CHECKINTR(SYS_DEV_SCC0, IOASIC_INTR_SCC_0);
3881.35Snisimura		CHECKINTR(SYS_DEV_SCC1, IOASIC_INTR_SCC_1);
3891.10Sjonathan
3901.10Sjonathan#ifdef notyet /* untested */
3911.10Sjonathan		/* If tty interrupts were enabled, re-enable them ASAP. */
3921.10Sjonathan		if ((old_mask & (KMIN_INTR_SCC_1|KMIN_INTR_SCC_0)) ==
3931.10Sjonathan		     (KMIN_INTR_SCC_1|KMIN_INTR_SCC_0)) {
3941.12Ssimonb			*imaskp = old_mask &
3951.10Sjonathan			  ~(KMIN_INTR_SCC_0|KMIN_INTR_SCC_1 |
3961.10Sjonathan			  IOASIC_INTR_LANCE|IOASIC_INTR_SCSI);
3971.14Snisimura			kn02ba_wbflush();
3981.10Sjonathan		}
3991.10Sjonathan
4001.10Sjonathan		/* XXX until we know about SPLs of TC options. */
4011.10Sjonathan		if (intr_depth > 1)
4021.10Sjonathan			 goto done;
4031.10Sjonathan#endif
4041.35Snisimura		CHECKINTR(SYS_DEV_LANCE, IOASIC_INTR_LANCE);
4051.35Snisimura		CHECKINTR(SYS_DEV_SCSI, IOASIC_INTR_SCSI);
4061.1Sjonathan
4071.1Sjonathan		if (user_warned && ((intr & KMIN_INTR_PSWARN) == 0)) {
4081.1Sjonathan			printf("%s\n", "Power supply ok now.");
4091.1Sjonathan			user_warned = 0;
4101.1Sjonathan		}
4111.1Sjonathan		if ((intr & KMIN_INTR_PSWARN) && (user_warned < 3)) {
4121.1Sjonathan			user_warned++;
4131.1Sjonathan			printf("%s\n", "Power supply overheating");
4141.1Sjonathan		}
4151.1Sjonathan	}
4161.39Snisimura	if ((ipending & MIPS_INT_MASK_0) && intrtab[SYS_DEV_OPT0].ih_func) {
4171.35Snisimura		(*intrtab[SYS_DEV_OPT0].ih_func)(intrtab[SYS_DEV_OPT0].ih_arg);
4181.52Ssimonb		intrtab[SYS_DEV_OPT0].ih_count.ev_count++;
4191.1Sjonathan 	}
4201.12Ssimonb
4211.39Snisimura	if ((ipending & MIPS_INT_MASK_1) && intrtab[SYS_DEV_OPT1].ih_func) {
4221.35Snisimura		(*intrtab[SYS_DEV_OPT1].ih_func)(intrtab[SYS_DEV_OPT1].ih_arg);
4231.52Ssimonb		intrtab[SYS_DEV_OPT1].ih_count.ev_count++;
4241.1Sjonathan	}
4251.39Snisimura	if ((ipending & MIPS_INT_MASK_2) && intrtab[SYS_DEV_OPT2].ih_func) {
4261.35Snisimura		(*intrtab[SYS_DEV_OPT2].ih_func)(intrtab[SYS_DEV_OPT2].ih_arg);
4271.52Ssimonb		intrtab[SYS_DEV_OPT2].ih_count.ev_count++;
4281.1Sjonathan	}
4291.1Sjonathan
4301.10Sjonathandone:
4311.10Sjonathan	/* restore entry state */
4321.10Sjonathan	splhigh();
4331.10Sjonathan	intr_depth--;
4341.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_IMSK) = old_mask;
4351.10Sjonathan
4361.42Snisimura	_splset(MIPS_SR_INT_IE | (status & ~cause & MIPS_HARD_INT_MASK));
4371.1Sjonathan}
4381.1Sjonathan
4391.1Sjonathan
4401.1Sjonathan
4411.1Sjonathan/*
4421.1Sjonathan ************************************************************************
4431.1Sjonathan * Extra functions
4441.1Sjonathan ************************************************************************
4451.1Sjonathan */
4461.14Snisimura
4471.31Ssimonbstatic void
4481.65Stsutsuikn02ba_wbflush(void)
4491.14Snisimura{
4501.65Stsutsui
4511.21Snisimura	/* read twice IOASIC_IMSK */
4521.54Sperry	__asm volatile("lw $0,%0; lw $0,%0" ::
4531.27Ssimonb	    "i"(MIPS_PHYS_TO_KSEG1(KMIN_REG_IMSK)));
4541.14Snisimura}
4551.14Snisimura
4561.59Sjoerg/*
4571.59Sjoerg * Support for using the MIPS 3 clock as a timecounter.
4581.59Sjoerg */
4591.59Sjoerg
4601.59Sjoergvoid
4611.59Sjoergdec_3min_tc_init(void)
4621.14Snisimura{
4631.60Stsutsui#if defined(MIPS3)
4641.59Sjoerg	static struct timecounter tc =  {
4651.59Sjoerg		.tc_get_timecount = (timecounter_get_t *)mips3_cp0_count_read,
4661.59Sjoerg		.tc_counter_mask = ~0u,
4671.59Sjoerg		.tc_name = "mips3_cp0_counter",
4681.59Sjoerg		.tc_quality = 100,
4691.59Sjoerg	};
4701.59Sjoerg
4711.59Sjoerg	if (MIPS_HAS_CLOCK) {
4721.59Sjoerg		tc.tc_frequency = cpu_mhz * 1000000;
4731.59Sjoerg		if (mips_cpu_flags & CPU_MIPS_DOUBLE_COUNT) {
4741.59Sjoerg			tc.tc_frequency /= 2;
4751.59Sjoerg		}
4761.59Sjoerg
4771.59Sjoerg		tc_init(&tc);
4781.14Snisimura	}
4791.60Stsutsui#endif
4801.1Sjonathan}
481