Home | History | Annotate | Line # | Download | only in vr
vr.c revision 1.24
      1 /*	$NetBSD: vr.c,v 1.24 2001/05/30 15:24:30 lukem 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 "opt_kgdb.h"
     37 
     38 #include <sys/param.h>
     39 #include <sys/types.h>
     40 #include <sys/systm.h>
     41 #include <sys/device.h>
     42 #include <sys/reboot.h>
     43 #include <sys/kcore.h>
     44 
     45 #include <machine/cpu.h>
     46 #include <machine/intr.h>
     47 #include <machine/reg.h>
     48 #include <machine/psl.h>
     49 #include <machine/locore.h>
     50 #include <machine/sysconf.h>
     51 #include <machine/bus.h>
     52 #include <machine/autoconf.h>
     53 
     54 #include <mips/mips_param.h>		/* hokey spl()s */
     55 #include <mips/mips/mips_mcclock.h>	/* mcclock CPUspeed estimation */
     56 
     57 #include "opt_vr41xx.h"
     58 #include <hpcmips/vr/vr.h>
     59 #include <hpcmips/vr/vr_asm.h>
     60 #include <hpcmips/vr/vrcpudef.h>
     61 #include <hpcmips/vr/vripreg.h>
     62 #include <hpcmips/vr/rtcreg.h>
     63 #include <hpcmips/hpcmips/machdep.h>	/* cpu_name */
     64 #include <machine/bootinfo.h>
     65 
     66 #include "vrip.h"
     67 #if NVRIP > 0
     68 #include <hpcmips/vr/vripvar.h>
     69 #endif
     70 
     71 #include "vrbcu.h"
     72 #if NVRBCU > 0
     73 #include <hpcmips/vr/bcuvar.h>
     74 #endif
     75 
     76 #include "vrdsu.h"
     77 #if NVRDSU > 0
     78 #include <hpcmips/vr/vrdsuvar.h>
     79 #endif
     80 
     81 #include "com.h"
     82 #if NCOM > 0
     83 #include <sys/termios.h>
     84 #include <sys/ttydefaults.h>
     85 #include <dev/ic/comreg.h>
     86 #include <dev/ic/comvar.h>
     87 #include <hpcmips/vr/siureg.h>
     88 #include <hpcmips/vr/com_vripvar.h>
     89 #ifndef CONSPEED
     90 #define CONSPEED TTYDEF_SPEED
     91 #endif
     92 #endif
     93 
     94 #include "hpcfb.h"
     95 #include "vrkiu.h"
     96 #if NVRKIU > 0
     97 #include <dev/wscons/wsdisplayvar.h>
     98 #include <dev/rasops/rasops.h>
     99 #endif
    100 
    101 #if NHPCFB > 0
    102 #include <dev/hpc/hpcfbvar.h>
    103 #endif
    104 
    105 #if NVRKIU > 0
    106 #include <arch/hpcmips/vr/vrkiuvar.h>
    107 #endif
    108 
    109 void	vr_init __P((void));
    110 void	vr_os_init __P((void));
    111 void	vr_bus_reset __P((void));
    112 int	vr_intr __P((u_int32_t, u_int32_t, u_int32_t, u_int32_t));
    113 void	vr_cons_init __P((void));
    114 void	vr_device_register __P((struct device *, void *));
    115 void    vr_fb_init __P((caddr_t*));
    116 void    vr_mem_init __P((paddr_t));
    117 void	vr_find_dram __P((paddr_t, paddr_t));
    118 void	vr_reboot __P((int howto, char *bootstr));
    119 
    120 extern unsigned nullclkread __P((void));
    121 extern unsigned (*clkread) __P((void));
    122 
    123 /*
    124  * CPU interrupt dispatch table (HwInt[0:3])
    125  */
    126 int null_handler __P((void*, u_int32_t, u_int32_t));
    127 static int (*intr_handler[4]) __P((void*, u_int32_t, u_int32_t)) =
    128 {
    129 	null_handler,
    130 	null_handler,
    131 	null_handler,
    132 	null_handler
    133 };
    134 static void *intr_arg[4];
    135 
    136 extern phys_ram_seg_t mem_clusters[];
    137 extern int mem_cluster_cnt;
    138 
    139 void
    140 vr_init()
    141 {
    142 	/*
    143 	 * Platform Information.
    144 	 */
    145 
    146 	/*
    147 	 * Platform Specific Function Hooks
    148 	 */
    149 	platform.os_init = vr_os_init;
    150 	platform.iointr = vr_intr;
    151 	platform.bus_reset = vr_bus_reset;
    152 	platform.cons_init = vr_cons_init;
    153 	platform.device_register = vr_device_register;
    154 	platform.fb_init = vr_fb_init;
    155 	platform.mem_init = vr_mem_init;
    156 	platform.reboot = vr_reboot;
    157 
    158 #if NVRBCU > 0
    159 	sprintf(cpu_name, "NEC %s rev%d.%d %d.%03dMHz",
    160 		vrbcu_vrip_getcpuname(),
    161 		vrbcu_vrip_getcpumajor(),
    162 		vrbcu_vrip_getcpuminor(),
    163 		vrbcu_vrip_getcpuclock() / 1000000,
    164 		(vrbcu_vrip_getcpuclock() % 1000000) / 1000);
    165 #else
    166 	sprintf(cpu_name, "NEC VR41xx");
    167 #endif
    168 }
    169 
    170 void
    171 vr_mem_init(kernend)
    172 	paddr_t kernend;
    173 {
    174 	mem_clusters[0].start = 0;
    175 	mem_clusters[0].size = kernend;
    176 	mem_cluster_cnt = 1;
    177 	vr_find_dram(kernend, 0x02000000);
    178 	vr_find_dram(0x02000000, 0x04000000);
    179 	vr_find_dram(0x04000000, 0x06000000);
    180 	vr_find_dram(0x06000000, 0x08000000);
    181 
    182 	/* Clear currently unused D-RAM area (For reboot Windows CE clearly)*/
    183 	memset((void *)(KERNBASE + 0x400), 0, KERNTEXTOFF - (KERNBASE + 0x800));
    184 }
    185 
    186 void
    187 vr_find_dram(addr, end)
    188 	paddr_t addr, end;
    189 {
    190 	int n;
    191 	caddr_t page;
    192 #ifdef NARLY_MEMORY_PROBE
    193 	int x, i;
    194 #endif
    195 
    196 	n = mem_cluster_cnt;
    197 	for (; addr < end; addr += NBPG) {
    198 
    199 		page = (void *)MIPS_PHYS_TO_KSEG1(addr);
    200 		if (badaddr(page, 4))
    201 			goto bad;
    202 
    203 		/* stop memory probing at first memory image */
    204 		if (bcmp(page, (void *)MIPS_PHYS_TO_KSEG0(0), 128) == 0)
    205 			return;
    206 
    207 		*(volatile int *)(page+0) = 0xa5a5a5a5;
    208 		*(volatile int *)(page+4) = 0x5a5a5a5a;
    209 		wbflush();
    210 		if (*(volatile int *)(page+0) != 0xa5a5a5a5)
    211 			goto bad;
    212 
    213 		*(volatile int *)(page+0) = 0x5a5a5a5a;
    214 		*(volatile int *)(page+4) = 0xa5a5a5a5;
    215 		wbflush();
    216 		if (*(volatile int *)(page+0) != 0x5a5a5a5a)
    217 			goto bad;
    218 
    219 #ifdef NARLY_MEMORY_PROBE
    220 		x = random();
    221 		for (i = 0; i < NBPG; i += 4)
    222 			*(volatile int *)(page+i) = (x ^ i);
    223 		wbflush();
    224 		for (i = 0; i < NBPG; i += 4)
    225 			if (*(volatile int *)(page+i) != (x ^ i))
    226 				goto bad;
    227 
    228 		x = random();
    229 		for (i = 0; i < NBPG; i += 4)
    230 			*(volatile int *)(page+i) = (x ^ i);
    231 		wbflush();
    232 		for (i = 0; i < NBPG; i += 4)
    233 			if (*(volatile int *)(page+i) != (x ^ i))
    234 				goto bad;
    235 #endif
    236 
    237 		if (!mem_clusters[n].size)
    238 			mem_clusters[n].start = addr;
    239 		mem_clusters[n].size += NBPG;
    240 		continue;
    241 
    242 	bad:
    243 		if (mem_clusters[n].size)
    244 			++n;
    245 		continue;
    246 	}
    247 	if (mem_clusters[n].size)
    248 		++n;
    249 	mem_cluster_cnt = n;
    250 }
    251 
    252 void
    253 vr_fb_init(kernend)
    254 	caddr_t *kernend;
    255 {
    256 	/* Nothing to do */
    257 }
    258 
    259 void
    260 vr_os_init()
    261 {
    262 	/*
    263 	 * Set up interrupt handling and I/O addresses.
    264 	 */
    265 
    266 	splvec.splbio = MIPS_SPL0;
    267 	splvec.splnet = MIPS_SPL0;
    268 	splvec.spltty = MIPS_SPL0;
    269 	splvec.splvm = MIPS_SPL0;
    270 	splvec.splclock = MIPS_SPL_0_1;
    271 	splvec.splstatclock = MIPS_SPL_0_1;
    272 
    273 	/* no high resolution timer circuit; possibly never called */
    274 	clkread = nullclkread;
    275 
    276 #ifdef NOT_YET
    277 	mcclock_addr = (volatile struct chiptime *)
    278 		MIPS_PHYS_TO_KSEG1(Vr_SYS_CLOCK);
    279 	mc_cpuspeed(mcclock_addr, MIPS_INT_MASK_1);
    280 #else
    281 	printf("%s(%d): cpuspeed estimation is notimplemented\n",
    282 	       __FILE__, __LINE__);
    283 #endif
    284 #ifdef HPCMIPS_L1CACHE_DISABLE
    285 	cpuspeed = 1;	/* XXX, CPU is very very slow because L1 cache is */
    286 	/* disabled. */
    287 #endif /*  HPCMIPS_L1CAHCE_DISABLE */
    288 }
    289 
    290 
    291 /*
    292  * Initalize the memory system and I/O buses.
    293  */
    294 void
    295 vr_bus_reset()
    296 {
    297 	printf("%s(%d): vr_bus_reset() not implemented.\n",
    298 	       __FILE__, __LINE__);
    299 }
    300 
    301 void
    302 vr_cons_init()
    303 {
    304 #if NCOM > 0 || NHPCFB > 0 || NVRKIU > 0
    305 	extern bus_space_tag_t system_bus_iot;
    306 	extern bus_space_tag_t mb_bus_space_init __P((void));
    307 
    308 	/*
    309 	 * At this time, system_bus_iot is not initialized yet.
    310 	 * Just initialize it here.
    311 	 */
    312 	mb_bus_space_init();
    313 #endif
    314 
    315 #if NCOM > 0
    316 #ifdef KGDB
    317 	/* if KGDB is defined, always use the serial port for KGDB */
    318 	if (com_vrip_cndb_attach(system_bus_iot, VRIP_SIU_ADDR, 9600,
    319 	    VRCOM_FREQ, (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8, 1)) {
    320 		printf("%s(%d): can't init kgdb's serial port",
    321 		    __FILE__, __LINE__);
    322 	}
    323 #else
    324 	if (bootinfo->bi_cnuse & BI_CNUSE_SERIAL) {
    325 		/* Serial console */
    326 		if (com_vrip_cndb_attach(system_bus_iot,
    327 		    VRIP_SIU_ADDR, CONSPEED, VRCOM_FREQ,
    328 		    (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8, 0)) {
    329 			printf("%s(%d): can't init serial console",
    330 			    __FILE__, __LINE__);
    331 		} else {
    332 			return;
    333 		}
    334 	}
    335 #endif
    336 #endif
    337 
    338 #if NHPCFB > 0
    339 	if (hpcfb_cnattach(NULL)) {
    340 		printf("%s(%d): can't init fb console", __FILE__, __LINE__);
    341 	} else {
    342 		goto find_keyboard;
    343 	}
    344 #endif
    345 
    346  find_keyboard:
    347 #if NVRKIU > 0 && VRIP_KIU_ADDR != VRIP_NO_ADDR
    348 	if (vrkiu_cnattach(system_bus_iot, VRIP_KIU_ADDR)) {
    349 		printf("%s(%d): can't init vrkiu as console",
    350 		       __FILE__, __LINE__);
    351 	} else {
    352 		return;
    353 	}
    354 #endif
    355 }
    356 
    357 void
    358 vr_device_register(dev, aux)
    359 	struct device *dev;
    360 	void *aux;
    361 {
    362 	printf("%s(%d): vr_device_register() not implemented.\n",
    363 	       __FILE__, __LINE__);
    364 	panic("abort");
    365 }
    366 
    367 void
    368 vr_reboot(howto, bootstr)
    369 	int howto;
    370 	char *bootstr;
    371 {
    372 	/*
    373 	 * power down
    374 	 */
    375 	if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
    376 		printf("fake powerdown\n");
    377 		__asm(__CONCAT(".word	",___STRING(VR_OPCODE_HIBERNATE)));
    378 		__asm("nop");
    379 		__asm("nop");
    380 		__asm("nop");
    381 		__asm("nop");
    382 		__asm("nop");
    383 		__asm(".set reorder");
    384 		/* not reach */
    385 		vr_reboot(howto&~RB_HALT, bootstr);
    386 	}
    387 	/*
    388 	 * halt
    389 	 */
    390 	if (howto & RB_HALT) {
    391 #if NVRIP > 0
    392 		_spllower(~MIPS_INT_MASK_0);
    393 		vrip_intr_suspend();
    394 #else
    395 		splhigh();
    396 #endif
    397 		__asm(".set noreorder");
    398 		__asm(__CONCAT(".word	",___STRING(VR_OPCODE_SUSPEND)));
    399 		__asm("nop");
    400 		__asm("nop");
    401 		__asm("nop");
    402 		__asm("nop");
    403 		__asm("nop");
    404 		__asm(".set reorder");
    405 #if NVRIP > 0
    406 		vrip_intr_resume();
    407 #endif
    408 	}
    409 	/*
    410 	 * reset
    411 	 */
    412 #if NVRDSU
    413 	vrdsu_reset();
    414 #else
    415 	printf("%s(%d): There is no DSU.", __FILE__, __LINE__);
    416 #endif
    417 }
    418 
    419 void *
    420 vr_intr_establish(line, ih_fun, ih_arg)
    421 	int line;
    422 	int (*ih_fun) __P((void*, u_int32_t, u_int32_t));
    423 	void *ih_arg;
    424 {
    425 	if (intr_handler[line] != null_handler) {
    426 		panic("vr_intr_establish: can't establish duplicated intr handler.");
    427 	}
    428 	intr_handler[line] = ih_fun;
    429 	intr_arg[line] = ih_arg;
    430 
    431 	return (void*)line;
    432 }
    433 
    434 
    435 void
    436 vr_intr_disestablish(ih)
    437 	void *ih;
    438 {
    439 	int line = (int)ih;
    440 	intr_handler[line] = null_handler;
    441 	intr_arg[line] = NULL;
    442 }
    443 
    444 int
    445 null_handler(arg, pc, statusReg)
    446 	void *arg;
    447 	u_int32_t pc;
    448 	u_int32_t statusReg;
    449 {
    450 	printf("null_handler\n");
    451 	return 0;
    452 }
    453 
    454 /*
    455  * Handle interrupts.
    456  */
    457 int
    458 vr_intr(status, cause, pc, ipending)
    459 	u_int32_t status, cause, pc, ipending;
    460 {
    461 	int hwintr;
    462 
    463 	hwintr = (ffs(ipending >> 10) -1) & 0x3;
    464 	(*intr_handler[hwintr])(intr_arg[hwintr], pc, status);
    465 
    466 	return (MIPS_SR_INT_IE | (status & ~cause & MIPS_HARD_INT_MASK));
    467 }
    468 
    469 
    470 /*
    471 int x4181 = VR4181;
    472 int x4101 = VR4101;
    473 int x4102 = VR4102;
    474 int x4111 = VR4111;
    475 int x4121 = VR4121;
    476 int x4122 = VR4122;
    477 int xo4181 = ONLY_VR4181;
    478 int xo4101 = ONLY_VR4101;
    479 int xo4102 = ONLY_VR4102;
    480 int xo4111_4121 = ONLY_VR4111_4121;
    481 int g4101=VRGROUP_4101;
    482 int g4102=VRGROUP_4102;
    483 int g4181=VRGROUP_4181;
    484 int g4102_4121=VRGROUP_4102_4121;
    485 int g4111_4121=VRGROUP_4111_4121;
    486 int g4102_4122=VRGROUP_4102_4122;
    487 int g4111_4122=VRGROUP_4111_4122;
    488 int single_vrip_base=SINGLE_VRIP_BASE;
    489 int vrip_base_addr=VRIP_BASE_ADDR;
    490 */
    491