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