Home | History | Annotate | Line # | Download | only in newsmips
news5000.c revision 1.2
      1  1.2  tsubai /*	$NetBSD: news5000.c,v 1.2 1999/12/23 06:52:31 tsubai 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.2  tsubai static void level1_intr __P((void));
     41  1.2  tsubai static void level0_intr __P((void));
     42  1.1  tsubai 
     43  1.1  tsubai /*
     44  1.1  tsubai  * Handle news5000 interrupts.
     45  1.1  tsubai  */
     46  1.1  tsubai int
     47  1.2  tsubai news5000_intr(mask, pc, status, cause)
     48  1.1  tsubai 	u_int mask;
     49  1.2  tsubai 	u_int pc;	/* program counter where to continue */
     50  1.2  tsubai 	u_int status;	/* status register at time of the exception */
     51  1.2  tsubai 	u_int cause;	/* cause register at time of exception */
     52  1.1  tsubai {
     53  1.1  tsubai 	if (mask & MIPS_INT_MASK_2) {
     54  1.2  tsubai #ifdef DEBUG
     55  1.2  tsubai 		static int l2cnt = 0;
     56  1.2  tsubai #endif
     57  1.2  tsubai 		u_int int2stat;
     58  1.2  tsubai 		struct clockframe cf;
     59  1.2  tsubai 
     60  1.2  tsubai 		int2stat = *(volatile u_int *)NEWS5000_INTST2;
     61  1.2  tsubai 
     62  1.2  tsubai #ifdef DEBUG
     63  1.2  tsubai 		l2cnt++;
     64  1.2  tsubai 		if (l2cnt == 50) {
     65  1.2  tsubai 			*(volatile u_int *)NEWS5000_LED_SEC = 1;
     66  1.2  tsubai 		}
     67  1.2  tsubai 		if (l2cnt == 100) {
     68  1.2  tsubai 			*(volatile u_int *)NEWS5000_LED_SEC = 0;
     69  1.2  tsubai 			l2cnt = 0;
     70  1.2  tsubai 		}
     71  1.2  tsubai #endif
     72  1.2  tsubai 
     73  1.2  tsubai 		if (int2stat & NEWS5000_INT2_TIMER0) {
     74  1.2  tsubai 			*(volatile u_int *)NEWS5000_TIMER0 = 1;
     75  1.2  tsubai 
     76  1.2  tsubai 			cf.pc = pc;
     77  1.2  tsubai 			cf.sr = status;
     78  1.2  tsubai 
     79  1.2  tsubai 			hardclock(&cf);
     80  1.2  tsubai 			intrcnt[HARDCLOCK_INTR]++;
     81  1.2  tsubai 		}
     82  1.2  tsubai 
     83  1.1  tsubai 		apbus_wbflush();
     84  1.2  tsubai 		cause &= ~MIPS_INT_MASK_2;
     85  1.1  tsubai 	}
     86  1.1  tsubai 	/* If clock interrupts were enabled, re-enable them ASAP. */
     87  1.2  tsubai 	splx(MIPS_SR_INT_IE | (status & MIPS_INT_MASK_2));
     88  1.1  tsubai 
     89  1.1  tsubai 	if (mask & MIPS_INT_MASK_5) {
     90  1.2  tsubai 		u_int int5stat = *(volatile u_int *)NEWS5000_INTST5;
     91  1.2  tsubai 		printf("level5 interrupt (%08x)\n", int5stat);
     92  1.2  tsubai 
     93  1.1  tsubai 		apbus_wbflush();
     94  1.2  tsubai 		cause &= ~MIPS_INT_MASK_5;
     95  1.1  tsubai 	}
     96  1.1  tsubai 
     97  1.1  tsubai 	if (mask & MIPS_INT_MASK_4) {
     98  1.2  tsubai 		u_int int4stat = *(volatile u_int *)NEWS5000_INTST4;
     99  1.2  tsubai 		printf("level4 interrupt (%08x)\n", int4stat);
    100  1.2  tsubai 
    101  1.1  tsubai 		apbus_wbflush();
    102  1.2  tsubai 		cause &= ~MIPS_INT_MASK_4;
    103  1.1  tsubai 	}
    104  1.1  tsubai 
    105  1.1  tsubai 	if (mask & MIPS_INT_MASK_3) {
    106  1.2  tsubai 		u_int int3stat = *(volatile u_int *)NEWS5000_INTST3;
    107  1.2  tsubai 		printf("level3 interrupt (%08x)\n", int3stat);
    108  1.2  tsubai 
    109  1.1  tsubai 		apbus_wbflush();
    110  1.2  tsubai 		cause &= ~MIPS_INT_MASK_3;
    111  1.1  tsubai 	}
    112  1.1  tsubai 
    113  1.1  tsubai 	if (mask & MIPS_INT_MASK_1) {
    114  1.2  tsubai 		level1_intr();
    115  1.1  tsubai 		apbus_wbflush();
    116  1.2  tsubai 		cause &= ~MIPS_INT_MASK_1;
    117  1.1  tsubai 	}
    118  1.1  tsubai 
    119  1.1  tsubai 	if (mask & MIPS_INT_MASK_0) {
    120  1.2  tsubai 		level0_intr();
    121  1.1  tsubai 		apbus_wbflush();
    122  1.2  tsubai 		cause &= ~MIPS_INT_MASK_0;
    123  1.1  tsubai 	}
    124  1.1  tsubai 
    125  1.2  tsubai 	return (status & ~cause & MIPS_HARD_INT_MASK) | MIPS_SR_INT_IE;
    126  1.1  tsubai }
    127  1.1  tsubai 
    128  1.1  tsubai 
    129  1.1  tsubai void
    130  1.2  tsubai level1_intr()
    131  1.1  tsubai {
    132  1.2  tsubai 	u_int int1stat;
    133  1.1  tsubai 
    134  1.2  tsubai 	int1stat = *(volatile u_int *)NEWS5000_INTST1;
    135  1.1  tsubai 
    136  1.1  tsubai 	if (int1stat) {
    137  1.2  tsubai 		if (apbus_intr_call(1, int1stat) == 0)
    138  1.2  tsubai 			printf("level1_intr: no andler (mask 0x%04x)\n",
    139  1.2  tsubai 			       int1stat);
    140  1.2  tsubai 	} else
    141  1.1  tsubai 		printf("level1 stray interrupt?\n");
    142  1.1  tsubai }
    143  1.1  tsubai 
    144  1.1  tsubai void
    145  1.2  tsubai level0_intr()
    146  1.1  tsubai {
    147  1.2  tsubai 	u_int int0stat;
    148  1.1  tsubai 
    149  1.2  tsubai 	int0stat = *(volatile u_int *)NEWS5000_INTST0;
    150  1.1  tsubai 
    151  1.1  tsubai 	if (int0stat) {
    152  1.2  tsubai 		if (apbus_intr_call(0, int0stat) == 0)
    153  1.2  tsubai 			printf("level0_intr: no handler (mask 0x%04x)\n",
    154  1.2  tsubai 			       int0stat);
    155  1.2  tsubai 	} else
    156  1.1  tsubai 		printf("level0 stray interrupt?\n");
    157  1.1  tsubai }
    158  1.1  tsubai 
    159  1.1  tsubai void
    160  1.1  tsubai enable_intr_5000()
    161  1.1  tsubai {
    162  1.2  tsubai 	volatile u_int *inten0 = (void *)NEWS5000_INTEN0;
    163  1.2  tsubai 	volatile u_int *inten1 = (void *)NEWS5000_INTEN1;
    164  1.2  tsubai 
    165  1.2  tsubai 	*inten0 = NEWS5000_INT0_DMAC | NEWS5000_INT0_SONIC |
    166  1.2  tsubai 		  NEWS5000_INT0_FDC;
    167  1.2  tsubai 	*inten1 = NEWS5000_INT1_KBD | NEWS5000_INT1_SCC |
    168  1.2  tsubai 		  NEWS5000_INT1_AUDIO0 | NEWS5000_INT1_AUDIO1 |
    169  1.2  tsubai 		  NEWS5000_INT1_PARALLEL | NEWS5000_INT1_FB;
    170  1.2  tsubai 
    171  1.2  tsubai 	/* It's not a time to enable timer yet. */
    172  1.2  tsubai 	/* *(volatile u_int *)NEWS5000_INTEN2 = 0; */
    173  1.2  tsubai 
    174  1.2  tsubai 	/* currently INT3-INT5 are not used */
    175  1.2  tsubai 	*(volatile u_int *)NEWS5000_INTEN3 = 0;
    176  1.2  tsubai 	*(volatile u_int *)NEWS5000_INTEN4 = 0;
    177  1.2  tsubai 	*(volatile u_int *)NEWS5000_INTEN5 = 0;
    178  1.1  tsubai }
    179  1.1  tsubai 
    180  1.1  tsubai void
    181  1.1  tsubai disable_intr_5000()
    182  1.1  tsubai {
    183  1.2  tsubai 	*(volatile u_int *)NEWS5000_INTEN0 = 0;
    184  1.2  tsubai 	*(volatile u_int *)NEWS5000_INTEN1 = 0;
    185  1.2  tsubai 	*(volatile u_int *)NEWS5000_INTEN2 = 0;
    186  1.2  tsubai 	*(volatile u_int *)NEWS5000_INTEN3 = 0;
    187  1.2  tsubai 	*(volatile u_int *)NEWS5000_INTEN4 = 0;
    188  1.2  tsubai 	*(volatile u_int *)NEWS5000_INTEN5 = 0;
    189  1.1  tsubai }
    190  1.1  tsubai 
    191  1.1  tsubai void
    192  1.1  tsubai readidrom_5000(rom)
    193  1.1  tsubai 	u_char *rom;
    194  1.1  tsubai {
    195  1.1  tsubai 	u_int32_t *p = (void *)NEWS5000_IDROM;
    196  1.1  tsubai 	int i;
    197  1.1  tsubai 
    198  1.1  tsubai 	for (i = 0; i < sizeof (struct idrom); i++, p += 2)
    199  1.1  tsubai 		*rom++ = ((*p & 0x0f) << 4) + (*(p + 1) & 0x0f);
    200  1.1  tsubai }
    201  1.1  tsubai 
    202  1.1  tsubai extern struct idrom idrom;
    203  1.1  tsubai 
    204  1.1  tsubai void
    205  1.1  tsubai news5000_init()
    206  1.1  tsubai {
    207  1.1  tsubai 	enable_intr = enable_intr_5000;
    208  1.1  tsubai 	disable_intr = disable_intr_5000;
    209  1.1  tsubai 
    210  1.1  tsubai 	readidrom_5000((u_char *)&idrom);
    211  1.1  tsubai }
    212