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