vr.c revision 1.8 1 1.8 takemura /* $NetBSD: vr.c,v 1.8 1999/12/04 14:23:36 takemura 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.1 takemura #include <sys/param.h>
37 1.1 takemura #include <sys/types.h>
38 1.1 takemura #include <sys/systm.h>
39 1.1 takemura #include <sys/device.h>
40 1.5 takemura #include <sys/reboot.h>
41 1.1 takemura
42 1.1 takemura #include <machine/cpu.h>
43 1.1 takemura #include <machine/intr.h>
44 1.1 takemura #include <machine/reg.h>
45 1.1 takemura #include <machine/psl.h>
46 1.1 takemura #include <machine/locore.h>
47 1.1 takemura #include <machine/sysconf.h>
48 1.1 takemura #include <machine/bus.h>
49 1.1 takemura #include <machine/autoconf.h>
50 1.1 takemura
51 1.1 takemura #include <mips/mips_param.h> /* hokey spl()s */
52 1.1 takemura #include <mips/mips/mips_mcclock.h> /* mcclock CPUspeed estimation */
53 1.1 takemura
54 1.1 takemura #include <hpcmips/vr/vr.h>
55 1.3 takemura #include <hpcmips/vr/vripreg.h>
56 1.1 takemura #include <hpcmips/vr/rtcreg.h>
57 1.1 takemura #include <hpcmips/hpcmips/machdep.h> /* XXXjrs replace with vectors */
58 1.1 takemura #include <machine/bootinfo.h>
59 1.1 takemura
60 1.8 takemura #include "vrip.h"
61 1.8 takemura #if NVRIP > 0
62 1.8 takemura #include <hpcmips/vr/vripvar.h>
63 1.8 takemura #endif
64 1.8 takemura
65 1.5 takemura #include "vrdsu.h"
66 1.5 takemura #if NVRDSU > 0
67 1.5 takemura #include <hpcmips/vr/vrdsuvar.h>
68 1.5 takemura #endif
69 1.5 takemura
70 1.1 takemura #include "com.h"
71 1.1 takemura #if NCOM > 0
72 1.1 takemura #include <sys/termios.h>
73 1.1 takemura #include <sys/ttydefaults.h>
74 1.1 takemura #include <dev/ic/comreg.h>
75 1.1 takemura #include <dev/ic/comvar.h>
76 1.1 takemura #include <hpcmips/vr/siureg.h>
77 1.1 takemura #include <hpcmips/vr/com_vripvar.h>
78 1.1 takemura #ifndef CONSPEED
79 1.1 takemura #define CONSPEED TTYDEF_SPEED
80 1.1 takemura #endif
81 1.1 takemura #endif
82 1.1 takemura
83 1.3 takemura #include "fb.h"
84 1.3 takemura #include "vrkiu.h"
85 1.3 takemura #if NFB > 0 || NVRKIU > 0
86 1.3 takemura #include <dev/rcons/raster.h>
87 1.3 takemura #include <dev/wscons/wsdisplayvar.h>
88 1.3 takemura #endif
89 1.3 takemura
90 1.3 takemura #if NFB > 0
91 1.3 takemura #include <arch/hpcmips/dev/fbvar.h>
92 1.3 takemura #endif
93 1.3 takemura
94 1.3 takemura #if NFB > 0
95 1.3 takemura #include <arch/hpcmips/vr/vrkiuvar.h>
96 1.3 takemura #endif
97 1.3 takemura
98 1.1 takemura void vr_init __P((void));
99 1.1 takemura void vr_os_init __P((void));
100 1.1 takemura void vr_bus_reset __P((void));
101 1.1 takemura int vr_intr __P((u_int32_t mask, u_int32_t pc, u_int32_t statusReg, u_int32_t causeReg));
102 1.1 takemura void vr_cons_init __P((void));
103 1.1 takemura void vr_device_register __P((struct device *, void *));
104 1.4 uch void vr_fb_init __P((caddr_t*));
105 1.4 uch int vr_mem_init __P((caddr_t));
106 1.5 takemura void vr_reboot __P((int howto, char *bootstr));
107 1.1 takemura
108 1.1 takemura char *vrbcu_vrip_getcpuname __P((void));
109 1.1 takemura int vrbcu_vrip_getcpumajor __P((void));
110 1.1 takemura int vrbcu_vrip_getcpuminor __P((void));
111 1.1 takemura
112 1.1 takemura extern unsigned nullclkread __P((void));
113 1.1 takemura extern unsigned (*clkread) __P((void));
114 1.1 takemura
115 1.1 takemura /*
116 1.1 takemura * CPU interrupt dispatch table (HwInt[0:3])
117 1.1 takemura */
118 1.1 takemura int null_handler __P((void*, u_int32_t, u_int32_t));
119 1.1 takemura static int (*intr_handler[4]) __P((void*, u_int32_t, u_int32_t)) =
120 1.1 takemura {
121 1.1 takemura null_handler,
122 1.1 takemura null_handler,
123 1.1 takemura null_handler,
124 1.1 takemura null_handler
125 1.1 takemura };
126 1.1 takemura static void *intr_arg[4];
127 1.1 takemura
128 1.1 takemura void
129 1.1 takemura vr_init()
130 1.1 takemura {
131 1.1 takemura /*
132 1.1 takemura * Platform Information.
133 1.1 takemura */
134 1.1 takemura
135 1.1 takemura /*
136 1.1 takemura * Platform Specific Function Hooks
137 1.1 takemura */
138 1.1 takemura platform.os_init = vr_os_init;
139 1.1 takemura platform.bus_reset = vr_bus_reset;
140 1.1 takemura platform.cons_init = vr_cons_init;
141 1.1 takemura platform.device_register = vr_device_register;
142 1.4 uch platform.fb_init = vr_fb_init;
143 1.4 uch platform.mem_init = vr_mem_init;
144 1.5 takemura platform.reboot = vr_reboot;
145 1.1 takemura
146 1.1 takemura sprintf(cpu_model, "NEC %s rev%d.%d",
147 1.1 takemura vrbcu_vrip_getcpuname(),
148 1.1 takemura vrbcu_vrip_getcpumajor(),
149 1.1 takemura vrbcu_vrip_getcpuminor());
150 1.4 uch }
151 1.4 uch
152 1.4 uch int
153 1.4 uch vr_mem_init(kernend)
154 1.4 uch caddr_t kernend; /* kseg0 */
155 1.4 uch {
156 1.4 uch u_int32_t startaddr, endaddr, page;
157 1.4 uch int npage;
158 1.4 uch #define VR41_SYSADDR_DRAMSTART 0x0
159 1.4 uch #define VR41_SYSADDR_DRAM_LEN 0x04000000
160 1.4 uch startaddr = MIPS_PHYS_TO_KSEG1(
161 1.4 uch (btoc((u_int32_t)kernend - MIPS_KSEG0_START)) << PGSHIFT);
162 1.4 uch endaddr = MIPS_PHYS_TO_KSEG1(VR41_SYSADDR_DRAMSTART +
163 1.4 uch VR41_SYSADDR_DRAM_LEN);
164 1.4 uch for(page = startaddr, npage = 0; page < endaddr;
165 1.4 uch page+= NBPG, npage++) {
166 1.4 uch if (badaddr((char*)page, 4))
167 1.4 uch break;
168 1.4 uch ((volatile int *)page)[0] = 0xa5a5a5a5;
169 1.4 uch ((volatile int *)page)[4] = 0x5a5a5a5a;
170 1.4 uch wbflush();
171 1.4 uch if (*(volatile int *)page != 0xa5a5a5a5)
172 1.4 uch break;
173 1.4 uch }
174 1.4 uch /* Clear currently unused D-RAM area (For reboot Windows CE clearly)*/
175 1.4 uch memset((void*)startaddr, 0, npage * NBPG);
176 1.4 uch memset((void*)(KERNBASE + 0x400), 0, KERNTEXTOFF - KERNBASE - 0x800);
177 1.4 uch
178 1.4 uch return npage;
179 1.4 uch }
180 1.4 uch
181 1.4 uch void
182 1.4 uch vr_fb_init(kernend)
183 1.4 uch caddr_t *kernend;
184 1.4 uch {
185 1.4 uch /* Nothing to do */
186 1.1 takemura }
187 1.1 takemura
188 1.1 takemura void
189 1.1 takemura vr_os_init()
190 1.1 takemura {
191 1.1 takemura /*
192 1.1 takemura * Set up interrupt handling and I/O addresses.
193 1.1 takemura */
194 1.1 takemura mips_hardware_intr = vr_intr;
195 1.1 takemura
196 1.1 takemura splvec.splbio = MIPS_SPL0;
197 1.1 takemura splvec.splnet = MIPS_SPL0;
198 1.1 takemura splvec.spltty = MIPS_SPL0;
199 1.1 takemura splvec.splimp = MIPS_SPL0;
200 1.1 takemura splvec.splclock = MIPS_SPL_0_1;
201 1.1 takemura splvec.splstatclock = MIPS_SPL_0_1;
202 1.1 takemura
203 1.1 takemura /* no high resolution timer circuit; possibly never called */
204 1.1 takemura clkread = nullclkread;
205 1.1 takemura
206 1.1 takemura #ifdef NOT_YET
207 1.1 takemura mcclock_addr = (volatile struct chiptime *)
208 1.1 takemura MIPS_PHYS_TO_KSEG1(Vr_SYS_CLOCK);
209 1.1 takemura mc_cpuspeed(mcclock_addr, MIPS_INT_MASK_1);
210 1.1 takemura #else
211 1.1 takemura printf("%s(%d): cpuspeed estimation is notimplemented\n",
212 1.1 takemura __FILE__, __LINE__);
213 1.1 takemura #endif
214 1.1 takemura #ifdef HPCMIPS_L1CACHE_DISABLE
215 1.1 takemura cpuspeed = 1; /* XXX, CPU is very very slow because L1 cache is */
216 1.1 takemura /* disabled. */
217 1.1 takemura #endif /* HPCMIPS_L1CAHCE_DISABLE */
218 1.1 takemura }
219 1.1 takemura
220 1.1 takemura
221 1.1 takemura /*
222 1.1 takemura * Initalize the memory system and I/O buses.
223 1.1 takemura */
224 1.1 takemura void
225 1.1 takemura vr_bus_reset()
226 1.1 takemura {
227 1.1 takemura printf("%s(%d): vr_bus_reset() not implemented.\n",
228 1.1 takemura __FILE__, __LINE__);
229 1.1 takemura }
230 1.1 takemura
231 1.1 takemura void
232 1.1 takemura vr_cons_init()
233 1.1 takemura {
234 1.3 takemura #if NCOM > 0 || NFB > 0 || NVRKIU > 0
235 1.1 takemura extern bus_space_tag_t system_bus_iot;
236 1.1 takemura extern bus_space_tag_t mb_bus_space_init __P((void));
237 1.1 takemura #endif
238 1.1 takemura
239 1.1 takemura #if NCOM > 0
240 1.1 takemura if (bootinfo->bi_cnuse & BI_CNUSE_SERIAL) {
241 1.1 takemura /* Serial console */
242 1.1 takemura mb_bus_space_init(); /* At this time, not initialized yet */
243 1.1 takemura if(com_vrip_cnattach(system_bus_iot, 0x0c000000, CONSPEED,
244 1.1 takemura VRCOM_FREQ,
245 1.1 takemura (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8)) {
246 1.1 takemura printf("%s(%d): can't init serial console", __FILE__, __LINE__);
247 1.1 takemura } else {
248 1.1 takemura return;
249 1.1 takemura }
250 1.1 takemura }
251 1.1 takemura #endif
252 1.1 takemura
253 1.3 takemura #if NFB > 0
254 1.3 takemura mb_bus_space_init(); /* At this time, not initialized yet */
255 1.3 takemura if(fb_cnattach(system_bus_iot, 0x0c000000, 0, 0)) {
256 1.3 takemura printf("%s(%d): can't init fb console", __FILE__, __LINE__);
257 1.3 takemura } else {
258 1.3 takemura goto find_keyboard;
259 1.3 takemura }
260 1.3 takemura #endif
261 1.3 takemura
262 1.3 takemura find_keyboard:
263 1.3 takemura #if NVRKIU > 0
264 1.3 takemura if (vrkiu_cnattach(system_bus_iot, VRIP_KIU_ADDR)) {
265 1.3 takemura printf("%s(%d): can't init vrkiu as console",
266 1.3 takemura __FILE__, __LINE__);
267 1.3 takemura } else {
268 1.3 takemura return;
269 1.3 takemura }
270 1.3 takemura #endif
271 1.1 takemura }
272 1.1 takemura
273 1.1 takemura void
274 1.1 takemura vr_device_register(dev, aux)
275 1.1 takemura struct device *dev;
276 1.1 takemura void *aux;
277 1.1 takemura {
278 1.2 shin printf("%s(%d): vr_device_register() not implemented.\n",
279 1.1 takemura __FILE__, __LINE__);
280 1.1 takemura panic("abort");
281 1.5 takemura }
282 1.5 takemura
283 1.5 takemura void
284 1.5 takemura vr_reboot(howto, bootstr)
285 1.5 takemura int howto;
286 1.5 takemura char *bootstr;
287 1.5 takemura {
288 1.7 takemura /*
289 1.7 takemura * power down
290 1.7 takemura */
291 1.7 takemura if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
292 1.7 takemura printf("fake powerdown\n");
293 1.7 takemura __asm(__CONCAT(".word ",___STRING(VR_OPCODE_HIBERNATE)));
294 1.7 takemura __asm("nop");
295 1.7 takemura __asm("nop");
296 1.7 takemura __asm("nop");
297 1.7 takemura __asm("nop");
298 1.7 takemura __asm("nop");
299 1.7 takemura __asm(".set reorder");
300 1.7 takemura /* not reach */
301 1.7 takemura vr_reboot(howto&~RB_HALT, bootstr);
302 1.7 takemura }
303 1.7 takemura /*
304 1.8 takemura * halt
305 1.7 takemura */
306 1.8 takemura if (howto & RB_HALT) {
307 1.8 takemura #if NVRIP > 0
308 1.8 takemura _spllower(~MIPS_INT_MASK_0);
309 1.8 takemura vrip_intr_suspend();
310 1.5 takemura #else
311 1.8 takemura splhigh();
312 1.5 takemura #endif
313 1.7 takemura __asm(".set noreorder");
314 1.7 takemura __asm(__CONCAT(".word ",___STRING(VR_OPCODE_SUSPEND)));
315 1.6 sato __asm("nop");
316 1.6 sato __asm("nop");
317 1.6 sato __asm("nop");
318 1.6 sato __asm("nop");
319 1.6 sato __asm("nop");
320 1.7 takemura __asm(".set reorder");
321 1.8 takemura #if NVRIP > 0
322 1.8 takemura vrip_intr_resume();
323 1.8 takemura #endif
324 1.6 sato }
325 1.8 takemura /*
326 1.8 takemura * reset
327 1.8 takemura */
328 1.8 takemura #if NVRDSU
329 1.8 takemura vrdsu_reset();
330 1.8 takemura #else
331 1.8 takemura printf("%s(%d): There is no DSU.", __FILE__, __LINE__);
332 1.8 takemura #endif
333 1.1 takemura }
334 1.1 takemura
335 1.1 takemura void *
336 1.1 takemura vr_intr_establish(line, ih_fun, ih_arg)
337 1.1 takemura int line;
338 1.1 takemura int (*ih_fun) __P((void*, u_int32_t, u_int32_t));
339 1.1 takemura void *ih_arg;
340 1.1 takemura {
341 1.1 takemura if (intr_handler[line] != null_handler) {
342 1.1 takemura panic("vr_intr_establish: can't establish duplicated intr handler.");
343 1.1 takemura }
344 1.1 takemura intr_handler[line] = ih_fun;
345 1.1 takemura intr_arg[line] = ih_arg;
346 1.1 takemura
347 1.1 takemura return (void*)line;
348 1.1 takemura }
349 1.1 takemura
350 1.1 takemura
351 1.1 takemura void
352 1.1 takemura vr_intr_disestablish(ih)
353 1.1 takemura void *ih;
354 1.1 takemura {
355 1.1 takemura int line = (int)ih;
356 1.1 takemura intr_handler[line] = null_handler;
357 1.1 takemura intr_arg[line] = NULL;
358 1.1 takemura }
359 1.1 takemura
360 1.1 takemura int
361 1.1 takemura null_handler(arg, pc, statusReg)
362 1.1 takemura void *arg;
363 1.1 takemura u_int32_t pc;
364 1.1 takemura u_int32_t statusReg;
365 1.1 takemura {
366 1.1 takemura printf("null_handler\n");
367 1.1 takemura return 0;
368 1.1 takemura }
369 1.1 takemura
370 1.1 takemura /*
371 1.1 takemura * Handle interrupts.
372 1.1 takemura */
373 1.1 takemura int
374 1.1 takemura vr_intr(mask, pc, status, cause)
375 1.1 takemura u_int32_t mask;
376 1.1 takemura u_int32_t pc;
377 1.1 takemura u_int32_t status;
378 1.1 takemura u_int32_t cause;
379 1.1 takemura {
380 1.1 takemura int hwintr;
381 1.1 takemura
382 1.1 takemura hwintr = (ffs(mask >> 10) -1) & 0x3;
383 1.1 takemura (*intr_handler[hwintr])(intr_arg[hwintr], pc, status);
384 1.1 takemura return (MIPS_SR_INT_IE | (status & ~cause & MIPS_HARD_INT_MASK));
385 1.1 takemura }
386