vr.c revision 1.30 1 1.30 uch /* $NetBSD: vr.c,v 1.30 2001/09/17 17:03:46 uch Exp $ */
2 1.1 takemura
3 1.1 takemura /*-
4 1.1 takemura * Copyright (c) 1999
5 1.1 takemura * Shin Takemura and PocketBSD Project. All rights reserved.
6 1.1 takemura *
7 1.1 takemura * Redistribution and use in source and binary forms, with or without
8 1.1 takemura * modification, are permitted provided that the following conditions
9 1.1 takemura * are met:
10 1.1 takemura * 1. Redistributions of source code must retain the above copyright
11 1.1 takemura * notice, this list of conditions and the following disclaimer.
12 1.1 takemura * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 takemura * notice, this list of conditions and the following disclaimer in the
14 1.1 takemura * documentation and/or other materials provided with the distribution.
15 1.1 takemura * 3. All advertising materials mentioning features or use of this software
16 1.1 takemura * must display the following acknowledgement:
17 1.1 takemura * This product includes software developed by the PocketBSD project
18 1.1 takemura * and its contributors.
19 1.1 takemura * 4. Neither the name of the project nor the names of its contributors
20 1.1 takemura * may be used to endorse or promote products derived from this software
21 1.1 takemura * without specific prior written permission.
22 1.1 takemura *
23 1.1 takemura * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 takemura * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 takemura * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 takemura * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 takemura * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 takemura * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 takemura * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 takemura * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 takemura * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 takemura * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 takemura * SUCH DAMAGE.
34 1.1 takemura *
35 1.1 takemura */
36 1.29 uch
37 1.29 uch #include "opt_vr41xx.h"
38 1.24 lukem #include "opt_kgdb.h"
39 1.24 lukem
40 1.1 takemura #include <sys/param.h>
41 1.1 takemura #include <sys/systm.h>
42 1.5 takemura #include <sys/reboot.h>
43 1.1 takemura
44 1.1 takemura #include <machine/sysconf.h>
45 1.1 takemura #include <machine/bus.h>
46 1.30 uch #include <machine/bootinfo.h>
47 1.1 takemura
48 1.26 enami #include <dev/hpc/hpckbdvar.h>
49 1.26 enami
50 1.30 uch #include <hpcmips/hpcmips/machdep.h> /* cpu_name, mem_cluster */
51 1.30 uch
52 1.1 takemura #include <hpcmips/vr/vr.h>
53 1.11 takemura #include <hpcmips/vr/vr_asm.h>
54 1.22 sato #include <hpcmips/vr/vrcpudef.h>
55 1.3 takemura #include <hpcmips/vr/vripreg.h>
56 1.1 takemura #include <hpcmips/vr/rtcreg.h>
57 1.1 takemura
58 1.8 takemura #include "vrip.h"
59 1.8 takemura #if NVRIP > 0
60 1.8 takemura #include <hpcmips/vr/vripvar.h>
61 1.8 takemura #endif
62 1.8 takemura
63 1.9 sato #include "vrbcu.h"
64 1.9 sato #if NVRBCU > 0
65 1.9 sato #include <hpcmips/vr/bcuvar.h>
66 1.9 sato #endif
67 1.9 sato
68 1.5 takemura #include "vrdsu.h"
69 1.5 takemura #if NVRDSU > 0
70 1.5 takemura #include <hpcmips/vr/vrdsuvar.h>
71 1.5 takemura #endif
72 1.5 takemura
73 1.1 takemura #include "com.h"
74 1.1 takemura #if NCOM > 0
75 1.1 takemura #include <sys/termios.h>
76 1.1 takemura #include <sys/ttydefaults.h>
77 1.1 takemura #include <dev/ic/comreg.h>
78 1.1 takemura #include <dev/ic/comvar.h>
79 1.1 takemura #include <hpcmips/vr/siureg.h>
80 1.1 takemura #include <hpcmips/vr/com_vripvar.h>
81 1.1 takemura #ifndef CONSPEED
82 1.1 takemura #define CONSPEED TTYDEF_SPEED
83 1.1 takemura #endif
84 1.1 takemura #endif
85 1.1 takemura
86 1.15 takemura #include "hpcfb.h"
87 1.3 takemura #include "vrkiu.h"
88 1.25 enami #if (NVRKIU > 0) || (NHPCFB > 0)
89 1.3 takemura #include <dev/wscons/wsdisplayvar.h>
90 1.15 takemura #include <dev/rasops/rasops.h>
91 1.3 takemura #endif
92 1.3 takemura
93 1.15 takemura #if NHPCFB > 0
94 1.20 uch #include <dev/hpc/hpcfbvar.h>
95 1.3 takemura #endif
96 1.3 takemura
97 1.15 takemura #if NVRKIU > 0
98 1.26 enami #include <arch/hpcmips/vr/vrkiureg.h>
99 1.3 takemura #include <arch/hpcmips/vr/vrkiuvar.h>
100 1.3 takemura #endif
101 1.3 takemura
102 1.28 uch void vr_init(void);
103 1.28 uch int vr_intr(u_int32_t, u_int32_t, u_int32_t, u_int32_t);
104 1.28 uch void vr_cons_init(void);
105 1.29 uch void vr_fb_init(caddr_t *);
106 1.28 uch void vr_mem_init(paddr_t);
107 1.28 uch void vr_find_dram(paddr_t, paddr_t);
108 1.28 uch void vr_reboot(int, char *);
109 1.29 uch void vr_idle(void);
110 1.1 takemura
111 1.1 takemura /*
112 1.1 takemura * CPU interrupt dispatch table (HwInt[0:3])
113 1.1 takemura */
114 1.28 uch int null_handler(void *, u_int32_t, u_int32_t);
115 1.28 uch static int (*intr_handler[4])(void*, u_int32_t, u_int32_t) =
116 1.1 takemura {
117 1.1 takemura null_handler,
118 1.1 takemura null_handler,
119 1.1 takemura null_handler,
120 1.1 takemura null_handler
121 1.1 takemura };
122 1.1 takemura static void *intr_arg[4];
123 1.1 takemura
124 1.1 takemura void
125 1.1 takemura vr_init()
126 1.1 takemura {
127 1.1 takemura /*
128 1.1 takemura * Platform Specific Function Hooks
129 1.1 takemura */
130 1.29 uch platform.cpu_idle = vr_idle;
131 1.29 uch platform.iointr = vr_intr;
132 1.29 uch platform.cons_init = vr_cons_init;
133 1.29 uch platform.fb_init = vr_fb_init;
134 1.29 uch platform.mem_init = vr_mem_init;
135 1.29 uch platform.reboot = vr_reboot;
136 1.1 takemura
137 1.9 sato #if NVRBCU > 0
138 1.12 sato sprintf(cpu_name, "NEC %s rev%d.%d %d.%03dMHz",
139 1.1 takemura vrbcu_vrip_getcpuname(),
140 1.1 takemura vrbcu_vrip_getcpumajor(),
141 1.10 shin vrbcu_vrip_getcpuminor(),
142 1.10 shin vrbcu_vrip_getcpuclock() / 1000000,
143 1.10 shin (vrbcu_vrip_getcpuclock() % 1000000) / 1000);
144 1.9 sato #else
145 1.12 sato sprintf(cpu_name, "NEC VR41xx");
146 1.9 sato #endif
147 1.4 uch }
148 1.4 uch
149 1.13 shin void
150 1.28 uch vr_mem_init(paddr_t kernend)
151 1.4 uch {
152 1.25 enami
153 1.13 shin mem_clusters[0].start = 0;
154 1.13 shin mem_clusters[0].size = kernend;
155 1.13 shin mem_cluster_cnt = 1;
156 1.25 enami
157 1.13 shin vr_find_dram(kernend, 0x02000000);
158 1.13 shin vr_find_dram(0x02000000, 0x04000000);
159 1.13 shin vr_find_dram(0x04000000, 0x06000000);
160 1.13 shin vr_find_dram(0x06000000, 0x08000000);
161 1.13 shin
162 1.13 shin /* Clear currently unused D-RAM area (For reboot Windows CE clearly)*/
163 1.13 shin memset((void *)(KERNBASE + 0x400), 0, KERNTEXTOFF - (KERNBASE + 0x800));
164 1.13 shin }
165 1.13 shin
166 1.13 shin void
167 1.28 uch vr_find_dram(paddr_t addr, paddr_t end)
168 1.13 shin {
169 1.13 shin int n;
170 1.13 shin caddr_t page;
171 1.13 shin #ifdef NARLY_MEMORY_PROBE
172 1.13 shin int x, i;
173 1.13 shin #endif
174 1.13 shin
175 1.25 enami #ifdef VR_FIND_DRAMLIM
176 1.25 enami if (VR_FIND_DRAMLIM < end)
177 1.25 enami end = VR_FIND_DRAMLIM;
178 1.25 enami #endif
179 1.13 shin n = mem_cluster_cnt;
180 1.13 shin for (; addr < end; addr += NBPG) {
181 1.13 shin
182 1.13 shin page = (void *)MIPS_PHYS_TO_KSEG1(addr);
183 1.13 shin if (badaddr(page, 4))
184 1.13 shin goto bad;
185 1.14 shin
186 1.14 shin /* stop memory probing at first memory image */
187 1.14 shin if (bcmp(page, (void *)MIPS_PHYS_TO_KSEG0(0), 128) == 0)
188 1.14 shin return;
189 1.13 shin
190 1.13 shin *(volatile int *)(page+0) = 0xa5a5a5a5;
191 1.13 shin *(volatile int *)(page+4) = 0x5a5a5a5a;
192 1.13 shin wbflush();
193 1.13 shin if (*(volatile int *)(page+0) != 0xa5a5a5a5)
194 1.13 shin goto bad;
195 1.13 shin
196 1.13 shin *(volatile int *)(page+0) = 0x5a5a5a5a;
197 1.13 shin *(volatile int *)(page+4) = 0xa5a5a5a5;
198 1.13 shin wbflush();
199 1.13 shin if (*(volatile int *)(page+0) != 0x5a5a5a5a)
200 1.13 shin goto bad;
201 1.13 shin
202 1.13 shin #ifdef NARLY_MEMORY_PROBE
203 1.13 shin x = random();
204 1.13 shin for (i = 0; i < NBPG; i += 4)
205 1.13 shin *(volatile int *)(page+i) = (x ^ i);
206 1.4 uch wbflush();
207 1.13 shin for (i = 0; i < NBPG; i += 4)
208 1.13 shin if (*(volatile int *)(page+i) != (x ^ i))
209 1.13 shin goto bad;
210 1.13 shin
211 1.13 shin x = random();
212 1.13 shin for (i = 0; i < NBPG; i += 4)
213 1.13 shin *(volatile int *)(page+i) = (x ^ i);
214 1.13 shin wbflush();
215 1.13 shin for (i = 0; i < NBPG; i += 4)
216 1.13 shin if (*(volatile int *)(page+i) != (x ^ i))
217 1.13 shin goto bad;
218 1.13 shin #endif
219 1.13 shin
220 1.13 shin if (!mem_clusters[n].size)
221 1.13 shin mem_clusters[n].start = addr;
222 1.13 shin mem_clusters[n].size += NBPG;
223 1.13 shin continue;
224 1.13 shin
225 1.13 shin bad:
226 1.13 shin if (mem_clusters[n].size)
227 1.13 shin ++n;
228 1.13 shin continue;
229 1.4 uch }
230 1.13 shin if (mem_clusters[n].size)
231 1.13 shin ++n;
232 1.13 shin mem_cluster_cnt = n;
233 1.4 uch }
234 1.4 uch
235 1.4 uch void
236 1.28 uch vr_fb_init(caddr_t *kernend)
237 1.4 uch {
238 1.4 uch /* Nothing to do */
239 1.1 takemura }
240 1.1 takemura
241 1.1 takemura void
242 1.1 takemura vr_cons_init()
243 1.1 takemura {
244 1.15 takemura #if NCOM > 0 || NHPCFB > 0 || NVRKIU > 0
245 1.30 uch bus_space_tag_t iot = hpcmips_system_bus_space();
246 1.1 takemura #endif
247 1.1 takemura
248 1.1 takemura #if NCOM > 0
249 1.18 jeffs #ifdef KGDB
250 1.18 jeffs /* if KGDB is defined, always use the serial port for KGDB */
251 1.30 uch if (com_vrip_cndb_attach(iot, VRIP_SIU_ADDR, 9600, VRCOM_FREQ,
252 1.30 uch (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8, 1)) {
253 1.18 jeffs printf("%s(%d): can't init kgdb's serial port",
254 1.23 enami __FILE__, __LINE__);
255 1.18 jeffs }
256 1.30 uch #else /* KGDB */
257 1.1 takemura if (bootinfo->bi_cnuse & BI_CNUSE_SERIAL) {
258 1.1 takemura /* Serial console */
259 1.30 uch if (com_vrip_cndb_attach(iot, VRIP_SIU_ADDR, CONSPEED,
260 1.30 uch VRCOM_FREQ, (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8, 0)) {
261 1.23 enami printf("%s(%d): can't init serial console",
262 1.23 enami __FILE__, __LINE__);
263 1.1 takemura } else {
264 1.1 takemura return;
265 1.1 takemura }
266 1.1 takemura }
267 1.30 uch #endif /* KGDB */
268 1.30 uch #endif /* NCOM > 0 */
269 1.1 takemura
270 1.15 takemura #if NHPCFB > 0
271 1.17 uch if (hpcfb_cnattach(NULL)) {
272 1.3 takemura printf("%s(%d): can't init fb console", __FILE__, __LINE__);
273 1.3 takemura } else {
274 1.3 takemura goto find_keyboard;
275 1.3 takemura }
276 1.25 enami find_keyboard:
277 1.30 uch #endif /* NHPCFB > 0 */
278 1.3 takemura
279 1.22 sato #if NVRKIU > 0 && VRIP_KIU_ADDR != VRIP_NO_ADDR
280 1.30 uch if (vrkiu_cnattach(iot, VRIP_KIU_ADDR)) {
281 1.3 takemura printf("%s(%d): can't init vrkiu as console",
282 1.3 takemura __FILE__, __LINE__);
283 1.3 takemura } else {
284 1.3 takemura return;
285 1.3 takemura }
286 1.30 uch #endif /* NVRKIU > 0 && VRIP_KIU_ADDR != VRIP_NO_ADDR */
287 1.5 takemura }
288 1.5 takemura
289 1.5 takemura void
290 1.28 uch vr_reboot(int howto, char *bootstr)
291 1.5 takemura {
292 1.7 takemura /*
293 1.7 takemura * power down
294 1.7 takemura */
295 1.7 takemura if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
296 1.7 takemura printf("fake powerdown\n");
297 1.7 takemura __asm(__CONCAT(".word ",___STRING(VR_OPCODE_HIBERNATE)));
298 1.7 takemura __asm("nop");
299 1.7 takemura __asm("nop");
300 1.7 takemura __asm("nop");
301 1.7 takemura __asm("nop");
302 1.7 takemura __asm("nop");
303 1.7 takemura __asm(".set reorder");
304 1.7 takemura /* not reach */
305 1.7 takemura vr_reboot(howto&~RB_HALT, bootstr);
306 1.7 takemura }
307 1.7 takemura /*
308 1.8 takemura * halt
309 1.7 takemura */
310 1.8 takemura if (howto & RB_HALT) {
311 1.8 takemura #if NVRIP > 0
312 1.8 takemura _spllower(~MIPS_INT_MASK_0);
313 1.8 takemura vrip_intr_suspend();
314 1.5 takemura #else
315 1.8 takemura splhigh();
316 1.5 takemura #endif
317 1.7 takemura __asm(".set noreorder");
318 1.7 takemura __asm(__CONCAT(".word ",___STRING(VR_OPCODE_SUSPEND)));
319 1.6 sato __asm("nop");
320 1.6 sato __asm("nop");
321 1.6 sato __asm("nop");
322 1.6 sato __asm("nop");
323 1.6 sato __asm("nop");
324 1.7 takemura __asm(".set reorder");
325 1.8 takemura #if NVRIP > 0
326 1.8 takemura vrip_intr_resume();
327 1.8 takemura #endif
328 1.6 sato }
329 1.8 takemura /*
330 1.8 takemura * reset
331 1.8 takemura */
332 1.8 takemura #if NVRDSU
333 1.8 takemura vrdsu_reset();
334 1.8 takemura #else
335 1.8 takemura printf("%s(%d): There is no DSU.", __FILE__, __LINE__);
336 1.8 takemura #endif
337 1.1 takemura }
338 1.1 takemura
339 1.30 uch /*
340 1.30 uch * Handle interrupts.
341 1.30 uch */
342 1.30 uch int
343 1.30 uch vr_intr(u_int32_t status, u_int32_t cause, u_int32_t pc, u_int32_t ipending)
344 1.30 uch {
345 1.30 uch int hwintr;
346 1.30 uch
347 1.30 uch hwintr = (ffs(ipending >> 10) -1) & 0x3;
348 1.30 uch (*intr_handler[hwintr])(intr_arg[hwintr], pc, status);
349 1.30 uch
350 1.30 uch return (MIPS_SR_INT_IE | (status & ~cause & MIPS_HARD_INT_MASK));
351 1.30 uch }
352 1.30 uch
353 1.1 takemura void *
354 1.30 uch vr_intr_establish(int line, int (*ih_fun)(void *, u_int32_t, u_int32_t),
355 1.28 uch void *ih_arg)
356 1.1 takemura {
357 1.28 uch
358 1.1 takemura if (intr_handler[line] != null_handler) {
359 1.30 uch panic("vr_intr_establish:"
360 1.30 uch " can't establish duplicated intr handler.");
361 1.1 takemura }
362 1.1 takemura intr_handler[line] = ih_fun;
363 1.1 takemura intr_arg[line] = ih_arg;
364 1.1 takemura
365 1.30 uch return ((void*)line);
366 1.1 takemura }
367 1.1 takemura
368 1.1 takemura
369 1.1 takemura void
370 1.28 uch vr_intr_disestablish(void *ih)
371 1.1 takemura {
372 1.1 takemura int line = (int)ih;
373 1.28 uch
374 1.1 takemura intr_handler[line] = null_handler;
375 1.1 takemura intr_arg[line] = NULL;
376 1.1 takemura }
377 1.1 takemura
378 1.1 takemura int
379 1.28 uch null_handler(void *arg, u_int32_t pc, u_int32_t statusReg)
380 1.1 takemura {
381 1.1 takemura printf("null_handler\n");
382 1.28 uch
383 1.28 uch return (0);
384 1.1 takemura }
385 1.22 sato
386 1.22 sato /*
387 1.22 sato int x4181 = VR4181;
388 1.22 sato int x4101 = VR4101;
389 1.22 sato int x4102 = VR4102;
390 1.22 sato int x4111 = VR4111;
391 1.22 sato int x4121 = VR4121;
392 1.22 sato int x4122 = VR4122;
393 1.22 sato int xo4181 = ONLY_VR4181;
394 1.22 sato int xo4101 = ONLY_VR4101;
395 1.22 sato int xo4102 = ONLY_VR4102;
396 1.22 sato int xo4111_4121 = ONLY_VR4111_4121;
397 1.22 sato int g4101=VRGROUP_4101;
398 1.22 sato int g4102=VRGROUP_4102;
399 1.22 sato int g4181=VRGROUP_4181;
400 1.22 sato int g4102_4121=VRGROUP_4102_4121;
401 1.22 sato int g4111_4121=VRGROUP_4111_4121;
402 1.22 sato int g4102_4122=VRGROUP_4102_4122;
403 1.22 sato int g4111_4122=VRGROUP_4111_4122;
404 1.22 sato int single_vrip_base=SINGLE_VRIP_BASE;
405 1.22 sato int vrip_base_addr=VRIP_BASE_ADDR;
406 1.22 sato */
407