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