dec_3min.c revision 1.21
11.21Snisimura/*	$NetBSD: dec_3min.c,v 1.21 1999/06/10 01:37:10 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.21Snisimura__KERNEL_RCSID(0, "$NetBSD: dec_3min.c,v 1.21 1999/06/10 01:37:10 nisimura Exp $");
771.1Sjonathan
781.1Sjonathan
791.1Sjonathan#include <sys/types.h>
801.1Sjonathan#include <sys/systm.h>
811.1Sjonathan
821.1Sjonathan#include <machine/cpu.h>
831.1Sjonathan#include <machine/intr.h>
841.1Sjonathan#include <machine/reg.h>
851.1Sjonathan#include <machine/psl.h>
861.1Sjonathan#include <machine/autoconf.h>		/* intr_arg_t */
871.1Sjonathan#include <machine/sysconf.h>
881.1Sjonathan
891.1Sjonathan#include <mips/mips_param.h>		/* hokey spl()s */
901.1Sjonathan#include <mips/mips/mips_mcclock.h>	/* mcclock CPUspeed estimation */
911.2Sjonathan
921.2Sjonathan/* all these to get ioasic_base */
931.2Sjonathan#include <sys/device.h>			/* struct cfdata for.. */
941.2Sjonathan#include <dev/tc/tcvar.h>		/* tc type definitions for.. */
951.7Sjonathan#include <dev/tc/ioasicreg.h>		/* ioasic interrrupt masks */
961.2Sjonathan#include <dev/tc/ioasicvar.h>		/* ioasic_base */
971.1Sjonathan
981.1Sjonathan#include <pmax/pmax/clockreg.h>
991.12Ssimonb#include <pmax/pmax/turbochannel.h>
1001.12Ssimonb#include <pmax/pmax/pmaxtype.h>
1011.20Ssimonb#include <pmax/pmax/machdep.h>
1021.1Sjonathan
1031.1Sjonathan#include <pmax/pmax/kmin.h>		/* 3min baseboard addresses */
1041.15Snisimura#include <pmax/pmax/memc.h>		/* 3min/maxine memory errors */
1051.1Sjonathan
1061.1Sjonathan
1071.1Sjonathan/*
1081.1Sjonathan * forward declarations
1091.1Sjonathan */
1101.1Sjonathanvoid		dec_3min_init __P((void));
1111.1Sjonathanvoid		dec_3min_os_init __P((void));
1121.1Sjonathanvoid		dec_3min_bus_reset __P((void));
1131.1Sjonathanvoid		dec_3maxplus_device_register __P((struct device *, void *));
1141.1Sjonathan
1151.12Ssimonbvoid		dec_3min_enable_intr
1161.1Sjonathan		   __P ((u_int slotno, int (*handler) __P((intr_arg_t sc)),
1171.1Sjonathan			 intr_arg_t sc, int onoff));
1181.17Snisimuraint		dec_3min_intr __P((unsigned, unsigned, unsigned, unsigned));
1191.1Sjonathanvoid		dec_3min_device_register __P((struct device *, void *));
1201.1Sjonathanvoid		dec_3min_cons_init __P((void));
1211.1Sjonathan
1221.1Sjonathan
1231.1Sjonathan/*
1241.1Sjonathan * Local declarations.
1251.1Sjonathan */
1261.1Sjonathanvoid dec_3min_mcclock_cpuspeed __P((volatile struct chiptime *mcclock_addr,
1271.1Sjonathan			       int clockmask));
1281.1Sjonathanu_long	kmin_tc3_imask;
1291.1Sjonathan
1301.14Snisimuravoid kn02ba_wbflush __P((void));
1311.14Snisimuraunsigned kn02ba_clkread __P((void));
1321.14Snisimuraextern unsigned (*clkread) __P((void));
1331.18Snisimura
1341.18Snisimuraextern volatile struct chiptime *mcclock_addr; /* XXX */
1351.18Snisimuraextern char cpu_model[];
1361.18Snisimuraextern int physmem_boardmax;
1371.18Snisimura
1381.18Snisimura#ifdef MIPS3
1391.19Snisimurastatic unsigned latched_cycle_cnt;
1401.18Snisimuraextern u_int32_t mips3_cycle_count __P((void));
1411.18Snisimura#endif
1421.18Snisimura
1431.1Sjonathan
1441.1Sjonathan/*
1451.12Ssimonb * Fill in platform struct.
1461.1Sjonathan */
1471.1Sjonathanvoid
1481.1Sjonathandec_3min_init()
1491.1Sjonathan{
1501.16Snisimura	platform.iobus = "tc3min";
1511.1Sjonathan
1521.1Sjonathan	platform.os_init = dec_3min_os_init;
1531.1Sjonathan	platform.bus_reset = dec_3min_bus_reset;
1541.1Sjonathan	platform.cons_init = dec_3min_cons_init;
1551.1Sjonathan	platform.device_register = dec_3min_device_register;
1561.1Sjonathan
1571.1Sjonathan	dec_3min_os_init();
1581.1Sjonathan
1591.5Sjonathan	sprintf(cpu_model, "DECstation 5000/1%d (3MIN)", cpu_mhz);
1601.1Sjonathan}
1611.1Sjonathan
1621.1Sjonathan
1631.1Sjonathan/*
1641.1Sjonathan * Initalize the memory system and I/O buses.
1651.1Sjonathan */
1661.1Sjonathanvoid
1671.1Sjonathandec_3min_bus_reset()
1681.1Sjonathan{
1691.1Sjonathan
1701.1Sjonathan	/*
1711.1Sjonathan	 * Reset interrupts, clear any errors from newconf probes
1721.1Sjonathan	 */
1731.1Sjonathan
1741.17Snisimura	*(u_int32_t *)MIPS_PHYS_TO_KSEG1(KMIN_REG_TIMEOUT) = 0;
1751.14Snisimura	kn02ba_wbflush();
1761.1Sjonathan
1771.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_INTR) = 0;
1781.14Snisimura	kn02ba_wbflush();
1791.1Sjonathan}
1801.1Sjonathan
1811.12Ssimonb
1821.1Sjonathanvoid
1831.1Sjonathandec_3min_os_init()
1841.1Sjonathan{
1851.1Sjonathan	ioasic_base = MIPS_PHYS_TO_KSEG1(KMIN_SYS_ASIC);
1861.1Sjonathan	mips_hardware_intr = dec_3min_intr;
1871.17Snisimura	tc_enable_interrupt = dec_3min_enable_intr;	/* XXX */
1881.17Snisimura	mcclock_addr = (void *)(ioasic_base + IOASIC_SLOT_8_START);
1891.16Snisimura
1901.16Snisimura	/* R4000 3MIN can ultilize on-chip counter */
1911.16Snisimura	clkread = kn02ba_clkread;
1921.1Sjonathan
1931.1Sjonathan	/*
1941.8Sjonathan	 * All the baseboard interrupts come through the I/O ASIC
1951.8Sjonathan	 * (at INT_MASK_3), so  it has to be turned off for all the spls.
1961.8Sjonathan	 * Since we don't know what kinds of devices are in the
1971.8Sjonathan	 * turbochannel option slots, just block them all.
1981.1Sjonathan	 */
1991.16Snisimura	splvec.splbio = MIPS_SPL_0_1_2_3;
2001.16Snisimura	splvec.splnet = MIPS_SPL_0_1_2_3;
2011.16Snisimura	splvec.spltty = MIPS_SPL_0_1_2_3;
2021.16Snisimura	splvec.splimp = MIPS_SPL_0_1_2_3;
2031.16Snisimura	splvec.splclock = MIPS_SPL_0_1_2_3;
2041.16Snisimura	splvec.splstatclock = MIPS_SPL_0_1_2_3;
2051.16Snisimura
2061.1Sjonathan	dec_3min_mcclock_cpuspeed(mcclock_addr, MIPS_INT_MASK_3);
2071.1Sjonathan
2081.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_LANCE_DECODE) = 0x3;
2091.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_SCSI_DECODE) = 0xe;
2101.14Snisimura#if 0
2111.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_SCC0_DECODE) = (0x10|4);
2121.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_SCC1_DECODE) = (0x10|6);
2131.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_CSR) = 0x00000f00;
2141.14Snisimura#endif
2151.1Sjonathan	/*
2161.1Sjonathan	 * Initialize interrupts.
2171.1Sjonathan	 */
2181.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_IMSK) = KMIN_IM0;
2191.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_INTR) = 0;
2201.1Sjonathan
2211.1Sjonathan	/*
2221.1Sjonathan	 * The kmin memory hardware seems to wrap  memory addresses
2231.1Sjonathan	 * with 4Mbyte SIMMs, which causes the physmem computation
2241.1Sjonathan	 * to lose.  Find out how big the SIMMS are and set
2251.1Sjonathan	 * max_	physmem accordingly.
2261.1Sjonathan	 */
2271.1Sjonathan	physmem_boardmax = KMIN_PHYS_MEMORY_END + 1;
2281.17Snisimura	if ((*(int *)(MIPS_PHYS_TO_KSEG1(KMIN_REG_MSR)) &
2291.1Sjonathan	     KMIN_MSR_SIZE_16Mb) == 0)
2301.1Sjonathan		physmem_boardmax = physmem_boardmax >> 2;
2311.1Sjonathan	physmem_boardmax = MIPS_PHYS_TO_KSEG1(physmem_boardmax);
2321.10Sjonathan
2331.17Snisimura	/* clear any memory errors from probes */
2341.17Snisimura	*(u_int32_t *)MIPS_PHYS_TO_KSEG1(KMIN_REG_TIMEOUT) = 0;
2351.17Snisimura	kn02ba_wbflush();
2361.17Snisimura
2371.17Snisimura	kmin_tc3_imask =
2381.17Snisimura		(KMIN_INTR_CLOCK | KMIN_INTR_PSWARN | KMIN_INTR_TIMEOUT);
2391.17Snisimura
2401.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_IMSK) =
2411.17Snisimura		kmin_tc3_imask |
2421.17Snisimura		(KMIN_IM0 & ~(KN03_INTR_TC_0|KN03_INTR_TC_1|KN03_INTR_TC_2));
2431.1Sjonathan}
2441.1Sjonathan
2451.1Sjonathan
2461.1Sjonathanvoid
2471.1Sjonathandec_3min_cons_init()
2481.1Sjonathan{
2491.1Sjonathan	/* notyet */
2501.1Sjonathan}
2511.1Sjonathan
2521.1Sjonathan
2531.1Sjonathanvoid
2541.1Sjonathandec_3min_device_register(dev, aux)
2551.1Sjonathan	struct device *dev;
2561.1Sjonathan	void *aux;
2571.1Sjonathan{
2581.1Sjonathan	panic("dec_3min_device_register unimplemented");
2591.1Sjonathan}
2601.1Sjonathan
2611.1Sjonathan
2621.1Sjonathanvoid
2631.1Sjonathandec_3min_enable_intr(slotno, handler, sc, on)
2641.13Ssimonb	unsigned int slotno;
2651.1Sjonathan	int (*handler) __P((void* softc));
2661.1Sjonathan	void *sc;
2671.1Sjonathan	int on;
2681.1Sjonathan{
2691.13Ssimonb	unsigned mask;
2701.1Sjonathan
2711.1Sjonathan	switch (slotno) {
2721.1Sjonathan		/* slots 0-2 don't interrupt through the IOASIC. */
2731.1Sjonathan	case 0:
2741.1Sjonathan		mask = MIPS_INT_MASK_0;	break;
2751.1Sjonathan	case 1:
2761.1Sjonathan		mask = MIPS_INT_MASK_1; break;
2771.1Sjonathan	case 2:
2781.1Sjonathan		mask = MIPS_INT_MASK_2; break;
2791.1Sjonathan
2801.1Sjonathan	case KMIN_SCSI_SLOT:
2811.7Sjonathan		mask = (IOASIC_INTR_SCSI | IOASIC_INTR_SCSI_PTR_LOAD |
2821.7Sjonathan			IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E);
2831.1Sjonathan		break;
2841.1Sjonathan
2851.1Sjonathan	case KMIN_LANCE_SLOT:
2861.1Sjonathan		mask = KMIN_INTR_LANCE;
2871.1Sjonathan		break;
2881.1Sjonathan	case KMIN_SCC0_SLOT:
2891.1Sjonathan		mask = KMIN_INTR_SCC_0;
2901.1Sjonathan		break;
2911.1Sjonathan	case KMIN_SCC1_SLOT:
2921.1Sjonathan		mask = KMIN_INTR_SCC_1;
2931.1Sjonathan		break;
2941.1Sjonathan	case KMIN_ASIC_SLOT:
2951.1Sjonathan		mask = KMIN_INTR_ASIC;
2961.1Sjonathan		break;
2971.1Sjonathan	default:
2981.1Sjonathan		return;
2991.1Sjonathan	}
3001.1Sjonathan
3011.1Sjonathan#if defined(DEBUG) || defined(DIAGNOSTIC)
3021.1Sjonathan	printf("3MIN: imask %lx, %sabling slot %d, sc %p handler %p\n",
3031.1Sjonathan	       kmin_tc3_imask, (on? "en" : "dis"), slotno, sc, handler);
3041.1Sjonathan#endif
3051.1Sjonathan
3061.1Sjonathan	/*
3071.1Sjonathan	 * Enable the interrupt  handler, and if it's an IOASIC
3081.1Sjonathan	 * slot, set the IOASIC interrupt mask.
3091.1Sjonathan	 * Otherwise, set the appropriate spl level in the R3000
3101.1Sjonathan	 * register.
3111.1Sjonathan	 * Be careful to set handlers  before enabling, and disable
3121.1Sjonathan	 * interrupts before clearing handlers.
3131.1Sjonathan	 */
3141.1Sjonathan
3151.1Sjonathan	if (on) {
3161.1Sjonathan		/* Set the interrupt handler and argument ... */
3171.1Sjonathan		tc_slot_info[slotno].intr = handler;
3181.1Sjonathan		tc_slot_info[slotno].sc = sc;
3191.1Sjonathan
3201.1Sjonathan		/* ... and set the relevant mask */
3211.1Sjonathan		if (slotno <= 2) {
3221.1Sjonathan			/* it's an option slot */
3231.1Sjonathan			int s = splhigh();
3241.1Sjonathan			s  |= mask;
3251.1Sjonathan			splx(s);
3261.1Sjonathan		} else {
3271.1Sjonathan			/* it's a baseboard device going via the ASIC */
3281.1Sjonathan			kmin_tc3_imask |= mask;
3291.1Sjonathan		}
3301.1Sjonathan	} else {
3311.1Sjonathan		/* Clear the relevant mask... */
3321.12Ssimonb		if (slotno <= 2) {
3331.1Sjonathan			/* it's an option slot */
3341.1Sjonathan			int s = splhigh();
3351.1Sjonathan			printf("kmin_intr: cannot disable option slot %d\n",
3361.1Sjonathan			    slotno);
3371.1Sjonathan			s &= ~mask;
3381.1Sjonathan			splx(s);
3391.1Sjonathan		} else {
3401.1Sjonathan			/* it's a baseboard device going via the ASIC */
3411.1Sjonathan			kmin_tc3_imask &= ~mask;
3421.1Sjonathan		}
3431.1Sjonathan		/* ... and clear the handler */
3441.1Sjonathan		tc_slot_info[slotno].intr = 0;
3451.1Sjonathan		tc_slot_info[slotno].sc = 0;
3461.1Sjonathan	}
3471.1Sjonathan}
3481.1Sjonathan
3491.1Sjonathan
3501.1Sjonathan
3511.1Sjonathan/*
3521.1Sjonathan * 3min hardware interrupts. (DECstation 5000/1xx)
3531.1Sjonathan */
3541.1Sjonathanint
3551.17Snisimuradec_3min_intr(cpumask, pc, status, cause)
3561.17Snisimura	unsigned cpumask;
3571.1Sjonathan	unsigned pc;
3581.17Snisimura	unsigned status;
3591.17Snisimura	unsigned cause;
3601.1Sjonathan{
3611.1Sjonathan	static int user_warned = 0;
3621.17Snisimura	static int intr_depth = 0;
3631.17Snisimura	u_int32_t old_mask;
3641.1Sjonathan
3651.10Sjonathan	intr_depth++;
3661.17Snisimura	old_mask = *(u_int32_t *)(ioasic_base + IOASIC_IMSK);
3671.10Sjonathan
3681.17Snisimura	if (cpumask & MIPS_INT_MASK_4)
3691.1Sjonathan		prom_haltbutton();
3701.1Sjonathan
3711.17Snisimura	if (cpumask & MIPS_INT_MASK_3) {
3721.10Sjonathan		/* NB: status & MIPS_INT_MASK3 must also be set */
3731.10Sjonathan		/* masked interrupts are still observable */
3741.17Snisimura		u_int32_t intr, imsk, turnoff;
3751.17Snisimura
3761.17Snisimura		turnoff = 0;
3771.17Snisimura		intr = *(u_int32_t *)(ioasic_base + IOASIC_INTR);
3781.17Snisimura		imsk = *(u_int32_t *)(ioasic_base + IOASIC_IMSK);
3791.17Snisimura		intr &= imsk;
3801.1Sjonathan
3811.7Sjonathan		if (intr & IOASIC_INTR_SCSI_PTR_LOAD) {
3821.17Snisimura			turnoff |= IOASIC_INTR_SCSI_PTR_LOAD;
3831.1Sjonathan#ifdef notdef
3841.1Sjonathan			asc_dma_intr();
3851.1Sjonathan#endif
3861.1Sjonathan		}
3871.12Ssimonb
3881.7Sjonathan		if (intr & (IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E))
3891.17Snisimura			turnoff |= IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E;
3901.1Sjonathan
3911.7Sjonathan		if (intr & IOASIC_INTR_LANCE_READ_E)
3921.17Snisimura			turnoff |= IOASIC_INTR_LANCE_READ_E;
3931.17Snisimura
3941.17Snisimura		if (turnoff)
3951.17Snisimura			*(u_int32_t *)(ioasic_base + IOASIC_INTR) = ~turnoff;
3961.1Sjonathan
3971.1Sjonathan		if (intr & KMIN_INTR_TIMEOUT)
3981.1Sjonathan			kn02ba_errintr();
3991.12Ssimonb
4001.1Sjonathan		if (intr & KMIN_INTR_CLOCK) {
4011.17Snisimura			struct clockframe cf;
4021.17Snisimura			struct chiptime *clk;
4031.17Snisimura			volatile int temp;
4041.6Sjonathan
4051.17Snisimura			clk = (void *)(ioasic_base + IOASIC_SLOT_8_START);
4061.17Snisimura			temp = clk->regc;	/* XXX clear interrupt bits */
4071.17Snisimura
4081.6Sjonathan#ifdef MIPS3
4091.6Sjonathan			if (CPUISMIPS3) {
4101.6Sjonathan				latched_cycle_cnt = mips3_cycle_count();
4111.6Sjonathan			}
4121.6Sjonathan#endif
4131.17Snisimura			cf.pc = pc;
4141.17Snisimura			cf.sr = status;
4151.1Sjonathan			hardclock(&cf);
4161.1Sjonathan			intrcnt[HARDCLOCK]++;
4171.1Sjonathan		}
4181.10Sjonathan
4191.10Sjonathan		/* If clock interrups were enabled, re-enable them ASAP. */
4201.10Sjonathan		if (old_mask & KMIN_INTR_CLOCK) {
4211.17Snisimura			/* ioctl interrupt mask to splclock and higher */
4221.17Snisimura			*(u_int32_t *)(ioasic_base + IOASIC_IMSK)
4231.17Snisimura				= old_mask &
4241.17Snisimura					~(KMIN_INTR_SCC_0|KMIN_INTR_SCC_1 |
4251.17Snisimura					  IOASIC_INTR_LANCE|IOASIC_INTR_SCSI);
4261.14Snisimura			kn02ba_wbflush();
4271.17Snisimura			_splset(MIPS_SR_INT_IE | (status & MIPS_INT_MASK_3));
4281.10Sjonathan		}
4291.10Sjonathan
4301.11Sjonathan		if (intr_depth > 1)
4311.11Sjonathan			 goto done;
4321.11Sjonathan
4331.1Sjonathan		if ((intr & KMIN_INTR_SCC_0) &&
4341.1Sjonathan		    tc_slot_info[KMIN_SCC0_SLOT].intr) {
4351.1Sjonathan			(*(tc_slot_info[KMIN_SCC0_SLOT].intr))
4361.1Sjonathan			  (tc_slot_info[KMIN_SCC0_SLOT].sc);
4371.1Sjonathan			intrcnt[SERIAL0_INTR]++;
4381.1Sjonathan		}
4391.1Sjonathan
4401.1Sjonathan		if ((intr & KMIN_INTR_SCC_1) &&
4411.1Sjonathan		    tc_slot_info[KMIN_SCC1_SLOT].intr) {
4421.1Sjonathan			(*(tc_slot_info[KMIN_SCC1_SLOT].intr))
4431.1Sjonathan			  (tc_slot_info[KMIN_SCC1_SLOT].sc);
4441.1Sjonathan			intrcnt[SERIAL1_INTR]++;
4451.1Sjonathan		}
4461.10Sjonathan
4471.10Sjonathan#ifdef notyet /* untested */
4481.10Sjonathan		/* If tty interrupts were enabled, re-enable them ASAP. */
4491.10Sjonathan		if ((old_mask & (KMIN_INTR_SCC_1|KMIN_INTR_SCC_0)) ==
4501.10Sjonathan		     (KMIN_INTR_SCC_1|KMIN_INTR_SCC_0)) {
4511.12Ssimonb			*imaskp = old_mask &
4521.10Sjonathan			  ~(KMIN_INTR_SCC_0|KMIN_INTR_SCC_1 |
4531.10Sjonathan			  IOASIC_INTR_LANCE|IOASIC_INTR_SCSI);
4541.14Snisimura			kn02ba_wbflush();
4551.10Sjonathan		}
4561.10Sjonathan
4571.10Sjonathan		/* XXX until we know about SPLs of TC options. */
4581.10Sjonathan		if (intr_depth > 1)
4591.10Sjonathan			 goto done;
4601.10Sjonathan#endif
4611.9Sjonathan		if ((intr & IOASIC_INTR_LANCE) &&
4621.9Sjonathan		    tc_slot_info[KMIN_LANCE_SLOT].intr) {
4631.9Sjonathan			(*(tc_slot_info[KMIN_LANCE_SLOT].intr))
4641.9Sjonathan			  (tc_slot_info[KMIN_LANCE_SLOT].sc);
4651.9Sjonathan			intrcnt[LANCE_INTR]++;
4661.9Sjonathan		}
4671.9Sjonathan
4681.7Sjonathan		if ((intr & IOASIC_INTR_SCSI) &&
4691.1Sjonathan		    tc_slot_info[KMIN_SCSI_SLOT].intr) {
4701.1Sjonathan			(*(tc_slot_info[KMIN_SCSI_SLOT].intr))
4711.1Sjonathan			  (tc_slot_info[KMIN_SCSI_SLOT].sc);
4721.1Sjonathan			intrcnt[SCSI_INTR]++;
4731.1Sjonathan		}
4741.1Sjonathan
4751.1Sjonathan		if (user_warned && ((intr & KMIN_INTR_PSWARN) == 0)) {
4761.1Sjonathan			printf("%s\n", "Power supply ok now.");
4771.1Sjonathan			user_warned = 0;
4781.1Sjonathan		}
4791.1Sjonathan		if ((intr & KMIN_INTR_PSWARN) && (user_warned < 3)) {
4801.1Sjonathan			user_warned++;
4811.1Sjonathan			printf("%s\n", "Power supply overheating");
4821.1Sjonathan		}
4831.1Sjonathan	}
4841.17Snisimura	if ((cpumask & MIPS_INT_MASK_0) && tc_slot_info[0].intr) {
4851.1Sjonathan		(*tc_slot_info[0].intr)(tc_slot_info[0].sc);
4861.1Sjonathan		intrcnt[SLOT0_INTR]++;
4871.1Sjonathan 	}
4881.12Ssimonb
4891.17Snisimura	if ((cpumask & MIPS_INT_MASK_1) && tc_slot_info[1].intr) {
4901.1Sjonathan		(*tc_slot_info[1].intr)(tc_slot_info[1].sc);
4911.1Sjonathan		intrcnt[SLOT1_INTR]++;
4921.1Sjonathan	}
4931.17Snisimura	if ((cpumask & MIPS_INT_MASK_2) && tc_slot_info[2].intr) {
4941.1Sjonathan		(*tc_slot_info[2].intr)(tc_slot_info[2].sc);
4951.1Sjonathan		intrcnt[SLOT2_INTR]++;
4961.1Sjonathan	}
4971.1Sjonathan
4981.10Sjonathandone:
4991.10Sjonathan	/* restore entry state */
5001.10Sjonathan	splhigh();
5011.10Sjonathan	intr_depth--;
5021.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_IMSK) = old_mask;
5031.10Sjonathan
5041.14Snisimura
5051.17Snisimura	return (MIPS_SR_INT_IE | (status & ~cause & MIPS_HARD_INT_MASK));
5061.1Sjonathan}
5071.1Sjonathan
5081.1Sjonathan
5091.1Sjonathan
5101.1Sjonathan/*
5111.1Sjonathan ************************************************************************
5121.1Sjonathan * Extra functions
5131.1Sjonathan ************************************************************************
5141.1Sjonathan */
5151.1Sjonathan
5161.1Sjonathan
5171.1Sjonathan
5181.1Sjonathan
5191.1Sjonathan/*
5201.1Sjonathan * Count instructions between 4ms mcclock interrupt requests,
5211.1Sjonathan * using the ioasic clock-interrupt-pending bit to determine
5221.12Ssimonb * when clock ticks occur.
5231.1Sjonathan * Set up iosiac to allow only clock interrupts, then
5241.12Ssimonb * call
5251.1Sjonathan */
5261.1Sjonathanvoid
5271.1Sjonathandec_3min_mcclock_cpuspeed(mcclock_addr, clockmask)
5281.1Sjonathan	volatile struct chiptime *mcclock_addr;
5291.1Sjonathan	int clockmask;
5301.1Sjonathan{
5311.17Snisimura	u_int32_t saved_imask;
5321.1Sjonathan
5331.17Snisimura	saved_imask = *(u_int32_t *)(ioasic_base + IOASIC_IMSK);
5341.1Sjonathan
5351.1Sjonathan	/* Allow only clock interrupts through ioasic. */
5361.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_IMSK) = KMIN_INTR_CLOCK;
5371.14Snisimura	kn02ba_wbflush();
5381.12Ssimonb
5391.1Sjonathan	mc_cpuspeed(mcclock_addr, clockmask);
5401.1Sjonathan
5411.17Snisimura	*(u_int32_t *)(ioasic_base + IOASIC_IMSK) = saved_imask;
5421.14Snisimura	kn02ba_wbflush();
5431.14Snisimura}
5441.14Snisimura
5451.14Snisimuravoid
5461.14Snisimurakn02ba_wbflush()
5471.14Snisimura{
5481.21Snisimura	/* read twice IOASIC_IMSK */
5491.21Snisimura	__asm __volatile("lw $0,%0; lw $0,%0" :: "i"(0xbc040120));
5501.14Snisimura}
5511.14Snisimura
5521.14Snisimuraunsigned
5531.14Snisimurakn02ba_clkread()
5541.14Snisimura{
5551.14Snisimura#ifdef MIPS3
5561.14Snisimura	if (CPUISMIPS3) {
5571.14Snisimura		u_int32_t mips3_cycles;
5581.14Snisimura
5591.14Snisimura		mips3_cycles = mips3_cycle_count() - latched_cycle_cnt;
5601.14Snisimura		/* XXX divides take 78 cycles: approximate with * 41/2048 */
5611.14Snisimura		return((mips3_cycles >> 6) + (mips3_cycles >> 8) +
5621.14Snisimura		       (mips3_cycles >> 11));
5631.14Snisimura	}
5641.14Snisimura#endif
5651.14Snisimura	return 0;
5661.1Sjonathan}
567