vr.c revision 1.16 1 /* $NetBSD: vr.c,v 1.16 2000/04/11 17:57:44 uch 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 "hpcfb.h"
91 #include "vrkiu.h"
92 #if NVRKIU > 0
93 #include <dev/wscons/wsdisplayvar.h>
94 #include <dev/rasops/rasops.h>
95 #endif
96
97 #if NHPCFB > 0
98 #include <arch/hpcmips/dev/hpcfbvar.h>
99 #endif
100
101 #if NVRKIU > 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, u_int32_t, u_int32_t, u_int32_t));
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.iointr = vr_intr;
147 platform.bus_reset = vr_bus_reset;
148 platform.cons_init = vr_cons_init;
149 platform.device_register = vr_device_register;
150 platform.fb_init = vr_fb_init;
151 platform.mem_init = vr_mem_init;
152 platform.reboot = vr_reboot;
153
154 #if NVRBCU > 0
155 sprintf(cpu_name, "NEC %s rev%d.%d %d.%03dMHz",
156 vrbcu_vrip_getcpuname(),
157 vrbcu_vrip_getcpumajor(),
158 vrbcu_vrip_getcpuminor(),
159 vrbcu_vrip_getcpuclock() / 1000000,
160 (vrbcu_vrip_getcpuclock() % 1000000) / 1000);
161 #else
162 sprintf(cpu_name, "NEC VR41xx");
163 #endif
164 }
165
166 void
167 vr_mem_init(kernend)
168 paddr_t kernend;
169 {
170 mem_clusters[0].start = 0;
171 mem_clusters[0].size = kernend;
172 mem_cluster_cnt = 1;
173 vr_find_dram(kernend, 0x02000000);
174 vr_find_dram(0x02000000, 0x04000000);
175 vr_find_dram(0x04000000, 0x06000000);
176 vr_find_dram(0x06000000, 0x08000000);
177
178 /* Clear currently unused D-RAM area (For reboot Windows CE clearly)*/
179 memset((void *)(KERNBASE + 0x400), 0, KERNTEXTOFF - (KERNBASE + 0x800));
180 }
181
182 void
183 vr_find_dram(addr, end)
184 paddr_t addr, end;
185 {
186 int n;
187 caddr_t page;
188 #ifdef NARLY_MEMORY_PROBE
189 int x, i;
190 #endif
191
192 n = mem_cluster_cnt;
193 for (; addr < end; addr += NBPG) {
194
195 page = (void *)MIPS_PHYS_TO_KSEG1(addr);
196 if (badaddr(page, 4))
197 goto bad;
198
199 /* stop memory probing at first memory image */
200 if (bcmp(page, (void *)MIPS_PHYS_TO_KSEG0(0), 128) == 0)
201 return;
202
203 *(volatile int *)(page+0) = 0xa5a5a5a5;
204 *(volatile int *)(page+4) = 0x5a5a5a5a;
205 wbflush();
206 if (*(volatile int *)(page+0) != 0xa5a5a5a5)
207 goto bad;
208
209 *(volatile int *)(page+0) = 0x5a5a5a5a;
210 *(volatile int *)(page+4) = 0xa5a5a5a5;
211 wbflush();
212 if (*(volatile int *)(page+0) != 0x5a5a5a5a)
213 goto bad;
214
215 #ifdef NARLY_MEMORY_PROBE
216 x = random();
217 for (i = 0; i < NBPG; i += 4)
218 *(volatile int *)(page+i) = (x ^ i);
219 wbflush();
220 for (i = 0; i < NBPG; i += 4)
221 if (*(volatile int *)(page+i) != (x ^ i))
222 goto bad;
223
224 x = random();
225 for (i = 0; i < NBPG; i += 4)
226 *(volatile int *)(page+i) = (x ^ i);
227 wbflush();
228 for (i = 0; i < NBPG; i += 4)
229 if (*(volatile int *)(page+i) != (x ^ i))
230 goto bad;
231 #endif
232
233 if (!mem_clusters[n].size)
234 mem_clusters[n].start = addr;
235 mem_clusters[n].size += NBPG;
236 continue;
237
238 bad:
239 if (mem_clusters[n].size)
240 ++n;
241 continue;
242 }
243 if (mem_clusters[n].size)
244 ++n;
245 mem_cluster_cnt = n;
246 }
247
248 void
249 vr_fb_init(kernend)
250 caddr_t *kernend;
251 {
252 /* Nothing to do */
253 }
254
255 void
256 vr_os_init()
257 {
258 /*
259 * Set up interrupt handling and I/O addresses.
260 */
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 || NHPCFB > 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 NHPCFB > 0
320 mb_bus_space_init(); /* At this time, not initialized yet */
321 if(hpcfb_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(status, cause, pc, ipending)
441 u_int32_t status, cause, pc, ipending;
442 {
443 int hwintr;
444
445 hwintr = (ffs(ipending >> 10) -1) & 0x3;
446 (*intr_handler[hwintr])(intr_arg[hwintr], pc, status);
447
448 return (MIPS_SR_INT_IE | (status & ~cause & MIPS_HARD_INT_MASK));
449 }
450