dec_3min.c revision 1.66
11.66Smatt/* $NetBSD: dec_3min.c,v 1.66 2009/12/14 00:46:10 matt 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.66Smatt__KERNEL_RCSID(0, "$NetBSD: dec_3min.c,v 1.66 2009/12/14 00:46:10 matt Exp $");
1101.1Sjonathan
1111.34Snisimura#include <sys/param.h>
1121.1Sjonathan#include <sys/systm.h>
1131.34Snisimura#include <sys/device.h>
1141.59Sjoerg#include <sys/timetc.h>
1151.1Sjonathan
1161.1Sjonathan#include <machine/cpu.h>
1171.1Sjonathan#include <machine/intr.h>
1181.1Sjonathan#include <machine/sysconf.h>
1191.1Sjonathan
1201.1Sjonathan#include <mips/mips/mips_mcclock.h>	/* mcclock CPUspeed estimation */
1211.2Sjonathan
1221.2Sjonathan/* all these to get ioasic_base */
1231.2Sjonathan#include <dev/tc/tcvar.h>		/* tc type definitions for.. */
1241.7Sjonathan#include <dev/tc/ioasicreg.h>		/* ioasic interrrupt masks */
1251.2Sjonathan#include <dev/tc/ioasicvar.h>		/* ioasic_base */
1261.1Sjonathan
1271.20Ssimonb#include <pmax/pmax/machdep.h>
1281.1Sjonathan#include <pmax/pmax/kmin.h>		/* 3min baseboard addresses */
1291.15Snisimura#include <pmax/pmax/memc.h>		/* 3min/maxine memory errors */
1301.51Sad
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.1Sjonathan
1361.61Sdslvoid		dec_3min_init(void);		/* XXX */
1371.61Sdslstatic void	dec_3min_bus_reset(void);
1381.61Sdslstatic void	dec_3min_cons_init(void);
1391.61Sdslstatic void	dec_3min_intr(unsigned, unsigned, unsigned, unsigned);
1401.61Sdslstatic void	dec_3min_intr_establish(struct device *, void *,
1411.61Sdsl		    int, int (*)(void *), void *);
1421.1Sjonathan
1431.61Sdslstatic void	kn02ba_wbflush(void);
1441.1Sjonathan
1451.59Sjoergstatic void	dec_3min_tc_init(void);
1461.1Sjonathan
1471.1Sjonathan/*
1481.1Sjonathan * Local declarations.
1491.1Sjonathan */
1501.65Stsutsuistatic uint32_t kmin_tc3_imask;
1511.18Snisimura
1521.57Syamtstatic const int dec_3min_ipl2spl_table[] = {
1531.57Syamt	[IPL_NONE] = 0,
1541.57Syamt	[IPL_SOFTCLOCK] = _SPL_SOFTCLOCK,
1551.57Syamt	[IPL_SOFTNET] = _SPL_SOFTNET,
1561.57Syamt	/*
1571.57Syamt	 * Since all the motherboard interrupts come through the
1581.57Syamt	 * IOASIC, it has to be turned off for all the spls and
1591.57Syamt	 * since we don't know what kinds of devices are in the
1601.57Syamt	 * TURBOchannel option slots, just splhigh().
1611.57Syamt	 */
1621.57Syamt	[IPL_VM] = MIPS_SPL_0_1_2_3,
1631.58Sad	[IPL_SCHED] = MIPS_SPL_0_1_2_3,
1641.58Sad	[IPL_HIGH] = MIPS_SPL_0_1_2_3,
1651.57Syamt};
1661.1Sjonathan
1671.1Sjonathanvoid
1681.65Stsutsuidec_3min_init(void)
1691.1Sjonathan{
1701.65Stsutsui
1711.24Snisimura	platform.iobus = "tcbus";
1721.1Sjonathan	platform.bus_reset = dec_3min_bus_reset;
1731.1Sjonathan	platform.cons_init = dec_3min_cons_init;
1741.22Snisimura	platform.iointr = dec_3min_intr;
1751.33Ssimonb	platform.intr_establish = dec_3min_intr_establish;
1761.47Smhitch	platform.memsize = memsize_bitmap;
1771.59Sjoerg	platform.tc_init = dec_3min_tc_init;
1781.1Sjonathan
1791.22Snisimura	/* clear any memory errors */
1801.65Stsutsui	*(volatile uint32_t *)MIPS_PHYS_TO_KSEG1(KMIN_REG_TIMEOUT) = 0;
1811.14Snisimura	kn02ba_wbflush();
1821.1Sjonathan
1831.1Sjonathan	ioasic_base = MIPS_PHYS_TO_KSEG1(KMIN_SYS_ASIC);
1841.1Sjonathan
1851.57Syamt	ipl2spl_table = dec_3min_ipl2spl_table;
1861.16Snisimura
1871.28Snisimura	/* enable posting of MIPS_INT_MASK_3 to CAUSE register */
1881.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_IMSK) = KMIN_INTR_CLOCK;
1891.44Stsutsui	/* calibrate cpu_mhz value */
1901.29Snisimura	mc_cpuspeed(ioasic_base+IOASIC_SLOT_8_START, MIPS_INT_MASK_3);
1911.1Sjonathan
1921.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_LANCE_DECODE) = 0x3;
1931.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_SCSI_DECODE) = 0xe;
1941.44Stsutsui#if 0
1951.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_SCC0_DECODE) = (0x10|4);
1961.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_SCC1_DECODE) = (0x10|6);
1971.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_CSR) = 0x00000f00;
1981.44Stsutsui#endif
1991.44Stsutsui
2001.22Snisimura	/* sanitize interrupt mask */
2011.22Snisimura	kmin_tc3_imask = (KMIN_INTR_CLOCK|KMIN_INTR_PSWARN|KMIN_INTR_TIMEOUT);
2021.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_INTR) = 0;
2031.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_IMSK) = kmin_tc3_imask;
2041.1Sjonathan
2051.1Sjonathan	/*
2061.22Snisimura	 * The kmin memory hardware seems to wrap memory addresses
2071.1Sjonathan	 * with 4Mbyte SIMMs, which causes the physmem computation
2081.1Sjonathan	 * to lose.  Find out how big the SIMMS are and set
2091.22Snisimura	 * max_ physmem accordingly.
2101.22Snisimura	 * XXX Do MAXINEs lose the same way?
2111.1Sjonathan	 */
2121.1Sjonathan	physmem_boardmax = KMIN_PHYS_MEMORY_END + 1;
2131.22Snisimura	if ((KMIN_MSR_SIZE_16Mb & *(int *)MIPS_PHYS_TO_KSEG1(KMIN_REG_MSR))
2141.65Stsutsui	    == 0)
2151.1Sjonathan		physmem_boardmax = physmem_boardmax >> 2;
2161.1Sjonathan	physmem_boardmax = MIPS_PHYS_TO_KSEG1(physmem_boardmax);
2171.10Sjonathan
2181.22Snisimura	sprintf(cpu_model, "DECstation 5000/1%d (3MIN)", cpu_mhz);
2191.22Snisimura}
2201.22Snisimura
2211.22Snisimura/*
2221.49Stsutsui * Initialize the memory system and I/O buses.
2231.22Snisimura */
2241.31Ssimonbstatic void
2251.65Stsutsuidec_3min_bus_reset(void)
2261.22Snisimura{
2271.22Snisimura
2281.22Snisimura	/*
2291.22Snisimura	 * Reset interrupts, clear any errors from newconf probes
2301.22Snisimura	 */
2311.22Snisimura
2321.65Stsutsui	*(volatile uint32_t *)MIPS_PHYS_TO_KSEG1(KMIN_REG_TIMEOUT) = 0;
2331.17Snisimura	kn02ba_wbflush();
2341.17Snisimura
2351.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_INTR) = 0;
2361.22Snisimura	kn02ba_wbflush();
2371.1Sjonathan}
2381.1Sjonathan
2391.31Ssimonbstatic void
2401.65Stsutsuidec_3min_cons_init(void)
2411.1Sjonathan{
2421.34Snisimura	int kbd, crt, screen;
2431.34Snisimura
2441.34Snisimura	kbd = crt = screen = 0;
2451.34Snisimura	prom_findcons(&kbd, &crt, &screen);
2461.34Snisimura
2471.34Snisimura	if (screen > 0) {
2481.51Sad#if NWSDISPLAY > 0
2491.51Sad 		if (tcfb_cnattach(crt) > 0) {
2501.51Sad			zs_ioasic_lk201_cnattach(ioasic_base, 0x180000, 0);
2511.51Sad 			return;
2521.51Sad 		}
2531.34Snisimura#endif
2541.34Snisimura		printf("No framebuffer device configured for slot %d: ", crt);
2551.34Snisimura		printf("using serial console\n");
2561.34Snisimura	}
2571.34Snisimura	/*
2581.34Snisimura	 * Delay to allow PROM putchars to complete.
2591.34Snisimura	 * FIFO depth * character time,
2601.34Snisimura	 * character time = (1000000 / (defaultrate / 10))
2611.34Snisimura	 */
2621.34Snisimura	DELAY(160000000 / 9600);	/* XXX */
2631.34Snisimura
2641.51Sad	zs_ioasic_cnattach(ioasic_base, 0x180000, 1);
2651.1Sjonathan}
2661.1Sjonathan
2671.31Ssimonbstatic void
2681.65Stsutsuidec_3min_intr_establish(struct device *dev, void *cookie, int level,
2691.65Stsutsui    int (*handler)(void *), void *arg)
2701.1Sjonathan{
2711.65Stsutsui	uint32_t mask;
2721.1Sjonathan
2731.66Smatt	switch ((uintptr_t)cookie) {
2741.1Sjonathan		/* slots 0-2 don't interrupt through the IOASIC. */
2751.65Stsutsui	case SYS_DEV_OPT0:
2761.33Ssimonb		mask = MIPS_INT_MASK_0;
2771.33Ssimonb		break;
2781.65Stsutsui	case SYS_DEV_OPT1:
2791.33Ssimonb		mask = MIPS_INT_MASK_1;
2801.33Ssimonb		break;
2811.65Stsutsui	case SYS_DEV_OPT2:
2821.33Ssimonb		mask = MIPS_INT_MASK_2;
2831.33Ssimonb		break;
2841.1Sjonathan
2851.65Stsutsui	case SYS_DEV_SCSI:
2861.7Sjonathan		mask = (IOASIC_INTR_SCSI | IOASIC_INTR_SCSI_PTR_LOAD |
2871.7Sjonathan			IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E);
2881.1Sjonathan		break;
2891.65Stsutsui	case SYS_DEV_LANCE:
2901.1Sjonathan		mask = KMIN_INTR_LANCE;
2911.1Sjonathan		break;
2921.65Stsutsui	case SYS_DEV_SCC0:
2931.1Sjonathan		mask = KMIN_INTR_SCC_0;
2941.1Sjonathan		break;
2951.65Stsutsui	case SYS_DEV_SCC1:
2961.1Sjonathan		mask = KMIN_INTR_SCC_1;
2971.1Sjonathan		break;
2981.65Stsutsui	default:
2991.33Ssimonb#ifdef DIAGNOSTIC
3001.66Smatt		printf("warning: enabling unknown intr %p\n", cookie);
3011.33Ssimonb#endif
3021.1Sjonathan		return;
3031.1Sjonathan	}
3041.1Sjonathan
3051.38Sad#if defined(DEBUG)
3061.66Smatt	printf("3MIN: imask %x, enabling slot %p, dev %p handler %p\n",
3071.66Smatt	    kmin_tc3_imask, cookie, dev, handler);
3081.1Sjonathan#endif
3091.1Sjonathan
3101.1Sjonathan	/*
3111.1Sjonathan	 * Enable the interrupt  handler, and if it's an IOASIC
3121.1Sjonathan	 * slot, set the IOASIC interrupt mask.
3131.1Sjonathan	 * Otherwise, set the appropriate spl level in the R3000
3141.1Sjonathan	 * register.
3151.35Snisimura	 * Be careful to set handlers before enabling, and disable
3161.1Sjonathan	 * interrupts before clearing handlers.
3171.1Sjonathan	 */
3181.1Sjonathan
3191.33Ssimonb	/* Set the interrupt handler and argument ... */
3201.66Smatt	intrtab[(uintptr_t)cookie].ih_func = handler;
3211.66Smatt	intrtab[(uintptr_t)cookie].ih_arg = arg;
3221.33Ssimonb	/* ... and set the relevant mask */
3231.66Smatt	switch ((uintptr_t)cookie) {
3241.35Snisimura	case SYS_DEV_OPT0:
3251.35Snisimura	case SYS_DEV_OPT1:
3261.35Snisimura	case SYS_DEV_OPT2:
3271.33Ssimonb		/* it's an option slot */
3281.35Snisimura		{
3291.33Ssimonb		int s = splhigh();
3301.33Ssimonb		s |= mask;
3311.33Ssimonb		splx(s);
3321.35Snisimura		}
3331.35Snisimura		break;
3341.35Snisimura	default:
3351.35Snisimura		/* it's a baseboard device going via the IOASIC */
3361.33Ssimonb		kmin_tc3_imask |= mask;
3371.35Snisimura		break;
3381.1Sjonathan	}
3391.33Ssimonb
3401.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_IMSK) = kmin_tc3_imask;
3411.25Snisimura	kn02ba_wbflush();
3421.1Sjonathan}
3431.1Sjonathan
3441.1Sjonathan
3451.44Stsutsui#define CHECKINTR(slot, bits)					\
3461.35Snisimura    do {							\
3471.44Stsutsui	if (can_serve & (bits)) {				\
3481.52Ssimonb		intrtab[slot].ih_count.ev_count++;		\
3491.44Stsutsui		(*intrtab[slot].ih_func)(intrtab[slot].ih_arg);	\
3501.44Stsutsui	}							\
3511.65Stsutsui    } while (/*CONSTCOND*/0)
3521.1Sjonathan
3531.42Snisimurastatic void
3541.65Stsutsuidec_3min_intr(uint32_t status, uint32_t cause, uint32_t pc, uint32_t ipending)
3551.1Sjonathan{
3561.1Sjonathan	static int user_warned = 0;
3571.17Snisimura	static int intr_depth = 0;
3581.65Stsutsui	uint32_t old_mask;
3591.1Sjonathan
3601.10Sjonathan	intr_depth++;
3611.65Stsutsui	old_mask = *(volatile uint32_t *)(ioasic_base + IOASIC_IMSK);
3621.10Sjonathan
3631.39Snisimura	if (ipending & MIPS_INT_MASK_4)
3641.1Sjonathan		prom_haltbutton();
3651.1Sjonathan
3661.39Snisimura	if (ipending & MIPS_INT_MASK_3) {
3671.10Sjonathan		/* NB: status & MIPS_INT_MASK3 must also be set */
3681.10Sjonathan		/* masked interrupts are still observable */
3691.65Stsutsui		uint32_t intr, imsk, can_serve, turnoff;
3701.17Snisimura
3711.17Snisimura		turnoff = 0;
3721.65Stsutsui		intr = *(volatile uint32_t *)(ioasic_base + IOASIC_INTR);
3731.65Stsutsui		imsk = *(volatile uint32_t *)(ioasic_base + IOASIC_IMSK);
3741.35Snisimura		can_serve = intr & imsk;
3751.1Sjonathan
3761.7Sjonathan		if (intr & IOASIC_INTR_SCSI_PTR_LOAD) {
3771.17Snisimura			turnoff |= IOASIC_INTR_SCSI_PTR_LOAD;
3781.1Sjonathan#ifdef notdef
3791.1Sjonathan			asc_dma_intr();
3801.1Sjonathan#endif
3811.1Sjonathan		}
3821.12Ssimonb
3831.7Sjonathan		if (intr & (IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E))
3841.65Stsutsui			turnoff |=
3851.65Stsutsui			    IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E;
3861.1Sjonathan
3871.7Sjonathan		if (intr & IOASIC_INTR_LANCE_READ_E)
3881.17Snisimura			turnoff |= IOASIC_INTR_LANCE_READ_E;
3891.17Snisimura
3901.17Snisimura		if (turnoff)
3911.65Stsutsui			*(volatile uint32_t *)(ioasic_base + IOASIC_INTR) =
3921.65Stsutsui			    ~turnoff;
3931.1Sjonathan
3941.48Snisimura		if (intr & KMIN_INTR_TIMEOUT) {
3951.1Sjonathan			kn02ba_errintr();
3961.48Snisimura			pmax_memerr_evcnt.ev_count++;
3971.48Snisimura		}
3981.12Ssimonb
3991.1Sjonathan		if (intr & KMIN_INTR_CLOCK) {
4001.17Snisimura			struct clockframe cf;
4011.17Snisimura
4021.54Sperry			__asm volatile("lbu $0,48(%0)" ::
4031.22Snisimura				"r"(ioasic_base + IOASIC_SLOT_8_START));
4041.59Sjoerg
4051.17Snisimura			cf.pc = pc;
4061.17Snisimura			cf.sr = status;
4071.1Sjonathan			hardclock(&cf);
4081.46Snisimura			pmax_clock_evcnt.ev_count++;
4091.1Sjonathan		}
4101.10Sjonathan
4111.55Swiz		/* If clock interrupts were enabled, re-enable them ASAP. */
4121.10Sjonathan		if (old_mask & KMIN_INTR_CLOCK) {
4131.17Snisimura			/* ioctl interrupt mask to splclock and higher */
4141.65Stsutsui			*(volatile uint32_t *)(ioasic_base + IOASIC_IMSK)
4151.17Snisimura				= old_mask &
4161.17Snisimura					~(KMIN_INTR_SCC_0|KMIN_INTR_SCC_1 |
4171.17Snisimura					  IOASIC_INTR_LANCE|IOASIC_INTR_SCSI);
4181.14Snisimura			kn02ba_wbflush();
4191.17Snisimura			_splset(MIPS_SR_INT_IE | (status & MIPS_INT_MASK_3));
4201.10Sjonathan		}
4211.10Sjonathan
4221.11Sjonathan		if (intr_depth > 1)
4231.11Sjonathan			 goto done;
4241.11Sjonathan
4251.35Snisimura		CHECKINTR(SYS_DEV_SCC0, IOASIC_INTR_SCC_0);
4261.35Snisimura		CHECKINTR(SYS_DEV_SCC1, IOASIC_INTR_SCC_1);
4271.10Sjonathan
4281.10Sjonathan#ifdef notyet /* untested */
4291.10Sjonathan		/* If tty interrupts were enabled, re-enable them ASAP. */
4301.10Sjonathan		if ((old_mask & (KMIN_INTR_SCC_1|KMIN_INTR_SCC_0)) ==
4311.10Sjonathan		     (KMIN_INTR_SCC_1|KMIN_INTR_SCC_0)) {
4321.12Ssimonb			*imaskp = old_mask &
4331.10Sjonathan			  ~(KMIN_INTR_SCC_0|KMIN_INTR_SCC_1 |
4341.10Sjonathan			  IOASIC_INTR_LANCE|IOASIC_INTR_SCSI);
4351.14Snisimura			kn02ba_wbflush();
4361.10Sjonathan		}
4371.10Sjonathan
4381.10Sjonathan		/* XXX until we know about SPLs of TC options. */
4391.10Sjonathan		if (intr_depth > 1)
4401.10Sjonathan			 goto done;
4411.10Sjonathan#endif
4421.35Snisimura		CHECKINTR(SYS_DEV_LANCE, IOASIC_INTR_LANCE);
4431.35Snisimura		CHECKINTR(SYS_DEV_SCSI, IOASIC_INTR_SCSI);
4441.1Sjonathan
4451.1Sjonathan		if (user_warned && ((intr & KMIN_INTR_PSWARN) == 0)) {
4461.1Sjonathan			printf("%s\n", "Power supply ok now.");
4471.1Sjonathan			user_warned = 0;
4481.1Sjonathan		}
4491.1Sjonathan		if ((intr & KMIN_INTR_PSWARN) && (user_warned < 3)) {
4501.1Sjonathan			user_warned++;
4511.1Sjonathan			printf("%s\n", "Power supply overheating");
4521.1Sjonathan		}
4531.1Sjonathan	}
4541.39Snisimura	if ((ipending & MIPS_INT_MASK_0) && intrtab[SYS_DEV_OPT0].ih_func) {
4551.35Snisimura		(*intrtab[SYS_DEV_OPT0].ih_func)(intrtab[SYS_DEV_OPT0].ih_arg);
4561.52Ssimonb		intrtab[SYS_DEV_OPT0].ih_count.ev_count++;
4571.1Sjonathan 	}
4581.12Ssimonb
4591.39Snisimura	if ((ipending & MIPS_INT_MASK_1) && intrtab[SYS_DEV_OPT1].ih_func) {
4601.35Snisimura		(*intrtab[SYS_DEV_OPT1].ih_func)(intrtab[SYS_DEV_OPT1].ih_arg);
4611.52Ssimonb		intrtab[SYS_DEV_OPT1].ih_count.ev_count++;
4621.1Sjonathan	}
4631.39Snisimura	if ((ipending & MIPS_INT_MASK_2) && intrtab[SYS_DEV_OPT2].ih_func) {
4641.35Snisimura		(*intrtab[SYS_DEV_OPT2].ih_func)(intrtab[SYS_DEV_OPT2].ih_arg);
4651.52Ssimonb		intrtab[SYS_DEV_OPT2].ih_count.ev_count++;
4661.1Sjonathan	}
4671.1Sjonathan
4681.10Sjonathandone:
4691.10Sjonathan	/* restore entry state */
4701.10Sjonathan	splhigh();
4711.10Sjonathan	intr_depth--;
4721.65Stsutsui	*(volatile uint32_t *)(ioasic_base + IOASIC_IMSK) = old_mask;
4731.10Sjonathan
4741.42Snisimura	_splset(MIPS_SR_INT_IE | (status & ~cause & MIPS_HARD_INT_MASK));
4751.1Sjonathan}
4761.1Sjonathan
4771.1Sjonathan
4781.1Sjonathan
4791.1Sjonathan/*
4801.1Sjonathan ************************************************************************
4811.1Sjonathan * Extra functions
4821.1Sjonathan ************************************************************************
4831.1Sjonathan */
4841.14Snisimura
4851.31Ssimonbstatic void
4861.65Stsutsuikn02ba_wbflush(void)
4871.14Snisimura{
4881.65Stsutsui
4891.21Snisimura	/* read twice IOASIC_IMSK */
4901.54Sperry	__asm volatile("lw $0,%0; lw $0,%0" ::
4911.27Ssimonb	    "i"(MIPS_PHYS_TO_KSEG1(KMIN_REG_IMSK)));
4921.14Snisimura}
4931.14Snisimura
4941.59Sjoerg/*
4951.59Sjoerg * Support for using the MIPS 3 clock as a timecounter.
4961.59Sjoerg */
4971.59Sjoerg
4981.59Sjoergvoid
4991.59Sjoergdec_3min_tc_init(void)
5001.14Snisimura{
5011.60Stsutsui#if defined(MIPS3)
5021.59Sjoerg	static struct timecounter tc =  {
5031.59Sjoerg		.tc_get_timecount = (timecounter_get_t *)mips3_cp0_count_read,
5041.59Sjoerg		.tc_counter_mask = ~0u,
5051.59Sjoerg		.tc_name = "mips3_cp0_counter",
5061.59Sjoerg		.tc_quality = 100,
5071.59Sjoerg	};
5081.59Sjoerg
5091.59Sjoerg	if (MIPS_HAS_CLOCK) {
5101.59Sjoerg		tc.tc_frequency = cpu_mhz * 1000000;
5111.59Sjoerg		if (mips_cpu_flags & CPU_MIPS_DOUBLE_COUNT) {
5121.59Sjoerg			tc.tc_frequency /= 2;
5131.59Sjoerg		}
5141.59Sjoerg
5151.59Sjoerg		tc_init(&tc);
5161.14Snisimura	}
5171.60Stsutsui#endif
5181.1Sjonathan}
519