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