Home | History | Annotate | Line # | Download | only in vr
vr.c revision 1.37
      1  1.37  takemura /*	$NetBSD: vr.c,v 1.37 2002/02/10 14:38:57 takemura Exp $	*/
      2   1.1  takemura 
      3   1.1  takemura /*-
      4  1.35  takemura  * Copyright (c) 1999-2002
      5   1.1  takemura  *         Shin Takemura and PocketBSD Project. All rights reserved.
      6   1.1  takemura  *
      7   1.1  takemura  * Redistribution and use in source and binary forms, with or without
      8   1.1  takemura  * modification, are permitted provided that the following conditions
      9   1.1  takemura  * are met:
     10   1.1  takemura  * 1. Redistributions of source code must retain the above copyright
     11   1.1  takemura  *    notice, this list of conditions and the following disclaimer.
     12   1.1  takemura  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1  takemura  *    notice, this list of conditions and the following disclaimer in the
     14   1.1  takemura  *    documentation and/or other materials provided with the distribution.
     15   1.1  takemura  * 3. All advertising materials mentioning features or use of this software
     16   1.1  takemura  *    must display the following acknowledgement:
     17   1.1  takemura  *	This product includes software developed by the PocketBSD project
     18   1.1  takemura  *	and its contributors.
     19   1.1  takemura  * 4. Neither the name of the project nor the names of its contributors
     20   1.1  takemura  *    may be used to endorse or promote products derived from this software
     21   1.1  takemura  *    without specific prior written permission.
     22   1.1  takemura  *
     23   1.1  takemura  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24   1.1  takemura  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25   1.1  takemura  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26   1.1  takemura  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27   1.1  takemura  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28   1.1  takemura  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29   1.1  takemura  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30   1.1  takemura  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31   1.1  takemura  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32   1.1  takemura  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33   1.1  takemura  * SUCH DAMAGE.
     34   1.1  takemura  *
     35   1.1  takemura  */
     36  1.29       uch 
     37  1.29       uch #include "opt_vr41xx.h"
     38  1.31       uch #include "opt_tx39xx.h"
     39  1.24     lukem #include "opt_kgdb.h"
     40  1.24     lukem 
     41   1.1  takemura #include <sys/param.h>
     42   1.1  takemura #include <sys/systm.h>
     43   1.5  takemura #include <sys/reboot.h>
     44   1.1  takemura 
     45  1.31       uch #include <uvm/uvm_extern.h>
     46  1.31       uch 
     47   1.1  takemura #include <machine/sysconf.h>
     48  1.32  takemura #include <machine/bootinfo.h>
     49   1.1  takemura #include <machine/bus.h>
     50  1.32  takemura #include <machine/bus_space_hpcmips.h>
     51  1.35  takemura #include <machine/platid.h>
     52  1.35  takemura #include <machine/platid_mask.h>
     53   1.1  takemura 
     54  1.26     enami #include <dev/hpc/hpckbdvar.h>
     55  1.30       uch 
     56   1.1  takemura #include <hpcmips/vr/vr.h>
     57  1.11  takemura #include <hpcmips/vr/vr_asm.h>
     58  1.22      sato #include <hpcmips/vr/vrcpudef.h>
     59   1.3  takemura #include <hpcmips/vr/vripreg.h>
     60   1.1  takemura #include <hpcmips/vr/rtcreg.h>
     61   1.1  takemura 
     62   1.8  takemura #include "vrip.h"
     63   1.8  takemura #if NVRIP > 0
     64   1.8  takemura #include <hpcmips/vr/vripvar.h>
     65   1.8  takemura #endif
     66   1.8  takemura 
     67   1.9      sato #include "vrbcu.h"
     68   1.9      sato #if NVRBCU > 0
     69   1.9      sato #include <hpcmips/vr/bcuvar.h>
     70   1.9      sato #endif
     71   1.9      sato 
     72   1.5  takemura #include "vrdsu.h"
     73   1.5  takemura #if NVRDSU > 0
     74   1.5  takemura #include <hpcmips/vr/vrdsuvar.h>
     75   1.5  takemura #endif
     76   1.5  takemura 
     77   1.1  takemura #include "com.h"
     78  1.35  takemura #include "com_vrip.h"
     79  1.35  takemura #include "com_hpcio.h"
     80  1.35  takemura #if NCOM > 0
     81   1.1  takemura #include <sys/termios.h>
     82   1.1  takemura #include <sys/ttydefaults.h>
     83   1.1  takemura #include <dev/ic/comreg.h>
     84   1.1  takemura #include <dev/ic/comvar.h>
     85  1.35  takemura #if NCOM_VRIP > 0
     86   1.1  takemura #include <hpcmips/vr/siureg.h>
     87   1.1  takemura #include <hpcmips/vr/com_vripvar.h>
     88  1.33  takemura #endif
     89  1.35  takemura #if NCOM_HPCIO > 0
     90  1.35  takemura #include <hpcmips/dev/com_hpciovar.h>
     91  1.33  takemura #endif
     92   1.1  takemura #ifndef CONSPEED
     93   1.1  takemura #define CONSPEED TTYDEF_SPEED
     94   1.1  takemura #endif
     95   1.1  takemura #endif
     96   1.1  takemura 
     97  1.15  takemura #include "hpcfb.h"
     98   1.3  takemura #include "vrkiu.h"
     99  1.25     enami #if (NVRKIU > 0) || (NHPCFB > 0)
    100   1.3  takemura #include <dev/wscons/wsdisplayvar.h>
    101  1.15  takemura #include <dev/rasops/rasops.h>
    102   1.3  takemura #endif
    103   1.3  takemura 
    104  1.15  takemura #if NHPCFB > 0
    105  1.20       uch #include <dev/hpc/hpcfbvar.h>
    106   1.3  takemura #endif
    107   1.3  takemura 
    108  1.15  takemura #if NVRKIU > 0
    109  1.26     enami #include <arch/hpcmips/vr/vrkiureg.h>
    110   1.3  takemura #include <arch/hpcmips/vr/vrkiuvar.h>
    111   1.3  takemura #endif
    112   1.3  takemura 
    113  1.31       uch #ifdef DEBUG
    114  1.31       uch #define STATIC
    115  1.31       uch #else
    116  1.31       uch #define STATIC	static
    117  1.31       uch #endif
    118  1.31       uch 
    119  1.31       uch /*
    120  1.31       uch  * This is a mask of bits to clear in the SR when we go to a
    121  1.31       uch  * given interrupt priority level.
    122  1.31       uch  */
    123  1.31       uch const u_int32_t __ipl_sr_bits_vr[_IPL_N] = {
    124  1.31       uch 	0,					/* IPL_NONE */
    125  1.31       uch 
    126  1.31       uch 	MIPS_SOFT_INT_MASK_0,			/* IPL_SOFT */
    127  1.31       uch 
    128  1.31       uch 	MIPS_SOFT_INT_MASK_0,			/* IPL_SOFTCLOCK */
    129  1.31       uch 
    130  1.31       uch 	MIPS_SOFT_INT_MASK_0|
    131  1.31       uch 		MIPS_SOFT_INT_MASK_1,		/* IPL_SOFTNET */
    132  1.31       uch 
    133  1.31       uch 	MIPS_SOFT_INT_MASK_0|
    134  1.31       uch 		MIPS_SOFT_INT_MASK_1,		/* IPL_SOFTSERIAL */
    135  1.31       uch 
    136  1.31       uch 	MIPS_SOFT_INT_MASK_0|
    137  1.31       uch 		MIPS_SOFT_INT_MASK_1|
    138  1.31       uch 		MIPS_INT_MASK_0,		/* IPL_BIO */
    139  1.31       uch 
    140  1.31       uch 	MIPS_SOFT_INT_MASK_0|
    141  1.31       uch 		MIPS_SOFT_INT_MASK_1|
    142  1.31       uch 		MIPS_INT_MASK_0,		/* IPL_NET */
    143  1.31       uch 
    144  1.31       uch 	MIPS_SOFT_INT_MASK_0|
    145  1.31       uch 		MIPS_SOFT_INT_MASK_1|
    146  1.31       uch 		MIPS_INT_MASK_0,		/* IPL_{TTY,SERIAL} */
    147  1.31       uch 
    148  1.31       uch 	MIPS_SOFT_INT_MASK_0|
    149  1.31       uch 		MIPS_SOFT_INT_MASK_1|
    150  1.31       uch 		MIPS_INT_MASK_0|
    151  1.31       uch 		MIPS_INT_MASK_1,		/* IPL_{CLOCK,HIGH} */
    152  1.31       uch };
    153  1.31       uch 
    154  1.31       uch #if defined(VR41XX) && defined(TX39XX)
    155  1.31       uch #define	VR_INTR	vr_intr
    156  1.31       uch #else
    157  1.31       uch #define	VR_INTR	cpu_intr	/* locore_mips3 directly call this */
    158  1.31       uch #endif
    159  1.31       uch 
    160  1.31       uch void vr_init(void);
    161  1.31       uch void VR_INTR(u_int32_t, u_int32_t, u_int32_t, u_int32_t);
    162  1.31       uch extern void vr_idle(void);
    163  1.31       uch STATIC void vr_cons_init(void);
    164  1.31       uch STATIC void vr_fb_init(caddr_t *);
    165  1.31       uch STATIC void vr_mem_init(paddr_t);
    166  1.31       uch STATIC void vr_find_dram(paddr_t, paddr_t);
    167  1.31       uch STATIC void vr_reboot(int, char *);
    168   1.1  takemura 
    169   1.1  takemura /*
    170   1.1  takemura  * CPU interrupt dispatch table (HwInt[0:3])
    171   1.1  takemura  */
    172  1.31       uch STATIC int vr_null_handler(void *, u_int32_t, u_int32_t);
    173  1.31       uch STATIC int (*vr_intr_handler[4])(void *, u_int32_t, u_int32_t) =
    174   1.1  takemura {
    175  1.31       uch 	vr_null_handler,
    176  1.31       uch 	vr_null_handler,
    177  1.31       uch 	vr_null_handler,
    178  1.31       uch 	vr_null_handler
    179   1.1  takemura };
    180  1.31       uch STATIC void *vr_intr_arg[4];
    181   1.1  takemura 
    182  1.35  takemura #if NCOM > 0
    183  1.35  takemura /*
    184  1.35  takemura  * machine dependent serial console info
    185  1.35  takemura  */
    186  1.35  takemura static struct vr_com_platdep {
    187  1.35  takemura 	platid_mask_t *platidmask;
    188  1.35  takemura 	int (*attach)(bus_space_tag_t, int, int, int, tcflag_t, int);
    189  1.35  takemura 	int addr;
    190  1.35  takemura 	int freq;
    191  1.35  takemura } platdep_com_table[] = {
    192  1.35  takemura #if NCOM_HPCIO > 0
    193  1.35  takemura 	{
    194  1.35  takemura 		&platid_mask_MACH_NEC_MCR_SIGMARION2,
    195  1.35  takemura 		com_hpcio_cndb_attach,	/* attach proc */
    196  1.35  takemura 		0x0b600000,		/* base address */
    197  1.35  takemura 		COM_FREQ,		/* frequency */
    198  1.35  takemura 	},
    199  1.35  takemura #endif
    200  1.35  takemura #if NCOM_VRIP > 0
    201  1.37  takemura #ifdef VR4102
    202  1.37  takemura 	{
    203  1.37  takemura 		&platid_mask_CPU_MIPS_VR_4102,
    204  1.37  takemura 		com_vrip_cndb_attach,	/* attach proc */
    205  1.37  takemura 		VR4102_SIU_ADDR,	/* base address */
    206  1.37  takemura 		VRCOM_FREQ,		/* frequency */
    207  1.37  takemura 	},
    208  1.37  takemura #endif /* VR4102 */
    209  1.37  takemura #ifdef VR4111
    210  1.37  takemura 	{
    211  1.37  takemura 		&platid_mask_CPU_MIPS_VR_4111,
    212  1.37  takemura 		com_vrip_cndb_attach,	/* attach proc */
    213  1.37  takemura 		VR4102_SIU_ADDR,	/* base address */
    214  1.37  takemura 		VRCOM_FREQ,		/* frequency */
    215  1.37  takemura 	},
    216  1.37  takemura #endif /* VR4111 */
    217  1.37  takemura #ifdef VR4121
    218  1.37  takemura 	{
    219  1.37  takemura 		&platid_mask_CPU_MIPS_VR_4121,
    220  1.37  takemura 		com_vrip_cndb_attach,	/* attach proc */
    221  1.37  takemura 		VR4102_SIU_ADDR,	/* base address */
    222  1.37  takemura 		VRCOM_FREQ,		/* frequency */
    223  1.37  takemura 	},
    224  1.37  takemura #endif /* VR4121 */
    225  1.37  takemura #ifdef VR4122
    226  1.37  takemura 	{
    227  1.37  takemura 		&platid_mask_CPU_MIPS_VR_4122,
    228  1.37  takemura 		com_vrip_cndb_attach,	/* attach proc */
    229  1.37  takemura 		VR4122_SIU_ADDR,	/* base address */
    230  1.37  takemura 		VRCOM_FREQ,		/* frequency */
    231  1.37  takemura 	},
    232  1.37  takemura #endif /* VR4122 */
    233  1.37  takemura #ifdef VR4131
    234  1.37  takemura 	{
    235  1.37  takemura 		&platid_mask_CPU_MIPS_VR_4122,
    236  1.37  takemura 		com_vrip_cndb_attach,	/* attach proc */
    237  1.37  takemura 		VR4122_SIU_ADDR,	/* base address */
    238  1.37  takemura 		VRCOM_FREQ,		/* frequency */
    239  1.37  takemura 	},
    240  1.37  takemura #endif /* VR4131 */
    241  1.37  takemura #ifdef SINGLE_VRIP_BASE
    242  1.35  takemura 	{
    243  1.35  takemura 		&platid_wild,
    244  1.35  takemura 		com_vrip_cndb_attach,	/* attach proc */
    245  1.35  takemura 		VRIP_SIU_ADDR,		/* base address */
    246  1.35  takemura 		VRCOM_FREQ,		/* frequency */
    247  1.35  takemura 	},
    248  1.37  takemura #endif /* SINGLE_VRIP_BASE */
    249  1.37  takemura #else /* NCOM_VRIP > 0 */
    250  1.35  takemura 	/* dummy */
    251  1.35  takemura 	{
    252  1.35  takemura 		&platid_wild,
    253  1.35  takemura 		NULL,			/* attach proc */
    254  1.35  takemura 		0,			/* base address */
    255  1.35  takemura 		0,			/* frequency */
    256  1.35  takemura 	},
    257  1.37  takemura #endif /* NCOM_VRIP > 0 */
    258  1.35  takemura };
    259  1.35  takemura #endif /* NCOM > 0 */
    260  1.35  takemura 
    261   1.1  takemura void
    262   1.1  takemura vr_init()
    263   1.1  takemura {
    264   1.1  takemura 	/*
    265   1.1  takemura 	 * Platform Specific Function Hooks
    266   1.1  takemura 	 */
    267  1.29       uch 	platform.cpu_idle	= vr_idle;
    268  1.31       uch 	platform.cpu_intr	= VR_INTR;
    269  1.29       uch 	platform.cons_init	= vr_cons_init;
    270  1.29       uch 	platform.fb_init	= vr_fb_init;
    271  1.29       uch 	platform.mem_init	= vr_mem_init;
    272  1.29       uch 	platform.reboot		= vr_reboot;
    273   1.1  takemura 
    274   1.9      sato #if NVRBCU > 0
    275  1.12      sato 	sprintf(cpu_name, "NEC %s rev%d.%d %d.%03dMHz",
    276   1.1  takemura 		vrbcu_vrip_getcpuname(),
    277   1.1  takemura 		vrbcu_vrip_getcpumajor(),
    278  1.10      shin 		vrbcu_vrip_getcpuminor(),
    279  1.10      shin 		vrbcu_vrip_getcpuclock() / 1000000,
    280  1.10      shin 		(vrbcu_vrip_getcpuclock() % 1000000) / 1000);
    281   1.9      sato #else
    282  1.12      sato 	sprintf(cpu_name, "NEC VR41xx");
    283   1.9      sato #endif
    284   1.4       uch }
    285   1.4       uch 
    286  1.13      shin void
    287  1.28       uch vr_mem_init(paddr_t kernend)
    288   1.4       uch {
    289  1.25     enami 
    290  1.13      shin 	mem_clusters[0].start = 0;
    291  1.13      shin 	mem_clusters[0].size = kernend;
    292  1.13      shin 	mem_cluster_cnt = 1;
    293  1.25     enami 
    294  1.13      shin 	vr_find_dram(kernend, 0x02000000);
    295  1.13      shin 	vr_find_dram(0x02000000, 0x04000000);
    296  1.13      shin 	vr_find_dram(0x04000000, 0x06000000);
    297  1.13      shin 	vr_find_dram(0x06000000, 0x08000000);
    298  1.13      shin }
    299  1.13      shin 
    300  1.13      shin void
    301  1.28       uch vr_find_dram(paddr_t addr, paddr_t end)
    302  1.13      shin {
    303  1.13      shin 	int n;
    304  1.13      shin 	caddr_t page;
    305  1.13      shin #ifdef NARLY_MEMORY_PROBE
    306  1.13      shin 	int x, i;
    307  1.13      shin #endif
    308  1.13      shin 
    309  1.25     enami #ifdef VR_FIND_DRAMLIM
    310  1.25     enami 	if (VR_FIND_DRAMLIM < end)
    311  1.25     enami 		end = VR_FIND_DRAMLIM;
    312  1.31       uch #endif /* VR_FIND_DRAMLIM */
    313  1.13      shin 	n = mem_cluster_cnt;
    314  1.13      shin 	for (; addr < end; addr += NBPG) {
    315  1.13      shin 
    316  1.13      shin 		page = (void *)MIPS_PHYS_TO_KSEG1(addr);
    317  1.13      shin 		if (badaddr(page, 4))
    318  1.13      shin 			goto bad;
    319  1.14      shin 
    320  1.14      shin 		/* stop memory probing at first memory image */
    321  1.14      shin 		if (bcmp(page, (void *)MIPS_PHYS_TO_KSEG0(0), 128) == 0)
    322  1.14      shin 			return;
    323  1.13      shin 
    324  1.13      shin 		*(volatile int *)(page+0) = 0xa5a5a5a5;
    325  1.13      shin 		*(volatile int *)(page+4) = 0x5a5a5a5a;
    326  1.13      shin 		wbflush();
    327  1.13      shin 		if (*(volatile int *)(page+0) != 0xa5a5a5a5)
    328  1.13      shin 			goto bad;
    329  1.13      shin 
    330  1.13      shin 		*(volatile int *)(page+0) = 0x5a5a5a5a;
    331  1.13      shin 		*(volatile int *)(page+4) = 0xa5a5a5a5;
    332  1.13      shin 		wbflush();
    333  1.13      shin 		if (*(volatile int *)(page+0) != 0x5a5a5a5a)
    334  1.13      shin 			goto bad;
    335  1.13      shin 
    336  1.13      shin #ifdef NARLY_MEMORY_PROBE
    337  1.13      shin 		x = random();
    338  1.13      shin 		for (i = 0; i < NBPG; i += 4)
    339  1.13      shin 			*(volatile int *)(page+i) = (x ^ i);
    340   1.4       uch 		wbflush();
    341  1.13      shin 		for (i = 0; i < NBPG; i += 4)
    342  1.13      shin 			if (*(volatile int *)(page+i) != (x ^ i))
    343  1.13      shin 				goto bad;
    344  1.13      shin 
    345  1.13      shin 		x = random();
    346  1.13      shin 		for (i = 0; i < NBPG; i += 4)
    347  1.13      shin 			*(volatile int *)(page+i) = (x ^ i);
    348  1.13      shin 		wbflush();
    349  1.13      shin 		for (i = 0; i < NBPG; i += 4)
    350  1.13      shin 			if (*(volatile int *)(page+i) != (x ^ i))
    351  1.13      shin 				goto bad;
    352  1.31       uch #endif /* NARLY_MEMORY_PROBE */
    353  1.13      shin 
    354  1.13      shin 		if (!mem_clusters[n].size)
    355  1.13      shin 			mem_clusters[n].start = addr;
    356  1.13      shin 		mem_clusters[n].size += NBPG;
    357  1.13      shin 		continue;
    358  1.13      shin 
    359  1.13      shin 	bad:
    360  1.13      shin 		if (mem_clusters[n].size)
    361  1.13      shin 			++n;
    362  1.13      shin 		continue;
    363   1.4       uch 	}
    364  1.13      shin 	if (mem_clusters[n].size)
    365  1.13      shin 		++n;
    366  1.13      shin 	mem_cluster_cnt = n;
    367   1.4       uch }
    368   1.4       uch 
    369   1.4       uch void
    370  1.28       uch vr_fb_init(caddr_t *kernend)
    371   1.4       uch {
    372   1.4       uch 	/* Nothing to do */
    373   1.1  takemura }
    374   1.1  takemura 
    375   1.1  takemura void
    376   1.1  takemura vr_cons_init()
    377   1.1  takemura {
    378  1.35  takemura #if NCOM > 0 || NHPCFB > 0 || NVRKIU > 0
    379  1.30       uch 	bus_space_tag_t iot = hpcmips_system_bus_space();
    380   1.1  takemura #endif
    381  1.35  takemura #if NCOM > 0
    382  1.35  takemura 	static struct vr_com_platdep *com_info;
    383  1.35  takemura #endif
    384   1.1  takemura 
    385   1.1  takemura #if NCOM > 0
    386  1.35  takemura 	com_info = platid_search(&platid, platdep_com_table,
    387  1.35  takemura 	    sizeof(platdep_com_table)/sizeof(*platdep_com_table),
    388  1.35  takemura 	    sizeof(*platdep_com_table));
    389  1.18     jeffs #ifdef KGDB
    390  1.35  takemura 	if (com_info->attach != NULL) {
    391  1.35  takemura 		/* if KGDB is defined, always use the serial port for KGDB */
    392  1.35  takemura 		if ((*com_info->attach)(iot, com_info->addr, 9600,
    393  1.35  takemura 		    com_info->freq,
    394  1.35  takemura 		    (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8, 1)) {
    395  1.35  takemura 			printf("%s(%d): can't init kgdb's serial port",
    396  1.23     enami 			    __FILE__, __LINE__);
    397   1.1  takemura 		}
    398  1.33  takemura #else /* KGDB */
    399  1.35  takemura 	if (com_info->attach != NULL && (bootinfo->bi_cnuse&BI_CNUSE_SERIAL)) {
    400  1.33  takemura 		/* Serial console */
    401  1.35  takemura 		if ((*com_info->attach)(iot, com_info->addr, CONSPEED,
    402  1.35  takemura 		    com_info->freq,
    403  1.35  takemura 		    (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8, 0)) {
    404  1.33  takemura 			printf("%s(%d): can't init serial console",
    405  1.33  takemura 			    __FILE__, __LINE__);
    406  1.33  takemura 		} else {
    407  1.33  takemura 			return;
    408  1.33  takemura 		}
    409  1.33  takemura 	}
    410  1.33  takemura #endif /* KGDB */
    411  1.35  takemura #endif /* NCOM > 0 */
    412   1.1  takemura 
    413  1.15  takemura #if NHPCFB > 0
    414  1.17       uch 	if (hpcfb_cnattach(NULL)) {
    415   1.3  takemura 		printf("%s(%d): can't init fb console", __FILE__, __LINE__);
    416   1.3  takemura 	} else {
    417   1.3  takemura 		goto find_keyboard;
    418   1.3  takemura 	}
    419  1.25     enami  find_keyboard:
    420  1.30       uch #endif /* NHPCFB > 0 */
    421   1.3  takemura 
    422  1.22      sato #if NVRKIU > 0 && VRIP_KIU_ADDR != VRIP_NO_ADDR
    423  1.30       uch 	if (vrkiu_cnattach(iot, VRIP_KIU_ADDR)) {
    424   1.3  takemura 		printf("%s(%d): can't init vrkiu as console",
    425   1.3  takemura 		       __FILE__, __LINE__);
    426   1.3  takemura 	} else {
    427   1.3  takemura 		return;
    428   1.3  takemura 	}
    429  1.30       uch #endif /* NVRKIU > 0 && VRIP_KIU_ADDR != VRIP_NO_ADDR */
    430   1.5  takemura }
    431   1.5  takemura 
    432   1.5  takemura void
    433  1.28       uch vr_reboot(int howto, char *bootstr)
    434   1.5  takemura {
    435   1.7  takemura 	/*
    436   1.7  takemura 	 * power down
    437   1.7  takemura 	 */
    438   1.7  takemura 	if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
    439   1.7  takemura 		printf("fake powerdown\n");
    440   1.7  takemura 		__asm(__CONCAT(".word	",___STRING(VR_OPCODE_HIBERNATE)));
    441   1.7  takemura 		__asm("nop");
    442   1.7  takemura 		__asm("nop");
    443   1.7  takemura 		__asm("nop");
    444   1.7  takemura 		__asm("nop");
    445   1.7  takemura 		__asm("nop");
    446   1.7  takemura 		__asm(".set reorder");
    447   1.7  takemura 		/* not reach */
    448   1.7  takemura 		vr_reboot(howto&~RB_HALT, bootstr);
    449   1.7  takemura 	}
    450   1.7  takemura 	/*
    451   1.8  takemura 	 * halt
    452   1.7  takemura 	 */
    453   1.8  takemura 	if (howto & RB_HALT) {
    454   1.8  takemura #if NVRIP > 0
    455   1.8  takemura 		_spllower(~MIPS_INT_MASK_0);
    456   1.8  takemura 		vrip_intr_suspend();
    457   1.5  takemura #else
    458   1.8  takemura 		splhigh();
    459   1.5  takemura #endif
    460   1.7  takemura 		__asm(".set noreorder");
    461   1.7  takemura 		__asm(__CONCAT(".word	",___STRING(VR_OPCODE_SUSPEND)));
    462   1.6      sato 		__asm("nop");
    463   1.6      sato 		__asm("nop");
    464   1.6      sato 		__asm("nop");
    465   1.6      sato 		__asm("nop");
    466   1.6      sato 		__asm("nop");
    467   1.7  takemura 		__asm(".set reorder");
    468   1.8  takemura #if NVRIP > 0
    469   1.8  takemura 		vrip_intr_resume();
    470   1.8  takemura #endif
    471   1.6      sato 	}
    472   1.8  takemura 	/*
    473   1.8  takemura 	 * reset
    474   1.8  takemura 	 */
    475   1.8  takemura #if NVRDSU
    476   1.8  takemura 	vrdsu_reset();
    477   1.8  takemura #else
    478   1.8  takemura 	printf("%s(%d): There is no DSU.", __FILE__, __LINE__);
    479   1.8  takemura #endif
    480   1.1  takemura }
    481   1.1  takemura 
    482  1.30       uch /*
    483  1.30       uch  * Handle interrupts.
    484  1.30       uch  */
    485  1.31       uch void
    486  1.31       uch VR_INTR(u_int32_t status, u_int32_t cause, u_int32_t pc, u_int32_t ipending)
    487  1.30       uch {
    488  1.31       uch 	uvmexp.intrs++;
    489  1.31       uch 
    490  1.31       uch 	if (ipending & MIPS_INT_MASK_5) {
    491  1.31       uch 		/*
    492  1.31       uch 		 * spl* uses MIPS_INT_MASK not MIPS3_INT_MASK. it causes
    493  1.31       uch 		 * INT5 interrupt.
    494  1.31       uch 		 */
    495  1.31       uch 		mips3_cp0_compare_write(mips3_cp0_count_read());
    496  1.31       uch 	}
    497  1.31       uch 
    498  1.31       uch 	/* for spllowersoftclock */
    499  1.31       uch 	_splset(((status & ~cause) & MIPS_HARD_INT_MASK) | MIPS_SR_INT_IE);
    500  1.31       uch 
    501  1.31       uch 	if (ipending & MIPS_INT_MASK_1) {
    502  1.31       uch 		(*vr_intr_handler[1])(vr_intr_arg[1], pc, status);
    503  1.30       uch 
    504  1.31       uch 		cause &= ~MIPS_INT_MASK_1;
    505  1.31       uch 		_splset(((status & ~cause) & MIPS_HARD_INT_MASK)
    506  1.31       uch 		    | MIPS_SR_INT_IE);
    507  1.31       uch 	}
    508  1.31       uch 
    509  1.31       uch 	if (ipending & MIPS_INT_MASK_0) {
    510  1.31       uch 		(*vr_intr_handler[0])(vr_intr_arg[0], pc, status);
    511  1.31       uch 
    512  1.31       uch 		cause &= ~MIPS_INT_MASK_0;
    513  1.31       uch 	}
    514  1.31       uch 	_splset(((status & ~cause) & MIPS_HARD_INT_MASK) | MIPS_SR_INT_IE);
    515  1.31       uch 
    516  1.31       uch 	softintr(ipending);
    517  1.30       uch }
    518  1.30       uch 
    519   1.1  takemura void *
    520  1.30       uch vr_intr_establish(int line, int (*ih_fun)(void *, u_int32_t, u_int32_t),
    521  1.28       uch     void *ih_arg)
    522   1.1  takemura {
    523  1.28       uch 
    524  1.31       uch 	KDASSERT(vr_intr_handler[line] == vr_null_handler);
    525  1.31       uch 
    526  1.31       uch 	vr_intr_handler[line] = ih_fun;
    527  1.31       uch 	vr_intr_arg[line] = ih_arg;
    528   1.1  takemura 
    529  1.31       uch 	return ((void *)line);
    530   1.1  takemura }
    531   1.1  takemura 
    532   1.1  takemura void
    533  1.28       uch vr_intr_disestablish(void *ih)
    534   1.1  takemura {
    535   1.1  takemura 	int line = (int)ih;
    536  1.28       uch 
    537  1.31       uch 	vr_intr_handler[line] = vr_null_handler;
    538  1.31       uch 	vr_intr_arg[line] = NULL;
    539   1.1  takemura }
    540   1.1  takemura 
    541   1.1  takemura int
    542  1.31       uch vr_null_handler(void *arg, u_int32_t pc, u_int32_t status)
    543   1.1  takemura {
    544  1.31       uch 
    545  1.31       uch 	printf("vr_null_handler\n");
    546  1.28       uch 
    547  1.28       uch 	return (0);
    548   1.1  takemura }
    549  1.22      sato 
    550  1.22      sato /*
    551  1.22      sato int x4181 = VR4181;
    552  1.22      sato int x4101 = VR4101;
    553  1.22      sato int x4102 = VR4102;
    554  1.22      sato int x4111 = VR4111;
    555  1.22      sato int x4121 = VR4121;
    556  1.22      sato int x4122 = VR4122;
    557  1.22      sato int xo4181 = ONLY_VR4181;
    558  1.22      sato int xo4101 = ONLY_VR4101;
    559  1.22      sato int xo4102 = ONLY_VR4102;
    560  1.22      sato int xo4111_4121 = ONLY_VR4111_4121;
    561  1.22      sato int g4101=VRGROUP_4101;
    562  1.22      sato int g4102=VRGROUP_4102;
    563  1.22      sato int g4181=VRGROUP_4181;
    564  1.22      sato int g4102_4121=VRGROUP_4102_4121;
    565  1.22      sato int g4111_4121=VRGROUP_4111_4121;
    566  1.22      sato int g4102_4122=VRGROUP_4102_4122;
    567  1.22      sato int g4111_4122=VRGROUP_4111_4122;
    568  1.22      sato int single_vrip_base=SINGLE_VRIP_BASE;
    569  1.22      sato int vrip_base_addr=VRIP_BASE_ADDR;
    570  1.22      sato */
    571