dec_3min.c revision 1.34
11.34Snisimura/* $NetBSD: dec_3min.c,v 1.34 2000/02/03 04:09:02 nisimura 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.34Snisimura__KERNEL_RCSID(0, "$NetBSD: dec_3min.c,v 1.34 2000/02/03 04:09:02 nisimura Exp $");
771.1Sjonathan
781.1Sjonathan
791.34Snisimura#include <sys/param.h>
801.1Sjonathan#include <sys/systm.h>
811.34Snisimura#include <sys/device.h>
821.1Sjonathan
831.1Sjonathan#include <machine/cpu.h>
841.1Sjonathan#include <machine/intr.h>
851.1Sjonathan#include <machine/sysconf.h>
861.1Sjonathan
871.1Sjonathan#include <mips/mips/mips_mcclock.h>	/* mcclock CPUspeed estimation */
881.2Sjonathan
891.2Sjonathan/* all these to get ioasic_base */
901.2Sjonathan#include <dev/tc/tcvar.h>		/* tc type definitions for.. */
911.7Sjonathan#include <dev/tc/ioasicreg.h>		/* ioasic interrrupt masks */
921.2Sjonathan#include <dev/tc/ioasicvar.h>		/* ioasic_base */
931.1Sjonathan
941.20Ssimonb#include <pmax/pmax/machdep.h>
951.1Sjonathan#include <pmax/pmax/kmin.h>		/* 3min baseboard addresses */
961.15Snisimura#include <pmax/pmax/memc.h>		/* 3min/maxine memory errors */
971.34Snisimura#include <pmax/tc/sccvar.h>
981.34Snisimura
991.34Snisimura#include "rasterconsole.h"
1001.1Sjonathan
1011.1Sjonathan
1021.1Sjonathan/*
1031.1Sjonathan * forward declarations
1041.1Sjonathan */
1051.31Ssimonbvoid		dec_3min_init __P((void));		/* XXX */
1061.31Ssimonbstatic void	dec_3min_bus_reset __P((void));
1071.33Ssimonbstatic void	dec_3min_cons_init __P((void));
1081.33Ssimonbstatic void	dec_3min_device_register __P((struct device *, void *));
1091.31Ssimonbstatic int	dec_3min_intr __P((unsigned, unsigned, unsigned, unsigned));
1101.33Ssimonbstatic void	dec_3min_intr_establish __P((struct device *, void *,
1111.33Ssimonb		    int, int (*)(void *), void *));
1121.33Ssimonbstatic void	dec_3min_intr_disestablish __P((struct device *, void *));
1131.1Sjonathan
1141.31Ssimonbstatic void	kn02ba_wbflush __P((void));
1151.31Ssimonbstatic unsigned	kn02ba_clkread __P((void));
1161.1Sjonathan
1171.1Sjonathan
1181.1Sjonathan/*
1191.1Sjonathan * Local declarations.
1201.1Sjonathan */
1211.22Snisimurastatic u_int32_t kmin_tc3_imask;
1221.18Snisimura
1231.18Snisimura#ifdef MIPS3
1241.31Ssimonbstatic unsigned latched_cycle_cnt;
1251.18Snisimura#endif
1261.18Snisimura
1271.1Sjonathan
1281.1Sjonathanvoid
1291.1Sjonathandec_3min_init()
1301.1Sjonathan{
1311.31Ssimonb	int physmem_boardmax;
1321.22Snisimura
1331.24Snisimura	platform.iobus = "tcbus";
1341.1Sjonathan	platform.bus_reset = dec_3min_bus_reset;
1351.1Sjonathan	platform.cons_init = dec_3min_cons_init;
1361.1Sjonathan	platform.device_register = dec_3min_device_register;
1371.22Snisimura	platform.iointr = dec_3min_intr;
1381.33Ssimonb	platform.intr_establish = dec_3min_intr_establish;
1391.33Ssimonb	platform.intr_disestablish = dec_3min_intr_disestablish;
1401.26Ssimonb	platform.memsize = memsize_scan;
1411.22Snisimura	platform.clkread = kn02ba_clkread;
1421.1Sjonathan
1431.22Snisimura	/* clear any memory errors */
1441.17Snisimura	*(u_int32_t *)MIPS_PHYS_TO_KSEG1(KMIN_REG_TIMEOUT) = 0;
1451.14Snisimura	kn02ba_wbflush();
1461.1Sjonathan
1471.1Sjonathan	ioasic_base = MIPS_PHYS_TO_KSEG1(KMIN_SYS_ASIC);
1481.22Snisimura	mips_hardware_intr = dec_3min_intr;
1491.1Sjonathan
1501.1Sjonathan	/*
1511.22Snisimura	 * Since all the motherboard interrupts come through the
1521.22Snisimura	 * IOASIC, it has to be turned off for all the spls and
1531.22Snisimura	 * since we don't know what kinds of devices are in the
1541.22Snisimura	 * TURBOchannel option slots, just splhigh().
1551.1Sjonathan	 */
1561.16Snisimura	splvec.splbio = MIPS_SPL_0_1_2_3;
1571.22Snisimura	splvec.splnet = MIPS_SPL_0_1_2_3;
1581.16Snisimura	splvec.spltty = MIPS_SPL_0_1_2_3;
1591.16Snisimura	splvec.splimp = MIPS_SPL_0_1_2_3;
1601.16Snisimura	splvec.splclock = MIPS_SPL_0_1_2_3;
1611.16Snisimura	splvec.splstatclock = MIPS_SPL_0_1_2_3;
1621.16Snisimura
1631.28Snisimura	/* enable posting of MIPS_INT_MASK_3 to CAUSE register */
1641.28Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_IMSK) = KMIN_INTR_CLOCK;
1651.22Snisimura	/* calibrate cpu_mhz value */
1661.29Snisimura	mc_cpuspeed(ioasic_base+IOASIC_SLOT_8_START, MIPS_INT_MASK_3);
1671.1Sjonathan
1681.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_LANCE_DECODE) = 0x3;
1691.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_SCSI_DECODE) = 0xe;
1701.22Snisimura#if 0
1711.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_SCC0_DECODE) = (0x10|4);
1721.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_SCC1_DECODE) = (0x10|6);
1731.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_CSR) = 0x00000f00;
1741.22Snisimura#endif
1751.22Snisimura
1761.22Snisimura	/* sanitize interrupt mask */
1771.22Snisimura	kmin_tc3_imask = (KMIN_INTR_CLOCK|KMIN_INTR_PSWARN|KMIN_INTR_TIMEOUT);
1781.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_INTR) = 0;
1791.22Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_IMSK) = kmin_tc3_imask;
1801.1Sjonathan
1811.1Sjonathan	/*
1821.22Snisimura	 * The kmin memory hardware seems to wrap memory addresses
1831.1Sjonathan	 * with 4Mbyte SIMMs, which causes the physmem computation
1841.1Sjonathan	 * to lose.  Find out how big the SIMMS are and set
1851.22Snisimura	 * max_ physmem accordingly.
1861.22Snisimura	 * XXX Do MAXINEs lose the same way?
1871.1Sjonathan	 */
1881.1Sjonathan	physmem_boardmax = KMIN_PHYS_MEMORY_END + 1;
1891.22Snisimura	if ((KMIN_MSR_SIZE_16Mb & *(int *)MIPS_PHYS_TO_KSEG1(KMIN_REG_MSR))
1901.22Snisimura			== 0)
1911.1Sjonathan		physmem_boardmax = physmem_boardmax >> 2;
1921.1Sjonathan	physmem_boardmax = MIPS_PHYS_TO_KSEG1(physmem_boardmax);
1931.10Sjonathan
1941.22Snisimura	sprintf(cpu_model, "DECstation 5000/1%d (3MIN)", cpu_mhz);
1951.22Snisimura}
1961.22Snisimura
1971.22Snisimura/*
1981.22Snisimura * Initalize the memory system and I/O buses.
1991.22Snisimura */
2001.31Ssimonbstatic void
2011.22Snisimuradec_3min_bus_reset()
2021.22Snisimura{
2031.22Snisimura
2041.22Snisimura	/*
2051.22Snisimura	 * Reset interrupts, clear any errors from newconf probes
2061.22Snisimura	 */
2071.22Snisimura
2081.17Snisimura	*(u_int32_t *)MIPS_PHYS_TO_KSEG1(KMIN_REG_TIMEOUT) = 0;
2091.17Snisimura	kn02ba_wbflush();
2101.17Snisimura
2111.22Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_INTR) = 0;
2121.22Snisimura	kn02ba_wbflush();
2131.1Sjonathan}
2141.1Sjonathan
2151.31Ssimonbstatic void
2161.1Sjonathandec_3min_cons_init()
2171.1Sjonathan{
2181.34Snisimura	int kbd, crt, screen;
2191.34Snisimura	extern int tcfb_cnattach __P((int));		/* XXX */
2201.34Snisimura
2211.34Snisimura	kbd = crt = screen = 0;
2221.34Snisimura	prom_findcons(&kbd, &crt, &screen);
2231.34Snisimura
2241.34Snisimura	if (screen > 0) {
2251.34Snisimura#if NRASTERCONSOLE > 0
2261.34Snisimura		if (tcfb_cnattach(crt) > 0) {
2271.34Snisimura			scc_lk201_cnattach(ioasic_base, 0x180000);
2281.34Snisimura			return;
2291.34Snisimura		}
2301.34Snisimura#endif
2311.34Snisimura		printf("No framebuffer device configured for slot %d: ", crt);
2321.34Snisimura		printf("using serial console\n");
2331.34Snisimura	}
2341.34Snisimura	/*
2351.34Snisimura	 * Delay to allow PROM putchars to complete.
2361.34Snisimura	 * FIFO depth * character time,
2371.34Snisimura	 * character time = (1000000 / (defaultrate / 10))
2381.34Snisimura	 */
2391.34Snisimura	DELAY(160000000 / 9600);	/* XXX */
2401.34Snisimura
2411.34Snisimura	scc_cnattach(ioasic_base, 0x180000);
2421.1Sjonathan}
2431.1Sjonathan
2441.1Sjonathan
2451.31Ssimonbstatic void
2461.1Sjonathandec_3min_device_register(dev, aux)
2471.1Sjonathan	struct device *dev;
2481.1Sjonathan	void *aux;
2491.1Sjonathan{
2501.1Sjonathan	panic("dec_3min_device_register unimplemented");
2511.1Sjonathan}
2521.1Sjonathan
2531.1Sjonathan
2541.31Ssimonbstatic void
2551.33Ssimonbdec_3min_intr_establish(dev, cookie, level, handler, arg)
2561.33Ssimonb	struct device *dev;
2571.33Ssimonb	void *cookie;
2581.33Ssimonb	int level;
2591.24Snisimura	int (*handler) __P((void *));
2601.33Ssimonb	void *arg;
2611.1Sjonathan{
2621.33Ssimonb	int slotno = (int)cookie;
2631.13Ssimonb	unsigned mask;
2641.1Sjonathan
2651.1Sjonathan	switch (slotno) {
2661.1Sjonathan		/* slots 0-2 don't interrupt through the IOASIC. */
2671.33Ssimonb	  case 0:
2681.33Ssimonb		mask = MIPS_INT_MASK_0;
2691.33Ssimonb		break;
2701.33Ssimonb	  case 1:
2711.33Ssimonb		mask = MIPS_INT_MASK_1;
2721.33Ssimonb		break;
2731.33Ssimonb	  case 2:
2741.33Ssimonb		mask = MIPS_INT_MASK_2;
2751.33Ssimonb		break;
2761.1Sjonathan
2771.33Ssimonb	  case KMIN_SCSI_SLOT:
2781.7Sjonathan		mask = (IOASIC_INTR_SCSI | IOASIC_INTR_SCSI_PTR_LOAD |
2791.7Sjonathan			IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E);
2801.1Sjonathan		break;
2811.33Ssimonb	  case KMIN_LANCE_SLOT:
2821.1Sjonathan		mask = KMIN_INTR_LANCE;
2831.1Sjonathan		break;
2841.33Ssimonb	  case KMIN_SCC0_SLOT:
2851.1Sjonathan		mask = KMIN_INTR_SCC_0;
2861.1Sjonathan		break;
2871.33Ssimonb	  case KMIN_SCC1_SLOT:
2881.1Sjonathan		mask = KMIN_INTR_SCC_1;
2891.1Sjonathan		break;
2901.33Ssimonb	  case KMIN_ASIC_SLOT:
2911.1Sjonathan		mask = KMIN_INTR_ASIC;
2921.1Sjonathan		break;
2931.33Ssimonb	  default:
2941.33Ssimonb#ifdef DIAGNOSTIC
2951.33Ssimonb		printf("warning: enabling unknown intr %x\n", slotno);
2961.33Ssimonb#endif
2971.1Sjonathan		return;
2981.1Sjonathan	}
2991.1Sjonathan
3001.1Sjonathan#if defined(DEBUG) || defined(DIAGNOSTIC)
3011.25Snisimura	printf("3MIN: imask %x, %sabling slot %d, sc %p handler %p\n",
3021.33Ssimonb	    kmin_tc3_imask, (on? "en" : "dis"), slotno, sc, handler);
3031.1Sjonathan#endif
3041.1Sjonathan
3051.1Sjonathan	/*
3061.1Sjonathan	 * Enable the interrupt  handler, and if it's an IOASIC
3071.1Sjonathan	 * slot, set the IOASIC interrupt mask.
3081.1Sjonathan	 * Otherwise, set the appropriate spl level in the R3000
3091.1Sjonathan	 * register.
3101.1Sjonathan	 * Be careful to set handlers  before enabling, and disable
3111.1Sjonathan	 * interrupts before clearing handlers.
3121.1Sjonathan	 */
3131.1Sjonathan
3141.33Ssimonb	/* Set the interrupt handler and argument ... */
3151.33Ssimonb	intrtab[slotno].ih_func = handler;
3161.33Ssimonb	intrtab[slotno].ih_arg = arg;
3171.33Ssimonb	/* ... and set the relevant mask */
3181.33Ssimonb	if (slotno <= 2) {
3191.33Ssimonb		/* it's an option slot */
3201.33Ssimonb		int s = splhigh();
3211.33Ssimonb		s |= mask;
3221.33Ssimonb		splx(s);
3231.1Sjonathan	} else {
3241.33Ssimonb		/* it's a baseboard device going via the ASIC */
3251.33Ssimonb		kmin_tc3_imask |= mask;
3261.1Sjonathan	}
3271.33Ssimonb
3281.25Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_IMSK) = kmin_tc3_imask;
3291.25Snisimura	kn02ba_wbflush();
3301.1Sjonathan}
3311.1Sjonathan
3321.1Sjonathan
3331.33Ssimonbstatic void
3341.33Ssimonbdec_3min_intr_disestablish(dev, arg)
3351.33Ssimonb	struct device *dev;
3361.33Ssimonb	void *arg;
3371.33Ssimonb{
3381.33Ssimonb	printf("dec_3min_intr_distestablish: not implemented\n");
3391.33Ssimonb}
3401.33Ssimonb
3411.1Sjonathan
3421.1Sjonathan/*
3431.1Sjonathan * 3min hardware interrupts. (DECstation 5000/1xx)
3441.1Sjonathan */
3451.31Ssimonbstatic int
3461.17Snisimuradec_3min_intr(cpumask, pc, status, cause)
3471.17Snisimura	unsigned cpumask;
3481.1Sjonathan	unsigned pc;
3491.17Snisimura	unsigned status;
3501.17Snisimura	unsigned cause;
3511.1Sjonathan{
3521.1Sjonathan	static int user_warned = 0;
3531.17Snisimura	static int intr_depth = 0;
3541.17Snisimura	u_int32_t old_mask;
3551.1Sjonathan
3561.10Sjonathan	intr_depth++;
3571.17Snisimura	old_mask = *(u_int32_t *)(ioasic_base + IOASIC_IMSK);
3581.10Sjonathan
3591.17Snisimura	if (cpumask & MIPS_INT_MASK_4)
3601.1Sjonathan		prom_haltbutton();
3611.1Sjonathan
3621.17Snisimura	if (cpumask & MIPS_INT_MASK_3) {
3631.10Sjonathan		/* NB: status & MIPS_INT_MASK3 must also be set */
3641.10Sjonathan		/* masked interrupts are still observable */
3651.17Snisimura		u_int32_t intr, imsk, turnoff;
3661.17Snisimura
3671.17Snisimura		turnoff = 0;
3681.17Snisimura		intr = *(u_int32_t *)(ioasic_base + IOASIC_INTR);
3691.17Snisimura		imsk = *(u_int32_t *)(ioasic_base + IOASIC_IMSK);
3701.17Snisimura		intr &= imsk;
3711.1Sjonathan
3721.7Sjonathan		if (intr & IOASIC_INTR_SCSI_PTR_LOAD) {
3731.17Snisimura			turnoff |= IOASIC_INTR_SCSI_PTR_LOAD;
3741.1Sjonathan#ifdef notdef
3751.1Sjonathan			asc_dma_intr();
3761.1Sjonathan#endif
3771.1Sjonathan		}
3781.12Ssimonb
3791.7Sjonathan		if (intr & (IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E))
3801.17Snisimura			turnoff |= IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E;
3811.1Sjonathan
3821.7Sjonathan		if (intr & IOASIC_INTR_LANCE_READ_E)
3831.17Snisimura			turnoff |= IOASIC_INTR_LANCE_READ_E;
3841.17Snisimura
3851.17Snisimura		if (turnoff)
3861.17Snisimura			*(u_int32_t *)(ioasic_base + IOASIC_INTR) = ~turnoff;
3871.1Sjonathan
3881.1Sjonathan		if (intr & KMIN_INTR_TIMEOUT)
3891.1Sjonathan			kn02ba_errintr();
3901.12Ssimonb
3911.1Sjonathan		if (intr & KMIN_INTR_CLOCK) {
3921.17Snisimura			struct clockframe cf;
3931.17Snisimura
3941.22Snisimura			__asm __volatile("lbu $0,48(%0)" ::
3951.22Snisimura				"r"(ioasic_base + IOASIC_SLOT_8_START));
3961.6Sjonathan#ifdef MIPS3
3971.6Sjonathan			if (CPUISMIPS3) {
3981.6Sjonathan				latched_cycle_cnt = mips3_cycle_count();
3991.6Sjonathan			}
4001.6Sjonathan#endif
4011.17Snisimura			cf.pc = pc;
4021.17Snisimura			cf.sr = status;
4031.1Sjonathan			hardclock(&cf);
4041.1Sjonathan			intrcnt[HARDCLOCK]++;
4051.1Sjonathan		}
4061.10Sjonathan
4071.10Sjonathan		/* If clock interrups were enabled, re-enable them ASAP. */
4081.10Sjonathan		if (old_mask & KMIN_INTR_CLOCK) {
4091.17Snisimura			/* ioctl interrupt mask to splclock and higher */
4101.17Snisimura			*(u_int32_t *)(ioasic_base + IOASIC_IMSK)
4111.17Snisimura				= old_mask &
4121.17Snisimura					~(KMIN_INTR_SCC_0|KMIN_INTR_SCC_1 |
4131.17Snisimura					  IOASIC_INTR_LANCE|IOASIC_INTR_SCSI);
4141.14Snisimura			kn02ba_wbflush();
4151.17Snisimura			_splset(MIPS_SR_INT_IE | (status & MIPS_INT_MASK_3));
4161.10Sjonathan		}
4171.10Sjonathan
4181.11Sjonathan		if (intr_depth > 1)
4191.11Sjonathan			 goto done;
4201.11Sjonathan
4211.1Sjonathan		if ((intr & KMIN_INTR_SCC_0) &&
4221.33Ssimonb		    intrtab[KMIN_SCC0_SLOT].ih_func) {
4231.33Ssimonb			(*(intrtab[KMIN_SCC0_SLOT].ih_func))
4241.33Ssimonb			  (intrtab[KMIN_SCC0_SLOT].ih_arg);
4251.1Sjonathan			intrcnt[SERIAL0_INTR]++;
4261.1Sjonathan		}
4271.1Sjonathan
4281.1Sjonathan		if ((intr & KMIN_INTR_SCC_1) &&
4291.33Ssimonb		    intrtab[KMIN_SCC1_SLOT].ih_func) {
4301.33Ssimonb			(*(intrtab[KMIN_SCC1_SLOT].ih_func))
4311.33Ssimonb			  (intrtab[KMIN_SCC1_SLOT].ih_arg);
4321.1Sjonathan			intrcnt[SERIAL1_INTR]++;
4331.1Sjonathan		}
4341.10Sjonathan
4351.10Sjonathan#ifdef notyet /* untested */
4361.10Sjonathan		/* If tty interrupts were enabled, re-enable them ASAP. */
4371.10Sjonathan		if ((old_mask & (KMIN_INTR_SCC_1|KMIN_INTR_SCC_0)) ==
4381.10Sjonathan		     (KMIN_INTR_SCC_1|KMIN_INTR_SCC_0)) {
4391.12Ssimonb			*imaskp = old_mask &
4401.10Sjonathan			  ~(KMIN_INTR_SCC_0|KMIN_INTR_SCC_1 |
4411.10Sjonathan			  IOASIC_INTR_LANCE|IOASIC_INTR_SCSI);
4421.14Snisimura			kn02ba_wbflush();
4431.10Sjonathan		}
4441.10Sjonathan
4451.10Sjonathan		/* XXX until we know about SPLs of TC options. */
4461.10Sjonathan		if (intr_depth > 1)
4471.10Sjonathan			 goto done;
4481.10Sjonathan#endif
4491.9Sjonathan		if ((intr & IOASIC_INTR_LANCE) &&
4501.33Ssimonb		    intrtab[KMIN_LANCE_SLOT].ih_func) {
4511.33Ssimonb			(*(intrtab[KMIN_LANCE_SLOT].ih_func))
4521.33Ssimonb			  (intrtab[KMIN_LANCE_SLOT].ih_arg);
4531.9Sjonathan			intrcnt[LANCE_INTR]++;
4541.9Sjonathan		}
4551.9Sjonathan
4561.7Sjonathan		if ((intr & IOASIC_INTR_SCSI) &&
4571.33Ssimonb		    intrtab[KMIN_SCSI_SLOT].ih_func) {
4581.33Ssimonb			(*(intrtab[KMIN_SCSI_SLOT].ih_func))
4591.33Ssimonb			  (intrtab[KMIN_SCSI_SLOT].ih_arg);
4601.1Sjonathan			intrcnt[SCSI_INTR]++;
4611.1Sjonathan		}
4621.1Sjonathan
4631.1Sjonathan		if (user_warned && ((intr & KMIN_INTR_PSWARN) == 0)) {
4641.1Sjonathan			printf("%s\n", "Power supply ok now.");
4651.1Sjonathan			user_warned = 0;
4661.1Sjonathan		}
4671.1Sjonathan		if ((intr & KMIN_INTR_PSWARN) && (user_warned < 3)) {
4681.1Sjonathan			user_warned++;
4691.1Sjonathan			printf("%s\n", "Power supply overheating");
4701.1Sjonathan		}
4711.1Sjonathan	}
4721.33Ssimonb	if ((cpumask & MIPS_INT_MASK_0) && intrtab[0].ih_func) {
4731.33Ssimonb		(*intrtab[0].ih_func)(intrtab[0].ih_arg);
4741.1Sjonathan		intrcnt[SLOT0_INTR]++;
4751.1Sjonathan 	}
4761.12Ssimonb
4771.33Ssimonb	if ((cpumask & MIPS_INT_MASK_1) && intrtab[1].ih_func) {
4781.33Ssimonb		(*intrtab[1].ih_func)(intrtab[1].ih_arg);
4791.1Sjonathan		intrcnt[SLOT1_INTR]++;
4801.1Sjonathan	}
4811.33Ssimonb	if ((cpumask & MIPS_INT_MASK_2) && intrtab[2].ih_func) {
4821.33Ssimonb		(*intrtab[2].ih_func)(intrtab[2].ih_arg);
4831.1Sjonathan		intrcnt[SLOT2_INTR]++;
4841.1Sjonathan	}
4851.1Sjonathan
4861.10Sjonathandone:
4871.10Sjonathan	/* restore entry state */
4881.10Sjonathan	splhigh();
4891.10Sjonathan	intr_depth--;
4901.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_IMSK) = old_mask;
4911.10Sjonathan
4921.14Snisimura
4931.17Snisimura	return (MIPS_SR_INT_IE | (status & ~cause & MIPS_HARD_INT_MASK));
4941.1Sjonathan}
4951.1Sjonathan
4961.1Sjonathan
4971.1Sjonathan
4981.1Sjonathan/*
4991.1Sjonathan ************************************************************************
5001.1Sjonathan * Extra functions
5011.1Sjonathan ************************************************************************
5021.1Sjonathan */
5031.14Snisimura
5041.31Ssimonbstatic void
5051.14Snisimurakn02ba_wbflush()
5061.14Snisimura{
5071.21Snisimura	/* read twice IOASIC_IMSK */
5081.27Ssimonb	__asm __volatile("lw $0,%0; lw $0,%0" ::
5091.27Ssimonb	    "i"(MIPS_PHYS_TO_KSEG1(KMIN_REG_IMSK)));
5101.14Snisimura}
5111.14Snisimura
5121.31Ssimonbstatic unsigned
5131.14Snisimurakn02ba_clkread()
5141.14Snisimura{
5151.14Snisimura#ifdef MIPS3
5161.14Snisimura	if (CPUISMIPS3) {
5171.14Snisimura		u_int32_t mips3_cycles;
5181.14Snisimura
5191.14Snisimura		mips3_cycles = mips3_cycle_count() - latched_cycle_cnt;
5201.14Snisimura		/* XXX divides take 78 cycles: approximate with * 41/2048 */
5211.14Snisimura		return((mips3_cycles >> 6) + (mips3_cycles >> 8) +
5221.14Snisimura		       (mips3_cycles >> 11));
5231.14Snisimura	}
5241.14Snisimura#endif
5251.14Snisimura	return 0;
5261.1Sjonathan}
527