Home | History | Annotate | Line # | Download | only in newsmips
news5000.c revision 1.18
      1  1.18     matt /*	$NetBSD: news5000.c,v 1.18 2011/02/20 07:56:32 matt 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.11    lukem 
     29  1.11    lukem #include <sys/cdefs.h>
     30  1.18     matt __KERNEL_RCSID(0, "$NetBSD: news5000.c,v 1.18 2011/02/20 07:56:32 matt Exp $");
     31   1.1   tsubai 
     32  1.18     matt #define __INTR_PRIVATE
     33   1.1   tsubai #include <sys/param.h>
     34   1.1   tsubai #include <sys/systm.h>
     35   1.1   tsubai #include <sys/kernel.h>
     36  1.16  tsutsui #include <sys/timetc.h>
     37  1.17       ad #include <sys/cpu.h>
     38  1.18     matt #include <sys/intr.h>
     39   1.1   tsubai 
     40   1.1   tsubai #include <machine/adrsmap.h>
     41   1.1   tsubai 
     42   1.1   tsubai #include <newsmips/apbus/apbusvar.h>
     43   1.1   tsubai #include <newsmips/newsmips/machid.h>
     44   1.1   tsubai 
     45   1.9  tsutsui static void news5000_level1_intr(void);
     46   1.9  tsutsui static void news5000_level0_intr(void);
     47   1.7     matt 
     48   1.9  tsutsui static void news5000_enable_intr(void);
     49   1.9  tsutsui static void news5000_disable_intr(void);
     50  1.12  tsutsui static void news5000_enable_timer(void);
     51  1.14  tsutsui static void news5000_readidrom(uint8_t *);
     52  1.16  tsutsui static void news5000_tc_init(void);
     53  1.16  tsutsui static uint32_t news5000_getfreerun(struct timecounter *);
     54   1.6     onoe 
     55   1.1   tsubai /*
     56   1.1   tsubai  * Handle news5000 interrupts.
     57   1.1   tsubai  */
     58   1.4   tsubai void
     59  1.18     matt news5000_intr(int ppl, vaddr_t pc, uint32_t status)
     60   1.1   tsubai {
     61  1.18     matt 	uint32_t ipending;
     62  1.18     matt 	int ipl;
     63  1.17       ad 
     64  1.18     matt 	while (ppl < (ipl = splintr(&ipending))) {
     65  1.17       ad 
     66  1.18     matt 		if (ipending & MIPS_INT_MASK_2) {
     67   1.2   tsubai #ifdef DEBUG
     68  1.18     matt 			static int l2cnt = 0;
     69   1.2   tsubai #endif
     70  1.18     matt 			uint32_t int2stat;
     71  1.18     matt 			struct clockframe cf;
     72   1.2   tsubai 
     73  1.18     matt 			int2stat = *(volatile uint32_t *)NEWS5000_INTST2;
     74   1.2   tsubai 
     75   1.2   tsubai #ifdef DEBUG
     76  1.18     matt 			l2cnt++;
     77  1.18     matt 			if (l2cnt == 50) {
     78  1.18     matt 				*(volatile uint32_t *)NEWS5000_LED_SEC = 1;
     79  1.18     matt 			}
     80  1.18     matt 			if (l2cnt == 100) {
     81  1.18     matt 				*(volatile uint32_t *)NEWS5000_LED_SEC = 0;
     82  1.18     matt 				l2cnt = 0;
     83  1.18     matt 			}
     84   1.2   tsubai #endif
     85   1.2   tsubai 
     86  1.18     matt 			if (int2stat & NEWS5000_INT2_TIMER0) {
     87  1.18     matt 				*(volatile uint32_t *)NEWS5000_TIMER0 = 1;
     88  1.18     matt 
     89  1.18     matt 				cf.pc = pc;
     90  1.18     matt 				cf.sr = status;
     91   1.2   tsubai 
     92  1.18     matt 				hardclock(&cf);
     93  1.18     matt 				intrcnt[HARDCLOCK_INTR]++;
     94  1.18     matt 			}
     95   1.2   tsubai 
     96  1.18     matt 			apbus_wbflush();
     97   1.2   tsubai 		}
     98   1.2   tsubai 
     99  1.18     matt 		if (ipending & MIPS_INT_MASK_5) {
    100  1.18     matt 			uint32_t int5stat;
    101   1.1   tsubai 
    102  1.18     matt 			int5stat = *(volatile u_int *)NEWS5000_INTST5;
    103  1.18     matt 			printf("level5 interrupt (%08x)\n", int5stat);
    104  1.14  tsutsui 
    105  1.18     matt 			apbus_wbflush();
    106  1.18     matt 		}
    107   1.2   tsubai 
    108  1.18     matt 		if (ipending & MIPS_INT_MASK_4) {
    109  1.18     matt 			uint32_t int4stat;
    110   1.1   tsubai 
    111  1.18     matt 			int4stat = *(volatile uint32_t *)NEWS5000_INTST4;
    112  1.18     matt 			printf("level4 interrupt (%08x)\n", int4stat);
    113  1.18     matt 			if (int4stat & NEWS5000_INT4_APBUS) {
    114  1.18     matt 				uint32_t stat;
    115  1.18     matt 
    116  1.18     matt 				stat = *(volatile uint32_t *)NEWS5000_APBUS_INTST;
    117  1.18     matt 				printf("APbus error 0x%04x\n", stat & 0xffff);
    118  1.18     matt 				if (stat & NEWS5000_APBUS_INT_DMAADDR) {
    119  1.18     matt 					printf("DMA Address Error: "
    120  1.18     matt 					    "slot=%x, addr=0x%08x\n",
    121  1.18     matt 					    *(volatile uint32_t *)NEWS5000_APBUS_DER_S,
    122  1.18     matt 					    *(volatile uint32_t *)NEWS5000_APBUS_DER_A);
    123  1.18     matt 				}
    124  1.18     matt 				if (stat & NEWS5000_APBUS_INT_RDTIMEO)
    125  1.18     matt 					printf("IO Read Timeout: addr=0x%08x\n",
    126  1.18     matt 					    *(volatile uint32_t *)NEWS5000_APBUS_BER_A);
    127  1.18     matt 				if (stat & NEWS5000_APBUS_INT_WRTIMEO)
    128  1.18     matt 					printf("IO Write Timeout: addr=0x%08x\n",
    129  1.18     matt 					    *(volatile uint32_t *)NEWS5000_APBUS_BER_A);
    130  1.18     matt 				*(volatile uint32_t *)0xb4c00014 = stat;
    131  1.18     matt 			}
    132  1.14  tsutsui 
    133  1.18     matt 			apbus_wbflush();
    134   1.6     onoe 		}
    135   1.2   tsubai 
    136  1.18     matt 		if (ipending & MIPS_INT_MASK_3) {
    137  1.18     matt 			uint32_t int3stat;
    138   1.1   tsubai 
    139  1.18     matt 			int3stat = *(volatile uint32_t *)NEWS5000_INTST3;
    140  1.18     matt 			printf("level3 interrupt (%08x)\n", int3stat);
    141  1.14  tsutsui 
    142  1.18     matt 			apbus_wbflush();
    143  1.18     matt 		}
    144   1.2   tsubai 
    145  1.18     matt 		if (ipending & MIPS_INT_MASK_1) {
    146  1.18     matt 			news5000_level1_intr();
    147  1.18     matt 			apbus_wbflush();
    148  1.18     matt 		}
    149   1.1   tsubai 
    150  1.18     matt 		if (ipending & MIPS_INT_MASK_0) {
    151  1.18     matt 			news5000_level0_intr();
    152  1.18     matt 			apbus_wbflush();
    153  1.18     matt 		}
    154   1.1   tsubai 	}
    155   1.1   tsubai }
    156   1.1   tsubai 
    157   1.1   tsubai 
    158   1.7     matt static void
    159   1.9  tsutsui news5000_level1_intr(void)
    160   1.1   tsubai {
    161  1.14  tsutsui 	uint32_t int1stat;
    162   1.1   tsubai 
    163  1.14  tsutsui 	int1stat = *(volatile uint32_t *)NEWS5000_INTST1;
    164   1.1   tsubai 
    165   1.1   tsubai 	if (int1stat) {
    166  1.10  tsutsui 		if (apbus_intr_dispatch(1, int1stat) == 0)
    167   1.3   tsubai 			printf("level1_intr: no handler (mask 0x%04x)\n",
    168   1.2   tsubai 			       int1stat);
    169   1.2   tsubai 	} else
    170   1.1   tsubai 		printf("level1 stray interrupt?\n");
    171   1.1   tsubai }
    172   1.1   tsubai 
    173   1.7     matt static void
    174   1.9  tsutsui news5000_level0_intr(void)
    175   1.1   tsubai {
    176  1.14  tsutsui 	uint32_t int0stat;
    177   1.1   tsubai 
    178  1.14  tsutsui 	int0stat = *(volatile uint32_t *)NEWS5000_INTST0;
    179   1.1   tsubai 
    180   1.1   tsubai 	if (int0stat) {
    181  1.10  tsutsui 		if (apbus_intr_dispatch(0, int0stat) == 0)
    182   1.2   tsubai 			printf("level0_intr: no handler (mask 0x%04x)\n",
    183   1.2   tsubai 			       int0stat);
    184   1.2   tsubai 	} else
    185   1.1   tsubai 		printf("level0 stray interrupt?\n");
    186   1.1   tsubai }
    187   1.1   tsubai 
    188   1.7     matt static void
    189   1.9  tsutsui news5000_enable_intr(void)
    190   1.1   tsubai {
    191   1.2   tsubai 
    192   1.6     onoe 	/* INT0 and INT1 has been enabled at attach */
    193   1.6     onoe 	/* INT2 -- It's not a time to enable timer yet. */
    194   1.6     onoe 	/* INT3 -- not used for NWS-5000 */
    195   1.2   tsubai 
    196  1.14  tsutsui 	*(volatile uint32_t *)NEWS5000_INTEN4 = NEWS5000_INT4_APBUS;
    197  1.14  tsutsui 	*(volatile uint32_t *)NEWS5000_APBUS_INTMSK = 0xffff;
    198   1.2   tsubai 
    199   1.6     onoe 	/* INT5 -- currently ignored */
    200  1.14  tsutsui 	*(volatile uint32_t *)NEWS5000_INTEN5 = 0;
    201   1.1   tsubai }
    202   1.1   tsubai 
    203   1.7     matt static void
    204   1.9  tsutsui news5000_disable_intr(void)
    205   1.1   tsubai {
    206   1.9  tsutsui 
    207  1.14  tsutsui 	*(volatile uint32_t *)NEWS5000_INTEN0 = 0;
    208  1.14  tsutsui 	*(volatile uint32_t *)NEWS5000_INTEN1 = 0;
    209  1.14  tsutsui 	*(volatile uint32_t *)NEWS5000_INTEN2 = 0;
    210  1.14  tsutsui 	*(volatile uint32_t *)NEWS5000_INTEN3 = 0;
    211  1.14  tsutsui 	*(volatile uint32_t *)NEWS5000_INTEN4 = 0;
    212  1.14  tsutsui 	*(volatile uint32_t *)NEWS5000_INTEN5 = 0;
    213   1.1   tsubai }
    214   1.1   tsubai 
    215   1.7     matt static void
    216  1.12  tsutsui news5000_enable_timer(void)
    217  1.12  tsutsui {
    218  1.12  tsutsui 
    219  1.16  tsutsui 	news5000_tc_init();
    220  1.16  tsutsui 
    221  1.12  tsutsui 	/* enable timer interrpt */
    222  1.13  tsutsui 	*(volatile uint32_t *)NEWS5000_INTEN2 = NEWS5000_INT2_TIMER0;
    223  1.12  tsutsui }
    224  1.12  tsutsui 
    225  1.16  tsutsui static uint32_t
    226  1.16  tsutsui news5000_getfreerun(struct timecounter *tc)
    227  1.16  tsutsui {
    228  1.16  tsutsui 	return *(volatile uint32_t *)NEWS5000_FREERUN;
    229  1.16  tsutsui }
    230  1.16  tsutsui 
    231  1.12  tsutsui static void
    232  1.16  tsutsui news5000_tc_init(void)
    233   1.6     onoe {
    234  1.16  tsutsui 	static struct timecounter tc = {
    235  1.16  tsutsui 		.tc_get_timecount = news5000_getfreerun,
    236  1.16  tsutsui 		.tc_frequency = 1000000,
    237  1.16  tsutsui 		.tc_counter_mask = ~0,
    238  1.16  tsutsui 		.tc_name = "news5000_freerun",
    239  1.16  tsutsui 		.tc_quality = 100,
    240  1.16  tsutsui 	};
    241   1.6     onoe 
    242  1.16  tsutsui 	tc_init(&tc);
    243   1.6     onoe }
    244  1.16  tsutsui 
    245   1.6     onoe 
    246   1.7     matt static void
    247  1.14  tsutsui news5000_readidrom(uint8_t *rom)
    248   1.1   tsubai {
    249  1.13  tsutsui 	uint32_t *p = (void *)NEWS5000_IDROM;
    250   1.1   tsubai 	int i;
    251   1.1   tsubai 
    252  1.14  tsutsui 	for (i = 0; i < sizeof(struct idrom); i++, p += 2)
    253   1.1   tsubai 		*rom++ = ((*p & 0x0f) << 4) + (*(p + 1) & 0x0f);
    254   1.1   tsubai }
    255   1.1   tsubai 
    256   1.1   tsubai extern struct idrom idrom;
    257   1.1   tsubai 
    258   1.1   tsubai void
    259   1.7     matt news5000_init(void)
    260   1.1   tsubai {
    261   1.1   tsubai 
    262   1.9  tsutsui 	enable_intr = news5000_enable_intr;
    263   1.9  tsutsui 	disable_intr = news5000_disable_intr;
    264  1.12  tsutsui 	enable_timer = news5000_enable_timer;
    265   1.9  tsutsui 
    266  1.14  tsutsui 	news5000_readidrom((uint8_t *)&idrom);
    267   1.5   tsubai 	hostid = idrom.id_serial;
    268   1.8  tsutsui 
    269   1.8  tsutsui 	/* XXX reset uPD72067 FDC to avoid spurious interrupts */
    270   1.8  tsutsui #define NEWS5000_FDC_FDOUT 0xbed20000
    271   1.8  tsutsui #define FDO_FRST 0x04
    272  1.13  tsutsui 	*(volatile uint8_t *)NEWS5000_FDC_FDOUT = FDO_FRST;
    273   1.1   tsubai }
    274