11.75Sandvar/* $NetBSD: dec_3min.c,v 1.75 2024/06/02 12:11:35 andvar 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.68Smatt#define	__INTR_PRIVATE
711.68Smatt
721.67Srmind#include <sys/cdefs.h>
731.75Sandvar__KERNEL_RCSID(0, "$NetBSD: dec_3min.c,v 1.75 2024/06/02 12:11:35 andvar Exp $");
741.1Sjonathan
751.34Snisimura#include <sys/param.h>
761.71Smatt#include <sys/cpu.h>
771.71Smatt#include <sys/device.h>
781.71Smatt#include <sys/intr.h>
791.71Smatt#include <sys/lwp.h>
801.1Sjonathan#include <sys/systm.h>
811.59Sjoerg#include <sys/timetc.h>
821.1Sjonathan
831.71Smatt#include <pmax/sysconf.h>
841.1Sjonathan
851.1Sjonathan#include <mips/mips/mips_mcclock.h>	/* mcclock CPUspeed estimation */
861.2Sjonathan
871.2Sjonathan/* all these to get ioasic_base */
881.2Sjonathan#include <dev/tc/tcvar.h>		/* tc type definitions for.. */
891.75Sandvar#include <dev/tc/ioasicreg.h>		/* ioasic interrupt masks */
901.2Sjonathan#include <dev/tc/ioasicvar.h>		/* ioasic_base */
911.1Sjonathan
921.20Ssimonb#include <pmax/pmax/machdep.h>
931.1Sjonathan#include <pmax/pmax/kmin.h>		/* 3min baseboard addresses */
941.15Snisimura#include <pmax/pmax/memc.h>		/* 3min/maxine memory errors */
951.51Sad
961.51Sad#include <pmax/pmax/cons.h>
971.51Sad#include <dev/ic/z8530sc.h>
981.51Sad#include <dev/tc/zs_ioasicvar.h>
991.51Sad#include "wsdisplay.h"
1001.1Sjonathan
1011.61Sdslvoid		dec_3min_init(void);		/* XXX */
1021.61Sdslstatic void	dec_3min_bus_reset(void);
1031.61Sdslstatic void	dec_3min_cons_init(void);
1041.68Smattstatic void	dec_3min_intr(uint32_t, vaddr_t, uint32_t);
1051.72Stsutsuistatic void	dec_3min_intr_establish(device_t, void *,
1061.61Sdsl		    int, int (*)(void *), void *);
1071.1Sjonathan
1081.61Sdslstatic void	kn02ba_wbflush(void);
1091.1Sjonathan
1101.59Sjoergstatic void	dec_3min_tc_init(void);
1111.1Sjonathan
1121.1Sjonathan/*
1131.1Sjonathan * Local declarations.
1141.1Sjonathan */
1151.65Stsutsuistatic uint32_t kmin_tc3_imask;
1161.18Snisimura
1171.68Smattstatic const struct ipl_sr_map dec_3min_ipl_sr_map = {
1181.68Smatt    .sr_bits = {
1191.57Syamt	[IPL_NONE] = 0,
1201.68Smatt	[IPL_SOFTCLOCK] = MIPS_SOFT_INT_MASK_0,
1211.68Smatt	[IPL_SOFTNET] = MIPS_SOFT_INT_MASK,
1221.57Syamt	/*
1231.57Syamt	 * Since all the motherboard interrupts come through the
1241.57Syamt	 * IOASIC, it has to be turned off for all the spls and
1251.57Syamt	 * since we don't know what kinds of devices are in the
1261.57Syamt	 * TURBOchannel option slots, just splhigh().
1271.57Syamt	 */
1281.68Smatt	[IPL_VM] = MIPS_SPLHIGH,
1291.68Smatt	[IPL_SCHED] = MIPS_SPLHIGH,
1301.68Smatt	[IPL_DDB] = MIPS_SPLHIGH,
1311.68Smatt	[IPL_HIGH] = MIPS_SPLHIGH,
1321.68Smatt    },
1331.57Syamt};
1341.1Sjonathan
1351.1Sjonathanvoid
1361.65Stsutsuidec_3min_init(void)
1371.1Sjonathan{
1381.65Stsutsui
1391.24Snisimura	platform.iobus = "tcbus";
1401.1Sjonathan	platform.bus_reset = dec_3min_bus_reset;
1411.1Sjonathan	platform.cons_init = dec_3min_cons_init;
1421.22Snisimura	platform.iointr = dec_3min_intr;
1431.33Ssimonb	platform.intr_establish = dec_3min_intr_establish;
1441.47Smhitch	platform.memsize = memsize_bitmap;
1451.59Sjoerg	platform.tc_init = dec_3min_tc_init;
1461.1Sjonathan
1471.22Snisimura	/* clear any memory errors */
1481.65Stsutsui	*(volatile uint32_t *)MIPS_PHYS_TO_KSEG1(KMIN_REG_TIMEOUT) = 0;
1491.14Snisimura	kn02ba_wbflush();
1501.1Sjonathan
1511.1Sjonathan	ioasic_base = MIPS_PHYS_TO_KSEG1(KMIN_SYS_ASIC);
1521.1Sjonathan
1531.68Smatt	ipl_sr_map = dec_3min_ipl_sr_map;
1541.16Snisimura
1551.28Snisimura	/* enable posting of MIPS_INT_MASK_3 to CAUSE register */
1561.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_IMSK) = KMIN_INTR_CLOCK;
1571.44Stsutsui	/* calibrate cpu_mhz value */
1581.29Snisimura	mc_cpuspeed(ioasic_base+IOASIC_SLOT_8_START, MIPS_INT_MASK_3);
1591.1Sjonathan
1601.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_LANCE_DECODE) = 0x3;
1611.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_SCSI_DECODE) = 0xe;
1621.44Stsutsui#if 0
1631.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_SCC0_DECODE) = (0x10|4);
1641.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_SCC1_DECODE) = (0x10|6);
1651.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_CSR) = 0x00000f00;
1661.44Stsutsui#endif
1671.44Stsutsui
1681.22Snisimura	/* sanitize interrupt mask */
1691.22Snisimura	kmin_tc3_imask = (KMIN_INTR_CLOCK|KMIN_INTR_PSWARN|KMIN_INTR_TIMEOUT);
1701.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_INTR) = 0;
1711.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_IMSK) = kmin_tc3_imask;
1721.1Sjonathan
1731.1Sjonathan	/*
1741.22Snisimura	 * The kmin memory hardware seems to wrap memory addresses
1751.1Sjonathan	 * with 4Mbyte SIMMs, which causes the physmem computation
1761.1Sjonathan	 * to lose.  Find out how big the SIMMS are and set
1771.22Snisimura	 * max_ physmem accordingly.
1781.22Snisimura	 * XXX Do MAXINEs lose the same way?
1791.1Sjonathan	 */
1801.1Sjonathan	physmem_boardmax = KMIN_PHYS_MEMORY_END + 1;
1811.22Snisimura	if ((KMIN_MSR_SIZE_16Mb & *(int *)MIPS_PHYS_TO_KSEG1(KMIN_REG_MSR))
1821.65Stsutsui	    == 0)
1831.1Sjonathan		physmem_boardmax = physmem_boardmax >> 2;
1841.1Sjonathan	physmem_boardmax = MIPS_PHYS_TO_KSEG1(physmem_boardmax);
1851.10Sjonathan
1861.73Schristos	cpu_setmodel("DECstation 5000/1%d (3MIN)", mips_options.mips_cpu_mhz);
1871.22Snisimura}
1881.22Snisimura
1891.22Snisimura/*
1901.49Stsutsui * Initialize the memory system and I/O buses.
1911.22Snisimura */
1921.31Ssimonbstatic void
1931.65Stsutsuidec_3min_bus_reset(void)
1941.22Snisimura{
1951.22Snisimura
1961.22Snisimura	/*
1971.22Snisimura	 * Reset interrupts, clear any errors from newconf probes
1981.22Snisimura	 */
1991.22Snisimura
2001.65Stsutsui	*(volatile uint32_t *)MIPS_PHYS_TO_KSEG1(KMIN_REG_TIMEOUT) = 0;
2011.17Snisimura	kn02ba_wbflush();
2021.17Snisimura
2031.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_INTR) = 0;
2041.22Snisimura	kn02ba_wbflush();
2051.1Sjonathan}
2061.1Sjonathan
2071.31Ssimonbstatic void
2081.65Stsutsuidec_3min_cons_init(void)
2091.1Sjonathan{
2101.34Snisimura	int kbd, crt, screen;
2111.34Snisimura
2121.34Snisimura	kbd = crt = screen = 0;
2131.34Snisimura	prom_findcons(&kbd, &crt, &screen);
2141.34Snisimura
2151.34Snisimura	if (screen > 0) {
2161.51Sad#if NWSDISPLAY > 0
2171.51Sad 		if (tcfb_cnattach(crt) > 0) {
2181.51Sad			zs_ioasic_lk201_cnattach(ioasic_base, 0x180000, 0);
2191.51Sad 			return;
2201.51Sad 		}
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.51Sad	zs_ioasic_cnattach(ioasic_base, 0x180000, 1);
2331.1Sjonathan}
2341.1Sjonathan
2351.31Ssimonbstatic void
2361.72Stsutsuidec_3min_intr_establish(device_t dev, void *cookie, int level,
2371.65Stsutsui    int (*handler)(void *), void *arg)
2381.1Sjonathan{
2391.65Stsutsui	uint32_t mask;
2401.1Sjonathan
2411.66Smatt	switch ((uintptr_t)cookie) {
2421.1Sjonathan		/* slots 0-2 don't interrupt through the IOASIC. */
2431.65Stsutsui	case SYS_DEV_OPT0:
2441.33Ssimonb		mask = MIPS_INT_MASK_0;
2451.33Ssimonb		break;
2461.65Stsutsui	case SYS_DEV_OPT1:
2471.33Ssimonb		mask = MIPS_INT_MASK_1;
2481.33Ssimonb		break;
2491.65Stsutsui	case SYS_DEV_OPT2:
2501.33Ssimonb		mask = MIPS_INT_MASK_2;
2511.33Ssimonb		break;
2521.1Sjonathan
2531.65Stsutsui	case SYS_DEV_SCSI:
2541.7Sjonathan		mask = (IOASIC_INTR_SCSI | IOASIC_INTR_SCSI_PTR_LOAD |
2551.7Sjonathan			IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E);
2561.1Sjonathan		break;
2571.65Stsutsui	case SYS_DEV_LANCE:
2581.1Sjonathan		mask = KMIN_INTR_LANCE;
2591.1Sjonathan		break;
2601.65Stsutsui	case SYS_DEV_SCC0:
2611.1Sjonathan		mask = KMIN_INTR_SCC_0;
2621.1Sjonathan		break;
2631.65Stsutsui	case SYS_DEV_SCC1:
2641.1Sjonathan		mask = KMIN_INTR_SCC_1;
2651.1Sjonathan		break;
2661.65Stsutsui	default:
2671.33Ssimonb#ifdef DIAGNOSTIC
2681.66Smatt		printf("warning: enabling unknown intr %p\n", cookie);
2691.33Ssimonb#endif
2701.1Sjonathan		return;
2711.1Sjonathan	}
2721.1Sjonathan
2731.38Sad#if defined(DEBUG)
2741.66Smatt	printf("3MIN: imask %x, enabling slot %p, dev %p handler %p\n",
2751.66Smatt	    kmin_tc3_imask, cookie, dev, handler);
2761.1Sjonathan#endif
2771.1Sjonathan
2781.1Sjonathan	/*
2791.1Sjonathan	 * Enable the interrupt  handler, and if it's an IOASIC
2801.1Sjonathan	 * slot, set the IOASIC interrupt mask.
2811.1Sjonathan	 * Otherwise, set the appropriate spl level in the R3000
2821.1Sjonathan	 * register.
2831.35Snisimura	 * Be careful to set handlers before enabling, and disable
2841.1Sjonathan	 * interrupts before clearing handlers.
2851.1Sjonathan	 */
2861.1Sjonathan
2871.33Ssimonb	/* Set the interrupt handler and argument ... */
2881.66Smatt	intrtab[(uintptr_t)cookie].ih_func = handler;
2891.66Smatt	intrtab[(uintptr_t)cookie].ih_arg = arg;
2901.33Ssimonb	/* ... and set the relevant mask */
2911.66Smatt	switch ((uintptr_t)cookie) {
2921.35Snisimura	case SYS_DEV_OPT0:
2931.35Snisimura	case SYS_DEV_OPT1:
2941.35Snisimura	case SYS_DEV_OPT2:
2951.74Stsutsui		/* it's an option slot and handled via MIPS_INT_MASK_[012] */
2961.35Snisimura		break;
2971.35Snisimura	default:
2981.35Snisimura		/* it's a baseboard device going via the IOASIC */
2991.33Ssimonb		kmin_tc3_imask |= mask;
3001.35Snisimura		break;
3011.1Sjonathan	}
3021.33Ssimonb
3031.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_IMSK) = kmin_tc3_imask;
3041.25Snisimura	kn02ba_wbflush();
3051.1Sjonathan}
3061.1Sjonathan
3071.1Sjonathan
3081.44Stsutsui#define CHECKINTR(slot, bits)					\
3091.35Snisimura    do {							\
3101.44Stsutsui	if (can_serve & (bits)) {				\
3111.52Ssimonb		intrtab[slot].ih_count.ev_count++;		\
3121.44Stsutsui		(*intrtab[slot].ih_func)(intrtab[slot].ih_arg);	\
3131.44Stsutsui	}							\
3141.65Stsutsui    } while (/*CONSTCOND*/0)
3151.1Sjonathan
3161.42Snisimurastatic void
3171.68Smattdec_3min_intr(uint32_t status, vaddr_t pc, uint32_t ipending)
3181.1Sjonathan{
3191.1Sjonathan	static int user_warned = 0;
3201.65Stsutsui	uint32_t old_mask;
3211.1Sjonathan
3221.65Stsutsui	old_mask = *(volatile uint32_t *)(ioasic_base + IOASIC_IMSK);
3231.10Sjonathan
3241.68Smatt	do {
3251.68Smatt		if (ipending & MIPS_INT_MASK_4)
3261.68Smatt			prom_haltbutton();
3271.68Smatt
3281.68Smatt		if (ipending & MIPS_INT_MASK_3) {
3291.68Smatt			/* NB: status & MIPS_INT_MASK3 must also be set */
3301.68Smatt			/* masked interrupts are still observable */
3311.68Smatt			uint32_t intr, imsk, can_serve, turnoff;
3321.68Smatt
3331.68Smatt			turnoff = 0;
3341.68Smatt			intr = *(volatile uint32_t *)(ioasic_base + IOASIC_INTR);
3351.68Smatt			imsk = *(volatile uint32_t *)(ioasic_base + IOASIC_IMSK);
3361.68Smatt			can_serve = intr & imsk;
3371.1Sjonathan
3381.68Smatt			if (intr & IOASIC_INTR_SCSI_PTR_LOAD) {
3391.68Smatt				turnoff |= IOASIC_INTR_SCSI_PTR_LOAD;
3401.1Sjonathan#ifdef notdef
3411.68Smatt				asc_dma_intr();
3421.1Sjonathan#endif
3431.68Smatt			}
3441.12Ssimonb
3451.68Smatt			if (intr & (IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E))
3461.68Smatt				turnoff |= IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E;
3471.12Ssimonb
3481.68Smatt			if (intr & IOASIC_INTR_LANCE_READ_E)
3491.68Smatt				turnoff |= IOASIC_INTR_LANCE_READ_E;
3501.17Snisimura
3511.68Smatt			if (turnoff)
3521.68Smatt				*(volatile uint32_t *)(ioasic_base + IOASIC_INTR) = ~turnoff;
3531.68Smatt
3541.68Smatt			if (intr & KMIN_INTR_TIMEOUT) {
3551.68Smatt				kn02ba_errintr();
3561.68Smatt				pmax_memerr_evcnt.ev_count++;
3571.68Smatt			}
3581.68Smatt
3591.68Smatt			if (intr & KMIN_INTR_CLOCK) {
3601.68Smatt				struct clockframe cf;
3611.68Smatt
3621.68Smatt				__asm volatile("lbu $0,48(%0)" ::
3631.68Smatt					"r"(ioasic_base + IOASIC_SLOT_8_START));
3641.68Smatt
3651.68Smatt				cf.pc = pc;
3661.68Smatt				cf.sr = status;
3671.69Stsutsui				cf.intr = (curcpu()->ci_idepth > 1);
3681.68Smatt				hardclock(&cf);
3691.68Smatt				pmax_clock_evcnt.ev_count++;
3701.68Smatt			}
3711.68Smatt
3721.68Smatt			/* If clock interrupts were enabled, re-enable them ASAP. */
3731.68Smatt			if (old_mask & KMIN_INTR_CLOCK) {
3741.68Smatt				/* ioctl interrupt mask to splclock and higher */
3751.68Smatt				*(uint32_t *)(ioasic_base + IOASIC_IMSK) =
3761.68Smatt				    old_mask &
3771.68Smatt					~(KMIN_INTR_SCC_0|KMIN_INTR_SCC_1
3781.68Smatt					  |IOASIC_INTR_LANCE|IOASIC_INTR_SCSI);
3791.68Smatt				kn02ba_wbflush();
3801.68Smatt			}
3811.59Sjoerg
3821.68Smatt			if (curcpu()->ci_idepth > 1)
3831.68Smatt				 break;
3841.10Sjonathan
3851.68Smatt			CHECKINTR(SYS_DEV_SCC0, IOASIC_INTR_SCC_0);
3861.68Smatt			CHECKINTR(SYS_DEV_SCC1, IOASIC_INTR_SCC_1);
3871.10Sjonathan
3881.68Smatt#ifdef notyet /* untested */
3891.68Smatt			/* If tty interrupts were enabled, re-enable them ASAP. */
3901.68Smatt			if ((old_mask & (KMIN_INTR_SCC_1|KMIN_INTR_SCC_0)) ==
3911.68Smatt			     (KMIN_INTR_SCC_1|KMIN_INTR_SCC_0)) {
3921.68Smatt				*imaskp = old_mask &
3931.68Smatt				  ~(KMIN_INTR_SCC_0|KMIN_INTR_SCC_1 |
3941.68Smatt				  IOASIC_INTR_LANCE|IOASIC_INTR_SCSI);
3951.68Smatt				kn02ba_wbflush();
3961.68Smatt			}
3971.68Smatt
3981.68Smatt			/* XXX until we know about SPLs of TC options. */
3991.68Smatt			if (curcpu()->ci_idepth > 1)
4001.68Smatt				 break;
4011.68Smatt#endif
4021.68Smatt			CHECKINTR(SYS_DEV_LANCE, IOASIC_INTR_LANCE);
4031.68Smatt			CHECKINTR(SYS_DEV_SCSI, IOASIC_INTR_SCSI);
4041.11Sjonathan
4051.68Smatt			if (user_warned && ((intr & KMIN_INTR_PSWARN) == 0)) {
4061.68Smatt				printf("%s\n", "Power supply ok now.");
4071.68Smatt				user_warned = 0;
4081.68Smatt			}
4091.68Smatt			if ((intr & KMIN_INTR_PSWARN) && (user_warned < 3)) {
4101.68Smatt				user_warned++;
4111.68Smatt				printf("%s\n", "Power supply overheating");
4121.68Smatt			}
4131.68Smatt		}
4141.68Smatt		if ((ipending & MIPS_INT_MASK_0) && intrtab[SYS_DEV_OPT0].ih_func) {
4151.68Smatt			(*intrtab[SYS_DEV_OPT0].ih_func)(intrtab[SYS_DEV_OPT0].ih_arg);
4161.68Smatt			intrtab[SYS_DEV_OPT0].ih_count.ev_count++;
4171.10Sjonathan		}
4181.10Sjonathan
4191.68Smatt		if ((ipending & MIPS_INT_MASK_1) && intrtab[SYS_DEV_OPT1].ih_func) {
4201.68Smatt			(*intrtab[SYS_DEV_OPT1].ih_func)(intrtab[SYS_DEV_OPT1].ih_arg);
4211.68Smatt			intrtab[SYS_DEV_OPT1].ih_count.ev_count++;
4221.1Sjonathan		}
4231.68Smatt		if ((ipending & MIPS_INT_MASK_2) && intrtab[SYS_DEV_OPT2].ih_func) {
4241.68Smatt			(*intrtab[SYS_DEV_OPT2].ih_func)(intrtab[SYS_DEV_OPT2].ih_arg);
4251.68Smatt			intrtab[SYS_DEV_OPT2].ih_count.ev_count++;
4261.1Sjonathan		}
4271.68Smatt	} while (0);
4281.1Sjonathan
4291.10Sjonathan	/* restore entry state */
4301.68Smatt	*(uint32_t *)(ioasic_base + IOASIC_IMSK) = old_mask;
4311.1Sjonathan}
4321.1Sjonathan
4331.1Sjonathan
4341.1Sjonathan
4351.1Sjonathan/*
4361.1Sjonathan ************************************************************************
4371.1Sjonathan * Extra functions
4381.1Sjonathan ************************************************************************
4391.1Sjonathan */
4401.14Snisimura
4411.31Ssimonbstatic void
4421.65Stsutsuikn02ba_wbflush(void)
4431.14Snisimura{
4441.65Stsutsui
4451.21Snisimura	/* read twice IOASIC_IMSK */
4461.54Sperry	__asm volatile("lw $0,%0; lw $0,%0" ::
4471.27Ssimonb	    "i"(MIPS_PHYS_TO_KSEG1(KMIN_REG_IMSK)));
4481.14Snisimura}
4491.14Snisimura
4501.59Sjoerg/*
4511.59Sjoerg * Support for using the MIPS 3 clock as a timecounter.
4521.59Sjoerg */
4531.59Sjoerg
4541.59Sjoergvoid
4551.59Sjoergdec_3min_tc_init(void)
4561.14Snisimura{
4571.60Stsutsui#if defined(MIPS3)
4581.59Sjoerg	static struct timecounter tc =  {
4591.59Sjoerg		.tc_get_timecount = (timecounter_get_t *)mips3_cp0_count_read,
4601.59Sjoerg		.tc_counter_mask = ~0u,
4611.59Sjoerg		.tc_name = "mips3_cp0_counter",
4621.59Sjoerg		.tc_quality = 100,
4631.59Sjoerg	};
4641.59Sjoerg
4651.59Sjoerg	if (MIPS_HAS_CLOCK) {
4661.68Smatt		tc.tc_frequency = mips_options.mips_cpu_mhz * 1000000;
4671.59Sjoerg
4681.59Sjoerg		tc_init(&tc);
4691.14Snisimura	}
4701.60Stsutsui#endif
4711.1Sjonathan}
472