Home | History | Annotate | Line # | Download | only in newsmips
news5000.c revision 1.6
      1  1.6    onoe /*	$NetBSD: news5000.c,v 1.6 2000/10/12 03:10:37 onoe Exp $	*/
      2  1.1  tsubai 
      3  1.1  tsubai /*-
      4  1.1  tsubai  * Copyright (C) 1999 SHIMIZU Ryo.  All rights reserved.
      5  1.1  tsubai  *
      6  1.1  tsubai  * Redistribution and use in source and binary forms, with or without
      7  1.1  tsubai  * modification, are permitted provided that the following conditions
      8  1.1  tsubai  * are met:
      9  1.1  tsubai  * 1. Redistributions of source code must retain the above copyright
     10  1.1  tsubai  *    notice, this list of conditions and the following disclaimer.
     11  1.1  tsubai  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  tsubai  *    notice, this list of conditions and the following disclaimer in the
     13  1.1  tsubai  *    documentation and/or other materials provided with the distribution.
     14  1.1  tsubai  * 3. The name of the author may not be used to endorse or promote products
     15  1.1  tsubai  *    derived from this software without specific prior written permission.
     16  1.1  tsubai  *
     17  1.1  tsubai  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18  1.1  tsubai  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19  1.1  tsubai  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20  1.1  tsubai  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21  1.1  tsubai  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22  1.1  tsubai  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23  1.1  tsubai  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24  1.1  tsubai  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25  1.1  tsubai  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     26  1.1  tsubai  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  1.1  tsubai  */
     28  1.1  tsubai 
     29  1.1  tsubai #include <sys/param.h>
     30  1.1  tsubai #include <sys/systm.h>
     31  1.1  tsubai #include <sys/kernel.h>
     32  1.1  tsubai 
     33  1.1  tsubai #include <machine/adrsmap.h>
     34  1.1  tsubai #include <machine/cpu.h>
     35  1.1  tsubai #include <machine/intr.h>
     36  1.1  tsubai 
     37  1.1  tsubai #include <newsmips/apbus/apbusvar.h>
     38  1.1  tsubai #include <newsmips/newsmips/machid.h>
     39  1.1  tsubai 
     40  1.6    onoe extern void (*readmicrotime) __P((struct timeval *tvp));
     41  1.6    onoe 
     42  1.2  tsubai static void level1_intr __P((void));
     43  1.2  tsubai static void level0_intr __P((void));
     44  1.1  tsubai 
     45  1.6    onoe static u_int freerun_off;
     46  1.6    onoe 
     47  1.1  tsubai /*
     48  1.1  tsubai  * Handle news5000 interrupts.
     49  1.1  tsubai  */
     50  1.4  tsubai void
     51  1.4  tsubai news5000_intr(status, cause, pc, ipending)
     52  1.2  tsubai 	u_int status;	/* status register at time of the exception */
     53  1.2  tsubai 	u_int cause;	/* cause register at time of exception */
     54  1.4  tsubai 	u_int pc;	/* program counter where to continue */
     55  1.4  tsubai 	u_int ipending;
     56  1.1  tsubai {
     57  1.4  tsubai 	if (ipending & MIPS_INT_MASK_2) {
     58  1.2  tsubai #ifdef DEBUG
     59  1.2  tsubai 		static int l2cnt = 0;
     60  1.2  tsubai #endif
     61  1.2  tsubai 		u_int int2stat;
     62  1.2  tsubai 		struct clockframe cf;
     63  1.2  tsubai 
     64  1.2  tsubai 		int2stat = *(volatile u_int *)NEWS5000_INTST2;
     65  1.2  tsubai 
     66  1.2  tsubai #ifdef DEBUG
     67  1.2  tsubai 		l2cnt++;
     68  1.2  tsubai 		if (l2cnt == 50) {
     69  1.2  tsubai 			*(volatile u_int *)NEWS5000_LED_SEC = 1;
     70  1.2  tsubai 		}
     71  1.2  tsubai 		if (l2cnt == 100) {
     72  1.2  tsubai 			*(volatile u_int *)NEWS5000_LED_SEC = 0;
     73  1.2  tsubai 			l2cnt = 0;
     74  1.2  tsubai 		}
     75  1.2  tsubai #endif
     76  1.2  tsubai 
     77  1.2  tsubai 		if (int2stat & NEWS5000_INT2_TIMER0) {
     78  1.2  tsubai 			*(volatile u_int *)NEWS5000_TIMER0 = 1;
     79  1.6    onoe 			freerun_off = *(volatile u_int *)NEWS5000_FREERUN;
     80  1.2  tsubai 
     81  1.2  tsubai 			cf.pc = pc;
     82  1.2  tsubai 			cf.sr = status;
     83  1.2  tsubai 
     84  1.2  tsubai 			hardclock(&cf);
     85  1.2  tsubai 			intrcnt[HARDCLOCK_INTR]++;
     86  1.2  tsubai 		}
     87  1.2  tsubai 
     88  1.1  tsubai 		apbus_wbflush();
     89  1.2  tsubai 		cause &= ~MIPS_INT_MASK_2;
     90  1.1  tsubai 	}
     91  1.1  tsubai 	/* If clock interrupts were enabled, re-enable them ASAP. */
     92  1.4  tsubai 	_splset(MIPS_SR_INT_IE | (status & MIPS_INT_MASK_2));
     93  1.1  tsubai 
     94  1.4  tsubai 	if (ipending & MIPS_INT_MASK_5) {
     95  1.2  tsubai 		u_int int5stat = *(volatile u_int *)NEWS5000_INTST5;
     96  1.2  tsubai 		printf("level5 interrupt (%08x)\n", int5stat);
     97  1.2  tsubai 
     98  1.1  tsubai 		apbus_wbflush();
     99  1.2  tsubai 		cause &= ~MIPS_INT_MASK_5;
    100  1.1  tsubai 	}
    101  1.1  tsubai 
    102  1.4  tsubai 	if (ipending & MIPS_INT_MASK_4) {
    103  1.2  tsubai 		u_int int4stat = *(volatile u_int *)NEWS5000_INTST4;
    104  1.2  tsubai 		printf("level4 interrupt (%08x)\n", int4stat);
    105  1.6    onoe 		if (int4stat & NEWS5000_INT4_APBUS) {
    106  1.6    onoe 			u_int stat = *(volatile u_int *)NEWS5000_APBUS_INTST;
    107  1.6    onoe 			printf("APbus error 0x%04x\n", stat & 0xffff);
    108  1.6    onoe 			if (stat & NEWS5000_APBUS_INT_DMAADDR) {
    109  1.6    onoe 				printf("DMA Address Error: slot=%x, addr=0x%08x\n",
    110  1.6    onoe 				    *(volatile u_int *)NEWS5000_APBUS_DER_S,
    111  1.6    onoe 				    *(volatile u_int *)NEWS5000_APBUS_DER_A);
    112  1.6    onoe 			}
    113  1.6    onoe 			if (stat & NEWS5000_APBUS_INT_RDTIMEO)
    114  1.6    onoe 				printf("IO Read Timeout: addr=0x%08x\n",
    115  1.6    onoe 				    *(volatile u_int *)NEWS5000_APBUS_BER_A);
    116  1.6    onoe 			if (stat & NEWS5000_APBUS_INT_WRTIMEO)
    117  1.6    onoe 				printf("IO Write Timeout: addr=0x%08x\n",
    118  1.6    onoe 				    *(volatile u_int *)NEWS5000_APBUS_BER_A);
    119  1.6    onoe 			*(volatile u_int *)0xb4c00014 = stat;
    120  1.6    onoe 		}
    121  1.2  tsubai 
    122  1.1  tsubai 		apbus_wbflush();
    123  1.2  tsubai 		cause &= ~MIPS_INT_MASK_4;
    124  1.1  tsubai 	}
    125  1.1  tsubai 
    126  1.4  tsubai 	if (ipending & MIPS_INT_MASK_3) {
    127  1.2  tsubai 		u_int int3stat = *(volatile u_int *)NEWS5000_INTST3;
    128  1.2  tsubai 		printf("level3 interrupt (%08x)\n", int3stat);
    129  1.2  tsubai 
    130  1.1  tsubai 		apbus_wbflush();
    131  1.2  tsubai 		cause &= ~MIPS_INT_MASK_3;
    132  1.1  tsubai 	}
    133  1.1  tsubai 
    134  1.4  tsubai 	if (ipending & MIPS_INT_MASK_1) {
    135  1.2  tsubai 		level1_intr();
    136  1.1  tsubai 		apbus_wbflush();
    137  1.2  tsubai 		cause &= ~MIPS_INT_MASK_1;
    138  1.1  tsubai 	}
    139  1.1  tsubai 
    140  1.4  tsubai 	if (ipending & MIPS_INT_MASK_0) {
    141  1.2  tsubai 		level0_intr();
    142  1.1  tsubai 		apbus_wbflush();
    143  1.2  tsubai 		cause &= ~MIPS_INT_MASK_0;
    144  1.1  tsubai 	}
    145  1.1  tsubai 
    146  1.4  tsubai 	_splset((status & ~cause & MIPS_HARD_INT_MASK) | MIPS_SR_INT_IE);
    147  1.1  tsubai }
    148  1.1  tsubai 
    149  1.1  tsubai 
    150  1.1  tsubai void
    151  1.2  tsubai level1_intr()
    152  1.1  tsubai {
    153  1.2  tsubai 	u_int int1stat;
    154  1.1  tsubai 
    155  1.2  tsubai 	int1stat = *(volatile u_int *)NEWS5000_INTST1;
    156  1.1  tsubai 
    157  1.1  tsubai 	if (int1stat) {
    158  1.2  tsubai 		if (apbus_intr_call(1, int1stat) == 0)
    159  1.3  tsubai 			printf("level1_intr: no handler (mask 0x%04x)\n",
    160  1.2  tsubai 			       int1stat);
    161  1.2  tsubai 	} else
    162  1.1  tsubai 		printf("level1 stray interrupt?\n");
    163  1.1  tsubai }
    164  1.1  tsubai 
    165  1.1  tsubai void
    166  1.2  tsubai level0_intr()
    167  1.1  tsubai {
    168  1.2  tsubai 	u_int int0stat;
    169  1.1  tsubai 
    170  1.2  tsubai 	int0stat = *(volatile u_int *)NEWS5000_INTST0;
    171  1.1  tsubai 
    172  1.1  tsubai 	if (int0stat) {
    173  1.2  tsubai 		if (apbus_intr_call(0, int0stat) == 0)
    174  1.2  tsubai 			printf("level0_intr: no handler (mask 0x%04x)\n",
    175  1.2  tsubai 			       int0stat);
    176  1.2  tsubai 	} else
    177  1.1  tsubai 		printf("level0 stray interrupt?\n");
    178  1.1  tsubai }
    179  1.1  tsubai 
    180  1.1  tsubai void
    181  1.1  tsubai enable_intr_5000()
    182  1.1  tsubai {
    183  1.2  tsubai 
    184  1.6    onoe 	/* INT0 and INT1 has been enabled at attach */
    185  1.6    onoe 	/* INT2 -- It's not a time to enable timer yet. */
    186  1.6    onoe 	/* INT3 -- not used for NWS-5000 */
    187  1.2  tsubai 
    188  1.6    onoe 	*(volatile u_int *)NEWS5000_INTEN4 = NEWS5000_INT4_APBUS;
    189  1.6    onoe 	*(volatile u_int *)NEWS5000_APBUS_INTMSK = 0xffff;
    190  1.2  tsubai 
    191  1.6    onoe 	/* INT5 -- currently ignored */
    192  1.2  tsubai 	*(volatile u_int *)NEWS5000_INTEN5 = 0;
    193  1.1  tsubai }
    194  1.1  tsubai 
    195  1.1  tsubai void
    196  1.1  tsubai disable_intr_5000()
    197  1.1  tsubai {
    198  1.2  tsubai 	*(volatile u_int *)NEWS5000_INTEN0 = 0;
    199  1.2  tsubai 	*(volatile u_int *)NEWS5000_INTEN1 = 0;
    200  1.2  tsubai 	*(volatile u_int *)NEWS5000_INTEN2 = 0;
    201  1.2  tsubai 	*(volatile u_int *)NEWS5000_INTEN3 = 0;
    202  1.2  tsubai 	*(volatile u_int *)NEWS5000_INTEN4 = 0;
    203  1.2  tsubai 	*(volatile u_int *)NEWS5000_INTEN5 = 0;
    204  1.1  tsubai }
    205  1.1  tsubai 
    206  1.1  tsubai void
    207  1.6    onoe readmicrotime_5000(tvp)
    208  1.6    onoe 	struct timeval *tvp;
    209  1.6    onoe {
    210  1.6    onoe 	u_int freerun;
    211  1.6    onoe 
    212  1.6    onoe 	*tvp = time;
    213  1.6    onoe 	freerun = *(volatile u_int *)NEWS5000_FREERUN;
    214  1.6    onoe 	freerun -= freerun_off;
    215  1.6    onoe 	if (freerun > 1000000)
    216  1.6    onoe 		freerun = 1000000;
    217  1.6    onoe 	tvp->tv_usec += freerun;
    218  1.6    onoe 	if (tvp->tv_usec >= 1000000) {
    219  1.6    onoe 		tvp->tv_usec -= 1000000;
    220  1.6    onoe 		tvp->tv_sec++;
    221  1.6    onoe 	}
    222  1.6    onoe }
    223  1.6    onoe 
    224  1.6    onoe void
    225  1.1  tsubai readidrom_5000(rom)
    226  1.1  tsubai 	u_char *rom;
    227  1.1  tsubai {
    228  1.1  tsubai 	u_int32_t *p = (void *)NEWS5000_IDROM;
    229  1.1  tsubai 	int i;
    230  1.1  tsubai 
    231  1.1  tsubai 	for (i = 0; i < sizeof (struct idrom); i++, p += 2)
    232  1.1  tsubai 		*rom++ = ((*p & 0x0f) << 4) + (*(p + 1) & 0x0f);
    233  1.1  tsubai }
    234  1.1  tsubai 
    235  1.1  tsubai extern struct idrom idrom;
    236  1.1  tsubai 
    237  1.1  tsubai void
    238  1.1  tsubai news5000_init()
    239  1.1  tsubai {
    240  1.1  tsubai 	enable_intr = enable_intr_5000;
    241  1.1  tsubai 	disable_intr = disable_intr_5000;
    242  1.1  tsubai 
    243  1.1  tsubai 	readidrom_5000((u_char *)&idrom);
    244  1.6    onoe 	readmicrotime = readmicrotime_5000;
    245  1.5  tsubai 	hostid = idrom.id_serial;
    246  1.1  tsubai }
    247