Home | History | Annotate | Line # | Download | only in vr
vr.c revision 1.10
      1 /*	$NetBSD: vr.c,v 1.10 1999/12/16 13:09:02 shin 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 %d.%03dMHz",
    149 		vrbcu_vrip_getcpuname(),
    150 		vrbcu_vrip_getcpumajor(),
    151 		vrbcu_vrip_getcpuminor(),
    152 		vrbcu_vrip_getcpuclock() / 1000000,
    153 		(vrbcu_vrip_getcpuclock() % 1000000) / 1000);
    154 #else
    155 	sprintf(cpu_model, "NEC VR41xx");
    156 #endif
    157 }
    158 
    159 int
    160 vr_mem_init(kernend)
    161 	caddr_t kernend; /* kseg0 */
    162 {
    163 	u_int32_t startaddr, endaddr, page;
    164 	int npage;
    165 #define VR41_SYSADDR_DRAMSTART 0x0
    166 #define VR41_SYSADDR_DRAM_LEN 0x04000000
    167 	startaddr = MIPS_PHYS_TO_KSEG1(
    168 		(btoc((u_int32_t)kernend - MIPS_KSEG0_START)) << PGSHIFT);
    169 	endaddr = MIPS_PHYS_TO_KSEG1(VR41_SYSADDR_DRAMSTART +
    170 				     VR41_SYSADDR_DRAM_LEN);
    171 	for(page = startaddr, npage = 0; page < endaddr;
    172 	    page+= NBPG, npage++) {
    173 		if (badaddr((char*)page, 4))
    174 			break;
    175 		((volatile int *)page)[0] = 0xa5a5a5a5;
    176 		((volatile int *)page)[4] = 0x5a5a5a5a;
    177 		wbflush();
    178 		if (*(volatile int *)page != 0xa5a5a5a5)
    179 			break;
    180 	}
    181 	/* Clear currently unused D-RAM area (For reboot Windows CE clearly)*/
    182 	memset((void*)startaddr, 0, npage * NBPG);
    183 	memset((void*)(KERNBASE + 0x400), 0, KERNTEXTOFF - KERNBASE - 0x800);
    184 
    185 	return npage;
    186 }
    187 
    188 void
    189 vr_fb_init(kernend)
    190 	caddr_t *kernend;
    191 {
    192 	/* Nothing to do */
    193 }
    194 
    195 void
    196 vr_os_init()
    197 {
    198 	/*
    199 	 * Set up interrupt handling and I/O addresses.
    200 	 */
    201 	mips_hardware_intr = vr_intr;
    202 
    203 	splvec.splbio = MIPS_SPL0;
    204 	splvec.splnet = MIPS_SPL0;
    205 	splvec.spltty = MIPS_SPL0;
    206 	splvec.splimp = MIPS_SPL0;
    207 	splvec.splclock = MIPS_SPL_0_1;
    208 	splvec.splstatclock = MIPS_SPL_0_1;
    209 
    210 	/* no high resolution timer circuit; possibly never called */
    211 	clkread = nullclkread;
    212 
    213 #ifdef NOT_YET
    214 	mcclock_addr = (volatile struct chiptime *)
    215 		MIPS_PHYS_TO_KSEG1(Vr_SYS_CLOCK);
    216 	mc_cpuspeed(mcclock_addr, MIPS_INT_MASK_1);
    217 #else
    218 	printf("%s(%d): cpuspeed estimation is notimplemented\n",
    219 	       __FILE__, __LINE__);
    220 #endif
    221 #ifdef HPCMIPS_L1CACHE_DISABLE
    222 	cpuspeed = 1;	/* XXX, CPU is very very slow because L1 cache is */
    223 	/* disabled. */
    224 #endif /*  HPCMIPS_L1CAHCE_DISABLE */
    225 }
    226 
    227 
    228 /*
    229  * Initalize the memory system and I/O buses.
    230  */
    231 void
    232 vr_bus_reset()
    233 {
    234 	printf("%s(%d): vr_bus_reset() not implemented.\n",
    235 	       __FILE__, __LINE__);
    236 }
    237 
    238 void
    239 vr_cons_init()
    240 {
    241 #if NCOM > 0 || NFB > 0 || NVRKIU > 0
    242 	extern bus_space_tag_t system_bus_iot;
    243 	extern bus_space_tag_t mb_bus_space_init __P((void));
    244 #endif
    245 
    246 #if NCOM > 0
    247 	if (bootinfo->bi_cnuse & BI_CNUSE_SERIAL) {
    248 		/* Serial console */
    249 		mb_bus_space_init(); /* At this time, not initialized yet */
    250 		if(com_vrip_cnattach(system_bus_iot, 0x0c000000, CONSPEED,
    251 				     VRCOM_FREQ,
    252 				     (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8)) {
    253 			printf("%s(%d): can't init serial console", __FILE__, __LINE__);
    254 		} else {
    255 			return;
    256 		}
    257 	}
    258 #endif
    259 
    260 #if NFB > 0
    261 	mb_bus_space_init(); /* At this time, not initialized yet */
    262 	if(fb_cnattach(system_bus_iot, 0x0c000000, 0, 0)) {
    263 		printf("%s(%d): can't init fb console", __FILE__, __LINE__);
    264 	} else {
    265 		goto find_keyboard;
    266 	}
    267 #endif
    268 
    269  find_keyboard:
    270 #if NVRKIU > 0
    271 	if (vrkiu_cnattach(system_bus_iot, VRIP_KIU_ADDR)) {
    272 		printf("%s(%d): can't init vrkiu as console",
    273 		       __FILE__, __LINE__);
    274 	} else {
    275 		return;
    276 	}
    277 #endif
    278 }
    279 
    280 void
    281 vr_device_register(dev, aux)
    282 	struct device *dev;
    283 	void *aux;
    284 {
    285 	printf("%s(%d): vr_device_register() not implemented.\n",
    286 	       __FILE__, __LINE__);
    287 	panic("abort");
    288 }
    289 
    290 void
    291 vr_reboot(howto, bootstr)
    292 	int howto;
    293 	char *bootstr;
    294 {
    295 	/*
    296 	 * power down
    297 	 */
    298 	if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
    299 		printf("fake powerdown\n");
    300 		__asm(__CONCAT(".word	",___STRING(VR_OPCODE_HIBERNATE)));
    301 		__asm("nop");
    302 		__asm("nop");
    303 		__asm("nop");
    304 		__asm("nop");
    305 		__asm("nop");
    306 		__asm(".set reorder");
    307 		/* not reach */
    308 		vr_reboot(howto&~RB_HALT, bootstr);
    309 	}
    310 	/*
    311 	 * halt
    312 	 */
    313 	if (howto & RB_HALT) {
    314 #if NVRIP > 0
    315 		_spllower(~MIPS_INT_MASK_0);
    316 		vrip_intr_suspend();
    317 #else
    318 		splhigh();
    319 #endif
    320 		__asm(".set noreorder");
    321 		__asm(__CONCAT(".word	",___STRING(VR_OPCODE_SUSPEND)));
    322 		__asm("nop");
    323 		__asm("nop");
    324 		__asm("nop");
    325 		__asm("nop");
    326 		__asm("nop");
    327 		__asm(".set reorder");
    328 #if NVRIP > 0
    329 		vrip_intr_resume();
    330 #endif
    331 	}
    332 	/*
    333 	 * reset
    334 	 */
    335 #if NVRDSU
    336 	vrdsu_reset();
    337 #else
    338 	printf("%s(%d): There is no DSU.", __FILE__, __LINE__);
    339 #endif
    340 }
    341 
    342 void *
    343 vr_intr_establish(line, ih_fun, ih_arg)
    344 	int line;
    345 	int (*ih_fun) __P((void*, u_int32_t, u_int32_t));
    346 	void *ih_arg;
    347 {
    348 	if (intr_handler[line] != null_handler) {
    349 		panic("vr_intr_establish: can't establish duplicated intr handler.");
    350 	}
    351 	intr_handler[line] = ih_fun;
    352 	intr_arg[line] = ih_arg;
    353 
    354 	return (void*)line;
    355 }
    356 
    357 
    358 void
    359 vr_intr_disestablish(ih)
    360 	void *ih;
    361 {
    362 	int line = (int)ih;
    363 	intr_handler[line] = null_handler;
    364 	intr_arg[line] = NULL;
    365 }
    366 
    367 int
    368 null_handler(arg, pc, statusReg)
    369 	void *arg;
    370 	u_int32_t pc;
    371 	u_int32_t statusReg;
    372 {
    373 	printf("null_handler\n");
    374 	return 0;
    375 }
    376 
    377 /*
    378  * Handle interrupts.
    379  */
    380 int
    381 vr_intr(mask, pc, status, cause)
    382 	u_int32_t mask;
    383 	u_int32_t pc;
    384 	u_int32_t status;
    385 	u_int32_t cause;
    386 {
    387 	int hwintr;
    388 
    389 	hwintr = (ffs(mask >> 10) -1) & 0x3;
    390 	(*intr_handler[hwintr])(intr_arg[hwintr], pc, status);
    391 	return (MIPS_SR_INT_IE | (status & ~cause & MIPS_HARD_INT_MASK));
    392 }
    393