Home | History | Annotate | Line # | Download | only in vr
vr.c revision 1.9
      1 /*	$NetBSD: vr.c,v 1.9 1999/12/09 02:15:27 sato Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1999
      5  *         Shin Takemura and PocketBSD Project. All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the PocketBSD project
     18  *	and its contributors.
     19  * 4. Neither the name of the project nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  *
     35  */
     36 #include <sys/param.h>
     37 #include <sys/types.h>
     38 #include <sys/systm.h>
     39 #include <sys/device.h>
     40 #include <sys/reboot.h>
     41 
     42 #include <machine/cpu.h>
     43 #include <machine/intr.h>
     44 #include <machine/reg.h>
     45 #include <machine/psl.h>
     46 #include <machine/locore.h>
     47 #include <machine/sysconf.h>
     48 #include <machine/bus.h>
     49 #include <machine/autoconf.h>
     50 
     51 #include <mips/mips_param.h>		/* hokey spl()s */
     52 #include <mips/mips/mips_mcclock.h>	/* mcclock CPUspeed estimation */
     53 
     54 #include <hpcmips/vr/vr.h>
     55 #include <hpcmips/vr/vripreg.h>
     56 #include <hpcmips/vr/rtcreg.h>
     57 #include <hpcmips/hpcmips/machdep.h>	/* XXXjrs replace with vectors */
     58 #include <machine/bootinfo.h>
     59 
     60 #include "vrip.h"
     61 #if NVRIP > 0
     62 #include <hpcmips/vr/vripvar.h>
     63 #endif
     64 
     65 #include "vrbcu.h"
     66 #if NVRBCU > 0
     67 #include <hpcmips/vr/bcuvar.h>
     68 #endif
     69 
     70 #include "vrdsu.h"
     71 #if NVRDSU > 0
     72 #include <hpcmips/vr/vrdsuvar.h>
     73 #endif
     74 
     75 #include "com.h"
     76 #if NCOM > 0
     77 #include <sys/termios.h>
     78 #include <sys/ttydefaults.h>
     79 #include <dev/ic/comreg.h>
     80 #include <dev/ic/comvar.h>
     81 #include <hpcmips/vr/siureg.h>
     82 #include <hpcmips/vr/com_vripvar.h>
     83 #ifndef CONSPEED
     84 #define CONSPEED TTYDEF_SPEED
     85 #endif
     86 #endif
     87 
     88 #include "fb.h"
     89 #include "vrkiu.h"
     90 #if NFB > 0 || NVRKIU > 0
     91 #include <dev/rcons/raster.h>
     92 #include <dev/wscons/wsdisplayvar.h>
     93 #endif
     94 
     95 #if NFB > 0
     96 #include <arch/hpcmips/dev/fbvar.h>
     97 #endif
     98 
     99 #if NFB > 0
    100 #include <arch/hpcmips/vr/vrkiuvar.h>
    101 #endif
    102 
    103 void	vr_init __P((void));
    104 void	vr_os_init __P((void));
    105 void	vr_bus_reset __P((void));
    106 int	vr_intr __P((u_int32_t mask, u_int32_t pc, u_int32_t statusReg, u_int32_t causeReg));
    107 void	vr_cons_init __P((void));
    108 void	vr_device_register __P((struct device *, void *));
    109 void    vr_fb_init __P((caddr_t*));
    110 int     vr_mem_init __P((caddr_t));
    111 void	vr_reboot __P((int howto, char *bootstr));
    112 
    113 extern unsigned nullclkread __P((void));
    114 extern unsigned (*clkread) __P((void));
    115 
    116 /*
    117  * CPU interrupt dispatch table (HwInt[0:3])
    118  */
    119 int null_handler __P((void*, u_int32_t, u_int32_t));
    120 static int (*intr_handler[4]) __P((void*, u_int32_t, u_int32_t)) =
    121 {
    122 	null_handler,
    123 	null_handler,
    124 	null_handler,
    125 	null_handler
    126 };
    127 static void *intr_arg[4];
    128 
    129 void
    130 vr_init()
    131 {
    132 	/*
    133 	 * Platform Information.
    134 	 */
    135 
    136 	/*
    137 	 * Platform Specific Function Hooks
    138 	 */
    139 	platform.os_init = vr_os_init;
    140 	platform.bus_reset = vr_bus_reset;
    141 	platform.cons_init = vr_cons_init;
    142 	platform.device_register = vr_device_register;
    143 	platform.fb_init = vr_fb_init;
    144 	platform.mem_init = vr_mem_init;
    145 	platform.reboot = vr_reboot;
    146 
    147 #if NVRBCU > 0
    148 	sprintf(cpu_model, "NEC %s rev%d.%d",
    149 		vrbcu_vrip_getcpuname(),
    150 		vrbcu_vrip_getcpumajor(),
    151 		vrbcu_vrip_getcpuminor());
    152 #else
    153 	sprintf(cpu_model, "NEC VR41xx");
    154 #endif
    155 }
    156 
    157 int
    158 vr_mem_init(kernend)
    159 	caddr_t kernend; /* kseg0 */
    160 {
    161 	u_int32_t startaddr, endaddr, page;
    162 	int npage;
    163 #define VR41_SYSADDR_DRAMSTART 0x0
    164 #define VR41_SYSADDR_DRAM_LEN 0x04000000
    165 	startaddr = MIPS_PHYS_TO_KSEG1(
    166 		(btoc((u_int32_t)kernend - MIPS_KSEG0_START)) << PGSHIFT);
    167 	endaddr = MIPS_PHYS_TO_KSEG1(VR41_SYSADDR_DRAMSTART +
    168 				     VR41_SYSADDR_DRAM_LEN);
    169 	for(page = startaddr, npage = 0; page < endaddr;
    170 	    page+= NBPG, npage++) {
    171 		if (badaddr((char*)page, 4))
    172 			break;
    173 		((volatile int *)page)[0] = 0xa5a5a5a5;
    174 		((volatile int *)page)[4] = 0x5a5a5a5a;
    175 		wbflush();
    176 		if (*(volatile int *)page != 0xa5a5a5a5)
    177 			break;
    178 	}
    179 	/* Clear currently unused D-RAM area (For reboot Windows CE clearly)*/
    180 	memset((void*)startaddr, 0, npage * NBPG);
    181 	memset((void*)(KERNBASE + 0x400), 0, KERNTEXTOFF - KERNBASE - 0x800);
    182 
    183 	return npage;
    184 }
    185 
    186 void
    187 vr_fb_init(kernend)
    188 	caddr_t *kernend;
    189 {
    190 	/* Nothing to do */
    191 }
    192 
    193 void
    194 vr_os_init()
    195 {
    196 	/*
    197 	 * Set up interrupt handling and I/O addresses.
    198 	 */
    199 	mips_hardware_intr = vr_intr;
    200 
    201 	splvec.splbio = MIPS_SPL0;
    202 	splvec.splnet = MIPS_SPL0;
    203 	splvec.spltty = MIPS_SPL0;
    204 	splvec.splimp = MIPS_SPL0;
    205 	splvec.splclock = MIPS_SPL_0_1;
    206 	splvec.splstatclock = MIPS_SPL_0_1;
    207 
    208 	/* no high resolution timer circuit; possibly never called */
    209 	clkread = nullclkread;
    210 
    211 #ifdef NOT_YET
    212 	mcclock_addr = (volatile struct chiptime *)
    213 		MIPS_PHYS_TO_KSEG1(Vr_SYS_CLOCK);
    214 	mc_cpuspeed(mcclock_addr, MIPS_INT_MASK_1);
    215 #else
    216 	printf("%s(%d): cpuspeed estimation is notimplemented\n",
    217 	       __FILE__, __LINE__);
    218 #endif
    219 #ifdef HPCMIPS_L1CACHE_DISABLE
    220 	cpuspeed = 1;	/* XXX, CPU is very very slow because L1 cache is */
    221 	/* disabled. */
    222 #endif /*  HPCMIPS_L1CAHCE_DISABLE */
    223 }
    224 
    225 
    226 /*
    227  * Initalize the memory system and I/O buses.
    228  */
    229 void
    230 vr_bus_reset()
    231 {
    232 	printf("%s(%d): vr_bus_reset() not implemented.\n",
    233 	       __FILE__, __LINE__);
    234 }
    235 
    236 void
    237 vr_cons_init()
    238 {
    239 #if NCOM > 0 || NFB > 0 || NVRKIU > 0
    240 	extern bus_space_tag_t system_bus_iot;
    241 	extern bus_space_tag_t mb_bus_space_init __P((void));
    242 #endif
    243 
    244 #if NCOM > 0
    245 	if (bootinfo->bi_cnuse & BI_CNUSE_SERIAL) {
    246 		/* Serial console */
    247 		mb_bus_space_init(); /* At this time, not initialized yet */
    248 		if(com_vrip_cnattach(system_bus_iot, 0x0c000000, CONSPEED,
    249 				     VRCOM_FREQ,
    250 				     (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8)) {
    251 			printf("%s(%d): can't init serial console", __FILE__, __LINE__);
    252 		} else {
    253 			return;
    254 		}
    255 	}
    256 #endif
    257 
    258 #if NFB > 0
    259 	mb_bus_space_init(); /* At this time, not initialized yet */
    260 	if(fb_cnattach(system_bus_iot, 0x0c000000, 0, 0)) {
    261 		printf("%s(%d): can't init fb console", __FILE__, __LINE__);
    262 	} else {
    263 		goto find_keyboard;
    264 	}
    265 #endif
    266 
    267  find_keyboard:
    268 #if NVRKIU > 0
    269 	if (vrkiu_cnattach(system_bus_iot, VRIP_KIU_ADDR)) {
    270 		printf("%s(%d): can't init vrkiu as console",
    271 		       __FILE__, __LINE__);
    272 	} else {
    273 		return;
    274 	}
    275 #endif
    276 }
    277 
    278 void
    279 vr_device_register(dev, aux)
    280 	struct device *dev;
    281 	void *aux;
    282 {
    283 	printf("%s(%d): vr_device_register() not implemented.\n",
    284 	       __FILE__, __LINE__);
    285 	panic("abort");
    286 }
    287 
    288 void
    289 vr_reboot(howto, bootstr)
    290 	int howto;
    291 	char *bootstr;
    292 {
    293 	/*
    294 	 * power down
    295 	 */
    296 	if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
    297 		printf("fake powerdown\n");
    298 		__asm(__CONCAT(".word	",___STRING(VR_OPCODE_HIBERNATE)));
    299 		__asm("nop");
    300 		__asm("nop");
    301 		__asm("nop");
    302 		__asm("nop");
    303 		__asm("nop");
    304 		__asm(".set reorder");
    305 		/* not reach */
    306 		vr_reboot(howto&~RB_HALT, bootstr);
    307 	}
    308 	/*
    309 	 * halt
    310 	 */
    311 	if (howto & RB_HALT) {
    312 #if NVRIP > 0
    313 		_spllower(~MIPS_INT_MASK_0);
    314 		vrip_intr_suspend();
    315 #else
    316 		splhigh();
    317 #endif
    318 		__asm(".set noreorder");
    319 		__asm(__CONCAT(".word	",___STRING(VR_OPCODE_SUSPEND)));
    320 		__asm("nop");
    321 		__asm("nop");
    322 		__asm("nop");
    323 		__asm("nop");
    324 		__asm("nop");
    325 		__asm(".set reorder");
    326 #if NVRIP > 0
    327 		vrip_intr_resume();
    328 #endif
    329 	}
    330 	/*
    331 	 * reset
    332 	 */
    333 #if NVRDSU
    334 	vrdsu_reset();
    335 #else
    336 	printf("%s(%d): There is no DSU.", __FILE__, __LINE__);
    337 #endif
    338 }
    339 
    340 void *
    341 vr_intr_establish(line, ih_fun, ih_arg)
    342 	int line;
    343 	int (*ih_fun) __P((void*, u_int32_t, u_int32_t));
    344 	void *ih_arg;
    345 {
    346 	if (intr_handler[line] != null_handler) {
    347 		panic("vr_intr_establish: can't establish duplicated intr handler.");
    348 	}
    349 	intr_handler[line] = ih_fun;
    350 	intr_arg[line] = ih_arg;
    351 
    352 	return (void*)line;
    353 }
    354 
    355 
    356 void
    357 vr_intr_disestablish(ih)
    358 	void *ih;
    359 {
    360 	int line = (int)ih;
    361 	intr_handler[line] = null_handler;
    362 	intr_arg[line] = NULL;
    363 }
    364 
    365 int
    366 null_handler(arg, pc, statusReg)
    367 	void *arg;
    368 	u_int32_t pc;
    369 	u_int32_t statusReg;
    370 {
    371 	printf("null_handler\n");
    372 	return 0;
    373 }
    374 
    375 /*
    376  * Handle interrupts.
    377  */
    378 int
    379 vr_intr(mask, pc, status, cause)
    380 	u_int32_t mask;
    381 	u_int32_t pc;
    382 	u_int32_t status;
    383 	u_int32_t cause;
    384 {
    385 	int hwintr;
    386 
    387 	hwintr = (ffs(mask >> 10) -1) & 0x3;
    388 	(*intr_handler[hwintr])(intr_arg[hwintr], pc, status);
    389 	return (MIPS_SR_INT_IE | (status & ~cause & MIPS_HARD_INT_MASK));
    390 }
    391